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 @@

Voting

--> - diff --git a/client/src/app/site/motions/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/motion-detail/motion-detail.component.ts index 08eefd9cb..3c35971cc 100644 --- a/client/src/app/site/motions/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/motion-detail/motion-detail.component.ts @@ -27,16 +27,12 @@ export class MotionDetailComponent extends BaseComponent implements OnInit { this.route.params.subscribe(params => { // has the motion of the DataStore was initialized before. this.motion = this.DS.get(Motion, params.id) as Motion; - if (this.motion) { - this.patchForm(); - } // Observe motion to get the motion in the parameter and also get the changes this.DS.getObservable().subscribe(newModel => { if (newModel instanceof Motion) { if (newModel.id === +params.id) { this.motion = newModel as Motion; - this.patchForm(); } } }); @@ -68,12 +64,16 @@ export class MotionDetailComponent extends BaseComponent implements OnInit { editMotionButton() { this.editMotion ? (this.editMotion = false) : (this.editMotion = true); + if (this.editMotion) { + // switch to edit mode + this.patchForm(); this.metaInfoPanel.open(); this.contentPanel.open(); + } else { + // save button + this.saveMotion(); } - - // console.log('this.motion.possible_states: ', this.motion.possible_states); } ngOnInit() { diff --git a/client/src/app/site/motions/motion-list/motion-list.component.html b/client/src/app/site/motions/motion-list/motion-list.component.html index 3c0a34dda..5bde0f84c 100644 --- a/client/src/app/site/motions/motion-list/motion-list.component.html +++ b/client/src/app/site/motions/motion-list/motion-list.component.html @@ -53,7 +53,7 @@ State -
+
diff --git a/client/src/app/site/start/start.component.ts b/client/src/app/site/start/start.component.ts index fcf6abb50..cc4db77d3 100644 --- a/client/src/app/site/start/start.component.ts +++ b/client/src/app/site/start/start.component.ts @@ -64,7 +64,6 @@ export class StartComponent extends BaseComponent implements OnInit { if (welcomeTextConfig) { this.welcomeText = welcomeTextConfig.value as string; } - console.log(this.DS.filter(Config, config => config.key === 'general_event_welcome_title')); // observe title and text in DS this.DS.getObservable().subscribe(newModel => {