argos/dmp-admin/src/app/dataset-profile-form/field-form/field-form.component.ts

49 lines
1.6 KiB
TypeScript
Raw Normal View History

import { Component, Input } from '@angular/core';
2017-12-07 14:57:20 +01:00
import { FormGroup, FormControl } from '@angular/forms';
import { Field } from 'app/models/DataSetProfile/Field';
import { Rule } from 'app/models/DataSetProfile/Rule';
import { Multiplicity } from 'app/models/DataSetProfile/Multiplicity';
2017-11-27 14:35:00 +01:00
import { FormArray } from '@angular/forms/src/model';
import { ComboboxComponent } from 'app/combobox/combobox-component';
2017-11-27 14:35:00 +01:00
@Component({
selector: 'field-form',
templateUrl: './field-form.component.html',
styleUrls: []
})
export class FieldFormComponent {
2017-12-07 14:57:20 +01:00
@Input() form: FormGroup;
@Input() dataModel: Field;
@Input() showMultiplicity: boolean = true;
@Input() indexPath: string;
isFieldMultiplicityEnabled: boolean = false;
2017-11-27 14:35:00 +01:00
2017-12-07 14:57:20 +01:00
constructon() { }
2017-11-27 14:35:00 +01:00
2017-12-07 14:57:20 +01:00
ngOnInit() {
2017-12-13 13:57:19 +01:00
if(this.form.get("multiplicity"))
if (this.form.get("multiplicity").value.min >1 || this.form.get("multiplicity").value.max >1)
this.isFieldMultiplicityEnabled = true;
2017-12-07 14:57:20 +01:00
// this.addNewRule();
}
2017-11-27 14:35:00 +01:00
2017-12-07 14:57:20 +01:00
onIsFieldMultiplicityEnabledChange(isFieldMultiplicityEnabled: boolean) {
if (!isFieldMultiplicityEnabled) {
(<FormControl>this.form.get('multiplicity').get("min")).setValue(0);
(<FormControl>this.form.get('multiplicity').get("max")).setValue(0);
}
}
2017-12-07 14:57:20 +01:00
addNewRule() {
let rule: Rule = new Rule();
this.dataModel.visible.rules.push(rule);
(<FormArray>this.form.get("visible").get("rules")).push(rule.buildForm());
}
DeleteRule(index) {
this.dataModel.visible.rules.splice(index, 1);
(<FormArray>this.form.get("visible").get("rules")).removeAt(index);
}
2017-11-27 14:35:00 +01:00
}