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);
}
if (!!storedFilter) {
if (storedFilter && storedFilter.length && newDefinitions && newDefinitions.length) {
for (const newDef of newDefinitions) {
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) {
@ -265,6 +269,7 @@ export abstract class BaseFilterListService<V extends BaseViewModel> {
newDef.count = count;
}
}
}
this.filterDefinitions = newDefinitions;
this.storeActiveFilters();

View File

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

View File

@ -30,7 +30,11 @@ import { ViewMotion } from '../../models/view-motion';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AmendmentListComponent extends BaseListViewComponent<ViewMotion> 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<ViewMotion> 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<ViewMotion> im
});
if (!!this.parentMotionId) {
this.amendmentFilterService.clearAllFilters();
this.amendmentFilterService.parentMotionId = this.parentMotionId;
} else {
this.amendmentFilterService.parentMotionId = 0;
// this.amendmentFilterService.clearAllFilters();
}
}

View File

@ -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 @@
<!-- Ammendments -->
<div *ngIf="!editMotion && amendments && amendments.length > 0">
<h4 translate>Amendments</h4>
<a *ngIf="amendments.length === 1" [routerLink]="['/motions/amendments', motion.id]">
{{ amendments.length }} <span translate>Amendment</span>
<a [routerLink]="['/motions/amendments', motion.id]">
{{ amendments.length }}
<span *ngIf="amendments.length === 1" translate>Amendment</span>
<span *ngIf="amendments.length > 1" translate>Amendments</span>
</a>
<a *ngIf="amendments.length > 1" [routerLink]="['/motions/amendments', motion.id]">
{{ amendments.length }} <span translate>Amendments</span></a
>
</div>
<!-- motion polls -->

View File

@ -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) {
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();
}

View File

@ -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[] {
if (this.motionFilterOptions) {
return [this.motionFilterOptions].concat(super.getFilterDefinitions());
}
}
}