Skip to content

Commit

Permalink
add select/unselect all SBs button (#1143)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv authored Nov 12, 2024
1 parent f476999 commit 50ba530
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
49 changes: 45 additions & 4 deletions src/resources/js/components/ServiceBodiesTree.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import { Button } from 'flowbite-svelte';
import Node from './ServiceBodiesTreeNode.svelte';
import type { ServiceBody } from 'bmlt-root-server-client';
import { translations } from '../stores/localization';
interface TreeNode {
label: string;
Expand Down Expand Up @@ -88,7 +90,7 @@
parent = treeMap[parent.label];
}
trees = trees;
trees = [...trees];
selectedValues = collectSelectedValues(trees);
}
Expand All @@ -107,13 +109,52 @@
trees.forEach(traverse);
return selected;
}
function selectAll() {
trees.forEach((node) => {
checkAllNodes(node, true);
});
trees = [...trees];
selectedValues = collectSelectedValues(trees);
}
function unselectAll() {
trees.forEach((node) => {
checkAllNodes(node, false);
});
trees = [...trees];
selectedValues = [];
}
function checkAllNodes(node: TreeNode, check: boolean) {
node.checked = check;
node.indeterminate = false;
if (node.children) {
node.children.forEach((child) => checkAllNodes(child, check));
}
}
function toggleAll() {
if (isAllSelected) {
unselectAll();
} else {
selectAll();
}
}
$: isAllSelected = trees.every((node) => isNodeFullySelected(node));
function isNodeFullySelected(node: TreeNode): boolean {
return !!node.checked && (!node.children || node.children.every(isNodeFullySelected));
}
</script>

<div class="mb-4">
<Button on:click={toggleAll} size="xs" color="primary" class="w-full">
{isAllSelected ? $translations.unselectAllServiceBodies : $translations.selectAllServiceBodies}
</Button>
</div>

<div>
{#each trees as tree}
<Node {tree} on:toggle={rebuildTree} />
{/each}
</div>

<style>
</style>
8 changes: 6 additions & 2 deletions src/resources/js/stores/localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const strings = new LocalizedStrings({
searchByServiceBody: 'Suche nach Service-Body',
searchMeetings: 'Suche Meetings...',
selectAllDays: 'Alle Tage wählen',
selectAllServiceBodies: 'Select All Service Bodies', // TODO: Translate
serverAdministratorTitle: 'Hauptserveradministrator*in',
serviceBodiesNoParent: 'Kein übergeordnetes Element (oberste Ebene)',
serviceBodiesTitle: 'Service-Bodies',
Expand All @@ -189,6 +190,7 @@ const strings = new LocalizedStrings({
trainLinesTitle: 'Zuglinien',
unpublished: 'Unveröffentlicht',
unselectAllDays: 'Auswahl für „Alle Tage“ aufheben',
unselectAllServiceBodies: 'Unselect All Service Bodies', // TODO: Translate
userDeleteConflictError: 'Fehler: Der Benutzer konnte nicht gelöscht werden, da er noch mindestens einem Service-Body zugeordnet ist oder das übergeordnete Element eines anderen Benutzers ist.',
userIsDeactivated: 'Benutzer ist deaktiviert.',
usernameTitle: 'Benutzername',
Expand Down Expand Up @@ -361,7 +363,8 @@ const strings = new LocalizedStrings({
searchByName: 'Search by name',
searchByServiceBody: 'Search by Service Body',
searchMeetings: 'Search meetings...',
selectAllDays: 'Select All days',
selectAllDays: 'Select All Days',
selectAllServiceBodies: 'Select All Service Bodies',
serverAdministratorTitle: 'Main Server Administrator',
serviceBodiesNoParent: 'No Parent (Top-Level)',
serviceBodiesTitle: 'Service Bodies',
Expand All @@ -386,7 +389,8 @@ const strings = new LocalizedStrings({
timeZoneTitle: 'Time Zone',
trainLinesTitle: 'Train Lines',
unpublished: 'Unpublished',
unselectAllDays: 'Unselect All days',
unselectAllDays: 'Unselect All Days',
unselectAllServiceBodies: 'Unselect All Service Bodies',
userDeleteConflictError: 'Error: The user could not be deleted because it is still associated with at least one service body or is the parent of another user.',
userIsDeactivated: 'User is deactivated.',
usernameTitle: 'Username',
Expand Down

0 comments on commit 50ba530

Please sign in to comment.