Merge pull request #4951 from tsiegleauq/better-amendments-list

Enhance amendment list and routing logic
This commit is contained in:
Emanuel Schütze 2019-08-28 14:57:48 +02:00 committed by GitHub
commit 5b11b672a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 40 deletions

View File

@ -241,8 +241,12 @@ export abstract class BaseFilterListService<V extends BaseViewModel> {
storedFilter = await this.store.get<OsFilter[]>('filter_' + this.storageKey); storedFilter = await this.store.get<OsFilter[]>('filter_' + this.storageKey);
} }
if (!!storedFilter) { if (storedFilter && storedFilter.length && newDefinitions && newDefinitions.length) {
for (const newDef of newDefinitions) { for (const newDef of newDefinitions) {
console.log('set filter');
// for some weird angular bugs, newDef can actually be undefined
if (newDef) {
let count = 0; let count = 0;
const matchingExistingFilter = storedFilter.find(oldDef => oldDef.property === newDef.property); const matchingExistingFilter = storedFilter.find(oldDef => oldDef.property === newDef.property);
for (const option of newDef.options) { for (const option of newDef.options) {
@ -265,6 +269,7 @@ export abstract class BaseFilterListService<V extends BaseViewModel> {
newDef.count = count; newDef.count = count;
} }
} }
}
this.filterDefinitions = newDefinitions; this.filterDefinitions = newDefinitions;
this.storeActiveFilters(); this.storeActiveFilters();

View File

@ -31,7 +31,7 @@ export class RoutingStateService {
if (this._previousUrl) { if (this._previousUrl) {
return !this.unsafeUrls.some(unsafeUrl => this._previousUrl.includes(unsafeUrl)); return !this.unsafeUrls.some(unsafeUrl => this._previousUrl.includes(unsafeUrl));
} else { } else {
return false; return true;
} }
} }

View File

@ -30,7 +30,11 @@ import { ViewMotion } from '../../models/view-motion';
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class AmendmentListComponent extends BaseListViewComponent<ViewMotion> implements OnInit { export class AmendmentListComponent extends BaseListViewComponent<ViewMotion> implements OnInit {
/**
* Has the id of the parent motion if passed through the constructor
*/
private parentMotionId: number; private parentMotionId: number;
/** /**
* Hold item visibility * Hold item visibility
*/ */
@ -95,6 +99,11 @@ export class AmendmentListComponent extends BaseListViewComponent<ViewMotion> im
super.setTitle('Amendments'); super.setTitle('Amendments');
this.canMultiSelect = true; this.canMultiSelect = true;
this.parentMotionId = parseInt(route.snapshot.params.id, 10); 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<ViewMotion> im
}); });
if (!!this.parentMotionId) { if (!!this.parentMotionId) {
this.amendmentFilterService.clearAllFilters(); // this.amendmentFilterService.clearAllFilters();
this.amendmentFilterService.parentMotionId = this.parentMotionId;
} else {
this.amendmentFilterService.parentMotionId = 0;
} }
} }

View File

@ -2,7 +2,6 @@
[mainButton]="perms.isAllowed('can_create_amendments', motion)" [mainButton]="perms.isAllowed('can_create_amendments', motion)"
mainActionTooltip="New amendment" mainActionTooltip="New amendment"
[prevUrl]="getPrevUrl()" [prevUrl]="getPrevUrl()"
[goBack]="routingStateService.isSafePrevUrl"
[nav]="false" [nav]="false"
[editMode]="editMotion" [editMode]="editMotion"
[isSaveButtonEnabled]="contentForm.valid" [isSaveButtonEnabled]="contentForm.valid"
@ -441,12 +440,11 @@
<!-- Ammendments --> <!-- Ammendments -->
<div *ngIf="!editMotion && amendments && amendments.length > 0"> <div *ngIf="!editMotion && amendments && amendments.length > 0">
<h4 translate>Amendments</h4> <h4 translate>Amendments</h4>
<a *ngIf="amendments.length === 1" [routerLink]="['/motions/amendments', motion.id]"> <a [routerLink]="['/motions/amendments', motion.id]">
{{ amendments.length }} <span translate>Amendment</span> {{ amendments.length }}
<span *ngIf="amendments.length === 1" translate>Amendment</span>
<span *ngIf="amendments.length > 1" translate>Amendments</span>
</a> </a>
<a *ngIf="amendments.length > 1" [routerLink]="['/motions/amendments', motion.id]">
{{ amendments.length }} <span translate>Amendments</span></a
>
</div> </div>
<!-- motion polls --> <!-- motion polls -->

View File

@ -447,7 +447,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit,
private itemRepo: ItemRepositoryService, private itemRepo: ItemRepositoryService,
private motionSortService: MotionSortListService, private motionSortService: MotionSortListService,
private motionFilterService: MotionFilterListService, private motionFilterService: MotionFilterListService,
public routingStateService: RoutingStateService private routingStateService: RoutingStateService
) { ) {
super(title, translate, matSnackBar); super(title, translate, matSnackBar);
} }
@ -1557,7 +1557,15 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit,
public getPrevUrl(): string { public getPrevUrl(): string {
if (this.motion && this.motion.parent_id) { if (this.motion && this.motion.parent_id) {
if (this.routingStateService.previousUrl && this.routingStateService.isSafePrevUrl) { if (this.routingStateService.previousUrl && this.routingStateService.isSafePrevUrl) {
if (
(this.previousMotion &&
this.routingStateService.previousUrl === this.previousMotion.getDetailStateURL()) ||
(this.nextMotion && this.routingStateService.previousUrl === this.nextMotion.getDetailStateURL())
) {
return '../..';
} else {
return this.routingStateService.previousUrl; return this.routingStateService.previousUrl;
}
} else { } else {
return this.motion.parent.getDetailStateURL(); return this.motion.parent.getDetailStateURL();
} }

View File

@ -26,26 +26,35 @@ export class AmendmentFilterListService extends MotionFilterListService {
/** /**
* Private accessor for an amendment id * Private accessor for an amendment id
*/ */
private _parentMotionId: number; public _parentMotionId: number;
/** /**
* set the storage key nae * 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 * publicly get an amendment id
*/ */
public set parentMotionId(id: number) { public set parentMotionId(id: number) {
this._parentMotionId = id; this._parentMotionId = id;
this.updateStorageKey();
} }
private motionFilterOptions: OsFilter = {
property: 'parent_id',
label: 'Motion',
options: []
};
public constructor( public constructor(
store: StorageService, store: StorageService,
OSStatus: OpenSlidesStatusService, 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 * @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[] { protected preFilter(motions: ViewMotion[]): ViewMotion[] {
return motions.filter(motion => { return motions.filter(motion => {
@ -96,6 +116,8 @@ export class AmendmentFilterListService extends MotionFilterListService {
* Currently, no filters for the amendment list, except the pre-filter * Currently, no filters for the amendment list, except the pre-filter
*/ */
protected getFilterDefinitions(): OsFilter[] { protected getFilterDefinitions(): OsFilter[] {
if (this.motionFilterOptions) {
return [this.motionFilterOptions].concat(super.getFilterDefinitions()); return [this.motionFilterOptions].concat(super.getFilterDefinitions());
} }
} }
}