2018-02-02 11:57:24 +01:00
|
|
|
|
|
|
|
|
|
import { Component, Input } from '@angular/core';
|
|
|
|
|
import { FormGroup, FormControl, FormArray } from '@angular/forms';
|
|
|
|
|
import { ValidationTypes } from '@app/models/common/ValidationTypes';
|
|
|
|
|
import { Field } from '@app/models/datasetProfileAdmin/Field';
|
|
|
|
|
import { Rule } from '@app/models/datasetProfileAdmin/Rule';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'field-form',
|
|
|
|
|
templateUrl: './field-form.component.html',
|
2018-03-06 15:58:38 +01:00
|
|
|
|
styleUrls: ['./field-form.component.scss']
|
2018-02-02 11:57:24 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
|
if (this.form.get("data")) this.form.removeControl("data");
|
|
|
|
|
}
|
|
|
|
|
}
|