Motion Workflow observing

This commit is contained in:
Sean Engelhardt 2018-08-20 12:28:43 +02:00 committed by sean
parent f1da2689b9
commit d26d131fa6
5 changed files with 46 additions and 48 deletions

View File

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

View File

@ -113,7 +113,6 @@
<h3 translate>Voting</h3>
</div> -->
</form>
<!-- </div> -->
</mat-expansion-panel>
<!-- Personal Note -->

View File

@ -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() {

View File

@ -53,7 +53,7 @@
<ng-container matColumnDef="state">
<mat-header-cell *matHeaderCellDef mat-sort-header> State </mat-header-cell>
<mat-cell *matCellDef="let motion">
<div *ngIf='motion.state.name !== "submitted"' class='innerTable'>
<div *ngIf='motion.state && motion.state.name !== "submitted"' class='innerTable'>
<fa-icon icon={{getStateIcon(motion.state)}}></fa-icon>
</div>
</mat-cell>

View File

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