2019-01-18 18:03:45 +01:00
|
|
|
|
|
2019-01-28 16:47:12 +01:00
|
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
|
|
|
|
import { FormArray, FormControl, FormGroup } from '@angular/forms';
|
2019-12-11 15:51:03 +01:00
|
|
|
|
import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style';
|
|
|
|
|
import { ValidationType } from '@app/core/common/enum/validation-type';
|
|
|
|
|
import { DatasetProfileService } from '@app/core/services/dataset-profile/dataset-profile.service';
|
|
|
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
|
|
|
import { BooleanDecisionFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/boolean-decision-field-data-editor-model';
|
|
|
|
|
import { CheckBoxFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/check-box-field-data-editor-model';
|
|
|
|
|
import { DatePickerDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/date-picker-data-editor-models';
|
|
|
|
|
import { FreeTextFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/free-text-field-data-editor-model';
|
|
|
|
|
import { RadioBoxFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/radio-box-field-data-editor-model';
|
|
|
|
|
import { ResearchersAutoCompleteFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/researchers-auto-complete-field-data-editor-model';
|
|
|
|
|
import { TextAreaFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/text-area-field-data-editor-model';
|
|
|
|
|
import { WordListFieldDataEditorModel } from '@app/ui/admin/dataset-profile/admin/field-data/word-list-field-data-editor-model';
|
|
|
|
|
import { RuleEditorModel } from '@app/ui/admin/dataset-profile/admin/rule-editor-model';
|
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2019-01-28 14:05:19 +01:00
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-dataset-profile-editor-field-component',
|
|
|
|
|
templateUrl: './dataset-profile-editor-field.component.html',
|
|
|
|
|
styleUrls: ['./dataset-profile-editor-field.component.scss']
|
|
|
|
|
})
|
2019-01-28 14:05:19 +01:00
|
|
|
|
export class DatasetProfileEditorFieldComponent extends BaseComponent implements OnInit {
|
2019-02-11 13:04:45 +01:00
|
|
|
|
@Input() viewOnly: boolean;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
@Input() form: FormGroup;
|
|
|
|
|
@Input() showOrdinal = true;
|
|
|
|
|
@Input() indexPath: string;
|
2019-01-28 14:05:19 +01:00
|
|
|
|
validationTypeEnum = ValidationType;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
viewStyleEnum = DatasetProfileFieldViewStyle;
|
|
|
|
|
isFieldMultiplicityEnabled = false;
|
|
|
|
|
|
2019-02-08 10:04:12 +01:00
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
|
constructor(
|
2019-10-15 17:29:34 +02:00
|
|
|
|
public enumUtils: EnumUtils,
|
|
|
|
|
public datasetProfileService: DatasetProfileService
|
2019-01-28 14:05:19 +01:00
|
|
|
|
) { super(); }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
if (this.form.get('multiplicity')) {
|
2019-02-01 09:29:00 +01:00
|
|
|
|
if (this.form.get('multiplicity').value.min > 1 && this.form.get('multiplicity').value.max > 1) {
|
2019-01-18 18:03:45 +01:00
|
|
|
|
this.isFieldMultiplicityEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// this.addNewRule();
|
2019-01-28 14:05:19 +01:00
|
|
|
|
|
|
|
|
|
this.form.get('viewStyle').get('renderStyle').valueChanges
|
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
|
.subscribe(x => {
|
|
|
|
|
if (this.form.get('data')) {
|
|
|
|
|
this.form.removeControl('data');
|
|
|
|
|
|
|
|
|
|
switch (x) {
|
|
|
|
|
case DatasetProfileFieldViewStyle.BooleanDecision:
|
|
|
|
|
this.form.addControl('data', new BooleanDecisionFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.CheckBox:
|
|
|
|
|
this.form.addControl('data', new CheckBoxFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.ComboBox:
|
2019-01-28 16:47:12 +01:00
|
|
|
|
this.form.addControl('data', new WordListFieldDataEditorModel().buildForm());
|
2019-01-28 14:05:19 +01:00
|
|
|
|
break;
|
2019-07-16 15:41:12 +02:00
|
|
|
|
case DatasetProfileFieldViewStyle.InternalDmpEntities:
|
|
|
|
|
this.form.addControl('data', new ResearchersAutoCompleteFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
2019-01-28 14:05:19 +01:00
|
|
|
|
case DatasetProfileFieldViewStyle.FreeText:
|
|
|
|
|
this.form.addControl('data', new FreeTextFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.RadioBox:
|
|
|
|
|
this.form.addControl('data', new RadioBoxFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
|
|
|
|
case DatasetProfileFieldViewStyle.TextArea:
|
|
|
|
|
this.form.addControl('data', new TextAreaFieldDataEditorModel().buildForm());
|
|
|
|
|
break;
|
2019-02-15 11:26:14 +01:00
|
|
|
|
case DatasetProfileFieldViewStyle.DatePicker:
|
|
|
|
|
this.form.addControl('data', new DatePickerDataEditorModel().buildForm());
|
|
|
|
|
break;
|
2019-01-28 14:05:19 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-01-18 18:03:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 10:04:12 +01:00
|
|
|
|
defaulValueRequired(viewStile: DatasetProfileFieldViewStyle): boolean {
|
|
|
|
|
switch (viewStile) {
|
|
|
|
|
case DatasetProfileFieldViewStyle.CheckBox:
|
|
|
|
|
return true;
|
|
|
|
|
case DatasetProfileFieldViewStyle.RadioBox:
|
|
|
|
|
case DatasetProfileFieldViewStyle.TextArea:
|
|
|
|
|
case DatasetProfileFieldViewStyle.FreeText:
|
|
|
|
|
case DatasetProfileFieldViewStyle.ComboBox:
|
2019-07-16 15:41:12 +02:00
|
|
|
|
case DatasetProfileFieldViewStyle.InternalDmpEntities:
|
2019-02-08 10:04:12 +01:00
|
|
|
|
case DatasetProfileFieldViewStyle.BooleanDecision:
|
2019-02-15 11:26:14 +01:00
|
|
|
|
case DatasetProfileFieldViewStyle.DatePicker:
|
2019-02-08 10:04:12 +01:00
|
|
|
|
return false;
|
|
|
|
|
default:
|
2019-02-11 13:04:45 +01:00
|
|
|
|
return false;
|
2019-02-08 10:04:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-18 18:03:45 +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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addNewRule() {
|
|
|
|
|
const rule: RuleEditorModel = new RuleEditorModel();
|
|
|
|
|
(<FormArray>this.form.get('visible').get('rules')).push(rule.buildForm());
|
|
|
|
|
}
|
|
|
|
|
}
|