diff --git a/src/components/donations/DonationDonor.svelte b/src/components/donations/DonationDonor.svelte new file mode 100644 index 00000000..a134053b --- /dev/null +++ b/src/components/donations/DonationDonor.svelte @@ -0,0 +1,18 @@ + + +{#if !donor || donor.firstname == 0} + {$_("donor-has-no-associated-donations")} +{:else} +
+{/if} diff --git a/src/components/donations/DonationRunner.svelte b/src/components/donations/DonationRunner.svelte new file mode 100644 index 00000000..64956f6b --- /dev/null +++ b/src/components/donations/DonationRunner.svelte @@ -0,0 +1,18 @@ + + +{#if !runner || runner.firstname == 0} + {$_("fixed-donation")} +{:else} + +{/if} diff --git a/src/components/donations/DonationStatus.svelte b/src/components/donations/DonationStatus.svelte new file mode 100644 index 00000000..e3b6cf63 --- /dev/null +++ b/src/components/donations/DonationStatus.svelte @@ -0,0 +1,16 @@ + + +{#if status == "PAID"} + {$_("paid")} +{:else} + {$_("open")} +{/if} diff --git a/src/components/donations/DonationsOverview.svelte b/src/components/donations/DonationsOverview.svelte index c165451c..dc215c1a 100644 --- a/src/components/donations/DonationsOverview.svelte +++ b/src/components/donations/DonationsOverview.svelte @@ -6,21 +6,37 @@ import DonationsEmptyState from "./DonationsEmptyState.svelte"; import AddDonationPaymentModal from "./AddDonationPaymentModal.svelte"; import { onMount } from "svelte"; + import { + createSvelteTable, + flexRender, + getCoreRowModel, + getFilteredRowModel, + getPaginationRowModel, + getSortedRowModel, + renderComponent, + } from "@tanstack/svelte-table"; + import { writable } from "svelte/store"; + import TableBottom from "../shared/TableBottom.svelte"; + import InputElement from "../shared/InputElement.svelte"; + import TableHeader from "../shared/TableHeader.svelte"; + import TableActions from "../shared/TableActions.svelte"; + import DonationDonor from "./DonationDonor.svelte"; + import DonationRunner from "./DonationRunner.svelte"; + import DonationStatus from "./DonationStatus.svelte"; $: searchvalue = ""; $: active_deletes = []; + $: selectedDonations = + $table?.getSelectedRowModel().rows.map((row) => row.original) || []; + $: selected = + $table?.getSelectedRowModel().rows.map((row) => row.index) || []; $: dataLoaded = false; + export let current_donations = []; export let payment_modal_open = false; export let editable = {}; export let original_data = {}; export let paid_amount_input = 0; - function should_display_based_on_id(id) { - if (searchvalue.toString().slice(-1) === "*") { - return id.toString().startsWith(searchvalue.replace("*", "")); - } - return id.toString() === searchvalue; - } function open_payment_modal(donation) { editable = Object.assign({}, donation); original_data = Object.assign({}, donation); @@ -28,6 +44,107 @@ payment_modal_open = true; } + //Section table + const columns = [ + { + accessorKey: "id", + header: () => "id", + filterFn: `equalsString`, + }, + { + accessorKey: "donor", + header: () => $_("donor"), + cell: (info) => { + return renderComponent(DonationDonor, { donor: info.getValue() }); + }, + filterFn: `includesString`, + }, + { + accessorKey: "runner", + header: () => $_("runner"), + cell: (info) => { + return renderComponent(DonationRunner, { runner: info.getValue() }); + }, + filterFn: `includesString`, + }, + { + accessorKey: "amountPerDistance", + header: () => $_("amount-per-kilometer"), + cell: (info) => { + if (!info.getValue()) { + return $_("fixed-donation"); + } + return `${(info.getValue() / 100) + .toFixed(2) + .toLocaleString("de-DE", { valute: "EUR" })} €`; + }, + enableColumnFilter: false, + }, + { + accessorKey: "amount", + header: () => $_("donation-amount"), + cell: (info) => { + return `${(info.getValue() / 100) + .toFixed(2) + .toLocaleString("de-DE", { valute: "EUR" })} €`; + }, + enableColumnFilter: false, + }, + { + accessorKey: "paidAmount", + header: () => $_("total-paid-amount"), + cell: (info) => { + return `${(info.getValue() / 100) + .toFixed(2) + .toLocaleString("de-DE", { valute: "EUR" })} €`; + }, + enableColumnFilter: false, + }, + { + accessorKey: "status", + header: () => $_("status"), + cell: (info) => { + return renderComponent(DonationStatus, {status: info.getValue()}); + }, + enableColumnFilter: false, + }, + { + accessorKey: "actions", + header: () => $_("action"), + cell: (info) => { + return renderComponent(TableActions, { + detailsLink: `./${info.row.original.id}`, + deleteAction: () => { + active_deletes = current_donations.filter( + (r) => r.id == info.row.original.id + ); + }, + deleteEnabled: + store.state.jwtinfo.userdetails.permissions.includes( + "DONATION:DELETE" + ), + }); + }, + enableColumnFilter: false, + enableSorting: false, + }, + ]; + const options = writable({ + data: [], + columns: columns, + initialState: { + pagination: { + pageSize: 50, + }, + }, + enableRowSelection: true, + getCoreRowModel: getCoreRowModel(), + getFilteredRowModel: getFilteredRowModel(), + getPaginationRowModel: getPaginationRowModel(), + getSortedRowModel: getSortedRowModel(), + }); + const table = createSvelteTable(options); + onMount(async () => { let page = 0; while (page >= 0) { @@ -40,6 +157,10 @@ } current_donations = current_donations.concat(...donations); + options.update((options) => ({ + ...options, + data: current_donations, + })); dataLoaded = true; page++; @@ -61,7 +182,7 @@ class="bg-teal-lightest border-t-4 border-teal rounded-b text-teal-darkest px-4 py-3 shadow-md my-2" role="alert" > -{$_('donations-are-being-loaded')}
+{$_("donations-are-being-loaded")}
{$_("this-might-take-a-moment")}
{:else if current_donations.length === 0} @@ -77,197 +198,50 @@- {$_("donor")} - | -- {$_("runner")} - | -- {$_("amount-per-kilometer")} - | -- {$_("donation-amount")} - | -- {$_("paid-amount")} - | -- {$_("status")} - | -- {$_("action")} - | -
---|
+ |
+ {#each headerGroup.headers as header}
+ ||||||||
---|---|---|---|---|---|---|---|---|
- + | ||||||||
+ |
+ {#each row.getVisibleCells() as cell}
+
+ |
-
- {#if donation.runner}
-
- {:else}
-
- {$_("fixed-donation")}
-
- {/if}
- |
-
- {#if donation.amountPerDistance}
-
- {(donation.amountPerDistance / 100)
- .toFixed(2)
- .toLocaleString("de-DE", { valute: "EUR" })}€
-
- {:else}
-
- {$_("fixed-donation")}
-
- {/if}
- |
-
-
- {(donation.amount / 100)
- .toFixed(2)
- .toLocaleString("de-DE", { valute: "EUR" })}€
-
- |
-
-
- {(donation.paidAmount / 100)
- .toFixed(2)
- .toLocaleString("de-DE", { valute: "EUR" })}€
-
- |
- - {#if donation.status == "PAID"} - {$_("paid")} - {:else} - {$_("open")} - {/if} - | - {#if active_deletes[donation.id] === true} -- - - | - {:else} -- - {$_("details")} - {#if store.state.jwtinfo.userdetails.permissions.includes("DONATION:DELETE")} - - {/if} - | - {/if} -