User and group details, add paginator and filter on permissions list

This commit is contained in:
Lebeau Elise 2022-02-03 15:42:13 +00:00 committed by Sylvain MATHIEU
parent 7bff9b40de
commit 5102039dbd
13 changed files with 78 additions and 64 deletions

View File

@ -310,7 +310,6 @@ import { DeletePermissionDialogComponent } from './components/permissions-manage
import { AddRoleToGroupComponent } from './components/group-details/add-role-to-group/add-role-to-group.component'; import { AddRoleToGroupComponent } from './components/group-details/add-role-to-group/add-role-to-group.component';
import {MatFormFieldModule} from "@angular/material/form-field"; import {MatFormFieldModule} from "@angular/material/form-field";
import { PermissionsFilterPipe } from './components/permissions-management/permissions-filter.pipe'; import { PermissionsFilterPipe } from './components/permissions-management/permissions-filter.pipe';
import { PermissionsTypeFilterPipe } from './components/permissions-management/permissions-type-filter.pipe';
import { DisplayPathPipe } from './components/permissions-management/display-path.pipe'; import { DisplayPathPipe } from './components/permissions-management/display-path.pipe';
import {RolePermissionsComponent} from "@components/role-management/role-detail/role-permissions/role-permissions.component"; import {RolePermissionsComponent} from "@components/role-management/role-detail/role-permissions/role-permissions.component";
@ -535,10 +534,11 @@ import {RolePermissionsComponent} from "@components/role-management/role-detail/
FilterCompletePipe, FilterCompletePipe,
UserPermissionsComponent, UserPermissionsComponent,
PermissionsFilterPipe, PermissionsFilterPipe,
PermissionsTypeFilterPipe,
FilterCompletePipe, FilterCompletePipe,
DisplayPathPipe, DisplayPathPipe,
RolePermissionsComponent RolePermissionsComponent,
DisplayPathPipe,
PermissionsFilterPipe,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

View File

@ -5,32 +5,21 @@
(addPermissionEvent)="refresh()"></app-add-permission-line> (addPermissionEvent)="refresh()"></app-add-permission-line>
</div> </div>
<div class="permission-content default-content"> <div class="permission-content default-content">
<input type="text"
matInput
name="typeInput"
placeholder="Search by name"
[(ngModel)]="searchPermissions"
[matAutocomplete]="auto"
class="permission-filter"
(input)="changeAutocomplete($event.target.value)">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
<mat-option *ngFor="let option of filteredOptions | filterComplete: searchPermissions" [value]="option">
{{option.name}}
</mat-option>
</mat-autocomplete>
<div *ngFor="let permission of permissions | permissionsFilter: searchPermissions?.id | paginator: pageEvent">
Filter :
<mat-select [(ngModel)]="typeFilter" name="type" placeholder="Type"
(selectionChange)="changeType($event)"
class="permission-filter">
<mat-option [value]="{value:'/', view:'/'}" selected>All</mat-option>
<mat-option *ngFor="let elt of typeValues" [value]="elt">{{elt.view}}</mat-option>
</mat-select>
<input type="text"
matInput
name="typeInput"
placeholder="Search by name"
[(ngModel)]="searchPermissions"
[matAutocomplete]="auto"
class="permission-filter"
(input)="changeAutocomplete($event.target.value)">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
<mat-option *ngFor="let option of filteredOptions | filterComplete: searchPermissions" [value]="option">
{{option.name}}
</mat-option>
</mat-autocomplete>
<div *ngFor="let permission of permissions | permissionsTypeFilter: typeFilter?.view | permissionsFilter: searchPermissions?.id | paginator: pageEvent">
<app-permission-add-edit-line <app-permission-add-edit-line
[permission]="permission" [permission]="permission"
[server]="server" [server]="server"

View File

@ -31,7 +31,6 @@
.permission-filter { .permission-filter {
border-bottom: 1px solid; border-bottom: 1px solid;
width : 200px;
margin: 5px; margin: 5px;
border-bottom-color: #b0bec5; border-bottom-color: #b0bec5;
} }

View File

@ -35,12 +35,6 @@ export class PermissionsManagementComponent implements OnInit {
pageEvent: PageEvent | undefined; pageEvent: PageEvent | undefined;
filteredOptions: IFormatedList[]; filteredOptions: IFormatedList[];
options: string[] = []; options: string[] = [];
typeFilter: any;
typeValues = [
{value: '{project_id}', view:'projects'},
{value: '{image_path}', view:'images'},
{value: '{template_id}', view:'templates'},
{value: '{compute_id}', view:'computes'}]
@ViewChild('dynamic', { @ViewChild('dynamic', {
read: ViewContainerRef read: ViewContainerRef
@ -74,18 +68,6 @@ export class PermissionsManagementComponent implements OnInit {
); );
} }
changeType(typeValue: any) {
if (typeValue.value.value.match(this.apiInformationService.bracketIdRegex)) {
this.apiInformationService.getListByObjectId(this.server, typeValue.value.value)
.subscribe((data) => {
this.filteredOptions = data;
});
} else {
this.filteredOptions = this.apiInformationService.getIdByObjNameFromCache('');
}
}
displayFn(value): string { displayFn(value): string {
return value && value.name ? value.name : ''; return value && value.name ? value.name : '';
} }

View File

@ -1,8 +0,0 @@
import { PermissionsTypeFilterPipe } from './permissions-type-filter.pipe';
describe('PermissionsTypeFilterPipe', () => {
it('create an instance', () => {
const pipe = new PermissionsTypeFilterPipe();
expect(pipe).toBeTruthy();
});
});

View File

@ -11,4 +11,5 @@
<button *ngIf="side === 'LEFT'" mat-button (click)="onClick()"> <button *ngIf="side === 'LEFT'" mat-button (click)="onClick()">
<mat-icon>keyboard_arrow_right</mat-icon> <mat-icon>keyboard_arrow_right</mat-icon>
</button> </button>
</div> </div>

View File

@ -28,8 +28,7 @@ export class EditablePermissionComponent implements OnInit {
constructor() { } constructor() { }
ngOnInit(): void { ngOnInit(): void {}
}
onClick() { onClick() {

View File

@ -9,6 +9,19 @@
</div> </div>
<div class="box deny"></div> <div class="box deny"></div>
</div> </div>
<input type="text"
matInput
name="typeInput"
placeholder="Search by name"
[(ngModel)]="searchPermissions"
[matAutocomplete]="auto"
class="permission-filter"
(input)="changeAutocomplete($event.target.value)">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
<mat-option *ngFor="let option of filteredOptions | filterComplete: searchPermissions" [value]="option">
{{option.name}}
</mat-option>
</mat-autocomplete>
<div> <div>
<button <button
mat-button mat-button
@ -23,6 +36,8 @@
</button> </button>
</div> </div>
</div> </div>
<div class="editor"> <div class="editor">
<div class="column"> <div class="column">
<div class="title">Owned</div> <div class="title">Owned</div>
@ -31,9 +46,11 @@
[permission]="permission" [permission]="permission"
[server]="server" [server]="server"
(click)="remove(permission)" (click)="remove(permission)"
*ngFor="let permission of owned"> *ngFor="let permission of ownedArray | permissionsFilter: searchPermissions?.id | paginator: pageEventOwned">
</app-editable-permission> </app-editable-permission>
<mat-paginator [length]="ownedArray.length" (page)="pageEventOwned = $event"
[pageSizeOptions]="[5, 20, 50, 100]"></mat-paginator>
</div> </div>
<mat-divider [vertical]="true"></mat-divider> <mat-divider [vertical]="true"></mat-divider>
<div class="column"> <div class="column">
@ -43,8 +60,10 @@
[permission]="permission" [permission]="permission"
[server]="server" [server]="server"
(click)="add(permission)" (click)="add(permission)"
*ngFor="let permission of available"> *ngFor="let permission of availableArray | permissionsFilter: searchPermissions?.id | paginator: pageEventAvailable">
</app-editable-permission> </app-editable-permission>
<mat-paginator [length]="availableArray.length" (page)="pageEventAvailable = $event"
[pageSizeOptions]="[5, 20, 50, 100]"></mat-paginator>
</div> </div>
</div> </div>

View File

@ -7,7 +7,7 @@
} }
.header { .header {
margin-top: 5px; margin: 10px;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
@ -45,3 +45,10 @@
.deny { .deny {
background-color: rgba(130, 8, 8, 0.36); background-color: rgba(130, 8, 8, 0.36);
} }
.permission-filter {
border-bottom: 1px solid;
margin: 5px;
border-bottom-color: #b0bec5;
}

View File

@ -17,6 +17,8 @@ import {Permission} from "@models/api/permission";
import {MatDialog} from "@angular/material/dialog"; import {MatDialog} from "@angular/material/dialog";
import {PermissionEditorValidateDialogComponent} from "@components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component"; import {PermissionEditorValidateDialogComponent} from "@components/role-management/role-detail/permission-editor/permission-editor-validate-dialog/permission-editor-validate-dialog.component";
import { EventEmitter } from '@angular/core'; import { EventEmitter } from '@angular/core';
import {ApiInformationService, IFormatedList} from "@services/api-information.service";
import {PageEvent} from "@angular/material/paginator";
@Component({ @Component({
selector: 'app-permission-editor', selector: 'app-permission-editor',
@ -24,16 +26,22 @@ import { EventEmitter } from '@angular/core';
styleUrls: ['./permission-editor.component.scss'] styleUrls: ['./permission-editor.component.scss']
}) })
export class PermissionEditorComponent implements OnInit { export class PermissionEditorComponent implements OnInit {
server: Server;
owned: Set<Permission>; owned: Set<Permission>;
available: Set<Permission>; available: Set<Permission>;
searchPermissions: any;
filteredOptions: IFormatedList[];
pageEventOwned: PageEvent | undefined;
pageEventAvailable: PageEvent | undefined;
@Input() server: Server;
@Input() ownedPermissions: Permission[]; @Input() ownedPermissions: Permission[];
@Input() availablePermissions: Permission[]; @Input() availablePermissions: Permission[];
@Output() updatedPermissions: EventEmitter<any> = new EventEmitter(); @Output() updatedPermissions: EventEmitter<any> = new EventEmitter();
constructor(private dialog: MatDialog) {} constructor(private dialog: MatDialog,
private apiInformationService: ApiInformationService) {}
ngOnInit(): void { ngOnInit(): void {
this.reset(); this.reset();
@ -88,4 +96,20 @@ export class PermissionEditorComponent implements OnInit {
return {add, remove}; return {add, remove};
} }
displayFn(value): string {
return value && value.name ? value.name : '';
}
changeAutocomplete(inputText) {
this.filteredOptions = this.apiInformationService.getIdByObjNameFromCache(inputText);
}
get ownedArray() {
return Array.from(this.owned.values())
}
get availableArray() {
return Array.from(this.available.values())
}
} }

View File

@ -12,5 +12,5 @@
Edit {{role.name}} role permissions Edit {{role.name}} role permissions
</div> </div>
</div> </div>
<app-permission-editor [ownedPermissions]="role.permissions" [availablePermissions]="permissions" <app-permission-editor [ownedPermissions]="role.permissions" [availablePermissions]="permissions" [server]="server"
(updatedPermissions)="updatePermissions($event)"></app-permission-editor> (updatedPermissions)="updatePermissions($event)"></app-permission-editor>

View File

@ -92,8 +92,10 @@
<mat-icon>edit</mat-icon> <mat-icon>edit</mat-icon>
</button> </button>
</div> </div>
<app-editable-permission <app-editable-permission
[permission]="permission" [permission]="permission"
[server]="server"
*ngFor="let permission of permissions"> *ngFor="let permission of permissions">
</app-editable-permission> </app-editable-permission>
</mat-tab> </mat-tab>

View File

@ -12,5 +12,5 @@
Edit {{user.username}} role permissions Edit {{user.username}} role permissions
</div> </div>
</div> </div>
<app-permission-editor [ownedPermissions]="userPermissions" [availablePermissions]="permissions" <app-permission-editor [ownedPermissions]="userPermissions" [availablePermissions]="permissions" [server]="server"
(updatedPermissions)="updatePermissions($event)"></app-permission-editor> (updatedPermissions)="updatePermissions($event)"></app-permission-editor>