Compare commits

...

4 Commits

Author SHA1 Message Date
Jürgen Mummert ac203b37ce Persist event filter state across reload and navigation 2026-02-23 21:54:27 +01:00
Jürgen Mummert 4b62e72382 Add svg class support for organization logo figures 2026-02-23 21:40:30 +01:00
Jürgen Mummert 97e4f639a0 Use Tom Select CDN major version 2 2026-02-23 21:28:15 +01:00
Jürgen Mummert b714bbeb1b Blur Tom Select only for mouse and touch selection 2026-02-23 21:22:59 +01:00
2 changed files with 168 additions and 9 deletions
@@ -96,8 +96,8 @@
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tom-select@2.4.3/dist/css/tom-select.css">
<script src="https://cdn.jsdelivr.net/npm/tom-select@2.4.3/dist/js/tom-select.complete.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tom-select@2/dist/css/tom-select.css">
<script src="https://cdn.jsdelivr.net/npm/tom-select@2/dist/js/tom-select.complete.min.js"></script>
<script type="module">
const filters = document.getElementById('eventfilters');
@@ -124,6 +124,8 @@
const orgWidget = orgSelect?.closest('.widget-select');
const resetButton = filters.querySelector('#eventfilter-reset');
const status = filters.querySelector('#eventfilter-status');
const stateStorageKey = 'event-filter-state';
const stateQueryKey = 'event_filter';
const animationMs = 220;
let hideTimers = new WeakMap();
@@ -135,6 +137,8 @@
return null;
}
let shouldBlurOnChange = false;
return new window.TomSelect(selectElement, {
create: false,
sortField: {
@@ -149,6 +153,30 @@
return '<div class="no-more-results" role="option" aria-disabled="true">Keine weiteren Ergebnisse</div>';
},
},
onInitialize() {
const markPointerInteraction = () => {
shouldBlurOnChange = true;
};
const markKeyboardInteraction = () => {
shouldBlurOnChange = false;
};
this.control.addEventListener('pointerdown', markPointerInteraction);
this.control.addEventListener('touchstart', markPointerInteraction, { passive: true });
this.control.addEventListener('keydown', markKeyboardInteraction);
this.dropdown.addEventListener('pointerdown', markPointerInteraction);
this.dropdown.addEventListener('touchstart', markPointerInteraction, { passive: true });
this.dropdown.addEventListener('keydown', markKeyboardInteraction);
},
onChange() {
if (!shouldBlurOnChange) {
return;
}
this.blur();
shouldBlurOnChange = false;
},
});
};
@@ -156,6 +184,109 @@
const locationTom = initTomSelect(locationSelect);
const orgTom = initTomSelect(orgSelect);
const hasOptionValue = (selectElement, value) => {
if (!selectElement) {
return false;
}
return Array.from(selectElement.options).some((option) => option.value === value);
};
const rawValueToFilterState = (rawValue) => {
const value = (rawValue || '').trim();
if (!value) {
return { type: 'all', value: '' };
}
if (value.startsWith('tag-') && hasOptionValue(tagSelect, value)) {
return { type: 'tag', value: value.replace('tag-', '') };
}
if (value.startsWith('location-') && hasOptionValue(locationSelect, value)) {
return { type: 'location', value: value.replace('location-', '') };
}
if (value.startsWith('org-') && hasOptionValue(orgSelect, value)) {
return { type: 'org', value: value.replace('org-', '') };
}
return { type: 'all', value: '' };
};
const filterStateToRawValue = (filterState) => {
if (!filterState.value || filterState.type === 'all') {
return '';
}
if (filterState.type === 'tag') {
return `tag-${filterState.value}`;
}
if (filterState.type === 'location') {
return `location-${filterState.value}`;
}
if (filterState.type === 'org') {
return `org-${filterState.value}`;
}
return '';
};
const readUrlState = () => {
const url = new URL(window.location.href);
return (url.searchParams.get(stateQueryKey) || '').trim();
};
const writeUrlState = (value) => {
const url = new URL(window.location.href);
if (value) {
url.searchParams.set(stateQueryKey, value);
} else {
url.searchParams.delete(stateQueryKey);
}
window.history.replaceState(window.history.state, '', url);
};
const readStoredState = () => {
try {
return (window.sessionStorage.getItem(stateStorageKey) || '').trim();
} catch (error) {
return '';
}
};
const writeStoredState = (value) => {
try {
if (value) {
window.sessionStorage.setItem(stateStorageKey, value);
} else {
window.sessionStorage.removeItem(stateStorageKey);
}
} catch (error) {
// noop
}
};
const syncState = (filterState) => {
const rawValue = filterStateToRawValue(filterState);
writeStoredState(rawValue);
writeUrlState(rawValue);
};
const applyControlState = (filterState) => {
const tagValue = filterState.type === 'tag' ? `tag-${filterState.value}` : '';
const locationValue = filterState.type === 'location' ? `location-${filterState.value}` : '';
const orgValue = filterState.type === 'org' ? `org-${filterState.value}` : '';
setSelectValue(tagSelect, tagTom, tagValue);
setSelectValue(locationSelect, locationTom, locationValue);
setSelectValue(orgSelect, orgTom, orgValue);
};
const setSelectValue = (selectElement, tomInstance, value) => {
if (!selectElement) {
return;
@@ -288,6 +419,7 @@
});
updateStatus(filterState);
syncState(filterState);
};
tagSelect?.addEventListener('change', () => {
@@ -349,5 +481,16 @@
applyFilter({ type: 'all', value: '' });
});
applyFilter(currentFilter);
const urlState = readUrlState();
const storedState = readStoredState();
const initialState = rawValueToFilterState(urlState || storedState);
applyControlState(initialState);
applyFilter(initialState);
window.addEventListener('popstate', () => {
const stateFromUrl = rawValueToFilterState(readUrlState());
applyControlState(stateFromUrl);
applyFilter(stateFromUrl);
});
</script>
@@ -53,7 +53,7 @@ class OrganizationListingTemplateDataListener
$organizationIds = array_values(array_unique(array_values($rowToOrganizationIdMap)));
$organizationTagMap = $this->fetchOrganizationTagMap($organizationIds);
$organizationLogoUuidMap = $this->fetchOrganizationLogoUuidMap($organizationIds);
$organizationLogoMap = $this->fetchOrganizationLogoMap($organizationIds);
$organizationTagLabelMap = [];
$rowTagIdsList = [];
@@ -74,7 +74,9 @@ class OrganizationListingTemplateDataListener
}
$tagData = $organizationTagMap[$organizationId] ?? ['ids' => [], 'labels' => []];
$logoUuid = $organizationLogoUuidMap[$organizationId] ?? '';
$logoData = $organizationLogoMap[$organizationId] ?? ['uuid' => '', 'isSvg' => false];
$logoUuid = (string) ($logoData['uuid'] ?? '');
$logoIsSvg = (bool) ($logoData['isSvg'] ?? false);
$tagIdsCsv = implode(',', $tagData['ids']);
$tagLabelsCsv = implode(', ', $tagData['labels']);
@@ -84,6 +86,7 @@ class OrganizationListingTemplateDataListener
if ('' !== $logoUuid) {
$tbody[$rowIndex]['logo_uuid']['content'] = $logoUuid;
$tbody[$rowIndex]['logo_is_svg']['content'] = $logoIsSvg ? '1' : '';
}
}
@@ -266,16 +269,19 @@ class OrganizationListingTemplateDataListener
}
/** @param list<int> $organizationIds
* @return array<int, string>
* @return array<int, array{uuid: string, isSvg: bool}>
*/
private function fetchOrganizationLogoUuidMap(array $organizationIds): array
private function fetchOrganizationLogoMap(array $organizationIds): array
{
if ([] === $organizationIds) {
return [];
}
$rows = $this->connection->executeQuery(
'SELECT o.id AS organization_id, o.logo AS logo_uuid FROM tl_organization o WHERE o.id IN (?)',
'SELECT o.id AS organization_id, o.logo AS logo_uuid, f.extension AS file_extension, f.path AS file_path
FROM tl_organization o
LEFT JOIN tl_files f ON f.uuid = o.logo
WHERE o.id IN (?)',
[$organizationIds],
[ArrayParameterType::INTEGER],
)->fetchAllAssociative();
@@ -285,12 +291,22 @@ class OrganizationListingTemplateDataListener
foreach ($rows as $row) {
$organizationId = (int) ($row['organization_id'] ?? 0);
$logoUuid = $this->normalizeUuid($row['logo_uuid'] ?? null);
$extension = strtolower(trim((string) ($row['file_extension'] ?? '')));
if ('' === $extension && isset($row['file_path']) && \is_scalar($row['file_path'])) {
$extension = strtolower((string) pathinfo((string) $row['file_path'], PATHINFO_EXTENSION));
}
$isSvg = 'svg' === $extension;
if ($organizationId <= 0 || '' === $logoUuid) {
continue;
}
$map[$organizationId] = $logoUuid;
$map[$organizationId] = [
'uuid' => $logoUuid,
'isSvg' => $isSvg,
];
}
return $map;