mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-05-09 20:12:53 +00:00
user management, add delete button on each row
This commit is contained in:
parent
9546ed94fe
commit
4e207d270e
@ -273,12 +273,13 @@ import { HttpRequestsInterceptor } from './interceptors/http.interceptor';
|
|||||||
import { UserManagementComponent } from './components/user-management/user-management.component';
|
import { UserManagementComponent } from './components/user-management/user-management.component';
|
||||||
import { UserService } from './services/user.service';
|
import { UserService } from './services/user.service';
|
||||||
import { LoggedUserComponent } from './components/users/logged-user/logged-user.component';
|
import { LoggedUserComponent } from './components/users/logged-user/logged-user.component';
|
||||||
|
import { AddUserDialogComponent } from './components/user-management/add-user-dialog/add-user-dialog.component';
|
||||||
|
import { UserFilterPipe } from './filters/user-filter.pipe';
|
||||||
import { GroupManagementComponent } from './components/group-management/group-management.component';
|
import { GroupManagementComponent } from './components/group-management/group-management.component';
|
||||||
import { GroupFilterPipe } from './filters/group-filter.pipe';
|
import { GroupFilterPipe } from './filters/group-filter.pipe';
|
||||||
import { AddGroupDialogComponent } from './components/group-management/add-group-dialog/add-group-dialog.component';
|
import { AddGroupDialogComponent } from './components/group-management/add-group-dialog/add-group-dialog.component';
|
||||||
import { DeleteGroupDialogComponent } from './components/group-management/delete-group-dialog/delete-group-dialog.component';
|
import { DeleteGroupDialogComponent } from './components/group-management/delete-group-dialog/delete-group-dialog.component';
|
||||||
import { AddUserDialogComponent } from './components/user-management/add-user-dialog/add-user-dialog.component';
|
import { DeleteUserDialogComponent } from './components/user-management/delete-user-dialog/delete-user-dialog.component';
|
||||||
import { UserFilterPipe } from './filters/user-filter.pipe';
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@ -467,12 +468,13 @@ import { UserFilterPipe } from './filters/user-filter.pipe';
|
|||||||
EditNetworkConfigurationDialogComponent,
|
EditNetworkConfigurationDialogComponent,
|
||||||
UserManagementComponent,
|
UserManagementComponent,
|
||||||
ProjectReadmeComponent,
|
ProjectReadmeComponent,
|
||||||
DeleteGroupDialogComponent,
|
|
||||||
AddGroupDialogComponent,
|
AddGroupDialogComponent,
|
||||||
GroupFilterPipe,
|
GroupFilterPipe,
|
||||||
GroupManagementComponent,
|
GroupManagementComponent,
|
||||||
AddUserDialogComponent,
|
AddUserDialogComponent,
|
||||||
UserFilterPipe,
|
UserFilterPipe,
|
||||||
|
DeleteGroupDialogComponent,
|
||||||
|
DeleteUserDialogComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Software Name : GNS3 Web UI
|
||||||
|
* Version: 3
|
||||||
|
* SPDX-FileCopyrightText: Copyright (c) 2022 Orange Business Services
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* This software is distributed under the GPL-3.0 or any later version,
|
||||||
|
* the text of which is available at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
* or see the "LICENSE" file for more details.
|
||||||
|
*
|
||||||
|
* Author: Sylvain MATHIEU, Elise LEBEAU
|
||||||
|
*/
|
||||||
import {Component, Inject, OnInit} from '@angular/core';
|
import {Component, Inject, OnInit} from '@angular/core';
|
||||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||||
import {Server} from "@models/server";
|
import {Server} from "@models/server";
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
<h1 mat-dialog-title>Are you sure to delete user named: '{{data.user.username}}' ?</h1>
|
||||||
|
<div mat-dialog-actions class="button-div">
|
||||||
|
<button mat-button (click)="onCancel()" color="accent">No, cancel</button>
|
||||||
|
<button mat-button (click)="onDelete()" tabindex="2" class="add-project-button" mat-raised-button color="primary">
|
||||||
|
Yes, delete!
|
||||||
|
</button>
|
||||||
|
</div>
|
@ -0,0 +1,3 @@
|
|||||||
|
.button-div {
|
||||||
|
float: right;
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { DeleteUserDialogComponent } from './delete-user-dialog.component';
|
||||||
|
|
||||||
|
describe('DeleteUserDialogComponent', () => {
|
||||||
|
let component: DeleteUserDialogComponent;
|
||||||
|
let fixture: ComponentFixture<DeleteUserDialogComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ DeleteUserDialogComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(DeleteUserDialogComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,26 @@
|
|||||||
|
import {Component, Inject, OnInit} from '@angular/core';
|
||||||
|
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||||
|
import {User} from "@models/users/user";
|
||||||
|
import {UserService} from "@services/user.service";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-delete-user-dialog',
|
||||||
|
templateUrl: './delete-user-dialog.component.html',
|
||||||
|
styleUrls: ['./delete-user-dialog.component.scss']
|
||||||
|
})
|
||||||
|
export class DeleteUserDialogComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor(private dialogRef: MatDialogRef<DeleteUserDialogComponent>,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: { user: User }) { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
onCancel() {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
onDelete() {
|
||||||
|
this.dialogRef.close(true);
|
||||||
|
}
|
||||||
|
}
|
@ -35,11 +35,16 @@
|
|||||||
<mat-header-cell *matHeaderCellDef mat-sort-header> Admin </mat-header-cell>
|
<mat-header-cell *matHeaderCellDef mat-sort-header> Admin </mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row">{{row.is_superadmin}}</mat-cell>
|
<mat-cell *matCellDef="let row">{{row.is_superadmin}}</mat-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container matColumnDef="last">
|
<ng-container matColumnDef="updated_at">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header> Last Update </mat-header-cell>
|
<mat-header-cell *matHeaderCellDef mat-sort-header> Last Update </mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row">{{row.updated_at ? row.updated_at : row.created_at}}</mat-cell>
|
<mat-cell *matCellDef="let row">{{row.updated_at ? row.updated_at : row.created_at}}</mat-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="delete">
|
||||||
|
<mat-header-cell *matHeaderCellDef> </mat-header-cell>
|
||||||
|
<mat-cell *matCellDef="let row"><button mat-button (click)="onDelete(row)"><mat-icon>delete</mat-icon></button></mat-cell>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
||||||
</mat-table>
|
</mat-table>
|
||||||
|
@ -20,9 +20,10 @@ import {User} from "@models/users/user";
|
|||||||
import {BehaviorSubject, merge, Observable} from "rxjs";
|
import {BehaviorSubject, merge, Observable} from "rxjs";
|
||||||
import {DataSource} from "@angular/cdk/collections";
|
import {DataSource} from "@angular/cdk/collections";
|
||||||
import {map} from "rxjs/operators";
|
import {map} from "rxjs/operators";
|
||||||
import {AddBlankProjectDialogComponent} from "@components/projects/add-blank-project-dialog/add-blank-project-dialog.component";
|
|
||||||
import {AddUserDialogComponent} from "@components/user-management/add-user-dialog/add-user-dialog.component";
|
import {AddUserDialogComponent} from "@components/user-management/add-user-dialog/add-user-dialog.component";
|
||||||
import {MatDialog} from "@angular/material/dialog";
|
import {MatDialog} from "@angular/material/dialog";
|
||||||
|
import {DeleteUserDialogComponent} from "@components/user-management/delete-user-dialog/delete-user-dialog.component";
|
||||||
|
import {ToasterService} from "@services/toaster.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-user-management',
|
selector: 'app-user-management',
|
||||||
@ -33,7 +34,7 @@ export class UserManagementComponent implements OnInit {
|
|||||||
server: Server;
|
server: Server;
|
||||||
dataSource: UserDataSource;
|
dataSource: UserDataSource;
|
||||||
userDatabase = new UserDatabase();
|
userDatabase = new UserDatabase();
|
||||||
displayedColumns = ['name', 'email', 'is_active', 'is_superadmin', 'last'];
|
displayedColumns = ['name', 'email', 'is_active', 'is_superadmin', 'updated_at', 'delete'];
|
||||||
|
|
||||||
searchText: string = '';
|
searchText: string = '';
|
||||||
|
|
||||||
@ -44,7 +45,8 @@ export class UserManagementComponent implements OnInit {
|
|||||||
private router: Router,
|
private router: Router,
|
||||||
private userService: UserService,
|
private userService: UserService,
|
||||||
private progressService: ProgressService,
|
private progressService: ProgressService,
|
||||||
public dialog: MatDialog) { }
|
public dialog: MatDialog,
|
||||||
|
private toasterService: ToasterService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.server = this.route.snapshot.data['server'];
|
this.server = this.route.snapshot.data['server'];
|
||||||
@ -80,6 +82,21 @@ export class UserManagementComponent implements OnInit {
|
|||||||
dialogRef.afterClosed().subscribe(() => this.refresh());
|
dialogRef.afterClosed().subscribe(() => this.refresh());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDelete(user: User) {
|
||||||
|
this.dialog
|
||||||
|
.open(DeleteUserDialogComponent, {width: '500px', data: {user: user}})
|
||||||
|
.afterClosed()
|
||||||
|
.subscribe((isDeletedConfirm) => {
|
||||||
|
if (isDeletedConfirm) {
|
||||||
|
this.userService.delete(this.server, user.user_id)
|
||||||
|
.subscribe(() => {
|
||||||
|
this.refresh()
|
||||||
|
}, (error) => {
|
||||||
|
this.toasterService.error(`An error occur while trying to delete user ${user.username}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UserDatabase {
|
export class UserDatabase {
|
||||||
|
@ -30,4 +30,7 @@ export class UserService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete(server: Server, user_id: string) {
|
||||||
|
return this.httpServer.delete(server, `/users/${user_id}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user