From a6676647d15f13eda0af59ffe3d5467a5ea41f14 Mon Sep 17 00:00:00 2001 From: mchouliara Date: Wed, 28 Aug 2024 16:36:07 +0300 Subject: [PATCH] WIP refactor description template editor validity checks WIP --- ...description-template-editor.component.html | 26 +++---- .../description-template-editor.component.ts | 70 ++++++++++++------- .../description-template-editor.model.ts | 18 ++--- ...te-table-of-contents-internal-section.html | 6 +- frontend/src/assets/i18n/baq.json | 3 +- frontend/src/assets/i18n/de.json | 3 +- frontend/src/assets/i18n/en.json | 3 +- frontend/src/assets/i18n/es.json | 3 +- frontend/src/assets/i18n/gr.json | 3 +- frontend/src/assets/i18n/hr.json | 3 +- frontend/src/assets/i18n/pl.json | 3 +- frontend/src/assets/i18n/pt.json | 3 +- frontend/src/assets/i18n/sk.json | 3 +- frontend/src/assets/i18n/sr.json | 3 +- frontend/src/assets/i18n/tr.json | 3 +- 15 files changed, 93 insertions(+), 60 deletions(-) diff --git a/frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.html b/frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.html index 0d9e8e54a..7531563b3 100644 --- a/frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.html +++ b/frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.html @@ -32,7 +32,7 @@ - +
@@ -106,8 +106,8 @@ {{usersMap.get(user?.get('userId')?.value)?.name}} {{enumUtils.toUserDescriptionTemplateRoleString(user?.get('role')?.value)}} - - + + @@ -136,7 +136,7 @@
- +
@@ -147,7 +147,7 @@ {{'GENERAL.VALIDATION.REQUIRED' | translate}}
- -
- -
+ @if(!viewOnly &&!selectedTocEntry?.subEntries?.length){ +
+ +
+ {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.ERROR-MESSAGES.FIELD-SELECT-AT-LEAST-ONE-REQUIRED' | translate}} + }
@@ -265,7 +267,7 @@ chevron_left {{'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.PREVIOUS' | translate}} - @@ -278,7 +280,7 @@
- -
diff --git a/frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.ts b/frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.ts index d66162502..b0c5cdb27 100644 --- a/frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.ts +++ b/frontend/src/app/ui/admin/description-template/editor/description-template-editor.component.ts @@ -62,7 +62,6 @@ export class DescriptionTemplateEditorComponent extends BaseEditor x === AppPermission.DeleteDescriptionTemplate)); - } + protected get belongsToCurrentTenant(): boolean { + return this.isNew || this.editorModel?.belongsToCurrentTenant; + } - protected get canSave(): boolean { - return !this.isDeleted && (this.hasPermission(this.authService.permissionEnum.EditDescriptionTemplate) || this.item?.authorizationFlags?.some(x => x === AppPermission.EditDescriptionTemplate)); + protected get isTransient(): boolean { + return this.isNew || this.isClone || this.isNewVersion; + } + + protected get viewOnly(): boolean { + return this.isDeleted || this.isFinalized || !this.hasPermission(AppPermission.EditDescriptionTemplate) || !this.belongsToCurrentTenant; + } + + protected get canDelete(): boolean { + return !this.isDeleted && !this.isTransient && this.belongsToCurrentTenant && (this.hasPermission(this.authService.permissionEnum.DeleteDescriptionTemplate) || this.item?.authorizationFlags?.some(x => x === AppPermission.DeleteDescriptionTemplate)); } protected get canFinalize(): boolean { - return !this.isDeleted && (this.hasPermission(this.authService.permissionEnum.EditDescriptionTemplate) || this.item?.authorizationFlags?.some(x => x === AppPermission.EditDescriptionTemplate)); + return !this.isTransient && !this.isFinalized; } + protected get isFinalized(): boolean { + return this.editorModel?.status == DescriptionTemplateStatus.Finalized; + } + + private hasPermission(permission: AppPermission): boolean { return this.authService.hasPermission(permission) || this.editorModel?.permissions?.includes(permission) || this.item?.authorizationFlags?.some(x => x === permission); } @@ -194,7 +206,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor { this.usersMap.set(obj.user.id, obj.user); }); - this.isDeleted = data ? data.isActive === IsActive.Inactive : false; + this.isDeleted = data?.isActive === IsActive.Inactive; this.buildForm(); if (data && data.id) this.checkLock(data.id, LockTargetType.DescriptionTemplate, 'DESCRIPTION-TEMPLATE-EDITOR.LOCKED-DIALOG.TITLE', 'DESCRIPTION-TEMPLATE-EDITOR.LOCKED-DIALOG.MESSAGE'); @@ -212,12 +224,9 @@ export class DescriptionTemplateEditorComponent extends BaseEditor x === AppPermission.EditDescriptionTemplate)), (this.isNew || this.isClone)); + this.formGroup = this.editorModel.buildForm(null, this.viewOnly); this.descriptionTemplateEditorService.setValidationErrorModel(this.editorModel.validationErrorModel); - this.isFinalized = this.editorModel.status == DescriptionTemplateStatus.Finalized; - if (this.isFinalized || this.isDeleted) { - this.formGroup.disable(); - } + const action = this.route.snapshot.data['action']; if (action && action == 'new-version') { this.formGroup.enable(); @@ -399,14 +408,14 @@ export class DescriptionTemplateEditorComponent extends BaseEditor { - if (stepIndex === index) { - stepCompleted = step.completed; - } - }); + // let stepCompleted = false; + // this.steps.forEach((step, index) => { + // if (stepIndex === index) { + // stepCompleted = step.completed; + // } + // }); - return stepCompleted; + return this.steps.toArray().at(stepIndex)?.completed; } isStepUnlocked(stepIndex: number): boolean { @@ -434,11 +443,9 @@ export class DescriptionTemplateEditorComponent extends BaseEditorthis.formGroup.get('definition').get('pages'))?.length; } - checkFormValidation() { - this.colorizeInvalid = true; + checkFormValidation(index: number) { + switch(index){ + case 0: { + this.colorizeInvalid = true; + break; + } + case 1: { + this.showErrors = true; + break; + } + } } get progressStyle() { diff --git a/frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts b/frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts index 0f37dde27..8d301ef12 100644 --- a/frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts +++ b/frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts @@ -45,17 +45,17 @@ export class DescriptionTemplateEditorModel extends BaseEditorModel implements D return this; } - buildForm(context: ValidationContext = null, disabled: boolean = false, isNewOrClone: boolean = false): UntypedFormGroup { + buildForm(context: ValidationContext = null, disabled: boolean = false): UntypedFormGroup { if (context == null) { context = this.createValidationContext(); } return this.formBuilder.group({ - id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators], - label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators], - code: [{ value: this.code, disabled: !isNewOrClone }, context.getValidation('code').validators], - description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators], - language: [{ value: this.language, disabled: disabled }, context.getValidation('language').validators], - type: [{ value: this.type, disabled: disabled }, context.getValidation('type').validators], - status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators], + id: [{ value: this.id, disabled }, context.getValidation('id').validators], + label: [{ value: this.label, disabled }, context.getValidation('label').validators], + code: [{ value: this.code, disabled: !!this.id ?? disabled }, context.getValidation('code').validators], + description: [{ value: this.description, disabled }, context.getValidation('description').validators], + language: [{ value: this.language, disabled }, context.getValidation('language').validators], + type: [{ value: this.type, disabled }, context.getValidation('type').validators], + status: [{ value: this.status, disabled }, context.getValidation('status').validators], definition: this.definition.buildForm({ rootPath: `definition.` }), @@ -66,7 +66,7 @@ export class DescriptionTemplateEditorModel extends BaseEditorModel implements D }) ), context.getValidation('users').validators ), - hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators] + hash: [{ value: this.hash, disabled }, context.getValidation('hash').validators] }); } diff --git a/frontend/src/app/ui/admin/description-template/editor/table-of-contents/table-of-contents-internal-section/description-template-table-of-contents-internal-section.html b/frontend/src/app/ui/admin/description-template/editor/table-of-contents/table-of-contents-internal-section/description-template-table-of-contents-internal-section.html index 21fc3b603..6694f32b1 100644 --- a/frontend/src/app/ui/admin/description-template/editor/table-of-contents/table-of-contents-internal-section/description-template-table-of-contents-internal-section.html +++ b/frontend/src/app/ui/admin/description-template/editor/table-of-contents/table-of-contents-internal-section/description-template-table-of-contents-internal-section.html @@ -1,7 +1,11 @@