import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, inject, OnInit } from "@angular/core"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { Route } from "@angular/router"; import { LiveGridColumnType, LiveGridComponent, LiveGridOptions } from "codefoxlivegrid"; import { ButtonDirective, CardHeaderComponent, CfDialogService, CfPermissionDirective } from "codefoxui"; import { DIALOG_DELETE_CONFIGURATION } from "src/app/const"; import { UserRow } from "src/app/interfaces"; import { LocalApiService } from "src/app/services/local.api.service"; import { UserEditorComponent } from "../usereditor/usereditor.component"; @Component({ standalone: true, selector: 'cf-users', changeDetection: ChangeDetectionStrategy.OnPush, templateUrl: 'users.component.html', styleUrls: ['users.component.scss'], imports: [ CardHeaderComponent, ButtonDirective, LiveGridComponent, CfPermissionDirective ] }) export class UsersComponent implements OnInit { dialogService: CfDialogService = inject(CfDialogService); las: LocalApiService = inject(LocalApiService); cdr: ChangeDetectorRef = inject(ChangeDetectorRef); destroyRef: DestroyRef = inject(DestroyRef); usersLiveGridCreateOptions: LiveGridOptions = { name: 'users', idField: 'userId', endPoint: 'users', columns: [{ title: 'Felhasználónév', field: 'username', type: LiveGridColumnType.STRING }, { title: 'Teljes név', field: 'fullname', type: LiveGridColumnType.STRING }, { title: 'Aktív', field: 'active', type: LiveGridColumnType.BOOLEAN }] } showEditorDialog(userRow: UserRow | null = null): void { this.dialogService.open(UserEditorComponent, { data: { userId: userRow !== null ? userRow.userId : null } }); } delete(userRow: UserRow | null): void { this.dialogService.confirmAccept(DIALOG_DELETE_CONFIGURATION).then(() => { if (userRow !== null) { this.las.deleteUser(userRow.userId).pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {}); } }); } ngOnInit(): void { this.cdr.detectChanges(); } constructor() { this.cdr.detach(); } } export const USERS_ROUTE: Route = { path: 'users', component: UsersComponent }