2018-08-16 17:03:39 +02:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
2018-08-09 16:03:24 +02:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
import { BaseComponent } from '../../../base.component';
|
|
|
|
import { Motion } from '../../../shared/models/motions/motion';
|
2018-08-16 17:03:39 +02:00
|
|
|
import { Category } from '../../../shared/models/motions/category';
|
|
|
|
import { FormGroup, FormBuilder } from '@angular/forms';
|
|
|
|
import { MatExpansionPanel } from '@angular/material';
|
2018-08-09 16:03:24 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-motion-detail',
|
|
|
|
templateUrl: './motion-detail.component.html',
|
|
|
|
styleUrls: ['./motion-detail.component.scss']
|
|
|
|
})
|
|
|
|
export class MotionDetailComponent extends BaseComponent implements OnInit {
|
2018-08-16 17:03:39 +02:00
|
|
|
@ViewChild('metaInfoPanel') metaInfoPanel: MatExpansionPanel;
|
|
|
|
@ViewChild('contentPanel') contentPanel: MatExpansionPanel;
|
|
|
|
|
2018-08-09 16:03:24 +02:00
|
|
|
motion: Motion;
|
2018-08-16 17:03:39 +02:00
|
|
|
metaInfoForm: FormGroup;
|
|
|
|
editMotion = false;
|
|
|
|
|
|
|
|
// categoryFormControl: FormControl;
|
2018-08-09 16:03:24 +02:00
|
|
|
|
2018-08-16 17:03:39 +02:00
|
|
|
constructor(private route: ActivatedRoute, private formBuilder: FormBuilder) {
|
2018-08-09 16:03:24 +02:00
|
|
|
super();
|
2018-08-16 17:03:39 +02:00
|
|
|
this.createForm();
|
2018-08-09 16:03:24 +02:00
|
|
|
this.route.params.subscribe(params => {
|
|
|
|
// has the motion of the DataStore was initialized before.
|
|
|
|
this.motion = this.DS.get(Motion, params.id) as Motion;
|
2018-08-16 17:03:39 +02:00
|
|
|
if (this.motion) {
|
|
|
|
this.patchForm();
|
|
|
|
}
|
2018-08-09 16:03:24 +02:00
|
|
|
|
|
|
|
// 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;
|
2018-08-16 17:03:39 +02:00
|
|
|
this.patchForm();
|
2018-08-09 16:03:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-16 17:03:39 +02:00
|
|
|
/** Parches the Form with content from the dataStore */
|
|
|
|
patchForm() {
|
|
|
|
this.metaInfoForm.patchValue({ categoryFormControl: this.motion.category });
|
|
|
|
this.metaInfoForm.patchValue({ state: this.motion.state });
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Create the whole Form with empty or default values */
|
|
|
|
createForm() {
|
|
|
|
this.metaInfoForm = this.formBuilder.group({
|
|
|
|
categoryFormControl: [''],
|
|
|
|
state: ['']
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
saveMotion() {
|
|
|
|
console.log('Save motion: ', this.metaInfoForm.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
getMotionCategories(): Category[] {
|
|
|
|
const categories = this.DS.get(Category);
|
|
|
|
return categories as Category[];
|
|
|
|
}
|
|
|
|
|
|
|
|
editMotionButton() {
|
|
|
|
this.editMotion ? (this.editMotion = false) : (this.editMotion = true);
|
|
|
|
if (this.editMotion) {
|
|
|
|
this.metaInfoPanel.open();
|
|
|
|
this.contentPanel.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
// console.log('this.motion.possible_states: ', this.motion.possible_states);
|
|
|
|
}
|
|
|
|
|
2018-08-09 16:03:24 +02:00
|
|
|
ngOnInit() {
|
|
|
|
console.log('(init)the motion: ', this.motion);
|
2018-08-16 17:03:39 +02:00
|
|
|
console.log('motion state name: ', this.motion.state);
|
2018-08-09 16:03:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
downloadSingleMotionButton() {
|
|
|
|
console.log('Download this motion');
|
|
|
|
}
|
|
|
|
}
|