dynamically show transaction permission apis from backend

mazdak/UI-2896
Mazdak Gibran 1 month ago
parent 1616545600
commit 3ea351d20d

@ -48,7 +48,7 @@
<tr *ngFor="let item of menuItems; let i = index"> <tr *ngFor="let item of menuItems; let i = index">
<td class="text-muted">{{ i + 1 }}</td> <td class="text-muted">{{ i + 1 }}</td>
<td>{{ item.name | translate }}</td> <td>{{ item.endpoint | translate }}</td>
<td class="text-center"><input type="checkbox" <td class="text-center"><input type="checkbox"
[(ngModel)]="item.checked" /></td> [(ngModel)]="item.checked" /></td>
</tr> </tr>

@ -25,12 +25,7 @@ export class MenuComponent {
showPermissions = false; showPermissions = false;
permissions: PermissionNode[] = []; permissions: PermissionNode[] = [];
saving = false; saving = false;
menuItems = [ menuItems: { endpoint: string; checked: boolean }[] = [];
{ name: 'accountToAccount', endpoint: URIKey.ACCOUNT_TO_ACCOUNT, checked: true },
{ name: 'glToGl', endpoint: URIKey.GL_TO_GL, checked: false },
{ name: 'accountToGl', endpoint: URIKey.ACCOUNT_TO_GL, checked: false },
{ name: 'glToAccount', endpoint: URIKey.GL_TO_ACCOUNT, checked: false }
];
constructor( constructor(
private credentialService: CredentialService, private credentialService: CredentialService,
@ -47,7 +42,21 @@ export class MenuComponent {
ngOnInit() { ngOnInit() {
this.getAllUsers(); this.getAllUsers();
this.loadTransactionEndpoints();
} }
loadTransactionEndpoints() {
this.httpService.requestGET<string[]>(URIKey.TRANSACTION_ENDPOINTS).subscribe((response) => {
if (!(response instanceof HttpErrorResponse)) {
this.menuItems = response.map(endpoint => ({
endpoint,
checked: false
}));
}
});
}
defaultPermissions(): Observable<PermissionNode[]> { defaultPermissions(): Observable<PermissionNode[]> {
return this.httpService.requestGET<PermissionNode[]>('assets/data/sideMenu.json'); return this.httpService.requestGET<PermissionNode[]>('assets/data/sideMenu.json');
} }
@ -88,16 +97,11 @@ onUserChange() {
.filter(p => p.allowed) .filter(p => p.allowed)
.map(p => this.normalizeUrl(p.transactionEndpoint)); // ← normalize .map(p => this.normalizeUrl(p.transactionEndpoint)); // ← normalize
this.uriService.canSubscribe.pipe(
filter(ready => ready === true),
take(1)
).subscribe(() => {
this.menuItems.forEach(item => { this.menuItems.forEach(item => {
const resolvedEndpoint = this.normalizeUrl( item.checked = allowedEndpoints.some(allowed =>
this.uriService.getURIForRequest(item.endpoint) // ← normalize allowed.endsWith(this.normalizeUrl(item.endpoint))
); );
item.checked = allowedEndpoints.includes(resolvedEndpoint);
});
}); });
} else { } else {
@ -151,7 +155,7 @@ savePermissions() {
).subscribe(() => { ).subscribe(() => {
const transactionEndpoints: string[] = this.menuItems const transactionEndpoints: string[] = this.menuItems
.filter(item => item.checked) .filter(item => item.checked)
.map(item => this.uriService.getURIForRequest(item.endpoint)); .map(item => item.endpoint);
const payload = { userId: selectedUser, transactionEndpoints }; const payload = { userId: selectedUser, transactionEndpoints };

@ -21,6 +21,8 @@ export enum URIKey {
ACCOUNT_TO_GL = "ACCOUNT_TO_GL", ACCOUNT_TO_GL = "ACCOUNT_TO_GL",
GL_TO_ACCOUNT = "GL_TO_ACCOUNT", GL_TO_ACCOUNT = "GL_TO_ACCOUNT",
TRANSACTION_PERMISSIONS_ASSIGN = "TRANSACTION_PERMISSIONS_ASSIGN", TRANSACTION_PERMISSIONS_ASSIGN = "TRANSACTION_PERMISSIONS_ASSIGN",
TRANSACTION_PERMISSIONS = "TRANSACTION_PERMISSIONS" TRANSACTION_PERMISSIONS = "TRANSACTION_PERMISSIONS",
TRANSACTION_ENDPOINTS = "TRANSACTION_ENDPOINTS"
} }

@ -116,6 +116,11 @@
"Id": "ENTITY_TRANSACTION_PERMISSIONS", "Id": "ENTITY_TRANSACTION_PERMISSIONS",
"URI": "/transaction-permissions/{userId}", "URI": "/transaction-permissions/{userId}",
"UUID": "TRANSACTION_PERMISSIONS" "UUID": "TRANSACTION_PERMISSIONS"
},
{
"Id": "ENTITY_TRANSACTION_ENDPOINTS",
"URI": "/transaction-permissions/endpoints",
"UUID": "TRANSACTION_ENDPOINTS"
} }
] ]
} }

@ -315,7 +315,7 @@
"exportAllData": "Export All Data", "exportAllData": "Export All Data",
"transactionLogDetails": "Transaction Logs Details", "transactionLogDetails": "Transaction Logs Details",
"USER_UPDATED_SUCCESS": "User Updated Successfully", "USER_UPDATED_SUCCESS": "User Updated Successfully",
"menu": "Menu", "menu": "Transaction Permissions",
"type": "Transaction Type", "type": "Transaction Type",
"ACCOUNT_TO_ACCOUNT": "Account to Account", "ACCOUNT_TO_ACCOUNT": "Account to Account",
"GL_TO_GL": "General Ledger to General Ledger", "GL_TO_GL": "General Ledger to General Ledger",

Loading…
Cancel
Save