From 985aeb095b69d591df849e8a7d91de785864b9cd Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Wed, 28 Aug 2019 14:30:41 +0200 Subject: [PATCH] Enhance amendment list and routing logic Enhances routing logic and amendment list --- .../ui-services/base-filter-list.service.ts | 39 +++++++++-------- .../core/ui-services/routing-state.service.ts | 2 +- .../amendment-list.component.ts | 14 +++++-- .../motion-detail.component.html | 10 ++--- .../motion-detail/motion-detail.component.ts | 12 +++++- .../services/amendment-filter-list.service.ts | 42 ++++++++++++++----- 6 files changed, 79 insertions(+), 40 deletions(-) diff --git a/client/src/app/core/ui-services/base-filter-list.service.ts b/client/src/app/core/ui-services/base-filter-list.service.ts index 15f435c67..5b76b1447 100644 --- a/client/src/app/core/ui-services/base-filter-list.service.ts +++ b/client/src/app/core/ui-services/base-filter-list.service.ts @@ -241,28 +241,33 @@ export abstract class BaseFilterListService { storedFilter = await this.store.get('filter_' + this.storageKey); } - if (!!storedFilter) { + if (storedFilter && storedFilter.length && newDefinitions && newDefinitions.length) { for (const newDef of newDefinitions) { - let count = 0; - const matchingExistingFilter = storedFilter.find(oldDef => oldDef.property === newDef.property); - for (const option of newDef.options) { - if (typeof option === 'object') { - if (matchingExistingFilter && matchingExistingFilter.options) { - const existingOption = matchingExistingFilter.options.find( - o => - typeof o !== 'string' && - JSON.stringify(o.condition) === JSON.stringify(option.condition) - ) as OsFilterOption; - if (existingOption) { - option.isActive = existingOption.isActive; - } - if (option.isActive) { - count++; + console.log('set filter'); + + // for some weird angular bugs, newDef can actually be undefined + if (newDef) { + let count = 0; + const matchingExistingFilter = storedFilter.find(oldDef => oldDef.property === newDef.property); + for (const option of newDef.options) { + if (typeof option === 'object') { + if (matchingExistingFilter && matchingExistingFilter.options) { + const existingOption = matchingExistingFilter.options.find( + o => + typeof o !== 'string' && + JSON.stringify(o.condition) === JSON.stringify(option.condition) + ) as OsFilterOption; + if (existingOption) { + option.isActive = existingOption.isActive; + } + if (option.isActive) { + count++; + } } } } + newDef.count = count; } - newDef.count = count; } } diff --git a/client/src/app/core/ui-services/routing-state.service.ts b/client/src/app/core/ui-services/routing-state.service.ts index 4b4727218..c2c2e4e87 100644 --- a/client/src/app/core/ui-services/routing-state.service.ts +++ b/client/src/app/core/ui-services/routing-state.service.ts @@ -31,7 +31,7 @@ export class RoutingStateService { if (this._previousUrl) { return !this.unsafeUrls.some(unsafeUrl => this._previousUrl.includes(unsafeUrl)); } else { - return false; + return true; } } diff --git a/client/src/app/site/motions/modules/amendment-list/amendment-list.component.ts b/client/src/app/site/motions/modules/amendment-list/amendment-list.component.ts index fd7861c5c..06da9bd26 100644 --- a/client/src/app/site/motions/modules/amendment-list/amendment-list.component.ts +++ b/client/src/app/site/motions/modules/amendment-list/amendment-list.component.ts @@ -30,7 +30,11 @@ import { ViewMotion } from '../../models/view-motion'; changeDetection: ChangeDetectionStrategy.OnPush }) export class AmendmentListComponent extends BaseListViewComponent implements OnInit { + /** + * Has the id of the parent motion if passed through the constructor + */ private parentMotionId: number; + /** * Hold item visibility */ @@ -95,6 +99,11 @@ export class AmendmentListComponent extends BaseListViewComponent im super.setTitle('Amendments'); this.canMultiSelect = true; this.parentMotionId = parseInt(route.snapshot.params.id, 10); + if (this.parentMotionId) { + this.amendmentFilterService.parentMotionId = this.parentMotionId; + } else { + this.amendmentFilterService.parentMotionId = undefined; + } } /** @@ -106,10 +115,7 @@ export class AmendmentListComponent extends BaseListViewComponent im }); if (!!this.parentMotionId) { - this.amendmentFilterService.clearAllFilters(); - this.amendmentFilterService.parentMotionId = this.parentMotionId; - } else { - this.amendmentFilterService.parentMotionId = 0; + // this.amendmentFilterService.clearAllFilters(); } } diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html index f9e875162..f06de8a47 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html @@ -2,7 +2,6 @@ [mainButton]="perms.isAllowed('can_create_amendments', motion)" mainActionTooltip="New amendment" [prevUrl]="getPrevUrl()" - [goBack]="routingStateService.isSafePrevUrl" [nav]="false" [editMode]="editMotion" [isSaveButtonEnabled]="contentForm.valid" @@ -441,12 +440,11 @@ diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts index 17ade8339..419e3807d 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts @@ -447,7 +447,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, private itemRepo: ItemRepositoryService, private motionSortService: MotionSortListService, private motionFilterService: MotionFilterListService, - public routingStateService: RoutingStateService + private routingStateService: RoutingStateService ) { super(title, translate, matSnackBar); } @@ -1557,7 +1557,15 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, public getPrevUrl(): string { if (this.motion && this.motion.parent_id) { if (this.routingStateService.previousUrl && this.routingStateService.isSafePrevUrl) { - return this.routingStateService.previousUrl; + if ( + (this.previousMotion && + this.routingStateService.previousUrl === this.previousMotion.getDetailStateURL()) || + (this.nextMotion && this.routingStateService.previousUrl === this.nextMotion.getDetailStateURL()) + ) { + return '../..'; + } else { + return this.routingStateService.previousUrl; + } } else { return this.motion.parent.getDetailStateURL(); } diff --git a/client/src/app/site/motions/services/amendment-filter-list.service.ts b/client/src/app/site/motions/services/amendment-filter-list.service.ts index 281c2143c..99c8949cf 100644 --- a/client/src/app/site/motions/services/amendment-filter-list.service.ts +++ b/client/src/app/site/motions/services/amendment-filter-list.service.ts @@ -26,26 +26,35 @@ export class AmendmentFilterListService extends MotionFilterListService { /** * Private accessor for an amendment id */ - private _parentMotionId: number; + public _parentMotionId: number; /** * set the storage key nae */ - protected storageKey = 'AmendmentList'; + protected storageKey: string; + + /** + * The sorage key prefix to identify the parent id + */ + private keyPrefix = 'AmendmentList'; + + /** + * Filters by motion parent id + */ + private motionFilterOptions: OsFilter = { + property: 'parent_id', + label: 'Motion', + options: [] + }; /** * publicly get an amendment id */ public set parentMotionId(id: number) { this._parentMotionId = id; + this.updateStorageKey(); } - private motionFilterOptions: OsFilter = { - property: 'parent_id', - label: 'Motion', - options: [] - }; - public constructor( store: StorageService, OSStatus: OpenSlidesStatusService, @@ -77,10 +86,21 @@ export class AmendmentFilterListService extends MotionFilterListService { ); } + /** + * Function to define a new storage key by parent id + */ + private updateStorageKey(): void { + if (!!this._parentMotionId) { + this.storageKey = `${this.keyPrefix}_parentId_${this._parentMotionId}`; + } else { + this.storageKey = this.keyPrefix; + } + } + /** * @override from base filter list service * - * @returns the list of Motions which only contains view motions + * @returns the only motons with a parentId */ protected preFilter(motions: ViewMotion[]): ViewMotion[] { return motions.filter(motion => { @@ -96,6 +116,8 @@ export class AmendmentFilterListService extends MotionFilterListService { * Currently, no filters for the amendment list, except the pre-filter */ protected getFilterDefinitions(): OsFilter[] { - return [this.motionFilterOptions].concat(super.getFilterDefinitions()); + if (this.motionFilterOptions) { + return [this.motionFilterOptions].concat(super.getFilterDefinitions()); + } } }