mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-08-10 07:11:18 +02:00
repertoire: remove matched-first sorting and faded/disabled system for filter entries
Remove the system that sorted valid (matched) filter entries to the top and faded/disabled unmatched ones when any filter was active. Entries now stay in their natural alphabetical/numeric order regardless of selection state. - Drop usort calls that reordered entries by matched status - Simplify repFilterEntry: remove anyActive and colHasMatch params - Remove colHasMatches computation - Remove rep-entry--faded CSS rule - All filter buttons remain clickable at all times
This commit is contained in:
@@ -62,22 +62,18 @@ function repFilterEntry(
|
||||
array $item,
|
||||
string $dim,
|
||||
array $activeSets,
|
||||
bool $anyActive,
|
||||
bool $colHasMatch,
|
||||
string $hx,
|
||||
): void {
|
||||
$val = (string)$item['value'];
|
||||
$isActive = in_array($val, $activeSets[$dim], true);
|
||||
$isFaded = $anyActive && $colHasMatch && !$item['matched'] && !$isActive;
|
||||
$cls = 'rep-entry'
|
||||
. ($isActive ? ' rep-entry--selected' : '')
|
||||
. ($isFaded ? ' rep-entry--faded' : '');
|
||||
. ($isActive ? ' rep-entry--selected' : '');
|
||||
$url = repToggleUrl($activeSets, $dim, $val);
|
||||
?>
|
||||
<li>
|
||||
<button type="button" class="<?= $cls ?>"
|
||||
aria-pressed="<?= $isActive ? 'true' : 'false' ?>"
|
||||
<?= $isFaded ? 'disabled' : "hx-get=\"" . htmlspecialchars($url) . "\" $hx" ?>>
|
||||
hx-get="<?= htmlspecialchars($url) ?>" <?= $hx ?>>
|
||||
<?= htmlspecialchars($dim === 'ap' ? formatApDisplay($val) : $val) ?>
|
||||
</button>
|
||||
</li>
|
||||
@@ -87,10 +83,6 @@ function repFilterEntry(
|
||||
// ── Column definitions ──────────────────────────────────────────────────────
|
||||
$hx = 'hx-target="#repertoire-index" hx-swap="outerHTML" hx-push-url="true" hx-indicator="#rep-indicator"';
|
||||
|
||||
$anyActive = !empty($activeSets['years']) || !empty($activeSets['ap'])
|
||||
|| !empty($activeSets['or']) || !empty($activeSets['fi'])
|
||||
|| !empty($activeSets['kw']);
|
||||
|
||||
$filterColumns = [
|
||||
['dataKey' => 'years', 'dim' => 'years', 'heading' => 'Années'],
|
||||
['dataKey' => 'ap_programs', 'dim' => 'ap', 'heading' => 'Ateliers Pluridisciplinaires'],
|
||||
@@ -99,29 +91,10 @@ $filterColumns = [
|
||||
['dataKey' => 'keywords', 'dim' => 'kw', 'heading' => 'Mots-clés'],
|
||||
];
|
||||
|
||||
$colHasMatches = [];
|
||||
foreach ($filterColumns as $col) {
|
||||
$colHasMatches[$col['dim']] = !empty(array_filter(
|
||||
$repData[$col['dataKey']],
|
||||
fn($i) => $i['matched']
|
||||
));
|
||||
}
|
||||
|
||||
?>
|
||||
<div id="repertoire-index" class="repertoire-index">
|
||||
|
||||
<?php
|
||||
// Sort filter columns: matched first (alpha), then unmatched (alpha) — keeps
|
||||
// viable entries at the top so users don't have to scroll past faded ones.
|
||||
$sortMatchedFirst = fn($a, $b) =>
|
||||
($b['matched'] <=> $a['matched']) ?: strcasecmp($a['value'], $b['value']);
|
||||
usort($repData['years'], fn($a, $b) =>
|
||||
($b['matched'] <=> $a['matched']) ?: ($b['value'] <=> $a['value']));
|
||||
usort($repData['ap_programs'], $sortMatchedFirst);
|
||||
usort($repData['orientations'], $sortMatchedFirst);
|
||||
usort($repData['finality_types'], $sortMatchedFirst);
|
||||
usort($repData['keywords'], $sortMatchedFirst);
|
||||
|
||||
// Render filter columns in the correct left-to-right order.
|
||||
// Students column (non-filter) is inserted between keywords and AP/or/fi/years.
|
||||
$renderOrder = ['years', 'ap', 'or', 'fi', 'students', 'kw'];
|
||||
@@ -184,7 +157,7 @@ foreach ($renderOrder as $colKey):
|
||||
<div class="rep-accordion__panel">
|
||||
<ul>
|
||||
<?php foreach ($repData[$col['dataKey']] as $item):
|
||||
repFilterEntry($item, $col['dim'], $activeSets, $anyActive, $colHasMatches[$col['dim']], $hx);
|
||||
repFilterEntry($item, $col['dim'], $activeSets, $hx);
|
||||
endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user