2018-02-02 11:57:24 +01:00
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
2018-02-02 11:57:24 +01:00
|
|
|
|
import { FormGroup, FormControl, FormArray } from '@angular/forms';
|
2018-05-14 08:44:35 +02:00
|
|
|
|
import { ValidationTypes } from '../../models/common/ValidationTypes';
|
|
|
|
|
import { Field } from '../../models/datasetProfileAdmin/Field';
|
|
|
|
|
import { Rule } from '../../models/datasetProfileAdmin/Rule';
|
2018-02-02 11:57:24 +01:00
|
|
|
|
|
|
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
|
selector: 'app-field-form',
|
|
|
|
|
templateUrl: './field-form.component.html',
|
|
|
|
|
styleUrls: ['./field-form.component.scss']
|
2018-02-02 11:57:24 +01:00
|
|
|
|
})
|
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
|
export class FieldFormComponent implements OnInit {
|
|
|
|
|
@Input() form: FormGroup;
|
|
|
|
|
@Input() dataModel: Field;
|
|
|
|
|
@Input() showMultiplicity = true;
|
|
|
|
|
@Input() indexPath: string;
|
|
|
|
|
validationsOptions: Array<any>;
|
|
|
|
|
isFieldMultiplicityEnabled = 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() {
|
|
|
|
|
const 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'); }
|
|
|
|
|
}
|
|
|
|
|
}
|