72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { DatasetProfileService } from '../services/dataset-profile.service';
|
|
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';
|
|
import { Router, ActivatedRoute, ParamMap, Params } from '@angular/router';
|
|
|
|
@Component({
|
|
selector: 'form-comp',
|
|
templateUrl: './form.component.html',
|
|
styleUrls: []
|
|
})
|
|
|
|
export class FormComponent {
|
|
|
|
dataModel: DatasetProfileModel;
|
|
form: FormGroup;
|
|
private profileID: string;
|
|
|
|
constructor(public restBase: RestBase, private datasetProfileService: DatasetProfileService, private route: ActivatedRoute) {
|
|
this.profileID = route.snapshot.params['id'];
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.dataModel = new JsonSerializer<DatasetProfileModel>().fromJSONObject(new DatasetProfileModel(), DatasetProfileModel);
|
|
this.form = this.dataModel.buildForm();
|
|
if (this.profileID) {
|
|
this.datasetProfileService.getDatasetProfileById(this.profileID).subscribe((data) => {
|
|
|
|
this.dataModel = new JsonSerializer<DatasetProfileModel>().fromJSONObject(data, DatasetProfileModel);
|
|
this.form = this.dataModel.buildForm();
|
|
});
|
|
}
|
|
else{
|
|
|
|
this.addSection();
|
|
}
|
|
|
|
// this.dataModel = new JsonSerializer<DatasetProfileModel>().fromJSONObject(TestModel, DatasetProfileModel);
|
|
// this.form = this.dataModel.buildForm();
|
|
}
|
|
|
|
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("/admin/addDmp", data);
|
|
}
|
|
|
|
onSubmit() {
|
|
debugger;
|
|
let data = this.form.value;
|
|
this.updateForm(data).subscribe();
|
|
}
|
|
|
|
} |