2019-02-04 17:10:22 +01:00
|
|
|
|
import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
import { ValidationType } from '../../../../core/common/enum/validation-type';
|
|
|
|
|
import { Field } from '../../../../core/model/admin/dataset-profile/dataset-profile';
|
|
|
|
|
import { BaseFormModel } from '../../../../core/model/base-form-model';
|
|
|
|
|
import { DefaultValueEditorModel } from './default-value-editor-model';
|
|
|
|
|
import { AutoCompleteFieldDataEditorModel } from './field-data/auto-complete-field-data-editor-model';
|
|
|
|
|
import { BooleanDecisionFieldDataEditorModel } from './field-data/boolean-decision-field-data-editor-model';
|
|
|
|
|
import { CheckBoxFieldDataEditorModel } from './field-data/check-box-field-data-editor-model';
|
|
|
|
|
import { FieldDataEditorModel } from './field-data/field-data-editor-model';
|
|
|
|
|
import { FreeTextFieldDataEditorModel } from './field-data/free-text-field-data-editor-model';
|
|
|
|
|
import { RadioBoxFieldDataEditorModel } from './field-data/radio-box-field-data-editor-model';
|
|
|
|
|
import { TextAreaFieldDataEditorModel } from './field-data/text-area-field-data-editor-model';
|
|
|
|
|
import { WordListFieldDataEditorModel } from './field-data/word-list-field-data-editor-model';
|
|
|
|
|
import { ViewStyleEditorModel } from './view-style-editor-model';
|
|
|
|
|
import { VisibilityEditorModel } from './visibility-editor-model';
|
2019-02-15 11:26:14 +01:00
|
|
|
|
import { DatasetProfileEditorDatePickerFieldComponent } from '../editor/components/field-type/datepicker/dataset-profile-editor-date-picker-field.component';
|
|
|
|
|
import { DatePickerDataEditorModel } from './field-data/date-picker-data-editor-models';
|
2019-07-16 15:41:12 +02:00
|
|
|
|
import { ResearchersAutoCompleteFieldDataEditorModel } from './field-data/researchers-auto-complete-field-data-editor-model';
|
2019-07-30 12:35:06 +02:00
|
|
|
|
import { DatasetsAutoCompleteFieldDataEditorModel } from './field-data/datasets-autocomplete-field-data-editor-mode';
|
2019-07-30 13:31:41 +02:00
|
|
|
|
import { DmpsAutoCompleteFieldDataEditorModel } from './field-data/dmps-autocomplete-field-data-editor-model';
|
2020-06-04 17:37:30 +02:00
|
|
|
|
import { ExternalDatasetsDataEditorModel } from './field-data/external-datasets-data-editor-models';
|
|
|
|
|
import { DataRepositoriesDataEditorModel } from './field-data/data-repositories-data-editor-models';
|
|
|
|
|
import { RegistriesDataEditorModel } from './field-data/registries-data-editor-models';
|
|
|
|
|
import { ServicesDataEditorModel } from './field-data/services-data-editor-models';
|
|
|
|
|
import { TagsDataEditorModel } from './field-data/tags-data-editor-models';
|
|
|
|
|
import { ResearchersDataEditorModel } from './field-data/researchers-data-editor-models';
|
|
|
|
|
import { OrganizationsDataEditorModel } from './field-data/organizations-data-editor-models';
|
|
|
|
|
import { DatasetIdentifierDataEditorModel } from './field-data/dataset-identifier-data-editor-models';
|
2020-06-25 12:00:29 +02:00
|
|
|
|
import { CurrencyDataEditorModel } from './field-data/currency-data-editor-models';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
export class FieldEditorModel extends BaseFormModel {
|
|
|
|
|
|
|
|
|
|
public id: string;
|
|
|
|
|
// public title: string;
|
|
|
|
|
public defaultValue: DefaultValueEditorModel = new DefaultValueEditorModel();
|
|
|
|
|
public viewStyle: ViewStyleEditorModel = new ViewStyleEditorModel();
|
2019-07-01 10:50:18 +02:00
|
|
|
|
public page: number = null;
|
|
|
|
|
public ordinal: number = null;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
public visible: VisibilityEditorModel = new VisibilityEditorModel();
|
|
|
|
|
public data: FieldDataEditorModel<any>;
|
2019-01-28 13:18:48 +01:00
|
|
|
|
public validations: ValidationType[] = [];
|
2019-10-15 17:29:34 +02:00
|
|
|
|
public rdaCommonStandard: string;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
fromModel(item: Field): FieldEditorModel {
|
|
|
|
|
this.id = item.id;
|
|
|
|
|
if (item.defaultValue) { this.defaultValue = new DefaultValueEditorModel().fromModel(item.defaultValue); }
|
|
|
|
|
this.page = item.page;
|
|
|
|
|
this.ordinal = item.ordinal;
|
|
|
|
|
this.validations = item.validations;
|
|
|
|
|
this.viewStyle = new ViewStyleEditorModel().fromModel(item.viewStyle);
|
|
|
|
|
this.visible = new VisibilityEditorModel().fromModel(item.visible);
|
2019-10-15 17:29:34 +02:00
|
|
|
|
this.rdaCommonStandard = item.rdaCommonStandard;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
if (item.data) {
|
|
|
|
|
if (this.viewStyle.renderStyle === 'combobox') {
|
|
|
|
|
if (item.data.type === 'autocomplete') { this.data = new AutoCompleteFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (item.data.type === 'wordlist') { this.data = new WordListFieldDataEditorModel().fromModel(item.data); }
|
2019-07-16 15:41:12 +02:00
|
|
|
|
} else if (this.viewStyle.renderStyle === 'internalDmpEntities') {
|
|
|
|
|
if (item.data.type === 'researchers') { this.data = new ResearchersAutoCompleteFieldDataEditorModel().fromModel(item.data); }
|
2019-07-30 12:35:06 +02:00
|
|
|
|
if (item.data.type === 'datasets') { this.data = new DatasetsAutoCompleteFieldDataEditorModel().fromModel(item.data); }
|
2019-07-30 13:31:41 +02:00
|
|
|
|
if (item.data.type === 'dmps') { this.data = new DmpsAutoCompleteFieldDataEditorModel().fromModel(item.data); }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
} else {
|
|
|
|
|
if (this.viewStyle.renderStyle === 'radiobox') { this.data = new RadioBoxFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'checkBox') { this.data = new CheckBoxFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'textarea') { this.data = new TextAreaFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'freetext') { this.data = new FreeTextFieldDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'booleanDecision') { this.data = new BooleanDecisionFieldDataEditorModel().fromModel(item.data); }
|
2019-02-15 11:26:14 +01:00
|
|
|
|
if (this.viewStyle.renderStyle === 'datePicker') { this.data = new DatePickerDataEditorModel().fromModel(item.data); }
|
2020-06-04 17:37:30 +02:00
|
|
|
|
if (this.viewStyle.renderStyle === 'externalDatasets') { this.data = new ExternalDatasetsDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'dataRepositories') { this.data = new DataRepositoriesDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'registeries') { this.data = new RegistriesDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'services') { this.data = new ServicesDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'tags') { this.data = new TagsDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'researchers') { this.data = new ResearchersDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'organizations') { this.data = new OrganizationsDataEditorModel().fromModel(item.data); }
|
|
|
|
|
if (this.viewStyle.renderStyle === 'datasetIdentifier') { this.data = new DatasetIdentifierDataEditorModel().fromModel(item.data); }
|
2020-06-25 12:00:29 +02:00
|
|
|
|
if (this.viewStyle.renderStyle === 'currency') { this.data = new CurrencyDataEditorModel().fromModel(item.data); }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
id: [{ value: this.id, disabled: (disabled && !skipDisable.includes('FieldEditorModel.id')) }, [Validators.required, Validators.pattern('^[^<_>]+$')]],
|
2019-01-18 18:03:45 +01:00
|
|
|
|
// title: [this.title],
|
2019-04-16 12:49:09 +02:00
|
|
|
|
page: [{ value: this.page, disabled: (disabled && !skipDisable.includes('FieldEditorModel.page')) }],
|
2019-10-17 17:23:19 +02:00
|
|
|
|
ordinal: [{ value: this.ordinal, disabled: (disabled && !skipDisable.includes('FieldEditorModel.ordinal')) }],
|
2019-10-15 17:29:34 +02:00
|
|
|
|
validations: [{ value: this.validations, disabled: (disabled && !skipDisable.includes('FieldEditorModel.validations')) }],
|
|
|
|
|
rdaCommonStandard: [{value: this.rdaCommonStandard, disabled: (disabled && !skipDisable.includes('FieldSetEditorModel.rdaCommonStandard')) }]
|
2019-01-18 18:03:45 +01:00
|
|
|
|
});
|
|
|
|
|
|
2019-04-16 12:49:09 +02:00
|
|
|
|
formGroup.addControl('defaultValue', this.defaultValue.buildForm(disabled, skipDisable));
|
|
|
|
|
formGroup.addControl('viewStyle', this.viewStyle.buildForm(disabled, skipDisable));
|
|
|
|
|
formGroup.addControl('visible', this.visible.buildForm(disabled, skipDisable));
|
|
|
|
|
if (this.data) { formGroup.addControl('data', this.data.buildForm(disabled, skipDisable)); }
|
|
|
|
|
else { formGroup.addControl('data', new WordListFieldDataEditorModel().buildForm(disabled, skipDisable)); }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|