refactor
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
<div class="handover icon-btn-sm" (click)="openHandoutDialog()" matTooltip="Schlüsselübergaben" [matTooltipShowDelay]="400"></div>
|
||||
<div class="magnifying-glass icon-btn-sm" (click)="openLostKeyDialog()" matTooltip="Verloren melden" [matTooltipShowDelay]="400"></div>
|
||||
<div class="delete icon-btn-sm" (click)="delete()" matTooltip="Löschen" [matTooltipShowDelay]="400"></div>
|
||||
<!-- <div class="edit icon-btn-sm" (click)="edit()" matTooltip="Bearbeiten" [matTooltipShowDelay]="400"></div> -->
|
||||
@@ -0,0 +1,13 @@
|
||||
:host {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.handover {
|
||||
background-image: url('../../../../../assets/img/key_2.svg');
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user