fixes
This commit is contained in:
parent
8b5a54814d
commit
5373e2d867
|
@ -1,6 +1,6 @@
|
|||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { DescriptionTemplateRadioBoxDataEditorModel } from '../../../description-template-editor.model';
|
||||
import { DescriptionTemplateRadioBoxOptionEditorModel } from '../../../description-template-editor.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-description-template-editor-radio-box-field-component',
|
||||
|
@ -15,7 +15,7 @@ export class DescriptionTemplateEditorRadioBoxFieldComponent implements OnInit {
|
|||
}
|
||||
|
||||
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([])); }
|
||||
(<UntypedFormArray>this.form.get('data').get('options')).push(radioListOptions.buildForm());
|
||||
}
|
||||
|
|
|
@ -805,9 +805,9 @@ export class DescriptionTemplateFieldEditorModel implements DescriptionTemplateF
|
|||
case DescriptionTemplateFieldType.EXTERNAL_SELECT:
|
||||
return new DescriptionTemplateExternalSelectDataEditorModel(this.validationErrorModel);
|
||||
case DescriptionTemplateFieldType.RADIO_BOX:
|
||||
return new DescriptionTemplateRadioBoxFieldEditorModel(this.validationErrorModel);
|
||||
return new DescriptionTemplateRadioBoxDataEditorModel(this.validationErrorModel);
|
||||
case DescriptionTemplateFieldType.SELECT:
|
||||
return new DescriptionTemplateSelectFieldEditorModel(this.validationErrorModel);
|
||||
return new DescriptionTemplateSelectDataEditorModel(this.validationErrorModel);
|
||||
case DescriptionTemplateFieldType.BOOLEAN_DECISION:
|
||||
case DescriptionTemplateFieldType.CHECK_BOX:
|
||||
case DescriptionTemplateFieldType.FREE_TEXT:
|
||||
|
@ -833,11 +833,11 @@ export class DescriptionTemplateFieldEditorModel implements DescriptionTemplateF
|
|||
case DescriptionTemplateFieldType.SERVICES:
|
||||
case DescriptionTemplateFieldType.RESEARCHERS:
|
||||
case DescriptionTemplateFieldType.ORGANIZATIONS:
|
||||
return new DescriptionTemplateLabelAndMultiplicityFieldEditorModel(this.validationErrorModel);
|
||||
return new DescriptionTemplateLabelAndMultiplicityDataEditorModel(this.validationErrorModel);
|
||||
case DescriptionTemplateFieldType.EXTERNAL_DATASETS:
|
||||
return new DescriptionTemplateExternalDatasetFieldEditorModel(this.validationErrorModel);
|
||||
return new DescriptionTemplateExternalDatasetDataEditorModel(this.validationErrorModel);
|
||||
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 {
|
||||
label: string;
|
||||
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;
|
||||
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||
|
||||
|
@ -954,7 +1026,7 @@ export class DescriptionTemplateLabelAndMultiplicityFieldEditorModel extends Des
|
|||
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||
) { super(validationErrorModel); }
|
||||
|
||||
fromModel(item: DescriptionTemplateLabelAndMultiplicityDataPersist): DescriptionTemplateLabelAndMultiplicityFieldEditorModel {
|
||||
fromModel(item: DescriptionTemplateLabelAndMultiplicityDataPersist): DescriptionTemplateLabelAndMultiplicityDataEditorModel {
|
||||
if (item) {
|
||||
super.fromModel(item);
|
||||
this.multipleSelect = item.multipleSelect;
|
||||
|
@ -969,7 +1041,7 @@ export class DescriptionTemplateLabelAndMultiplicityFieldEditorModel extends Des
|
|||
}): UntypedFormGroup {
|
||||
let { context = null, disabled = false, rootPath } = params ?? {}
|
||||
if (context == null) {
|
||||
context = DescriptionTemplateLabelAndMultiplicityFieldEditorModel.createValidationContext({
|
||||
context = DescriptionTemplateLabelAndMultiplicityDataEditorModel.createValidationContext({
|
||||
validationErrorModel: this.validationErrorModel,
|
||||
rootPath
|
||||
});
|
||||
|
@ -997,7 +1069,7 @@ export class DescriptionTemplateLabelAndMultiplicityFieldEditorModel extends Des
|
|||
}): void {
|
||||
|
||||
const { formGroup, rootPath, validationErrorModel } = params;
|
||||
const context = DescriptionTemplateLabelAndMultiplicityFieldEditorModel.createValidationContext({
|
||||
const context = DescriptionTemplateLabelAndMultiplicityDataEditorModel.createValidationContext({
|
||||
rootPath,
|
||||
validationErrorModel
|
||||
});
|
||||
|
@ -1015,7 +1087,7 @@ export class DescriptionTemplateLabelAndMultiplicityFieldEditorModel extends Des
|
|||
// External Dataset Field
|
||||
//
|
||||
//
|
||||
export class DescriptionTemplateExternalDatasetFieldEditorModel extends DescriptionTemplateLabelAndMultiplicityFieldEditorModel implements DescriptionTemplateExternalDatasetDataPersist {
|
||||
export class DescriptionTemplateExternalDatasetDataEditorModel extends DescriptionTemplateLabelAndMultiplicityDataEditorModel implements DescriptionTemplateExternalDatasetDataPersist {
|
||||
type: DescriptionTemplateFieldDataExternalDatasetType;
|
||||
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||
|
||||
|
@ -1023,7 +1095,7 @@ export class DescriptionTemplateExternalDatasetFieldEditorModel extends Descript
|
|||
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||
) { super(validationErrorModel); }
|
||||
|
||||
fromModel(item: DescriptionTemplateExternalDatasetDataPersist): DescriptionTemplateExternalDatasetFieldEditorModel {
|
||||
fromModel(item: DescriptionTemplateExternalDatasetDataPersist): DescriptionTemplateExternalDatasetDataEditorModel {
|
||||
if (item) {
|
||||
super.fromModel(item);
|
||||
this.type = item.type;
|
||||
|
@ -1038,7 +1110,7 @@ export class DescriptionTemplateExternalDatasetFieldEditorModel extends Descript
|
|||
}): UntypedFormGroup {
|
||||
let { context = null, disabled = false, rootPath } = params ?? {}
|
||||
if (context == null) {
|
||||
context = DescriptionTemplateExternalDatasetFieldEditorModel.createValidationContext({
|
||||
context = DescriptionTemplateExternalDatasetDataEditorModel.createValidationContext({
|
||||
validationErrorModel: this.validationErrorModel,
|
||||
rootPath
|
||||
});
|
||||
|
@ -1066,7 +1138,7 @@ export class DescriptionTemplateExternalDatasetFieldEditorModel extends Descript
|
|||
}): void {
|
||||
|
||||
const { formGroup, rootPath, validationErrorModel } = params;
|
||||
const context = DescriptionTemplateExternalDatasetFieldEditorModel.createValidationContext({
|
||||
const context = DescriptionTemplateExternalDatasetDataEditorModel.createValidationContext({
|
||||
rootPath,
|
||||
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 {
|
||||
label: string;
|
||||
value: string;
|
||||
|
@ -1509,18 +1510,18 @@ export class DescriptionTemplateExternalSelectAuthDataEditorModel implements Des
|
|||
// Radiobox Field
|
||||
//
|
||||
//
|
||||
export class DescriptionTemplateRadioBoxFieldEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateRadioBoxDataPersist {
|
||||
options: DescriptionTemplateRadioBoxDataEditorModel[] = [];
|
||||
export class DescriptionTemplateRadioBoxDataEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateRadioBoxDataPersist {
|
||||
options: DescriptionTemplateRadioBoxOptionEditorModel[] = [];
|
||||
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||
|
||||
constructor(
|
||||
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||
) { super(validationErrorModel); }
|
||||
|
||||
fromModel(item: DescriptionTemplateRadioBoxDataPersist): DescriptionTemplateRadioBoxFieldEditorModel {
|
||||
fromModel(item: DescriptionTemplateRadioBoxDataPersist): DescriptionTemplateRadioBoxDataEditorModel {
|
||||
if (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;
|
||||
}
|
||||
|
@ -1532,7 +1533,7 @@ export class DescriptionTemplateRadioBoxFieldEditorModel extends DescriptionTemp
|
|||
}): UntypedFormGroup {
|
||||
let { context = null, disabled = false, rootPath } = params ?? {}
|
||||
if (context == null) {
|
||||
context = DescriptionTemplateRadioBoxFieldEditorModel.createValidationContext({
|
||||
context = DescriptionTemplateRadioBoxDataEditorModel.createValidationContext({
|
||||
validationErrorModel: this.validationErrorModel,
|
||||
rootPath
|
||||
});
|
||||
|
@ -1541,7 +1542,7 @@ export class DescriptionTemplateRadioBoxFieldEditorModel extends DescriptionTemp
|
|||
const formGroup = super.buildForm({ context, disabled, rootPath });
|
||||
formGroup.setControl('options', this.formBuilder.array(
|
||||
(this.options ?? []).map(
|
||||
(item, index) => new DescriptionTemplateRadioBoxDataEditorModel(
|
||||
(item, index) => new DescriptionTemplateRadioBoxOptionEditorModel(
|
||||
this.validationErrorModel
|
||||
).fromModel(item).buildForm({
|
||||
rootPath: `${rootPath}options[${index}].`
|
||||
|
@ -1567,7 +1568,7 @@ export class DescriptionTemplateRadioBoxFieldEditorModel extends DescriptionTemp
|
|||
}): void {
|
||||
const { validationErrorModel, rootPath, formArray } = params;
|
||||
formArray?.controls?.forEach(
|
||||
(control, index) => DescriptionTemplateRadioBoxDataEditorModel.reapplyValidators({
|
||||
(control, index) => DescriptionTemplateRadioBoxOptionEditorModel.reapplyValidators({
|
||||
formGroup: control as UntypedFormGroup,
|
||||
rootPath: `${rootPath}options[${index}].`,
|
||||
validationErrorModel: validationErrorModel
|
||||
|
@ -1576,7 +1577,7 @@ export class DescriptionTemplateRadioBoxFieldEditorModel extends DescriptionTemp
|
|||
}
|
||||
}
|
||||
|
||||
export class DescriptionTemplateRadioBoxDataEditorModel implements DescriptionTemplateRadioBoxOptionPersist {
|
||||
export class DescriptionTemplateRadioBoxOptionEditorModel implements DescriptionTemplateRadioBoxOptionPersist {
|
||||
label: string;
|
||||
value: string;
|
||||
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||
|
@ -1585,7 +1586,7 @@ export class DescriptionTemplateRadioBoxDataEditorModel implements DescriptionTe
|
|||
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||
) { }
|
||||
|
||||
fromModel(item: DescriptionTemplateRadioBoxOptionPersist): DescriptionTemplateRadioBoxDataEditorModel {
|
||||
fromModel(item: DescriptionTemplateRadioBoxOptionPersist): DescriptionTemplateRadioBoxOptionEditorModel {
|
||||
if (item) {
|
||||
this.label = item.label;
|
||||
this.value = item.value;
|
||||
|
@ -1600,7 +1601,7 @@ export class DescriptionTemplateRadioBoxDataEditorModel implements DescriptionTe
|
|||
}): UntypedFormGroup {
|
||||
let { context = null, disabled = false, rootPath } = params ?? {}
|
||||
if (context == null) {
|
||||
context = DescriptionTemplateRadioBoxDataEditorModel.createValidationContext({
|
||||
context = DescriptionTemplateRadioBoxOptionEditorModel.createValidationContext({
|
||||
validationErrorModel: this.validationErrorModel,
|
||||
rootPath
|
||||
});
|
||||
|
@ -1634,7 +1635,7 @@ export class DescriptionTemplateRadioBoxDataEditorModel implements DescriptionTe
|
|||
}): void {
|
||||
|
||||
const { formGroup, rootPath, validationErrorModel } = params;
|
||||
const context = DescriptionTemplateRadioBoxDataEditorModel.createValidationContext({
|
||||
const context = DescriptionTemplateRadioBoxOptionEditorModel.createValidationContext({
|
||||
rootPath,
|
||||
validationErrorModel
|
||||
});
|
||||
|
@ -1652,7 +1653,7 @@ export class DescriptionTemplateRadioBoxDataEditorModel implements DescriptionTe
|
|||
// Select Field
|
||||
//
|
||||
//
|
||||
export class DescriptionTemplateSelectFieldEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateSelectDataPersist {
|
||||
export class DescriptionTemplateSelectDataEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateSelectDataPersist {
|
||||
options: DescriptionTemplateSelectOptionEditorModel[] = [];
|
||||
multipleSelect: boolean;
|
||||
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||
|
@ -1661,7 +1662,7 @@ export class DescriptionTemplateSelectFieldEditorModel extends DescriptionTempla
|
|||
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||
) { super(validationErrorModel); }
|
||||
|
||||
fromModel(item: DescriptionTemplateSelectDataPersist): DescriptionTemplateSelectFieldEditorModel {
|
||||
fromModel(item: DescriptionTemplateSelectDataPersist): DescriptionTemplateSelectDataEditorModel {
|
||||
if (item) {
|
||||
super.fromModel(item);
|
||||
this.multipleSelect = item.multipleSelect;
|
||||
|
@ -1677,7 +1678,7 @@ export class DescriptionTemplateSelectFieldEditorModel extends DescriptionTempla
|
|||
}): UntypedFormGroup {
|
||||
let { context = null, disabled = false, rootPath } = params ?? {}
|
||||
if (context == null) {
|
||||
context = DescriptionTemplateSelectFieldEditorModel.createValidationContext({
|
||||
context = DescriptionTemplateSelectDataEditorModel.createValidationContext({
|
||||
validationErrorModel: this.validationErrorModel,
|
||||
rootPath
|
||||
});
|
||||
|
@ -1714,7 +1715,7 @@ export class DescriptionTemplateSelectFieldEditorModel extends DescriptionTempla
|
|||
}): void {
|
||||
|
||||
const { formGroup, rootPath, validationErrorModel } = params;
|
||||
const context = DescriptionTemplateSelectFieldEditorModel.createValidationContext({
|
||||
const context = DescriptionTemplateSelectDataEditorModel.createValidationContext({
|
||||
rootPath,
|
||||
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
|
||||
//
|
||||
//
|
||||
export class DescriptionTemplateUploadFieldEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateUploadDataPersist {
|
||||
export class DescriptionTemplateUploadDataEditorModel extends DescriptionTemplateLabelDataEditorModel implements DescriptionTemplateUploadDataPersist {
|
||||
types: DescriptionTemplateUploadOptionEditorModel[] = [];
|
||||
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||
|
||||
|
@ -1748,7 +1821,7 @@ export class DescriptionTemplateUploadFieldEditorModel extends DescriptionTempla
|
|||
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||
) { super(validationErrorModel); }
|
||||
|
||||
fromModel(item: DescriptionTemplateUploadDataPersist): DescriptionTemplateUploadFieldEditorModel {
|
||||
fromModel(item: DescriptionTemplateUploadDataPersist): DescriptionTemplateUploadDataEditorModel {
|
||||
if (item) {
|
||||
super.fromModel(item);
|
||||
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 {
|
||||
let { context = null, disabled = false, rootPath } = params ?? {}
|
||||
if (context == null) {
|
||||
context = DescriptionTemplateUploadFieldEditorModel.createValidationContext({
|
||||
context = DescriptionTemplateUploadDataEditorModel.createValidationContext({
|
||||
validationErrorModel: this.validationErrorModel,
|
||||
rootPath
|
||||
});
|
||||
|
@ -1878,75 +1951,3 @@ export class DescriptionTemplateUploadOptionEditorModel implements DescriptionTe
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue