argos/dmp-admin/src/app/formBuilder/form.component.ts

53 lines
1.5 KiB
TypeScript
Raw Normal View History

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';
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;
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();
//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());
}
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
}