From 7403e4d81de0c87311f48084236c18fc3f8f5f08 Mon Sep 17 00:00:00 2001 From: Mazdak Gibran <141390141+mazdakgibran@users.noreply.github.com> Date: Tue, 7 Apr 2026 10:47:56 +0500 Subject: [PATCH] Update menu.component.ts --- src/app/menu/menu.component.ts | 57 ++++++---------------------------- 1 file changed, 9 insertions(+), 48 deletions(-) diff --git a/src/app/menu/menu.component.ts b/src/app/menu/menu.component.ts index 5df2f5c..8de6097 100644 --- a/src/app/menu/menu.component.ts +++ b/src/app/menu/menu.component.ts @@ -36,7 +36,7 @@ export class MenuComponent { ) { this.permission = this.fb.group({ userCode: [null] }); this.defaultPermissions().subscribe((data: PermissionNode[]) => { - this.permissions = data; // needed for savePermissions + this.permissions = data; }); } @@ -71,19 +71,7 @@ export class MenuComponent { } }); } -// mapEndpointsToPermissions(endpoints: string[]): PermissionNode[] { -// return [{ -// name: 'menu', -// checked: false, -// expanded: false, -// children: [ -// { name: 'accountToAccount', checked: endpoints.includes(this.uriService.getURIForRequest(URIKey.ACCOUNT_TO_ACCOUNT)), expanded: false }, -// { name: 'glToGl', checked: endpoints.includes(this.uriService.getURIForRequest(URIKey.GL_TO_GL)), expanded: false }, -// { name: 'accountToGl', checked: endpoints.includes(this.uriService.getURIForRequest(URIKey.ACCOUNT_TO_GL)), expanded: false }, -// { name: 'glToAccount', checked: endpoints.includes(this.uriService.getURIForRequest(URIKey.GL_TO_ACCOUNT)), expanded: false } -// ] -// }]; -// } + onUserChange() { this.showPermissions = true; const userId = this.permission.get('userCode')?.value; @@ -110,41 +98,12 @@ onUserChange() { }); } -// Add this helper method to the class private normalizeUrl(url: string): string { return url?.trim().toLowerCase().replace(/\/+$/, ''); // trim, lowercase, remove trailing slash } - -// savePermissions() { -// const selectedUser = this.permission.get('userCode')?.value; -// const menuNode = this.permissions.find(x => x.name === 'menu'); -// if (!menuNode) return; - -// const nameToURIKey: { [key: string]: URIKey } = { -// accountToAccount: URIKey.ACCOUNT_TO_ACCOUNT, -// glToGl: URIKey.GL_TO_GL, -// accountToGl: URIKey.ACCOUNT_TO_GL, -// glToAccount: URIKey.GL_TO_ACCOUNT -// }; - -// const transactionEndpoints: string[] = (menuNode.children || []) -// .filter(c => c.checked) -// .map(c => this.uriService.getURIForRequest(nameToURIKey[c.name])); - -// const payload = { userId: selectedUser, transactionEndpoints, permissions: JSON.stringify(this.permissions) }; - -// this.httpService.requestPOST(URIKey.TRANSACTION_PERMISSIONS_ASSIGN, payload).subscribe((response: any) => { -// if (!(response instanceof HttpErrorResponse)) { -// this.i18nService.success(SuccessMessages.SAVED_SUCCESSFULLY, []); -// this.permission.get('userCode')?.setValue(selectedUser); -// this.onUserChange(); -// } -// }); -// } - savePermissions() { - if (this.saving) return; // ← guard against double clicks + if (this.saving) return; this.saving = true; const selectedUser = this.permission.get('userCode')?.value; @@ -157,7 +116,11 @@ savePermissions() { .filter(item => item.checked) .map(item => item.endpoint); - const payload = { userId: selectedUser, transactionEndpoints }; + const payload = { + porOrgacode: this.credentialService.getPorOrgacode(), + userId: selectedUser, + transactionEndpoints + }; this.httpService.requestPOST(URIKey.TRANSACTION_PERMISSIONS_ASSIGN, payload) .subscribe({ @@ -183,9 +146,7 @@ savePermissions() { if (savedNode) { // Update state from saved node existingNode.checked = savedNode.checked; - //existingNode.expanded = savedNode.expanded; - - // Recursively update children if they exist + if (existingNode.children) { this.updatePermissions(savedNode.children || [], existingNode.children); }