Merge pull request #4226 from MaximilianKrambach/workflowfilter

only show motion workflow filter for config-enabled workflows
This commit is contained in:
Sean 2019-01-31 12:19:31 +01:00 committed by GitHub
commit 9136b53d48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,8 @@ import { MotionRepositoryService } from './motion-repository.service';
import { MotionBlockRepositoryService } from './motion-block-repository.service'; import { MotionBlockRepositoryService } from './motion-block-repository.service';
import { MotionCommentSectionRepositoryService } from './motion-comment-section-repository.service'; import { MotionCommentSectionRepositoryService } from './motion-comment-section-repository.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ConfigService } from 'app/core/services/config.service';
import { ViewWorkflow } from '../models/view-workflow';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -41,6 +43,16 @@ export class MotionFilterListService extends FilterListService<Motion, ViewMotio
options: [] options: []
}; };
/**
* Listen to the configuration for change in defined/used workflows
*/
private enabledWorkflows = { statuteEnabled: false, statute: null, motion: null };
/**
* storage for currently used workflows
*/
private currentWorkflows: ViewWorkflow[];
/** /**
* Filter definitions for the category filter. Options will be generated by * Filter definitions for the category filter. Options will be generated by
* getFilterOptions (as the categories available may change) * getFilterOptions (as the categories available may change)
@ -111,6 +123,7 @@ export class MotionFilterListService extends FilterListService<Motion, ViewMotio
* @param motionBlockRepo Subscribing to filters by MotionBlock * @param motionBlockRepo Subscribing to filters by MotionBlock
* @param commentRepo subycribing filter by presense of comment * @param commentRepo subycribing filter by presense of comment
* @param translate Translation service * @param translate Translation service
* @param config the current configuration (to determine which workflow filters to offer )
* @param motionRepo the motion's own repository, required by the parent * @param motionRepo the motion's own repository, required by the parent
*/ */
public constructor( public constructor(
@ -120,6 +133,7 @@ export class MotionFilterListService extends FilterListService<Motion, ViewMotio
private motionBlockRepo: MotionBlockRepositoryService, private motionBlockRepo: MotionBlockRepositoryService,
private commentRepo: MotionCommentSectionRepositoryService, private commentRepo: MotionCommentSectionRepositoryService,
private translate: TranslateService, private translate: TranslateService,
private config: ConfigService,
motionRepo: MotionRepositoryService motionRepo: MotionRepositoryService
) { ) {
super(store, motionRepo); super(store, motionRepo);
@ -193,14 +207,44 @@ export class MotionFilterListService extends FilterListService<Motion, ViewMotio
/** /**
* Subscibes to changing Workflows, and updates the state and recommendation filters accordingly * Subscibes to changing Workflows, and updates the state and recommendation filters accordingly
* Only subscribes to workflows that are enabled in the config as motion or statute paragraph workflow
*/ */
private subscribeWorkflows(): void { private subscribeWorkflows(): void {
this.workflowRepo.getViewModelListObservable().subscribe(workflows => { this.workflowRepo.getViewModelListObservable().subscribe(workflows => {
this.currentWorkflows = workflows;
this.updateWorkflows();
});
this.config.get<string>('motions_statute_amendments_workflow').subscribe(id => {
this.enabledWorkflows.statute = +id;
this.updateWorkflows();
});
this.config.get<string>('motions_workflow').subscribe(id => {
this.enabledWorkflows.motion = +id;
this.updateWorkflows();
});
this.config.get<boolean>('motions_statutes_enabled').subscribe(bool => {
this.enabledWorkflows.statuteEnabled = bool;
this.updateWorkflows();
});
}
/**
* Helper to show only filter for workflows that are included in to currently
* set config options
*/
private updateWorkflows(): void {
const workflowOptions: (OsFilterOption | string)[] = []; const workflowOptions: (OsFilterOption | string)[] = [];
const finalStates: number[] = []; const finalStates: number[] = [];
const nonFinalStates: number[] = []; const nonFinalStates: number[] = [];
const recommendationOptions: (OsFilterOption | string)[] = []; const recommendationOptions: (OsFilterOption | string)[] = [];
workflows.forEach(workflow => { if (!this.currentWorkflows) {
return;
}
this.currentWorkflows.forEach(workflow => {
if (
workflow.id === this.enabledWorkflows.motion ||
(this.enabledWorkflows.statuteEnabled && workflow.id === this.enabledWorkflows.statute)
) {
workflowOptions.push(workflow.name); workflowOptions.push(workflow.name);
recommendationOptions.push(workflow.name); recommendationOptions.push(workflow.name);
workflow.states.forEach(state => { workflow.states.forEach(state => {
@ -222,6 +266,7 @@ export class MotionFilterListService extends FilterListService<Motion, ViewMotio
}); });
} }
}); });
}
}); });
if (workflowOptions.length) { if (workflowOptions.length) {
workflowOptions.push('-'); workflowOptions.push('-');
@ -244,7 +289,6 @@ export class MotionFilterListService extends FilterListService<Motion, ViewMotio
this.flowFilterOptions.options = workflowOptions; this.flowFilterOptions.options = workflowOptions;
this.recommendationFilterOptions.options = recommendationOptions; this.recommendationFilterOptions.options = recommendationOptions;
this.updateFilterDefinitions(this.filterOptions); this.updateFilterDefinitions(this.filterOptions);
});
} }
/** /**