2019-01-28 14:47:31 +01:00
|
|
|
|
import { FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms";
|
2019-01-18 18:03:45 +01:00
|
|
|
|
import { ValidationType } from "../../../core/common/enum/validation-type";
|
2019-01-28 14:47:31 +01:00
|
|
|
|
import { BaseFormModel } from "../../../core/model/base-form-model";
|
2019-01-18 18:03:45 +01:00
|
|
|
|
import { CompositeField } from "../../../core/model/dataset-profile-definition/composite-field";
|
|
|
|
|
import { DatasetProfileDefinitionModel } from "../../../core/model/dataset-profile-definition/dataset-profile-definition";
|
|
|
|
|
import { DefaultValue } from "../../../core/model/dataset-profile-definition/default-value";
|
|
|
|
|
import { Field } from "../../../core/model/dataset-profile-definition/field";
|
|
|
|
|
import { Multiplicity } from "../../../core/model/dataset-profile-definition/multiplicity";
|
|
|
|
|
import { Page } from "../../../core/model/dataset-profile-definition/page";
|
|
|
|
|
import { Rule } from "../../../core/model/dataset-profile-definition/rule";
|
|
|
|
|
import { Section } from "../../../core/model/dataset-profile-definition/section";
|
|
|
|
|
import { ViewStyle } from "../../../core/model/dataset-profile-definition/view-style";
|
2019-02-01 09:29:00 +01:00
|
|
|
|
import { Guid } from "../../../common/types/guid";
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
export class DatasetDescriptionFormEditorModel extends BaseFormModel {
|
|
|
|
|
|
|
|
|
|
public status: number;
|
|
|
|
|
public pages: Array<DatasetDescriptionPageEditorModel> = [];
|
|
|
|
|
public rules: Rule[] = [];
|
|
|
|
|
|
|
|
|
|
fromModel(item: DatasetProfileDefinitionModel): DatasetDescriptionFormEditorModel {
|
|
|
|
|
this.status = item.status;
|
|
|
|
|
this.rules = item.rules;
|
|
|
|
|
if (item.pages) { item.pages.map(x => this.pages.push(new DatasetDescriptionPageEditorModel().fromModel(x))); }
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm(): FormGroup {
|
|
|
|
|
const formGroup: FormGroup = new FormBuilder().group({});
|
|
|
|
|
const pagesFormArray = new Array<FormGroup>();
|
|
|
|
|
|
|
|
|
|
this.pages.forEach(item => {
|
|
|
|
|
const form: FormGroup = item.buildForm();
|
|
|
|
|
pagesFormArray.push(form);
|
|
|
|
|
});
|
|
|
|
|
formGroup.addControl('pages', this.formBuilder.array(pagesFormArray));
|
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DatasetDescriptionPageEditorModel extends BaseFormModel {
|
|
|
|
|
public ordinal: number;
|
|
|
|
|
public title: string;
|
|
|
|
|
public sections: DatasetDescriptionSectionEditorModel[] = [];
|
|
|
|
|
|
|
|
|
|
fromModel(item: Page): DatasetDescriptionPageEditorModel {
|
|
|
|
|
this.ordinal = item.ordinal;
|
|
|
|
|
this.title = item.title;
|
|
|
|
|
if (item.sections) { item.sections.map(x => this.sections.push(new DatasetDescriptionSectionEditorModel().fromModel(x))); }
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm(): FormGroup {
|
|
|
|
|
const formGroup: FormGroup = new FormBuilder().group({});
|
|
|
|
|
const sectionsFormArray = new Array<FormGroup>();
|
|
|
|
|
this.sections.forEach(item => {
|
|
|
|
|
const form: FormGroup = item.buildForm();
|
|
|
|
|
sectionsFormArray.push(form);
|
|
|
|
|
});
|
|
|
|
|
formGroup.addControl('sections', this.formBuilder.array(sectionsFormArray));
|
2019-01-28 14:47:31 +01:00
|
|
|
|
formGroup.addControl('title', new FormControl({ value: this.title, disabled: true }));
|
2019-01-18 18:03:45 +01:00
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DatasetDescriptionSectionEditorModel extends BaseFormModel {
|
|
|
|
|
|
|
|
|
|
sections: Array<DatasetDescriptionSectionEditorModel> = new Array<DatasetDescriptionSectionEditorModel>();
|
|
|
|
|
defaultVisibility: boolean;
|
|
|
|
|
page: number;
|
|
|
|
|
numbering: string;
|
|
|
|
|
ordinal: number;
|
|
|
|
|
id: string;
|
|
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
compositeFields: Array<DatasetDescriptionCompositeFieldEditorModel> = new Array<DatasetDescriptionCompositeFieldEditorModel>();
|
|
|
|
|
|
|
|
|
|
fromModel(item: Section): DatasetDescriptionSectionEditorModel {
|
|
|
|
|
if (item.sections) { item.sections.map(x => this.sections.push(new DatasetDescriptionSectionEditorModel().fromModel(x))); }
|
|
|
|
|
this.page = item.page;
|
|
|
|
|
this.defaultVisibility = item.defaultVisibility;
|
|
|
|
|
this.numbering = item.numbering;
|
|
|
|
|
this.id = item.id;
|
|
|
|
|
this.title = item.title;
|
|
|
|
|
this.ordinal = item.ordinal;
|
|
|
|
|
this.description = item.description;
|
|
|
|
|
if (item.compositeFields) { item.compositeFields.map(x => this.compositeFields.push(new DatasetDescriptionCompositeFieldEditorModel().fromModel(x))); }
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm(): FormGroup {
|
|
|
|
|
const formGroup: FormGroup = new FormBuilder().group({});
|
|
|
|
|
const sectionsFormArray = new Array<FormGroup>();
|
|
|
|
|
if (this.sections) {
|
|
|
|
|
this.sections.forEach(item => {
|
|
|
|
|
const form: FormGroup = item.buildForm();
|
|
|
|
|
sectionsFormArray.push(form);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const compositeFieldsFormArray = new Array<FormGroup>();
|
|
|
|
|
if (this.compositeFields) {
|
|
|
|
|
this.compositeFields.forEach(item => {
|
|
|
|
|
const form: FormGroup = item.buildForm();
|
|
|
|
|
compositeFieldsFormArray.push(form);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
formGroup.addControl('compositeFields', this.formBuilder.array(compositeFieldsFormArray));
|
|
|
|
|
formGroup.addControl('sections', this.formBuilder.array(sectionsFormArray));
|
2019-01-28 14:47:31 +01:00
|
|
|
|
formGroup.addControl('description', new FormControl({ value: this.description, disabled: true }));
|
|
|
|
|
formGroup.addControl('numbering', new FormControl({ value: this.numbering, disabled: true }));
|
|
|
|
|
formGroup.addControl('title', new FormControl({ value: this.title, disabled: true }));
|
2019-02-01 09:29:00 +01:00
|
|
|
|
formGroup.addControl('id', new FormControl({ value: this.title, disabled: false }));
|
2019-01-18 18:03:45 +01:00
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DatasetDescriptionCompositeFieldEditorModel extends BaseFormModel {
|
|
|
|
|
|
|
|
|
|
fields: Array<DatasetDescriptionFieldEditorModel> = new Array<DatasetDescriptionFieldEditorModel>();
|
|
|
|
|
ordinal: number;
|
|
|
|
|
id: string;
|
|
|
|
|
numbering: string;
|
|
|
|
|
multiplicity: DatasetDescriptionMultiplicityEditorModel;
|
|
|
|
|
multiplicityItems: DatasetDescriptionCompositeFieldEditorModel[] = [];
|
|
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
extendedDescription: string;
|
|
|
|
|
hasCommentField: boolean;
|
|
|
|
|
commentFieldValue: string;
|
|
|
|
|
|
|
|
|
|
fromModel(item: CompositeField): DatasetDescriptionCompositeFieldEditorModel {
|
|
|
|
|
|
|
|
|
|
if (item.fields) { item.fields.map(x => this.fields.push(new DatasetDescriptionFieldEditorModel().fromModel(x))); }
|
|
|
|
|
this.ordinal = item.ordinal;
|
|
|
|
|
this.id = item.id;
|
|
|
|
|
this.title = item.title;
|
|
|
|
|
this.numbering = item.numbering;
|
|
|
|
|
this.description = item.description;
|
|
|
|
|
this.extendedDescription = item.extendedDescription;
|
|
|
|
|
this.hasCommentField = item.hasCommentField;
|
|
|
|
|
this.commentFieldValue = item.commentFieldValue;
|
|
|
|
|
if (item.multiplicity) this.multiplicity = new DatasetDescriptionMultiplicityEditorModel().fromModel(item.multiplicity);
|
|
|
|
|
if (item.multiplicityItems) { item.multiplicityItems.map(x => this.multiplicityItems.push(new DatasetDescriptionCompositeFieldEditorModel().fromModel(x))); }
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm(): FormGroup {
|
|
|
|
|
const formGroup = this.formBuilder.group({
|
|
|
|
|
id: this.id,
|
|
|
|
|
ordinal: this.ordinal,
|
|
|
|
|
extendedDescription: this.extendedDescription,
|
|
|
|
|
hasCommentField: this.hasCommentField,
|
2019-01-28 14:47:31 +01:00
|
|
|
|
commentFieldValue: this.commentFieldValue,
|
|
|
|
|
multiplicity: [{ value: this.multiplicity, disabled: true }],
|
|
|
|
|
title: [{ value: this.title, disabled: true }],
|
|
|
|
|
description: [{ value: this.description, disabled: true }],
|
|
|
|
|
numbering: [{ value: this.numbering, disabled: true }],
|
2019-01-18 18:03:45 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const fieldsFormArray = new Array<FormGroup>();
|
|
|
|
|
this.fields.forEach(item => {
|
|
|
|
|
const form: FormGroup = item.buildForm();
|
|
|
|
|
fieldsFormArray.push(form);
|
|
|
|
|
});
|
|
|
|
|
formGroup.addControl('fields', this.formBuilder.array(fieldsFormArray));
|
|
|
|
|
|
|
|
|
|
const multiplicityItemsFormArray = new Array<FormGroup>();
|
|
|
|
|
this.multiplicityItems.forEach(item => {
|
|
|
|
|
const form: FormGroup = item.buildForm();
|
|
|
|
|
multiplicityItemsFormArray.push(form);
|
|
|
|
|
});
|
|
|
|
|
formGroup.addControl('multiplicityItems', this.formBuilder.array(multiplicityItemsFormArray));
|
|
|
|
|
|
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-31 11:29:35 +01:00
|
|
|
|
// cloneForMultiplicity(index: number): DatasetDescriptionCompositeFieldEditorModel {
|
|
|
|
|
// const newItem: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel();
|
|
|
|
|
// newItem.id = 'multiple_' + this.id + '_' + index;
|
|
|
|
|
// this.fields.forEach(field => {
|
|
|
|
|
// newItem.fields.push(field.cloneForMultiplicity(this.fields.indexOf(field), newItem.id + '_'));
|
|
|
|
|
// });
|
|
|
|
|
// newItem.ordinal = this.ordinal;
|
|
|
|
|
// return newItem;
|
|
|
|
|
// }
|
|
|
|
|
|
2019-02-01 09:29:00 +01:00
|
|
|
|
cloneForMultiplicity(item: CompositeField): DatasetDescriptionCompositeFieldEditorModel {
|
2019-01-18 18:03:45 +01:00
|
|
|
|
const newItem: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel();
|
2019-02-01 09:29:00 +01:00
|
|
|
|
newItem.id = 'multiple_' + item.id + '_' + Guid.create();
|
2019-01-31 11:29:35 +01:00
|
|
|
|
item.fields.forEach((field, index) => {
|
2019-02-04 14:41:54 +01:00
|
|
|
|
newItem.fields.push(new DatasetDescriptionFieldEditorModel().cloneForMultiplicity(field, newItem.id));
|
2019-01-18 18:03:45 +01:00
|
|
|
|
});
|
2019-01-31 11:29:35 +01:00
|
|
|
|
newItem.ordinal = item.ordinal;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
return newItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DatasetDescriptionFieldEditorModel extends BaseFormModel {
|
|
|
|
|
|
|
|
|
|
public id: string;
|
|
|
|
|
public title: string;
|
|
|
|
|
public value: any;
|
|
|
|
|
public defaultValue: DefaultValue;
|
|
|
|
|
public description: string;
|
|
|
|
|
public numbering: string;
|
|
|
|
|
public extendedDescription: string;
|
|
|
|
|
public viewStyle: ViewStyle;
|
|
|
|
|
public defaultVisibility: boolean;
|
|
|
|
|
public page: number;
|
|
|
|
|
public multiplicity: DatasetDescriptionMultiplicityEditorModel;
|
|
|
|
|
public multiplicityItems: Array<DatasetDescriptionFieldEditorModel> = new Array<DatasetDescriptionFieldEditorModel>();
|
|
|
|
|
public data: any;
|
|
|
|
|
public validations: Array<ValidationType>;
|
|
|
|
|
public validationRequired = false;
|
|
|
|
|
|
|
|
|
|
fromModel(item: Field): DatasetDescriptionFieldEditorModel {
|
|
|
|
|
this.id = item.id;
|
|
|
|
|
this.title = item.title;
|
|
|
|
|
this.numbering = item.numbering;
|
|
|
|
|
this.description = item.description;
|
|
|
|
|
this.extendedDescription = item.extendedDescription;
|
|
|
|
|
this.viewStyle = item.viewStyle;
|
|
|
|
|
this.defaultVisibility = item.defaultVisibility;
|
|
|
|
|
this.page = item.page;
|
|
|
|
|
this.validations = item.validations;
|
|
|
|
|
if (item.multiplicity) this.multiplicity = new DatasetDescriptionMultiplicityEditorModel().fromModel(item.multiplicity);
|
|
|
|
|
if (item.defaultValue) this.defaultValue = new DatasetDescriptionDefaultValueEditorModel().fromModel(item.defaultValue);
|
2019-02-04 17:10:22 +01:00
|
|
|
|
this.value = item.value ? item.value : (this.defaultValue.value ? this.defaultValue.value : undefined);
|
2019-01-18 18:03:45 +01:00
|
|
|
|
if (this.viewStyle.renderStyle === 'checkBox') { this.value = this.value === 'true'; }
|
|
|
|
|
if (item.multiplicityItems) { item.multiplicityItems.map(x => this.multiplicityItems.push(new DatasetDescriptionFieldEditorModel().fromModel(x))); }
|
|
|
|
|
this.data = item.data;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm(): FormGroup {
|
|
|
|
|
if (this.validations) {
|
|
|
|
|
this.validations.forEach(validation => {
|
|
|
|
|
if (validation === ValidationType.Required) { this.validationRequired = true; }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const formGroup = this.formBuilder.group({
|
2019-01-28 14:47:31 +01:00
|
|
|
|
value: [this.value, this.validationRequired === true ? Validators.required : null],
|
2019-02-01 09:29:00 +01:00
|
|
|
|
id: [{ value: this.id, disabled: false }],
|
2019-01-28 14:47:31 +01:00
|
|
|
|
viewStyle: [{ value: this.viewStyle, disabled: true }],
|
|
|
|
|
data: [{ value: this.data, disabled: true }],
|
|
|
|
|
validationRequired: [{ value: this.validationRequired, disabled: true }],
|
|
|
|
|
description: [{ value: this.description, disabled: true }],
|
|
|
|
|
extendedDescription: [{ value: this.extendedDescription, disabled: true }],
|
2019-01-29 08:47:50 +01:00
|
|
|
|
title: [{ value: this.title, disabled: true }],
|
2019-02-08 09:48:28 +01:00
|
|
|
|
defaultValue: [{ value: this.defaultValue, disabled: true }],
|
2019-01-18 18:03:45 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const multiplicityItemsFormArray = new Array<FormGroup>();
|
|
|
|
|
this.multiplicityItems.forEach(item => {
|
|
|
|
|
const form: FormGroup = item.buildForm();
|
|
|
|
|
multiplicityItemsFormArray.push(form);
|
|
|
|
|
});
|
|
|
|
|
formGroup.addControl('multiplicityItems', this.formBuilder.array(multiplicityItemsFormArray));
|
|
|
|
|
|
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-31 11:29:35 +01:00
|
|
|
|
// cloneForMultiplicity(index: number, idPath: string): DatasetDescriptionFieldEditorModel {
|
|
|
|
|
// const newItem: DatasetDescriptionFieldEditorModel = new DatasetDescriptionFieldEditorModel();
|
|
|
|
|
|
|
|
|
|
// newItem.id = idPath ? idPath + index : 'multiple_' + this.id + '_' + index;
|
|
|
|
|
// newItem.title = this.title;
|
|
|
|
|
// newItem.description = this.description;
|
|
|
|
|
// newItem.extendedDescription = this.extendedDescription;
|
|
|
|
|
// newItem.viewStyle = this.viewStyle;
|
|
|
|
|
// newItem.defaultVisibility = this.defaultVisibility;
|
|
|
|
|
// newItem.page = this.page;
|
|
|
|
|
// newItem.multiplicity = null;
|
|
|
|
|
// newItem.data = this.data;
|
|
|
|
|
|
|
|
|
|
// return newItem;
|
|
|
|
|
// }
|
2019-02-04 14:41:54 +01:00
|
|
|
|
cloneForMultiplicity(item: Field, idPath: string): DatasetDescriptionFieldEditorModel {
|
2019-01-18 18:03:45 +01:00
|
|
|
|
const newItem: DatasetDescriptionFieldEditorModel = new DatasetDescriptionFieldEditorModel();
|
|
|
|
|
|
2019-02-04 14:41:54 +01:00
|
|
|
|
//newItem.id = idPath ? idPath : 'multiple_' + item.id + '_' + Guid.create();
|
|
|
|
|
newItem.id = idPath ? idPath + '_' + item.id : 'multiple_' + Guid.create() + '_' + item.id;
|
2019-01-31 11:29:35 +01:00
|
|
|
|
newItem.title = item.title;
|
|
|
|
|
newItem.description = item.description;
|
|
|
|
|
newItem.extendedDescription = item.extendedDescription;
|
|
|
|
|
newItem.viewStyle = item.viewStyle;
|
|
|
|
|
newItem.defaultVisibility = item.defaultVisibility;
|
|
|
|
|
newItem.page = item.page;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
newItem.multiplicity = null;
|
2019-01-31 11:29:35 +01:00
|
|
|
|
newItem.data = item.data;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
|
|
return newItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class DatasetDescriptionMultiplicityEditorModel extends BaseFormModel {
|
|
|
|
|
public min: number;
|
|
|
|
|
public max: number;
|
|
|
|
|
|
|
|
|
|
fromModel(item: Multiplicity): DatasetDescriptionMultiplicityEditorModel {
|
|
|
|
|
this.min = item.min;
|
|
|
|
|
this.max = item.max;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm(): FormGroup {
|
|
|
|
|
const formGroup = this.formBuilder.group({
|
|
|
|
|
min: [this.min],
|
|
|
|
|
max: [this.max]
|
|
|
|
|
});
|
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DatasetDescriptionDefaultValueEditorModel extends BaseFormModel {
|
|
|
|
|
public type: string;
|
|
|
|
|
public value: string;
|
|
|
|
|
|
|
|
|
|
fromModel(item: DefaultValue): DatasetDescriptionDefaultValueEditorModel {
|
|
|
|
|
this.type = item.type;
|
|
|
|
|
this.value = item.value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildForm(): FormGroup {
|
|
|
|
|
const formGroup = this.formBuilder.group({
|
|
|
|
|
type: [this.type],
|
|
|
|
|
value: [this.value]
|
|
|
|
|
});
|
|
|
|
|
return formGroup;
|
|
|
|
|
}
|
|
|
|
|
}
|