This commit is contained in:
Bastian Wagner
2024-10-23 13:58:14 +02:00
parent d4ddcafd2b
commit b453945183
33 changed files with 570 additions and 19 deletions

View File

@@ -0,0 +1 @@
<div class="delete icon-btn-sm" (click)="delete()" ></div>

View File

@@ -0,0 +1,8 @@
:host {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AgDeleteKeyComponent } from './ag-delete-key.component';
describe('AgDeleteKeyComponent', () => {
let component: AgDeleteKeyComponent;
let fixture: ComponentFixture<AgDeleteKeyComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AgDeleteKeyComponent]
})
.compileComponents();
fixture = TestBed.createComponent(AgDeleteKeyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,69 @@
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';
@Component({
selector: 'app-ag-delete-key',
standalone: true,
imports: [MatDialogModule],
templateUrl: './ag-delete-key.component.html',
styleUrl: './ag-delete-key.component.scss'
})
export class AgDeleteKeyComponent 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
})
ref.afterClosed().subscribe({
next: n => {
if (n) {
this.deleteThisKey();
}
}
})
}
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: () => {
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);
},
error: () => {
this.params.api.setGridOption("loading", false);
}
})
}
}

View File

@@ -0,0 +1 @@
<mat-spinner></mat-spinner>

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AgLoadingComponent } from './ag-loading.component';
describe('AgLoadingComponent', () => {
let component: AgLoadingComponent;
let fixture: ComponentFixture<AgLoadingComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AgLoadingComponent]
})
.compileComponents();
fixture = TestBed.createComponent(AgLoadingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,21 @@
import { Component } from '@angular/core';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { ILoadingOverlayAngularComp } from 'ag-grid-angular';
import { ILoadingOverlayParams } from 'ag-grid-community';
@Component({
selector: 'app-ag-loading',
standalone: true,
imports: [MatProgressSpinnerModule],
templateUrl: './ag-loading.component.html',
styleUrl: './ag-loading.component.scss'
})
export class AgLoadingComponent implements ILoadingOverlayAngularComp {
agInit(params: ILoadingOverlayParams<any, any>): void {
}
refresh?(params: ILoadingOverlayParams<any, any>): void {
}
}