This commit is contained in:
Bastian Wagner
2024-09-13 22:20:27 +02:00
parent 00d5498e00
commit ed6b2b9c45
11 changed files with 70 additions and 18 deletions

View File

@@ -4,11 +4,15 @@ import { ApiService } from '../../../shared/api.service';
import { AgGridAngular } from 'ag-grid-angular';
import { GridOptions,GridApi, GridReadyEvent, CellEditingStoppedEvent } from 'ag-grid-community';
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';
@Component({
selector: 'app-all-users',
standalone: true,
imports: [AgGridAngular],
providers: [DatePipe],
templateUrl: './all-users.component.html',
styleUrl: './all-users.component.scss'
})
@@ -16,24 +20,41 @@ export class AllUsersComponent {
private toast: HotToastService = inject(HotToastService);
private api: ApiService = inject(ApiService);
private authService = inject(AuthService);
private datePipe = inject(DatePipe);
gridApi!: GridApi;
private roles: string [] = [];
gridOptions: GridOptions = {
localeText: AG_GRID_LOCALE_DE,
rowData: [],
columnDefs: [
{ field: 'username' , headerName: 'User', flex: 1, editable: true, sort: 'asc' },
{ field: 'firstName', headerName: 'Vorname', flex: 1, editable: true},
{ field: 'lastName', headerName: 'Nachname', flex: 1, editable: true},
{ field: 'isActive', headerName: 'Aktiv', flex: 1, editable: true, },
{ field: 'role', headerName: 'Rolle', flex: 1, editable: true, cellEditor: 'agSelectCellEditor',
{ field: 'username' , headerName: 'User', flex: 1, editable: this.authService.isAdmin, sort: 'asc', filter: true },
{ field: 'firstName', headerName: 'Vorname', flex: 1, editable: this.authService.isAdmin, filter: true},
{ field: 'lastName', headerName: 'Nachname', flex: 1, editable: this.authService.isAdmin, filter: true},
{ field: 'isActive', headerName: 'Aktiv', width: 70, editable: (params) => params.data.id != this.authService.user.id && this.authService.isAdmin, },
{ field: 'role', headerName: 'Rolle', width: 100 ,editable: this.authService.isAdmin, cellEditor: 'agSelectCellEditor',
cellEditorParams: {
values: ['user', 'develop', 'admin'],
},
singleClickEdit: true,
cellEditorPopup: false
},
{
field: 'createdAt'
, headerName: 'Erstellt'
, width: 120
, type: 'date'
, cellRenderer: (data: any) => this.datePipe.transform(new Date(data.value))
, tooltipValueGetter: (data: any) => this.datePipe.transform(new Date(data.value), 'medium')
},
{
field: 'lastLogin'
, headerName: 'Letzter Login'
, width: 170
, type: 'date'
, cellRenderer: (data: any) => data.value ? this.datePipe.transform(new Date(data.value), 'medium') : '-'
}
],
loading: true,
overlayLoadingTemplate: 'Lade Daten...'
@@ -42,6 +63,7 @@ export class AllUsersComponent {
ngOnInit(): void {
}
loadUsers() {
this.api.getAllUsers().subscribe({
next: n => {