feat: add delete functionality with confirmation dialog and Ctrl+S shortcut
- Added `@HostListener` for `window:keydown.control.s` to trigger the update service using the Ctrl+S shortcut. - Added `@HostListener` for `window:keydown.delete` to handle item deletion via keyboard. - Implemented `deleteItem` method with SweetAlert2 confirmation dialog before deleting selected items. - Integrated `forkJoin` for simultaneous handling of multiple delete requests and appropriate success/error notifications.
This commit is contained in:
parent
7bbd9aacd6
commit
0b31b78544
@ -1,4 +1,4 @@
|
||||
import { AfterViewInit, Component, ViewChild } from '@angular/core';
|
||||
import { AfterViewInit, Component, ViewChild, HostListener } from '@angular/core';
|
||||
import { GroupTableComponent } from '../../components/tables/group-table/group-table.component';
|
||||
import { UserTableComponent } from '../../components/tables/user-table/user-table.component';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
@ -6,7 +6,8 @@ import { GuiCellEdit, GuiSelectedRow } from '@generic-ui/ngx-grid';
|
||||
import { GroupFormComponent } from '../../components/forms/group-form/group-form.component';
|
||||
import { BasePageComponent } from '../base-page/base-page.component';
|
||||
import { Group } from '../../models/user-management.api.models';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { firstValueFrom, forkJoin } from 'rxjs';
|
||||
import Swal from 'sweetalert2';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
@ -53,4 +54,45 @@ export class GroupComponent extends BasePageComponent implements AfterViewInit {
|
||||
this.userTable.fetchDataByGroupId(this.sGroupId);
|
||||
}
|
||||
}
|
||||
|
||||
@HostListener('window:keydown.control.s', ['$event'])
|
||||
handleCtrlS(event: KeyboardEvent) {
|
||||
event.preventDefault();
|
||||
this.updateService.executeAll();
|
||||
}
|
||||
|
||||
@HostListener('window:keydown.delete', ['$event'])
|
||||
handleDelete(event: KeyboardEvent) {
|
||||
this.deleteItem();
|
||||
}
|
||||
|
||||
deleteItem() {
|
||||
const sRows = this.groupTable.selectedRows;
|
||||
if (sRows.length > 0)
|
||||
Swal.fire({
|
||||
title: "Löschen bestätigen",
|
||||
html: `<p class="text-start">Dieser Vorgang ist unwiderruflich. Möchten Sie fortfahren?<br><br>Anzahl der zu löschenden Einträge: ${sRows.length}</p>`,
|
||||
showDenyButton: true,
|
||||
confirmButtonText: "Ja",
|
||||
denyButtonText: `Nein`
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
const deleteRequests = sRows.map(sRow => this.groupTable.service.delete(sRow.source.id!));
|
||||
forkJoin(deleteRequests).subscribe({
|
||||
next: () => {
|
||||
this.refreshService.executeAll(),
|
||||
Swal.fire({
|
||||
text: `${sRows.length} Einträge wurden erfolgreich gelöscht.`,
|
||||
icon: "success"
|
||||
})
|
||||
},
|
||||
error: err => Swal.fire({
|
||||
title: "Fehler",
|
||||
text: `${err.message}`,
|
||||
icon: "error"
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user