feat(donationsoverview): Switched donations overview to datatable
This commit is contained in:
parent
4a6230c439
commit
133470b6f2
18
src/components/donations/DonationDonor.svelte
Normal file
18
src/components/donations/DonationDonor.svelte
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<script>
|
||||||
|
import { _ } from "svelte-i18n";
|
||||||
|
export let donor;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if !donor || donor.firstname == 0}
|
||||||
|
{$_("donor-has-no-associated-donations")}
|
||||||
|
{:else}
|
||||||
|
<div class="flex items-center">
|
||||||
|
<a
|
||||||
|
href="../donors/{donor.id}"
|
||||||
|
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800"
|
||||||
|
>{donor.firstname}
|
||||||
|
{#if donor.middlename}{donor.middlename}{/if}
|
||||||
|
{donor.lastname}</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
{/if}
|
18
src/components/donations/DonationRunner.svelte
Normal file
18
src/components/donations/DonationRunner.svelte
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<script>
|
||||||
|
import { _ } from "svelte-i18n";
|
||||||
|
export let runner;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if !runner || runner.firstname == 0}
|
||||||
|
{$_("fixed-donation")}
|
||||||
|
{:else}
|
||||||
|
<div class="text-sm font-medium text-gray-900">
|
||||||
|
<a
|
||||||
|
href="../runners/{runner.id}"
|
||||||
|
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800"
|
||||||
|
>{runner.firstname}
|
||||||
|
{#if runner.middlename}{runner.middlename}{/if}
|
||||||
|
{runner.lastname}</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
{/if}
|
16
src/components/donations/DonationStatus.svelte
Normal file
16
src/components/donations/DonationStatus.svelte
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<script>
|
||||||
|
import { _ } from "svelte-i18n";
|
||||||
|
export let status;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if status == "PAID"}
|
||||||
|
<span
|
||||||
|
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800"
|
||||||
|
>{$_("paid")}</span
|
||||||
|
>
|
||||||
|
{:else}
|
||||||
|
<span
|
||||||
|
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800"
|
||||||
|
>{$_("open")}</span
|
||||||
|
>
|
||||||
|
{/if}
|
@ -6,21 +6,37 @@
|
|||||||
import DonationsEmptyState from "./DonationsEmptyState.svelte";
|
import DonationsEmptyState from "./DonationsEmptyState.svelte";
|
||||||
import AddDonationPaymentModal from "./AddDonationPaymentModal.svelte";
|
import AddDonationPaymentModal from "./AddDonationPaymentModal.svelte";
|
||||||
import { onMount } from "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 = "";
|
$: searchvalue = "";
|
||||||
$: active_deletes = [];
|
$: active_deletes = [];
|
||||||
|
$: selectedDonations =
|
||||||
|
$table?.getSelectedRowModel().rows.map((row) => row.original) || [];
|
||||||
|
$: selected =
|
||||||
|
$table?.getSelectedRowModel().rows.map((row) => row.index) || [];
|
||||||
$: dataLoaded = false;
|
$: dataLoaded = false;
|
||||||
|
|
||||||
export let current_donations = [];
|
export let current_donations = [];
|
||||||
export let payment_modal_open = false;
|
export let payment_modal_open = false;
|
||||||
export let editable = {};
|
export let editable = {};
|
||||||
export let original_data = {};
|
export let original_data = {};
|
||||||
export let paid_amount_input = 0;
|
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) {
|
function open_payment_modal(donation) {
|
||||||
editable = Object.assign({}, donation);
|
editable = Object.assign({}, donation);
|
||||||
original_data = Object.assign({}, donation);
|
original_data = Object.assign({}, donation);
|
||||||
@ -28,6 +44,107 @@
|
|||||||
payment_modal_open = true;
|
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 () => {
|
onMount(async () => {
|
||||||
let page = 0;
|
let page = 0;
|
||||||
while (page >= 0) {
|
while (page >= 0) {
|
||||||
@ -40,6 +157,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
current_donations = current_donations.concat(...donations);
|
current_donations = current_donations.concat(...donations);
|
||||||
|
options.update((options) => ({
|
||||||
|
...options,
|
||||||
|
data: current_donations,
|
||||||
|
}));
|
||||||
|
|
||||||
dataLoaded = true;
|
dataLoaded = true;
|
||||||
page++;
|
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"
|
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"
|
||||||
>
|
>
|
||||||
<p class="font-bold">{$_('donations-are-being-loaded')}</p>
|
<p class="font-bold">{$_("donations-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>
|
||||||
{:else if current_donations.length === 0}
|
{:else if current_donations.length === 0}
|
||||||
@ -77,197 +198,50 @@
|
|||||||
<div
|
<div
|
||||||
class="shadow border-b border-gray-200 sm:rounded-lg overflow-x-scroll"
|
class="shadow border-b border-gray-200 sm:rounded-lg overflow-x-scroll"
|
||||||
>
|
>
|
||||||
<table class="divide-y divide-gray-200 w-full">
|
<table class="w-full">
|
||||||
<thead class="bg-gray-50">
|
<thead>
|
||||||
<tr>
|
{#each $table.getHeaderGroups() as headerGroup}
|
||||||
<th
|
<tr class="select-none">
|
||||||
scope="col"
|
<th class="inset-y-0 left-0 px-4 py-2 text-left w-px">
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
<InputElement
|
||||||
>
|
type="checkbox"
|
||||||
{$_("donor")}
|
checked={$table.getIsAllRowsSelected()}
|
||||||
</th>
|
indeterminate={$table.getIsSomeRowsSelected()}
|
||||||
<th
|
on:change={() => $table.toggleAllRowsSelected()}
|
||||||
scope="col"
|
/>
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
</th>
|
||||||
>
|
{#each headerGroup.headers as header}
|
||||||
{$_("runner")}
|
<TableHeader {header} />
|
||||||
</th>
|
{/each}
|
||||||
<th
|
</tr>
|
||||||
scope="col"
|
{/each}
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
|
||||||
>
|
|
||||||
{$_("amount-per-kilometer")}
|
|
||||||
</th>
|
|
||||||
<th
|
|
||||||
scope="col"
|
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
|
||||||
>
|
|
||||||
{$_("donation-amount")}
|
|
||||||
</th>
|
|
||||||
<th
|
|
||||||
scope="col"
|
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
|
||||||
>
|
|
||||||
{$_("paid-amount")}
|
|
||||||
</th>
|
|
||||||
<th
|
|
||||||
scope="col"
|
|
||||||
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
|
||||||
>
|
|
||||||
{$_("status")}
|
|
||||||
</th>
|
|
||||||
<th scope="col" class="relative px-6 py-3">
|
|
||||||
<span class="sr-only">{$_("action")}</span>
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="divide-y divide-gray-200">
|
<tbody>
|
||||||
{#each current_donations as donation}
|
{#each $table.getRowModel().rows as row}
|
||||||
{#if donation.donor.firstname
|
<tr>
|
||||||
.toLowerCase()
|
<td class="inset-y-0 left-0 px-4 py-2 text-center w-px">
|
||||||
.includes(searchvalue.toLowerCase()) || donation.donor.lastname
|
<InputElement
|
||||||
.toLowerCase()
|
type="checkbox"
|
||||||
.includes(searchvalue.toLowerCase()) || donation.runner?.firstname
|
checked={row.getIsSelected()}
|
||||||
.toLowerCase()
|
on:change={() => row.toggleSelected()}
|
||||||
.includes(searchvalue.toLowerCase()) || donation.runner?.lastname
|
/>
|
||||||
.toLowerCase()
|
</td>
|
||||||
.includes(searchvalue.toLowerCase()) || should_display_based_on_id(donation.id)}
|
{#each row.getVisibleCells() as cell}
|
||||||
<tr data-rowid="donation_{donation.id}">
|
<td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
<svelte:component
|
||||||
<div class="flex items-center">
|
this={flexRender(
|
||||||
<a
|
cell.column.columnDef.cell,
|
||||||
href="../donors/{donation.donor.id}"
|
cell.getContext()
|
||||||
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800"
|
)}
|
||||||
>{donation.donor.firstname}
|
/>
|
||||||
{donation.donor.middlename || ""}
|
|
||||||
{donation.donor.lastname}</a
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
{/each}
|
||||||
{#if donation.runner}
|
</tr>
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
<a
|
|
||||||
href="../runners/{donation.runner.id}"
|
|
||||||
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800"
|
|
||||||
>{donation.runner.firstname}
|
|
||||||
{donation.runner.middlename || ""}
|
|
||||||
{donation.runner.lastname}</a
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
{$_("fixed-donation")}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
|
||||||
{#if donation.amountPerDistance}
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
{(donation.amountPerDistance / 100)
|
|
||||||
.toFixed(2)
|
|
||||||
.toLocaleString("de-DE", { valute: "EUR" })}€
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
{$_("fixed-donation")}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
{(donation.amount / 100)
|
|
||||||
.toFixed(2)
|
|
||||||
.toLocaleString("de-DE", { valute: "EUR" })}€
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
|
||||||
<div class="text-sm font-medium text-gray-900">
|
|
||||||
{(donation.paidAmount / 100)
|
|
||||||
.toFixed(2)
|
|
||||||
.toLocaleString("de-DE", { valute: "EUR" })}€
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
|
||||||
{#if donation.status == "PAID"}
|
|
||||||
<span
|
|
||||||
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800"
|
|
||||||
>{$_("paid")}</span
|
|
||||||
>
|
|
||||||
{:else}
|
|
||||||
<span
|
|
||||||
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800"
|
|
||||||
>{$_("open")}</span
|
|
||||||
>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
{#if active_deletes[donation.id] === true}
|
|
||||||
<td
|
|
||||||
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
on:click={() => {
|
|
||||||
active_deletes[donation.id] = false;
|
|
||||||
}}
|
|
||||||
tabindex="0"
|
|
||||||
class="ml-4 text-indigo-600 hover:text-indigo-900 cursor-pointer"
|
|
||||||
>{$_("cancel-delete")}</button
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
on:click={() => {
|
|
||||||
DonationService.donationControllerRemove(
|
|
||||||
donation.id,
|
|
||||||
false
|
|
||||||
).then((resp) => {
|
|
||||||
current_donations = current_donations.filter(
|
|
||||||
(obj) => obj.id !== donation.id
|
|
||||||
);
|
|
||||||
Toastify({
|
|
||||||
text: $_("donation-deleted"),
|
|
||||||
duration: 500,
|
|
||||||
backgroundColor:
|
|
||||||
"linear-gradient(to right, #00b09b, #96c93d)",
|
|
||||||
}).showToast();
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
tabindex="0"
|
|
||||||
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer"
|
|
||||||
>{$_("confirm-delete")}</button
|
|
||||||
>
|
|
||||||
</td>
|
|
||||||
{:else}
|
|
||||||
<td
|
|
||||||
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
on:click={() => {
|
|
||||||
open_payment_modal(donation);
|
|
||||||
}}
|
|
||||||
class="text-[#025a21] hover:text-green-900 mr-4"
|
|
||||||
>{$_("enter-payment")}</button
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href="./{donation.id}"
|
|
||||||
class="text-indigo-600 hover:text-indigo-900"
|
|
||||||
>{$_("details")}</a
|
|
||||||
>
|
|
||||||
{#if store.state.jwtinfo.userdetails.permissions.includes("DONATION:DELETE")}
|
|
||||||
<button
|
|
||||||
on:click={() => {
|
|
||||||
active_deletes[donation.id] = true;
|
|
||||||
}}
|
|
||||||
tabindex="0"
|
|
||||||
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer"
|
|
||||||
>{$_("delete")}</button
|
|
||||||
>
|
|
||||||
{/if}
|
|
||||||
</td>
|
|
||||||
{/if}
|
|
||||||
</tr>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="h-2" />
|
||||||
|
<TableBottom {table} {selected} />
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user