Skip to content

Commit

Permalink
closes #70
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 22, 2024
1 parent ddafe71 commit 312b6f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
}

@if(params.showDeleteButton) {
<button class="ml-2 btn btn-sm btn-warning" [swal]="deleteItem" floatUi="Delete">
<button class="ml-2 btn btn-sm btn-warning" (click)="attemptDelete($event)" floatUi="Delete">
<ng-icon name="heroTrash"></ng-icon>
</button>

<swal #deleteItem title="Delete This?" text="This cannot be undone." icon="warning" [showCancelButton]="true"
confirmButtonText="Yes, delete" [focusCancel]="true" (confirm)="params.deleteCallback?.(params.data)">
<swal #deleteItem title="Delete This?" text="This cannot be undone. You can hold shift to bypass this warning."
icon="warning" [showCancelButton]="true" confirmButtonText="Yes, delete" [focusCancel]="true"
(confirm)="params.deleteCallback?.(params.data)">
</swal>
}
</div>
15 changes: 14 additions & 1 deletion src/app/shared/components/cell-buttons/cell-buttons.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from '@angular/core';
import { Component, viewChild } from '@angular/core';
import { SwalComponent } from '@sweetalert2/ngx-sweetalert2';
import { ICellRendererAngularComp } from 'ag-grid-angular';
import { ICellRendererParams } from 'ag-grid-community';

Expand All @@ -10,6 +11,8 @@ import { ICellRendererParams } from 'ag-grid-community';
export class CellButtonsComponent implements ICellRendererAngularComp {
public params!: any;

public deleteWarnSwal = viewChild<SwalComponent>('deleteItem');

agInit(params: ICellRendererParams) {
this.params = params;
}
Expand All @@ -18,4 +21,14 @@ export class CellButtonsComponent implements ICellRendererAngularComp {
this.params = params;
return true;
}

async attemptDelete($event: any) {
const holdingShift = $event.shiftKey;
if (!holdingShift) {
await this.deleteWarnSwal()?.fire();
return;
}

this.params.deleteCallback?.(this.params.data);
}
}

0 comments on commit 312b6f2

Please sign in to comment.