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

53 lines
1.6 KiB
TypeScript

import { Field } from '../../models/DataSetProfile/Field';
import { Rule } from '../../models/DataSetProfile/Rule';
import { Component, Input } from '@angular/core';
import { FormGroup, FormControl, FormArray } from '@angular/forms';
import { ValidationTypes } from 'app/common/validationTypes';
@Component({
selector: 'field-form',
templateUrl: './field-form.component.html',
styleUrls: []
})
export class FieldFormComponent {
@Input() form: FormGroup;
@Input() dataModel: Field;
@Input() showMultiplicity: boolean = true;
@Input() indexPath: string;
validationsOptions: Array<any>;
isFieldMultiplicityEnabled: boolean = false;
constructon() {
}
ngOnInit() {
if (this.form.get("multiplicity"))
if (this.form.get("multiplicity").value.min > 1 || this.form.get("multiplicity").value.max > 1)
this.isFieldMultiplicityEnabled = true;
this.validationsOptions = [{ key: 0, value: ValidationTypes[0] }, { key: 1, value: ValidationTypes[1] }]
// this.addNewRule();
}
onIsFieldMultiplicityEnabledChange(isFieldMultiplicityEnabled: boolean) {
if (!isFieldMultiplicityEnabled) {
(<FormControl>this.form.get('multiplicity').get("min")).setValue(0);
(<FormControl>this.form.get('multiplicity').get("max")).setValue(0);
}
}
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);
}
onchangeCombo() {
debugger;
}
}