135 lines
3.8 KiB
TypeScript
135 lines
3.8 KiB
TypeScript
import { Component, inject } from '@angular/core';
|
|
import { ICellRendererAngularComp } from 'ag-grid-angular';
|
|
import { ICellRendererParams } from 'ag-grid-community';
|
|
import { IKey } from '../../../../model/interface/key.interface';
|
|
import { ApiService } from '../../../api.service';
|
|
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
|
import { DeleteKeyComponent } from '../../../../modules/keys/components/delete-key/delete-key.component';
|
|
import { HotToastService } from '@ngxpert/hot-toast';
|
|
import { HandoverDialogComponent } from '../../../../modules/keys/components/handover-dialog/handover-dialog.component';
|
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
import { LostKeyComponent } from '../../../../modules/keys/components/lost-key/lost-key.component';
|
|
import { CreateKeyComponent } from '../../../../modules/keys/create/create.component';
|
|
|
|
@Component({
|
|
selector: 'app-ag-delete-key',
|
|
imports: [MatDialogModule, MatTooltipModule],
|
|
templateUrl: './ag-key-actions.component.html',
|
|
styleUrl: './ag-key-actions.component.scss'
|
|
})
|
|
export class AgKeyActionsComponent implements ICellRendererAngularComp {
|
|
key!: IKey;
|
|
params!: ICellRendererParams<any, any, any>;
|
|
|
|
private api: ApiService = inject(ApiService);
|
|
private dialog: MatDialog = inject(MatDialog);
|
|
private toast = inject(HotToastService);
|
|
|
|
agInit(params: ICellRendererParams<any, any, any>): void {
|
|
this.params = params;
|
|
this.key = params.data;
|
|
}
|
|
refresh(params: ICellRendererParams<any, any, any>): boolean {
|
|
return false;
|
|
}
|
|
|
|
delete() {
|
|
const ref = this.dialog.open(DeleteKeyComponent, {
|
|
data: this.key,
|
|
autoFocus: false,
|
|
width: '500px',
|
|
maxWidth: 'calc(100vw - 24px)',
|
|
})
|
|
|
|
ref.afterClosed().subscribe({
|
|
next: n => {
|
|
if (n) {
|
|
this.deleteThisKey();
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
edit() {
|
|
const ref = this.dialog.open(CreateKeyComponent, {
|
|
data: this.key,
|
|
autoFocus: false,
|
|
maxWidth: '100vw',
|
|
maxHeight: '100vh'
|
|
})
|
|
ref.afterClosed().subscribe({
|
|
next: n => {
|
|
if (n != null) {
|
|
this.key.handedOut = n;
|
|
this.params.api.refreshCells();
|
|
}
|
|
}
|
|
});
|
|
|
|
// ref.componentInstance.editKey(this.key)
|
|
}
|
|
|
|
deleteThisKey() {
|
|
this.params.api.setGridOption("loading", true);
|
|
this.api.deleteKey(this.key.id).pipe(
|
|
this.toast.observe({
|
|
loading: 'Lösche Schlüssel ' + this.key.name,
|
|
success: 'Schlüssel ' + this.key.name + ' gelöscht',
|
|
error: 'Konnte nicht gelöscht werden'
|
|
})
|
|
).subscribe({
|
|
next: () => {
|
|
this.setData();
|
|
},
|
|
error: () => {
|
|
this.params.api.setGridOption("loading", false);
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
openHandoutDialog() {
|
|
this.dialog.open(HandoverDialogComponent, {
|
|
data: this.key,
|
|
autoFocus: false,
|
|
maxWidth: '100vw',
|
|
maxHeight: '100vh'
|
|
}).afterClosed().subscribe({
|
|
next: n => {
|
|
if (n != null) {
|
|
this.key.handedOut = n;
|
|
this.params.api.refreshCells();
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
openLostKeyDialog() {
|
|
this.dialog.open(LostKeyComponent, {
|
|
data: this.key,
|
|
autoFocus: false,
|
|
maxWidth: '100vw',
|
|
maxHeight: '100vh'
|
|
}).afterClosed().subscribe({
|
|
next: n => {
|
|
if (n != null) {
|
|
if (n == "") {
|
|
n = null;
|
|
}
|
|
this.key.keyLost = n;
|
|
this.params.api.refreshCells();
|
|
this.api.updateKey(this.key).subscribe();
|
|
this.setData();
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
private setData() {
|
|
let data = this.params.api.getGridOption("rowData");
|
|
data = data?.filter(d => d.id != this.key.id);
|
|
this.params.api.setGridOption("rowData", data);
|
|
this.params.api.setGridOption("loading", false);
|
|
}
|
|
}
|