This commit is contained in:
Diamantis Tziotzios 2024-01-31 21:25:15 +02:00
parent 8b5a54814d
commit 5373e2d867
2 changed files with 177 additions and 176 deletions

View File

@ -1,6 +1,6 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { DescriptionTemplateRadioBoxDataEditorModel } from '../../../description-template-editor.model'; import { DescriptionTemplateRadioBoxOptionEditorModel } from '../../../description-template-editor.model';
@Component({ @Component({
selector: 'app-description-template-editor-radio-box-field-component', selector: 'app-description-template-editor-radio-box-field-component',
@ -15,7 +15,7 @@ export class DescriptionTemplateEditorRadioBoxFieldComponent implements OnInit {
} }
addNewRow() { addNewRow() {
const radioListOptions: DescriptionTemplateRadioBoxDataEditorModel = new DescriptionTemplateRadioBoxDataEditorModel(); const radioListOptions: DescriptionTemplateRadioBoxOptionEditorModel = new DescriptionTemplateRadioBoxOptionEditorModel();
if (!this.form.get('data').get('options')) { (<UntypedFormGroup>this.form.get('data')).addControl('options', new UntypedFormBuilder().array([])); } if (!this.form.get('data').get('options')) { (<UntypedFormGroup>this.form.get('data')).addControl('options', new UntypedFormBuilder().array([])); }
(<UntypedFormArray>this.form.get('data').get('options')).push(radioListOptions.buildForm()); (<UntypedFormArray>this.form.get('data').get('options')).push(radioListOptions.buildForm());
} }

View File

@ -805,9 +805,9 @@ export class DescriptionTemplateFieldEditorModel implements DescriptionTemplateF
case DescriptionTemplateFieldType.EXTERNAL_SELECT: case DescriptionTemplateFieldType.EXTERNAL_SELECT:
return new DescriptionTemplateExternalSelectDataEditorModel(this.validationErrorModel); return new DescriptionTemplateExternalSelectDataEditorModel(this.validationErrorModel);
case DescriptionTemplateFieldType.RADIO_BOX: case DescriptionTemplateFieldType.RADIO_BOX:
return new DescriptionTemplateRadioBoxFieldEditorModel(this.validationErrorModel); return new DescriptionTemplateRadioBoxDataEditorModel(this.validationErrorModel);
case DescriptionTemplateFieldType.SELECT: case DescriptionTemplateFieldType.SELECT:
return new DescriptionTemplateSelectFieldEditorModel(this.validationErrorModel); return new DescriptionTemplateSelectDataEditorModel(this.validationErrorModel);
case DescriptionTemplateFieldType.BOOLEAN_DECISION: case DescriptionTemplateFieldType.BOOLEAN_DECISION:
case DescriptionTemplateFieldType.CHECK_BOX: case DescriptionTemplateFieldType.CHECK_BOX:
case DescriptionTemplateFieldType.FREE_TEXT: case DescriptionTemplateFieldType.FREE_TEXT:
@ -833,11 +833,11 @@ export class DescriptionTemplateFieldEditorModel implements DescriptionTemplateF
case DescriptionTemplateFieldType.SERVICES: case DescriptionTemplateFieldType.SERVICES:
case DescriptionTemplateFieldType.RESEARCHERS: case DescriptionTemplateFieldType.RESEARCHERS:
case DescriptionTemplateFieldType.ORGANIZATIONS: case DescriptionTemplateFieldType.ORGANIZATIONS:
return new DescriptionTemplateLabelAndMultiplicityFieldEditorModel(this.validationErrorModel); return new DescriptionTemplateLabelAndMultiplicityDataEditorModel(this.validationErrorModel);
case DescriptionTemplateFieldType.EXTERNAL_DATASETS: case DescriptionTemplateFieldType.EXTERNAL_DATASETS:
return new DescriptionTemplateExternalDatasetFieldEditorModel(this.validationErrorModel); return new DescriptionTemplateExternalDatasetDataEditorModel(this.validationErrorModel);
case DescriptionTemplateFieldType.UPLOAD: case DescriptionTemplateFieldType.UPLOAD:
return new DescriptionTemplateUploadFieldEditorModel(this.validationErrorModel); return new DescriptionTemplateUploadDataEditorModel(this.validationErrorModel);
} }
} }
@ -875,6 +875,78 @@ export class DescriptionTemplateFieldEditorModel implements DescriptionTemplateF
} }
} }
export class DescriptionTemplateRuleEditorModel implements DescriptionTemplateRulePersist {
target: string;
value: string;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { }
fromModel(item: DescriptionTemplateRule): DescriptionTemplateRuleEditorModel {
if (item) {
this.target = item.target;
this.value = item.value;
}
return this;
}
buildForm(params?: {
context?: ValidationContext,
disabled?: boolean,
rootPath?: string
}): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) {
context = DescriptionTemplateRuleEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath
});
}
return this.formBuilder.group({
target: [{ value: this.target, disabled: disabled }, context.getValidation('target').validators],
value: [{ value: this.value, disabled: disabled }, context.getValidation('value').validators]
});
}
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'target', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}target`)] });
baseValidationArray.push({ key: 'value', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}value`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = DescriptionTemplateRuleEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['target', 'value'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
})
}
}
export class DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateLabelDataPersist { export class DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateLabelDataPersist {
label: string; label: string;
fieldType: DescriptionTemplateFieldType; fieldType: DescriptionTemplateFieldType;
@ -946,7 +1018,7 @@ export class DescriptionTemplateLabelDataEditorModel implements DescriptionTempl
} }
} }
export class DescriptionTemplateLabelAndMultiplicityFieldEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateLabelAndMultiplicityDataPersist { export class DescriptionTemplateLabelAndMultiplicityDataEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateLabelAndMultiplicityDataPersist {
multipleSelect: boolean; multipleSelect: boolean;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
@ -954,7 +1026,7 @@ export class DescriptionTemplateLabelAndMultiplicityFieldEditorModel extends Des
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { super(validationErrorModel); } ) { super(validationErrorModel); }
fromModel(item: DescriptionTemplateLabelAndMultiplicityDataPersist): DescriptionTemplateLabelAndMultiplicityFieldEditorModel { fromModel(item: DescriptionTemplateLabelAndMultiplicityDataPersist): DescriptionTemplateLabelAndMultiplicityDataEditorModel {
if (item) { if (item) {
super.fromModel(item); super.fromModel(item);
this.multipleSelect = item.multipleSelect; this.multipleSelect = item.multipleSelect;
@ -969,7 +1041,7 @@ export class DescriptionTemplateLabelAndMultiplicityFieldEditorModel extends Des
}): UntypedFormGroup { }): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {} let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) { if (context == null) {
context = DescriptionTemplateLabelAndMultiplicityFieldEditorModel.createValidationContext({ context = DescriptionTemplateLabelAndMultiplicityDataEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel, validationErrorModel: this.validationErrorModel,
rootPath rootPath
}); });
@ -997,7 +1069,7 @@ export class DescriptionTemplateLabelAndMultiplicityFieldEditorModel extends Des
}): void { }): void {
const { formGroup, rootPath, validationErrorModel } = params; const { formGroup, rootPath, validationErrorModel } = params;
const context = DescriptionTemplateLabelAndMultiplicityFieldEditorModel.createValidationContext({ const context = DescriptionTemplateLabelAndMultiplicityDataEditorModel.createValidationContext({
rootPath, rootPath,
validationErrorModel validationErrorModel
}); });
@ -1015,7 +1087,7 @@ export class DescriptionTemplateLabelAndMultiplicityFieldEditorModel extends Des
// External Dataset Field // External Dataset Field
// //
// //
export class DescriptionTemplateExternalDatasetFieldEditorModel extends DescriptionTemplateLabelAndMultiplicityFieldEditorModel implements DescriptionTemplateExternalDatasetDataPersist { export class DescriptionTemplateExternalDatasetDataEditorModel extends DescriptionTemplateLabelAndMultiplicityDataEditorModel implements DescriptionTemplateExternalDatasetDataPersist {
type: DescriptionTemplateFieldDataExternalDatasetType; type: DescriptionTemplateFieldDataExternalDatasetType;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
@ -1023,7 +1095,7 @@ export class DescriptionTemplateExternalDatasetFieldEditorModel extends Descript
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { super(validationErrorModel); } ) { super(validationErrorModel); }
fromModel(item: DescriptionTemplateExternalDatasetDataPersist): DescriptionTemplateExternalDatasetFieldEditorModel { fromModel(item: DescriptionTemplateExternalDatasetDataPersist): DescriptionTemplateExternalDatasetDataEditorModel {
if (item) { if (item) {
super.fromModel(item); super.fromModel(item);
this.type = item.type; this.type = item.type;
@ -1038,7 +1110,7 @@ export class DescriptionTemplateExternalDatasetFieldEditorModel extends Descript
}): UntypedFormGroup { }): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {} let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) { if (context == null) {
context = DescriptionTemplateExternalDatasetFieldEditorModel.createValidationContext({ context = DescriptionTemplateExternalDatasetDataEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel, validationErrorModel: this.validationErrorModel,
rootPath rootPath
}); });
@ -1066,7 +1138,7 @@ export class DescriptionTemplateExternalDatasetFieldEditorModel extends Descript
}): void { }): void {
const { formGroup, rootPath, validationErrorModel } = params; const { formGroup, rootPath, validationErrorModel } = params;
const context = DescriptionTemplateExternalDatasetFieldEditorModel.createValidationContext({ const context = DescriptionTemplateExternalDatasetDataEditorModel.createValidationContext({
rootPath, rootPath,
validationErrorModel validationErrorModel
}); });
@ -1275,77 +1347,6 @@ export class DescriptionTemplateExternalSelectSourceEditorModel implements Descr
} }
} }
export class DescriptionTemplateSelectOptionEditorModel implements DescriptionTemplateSelectOptionPersist {
label: string;
value: string;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { }
fromModel(item: DescriptionTemplateSelectOptionPersist): DescriptionTemplateSelectOptionEditorModel {
if (item) {
this.label = item.label;
this.value = item.value;
}
return this;
}
buildForm(params?: {
context?: ValidationContext,
disabled?: boolean,
rootPath?: string
}): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) {
context = DescriptionTemplateSelectOptionEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath
});
}
return this.formBuilder.group({
label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators],
value: [{ value: this.value, disabled: disabled }, context.getValidation('value').validators],
});
}
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'label', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}label`)] });
baseValidationArray.push({ key: 'value', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}value`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = DescriptionTemplateSelectOptionEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['label', 'value'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
})
}
}
export class DescriptionTemplateExternalSelectSourceBindingEditorModel implements DescriptionTemplateExternalSelectSourceBindingPersist { export class DescriptionTemplateExternalSelectSourceBindingEditorModel implements DescriptionTemplateExternalSelectSourceBindingPersist {
label: string; label: string;
value: string; value: string;
@ -1509,18 +1510,18 @@ export class DescriptionTemplateExternalSelectAuthDataEditorModel implements Des
// Radiobox Field // Radiobox Field
// //
// //
export class DescriptionTemplateRadioBoxFieldEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateRadioBoxDataPersist { export class DescriptionTemplateRadioBoxDataEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateRadioBoxDataPersist {
options: DescriptionTemplateRadioBoxDataEditorModel[] = []; options: DescriptionTemplateRadioBoxOptionEditorModel[] = [];
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor( constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { super(validationErrorModel); } ) { super(validationErrorModel); }
fromModel(item: DescriptionTemplateRadioBoxDataPersist): DescriptionTemplateRadioBoxFieldEditorModel { fromModel(item: DescriptionTemplateRadioBoxDataPersist): DescriptionTemplateRadioBoxDataEditorModel {
if (item) { if (item) {
super.fromModel(item); super.fromModel(item);
if (item.options) { item.options.map(x => this.options.push(new DescriptionTemplateRadioBoxDataEditorModel(this.validationErrorModel).fromModel(x))); } if (item.options) { item.options.map(x => this.options.push(new DescriptionTemplateRadioBoxOptionEditorModel(this.validationErrorModel).fromModel(x))); }
} }
return this; return this;
} }
@ -1532,7 +1533,7 @@ export class DescriptionTemplateRadioBoxFieldEditorModel extends DescriptionTemp
}): UntypedFormGroup { }): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {} let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) { if (context == null) {
context = DescriptionTemplateRadioBoxFieldEditorModel.createValidationContext({ context = DescriptionTemplateRadioBoxDataEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel, validationErrorModel: this.validationErrorModel,
rootPath rootPath
}); });
@ -1541,7 +1542,7 @@ export class DescriptionTemplateRadioBoxFieldEditorModel extends DescriptionTemp
const formGroup = super.buildForm({ context, disabled, rootPath }); const formGroup = super.buildForm({ context, disabled, rootPath });
formGroup.setControl('options', this.formBuilder.array( formGroup.setControl('options', this.formBuilder.array(
(this.options ?? []).map( (this.options ?? []).map(
(item, index) => new DescriptionTemplateRadioBoxDataEditorModel( (item, index) => new DescriptionTemplateRadioBoxOptionEditorModel(
this.validationErrorModel this.validationErrorModel
).fromModel(item).buildForm({ ).fromModel(item).buildForm({
rootPath: `${rootPath}options[${index}].` rootPath: `${rootPath}options[${index}].`
@ -1567,7 +1568,7 @@ export class DescriptionTemplateRadioBoxFieldEditorModel extends DescriptionTemp
}): void { }): void {
const { validationErrorModel, rootPath, formArray } = params; const { validationErrorModel, rootPath, formArray } = params;
formArray?.controls?.forEach( formArray?.controls?.forEach(
(control, index) => DescriptionTemplateRadioBoxDataEditorModel.reapplyValidators({ (control, index) => DescriptionTemplateRadioBoxOptionEditorModel.reapplyValidators({
formGroup: control as UntypedFormGroup, formGroup: control as UntypedFormGroup,
rootPath: `${rootPath}options[${index}].`, rootPath: `${rootPath}options[${index}].`,
validationErrorModel: validationErrorModel validationErrorModel: validationErrorModel
@ -1576,7 +1577,7 @@ export class DescriptionTemplateRadioBoxFieldEditorModel extends DescriptionTemp
} }
} }
export class DescriptionTemplateRadioBoxDataEditorModel implements DescriptionTemplateRadioBoxOptionPersist { export class DescriptionTemplateRadioBoxOptionEditorModel implements DescriptionTemplateRadioBoxOptionPersist {
label: string; label: string;
value: string; value: string;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
@ -1585,7 +1586,7 @@ export class DescriptionTemplateRadioBoxDataEditorModel implements DescriptionTe
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { } ) { }
fromModel(item: DescriptionTemplateRadioBoxOptionPersist): DescriptionTemplateRadioBoxDataEditorModel { fromModel(item: DescriptionTemplateRadioBoxOptionPersist): DescriptionTemplateRadioBoxOptionEditorModel {
if (item) { if (item) {
this.label = item.label; this.label = item.label;
this.value = item.value; this.value = item.value;
@ -1600,7 +1601,7 @@ export class DescriptionTemplateRadioBoxDataEditorModel implements DescriptionTe
}): UntypedFormGroup { }): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {} let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) { if (context == null) {
context = DescriptionTemplateRadioBoxDataEditorModel.createValidationContext({ context = DescriptionTemplateRadioBoxOptionEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel, validationErrorModel: this.validationErrorModel,
rootPath rootPath
}); });
@ -1634,7 +1635,7 @@ export class DescriptionTemplateRadioBoxDataEditorModel implements DescriptionTe
}): void { }): void {
const { formGroup, rootPath, validationErrorModel } = params; const { formGroup, rootPath, validationErrorModel } = params;
const context = DescriptionTemplateRadioBoxDataEditorModel.createValidationContext({ const context = DescriptionTemplateRadioBoxOptionEditorModel.createValidationContext({
rootPath, rootPath,
validationErrorModel validationErrorModel
}); });
@ -1652,7 +1653,7 @@ export class DescriptionTemplateRadioBoxDataEditorModel implements DescriptionTe
// Select Field // Select Field
// //
// //
export class DescriptionTemplateSelectFieldEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateSelectDataPersist { export class DescriptionTemplateSelectDataEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateSelectDataPersist {
options: DescriptionTemplateSelectOptionEditorModel[] = []; options: DescriptionTemplateSelectOptionEditorModel[] = [];
multipleSelect: boolean; multipleSelect: boolean;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
@ -1661,7 +1662,7 @@ export class DescriptionTemplateSelectFieldEditorModel extends DescriptionTempla
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { super(validationErrorModel); } ) { super(validationErrorModel); }
fromModel(item: DescriptionTemplateSelectDataPersist): DescriptionTemplateSelectFieldEditorModel { fromModel(item: DescriptionTemplateSelectDataPersist): DescriptionTemplateSelectDataEditorModel {
if (item) { if (item) {
super.fromModel(item); super.fromModel(item);
this.multipleSelect = item.multipleSelect; this.multipleSelect = item.multipleSelect;
@ -1677,7 +1678,7 @@ export class DescriptionTemplateSelectFieldEditorModel extends DescriptionTempla
}): UntypedFormGroup { }): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {} let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) { if (context == null) {
context = DescriptionTemplateSelectFieldEditorModel.createValidationContext({ context = DescriptionTemplateSelectDataEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel, validationErrorModel: this.validationErrorModel,
rootPath rootPath
}); });
@ -1714,7 +1715,7 @@ export class DescriptionTemplateSelectFieldEditorModel extends DescriptionTempla
}): void { }): void {
const { formGroup, rootPath, validationErrorModel } = params; const { formGroup, rootPath, validationErrorModel } = params;
const context = DescriptionTemplateSelectFieldEditorModel.createValidationContext({ const context = DescriptionTemplateSelectDataEditorModel.createValidationContext({
rootPath, rootPath,
validationErrorModel validationErrorModel
}); });
@ -1735,12 +1736,84 @@ export class DescriptionTemplateSelectFieldEditorModel extends DescriptionTempla
} }
} }
export class DescriptionTemplateSelectOptionEditorModel implements DescriptionTemplateSelectOptionPersist {
label: string;
value: string;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { }
fromModel(item: DescriptionTemplateSelectOptionPersist): DescriptionTemplateSelectOptionEditorModel {
if (item) {
this.label = item.label;
this.value = item.value;
}
return this;
}
buildForm(params?: {
context?: ValidationContext,
disabled?: boolean,
rootPath?: string
}): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) {
context = DescriptionTemplateSelectOptionEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath
});
}
return this.formBuilder.group({
label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators],
value: [{ value: this.value, disabled: disabled }, context.getValidation('value').validators],
});
}
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'label', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}label`)] });
baseValidationArray.push({ key: 'value', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}value`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = DescriptionTemplateSelectOptionEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['label', 'value'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
})
}
}
// //
// //
// Upload Field // Upload Field
// //
// //
export class DescriptionTemplateUploadFieldEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateUploadDataPersist { export class DescriptionTemplateUploadDataEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateUploadDataPersist {
types: DescriptionTemplateUploadOptionEditorModel[] = []; types: DescriptionTemplateUploadOptionEditorModel[] = [];
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
@ -1748,7 +1821,7 @@ export class DescriptionTemplateUploadFieldEditorModel extends DescriptionTempla
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { super(validationErrorModel); } ) { super(validationErrorModel); }
fromModel(item: DescriptionTemplateUploadDataPersist): DescriptionTemplateUploadFieldEditorModel { fromModel(item: DescriptionTemplateUploadDataPersist): DescriptionTemplateUploadDataEditorModel {
if (item) { if (item) {
super.fromModel(item); super.fromModel(item);
if (item.types) { item.types.map(x => this.types.push(new DescriptionTemplateUploadOptionEditorModel(this.validationErrorModel).fromModel(x))); } if (item.types) { item.types.map(x => this.types.push(new DescriptionTemplateUploadOptionEditorModel(this.validationErrorModel).fromModel(x))); }
@ -1763,7 +1836,7 @@ export class DescriptionTemplateUploadFieldEditorModel extends DescriptionTempla
}): UntypedFormGroup { }): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {} let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) { if (context == null) {
context = DescriptionTemplateUploadFieldEditorModel.createValidationContext({ context = DescriptionTemplateUploadDataEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel, validationErrorModel: this.validationErrorModel,
rootPath rootPath
}); });
@ -1877,76 +1950,4 @@ export class DescriptionTemplateUploadOptionEditorModel implements DescriptionTe
control?.addValidators(context.getValidation(keyField).validators); control?.addValidators(context.getValidation(keyField).validators);
}) })
} }
}
export class DescriptionTemplateRuleEditorModel implements DescriptionTemplateRulePersist {
target: string;
value: string;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
) { }
fromModel(item: DescriptionTemplateRule): DescriptionTemplateRuleEditorModel {
if (item) {
this.target = item.target;
this.value = item.value;
}
return this;
}
buildForm(params?: {
context?: ValidationContext,
disabled?: boolean,
rootPath?: string
}): UntypedFormGroup {
let { context = null, disabled = false, rootPath } = params ?? {}
if (context == null) {
context = DescriptionTemplateRuleEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath
});
}
return this.formBuilder.group({
target: [{ value: this.target, disabled: disabled }, context.getValidation('target').validators],
value: [{ value: this.value, disabled: disabled }, context.getValidation('value').validators]
});
}
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
const baseContext: ValidationContext = new ValidationContext();
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'target', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}target`)] });
baseValidationArray.push({ key: 'value', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}value`)] });
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = DescriptionTemplateRuleEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['target', 'value'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
})
}
} }