2019-01-18 18:03:45 +01:00
|
|
|
import { FormGroup } from '@angular/forms';
|
|
|
|
import { DatasetProfileComboBoxType } from '../../../../../core/common/enum/dataset-profile-combo-box-type';
|
|
|
|
import { WordListFieldData } from '../../../../../core/model/dataset-profile-definition/field-data/field-data';
|
|
|
|
import { FieldDataEditorModel } from './field-data-editor-model';
|
|
|
|
import { FieldDataOptionEditorModel } from './field-data-option-editor-model';
|
|
|
|
|
|
|
|
export class WordListFieldDataEditorModel extends FieldDataEditorModel<WordListFieldDataEditorModel> {
|
2019-01-28 14:05:19 +01:00
|
|
|
public type: DatasetProfileComboBoxType = DatasetProfileComboBoxType.WordList;
|
2019-01-18 18:03:45 +01:00
|
|
|
public options: Array<FieldDataOptionEditorModel>;
|
2020-09-10 17:04:14 +02:00
|
|
|
public multipleList: boolean;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2019-04-16 12:49:09 +02:00
|
|
|
buildForm(disabled: boolean = false, skipDisable: Array<String> = []): FormGroup {
|
2019-01-18 18:03:45 +01:00
|
|
|
const formGroup = this.formBuilder.group({
|
2019-04-16 12:49:09 +02:00
|
|
|
type: [{ value: this.type, disabled: (disabled && !skipDisable.includes('WordListFieldDataEditorModel.type')) }],
|
2020-09-10 17:04:14 +02:00
|
|
|
label: [{ value: this.label, disabled: (disabled && !skipDisable.includes('WordListFieldDataEditorModel.label')) }],
|
|
|
|
multiList: [{ value: this.multipleList, disabled: (disabled && !skipDisable.includes('WordListFieldDataEditorModel.multipleList'))}]
|
2019-01-18 18:03:45 +01:00
|
|
|
});
|
|
|
|
const optionsFormArray = new Array<FormGroup>();
|
|
|
|
if (this.options) {
|
|
|
|
this.options.forEach(item => {
|
2019-04-16 12:49:09 +02:00
|
|
|
const form: FormGroup = item.buildForm(disabled, skipDisable);
|
2019-01-18 18:03:45 +01:00
|
|
|
optionsFormArray.push(form);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
formGroup.addControl('options', this.formBuilder.array(optionsFormArray));
|
|
|
|
|
|
|
|
return formGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
fromModel(item: WordListFieldData): WordListFieldDataEditorModel {
|
|
|
|
this.type = item.type;
|
2019-01-28 14:05:19 +01:00
|
|
|
if (item.options) { this.options = item.options.map(x => new FieldDataOptionEditorModel().fromModel(x)); }
|
2019-01-18 18:03:45 +01:00
|
|
|
this.label = item.label;
|
2020-09-10 17:04:14 +02:00
|
|
|
this.multipleList = item.multiList;
|
2019-01-18 18:03:45 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|