From 7836ac121874af3f515b7e67be2463516f1c6cb2 Mon Sep 17 00:00:00 2001 From: "CITE\\spapacharalampous" Date: Wed, 28 Aug 2024 16:04:10 +0300 Subject: [PATCH] refactor description template editor, change belongsToTenant on copied items --- ...description-template-editor.component.html | 14 ++--- .../description-template-editor.component.ts | 62 ++++++++++++------- .../description-template-editor.model.ts | 51 +++++++++------ 3 files changed, 77 insertions(+), 50 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..259636957 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 @@ -107,7 +107,7 @@ {{usersMap.get(user?.get('userId')?.value)?.name}} {{enumUtils.toUserDescriptionTemplateRoleString(user?.get('role')?.value)}} - + @@ -123,7 +123,7 @@
- + {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.GENERAL-INFO.DESCRIPTION-TEMPLATE-USERS' | translate}} @@ -147,7 +147,7 @@
-
+
@@ -195,7 +195,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..d2b2448e0 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 @@ -27,7 +27,6 @@ import { AnalyticsService } from '@app/core/services/matomo/analytics-service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { UserService } from '@app/core/services/user/user.service'; import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; -import { FileUtils } from '@app/core/services/utilities/file-utils.service'; import { QueryParamsService } from '@app/core/services/utilities/query-params.service'; import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration'; import { BaseEditor } from '@common/base/base-editor'; @@ -60,9 +59,6 @@ export class DescriptionTemplateEditorComponent extends BaseEditor; toCEntries: ToCEntry[]; @@ -84,6 +78,31 @@ export class DescriptionTemplateEditorComponent extends BaseEditor x === AppPermission.DeleteDescriptionTemplate)); - } - protected get canSave(): boolean { return !this.isDeleted && (this.hasPermission(this.authService.permissionEnum.EditDescriptionTemplate) || this.item?.authorizationFlags?.some(x => x === AppPermission.EditDescriptionTemplate)); } - protected get canFinalize(): boolean { - return !this.isDeleted && (this.hasPermission(this.authService.permissionEnum.EditDescriptionTemplate) || this.item?.authorizationFlags?.some(x => x === AppPermission.EditDescriptionTemplate)); - } - private hasPermission(permission: AppPermission): boolean { return this.authService.hasPermission(permission) || this.editorModel?.permissions?.includes(permission) || this.item?.authorizationFlags?.some(x => x === permission); } @@ -140,7 +151,6 @@ export class DescriptionTemplateEditorComponent extends BaseEditor { this.usersMap.set(obj.user.id, obj.user); }); - this.isDeleted = data ? data.isActive === IsActive.Inactive : false; + this.isDeleted = dataCopy ? dataCopy.isActive === IsActive.Inactive : false; + this.belongsToCurrentTenant = this.isNew || dataCopy.belongsToCurrentTenant; + 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,15 +230,11 @@ export class DescriptionTemplateEditorComponent extends BaseEditor x === AppPermission.EditDescriptionTemplate)), (this.isNew || this.isClone)); + this.formGroup = this.editorModel.buildForm(null, this.hideEditActions, (this.isNew || this.isClone)); 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(); this.formGroup.get('code').disable(); this.formGroup.get('status').setValue(DescriptionTemplateStatus.Draft); } @@ -247,7 +261,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor void): void { - if (this.isNewVersion == false) { + if (!this.isNewVersion) { const formData = this.formService.getValue(this.formGroup.value) as DescriptionTemplatePersist; formData.code = this.formGroup.get('code').getRawValue(); 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..44060e2ab 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 @@ -49,15 +49,16 @@ export class DescriptionTemplateEditorModel extends BaseEditorModel implements D 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], + id: [{ value: this.id, disabled }, context.getValidation('id').validators], + label: [{ value: this.label, 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], + 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.` + rootPath: `definition.`, + disabled }), users: this.formBuilder.array( (this.users ?? []).map( @@ -219,7 +220,8 @@ export class DescriptionTemplateDefinitionEditorModel implements DescriptionTemp pages: this.formBuilder.array( (this.pages ?? []).map( (item, index) => item.buildForm({ - rootPath: `${rootPath}pages[${index}].` + rootPath: `${rootPath}pages[${index}].`, + disabled }) ), context.getValidation('pages').validators ), @@ -299,7 +301,8 @@ export class DescriptionTemplatePageEditorModel implements DescriptionTemplatePa sections: this.formBuilder.array( (this.sections ?? []).map( (item, index) => item.buildForm({ - rootPath: `${rootPath}sections[${index}].` + rootPath: `${rootPath}sections[${index}].`, + disabled }) ), context.getValidation('sections').validators ), @@ -408,14 +411,16 @@ export class DescriptionTemplateSectionEditorModel implements DescriptionTemplat sections: this.formBuilder.array( (this.sections ?? []).map( (item, index) => item.buildForm({ - rootPath: `${rootPath}sections[${index}].` + rootPath: `${rootPath}sections[${index}].`, + disabled }) ), context.getValidation('sections').validators ), fieldSets: this.formBuilder.array( (this.fieldSets ?? []).map( (item, index) => item.buildForm({ - rootPath: `${rootPath}fieldSets[${index}].` + rootPath: `${rootPath}fieldSets[${index}].`, + disabled }) ), context.getValidation('fieldSets').validators ) @@ -540,12 +545,14 @@ export class DescriptionTemplateFieldSetEditorModel implements DescriptionTempla hasCommentField: [{ value: this.hasCommentField, disabled: disabled }, context.getValidation('hasCommentField').validators], hasMultiplicity: [{ value: this.hasMultiplicity, disabled: disabled }, context.getValidation('hasMultiplicity').validators], multiplicity: this.multiplicity.buildForm({ - rootPath: `${rootPath}multiplicity.` + rootPath: `${rootPath}multiplicity.`, + disabled }), fields: this.formBuilder.array( (this.fields ?? []).map( (item, index) => item.buildForm({ - rootPath: `${rootPath}fields[${index}].` + rootPath: `${rootPath}fields[${index}].`, + disabled }) ), context.getValidation('fields').validators ) @@ -745,15 +752,18 @@ export class DescriptionTemplateFieldEditorModel implements DescriptionTemplateF validations: [{ value: this.validations, disabled: disabled }, context.getValidation('validations').validators], includeInExport: [{ value: this.includeInExport, disabled: disabled }, context.getValidation('includeInExport').validators], data: this.data.buildForm({ - rootPath: `${rootPath}data.` + rootPath: `${rootPath}data.`, + disabled }), defaultValue: this.defaultValue.buildForm({ - rootPath: `${rootPath}defaultValue.` + rootPath: `${rootPath}defaultValue.`, + disabled }), visibilityRules: this.formBuilder.array( (this.visibilityRules ?? []).map( (item, index) => item.buildForm({ - rootPath: `${rootPath}visibilityRules[${index}].` + rootPath: `${rootPath}visibilityRules[${index}].`, + disabled }) ), context.getValidation('visibilityRules').validators ) @@ -1350,7 +1360,8 @@ export class DescriptionTemplateRadioBoxDataEditorModel extends DescriptionTempl formGroup.setControl('options', this.formBuilder.array( (this.options ?? []).map( (item, index) => item.buildForm({ - rootPath: `${rootPath}options[${index}].` + rootPath: `${rootPath}options[${index}].`, + disabled }) ), context.getValidation('options').validators )); @@ -1495,7 +1506,8 @@ export class DescriptionTemplateSelectDataEditorModel extends DescriptionTemplat formGroup.setControl('options', this.formBuilder.array( (this.options ?? []).map( (item, index) => item.buildForm({ - rootPath: `${rootPath}options[${index}].` + rootPath: `${rootPath}options[${index}].`, + disabled }) ), context.getValidation('options').validators )); @@ -1654,7 +1666,8 @@ export class DescriptionTemplateUploadDataEditorModel extends DescriptionTemplat formGroup.setControl('types', this.formBuilder.array( (this.types ?? []).map( (item, index) => item.buildForm({ - rootPath: `${rootPath}types[${index}].` + rootPath: `${rootPath}types[${index}].`, + disabled }) ), context.getValidation('types').validators ));