Manage SystemManagers
This commit is contained in:
@@ -7,11 +7,12 @@ import { HotToastService } from '@ngxpert/hot-toast';
|
||||
import { AuthService } from '../../../core/auth/auth.service';
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { AG_GRID_LOCALE_DE } from '@ag-grid-community/locale';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
|
||||
@Component({
|
||||
selector: 'app-all-users',
|
||||
standalone: true,
|
||||
imports: [AgGridAngular],
|
||||
imports: [AgGridAngular, MatButtonModule],
|
||||
providers: [DatePipe],
|
||||
templateUrl: './all-users.component.html',
|
||||
styleUrl: './all-users.component.scss'
|
||||
@@ -54,7 +55,26 @@ export class AllUsersComponent {
|
||||
, width: 170
|
||||
, type: 'date'
|
||||
, cellRenderer: (data: any) => data.value ? this.datePipe.transform(new Date(data.value), 'medium') : '-'
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'delete',
|
||||
headerName: '',
|
||||
width: 50,
|
||||
cellRenderer: (params: any) => {
|
||||
if (params.data.id == this.authService.user.id || !this.authService.isAdmin) {
|
||||
return '';
|
||||
}
|
||||
return `<div class="delete icon icon-btn-xs" (click)="deleteUser(${params.data.id})"></div>`;
|
||||
},
|
||||
onCellClicked: (event: any) => {
|
||||
if (event.data.id == this.authService.user.id || !this.authService.isAdmin) {
|
||||
return;
|
||||
}
|
||||
if (event.colDef.field == 'delete') {
|
||||
this.deleteUser(event.data.id);
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
loading: true,
|
||||
overlayLoadingTemplate: 'Lade Daten...'
|
||||
@@ -64,12 +84,36 @@ export class AllUsersComponent {
|
||||
|
||||
}
|
||||
|
||||
deleteUser(id: string) {
|
||||
if ( confirm('Soll der Benutzer wirklich gelöscht werden?')) {
|
||||
this.api.deleteUser(id)
|
||||
.pipe(
|
||||
this.toast.observe({
|
||||
loading: 'löschen...',
|
||||
success: 'Benutzer gelöscht',
|
||||
error: 'Benutzer konnte nicht gelöscht werden!'
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.loadUsers();
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
loadUsers() {
|
||||
this.gridApi.setGridOption("loading", true);
|
||||
this.api.getAllUsers().subscribe({
|
||||
next: n => {
|
||||
this.gridApi.setGridOption("rowData", n)
|
||||
this.gridApi.setGridOption("loading", false);
|
||||
},
|
||||
error: () => {
|
||||
this.toast.error('Benutzer konnten nicht geladen werden!')
|
||||
this.gridApi.setGridOption("loading", false);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user