2017-12-20 17:46:52 +01:00
|
|
|
|
import { Component, OnInit, Input, ViewEncapsulation } from '@angular/core';
|
2018-01-19 10:31:05 +01:00
|
|
|
|
import { FormGroup } from '@angular/forms';
|
2017-12-20 17:46:52 +01:00
|
|
|
|
import { Section } from 'app/models/DataSetProfile/Section';
|
|
|
|
|
import { FieldGroup } from 'app/models/DataSetProfile/FieldGroup';
|
2017-11-27 14:35:00 +01:00
|
|
|
|
import { FormArray } from '@angular/forms/src/model';
|
2017-12-20 17:46:52 +01:00
|
|
|
|
import { DatasetProfileModel } from 'app/models/DataSetProfile/DatasetProfileModel';
|
2018-01-02 17:29:27 +01:00
|
|
|
|
import { FieldSet } from 'app/models/DataSetProfile/FieldSet';
|
2017-12-20 17:46:52 +01:00
|
|
|
|
import { Field } from 'app/models/DataSetProfile/Field';
|
|
|
|
|
import { Page } from 'app/models/DataSetProfile/Page';
|
|
|
|
|
import { JsonSerializer } from 'app/utilities/JsonSerializer';
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'section-form',
|
|
|
|
|
templateUrl: './section-form.component.html',
|
2017-12-07 14:57:20 +01:00
|
|
|
|
styleUrls: ['./section-form.component.css'],
|
|
|
|
|
encapsulation: ViewEncapsulation.None
|
2017-11-27 14:35:00 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export class SectionFormComponent {
|
|
|
|
|
@Input() form: FormGroup;
|
2017-12-07 14:57:20 +01:00
|
|
|
|
@Input() dataModel: Section;
|
|
|
|
|
@Input() indexPath: string;
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
2017-12-07 14:57:20 +01:00
|
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-01-19 10:31:05 +01:00
|
|
|
|
var self = this;
|
|
|
|
|
this.form.root.get("pages").valueChanges.subscribe(function (value) {
|
|
|
|
|
self.keepPageSelectionValid(value);
|
|
|
|
|
});
|
2017-11-27 14:35:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-03 16:19:52 +01:00
|
|
|
|
addField() {
|
2018-01-02 17:29:27 +01:00
|
|
|
|
let fieldSet: FieldSet = new FieldSet();
|
2017-12-08 15:58:23 +01:00
|
|
|
|
let field: Field = new Field();
|
|
|
|
|
fieldSet.fields.push(field);
|
2018-01-02 17:29:27 +01:00
|
|
|
|
if (this.dataModel.fieldSets)
|
|
|
|
|
this.dataModel.fieldSets.push(fieldSet);
|
|
|
|
|
(<FormArray>this.form.get("fieldSets")).push(fieldSet.buildForm());
|
2017-12-08 15:58:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-07 14:57:20 +01:00
|
|
|
|
addSectioninSection() {
|
|
|
|
|
let section: Section = new Section();
|
2017-12-01 17:33:37 +01:00
|
|
|
|
this.dataModel.sections.push(section);
|
|
|
|
|
(<FormArray>this.form.get("sections")).push(section.buildForm());
|
|
|
|
|
}
|
2017-12-05 12:02:03 +01:00
|
|
|
|
|
2017-12-07 14:57:20 +01:00
|
|
|
|
DeleteSectionInSection(index) {
|
2017-12-05 12:02:03 +01:00
|
|
|
|
this.dataModel.sections.splice(index);
|
|
|
|
|
(<FormArray>this.form.get("sections")).removeAt(index);
|
|
|
|
|
}
|
2017-12-07 14:57:20 +01:00
|
|
|
|
|
2018-01-19 10:31:05 +01:00
|
|
|
|
DeleteFieldSet(index) {
|
2018-01-02 17:29:27 +01:00
|
|
|
|
this.dataModel.fieldSets.splice(index, 1);
|
2018-01-12 17:57:01 +01:00
|
|
|
|
(<FormArray>this.form.get("fieldSets")).removeAt(index);
|
2018-01-02 17:29:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:46:52 +01:00
|
|
|
|
keepPageSelectionValid(pagesJson: Array<any>) {
|
2018-01-19 10:31:05 +01:00
|
|
|
|
let selectedPage = this.form.get("page").value as String;
|
2018-02-01 15:04:36 +01:00
|
|
|
|
let pages: Array<Page> = JsonSerializer.fromJSONArray(pagesJson, Page);
|
2018-01-19 10:31:05 +01:00
|
|
|
|
if (pages.find(elem => elem.id === selectedPage) === undefined)
|
|
|
|
|
this.form.get("page").reset();
|
2017-12-20 17:46:52 +01:00
|
|
|
|
}
|
2017-11-27 14:35:00 +01:00
|
|
|
|
}
|