authentication
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, inject } from '@angular/core';
|
||||
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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-all-users',
|
||||
standalone: true,
|
||||
imports: [AgGridAngular],
|
||||
templateUrl: './all-users.component.html',
|
||||
styleUrl: './all-users.component.scss'
|
||||
})
|
||||
export class AllUsersComponent {
|
||||
|
||||
private toast: HotToastService = inject(HotToastService);
|
||||
private api: ApiService = inject(ApiService);
|
||||
|
||||
gridApi!: GridApi;
|
||||
|
||||
private roles: string [] = [];
|
||||
|
||||
gridOptions: GridOptions = {
|
||||
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',
|
||||
cellEditorParams: {
|
||||
values: ['user', 'develop', 'admin'],
|
||||
},
|
||||
singleClickEdit: true,
|
||||
},
|
||||
],
|
||||
loading: true,
|
||||
overlayLoadingTemplate: 'Lade Daten...'
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
loadUsers() {
|
||||
this.api.getAllUsers().subscribe({
|
||||
next: n => {
|
||||
this.gridApi.setGridOption("rowData", n)
|
||||
this.gridApi.setGridOption("loading", false);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
cellEditEnd(params: CellEditingStoppedEvent, self: AllUsersComponent) {
|
||||
if (!params.valueChanged) { return; }
|
||||
|
||||
self.api.saveUser(params.data)
|
||||
.pipe(
|
||||
self.toast.observe({
|
||||
loading: 'speichern...',
|
||||
success: 'Änderungen gespeichert',
|
||||
error: 'Änderungen konnten nicht gespeichert werden!'
|
||||
})
|
||||
).subscribe({
|
||||
error: () => {
|
||||
const data = self.gridApi.getRowNode(params.node.id as string);
|
||||
data?.setDataValue(params.colDef.field as string, params.oldValue)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onGridReady(params: GridReadyEvent) {
|
||||
this.gridApi = params.api;
|
||||
const self = this;
|
||||
this.gridApi.addEventListener("cellEditingStopped", evt => this.cellEditEnd(evt, self))
|
||||
this.loadUsers();
|
||||
console.log(params)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user