Paginated scan loading

ref #175
This commit is contained in:
Nicolai Ort 2023-04-18 20:43:04 +02:00
parent faf3893180
commit cac34db1fd
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F

View File

@ -30,6 +30,7 @@
$table?.getSelectedRowModel().rows.map((row) => row.index) || []; $table?.getSelectedRowModel().rows.map((row) => row.index) || [];
$: active_delete = undefined; $: active_delete = undefined;
$: dataLoaded = false;
export let current_scans = []; export let current_scans = [];
export const addScans = (scans) => { export const addScans = (scans) => {
current_scans = current_scans.concat(...scans); current_scans = current_scans.concat(...scans);
@ -39,15 +40,6 @@
})); }));
}; };
const scans_promise = ScanService.scanControllerGetAll().then((val) => {
current_scans = val;
// handler.setRows(val);
current_scans = val;
options.update((options) => ({
...options,
data: current_scans,
}));
});
let allTracks = []; let allTracks = [];
TrackService.trackControllerGetAll().then((val) => { TrackService.trackControllerGetAll().then((val) => {
allTracks = val; allTracks = val;
@ -99,7 +91,7 @@
accessorKey: "timestamp", accessorKey: "timestamp",
header: () => $_("timestamp"), header: () => $_("timestamp"),
cell: (info) => { cell: (info) => {
return (new Date(parseInt(info.getValue())*1000)).toLocaleString() return new Date(parseInt(info.getValue()) * 1000).toLocaleString();
}, },
enableColumnFilter: false, enableColumnFilter: false,
}, },
@ -183,6 +175,29 @@
backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)", backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
}).showToast(); }).showToast();
} }
onMount(async () => {
let page = 0;
while (page >= 0) {
const scans = await ScanService.scanControllerGetAll(page, 500);
if (scans.length == 0) {
page = -2;
dataLoaded = true;
}
current_scans = current_scans.concat(...scans);
options.update((options) => ({
...options,
data: current_scans,
}));
if (page == 0) {
dataLoaded = true;
}
page++;
}
console.log("All scans loaded");
});
</script> </script>
<DeleteScanModal <DeleteScanModal
@ -193,7 +208,7 @@
}} }}
/> />
{#if store.state.jwtinfo.userdetails.permissions.includes("SCAN:GET")} {#if store.state.jwtinfo.userdetails.permissions.includes("SCAN:GET")}
{#await scans_promise} {#if !dataLoaded}
<div <div
class="bg-teal-lightest border-t-4 border-teal rounded-b text-teal-darkest px-4 py-3 shadow-md my-2" class="bg-teal-lightest border-t-4 border-teal rounded-b text-teal-darkest px-4 py-3 shadow-md my-2"
role="alert" role="alert"
@ -201,8 +216,7 @@
<p class="font-bold">{$_("scans-are-being-loaded")}</p> <p class="font-bold">{$_("scans-are-being-loaded")}</p>
<p class="text-sm">{$_("this-might-take-a-moment")}</p> <p class="text-sm">{$_("this-might-take-a-moment")}</p>
</div> </div>
{:then} {:else if current_scans.length === 0}
{#if current_scans.length === 0}
<ScansEmptyState /> <ScansEmptyState />
{:else} {:else}
{#if selected.length > 0} {#if selected.length > 0}
@ -294,12 +308,4 @@
</div> </div>
<TableBottom {table} {selected} /> <TableBottom {table} {selected} />
{/if} {/if}
{:catch error}
<div class="text-white px-6 py-4 border-0 rounded relative mb-4 bg-red-500">
<span class="inline-block align-middle mr-8">
<b class="capitalize">{$_("general_promise_error")}</b>
{error}
</span>
</div>
{/await}
{/if} {/if}