Merge pull request #4226 from MaximilianKrambach/workflowfilter
only show motion workflow filter for config-enabled workflows
This commit is contained in:
commit
9136b53d48
@ -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 => {
|
||||||
const workflowOptions: (OsFilterOption | string)[] = [];
|
this.currentWorkflows = workflows;
|
||||||
const finalStates: number[] = [];
|
this.updateWorkflows();
|
||||||
const nonFinalStates: number[] = [];
|
});
|
||||||
const recommendationOptions: (OsFilterOption | string)[] = [];
|
this.config.get<string>('motions_statute_amendments_workflow').subscribe(id => {
|
||||||
workflows.forEach(workflow => {
|
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);
|
workflowOptions.push(workflow.name);
|
||||||
recommendationOptions.push(workflow.name);
|
recommendationOptions.push(workflow.name);
|
||||||
workflow.states.forEach(state => {
|
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