only show motion workflow filter for config-enabled workflows
This commit is contained in:
parent
eb21ae0136
commit
271d8cbfa4
@ -10,6 +10,8 @@ import { MotionRepositoryService } from './motion-repository.service';
|
||||
import { MotionBlockRepositoryService } from './motion-block-repository.service';
|
||||
import { MotionCommentSectionRepositoryService } from './motion-comment-section-repository.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { ConfigService } from 'app/core/services/config.service';
|
||||
import { ViewWorkflow } from '../models/view-workflow';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -41,6 +43,16 @@ export class MotionFilterListService extends FilterListService<Motion, ViewMotio
|
||||
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
|
||||
* 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 commentRepo subycribing filter by presense of comment
|
||||
* @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
|
||||
*/
|
||||
public constructor(
|
||||
@ -120,6 +133,7 @@ export class MotionFilterListService extends FilterListService<Motion, ViewMotio
|
||||
private motionBlockRepo: MotionBlockRepositoryService,
|
||||
private commentRepo: MotionCommentSectionRepositoryService,
|
||||
private translate: TranslateService,
|
||||
private config: ConfigService,
|
||||
motionRepo: MotionRepositoryService
|
||||
) {
|
||||
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
|
||||
* Only subscribes to workflows that are enabled in the config as motion or statute paragraph workflow
|
||||
*/
|
||||
private subscribeWorkflows(): void {
|
||||
this.workflowRepo.getViewModelListObservable().subscribe(workflows => {
|
||||
const workflowOptions: (OsFilterOption | string)[] = [];
|
||||
const finalStates: number[] = [];
|
||||
const nonFinalStates: number[] = [];
|
||||
const recommendationOptions: (OsFilterOption | string)[] = [];
|
||||
workflows.forEach(workflow => {
|
||||
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 finalStates: number[] = [];
|
||||
const nonFinalStates: number[] = [];
|
||||
const recommendationOptions: (OsFilterOption | string)[] = [];
|
||||
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);
|
||||
recommendationOptions.push(workflow.name);
|
||||
workflow.states.forEach(state => {
|
||||
@ -222,29 +266,29 @@ export class MotionFilterListService extends FilterListService<Motion, ViewMotio
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
if (workflowOptions.length) {
|
||||
workflowOptions.push('-');
|
||||
workflowOptions.push({
|
||||
label: 'Done',
|
||||
condition: finalStates
|
||||
});
|
||||
workflowOptions.push({
|
||||
label: 'Undone',
|
||||
condition: nonFinalStates
|
||||
});
|
||||
}
|
||||
if (recommendationOptions.length) {
|
||||
recommendationOptions.push('-');
|
||||
recommendationOptions.push({
|
||||
label: 'No recommendation',
|
||||
condition: null
|
||||
});
|
||||
}
|
||||
this.flowFilterOptions.options = workflowOptions;
|
||||
this.recommendationFilterOptions.options = recommendationOptions;
|
||||
this.updateFilterDefinitions(this.filterOptions);
|
||||
});
|
||||
if (workflowOptions.length) {
|
||||
workflowOptions.push('-');
|
||||
workflowOptions.push({
|
||||
label: 'Done',
|
||||
condition: finalStates
|
||||
});
|
||||
workflowOptions.push({
|
||||
label: 'Undone',
|
||||
condition: nonFinalStates
|
||||
});
|
||||
}
|
||||
if (recommendationOptions.length) {
|
||||
recommendationOptions.push('-');
|
||||
recommendationOptions.push({
|
||||
label: 'No recommendation',
|
||||
condition: null
|
||||
});
|
||||
}
|
||||
this.flowFilterOptions.options = workflowOptions;
|
||||
this.recommendationFilterOptions.options = recommendationOptions;
|
||||
this.updateFilterDefinitions(this.filterOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user