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>;
|
|
|
|
|
|
|
|
buildForm(): FormGroup {
|
|
|
|
const formGroup = this.formBuilder.group({
|
|
|
|
type: [this.type],
|
|
|
|
label: [this.label]
|
|
|
|
});
|
|
|
|
const optionsFormArray = new Array<FormGroup>();
|
|
|
|
if (this.options) {
|
|
|
|
this.options.forEach(item => {
|
|
|
|
const form: FormGroup = item.buildForm();
|
|
|
|
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;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|