2017-11-27 14:35:00 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { FormGroup } from '@angular/forms';
|
|
|
|
import { JsonSerializer } from '../utilities/JsonSerializer';
|
|
|
|
import { SectionFormComponent } from '../section-form/section-form.component';
|
|
|
|
import { Section } from '../models/Section';
|
|
|
|
import { FieldGroup } from '../models/FieldGroup';
|
|
|
|
import { DatasetProfileModel } from '../models/DatasetProfileModel';
|
|
|
|
import { TestModel } from '../testModel/testModel';
|
|
|
|
import { FormArray } from '@angular/forms/src/model';
|
2017-11-29 17:51:28 +01:00
|
|
|
import {RestBase} from '../services/rest-base';
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'form-comp',
|
|
|
|
templateUrl: './form.component.html',
|
|
|
|
styleUrls: []
|
|
|
|
})
|
|
|
|
|
|
|
|
export class FormComponent {
|
|
|
|
|
|
|
|
dataModel: DatasetProfileModel ;
|
|
|
|
form: FormGroup;
|
|
|
|
|
2017-11-29 17:51:28 +01:00
|
|
|
constructor(public restBase: RestBase){
|
2017-11-27 14:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(){
|
|
|
|
this.dataModel = new DatasetProfileModel();
|
|
|
|
this.dataModel = new JsonSerializer<DatasetProfileModel>().fromJSONObject(TestModel,DatasetProfileModel);
|
|
|
|
this.form = this.dataModel.buildForm();
|
2017-11-29 17:51:28 +01:00
|
|
|
//if (!this.dataModel) this.addSection();
|
2017-11-27 14:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
addSection(){
|
|
|
|
let section:Section = new Section();
|
|
|
|
this.dataModel.sections.push(section);
|
|
|
|
(<FormArray>this.form.get("sections")).push(section.buildForm());
|
|
|
|
}
|
2017-11-29 17:51:28 +01:00
|
|
|
|
|
|
|
DeleteSection(index){
|
|
|
|
this.dataModel.sections.splice(index);
|
|
|
|
(<FormArray>this.form.get("sections")).removeAt(index)
|
|
|
|
}
|
|
|
|
|
|
|
|
updateForm(data){
|
|
|
|
return this.restBase.post("", data);
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit(){ debugger;
|
|
|
|
let data = JSON.stringify(this.form.value);
|
|
|
|
this.updateForm(data).subscribe();
|
|
|
|
}
|
2017-11-27 14:35:00 +01:00
|
|
|
|
|
|
|
}
|