mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-06 10:58:48 +00:00
feat: rehauled console (#3525)
* new console * move npm ci to angular build * rel path for assets * local grpc copy * login policy, rm clear views, features rel path * lock Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
co-authored by
Livio Amstutz
parent
00f7dbe875
commit
08ae39ae19
@@ -0,0 +1,85 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
|
||||
import { BehaviorSubject, from, Observable, of } from 'rxjs';
|
||||
import { catchError, finalize, map } from 'rxjs/operators';
|
||||
import { Role } from 'src/app/proto/generated/zitadel/project_pb';
|
||||
import { ManagementService } from 'src/app/services/mgmt.service';
|
||||
|
||||
/**
|
||||
* Data source for the ProjectMembers view. This class should
|
||||
* encapsulate all logic for fetching and manipulating the displayed data
|
||||
* (including sorting, pagination, and filtering).
|
||||
*/
|
||||
export class ProjectRolesDataSource extends DataSource<Role.AsObject> {
|
||||
public totalResult: number = 0;
|
||||
public viewTimestamp!: Timestamp.AsObject;
|
||||
|
||||
public rolesSubject: BehaviorSubject<Role.AsObject[]> = new BehaviorSubject<Role.AsObject[]>([]);
|
||||
private loadingSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
public loading$: Observable<boolean> = this.loadingSubject.asObservable();
|
||||
|
||||
constructor(private mgmtService: ManagementService) {
|
||||
super();
|
||||
}
|
||||
|
||||
public loadRoles(projectId: string, grantId: string, pageIndex: number, pageSize: number, sortDirection?: string): void {
|
||||
const offset = pageIndex * pageSize;
|
||||
|
||||
this.loadingSubject.next(true);
|
||||
if (grantId && projectId) {
|
||||
from(this.mgmtService.listGrantedProjectRoles(projectId, grantId, pageSize, offset))
|
||||
.pipe(
|
||||
map((resp) => {
|
||||
if (resp.details?.totalResult !== undefined) {
|
||||
this.totalResult = resp.details.totalResult;
|
||||
}
|
||||
if (resp.details?.viewTimestamp) {
|
||||
this.viewTimestamp = resp.details.viewTimestamp;
|
||||
}
|
||||
return resp.resultList;
|
||||
}),
|
||||
catchError(() => of([])),
|
||||
finalize(() => this.loadingSubject.next(false)),
|
||||
)
|
||||
.subscribe((roles) => {
|
||||
this.rolesSubject.next(roles);
|
||||
});
|
||||
} else if (projectId) {
|
||||
from(this.mgmtService.listProjectRoles(projectId, pageSize, offset))
|
||||
.pipe(
|
||||
map((resp) => {
|
||||
if (resp.details?.totalResult !== undefined) {
|
||||
this.totalResult = resp.details.totalResult;
|
||||
}
|
||||
if (resp.details?.viewTimestamp) {
|
||||
this.viewTimestamp = resp.details.viewTimestamp;
|
||||
}
|
||||
return resp.resultList;
|
||||
}),
|
||||
catchError(() => of([])),
|
||||
finalize(() => this.loadingSubject.next(false)),
|
||||
)
|
||||
.subscribe((roles) => {
|
||||
this.rolesSubject.next(roles);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect this data source to the table. The table will only update when
|
||||
* the returned stream emits new items.
|
||||
* @returns A stream of the items to be rendered.
|
||||
*/
|
||||
public connect(): Observable<Role.AsObject[]> {
|
||||
return this.rolesSubject.asObservable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the table is being destroyed. Use this function, to clean up
|
||||
* any open connections or free any held resources that were set up during connect.
|
||||
*/
|
||||
public disconnect(): void {
|
||||
this.rolesSubject.complete();
|
||||
this.loadingSubject.complete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<cnsl-refresh-table [showSelectionActionButton]="showSelectionActionButton" *ngIf="projectId"
|
||||
(refreshed)="refreshPage()" [dataSize]="dataSource?.totalResult ?? 0"
|
||||
[emitRefreshOnPreviousRoutes]="['/projects/'+projectId+'/roles/create']" [selection]="selection"
|
||||
[loading]="dataSource?.loading$ | async" [timestamp]="dataSource?.viewTimestamp">
|
||||
|
||||
<ng-template cnslHasRole [hasRole]="['project.role.write:' + projectId, 'project.role.write']" actions>
|
||||
<a *ngIf="actionsVisible" [disabled]="disabled" [routerLink]="[ '/projects', projectId, 'roles', 'create']"
|
||||
color="primary" class="cnsl-action-button" mat-raised-button [attr.data-e2e]="'add-new-role'">
|
||||
<mat-icon class="icon">add</mat-icon>
|
||||
<span>{{ 'ACTIONS.NEW' | translate }}</span>
|
||||
<cnsl-action-keys (actionTriggered)="gotoRouterLink([ '/projects', projectId, 'roles', 'create'])">
|
||||
</cnsl-action-keys>
|
||||
</a>
|
||||
</ng-template>
|
||||
|
||||
<div class="table-wrapper">
|
||||
<table [dataSource]="dataSource" mat-table class="table" matSort aria-label="Elements">
|
||||
<ng-container matColumnDef="select">
|
||||
<th class="selection" mat-header-cell *matHeaderCellDef>
|
||||
<mat-checkbox [disabled]="disabled" color="primary" (change)="$event ? masterToggle() : null"
|
||||
[checked]="selection.hasValue() && isAllSelected()"
|
||||
[indeterminate]="selection.hasValue() && !isAllSelected()">
|
||||
</mat-checkbox>
|
||||
</th>
|
||||
<td class="selection" mat-cell *matCellDef="let row">
|
||||
<mat-checkbox color="primary" [disabled]="disabled" (click)="$event.stopPropagation()"
|
||||
(change)="$event ? selection.toggle(row) : null" [checked]="selection.isSelected(row)">
|
||||
</mat-checkbox>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="key">
|
||||
<th mat-header-cell *matHeaderCellDef> {{ 'PROJECT.ROLE.KEY' | translate }} </th>
|
||||
<td class="pointer" (click)="openDetailDialog(role)" mat-cell *matCellDef="let role">
|
||||
<div class="role-key">
|
||||
<cnsl-project-role-chip [roleName]="role.key">{{ role.key }}
|
||||
</cnsl-project-role-chip>
|
||||
</div>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="displayname">
|
||||
<th mat-header-cell *matHeaderCellDef> {{ 'PROJECT.ROLE.DISPLAY_NAME' | translate }} </th>
|
||||
<td class="pointer" (click)="openDetailDialog(role)" mat-cell *matCellDef="let role"> {{role.displayName}} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="group">
|
||||
<th mat-header-cell *matHeaderCellDef> {{ 'PROJECT.ROLE.GROUP' | translate }} </th>
|
||||
<td mat-cell *matCellDef="let role" class="pointer">
|
||||
<span class="role state" [ngClass]="{'no-selection': !selectionAllowed}" *ngIf="role.group"
|
||||
(click)="selectionAllowed ? selectAllOfGroup(role.group) : openDetailDialog(role)"
|
||||
[matTooltip]="selectionAllowed ? ('PROJECT.ROLE.SELECTGROUPTOOLTIP' | translate: role) : null">{{role.group}}</span>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="creationDate">
|
||||
<th mat-header-cell *matHeaderCellDef> {{ 'PROJECT.ROLE.CREATIONDATE' | translate }} </th>
|
||||
<td class="pointer" (click)="openDetailDialog(role)" mat-cell *matCellDef="let role">
|
||||
<span *ngIf="role?.details?.creationDate">{{role.details.creationDate | timestampToDate |
|
||||
localizedDate: 'dd. MMM, HH:mm' }}</span>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="changeDate">
|
||||
<th mat-header-cell *matHeaderCellDef> {{ 'PROJECT.ROLE.CHANGEDATE' | translate }} </th>
|
||||
<td class="pointer" (click)="openDetailDialog(role)" mat-cell *matCellDef="let role">
|
||||
<span *ngIf="role?.details?.changeDate">{{role.details.changeDate | timestampToDate |
|
||||
localizedDate: 'dd. MMM, HH:mm' }}</span>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="actions" stickyEnd>
|
||||
<th mat-header-cell *matHeaderCellDef class="role-table-actions"></th>
|
||||
<td mat-cell *matCellDef="let role" class="role-table-actions">
|
||||
<cnsl-table-actions>
|
||||
<button actions
|
||||
[disabled]="disabled || (['project.role.delete', 'project.role.delete:' + projectId] | hasRole | async) === false"
|
||||
mat-icon-button color="warn" matTooltip="{{'ACTIONS.DELETE' | translate}}" (click)="deleteRole(role)">
|
||||
<i class="las la-trash"></i>
|
||||
</button>
|
||||
</cnsl-table-actions>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr class="highlight" mat-row *matRowDef="let role; columns: displayedColumns;">
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div *ngIf="(dataSource.loading$ | async) === false && !dataSource?.totalResult" class="no-content-row">
|
||||
<i class="las la-exclamation"></i>
|
||||
<span>{{'PROJECT.ROLE.EMPTY' | translate}}</span>
|
||||
</div>
|
||||
|
||||
<cnsl-paginator #paginator [timestamp]="dataSource?.viewTimestamp" [length]="dataSource.totalResult" [pageSize]="50"
|
||||
(page)="changePage()" [pageSizeOptions]="[25, 50, 100, 250]">
|
||||
</cnsl-paginator>
|
||||
</cnsl-refresh-table>
|
||||
@@ -0,0 +1,48 @@
|
||||
.icon-button {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
.action {
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.margin-neg {
|
||||
margin-left: -1rem;
|
||||
}
|
||||
|
||||
.role {
|
||||
display: inline-block;
|
||||
margin: 0.25rem;
|
||||
cursor: pointer;
|
||||
|
||||
&.no-selection {
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
|
||||
.role-table-actions {
|
||||
width: 50px;
|
||||
}
|
||||
|
||||
.role-key {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.pointer {
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
tr {
|
||||
outline: none;
|
||||
|
||||
button {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
button {
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { MatSortModule } from '@angular/material/sort';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
import { ProjectRolesTableComponent } from './project-roles-table.component';
|
||||
|
||||
describe('ProjectRolesTableComponent', () => {
|
||||
let component: ProjectRolesTableComponent;
|
||||
let fixture: ComponentFixture<ProjectRolesTableComponent>;
|
||||
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ProjectRolesTableComponent],
|
||||
imports: [NoopAnimationsModule, MatSortModule, MatTableModule],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ProjectRolesTableComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should compile', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,145 @@
|
||||
import { SelectionModel } from '@angular/cdk/collections';
|
||||
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatTable } from '@angular/material/table';
|
||||
import { Router } from '@angular/router';
|
||||
import { Role } from 'src/app/proto/generated/zitadel/project_pb';
|
||||
import { ManagementService } from 'src/app/services/mgmt.service';
|
||||
import { ToastService } from 'src/app/services/toast.service';
|
||||
|
||||
import {
|
||||
ProjectRoleDetailComponent,
|
||||
} from '../../pages/projects/owned-projects/project-roles/project-role-detail/project-role-detail.component';
|
||||
import { PaginatorComponent } from '../paginator/paginator.component';
|
||||
import { WarnDialogComponent } from '../warn-dialog/warn-dialog.component';
|
||||
import { ProjectRolesDataSource } from './project-roles-table-datasource';
|
||||
|
||||
@Component({
|
||||
selector: 'cnsl-project-roles-table',
|
||||
templateUrl: './project-roles-table.component.html',
|
||||
styleUrls: ['./project-roles-table.component.scss'],
|
||||
})
|
||||
export class ProjectRolesTableComponent implements OnInit {
|
||||
@Input() public projectId: string = '';
|
||||
@Input() public grantId: string = '';
|
||||
@Input() public disabled: boolean = false;
|
||||
@Input() public actionsVisible: boolean = false;
|
||||
@Input() public selectedKeys: string[] = [];
|
||||
@Input() public showSelectionActionButton: boolean = true;
|
||||
@ViewChild(PaginatorComponent) public paginator!: PaginatorComponent;
|
||||
@ViewChild(MatTable) public table!: MatTable<Role.AsObject>;
|
||||
public dataSource!: ProjectRolesDataSource;
|
||||
public selection: SelectionModel<Role.AsObject> = new SelectionModel<Role.AsObject>(true, []);
|
||||
@Output() public changedSelection: EventEmitter<Array<Role.AsObject>> = new EventEmitter();
|
||||
@Input() public displayedColumns: string[] = ['key', 'displayname', 'group', 'creationDate', 'changeDate', 'actions'];
|
||||
|
||||
constructor(
|
||||
private mgmtService: ManagementService,
|
||||
private toast: ToastService,
|
||||
private dialog: MatDialog,
|
||||
private router: Router,
|
||||
) {
|
||||
this.dataSource = new ProjectRolesDataSource(this.mgmtService);
|
||||
}
|
||||
|
||||
public gotoRouterLink(rL: any) {
|
||||
this.router.navigate(rL);
|
||||
}
|
||||
|
||||
public ngOnInit(): void {
|
||||
this.dataSource.loadRoles(this.projectId, this.grantId, 0, 25, 'asc');
|
||||
|
||||
this.dataSource.rolesSubject.subscribe((roles) => {
|
||||
const selectedRoles: Role.AsObject[] = roles.filter((role) => this.selectedKeys.includes(role.key));
|
||||
this.selection.select(...selectedRoles);
|
||||
});
|
||||
|
||||
this.selection.changed.subscribe(() => {
|
||||
this.changedSelection.emit(this.selection.selected);
|
||||
});
|
||||
}
|
||||
|
||||
public selectAllOfGroup(group: string): void {
|
||||
const groupRoles: Role.AsObject[] = this.dataSource.rolesSubject.getValue().filter((role) => role.group === group);
|
||||
this.selection.select(...groupRoles);
|
||||
}
|
||||
|
||||
private loadRolesPage(): void {
|
||||
this.dataSource.loadRoles(this.projectId, this.grantId, this.paginator.pageIndex, this.paginator.pageSize);
|
||||
}
|
||||
|
||||
public changePage(): void {
|
||||
this.selection.clear();
|
||||
this.loadRolesPage();
|
||||
}
|
||||
|
||||
public isAllSelected(): boolean {
|
||||
const numSelected = this.selection.selected.length;
|
||||
const numRows = this.dataSource.rolesSubject.value.length;
|
||||
return numSelected === numRows;
|
||||
}
|
||||
|
||||
public masterToggle(): void {
|
||||
this.isAllSelected()
|
||||
? this.selection.clear()
|
||||
: this.dataSource.rolesSubject.value.forEach((row: Role.AsObject) => this.selection.select(row));
|
||||
}
|
||||
|
||||
public deleteRole(role: Role.AsObject): void {
|
||||
const dialogRef = this.dialog.open(WarnDialogComponent, {
|
||||
data: {
|
||||
confirmKey: 'ACTIONS.DELETE',
|
||||
cancelKey: 'ACTIONS.CANCEL',
|
||||
titleKey: 'PROJECT.ROLE.DIALOG.DELETE_TITLE',
|
||||
descriptionKey: 'PROJECT.ROLE.DIALOG.DELETE_DESCRIPTION',
|
||||
},
|
||||
width: '400px',
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((resp) => {
|
||||
if (resp) {
|
||||
const index = this.dataSource.rolesSubject.value.findIndex((iter) => iter.key === role.key);
|
||||
|
||||
this.mgmtService.removeProjectRole(this.projectId, role.key).then(() => {
|
||||
this.toast.showInfo('PROJECT.TOAST.ROLEREMOVED', true);
|
||||
|
||||
if (index > -1) {
|
||||
this.dataSource.rolesSubject.value.splice(index, 1);
|
||||
this.dataSource.rolesSubject.next(this.dataSource.rolesSubject.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public removeRole(role: Role.AsObject, index: number): void {
|
||||
this.mgmtService
|
||||
.removeProjectRole(this.projectId, role.key)
|
||||
.then(() => {
|
||||
this.toast.showInfo('PROJECT.TOAST.ROLEREMOVED', true);
|
||||
this.dataSource.rolesSubject.value.splice(index, 1);
|
||||
this.dataSource.rolesSubject.next(this.dataSource.rolesSubject.value);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.toast.showError(error);
|
||||
});
|
||||
}
|
||||
|
||||
public openDetailDialog(role: Role.AsObject): void {
|
||||
this.dialog.open(ProjectRoleDetailComponent, {
|
||||
data: {
|
||||
role,
|
||||
projectId: this.projectId,
|
||||
},
|
||||
width: '400px',
|
||||
});
|
||||
}
|
||||
|
||||
public refreshPage(): void {
|
||||
this.dataSource.loadRoles(this.projectId, this.grantId, this.paginator.pageIndex, this.paginator.pageSize);
|
||||
}
|
||||
|
||||
public get selectionAllowed(): boolean {
|
||||
return this.displayedColumns.includes('select');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { HasRoleModule } from 'src/app/directives/has-role/has-role.module';
|
||||
import { InputModule } from 'src/app/modules/input/input.module';
|
||||
import { PaginatorModule } from 'src/app/modules/paginator/paginator.module';
|
||||
import { RefreshTableModule } from 'src/app/modules/refresh-table/refresh-table.module';
|
||||
import { HasRolePipeModule } from 'src/app/pipes/has-role-pipe/has-role-pipe.module';
|
||||
import { LocalizedDatePipeModule } from 'src/app/pipes/localized-date-pipe/localized-date-pipe.module';
|
||||
import { TimestampToDatePipeModule } from 'src/app/pipes/timestamp-to-date-pipe/timestamp-to-date-pipe.module';
|
||||
|
||||
import { ActionKeysModule } from '../action-keys/action-keys.module';
|
||||
import { ProjectRoleChipModule } from '../project-role-chip/project-role-chip.module';
|
||||
import { TableActionsModule } from '../table-actions/table-actions.module';
|
||||
import { ProjectRolesTableComponent } from './project-roles-table.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [ProjectRolesTableComponent],
|
||||
imports: [
|
||||
CommonModule,
|
||||
MatButtonModule,
|
||||
ProjectRoleChipModule,
|
||||
HasRoleModule,
|
||||
MatTableModule,
|
||||
PaginatorModule,
|
||||
MatDialogModule,
|
||||
InputModule,
|
||||
RouterModule,
|
||||
FormsModule,
|
||||
ActionKeysModule,
|
||||
ReactiveFormsModule,
|
||||
MatIconModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatCheckboxModule,
|
||||
MatTooltipModule,
|
||||
HasRolePipeModule,
|
||||
TranslateModule,
|
||||
TableActionsModule,
|
||||
MatMenuModule,
|
||||
TimestampToDatePipeModule,
|
||||
RefreshTableModule,
|
||||
LocalizedDatePipeModule,
|
||||
],
|
||||
exports: [ProjectRolesTableComponent],
|
||||
})
|
||||
export class ProjectRolesTableModule {}
|
||||
Reference in New Issue
Block a user