Merge pull request #4926 from tsiegleauq/hide-amendments-from-motion-list

Add option to hide amendments
This commit is contained in:
Emanuel Schütze 2019-08-20 12:00:25 +02:00 committed by GitHub
commit 14d7269959
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 16 deletions

View File

@ -338,23 +338,27 @@ export class ListViewTableComponent<V extends BaseViewModel, M extends BaseModel
// custom filter predicates // custom filter predicates
if (this.filterProps && this.filterProps.length) { if (this.filterProps && this.filterProps.length) {
for (const prop of this.filterProps) { for (const prop of this.filterProps) {
let propertyAsString = ''; if (item[prop]) {
// If the property is a function, call it. let propertyAsString = '';
if (typeof item[prop] === 'function') { // If the property is a function, call it.
propertyAsString = '' + item[prop](); if (typeof item[prop] === 'function') {
} else { propertyAsString = '' + item[prop]();
propertyAsString = '' + item[prop]; } else if (item[prop].constructor === Array) {
} propertyAsString = item[prop].join('');
} else {
propertyAsString = '' + item[prop];
}
if (!!propertyAsString) { if (!!propertyAsString) {
const foundProp = const foundProp =
propertyAsString propertyAsString
.trim() .trim()
.toLowerCase() .toLowerCase()
.indexOf(trimmedInput) !== -1; .indexOf(trimmedInput) !== -1;
if (foundProp) { if (foundProp) {
return true; return true;
}
} }
} }
} }

View File

@ -62,7 +62,7 @@ export class AmendmentListComponent extends BaseListViewComponent<ViewMotion> im
/** /**
* To filter stuff * To filter stuff
*/ */
public filterProps = ['submitters', 'title', 'identifier']; public filterProps = ['submitters', 'title', 'identifier', 'amendment_paragraphs'];
/** /**
* *

View File

@ -39,6 +39,11 @@ export class MotionFilterListService extends BaseFilterListService<ViewMotion> {
*/ */
private enabledWorkflows = { statuteEnabled: false, statute: null, motion: null }; private enabledWorkflows = { statuteEnabled: false, statute: null, motion: null };
/**
* Determine to show amendments in the motion list
*/
private showAmendmentsInMainTable: boolean;
/** /**
* Filter definitions for the workflow filter. Options will be generated by * Filter definitions for the workflow filter. Options will be generated by
* getFilterOptions (as the workflows available may change) * getFilterOptions (as the workflows available may change)
@ -136,6 +141,7 @@ export class MotionFilterListService extends BaseFilterListService<ViewMotion> {
) { ) {
super(store, OSStatus); super(store, OSStatus);
this.getWorkflowConfig(); this.getWorkflowConfig();
this.getShowAmendmentConfig();
this.updateFilterForRepo(categoryRepo, this.categoryFilterOptions, this.translate.instant('No category set')); this.updateFilterForRepo(categoryRepo, this.categoryFilterOptions, this.translate.instant('No category set'));
@ -155,6 +161,25 @@ export class MotionFilterListService extends BaseFilterListService<ViewMotion> {
}); });
} }
/**
* @override
* @param motions The motions without amendments, if the according config was set
*/
protected preFilter(motions: ViewMotion[]): ViewMotion[] {
if (!this.showAmendmentsInMainTable) {
return motions.filter(motion => !motion.parent_id);
}
}
/**
* Listen to changes for the 'motions_amendments_main_table' config value
*/
private getShowAmendmentConfig(): void {
this.config.get<boolean>('motions_amendments_main_table').subscribe(show => {
this.showAmendmentsInMainTable = show;
});
}
private getWorkflowConfig(): void { private getWorkflowConfig(): void {
this.config.get<string>('motions_statute_amendments_workflow').subscribe(id => { this.config.get<string>('motions_statute_amendments_workflow').subscribe(id => {
this.enabledWorkflows.statute = +id; this.enabledWorkflows.statute = +id;