From 1bf3fae0b8c53ad088fc5fe779bbbc15d14b9cf4 Mon Sep 17 00:00:00 2001 From: mchouliara Date: Wed, 28 Aug 2024 12:43:45 +0300 Subject: [PATCH] refactor plan blueprint editor, change belongsToTenant on copied items --- .../plan-blueprint-editor.component.html | 44 ++++----- .../editor/plan-blueprint-editor.component.ts | 91 ++++++++++--------- .../editor/plan-blueprint-editor.model.ts | 10 +- 3 files changed, 76 insertions(+), 69 deletions(-) diff --git a/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.html b/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.html index c1f888f8b..e6d22caff 100644 --- a/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.html +++ b/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.html @@ -5,17 +5,17 @@
-
+
-
+
-
- +
+
@@ -52,8 +52,8 @@
drag_indicator
-
-
@@ -77,8 +77,8 @@ {{'GENERAL.VALIDATION.REQUIRED' | translate}}
-
- +
+
@@ -90,8 +90,8 @@ {{fieldIndex + 1}} drag_indicator
-
-
@@ -190,8 +190,8 @@ -
-
@@ -216,8 +216,8 @@ {{section.get('hasTemplates').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} -
- +
+
@@ -233,8 +233,8 @@ {{descriptionTemplateIndex + 1}} drag_indicator -
-
@@ -283,8 +283,8 @@
-
-
@@ -318,8 +318,8 @@
-
- +
+ {{'PLAN-BLUEPRINT-EDITOR.SECTIONS-REQUIRED' | translate}} {{formGroup.get('definition').get('sections').getError('backendError').message}}
@@ -331,8 +331,8 @@
-
-
diff --git a/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.ts b/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.ts index 5a38ad836..522004cc9 100644 --- a/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.ts +++ b/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.ts @@ -55,10 +55,6 @@ import { RouterUtilsService } from '@app/core/services/router/router-utils.servi }) export class PlanBlueprintEditorComponent extends BaseEditor implements OnInit { - isNew = true; - isClone = false; - isNewVersion = false; - isDeleted = false; formGroup: UntypedFormGroup = null; showInactiveDetails = false; @@ -74,22 +70,31 @@ export class PlanBlueprintEditorComponent extends BaseEditor = new Map; public descriptionTemplateGroupIdsConfigBySection: Map = new Map; - protected get canDelete(): boolean { - return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeletePlanBlueprint); - } + PlanBlueprintStatus = PlanBlueprintStatus; + isNew = true; + isClone = false; + isNewVersion = false; + isDeleted = false; + belongsToCurrentTenant = true; - protected get canSave(): boolean { - if (this.isDeleted || !this.hasPermission(this.authService.permissionEnum.EditPlanBlueprint)) return false; - if (this.isNewVersion) return this.canCreateNewVersion; - return !this.formGroup.disabled; + protected get isTransient(): boolean { + return this.isNew || this.isClone || this.isNewVersion; + } + + protected get hideEditActions(): boolean { + return this.isDeleted || this.isFinalized || !this.authService.hasPermission(AppPermission.EditPlanBlueprint) || !this.belongsToCurrentTenant; + } + + protected get canDownloadXML(): boolean { + return (this.formGroup.get('status').value === PlanBlueprintStatus.Finalized) && !this.isTransient; + } + + protected get canDelete(): boolean { + return !this.isTransient && this.hasPermission(this.authService.permissionEnum.DeletePlanBlueprint); } protected get canFinalize(): boolean { - return !this.isNewVersion && !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditPlanBlueprint); - } - - protected get canCreateNewVersion(): boolean { - return this.isFinalized; + return !this.isTransient && !this.isFinalized; } protected get isFinalized(): boolean { @@ -167,16 +172,22 @@ export class PlanBlueprintEditorComponent extends BaseEditor void) { this.planBlueprintService.getSingle(itemId, PlanBlueprintEditorResolver.lookupFields()) .pipe(map(data => data as PlanBlueprint), takeUntil(this._destroyed)) - .subscribe( - data => successFunction(data), - error => this.onCallbackError(error) - ); + .subscribe({ + next: (data) => successFunction(data), + error: (error) => this.onCallbackError(error) + }); } prepareForm(data: PlanBlueprint) { try { - this.editorModel = data ? new PlanBlueprintEditorModel().fromModel(data) : new PlanBlueprintEditorModel(); - this.isDeleted = data ? data.isActive === IsActive.Inactive : false; + const dataCopy = data ? JSON.parse(JSON.stringify(data)) : null; + if(dataCopy && this.isClone) { + dataCopy.belongsToCurrentTenant = true; + } + this.editorModel = dataCopy ? new PlanBlueprintEditorModel().fromModel(dataCopy) : new PlanBlueprintEditorModel(); + 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.PlanBlueprint, 'PLAN-BLUEPRINT-EDITOR.LOCKED-DIALOG.TITLE', 'PLAN-BLUEPRINT-EDITOR.LOCKED-DIALOG.MESSAGE'); @@ -194,13 +205,9 @@ export class PlanBlueprintEditorComponent extends BaseEditor void): void { - if (this.isNewVersion == false) { + if (!this.isNewVersion) { const formData = this.formService.getValue(this.formGroup.value) as PlanBlueprintPersist; formData.code = this.formGroup.get('code').getRawValue(); this.planBlueprintService.persist(formData) - .pipe(takeUntil(this._destroyed)).subscribe( - complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), - error => { + .pipe(takeUntil(this._destroyed)).subscribe({ + next: (complete) => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), + error: (error) => { this.formGroup.get('status').setValue(PlanBlueprintStatus.Draft); this.onCallbackError(error); } - ); - } else if (this.isNewVersion == true && this.isNew == false && this.isClone == false) { + }); + } else if (!this.isNew && !this.isClone) { const formData = this.formService.getValue(this.formGroup.value) as NewVersionPlanBlueprintPersist; this.planBlueprintService.newVersion(formData) - .pipe(takeUntil(this._destroyed)).subscribe( - complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), - error => this.onCallbackError(error) - ); + .pipe(takeUntil(this._destroyed)).subscribe({ + next: (complete) => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), + error: (error) => this.onCallbackError(error) + }); } } @@ -269,10 +276,10 @@ export class PlanBlueprintEditorComponent extends BaseEditor { if (result) { this.planBlueprintService.delete(value.id).pipe(takeUntil(this._destroyed)) - .subscribe( - complete => this.onCallbackDeleteSuccess(), - error => this.onCallbackError(error) - ); + .subscribe({ + complete: () => this.onCallbackDeleteSuccess(), + error: (error) => this.onCallbackError(error) + }); } }); } @@ -637,7 +644,7 @@ export class PlanBlueprintEditorComponent extends BaseEditor