From 7319cc7cc9016770d1a07c7c10b4522137e8a79b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Wed, 22 May 2024 14:16:35 +0300 Subject: [PATCH] RED-8872: More readonly tabs in edit dossier, rework to signals --- .../edit-dossier-dialog.component.html | 38 +++--- .../edit-dossier-dialog.component.ts | 117 ++++++++---------- .../src/app/services/permissions.service.ts | 9 +- 3 files changed, 77 insertions(+), 87 deletions(-) diff --git a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/edit-dossier-dialog.component.html b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/edit-dossier-dialog.component.html index e4961c79b..82dc74088 100644 --- a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/edit-dossier-dialog.component.html +++ b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/edit-dossier-dialog.component.html @@ -1,18 +1,18 @@ -
+
-
+
{{ item.sideNavTitle || item.title | translate }} @@ -22,46 +22,46 @@
-
-
- {{ activeNavItem.title | translate }} +
+
+ {{ activeNavItem().title | translate }}
-
+
{{ 'readonly' | translate }}
- +
; + + readonly activeNav: WritableSignal
; + readonly dossier: Signal; + readonly navItems: Signal; + readonly activeNavItem: Signal; + readonly activeComponent: Signal; + readonly noPaddingTab: Signal; + readonly showHeading: Signal; + readonly showActionButtons: Signal; + @ViewChild(EditDossierGeneralInfoComponent) generalInfoComponent: EditDossierGeneralInfoComponent; @ViewChild(EditDossierDownloadPackageComponent) downloadPackageComponent: EditDossierDownloadPackageComponent; @ViewChild(EditDossierDictionaryComponent) dictionaryComponent: EditDossierDictionaryComponent; @ViewChild(EditDossierTeamComponent) membersComponent: EditDossierTeamComponent; @ViewChild(EditDossierAttributesComponent) attributesComponent: EditDossierAttributesComponent; - readonly #currentUser = getCurrentUser(); - #dossier: Dossier; constructor( - readonly iqserPermissionsService: IqserPermissionsService, private readonly _dossiersService: DossiersService, private readonly _permissionsService: PermissionsService, protected readonly _dialogRef: MatDialogRef, @@ -61,72 +63,43 @@ export class EditDossierDialogComponent extends BaseDialogComponent implements A readonly configService: ConfigService, ) { super(_dialogRef, true); - this.dossier$ = this._dossiersService.getEntityChanged$(this._data.dossierId).pipe( - tap(dossier => { - this.#dossier = dossier; - this._initializeNavItems(); - }), - ); - this.activeNav = this._data.section || 'dossierInfo'; - } - - get activeNavItem(): NavItem { - return this.navItems.find(item => item.key === this.activeNav); - } - - get activeComponent(): EditDossierSectionInterface { - return { - dossierInfo: this.generalInfoComponent, - downloadPackage: this.downloadPackageComponent, - dossierDictionary: this.dictionaryComponent, - members: this.membersComponent, - dossierAttributes: this.attributesComponent, - }[this.activeNav]; - } - - get noPaddingTab(): boolean { - return ['dossierAttributes', 'dossierDictionary'].includes(this.activeNav); - } - - get showHeading(): boolean { - return !['dossierAttributes', 'dossierDictionary'].includes(this.activeNav); - } - - get showActionButtons(): boolean { - return ( - (['dossierDictionary'].includes(this.activeNav) && this._permissionsService.canEditDossierDictionary(this.#dossier)) || - (['members'].includes(this.activeNav) && - this.#currentUser.isManager && - this.iqserPermissionsService.has(Roles.dossiers.edit)) || - this._permissionsService.canEditDossier(this.#dossier) - ); + this.dossier = toSignal(this._dossiersService.getEntityChanged$(this._data.dossierId)); + this.navItems = computed(() => this._getNavItems(this.dossier())); + this.activeNav = signal(this._data.section || 'dossierInfo'); + this.activeNavItem = computed(() => this.navItems().find(item => item.key === this.activeNav())); + this.activeComponent = computed(() => this._getActiveComponent(this.activeNav())); + this.noPaddingTab = computed(() => ['dossierAttributes', 'dossierDictionary'].includes(this.activeNav())); + this.showHeading = computed(() => !['dossierAttributes', 'dossierDictionary'].includes(this.activeNav())); + this.showActionButtons = computed(() => !this.activeNavItem().readonly); } get changed(): boolean { - return this.activeComponent?.changed; + return this.activeComponent()?.changed; } get valid(): boolean { - return this.activeComponent?.valid; + return this.activeComponent()?.valid; } get disabled(): boolean { - return this.activeComponent?.disabled; + return this.activeComponent()?.disabled; } ngAfterViewInit() { - if (!this.#dossier.ownerId) { + if (!untracked(this.dossier).ownerId) { this._toaster.error(_('edit-dossier-dialog.missing-owner')); } } async save(options?: SaveOptions) { this._loadingService.start(); - const result = await this.activeComponent.save(); + const result = await untracked(this.activeComponent).save(); this._loadingService.stop(); if (result.success) { - this._toaster.success(_('edit-dossier-dialog.change-successful'), { params: { dossierName: this.#dossier.dossierName } }); + this._toaster.success(_('edit-dossier-dialog.change-successful'), { + params: { dossierName: untracked(this.dossier).dossierName }, + }); } if (result.success && options?.closeAfterSave) { @@ -135,7 +108,7 @@ export class EditDossierDialogComponent extends BaseDialogComponent implements A } revert() { - this.activeComponent.revert(); + untracked(this.activeComponent).revert(); } changeTab(key: Section) { @@ -146,34 +119,44 @@ export class EditDossierDialogComponent extends BaseDialogComponent implements A } else { this.revert(); } - this.activeNav = key; + this.activeNav.set(key); }); } else { - this.activeNav = key; + this.activeNav.set(key); } } - private _initializeNavItems(): void { - this.navItems = [ + private _getActiveComponent(section: Section): EditDossierSectionInterface { + return { + dossierInfo: this.generalInfoComponent, + downloadPackage: this.downloadPackageComponent, + dossierDictionary: this.dictionaryComponent, + members: this.membersComponent, + dossierAttributes: this.attributesComponent, + }[section]; + } + + private _getNavItems(dossier: Dossier): NavItem[] { + return [ { key: 'dossierInfo', title: _('edit-dossier-dialog.nav-items.general-info'), sideNavTitle: _('edit-dossier-dialog.nav-items.dossier-info'), - readonly: !this.#dossier.isActive || !this._permissionsService.canEditDossier(this.#dossier), + readonly: !this._permissionsService.canEditDossier(dossier), helpModeKey: 'edit_dossier_dossier_info_DIALOG', }, { key: 'downloadPackage', title: _('edit-dossier-dialog.nav-items.choose-download'), sideNavTitle: _('edit-dossier-dialog.nav-items.download-package'), - readonly: !this._permissionsService.canEditDossier(this.#dossier), + readonly: !this._permissionsService.canEditDossier(dossier), helpModeKey: 'edit_dossier_download_package_DIALOG', }, { key: 'dossierDictionary', sideNavTitle: _('edit-dossier-dialog.nav-items.dictionary'), title: _('edit-dossier-dialog.nav-items.dossier-dictionary'), - readonly: !this._permissionsService.canEditDossierDictionary(this.#dossier), + readonly: !this._permissionsService.canEditDossierDictionary(dossier), helpModeKey: 'edit_dossier_dossier_dictionary_DIALOG', hide: this.configService.values.IS_DOCUMINE, }, @@ -181,13 +164,13 @@ export class EditDossierDialogComponent extends BaseDialogComponent implements A key: 'members', title: _('edit-dossier-dialog.nav-items.team-members'), sideNavTitle: _('edit-dossier-dialog.nav-items.members'), - readonly: !this._permissionsService.canEditTeamMembers(this.#dossier), + readonly: !this._permissionsService.canEditTeamMembers(dossier), helpModeKey: 'edit_dossier_members_DIALOG', }, { key: 'dossierAttributes', title: _('edit-dossier-dialog.nav-items.dossier-attributes'), - readonly: !this._permissionsService.canEditDossierAttributes(this.#dossier), + readonly: !this._permissionsService.canEditDossierAttributes(dossier), helpModeKey: 'edit_dossier_dossier_attributes_DIALOG', }, ]; diff --git a/apps/red-ui/src/app/services/permissions.service.ts b/apps/red-ui/src/app/services/permissions.service.ts index 05e98f73d..0786aa785 100644 --- a/apps/red-ui/src/app/services/permissions.service.ts +++ b/apps/red-ui/src/app/services/permissions.service.ts @@ -302,7 +302,14 @@ export class PermissionsService { } canEditDossier(dossier: Dossier): boolean { - return this._iqserPermissionsService.has(Roles.dossiers.edit) && this.isManager() && !!dossier?.ownerId; + const dossierTemplate = this._dossierTemplatesService.find(dossier.dossierTemplateId); + return ( + this._iqserPermissionsService.has(Roles.dossiers.edit) && + this.isManager() && + !!dossier?.ownerId && + dossier.isActive && + dossierTemplate.isActive + ); } canEditDossierDictionary(dossier: Dossier): boolean {