diff --git a/client/src/app/shared/models/motions/motion.ts b/client/src/app/shared/models/motions/motion.ts index ef639c476..b6d443805 100644 --- a/client/src/app/shared/models/motions/motion.ts +++ b/client/src/app/shared/models/motions/motion.ts @@ -37,6 +37,11 @@ export class Motion extends BaseModel { agenda_item_id: number; log_messages: MotionLog[]; + // read from config + workflow_id: number; + // by the config above + workflow: Workflow; + constructor( id?: number, identifier?: string, @@ -79,6 +84,33 @@ export class Motion extends BaseModel { this.polls = polls; this.agenda_item_id = agenda_item_id; this.log_messages = log_messages; + + this.initDataStoreValues(); + } + + /** + * sets the workflow_id and the workflow + */ + initDataStoreValues() { + const motionsWorkflowConfig = this.DS.filter(Config, config => config.key === 'motions_workflow')[0] as Config; + if (motionsWorkflowConfig) { + this.workflow_id = +motionsWorkflowConfig.value; + } else { + this.DS.getObservable().subscribe(newConfig => { + if (newConfig instanceof Config && newConfig.key === 'motions_workflow') { + this.workflow_id = +newConfig.value; + } + }); + } + + this.workflow = this.DS.get(Workflow, this.workflow_id) as Workflow; + if (!this.workflow.id) { + this.DS.getObservable().subscribe(newModel => { + if (newModel instanceof Workflow && newModel.id === this.workflow_id) { + this.workflow = newModel; + } + }); + } } /** @@ -149,30 +181,18 @@ export class Motion extends BaseModel { this.category_id = newCategory.id; } - /** - * Returns the workflow - * - * TODO this is the default workflow, not yet the coresponding for the motion - */ - get workflow(): Workflow { - const motionsWorkflowConfig = this.DS.filter(Config, config => config.key === 'motions_workflow')[0] as Config; - //make sure this is a number - const workflowId = +motionsWorkflowConfig.value; - //get the workflow for our motion - const selectedWorkflow = this.DS.get(Workflow, workflowId) as Workflow; - return selectedWorkflow; - } - /** * return the workflow state * - * Right now only the default workflow is assumed - * TODO: Motion workflow needs to be specific on the server + * set the workflow via a component */ get state() { - const workflow = this.workflow; - const state = workflow.state_by_id(this.state_id); - return state; + if (this.workflow && this.workflow.id) { + const state = this.workflow.state_by_id(this.state_id); + return state; + } else { + return null; + } } /** @@ -182,25 +202,6 @@ export class Motion extends BaseModel { return this.workflow.states; } - /** - * Returns possible "initial" states for a motion. - * - * Will filter "submitted" - */ - // get initial_states(): WorkflowState[] { - // const states = this.workflow.states; - - // //find index of 'submitted' - // const submitted = states.findIndex(state => state.name === 'submitted'); - - // //if found a valid index, remove "submitted" from array - // if (typeof submitted === 'number' && submitted >= 0) { - // states.splice(submitted, 1); - // } - - // return states; - // } - /** * Returns the name of the recommendation. * @@ -208,7 +209,6 @@ export class Motion extends BaseModel { * TODO: Motion workflow needs to be specific on the server */ get recommendation() { - // const stateName = this.workflow.getStateNameById(this.recommendation_id); const state = this.workflow.state_by_id(this.recommendation_id); if (state) { return state.recommendation_label; diff --git a/client/src/app/site/motions/motion-detail/motion-detail.component.html b/client/src/app/site/motions/motion-detail/motion-detail.component.html index 9ba5c33b7..8cf439405 100644 --- a/client/src/app/site/motions/motion-detail/motion-detail.component.html +++ b/client/src/app/site/motions/motion-detail/motion-detail.component.html @@ -113,7 +113,6 @@