100 lines
3.5 KiB
TypeScript
100 lines
3.5 KiB
TypeScript
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
|
import { DmpBlueprintFieldDataType } from '@app/core/common/enum/dmp-blueprint-field-type';
|
|
import { DmpBlueprintType } from '@app/core/common/enum/dmp-blueprint-type';
|
|
import { DmpBlueprint } from '@app/core/model/dmp-blueprint/dmp-blueprint';
|
|
import { DmpBlueprintField } from '@app/core/model/dmp-blueprint/dmp-blueprint-field';
|
|
import { DmpBlueprintDefinition } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint';
|
|
import { DmpBlueprintExternalAutoCompleteFieldDataEditorModel } from '@app/ui/admin/dmp-blueprint/editor/external-autocomplete/dmp-blueprint-external-autocomplete-field-editor.model';
|
|
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
|
|
|
|
export class DmpBlueprintEditorModel {
|
|
|
|
public id: string;
|
|
public label: string;
|
|
public definition: DmpBlueprintDefinitionEditorModel = new DmpBlueprintDefinitionEditorModel();
|
|
public status: number;
|
|
public created: Date;
|
|
public modified: Date;
|
|
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
|
|
|
|
fromModel(item: DmpBlueprint): DmpBlueprintEditorModel {
|
|
// this.id = item.id;
|
|
// this.label = item.label;
|
|
// this.definition = new DmpBlueprintDefinitionEditorModel().fromModel(item.definition);
|
|
// this.status = item.status;
|
|
// this.created = item.created;
|
|
// this.modified = item.modified;
|
|
return this;
|
|
}
|
|
|
|
buildForm(): UntypedFormGroup {
|
|
const formGroup = new UntypedFormBuilder().group({
|
|
id: [this.id],
|
|
label: [this.label],
|
|
status: [this.status],
|
|
created: [this.created],
|
|
modified: [this.modified]
|
|
});
|
|
formGroup.addControl('definition', this.definition.buildForm());
|
|
return formGroup;
|
|
}
|
|
}
|
|
|
|
export class DmpBlueprintDefinitionEditorModel {
|
|
|
|
public fields: DmpBlueprintFieldEditorModel[] = new Array<DmpBlueprintFieldEditorModel>();
|
|
|
|
fromModel(item: DmpBlueprintDefinition): DmpBlueprintDefinitionEditorModel {
|
|
if (item.fields) { item.fields.map(x => this.fields.push(new DmpBlueprintFieldEditorModel().fromModel(x))); }
|
|
return this;
|
|
}
|
|
|
|
buildForm(): UntypedFormGroup {
|
|
const formBuilder = new UntypedFormBuilder();
|
|
const formGroup = formBuilder.group({});
|
|
const fieldsFormArray = new Array<UntypedFormGroup>();
|
|
this.fields.forEach(item => {
|
|
const form: UntypedFormGroup = item.buildForm();
|
|
fieldsFormArray.push(form);
|
|
});
|
|
formGroup.addControl('fields', formBuilder.array(fieldsFormArray));
|
|
return formGroup;
|
|
}
|
|
}
|
|
|
|
export class DmpBlueprintFieldEditorModel {
|
|
public id: string;
|
|
public type: DmpBlueprintType;
|
|
public dataType: DmpBlueprintFieldDataType;
|
|
public required = false;
|
|
public label: string;
|
|
public value: any;
|
|
public externalAutocomplete?: DmpBlueprintExternalAutoCompleteFieldDataEditorModel;
|
|
|
|
fromModel(item: DmpBlueprintField): DmpBlueprintFieldEditorModel {
|
|
this.type = item.type;
|
|
this.dataType = item.dataType;
|
|
this.required = item.required;
|
|
this.label = item.label;
|
|
this.id = item.id;
|
|
this.value = item.value;
|
|
if (item.externalAutocomplete)
|
|
this.externalAutocomplete = new DmpBlueprintExternalAutoCompleteFieldDataEditorModel().fromModel(item.externalAutocomplete);
|
|
return this;
|
|
}
|
|
|
|
buildForm(): UntypedFormGroup {
|
|
const formGroup = new UntypedFormBuilder().group({
|
|
type: [this.type],
|
|
id: [this.id],
|
|
dataType: [this.dataType],
|
|
required: [this.required],
|
|
label: [this.label]
|
|
});
|
|
if (this.externalAutocomplete) {
|
|
formGroup.addControl('externalAutocomplete', this.externalAutocomplete.buildForm());
|
|
}
|
|
return formGroup;
|
|
}
|
|
}
|