description template validation changes

This commit is contained in:
amentis 2024-02-08 18:47:19 +02:00
parent e5946f90cd
commit 313f5e3b3c
8 changed files with 24 additions and 31 deletions

View File

@ -15,7 +15,7 @@ export class DescriptionTemplateEditorExternalSelectFieldComponent implements On
@Input() form: UntypedFormGroup; @Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel; @Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string; @Input() validationRootPath: string;
methodTypeValues = this.enumUtils.getEnumValues<DescriptionTemplateExternalSelectHttpMethodType>(DescriptionTemplateExternalSelectHttpMethodType); methodTypeValues = this.enumUtils.getEnumValues<DescriptionTemplateExternalSelectHttpMethodType>(DescriptionTemplateExternalSelectHttpMethodType);
authTypeValues = this.enumUtils.getEnumValues<DescriptionTemplateExternalSelectAuthType>(DescriptionTemplateExternalSelectAuthType); authTypeValues = this.enumUtils.getEnumValues<DescriptionTemplateExternalSelectAuthType>(DescriptionTemplateExternalSelectAuthType);
@ -30,14 +30,14 @@ export class DescriptionTemplateEditorExternalSelectFieldComponent implements On
addSource() { addSource() {
const externalDataset = new DescriptionTemplateExternalSelectSourceEditorModel(this.validationErrorModel); const externalDataset = new DescriptionTemplateExternalSelectSourceEditorModel(this.validationErrorModel);
const externalSelectArray = this.form.get('data').get('sources') as UntypedFormArray; const externalSelectArray = this.form.get('data').get('sources') as UntypedFormArray;
externalSelectArray.push(externalDataset.buildForm({rootPath: this.rootPath + 'data.sources[' + externalSelectArray.length + '].'})); externalSelectArray.push(externalDataset.buildForm({rootPath: this.validationRootPath + 'data.sources[' + externalSelectArray.length + '].'}));
} }
removeSource(index: number) { removeSource(index: number) {
(<UntypedFormArray>this.form.get('data').get('sources')).removeAt(index); (<UntypedFormArray>this.form.get('data').get('sources')).removeAt(index);
DescriptionTemplateExternalSelectDataEditorModel.reapplyValidators({ DescriptionTemplateExternalSelectDataEditorModel.reapplyValidators({
formGroup: this.form?.get('data') as UntypedFormGroup, formGroup: this.form?.get('data') as UntypedFormGroup,
rootPath: `${this.rootPath}data.`, rootPath: `${this.validationRootPath}data.`,
validationErrorModel: this.validationErrorModel validationErrorModel: this.validationErrorModel
}); });

View File

@ -12,7 +12,7 @@ export class DescriptionTemplateEditorRadioBoxFieldComponent implements OnInit {
@Input() form: UntypedFormGroup; @Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel; @Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string; @Input() validationRootPath: string;
ngOnInit() { ngOnInit() {
} }
@ -22,7 +22,7 @@ export class DescriptionTemplateEditorRadioBoxFieldComponent implements OnInit {
const selectOptionsArray = this.form.get('data').get('options') as UntypedFormArray; const selectOptionsArray = this.form.get('data').get('options') as UntypedFormArray;
if (!selectOptionsArray) { (<UntypedFormGroup>this.form.get('data')).addControl('options', new UntypedFormBuilder().array([])); } if (!selectOptionsArray) { (<UntypedFormGroup>this.form.get('data')).addControl('options', new UntypedFormBuilder().array([])); }
selectOptionsArray.push(radioListOptions.buildForm({rootPath: this.rootPath + 'data.options[' + selectOptionsArray.length + '].'})); selectOptionsArray.push(radioListOptions.buildForm({rootPath: this.validationRootPath + 'data.options[' + selectOptionsArray.length + '].'}));
} }
deleteRow(intex: number) { deleteRow(intex: number) {
@ -31,7 +31,7 @@ export class DescriptionTemplateEditorRadioBoxFieldComponent implements OnInit {
DescriptionTemplateRadioBoxDataEditorModel.reapplyRadioBoxValidators({ DescriptionTemplateRadioBoxDataEditorModel.reapplyRadioBoxValidators({
formGroup: this.form.get('data') as UntypedFormGroup, formGroup: this.form.get('data') as UntypedFormGroup,
rootPath: `${this.rootPath}data.`, rootPath: `${this.validationRootPath}data.`,
validationErrorModel: this.validationErrorModel validationErrorModel: this.validationErrorModel
}); });

View File

@ -12,7 +12,7 @@ export class DescriptionTemplateEditorSelectFieldComponent implements OnInit {
@Input() form: UntypedFormGroup; @Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel; @Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string; @Input() validationRootPath: string;
ngOnInit() { ngOnInit() {
} }
@ -20,7 +20,7 @@ export class DescriptionTemplateEditorSelectFieldComponent implements OnInit {
addNewRow() { addNewRow() {
const selectOptions: DescriptionTemplateSelectOptionEditorModel = new DescriptionTemplateSelectOptionEditorModel(this.validationErrorModel); const selectOptions: DescriptionTemplateSelectOptionEditorModel = new DescriptionTemplateSelectOptionEditorModel(this.validationErrorModel);
const selectOptionsArray = this.form.get('data').get('options') as UntypedFormArray; const selectOptionsArray = this.form.get('data').get('options') as UntypedFormArray;
selectOptionsArray.push(selectOptions.buildForm({rootPath: this.rootPath + 'data.options[' + selectOptionsArray.length + '].'})); selectOptionsArray.push(selectOptions.buildForm({rootPath: this.validationRootPath + 'data.options[' + selectOptionsArray.length + '].'}));
} }
deleteRow(intex: number) { deleteRow(intex: number) {
@ -29,7 +29,7 @@ export class DescriptionTemplateEditorSelectFieldComponent implements OnInit {
DescriptionTemplateSelectDataEditorModel.reapplySelectValidators({ DescriptionTemplateSelectDataEditorModel.reapplySelectValidators({
formGroup: this.form?.get('data') as UntypedFormGroup, formGroup: this.form?.get('data') as UntypedFormGroup,
rootPath: `${this.rootPath}data.`, rootPath: `${this.validationRootPath}data.`,
validationErrorModel: this.validationErrorModel validationErrorModel: this.validationErrorModel
}); });

View File

@ -47,7 +47,7 @@ export class DescriptionTemplateEditorUploadFieldComponent implements OnInit {
@Input() form: UntypedFormGroup; @Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel; @Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string; @Input() validationRootPath: string;
constructor(private configurationService: ConfigurationService) { } constructor(private configurationService: ConfigurationService) { }
@ -88,7 +88,7 @@ export class DescriptionTemplateEditorUploadFieldComponent implements OnInit {
typeListOptions.fromModel(type); typeListOptions.fromModel(type);
} }
(<UntypedFormGroup>this.form.get('data')).addControl('types', new UntypedFormBuilder().array([])); (<UntypedFormGroup>this.form.get('data')).addControl('types', new UntypedFormBuilder().array([]));
typesArray.push(typeListOptions.buildForm({rootPath: this.rootPath + 'data.types[' + typesArray.length + '].'})); typesArray.push(typeListOptions.buildForm({rootPath: this.validationRootPath + 'data.types[' + typesArray.length + '].'}));
} }
deleteRow(index: number) { deleteRow(index: number) {
@ -98,7 +98,7 @@ export class DescriptionTemplateEditorUploadFieldComponent implements OnInit {
{ {
formGroup: this.form.get('data') as UntypedFormGroup, formGroup: this.form.get('data') as UntypedFormGroup,
validationErrorModel: this.validationErrorModel, validationErrorModel: this.validationErrorModel,
rootPath: `${this.rootPath}data.`, rootPath: `${this.validationRootPath}data.`,
} }
); );

View File

@ -202,7 +202,7 @@
<ng-container *ngIf="form.get('visibilityRules')?.value.length"> <ng-container *ngIf="form.get('visibilityRules')?.value.length">
<h4 class="col-12" style="font-weight: bold">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.RULES-TITLE' | translate}} <h4 class="col-12" style="font-weight: bold">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.RULES-TITLE' | translate}}
</h4> </h4>
<app-description-template-editor-visibility-rule-component class="col-12" [form]="form.get('visibilityRules')" [validationErrorModel]="validationErrorModel" [rootPath]="validationRootPath" [fieldTypeForCheck]="form.get('data').get('fieldType').value" [formArrayOptionsForCheck]="this.form.get('data')?.get('options')" [viewOnly]="viewOnly"></app-description-template-editor-visibility-rule-component> <app-description-template-editor-visibility-rule-component class="col-12" [form]="form.get('visibilityRules')" [validationErrorModel]="validationErrorModel" [validationRootPath]="validationRootPath" [fieldTypeForCheck]="form.get('data').get('fieldType').value" [formArrayOptionsForCheck]="this.form.get('data')?.get('options')" [viewOnly]="viewOnly"></app-description-template-editor-visibility-rule-component>
<!-- <div class="col-12" *ngIf="!viewOnly"> <!-- <div class="col-12" *ngIf="!viewOnly">
<button mat-button class="full-width" (click)="addNewRule()" [disabled]="!form.get('data').get('fieldType').value">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.ACTIONS.ADD-RULE' | translate}}</button> <button mat-button class="full-width" (click)="addNewRule()" [disabled]="!form.get('data').get('fieldType').value">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.ACTIONS.ADD-RULE' | translate}}</button>
</div> --> </div> -->
@ -210,10 +210,10 @@
</div> </div>
<div class="row" [ngSwitch]="form.get('data')?.get('fieldType')?.value" > <div class="row" [ngSwitch]="form.get('data')?.get('fieldType')?.value" >
<app-description-template-editor-external-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.EXTERNAL_SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="validationRootPath"></app-description-template-editor-external-select-field-component> <app-description-template-editor-external-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.EXTERNAL_SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [validationRootPath]="validationRootPath"></app-description-template-editor-external-select-field-component>
<app-description-template-editor-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="validationRootPath"></app-description-template-editor-select-field-component> <app-description-template-editor-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [validationRootPath]="validationRootPath"></app-description-template-editor-select-field-component>
<app-description-template-editor-radio-box-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.RADIO_BOX" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="validationRootPath"></app-description-template-editor-radio-box-field-component> <app-description-template-editor-radio-box-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.RADIO_BOX" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [validationRootPath]="validationRootPath"></app-description-template-editor-radio-box-field-component>
<app-description-template-editor-upload-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.UPLOAD" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="validationRootPath"></app-description-template-editor-upload-field-component> <app-description-template-editor-upload-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.UPLOAD" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [validationRootPath]="validationRootPath"></app-description-template-editor-upload-field-component>
<app-description-template-editor-label-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.BOOLEAN_DECISION" class="col-12" [form]="form"></app-description-template-editor-label-field-component> <app-description-template-editor-label-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.BOOLEAN_DECISION" class="col-12" [form]="form"></app-description-template-editor-label-field-component>
<app-description-template-editor-label-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.CHECK_BOX" class="col-12" [form]="form"></app-description-template-editor-label-field-component> <app-description-template-editor-label-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.CHECK_BOX" class="col-12" [form]="form"></app-description-template-editor-label-field-component>

View File

@ -195,13 +195,13 @@ export class DescriptionTemplateEditorSectionFieldSetComponent implements OnInit
} }
addFieldSetAfter(afterOrdinal: number, afterIndex: number): void { addFieldSetAfter(afterOrdinal: number, afterIndex: number): void {
const field: DescriptionTemplateFieldEditorModel = new DescriptionTemplateFieldEditorModel(); const field: DescriptionTemplateFieldEditorModel = new DescriptionTemplateFieldEditorModel(this.validationErrorModel);
field.id = Guid.create().toString(); field.id = Guid.create().toString();
field.ordinal = 0;//first filed in the fields list field.ordinal = 0;//first filed in the fields list
const fieldForm = field.buildForm(); const fieldForm = field.buildForm({rootPath: this.validationRootPath + '.fieldSets[' + this.form.length + ']' + '.fields[' + 0 + '].'});
//give fieldset id and ordinal //give fieldset id and ordinal
const fieldSet: DescriptionTemplateFieldSetEditorModel = new DescriptionTemplateFieldSetEditorModel(); const fieldSet: DescriptionTemplateFieldSetEditorModel = new DescriptionTemplateFieldSetEditorModel(this.validationErrorModel);
const fieldSetId = Guid.create().toString(); const fieldSetId = Guid.create().toString();
fieldSet.id = fieldSetId; fieldSet.id = fieldSetId;
fieldSet.ordinal = afterOrdinal < 0 ? 0 : afterOrdinal; fieldSet.ordinal = afterOrdinal < 0 ? 0 : afterOrdinal;
@ -215,7 +215,7 @@ export class DescriptionTemplateEditorSectionFieldSetComponent implements OnInit
ordinalControl.setValue(ordinalValue + 1); ordinalControl.setValue(ordinalValue + 1);
} }
}); });
const fieldsetForm = fieldSet.buildForm(); const fieldsetForm = fieldSet.buildForm({rootPath: this.validationRootPath + '.fieldSets[' + this.form.length + '].'});
(fieldsetForm.get('fields') as UntypedFormArray).push(fieldForm); (fieldsetForm.get('fields') as UntypedFormArray).push(fieldForm);
const index = afterOrdinal < 0 ? 0 : afterIndex + 1; const index = afterOrdinal < 0 ? 0 : afterIndex + 1;

View File

@ -22,7 +22,7 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
@Input() formArrayOptionsForCheck: UntypedFormArray; @Input() formArrayOptionsForCheck: UntypedFormArray;
@Input() viewOnly: boolean; @Input() viewOnly: boolean;
@Input() validationErrorModel: ValidationErrorModel; @Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string; @Input() validationRootPath: string;
options: OptionItem[]; options: OptionItem[];
@ -48,7 +48,7 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
this.form.controls?.forEach( this.form.controls?.forEach(
(control, index) => DescriptionTemplateRuleEditorModel.reapplyValidators({ (control, index) => DescriptionTemplateRuleEditorModel.reapplyValidators({
formGroup: control as UntypedFormGroup, formGroup: control as UntypedFormGroup,
rootPath: `${this.rootPath}visibilityRules[${index}].`, rootPath: `${this.validationRootPath}visibilityRules[${index}].`,
validationErrorModel: this.validationErrorModel validationErrorModel: this.validationErrorModel
}) })
); );

View File

@ -70,7 +70,6 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
usersMap: Map<Guid, User> = new Map<Guid, User>(); usersMap: Map<Guid, User> = new Map<Guid, User>();
userFormControl = new FormControl(); userFormControl = new FormControl();
rootPath: string = null;
// selectedSystemFields: Array<DescriptionTemplateSystemFieldType> = []; // selectedSystemFields: Array<DescriptionTemplateSystemFieldType> = [];
@ -632,9 +631,6 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
} }
//store rootPath for next levels/components
this.rootPath = 'definition.pages[' + pageIndex + '].sections[' + sectionsArray.length + '].';
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages[' + pageIndex + '].sections[' + sectionsArray.length + '].' })); sectionsArray.push(section.buildForm({ rootPath: 'definition.pages[' + pageIndex + '].sections[' + sectionsArray.length + '].' }));
// this.form.updateValueAndValidity(); // this.form.updateValueAndValidity();
@ -664,9 +660,6 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
section.ordinal = sectionsArray.length; section.ordinal = sectionsArray.length;
} }
//store rootPath for next levels/components
this.rootPath = 'definition.pages[' + pageIndex + '].' + parentSectionRootPath;
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages[' + pageIndex + '].' + parentSectionRootPath + 'sections[' + sectionsArray.length + '].' })); sectionsArray.push(section.buildForm({ rootPath: 'definition.pages[' + pageIndex + '].' + parentSectionRootPath + 'sections[' + sectionsArray.length + '].' }));
// (child.form.parent as FormArray).push(section.buildForm()); // (child.form.parent as FormArray).push(section.buildForm());
@ -709,7 +702,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
field.ordinal = 0;//first filed in the fields list field.ordinal = 0;//first filed in the fields list
const fieldSetsArray = parent.form.get('fieldSets') as UntypedFormArray const fieldSetsArray = parent.form.get('fieldSets') as UntypedFormArray
const fieldForm = field.buildForm({ rootPath: this.rootPath + 'fields[' + 0 + '].' }); const fieldForm = field.buildForm({ rootPath:'definition.pages[' + pageIndex + '].' + parentSectionRootPath + 'fieldSets[' + fieldSetsArray.length + '].' + 'fields[' + 0 + '].' });
//give fieldset id and ordinal //give fieldset id and ordinal
const fieldSet: DescriptionTemplateFieldSetEditorModel = new DescriptionTemplateFieldSetEditorModel(this.editorModel.validationErrorModel); const fieldSet: DescriptionTemplateFieldSetEditorModel = new DescriptionTemplateFieldSetEditorModel(this.editorModel.validationErrorModel);