Compare commits

..

No commits in common. "b82d638de1aa1f72aada212cf3e4147d808b4fcf" and "026d3d41c1b976a4dc7c733576a6a9e8d4b13b78" have entirely different histories.

6 changed files with 234 additions and 229 deletions

View File

@ -10,7 +10,6 @@
}, },
"license": "CC-BY-NC-SA-4.0", "license": "CC-BY-NC-SA-4.0",
"devDependencies": { "devDependencies": {
"@vincjo/datatables": "^1.1.0",
"@odit/lfk-client-js": "0.13.1", "@odit/lfk-client-js": "0.13.1",
"@odit/license-exporter": "0.0.11", "@odit/license-exporter": "0.0.11",
"@sveltejs/vite-plugin-svelte": "1.0.0-next.6", "@sveltejs/vite-plugin-svelte": "1.0.0-next.6",

View File

@ -369,7 +369,7 @@
</div> </div>
{#if cards_dropdown_open} {#if cards_dropdown_open}
<div <div
class="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-10" class="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5"
id="cards:dropdown:menu"> id="cards:dropdown:menu">
<div <div
class="py-1" class="py-1"

View File

@ -298,7 +298,7 @@
</div> </div>
{#if certificates_dropdown_open} {#if certificates_dropdown_open}
<div <div
class="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-10" class="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5"
id="certificates:dropdown:menu"> id="certificates:dropdown:menu">
<div <div
class="py-1" class="py-1"

View File

@ -272,7 +272,7 @@
</div> </div>
{#if sponsoring_contracts_download_open} {#if sponsoring_contracts_download_open}
<div <div
class="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-10" class="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5"
id="sponsoring:dropdown:menu"> id="sponsoring:dropdown:menu">
<div <div
class="py-1" class="py-1"

View File

@ -1,26 +1,37 @@
<script> <script>
import { _ } from "svelte-i18n"; import { getLocaleFromNavigator, _ } from "svelte-i18n";
import { import {
RunnerService, RunnerService,
RunnerTeamService, RunnerTeamService,
RunnerOrganizationService, RunnerOrganizationService,
} from "@odit/lfk-client-js"; } from "@odit/lfk-client-js";
import ThFilterGroup from "./ThFilterGroup.svelte";
import { DataHandler, Datatable, Th, ThFilter } from "@vincjo/datatables";
import store from "../../store"; import store from "../../store";
import RunnersEmptyState from "./RunnersEmptyState.svelte";
import Select from "svelte-select";
import GenerateSponsoringContracts from "../pdf_generation/GenerateSponsoringContracts.svelte"; import GenerateSponsoringContracts from "../pdf_generation/GenerateSponsoringContracts.svelte";
import GenerateRunnerCards from "../pdf_generation/GenerateRunnerCards.svelte"; import GenerateRunnerCards from "../pdf_generation/GenerateRunnerCards.svelte";
import GenerateRunnerCertificates from "../pdf_generation/GenerateRunnerCertificates.svelte"; import GenerateRunnerCertificates from "../pdf_generation/GenerateRunnerCertificates.svelte";
import { onMount } from "svelte"; $: searchvalue = "";
$: active_deletes = []; $: active_deletes = [];
let dataLoaded = false; export let current_runners = [];
let current_runners = []; const runners_promise = RunnerService.runnerControllerGetAll().then((val) => {
const handler = new DataHandler(current_runners, { rowsPerPage: 50 }); current_runners = val;
const rows = handler.getRows(); });
$: sponsoring_contracts_show = generate_runners.length > 0; $: selectedFilter_teams = null;
$: cards_show = generate_runners.length > 0; $: selectedFilter = null;
$: certificates_show = generate_runners.length > 0; $: filter__teams = selectedFilter_teams || [];
$: generate_runners = []; //current_runners.filter((r) => r.selected === true); $: filter__orgs = selectedFilter || [];
$: filterGroupIDs = filter__teams.concat(filter__orgs).map((i) => i.value);
$: sponsoring_contracts_show = current_runners.some(
(r) => r.is_selected === true
);
$: cards_show = current_runners.some(
(r) => r.is_selected === true
);
$: certificates_show = current_runners.some(
(r) => r.is_selected === true
);
$: generate_runners = current_runners.filter((r) => r.is_selected === true);
$: teams = []; $: teams = [];
$: orgs = []; $: orgs = [];
$: mappedteams = teams.map(function (g) { $: mappedteams = teams.map(function (g) {
@ -31,193 +42,222 @@
return { value: g.id, label: g.name }; return { value: g.id, label: g.name };
}) })
.concat(mappedteams); .concat(mappedteams);
onMount(() => {
RunnerService.runnerControllerGetAll().then((val) => { RunnerTeamService.runnerTeamControllerGetAll().then((val) => {
current_runners = val; teams = val;
dataLoaded = true;
handler.setRows(val);
});
RunnerTeamService.runnerTeamControllerGetAll().then((val) => {
teams = val;
});
RunnerOrganizationService.runnerOrganizationControllerGetAll().then(
(val) => {
orgs = val;
}
);
}); });
RunnerOrganizationService.runnerOrganizationControllerGetAll().then((val) => {
orgs = val;
});
function should_display_based_on_id(id) {
if (searchvalue.toString().slice(-1) === "*") {
return id.toString().startsWith(searchvalue.replace("*", ""));
}
return id.toString() === searchvalue;
}
</script> </script>
{#if store.state.jwtinfo.userdetails.permissions.includes("RUNNER:GET")} {#if store.state.jwtinfo.userdetails.permissions.includes('RUNNER:GET')}
{#if !dataLoaded} {#await runners_promise}
<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">
> <p class="font-bold">{$_('runners-are-being-loaded')}</p>
<p class="font-bold">{$_("runners-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} {:then}
<div class="h-12"> {#if current_runners.length === 0}
<GenerateSponsoringContracts <RunnersEmptyState />
bind:sponsoring_contracts_show {:else}
bind:generate_runners <input
/> type="search"
<GenerateRunnerCards bind:cards_show bind:generate_runners /> bind:value={searchvalue}
<GenerateRunnerCertificates placeholder={$_('datatable.search')}
bind:certificates_show aria-label={$_('datatable.search')}
bind:generate_runners class="gridjs-input gridjs-search-input mb-4" />
/> <div class="block mb-6">
</div> <label
<Datatable {handler}> for="country"
<table> class="text-sm font-medium text-gray-700">{$_('filter-by-organization-team')}</label>
<thead> <Select
<tr> on:select={(event) => {
<th> selectedFilter = event.detail;
<input }}
type="checkbox" selectedValue={selectedFilter}
class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" placeholder={$_('filter-by-organization-team')}
checked={generate_runners.length == current_runners.length} containerClasses="mt-1 py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
on:click={() => { items={selectgroups}
if (generate_runners.length != current_runners.length) { isMulti={true} />
generate_runners = current_runners; </div>
} else { <div class="h-12">
generate_runners = []; <GenerateSponsoringContracts
} bind:sponsoring_contracts_show
}} bind:generate_runners />
/> <GenerateRunnerCards
</th> bind:cards_show
<Th {handler} orderBy="id">ID</Th> bind:generate_runners />
<Th {handler} orderBy="firstname">First Name</Th> <GenerateRunnerCertificates
<Th {handler} orderBy="middlename">Middle Name</Th> bind:certificates_show
<Th {handler} orderBy="lastname">Last Name</Th> bind:generate_runners />
<th>Gruppe</th> </div>
<Th {handler} orderBy="distance">Distanz</Th> <div
<th>{$_("action")}</th> class="shadow border-b border-gray-200 sm:rounded-lg overflow-x-scroll">
</tr> <table class="divide-y divide-gray-200 w-full">
<tr> <thead class="bg-gray-50">
<th />
<ThFilter {handler} filterBy="id" />
<ThFilter {handler} filterBy="firstname" />
<ThFilter {handler} filterBy="middlename" />
<ThFilter {handler} filterBy="lastname" />
<ThFilterGroup groups={selectgroups} {handler} />
<th />
<th />
</tr>
</thead>
<tbody>
{#each $rows as row}
<tr> <tr>
<td> <th
<input scope="col"
type="checkbox" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" <span
checked={generate_runners.filter((i)=>i.id == row.id).length > 0}
on:click={() => { on:click={() => {
if ( const newstate = !current_runners.some((r) => r.is_selected === true);
generate_runners.findIndex((i) => i.id == row.id) == -1 current_runners = current_runners.map((r) => {
) { r.is_selected = newstate;
generate_runners.push(row); return r;
generate_runners = generate_runners; });
} else {
generate_runners = generate_runners.filter(
(r) => r.id != row.id
);
}
console.log(generate_runners)
}} }}
/> class="underline cursor-pointer select-none">{#if current_runners.some((r) => r.is_selected === true)}
</td> {$_('deselect-all')}
<td>{row.id}</td> {:else}{$_('select-all')}{/if}
<td>{row.firstname}</td> </span>
<td>{row.middlename || ""}</td> </th>
<td>{row.lastname}</td> <th
<td scope="col"
>{#if row.group.responseType === "RUNNERTEAM"} class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
<a {$_('name')}
href="../teams/{row.group.id}" </th>
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800" <th
>{row.group.parentGroup.name} &gt; {row.group.name}</a scope="col"
> class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
{/if} {$_('contact-information')}
{#if row.group.responseType === "RUNNERORGANIZATION"} </th>
<a <th
href="../orgs/{row.group.id}" scope="col"
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
>{row.group.name}</a {$_('group')}
> </th>
{/if}</td <th
> scope="col"
<td>{row.distance / 1000} km</td> class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
<td> {$_('distance-in-km')}
{#if active_deletes[row.id] === true} </th>
<button <th scope="col" class="relative px-6 py-3">
on:click={() => { <span class="sr-only">{$_('action')}</span>
active_deletes[row.id] = false; </th>
}}
tabindex="0"
class="ml-4 text-indigo-600 hover:text-indigo-900 cursor-pointer"
>{$_("cancel-delete")}</button
>
<button
on:click={() => {
RunnerService.runnerControllerRemove(row.id, true)
.then((resp) => {
current_runners = current_runners.filter(
(obj) => obj.id !== row.id
);
})
.catch((err) => {});
}}
tabindex="0"
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer"
>{$_("confirm-delete")}</button
>
{:else}
<a
href="./{row.id}"
class="text-indigo-600 hover:text-indigo-900"
>{$_("details")}</a
>
{#if store.state.jwtinfo.userdetails.permissions.includes("RUNNER:DELETE")}
<button
on:click={() => {
active_deletes[row.id] = true;
}}
tabindex="0"
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer"
>{$_("delete")}</button
>
{/if}
{/if}
</td>
</tr> </tr>
{/each} </thead>
</tbody> <tbody class="divide-y divide-gray-200">
</table> {#each current_runners as runner}
</Datatable> {#if runner.firstname
{/if} .toLowerCase()
.includes(
searchvalue.toLowerCase()
) || runner.lastname
.toLowerCase()
.includes(
searchvalue.toLowerCase()
) || should_display_based_on_id(runner.id)}
{#if filterGroupIDs.includes(runner.group.id) || filterGroupIDs.includes(runner.group.parentGroup?.id) || filterGroupIDs.length === 0}
<tr
data-rowid="user_{runner.id}"
data-groupid={runner.group.id}>
<td class="px-6 py-4 whitespace-nowrap">
<input
bind:checked={runner.is_selected}
type="checkbox"
class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded" />
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div class="ml-4">
<div class="text-sm font-medium text-gray-900">
{runner.firstname}
{runner.middlename || ''}
{runner.lastname}
</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
{#if runner.email}
<div class="text-sm text-gray-500">{runner.email}</div>
{/if}
{#if runner.phone}
<div class="text-sm text-gray-500">{runner.phone}</div>
{/if}
{#if runner.address.address1 !== null}
{runner.address.address1}<br />
{runner.address.address2 || ''}<br />
{runner.address.postalcode}
{runner.address.city}
{runner.address.country}
{/if}
</td>
<td class="px-6 py-4 whitespace-nowrap">
{#if runner.group.responseType === 'RUNNERTEAM'}
<a
href="../teams/{runner.group.id}"
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">{runner.group.parentGroup.name} &gt; {runner.group.name}</a>
{/if}
{#if runner.group.responseType === 'RUNNERORGANIZATION'}
<a
href="../orgs/{runner.group.id}"
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">{runner.group.name}</a>
{/if}
</td>
<td class="px-6 py-4 whitespace-nowrap">
{runner.distance /1000 } km
</td>
{#if active_deletes[runner.id] === true}
<td
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<button
on:click={() => {
active_deletes[runner.id] = false;
}}
tabindex="0"
class="ml-4 text-indigo-600 hover:text-indigo-900 cursor-pointer">{$_('cancel-delete')}</button>
<button
on:click={() => {
RunnerService.runnerControllerRemove(runner.id, true)
.then((resp) => {
current_runners = current_runners.filter((obj) => obj.id !== runner.id);
})
.catch((err) => {});
}}
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">
<a
href="./{runner.id}"
class="text-indigo-600 hover:text-indigo-900">{$_('details')}</a>
{#if store.state.jwtinfo.userdetails.permissions.includes('RUNNER:DELETE')}
<button
on:click={() => {
active_deletes[runner.id] = true;
}}
tabindex="0"
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer">{$_('delete')}</button>
{/if}
</td>
{/if}
</tr>
{/if}
{/if}
{/each}
</tbody>
</table>
</div>
{/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}
<style>
thead {
background: #fff;
}
thead {
position: sticky;
inset-block-start: 0;
}
tbody td {
padding: 4px;
}
tbody tr:nth-child(even) {
background: #fafafa;
}
tbody tr {
transition: all, 0.2s;
}
tbody tr:hover {
background: #f5f5f5;
}
</style>

View File

@ -1,34 +0,0 @@
<script>
export let groups;
export let handler;
let selected = "all";
</script>
<th>
<select
on:input={() => {
setTimeout(() => {
if (`${selected}`.trim()) {
const value = selected;
handler.filter(value, (runner) => {
if (
runner.group.id === value ||
runner?.group?.parentGroup?.id === value ||
value === "all"
)
return runner;
return "";
});
}
}, 50);
}}
bind:value={selected}
name="groupfilter"
id="groupfilter"
>
<option value="all">Alle</option>
{#each groups as g}
<option value={g.value}>{g.label}</option>
{/each}
</select>
</th>