User and ROle Permission

This commit is contained in:
Mohaimen Hasan 2026-11-17 10:58:33 +06:00
parent 182effa8b5
commit 46ad335dbe
4 changed files with 75 additions and 38 deletions

View File

@ -1,5 +1,5 @@
<app-loading-panel></app-loading-panel>
<kendo-grid [kendoGridBinding]="gridView"
<kendo-grid #rlGrid [kendoGridBinding]="gridView"
class="rl-grid"
kendoGridSelectBy="id"
[pageSize]="20"
@ -34,10 +34,12 @@
</div>
<div class="rl-toolbar__actions">
<button kendoGridExcelCommand type="button" fillMode="outline"
[svgIcon]="apiService.KendoSVGIcon['fileExcel']">Export to Excel</button>
<button kendoGridPDFCommand type="button" fillMode="outline"
[svgIcon]="apiService.KendoSVGIcon['filePdf']">Export to PDF</button>
<!-- Plain buttons, not kendoGridExcelCommand/kendoGridPDFCommand: grid toolbar commands take the
focus on any toolbar click, which steals it from the search box. -->
<button kendoButton type="button" fillMode="outline"
[svgIcon]="apiService.KendoSVGIcon['fileExcel']" (click)="rlGrid.saveAsExcel()">Export to Excel</button>
<button kendoButton type="button" fillMode="outline"
[svgIcon]="apiService.KendoSVGIcon['filePdf']" (click)="rlGrid.saveAsPDF()">Export to PDF</button>
<button kendoButton type="button" themeColor="primary" [svgIcon]="apiService.KendoSVGIcon['plus']" (click)="addHandler()">Add new</button>
</div>
</div>
@ -75,7 +77,10 @@
<button class="k-button k-primary" kendoButton [svgIcon]="apiService.KendoSVGIcon['edit']" (click)="ViewPermission(roles.indexOf(dataItem));">Edit</button>
}
@if (dataItem.roleStatus !=1 && dataItem.roleStatus !=5) {
<button class="k-button k-primary" kendoButton [svgIcon]="apiService.KendoSVGIcon['edit']" (click)="Approve(roles.indexOf(dataItem));">Approve</button>
<button class="k-button k-primary" kendoButton [svgIcon]="apiService.KendoSVGIcon['edit']"
[disabled]="isMakerOf(dataItem)"
[attr.title]="isMakerOf(dataItem) ? 'You made this change, so another user must approve it.' : null"
(click)="Approve(roles.indexOf(dataItem));">Approve</button>
}
</ng-template>
</kendo-grid-command-column>

View File

@ -73,9 +73,29 @@ export class RolePermissionListComponent implements OnInit {
public ngOnInit(): void {
this.selectedRole = new Role();
this.showModal = false;
this.useService.GetCurrentUser().subscribe(
(resp: any) => {
this.currentUserID = resp?.userID;
},
);
this.load();
}
/** Logged-in user's ID: the maker of a pending role cannot approve it. */
currentUserID: number;
/**
* True when the logged-in user made the role's pending change: whoever last edited it, or its
* creator if it was never edited (same rule as the entry dialog and the server). Their Approve is disabled.
*/
isMakerOf(role: Role): boolean {
if (this.currentUserID == undefined || role == undefined) {
return false;
}
const makerID = (role.modifiedBy ?? 0) > 0 ? role.modifiedBy : role.createdBy;
return makerID == this.currentUserID;
}
load() {
this.useService.getAllRoles()

View File

@ -30,13 +30,8 @@
</ng-template>
</kendo-dropdownlist>
<kendo-textbox
class="ul-search"
placeholder="Search login ID or name"
[clearButton]="true"
[value]="searchText"
(valueChange)="onSearch($event)">
</kendo-textbox>
<input kendoTextBox class="ul-search" placeholder="Search login ID or name"
[value]="searchText" (input)="onSearch($event.target.value)" />
<div class="ul-chips" role="group" aria-label="Filter by status">
<button type="button" class="ul-chip" [class.is-selected]="statusFilter === 'all'" (click)="setStatusFilter('all')">
@ -57,13 +52,10 @@
<div class="ul-toolbar__actions">
<button kendoButton type="button" fillMode="flat" [svgIcon]="icons.refresh"
title="Reload list" aria-label="Reload list" (click)="RefreshControl()"></button>
<kendo-dropdownbutton
[data]="exportItems"
[svgIcon]="icons.export"
fillMode="outline"
(itemClick)="onExport($event)">
Export
</kendo-dropdownbutton>
<!-- Plain buttons, not kendoGridExcelCommand/kendoGridPDFCommand: grid toolbar commands take the
focus on any toolbar click, which closed the User type dropdown before it could open. -->
<button kendoButton type="button" fillMode="outline" [svgIcon]="icons.excel" (click)="grid.saveAsExcel()">Export to Excel</button>
<button kendoButton type="button" fillMode="outline" [svgIcon]="icons.pdf" (click)="grid.saveAsPDF()">Export to PDF</button>
<button kendoButton type="button" themeColor="primary" [svgIcon]="icons.add" (click)="addHandler()">Add user</button>
</div>
</div>
@ -92,22 +84,19 @@
<span>{{ dataItem.createdDate | date: 'dd MMM yyyy' }}</span>
}
@if (dataItem.createdByName) {
<span class="ul-muted"> · {{ dataItem.createdByName }}</span>
<span class="ul-badge ul-badge--info ul-created-by" title="Created by"><span class="ul-badge__dot"></span>{{ dataItem.createdByName }}</span>
}
</ng-template>
</kendo-grid-column>
<kendo-grid-column title="" [width]="64" [filterable]="false" [sortable]="false" class="ul-actions-cell" headerClass="ul-actions-cell">
<!-- Same look as the Role page's last column: one button per action. Which actions a row gets
is still decided by actionsFor() (dataItem.actions), and a click still runs onRowAction(). -->
<kendo-grid-column title="Actions" [width]="180" [filterable]="false" [sortable]="false">
<ng-template kendoGridCellTemplate let-dataItem>
<kendo-dropdownbutton
[data]="dataItem.actions"
[svgIcon]="icons.more"
fillMode="flat"
[popupSettings]="{ align: 'right' }"
[attr.aria-label]="'Actions for ' + dataItem.loginID"
title="Actions"
(itemClick)="onRowAction($event, dataItem)">
</kendo-dropdownbutton>
@for (a of dataItem.actions; track a.action) {
<button class="k-button k-primary ul-row-action" kendoButton [svgIcon]="a.svgIcon"
(click)="onRowAction(a, dataItem)">{{ a.text }}</button>
}
</ng-template>
</kendo-grid-column>
@ -139,12 +128,14 @@
</div>
@if (showModal) {
<kendo-dialog (close)="onPopUpClose()" [minWidth]="750" [width]="650">
<kendo-dialog-titlebar>
Add/Edit User
</kendo-dialog-titlebar>
<app-users-entry [inputObject]="_user" (saveCompleted)="saveCompleted($event)"></app-users-entry>
</kendo-dialog>
<div class="blur-background">
<kendo-dialog (close)="onPopUpClose()" [minWidth]="750" [width]="650">
<kendo-dialog-titlebar>
Add/Edit User
</kendo-dialog-titlebar>
<app-users-entry [inputObject]="_user" (saveCompleted)="saveCompleted($event)"></app-users-entry>
</kendo-dialog>
</div>
}
@if (showReason) {

View File

@ -103,9 +103,15 @@
// ---------- grid ----------
:host ::ng-deep .ul-grid {
// The global `.k-dropdownlist { width: 100% !important }` (styles/vendors/kendo/_calendar.scss)
// made the User type dropdown fill the whole toolbar row and pushed the rest onto the next line.
// Keep it compact so dropdown, search, chips and buttons stay on one line, like the Role page.
.ul-type.k-dropdownlist {
width: 170px !important;
}
// Uniform, compact rows
.k-grid-table td {
height: 44px;
padding-top: 4px;
padding-bottom: 4px;
vertical-align: middle;
@ -126,6 +132,11 @@
}
}
// Row action buttons (last column), side by side like the Role page
.ul-row-action + .ul-row-action {
margin-left: 6px;
}
.ul-login {
font-weight: 600;
color: $gray-700;
@ -160,6 +171,12 @@
.ul-badge--warning { background: $userlist-warning-bg; color: $userlist-warning; }
.ul-badge--neutral { background: $userlist-neutral-bg; color: $userlist-neutral; }
.ul-badge--danger { background: $userlist-danger-bg; color: $danger; }
// "Created by" name next to the date in the Created column
.ul-badge--info { background: #E8EEFC; color: #2F4FB5; }
.ul-created-by {
margin-left: 8px;
}
.ul-empty {
padding: 32px 16px;
@ -194,4 +211,8 @@
.ul-search {
width: 100%;
}
:host ::ng-deep .ul-grid .ul-type.k-dropdownlist {
width: 100% !important;
}
}