2018-09-13 09:23:57 +02:00
|
|
|
import { Deserializer } from '../base/deserializer';
|
2018-08-23 10:35:05 +02:00
|
|
|
import { Workflow } from './workflow';
|
2018-07-12 14:11:31 +02:00
|
|
|
|
2018-11-04 11:11:48 +01:00
|
|
|
/**
|
|
|
|
* Specifies if an amendment of this state/recommendation should be merged into the motion
|
|
|
|
*/
|
|
|
|
export enum MergeAmendment {
|
|
|
|
NO = -1,
|
|
|
|
UNDEFINED = 0,
|
|
|
|
YES = 1
|
|
|
|
}
|
|
|
|
|
2018-07-12 14:11:31 +02:00
|
|
|
/**
|
|
|
|
* Representation of a workflow state
|
|
|
|
*
|
|
|
|
* Part of the 'states'-array in motion/workflow
|
|
|
|
* @ignore
|
|
|
|
*/
|
2018-09-10 11:15:12 +02:00
|
|
|
export class WorkflowState extends Deserializer {
|
2018-08-29 13:21:25 +02:00
|
|
|
public id: number;
|
|
|
|
public name: string;
|
|
|
|
public recommendation_label: string;
|
|
|
|
public css_class: string;
|
2019-02-07 16:36:33 +01:00
|
|
|
public access_level: number;
|
2018-08-29 13:21:25 +02:00
|
|
|
public allow_support: boolean;
|
|
|
|
public allow_create_poll: boolean;
|
|
|
|
public allow_submitter_edit: boolean;
|
|
|
|
public dont_set_identifier: boolean;
|
2019-01-21 16:34:19 +01:00
|
|
|
public show_state_extension_field: boolean;
|
2018-11-04 11:11:48 +01:00
|
|
|
public merge_amendment_into_final: MergeAmendment;
|
2018-08-29 13:21:25 +02:00
|
|
|
public show_recommendation_extension_field: boolean;
|
|
|
|
public next_states_id: number[];
|
|
|
|
public workflow_id: number;
|
2018-07-12 14:11:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Needs to be completely optional because Workflow has (yet) the optional parameter 'states'
|
2018-09-04 11:33:28 +02:00
|
|
|
* @param input If given, it will be deserialized
|
2018-07-12 14:11:31 +02:00
|
|
|
*/
|
2018-09-04 11:33:28 +02:00
|
|
|
public constructor(input?: any) {
|
2018-09-10 11:15:12 +02:00
|
|
|
super(input);
|
2018-07-12 14:11:31 +02:00
|
|
|
}
|
|
|
|
|
2018-08-23 10:35:05 +02:00
|
|
|
/**
|
|
|
|
* return a list of the next possible states.
|
|
|
|
* Also adds the current state.
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
public getNextStates(workflow: Workflow): WorkflowState[] {
|
2019-02-08 09:48:58 +01:00
|
|
|
return workflow.states.filter(state => {
|
|
|
|
return this.next_states_id.includes(state.id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public getPreviousStates(workflow: Workflow): WorkflowState[] {
|
|
|
|
return workflow.states.filter(state => {
|
|
|
|
return state.next_states_id.includes(this.id);
|
2018-08-23 10:35:05 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-16 17:03:39 +02:00
|
|
|
public toString = (): string => {
|
|
|
|
return this.name;
|
|
|
|
};
|
2018-10-22 16:44:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a workflowstate has no 'next state' left, and is final
|
|
|
|
*/
|
|
|
|
public get isFinalState(): boolean {
|
2019-01-10 12:54:48 +01:00
|
|
|
if (!this.next_states_id || !this.next_states_id.length) {
|
2018-10-22 16:44:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (this.next_states_id.length === 1 && this.next_states_id[0] === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-12 14:11:31 +02:00
|
|
|
}
|