scan delete working

This commit is contained in:
Philipp Dormann 2023-04-12 21:10:36 +02:00
parent 17217dae76
commit c7dcf7c66d
Signed by: philipp
GPG Key ID: 3BB9ADD52DCA4314
4 changed files with 61 additions and 40 deletions

View File

@ -3,7 +3,13 @@
import { clickOutside } from "../base/outsideclick"; import { clickOutside } from "../base/outsideclick";
import { createEventDispatcher, onMount } from "svelte"; import { createEventDispatcher, onMount } from "svelte";
export let modal_open; export let modal_open;
export let delete_scans = []; export let delete_scan = {
id: 0,
runner: {
firstname: "",
lastname: "",
},
};
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
onMount(() => { onMount(() => {
document.onkeydown = (e) => { document.onkeydown = (e) => {
@ -20,7 +26,7 @@
}; };
}); });
async function submit() { async function submit() {
dispatch("delete", { scans: delete_scans }); dispatch("delete", { id: delete_scan.id });
modal_open = false; modal_open = false;
} }
</script> </script>
@ -75,7 +81,7 @@
{$_("confirm-delete")} {$_("confirm-delete")}
</h3> </h3>
<div class="mt-2 mb-6"> <div class="mt-2 mb-6">
please confirm deletion of {delete_scans.length} scans {$_("please-confirm-the-deletion-of-scan")} #{delete_scan.id}
</div> </div>
</div> </div>
</div> </div>

View File

@ -22,15 +22,14 @@
import { runnerFilter, statusFilter } from "../shared/tablefilters"; import { runnerFilter, statusFilter } from "../shared/tablefilters";
import CardRunner from "../cards/CardRunner.svelte"; import CardRunner from "../cards/CardRunner.svelte";
import ScanValid from "./ScanValid.svelte"; import ScanValid from "./ScanValid.svelte";
import DeleteScansModal from "./DeleteScansModal.svelte"; import DeleteScanModal from "./DeleteScanModal.svelte";
$: selectedScans = $: selectedScans =
$table?.getSelectedRowModel().rows.map((row) => row.original) || []; $table?.getSelectedRowModel().rows.map((row) => row.original) || [];
$: selected = $: selected =
$table?.getSelectedRowModel().rows.map((row) => row.index) || []; $table?.getSelectedRowModel().rows.map((row) => row.index) || [];
$: delete_active = false; $: active_delete = undefined;
$: active_deletes = [];
export let current_scans = []; export let current_scans = [];
const scans_promise = ScanService.scanControllerGetAll().then((val) => { const scans_promise = ScanService.scanControllerGetAll().then((val) => {
current_scans = val; current_scans = val;
@ -123,12 +122,10 @@
return renderComponent(TableActions, { return renderComponent(TableActions, {
detailsLink: `./${info.row.original.id}`, detailsLink: `./${info.row.original.id}`,
deleteAction: () => { deleteAction: () => {
active_deletes = [ active_delete =
current_scans[ current_scans[
current_scans.findIndex((r) => r.id == info.row.original.id) current_scans.findIndex((r) => r.id == info.row.original.id)
], ];
];
delete_active = true;
}, },
deleteEnabled: deleteEnabled:
store.state.jwtinfo.userdetails.permissions.includes("SCAN:DELETE"), store.state.jwtinfo.userdetails.permissions.includes("SCAN:DELETE"),
@ -158,41 +155,25 @@
}); });
const table = createSvelteTable(options); const table = createSvelteTable(options);
async function deleteScan(scan_id) { async function deleteScan(scan_id) {
// await ScanService.scanControllerRemove(scan_id, true); await ScanService.scanControllerRemove(scan_id, true);
current_scans = current_scans.filter((r) => r.id !== scan_id); current_scans = current_scans.filter((r) => r.id !== scan_id);
// options.update((options) => ({ options.update((options) => ({
// ...options, ...options,
// data: current_scans, data: current_scans,
// })); }));
// Toastify({ Toastify({
// text: $_("scans-deleted"), text: $_("scan-deleted"),
// duration: 3500, duration: 3500,
// backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)", backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
// }).showToast(); }).showToast();
}
async function deleteScans(scan_ids) {
scan_ids.forEach((scan_id) => {
deleteScan(scan_id);
});
// // await ScanService.scanControllerRemove(scan_id, true);
// current_scans = current_scans.filter((r) => r.id !== scan_id);
// options.update((options) => ({
// ...options,
// data: current_scans,
// }));
// Toastify({
// text: $_("scans-deleted"),
// duration: 3500,
// backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
// }).showToast();
} }
</script> </script>
<DeleteScansModal <DeleteScanModal
delete_scans={active_deletes} delete_scan={active_delete}
modal_open={delete_active} modal_open={active_delete != undefined}
on:delete={(event) => { on:delete={(event) => {
deleteScans(event.detail.scans); deleteScan(event.detail.id);
}} }}
/> />
{#if store.state.jwtinfo.userdetails.permissions.includes("SCAN:GET")} {#if store.state.jwtinfo.userdetails.permissions.includes("SCAN:GET")}
@ -208,6 +189,36 @@
{#if current_scans.length === 0} {#if current_scans.length === 0}
<ScansEmptyState /> <ScansEmptyState />
{:else} {:else}
{#if selected.length > 0}
<button
type="button"
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-600 text-base font-medium text-white hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:ml-3 sm:w-auto sm:text-sm inline-flex"
id="options-menu"
on:click={async () => {
const prom = [];
for (const scan of selectedScans) {
prom.push(deleteScan(scan.id));
}
await Promise.all(prom);
}}
>
{$_("delete-cards")}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="w-5 h-5"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"
/>
</svg>
</button>
{/if}
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="w-full"> <table class="w-full">
<thead> <thead>

View File

@ -478,6 +478,8 @@
"cards-deleted": "Karten gelöscht", "cards-deleted": "Karten gelöscht",
"please-confirm-the-deletion-of-runner": "Bitte bestätige die Löschung der Läufer:in", "please-confirm-the-deletion-of-runner": "Bitte bestätige die Löschung der Läufer:in",
"runner-deleted": "Läufer:in gelöscht", "runner-deleted": "Läufer:in gelöscht",
"scan-deleted": "Scan gelöscht",
"please-confirm-the-deletion-of-scan": "Bitte bestätige die Löschung des Scans",
"please-confirm-the-deletion-of-card": "Bitte bestätige die Löschung der Karte", "please-confirm-the-deletion-of-card": "Bitte bestätige die Löschung der Karte",
"card": "Läuferkarte" "card": "Läuferkarte"
} }

View File

@ -478,6 +478,8 @@
"cards-deleted": "Cards deleted", "cards-deleted": "Cards deleted",
"please-confirm-the-deletion-of-runner": "Please confirm the deletion of this runner", "please-confirm-the-deletion-of-runner": "Please confirm the deletion of this runner",
"runner-deleted": "runner deleted", "runner-deleted": "runner deleted",
"scan-deleted": "scan deleted",
"please-confirm-the-deletion-of-scan": "Please confirm the deletion of scan",
"please-confirm-the-deletion-of-card": "Please confirm the deletion of this card", "please-confirm-the-deletion-of-card": "Please confirm the deletion of this card",
"card": "card" "card": "card"
} }