mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-08-10 23:31:21 +02:00
Switch from swapping the entire #repertoire-index block to targeted hx-swap-oob swaps: only the <ul> list elements are replaced, while section headers and accordion chrome stay in the DOM untouched. - Filter column <ul>s get IDs (rep-list-years, rep-list-ap, etc.) and render with hx-swap-oob=true on HTMX requests - Students <ul> gets id=rep-students as main swap target - Filter buttons now target #rep-students instead of #repertoire-index - Server sets $isOob=true when rendering HTMX partial responses - Accordion re-init on swap no longer needed (headers never replaced) - Scroll-restore updated to capture/restore per <ul> ID Fading fixes: - Restore rep-entry--faded class with simplified logic: any active filter fades entries whose matched flag is false (removed the $colHasMatch gate that prevented fading when a column had no matches) - Add $noResults guard: when matched_ids is empty (zero theses match all active filters), force-fade all non-selected entries across ALL columns. This covers the keyword edge case where per-column matched is computed excluding the keyword filter (many-to-many), causing keywords to appear valid even though the full intersection is empty.
219 lines
8.7 KiB
PHP
219 lines
8.7 KiB
PHP
<?php
|
|
/**
|
|
* Partial: répertoire index columns.
|
|
* Rendered both on full page load and as HTMX partial swap.
|
|
*
|
|
* When $isOob is true, renders only <ul> elements with hx-swap-oob attributes
|
|
* for the filter columns, and the students <ul> as the main swap target.
|
|
*
|
|
* Expected variables:
|
|
* $repData array output of Database::getRepertoireFilterData()
|
|
* $activeFilters array{years:int[], ap:string[], or:string[], fi:string[], kw:string[]}
|
|
* $isOob bool (optional) render OOB-only response for HTMX swaps
|
|
*/
|
|
|
|
$isOob = $isOob ?? false;
|
|
|
|
$activeSets = [
|
|
'years' => array_map('strval', $activeFilters['years'] ?? []),
|
|
'ap' => $activeFilters['ap'] ?? [],
|
|
'or' => $activeFilters['or'] ?? [],
|
|
'fi' => $activeFilters['fi'] ?? [],
|
|
'kw' => $activeFilters['kw'] ?? [],
|
|
];
|
|
|
|
// ── Students ────────────────────────────────────────────────────────────────
|
|
$studentWorks = [];
|
|
foreach ($repData['students'] as $s) {
|
|
if (empty($s['authors'])) continue;
|
|
foreach (explode(',', $s['authors']) as $name) {
|
|
$name = trim($name);
|
|
if ($name === '') continue;
|
|
$studentWorks[$name][] = (int)$s['id'];
|
|
}
|
|
}
|
|
ksort($studentWorks);
|
|
|
|
// ── Shared helpers ──────────────────────────────────────────────────────────
|
|
|
|
// AP abbreviation mapping (cf. maquette: diminutifs entre crochets)
|
|
const AP_ABBREVIATIONS = [
|
|
'Atelier Pratiques Situées' => '[APS]',
|
|
'Design et Politique du Multiple' => '[DPM]',
|
|
'Lieux, Interdisciplinarités, Écologie, Nécessité, Systèmes' => '[L.I.E.N.S.]',
|
|
];
|
|
|
|
function formatApDisplay(string $name): string {
|
|
$abbr = AP_ABBREVIATIONS[$name] ?? '';
|
|
return $abbr !== '' ? "$name $abbr" : $name;
|
|
}
|
|
|
|
function repToggleUrl(array $sets, string $dim, string $value): string {
|
|
if (in_array($value, $sets[$dim], true)) {
|
|
$sets[$dim] = array_values(array_filter($sets[$dim], fn($v) => $v !== $value));
|
|
} else {
|
|
$sets[$dim][] = $value;
|
|
}
|
|
$params = [];
|
|
foreach ($sets['years'] as $v) $params[] = 'fy[]=' . urlencode((string)$v);
|
|
foreach ($sets['ap'] as $v) $params[] = 'ap[]=' . urlencode($v);
|
|
foreach ($sets['or'] as $v) $params[] = 'or[]=' . urlencode($v);
|
|
foreach ($sets['fi'] as $v) $params[] = 'fi[]=' . urlencode($v);
|
|
foreach ($sets['kw'] as $v) $params[] = 'kw[]=' . urlencode($v);
|
|
$qs = implode('&', $params);
|
|
return '/repertoire' . ($qs ? '?' . $qs : '');
|
|
}
|
|
|
|
/**
|
|
* Render a single filter entry <li>.
|
|
*
|
|
* Fading logic: when any filter is active, entries that would yield zero
|
|
* results (matched=false) are faded and disabled. The selected entry itself
|
|
* is never faded.
|
|
*/
|
|
function repFilterEntry(
|
|
array $item,
|
|
string $dim,
|
|
array $activeSets,
|
|
bool $anyActive,
|
|
bool $noResults,
|
|
string $hx,
|
|
): void {
|
|
$val = (string)$item['value'];
|
|
$isActive = in_array($val, $activeSets[$dim], true);
|
|
$isFaded = $anyActive && ($noResults || !$item['matched']) && !$isActive;
|
|
$cls = 'rep-entry'
|
|
. ($isActive ? ' rep-entry--selected' : '')
|
|
. ($isFaded ? ' rep-entry--faded' : '');
|
|
$url = repToggleUrl($activeSets, $dim, $val);
|
|
?>
|
|
<li>
|
|
<button type="button" class="<?= $cls ?>"
|
|
aria-pressed="<?= $isActive ? 'true' : 'false' ?>"
|
|
<?= $isFaded ? 'disabled' : "hx-get=\"" . htmlspecialchars($url) . "\" $hx" ?>>
|
|
<?= htmlspecialchars($dim === 'ap' ? formatApDisplay($val) : $val) ?>
|
|
</button>
|
|
</li>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* Render the students <ul> (no section chrome).
|
|
*/
|
|
function renderStudentsList(array $studentWorks): void {
|
|
?>
|
|
<ul id="rep-students">
|
|
<?php if (empty($studentWorks)): ?>
|
|
<li class="rep-empty">—</li>
|
|
<?php else: ?>
|
|
<?php foreach ($studentWorks as $name => $ids): ?>
|
|
<?php
|
|
$firstId = $ids[0];
|
|
$targetUrl = count($ids) === 1 ? '/tfe?id=' . $firstId : '#';
|
|
$previewUrl = '/repertoire/student-preview?name=' . urlencode($name);
|
|
?>
|
|
<li class="student-entry">
|
|
<a href="<?= htmlspecialchars($targetUrl) ?>"
|
|
class="rep-entry rep-entry--link"
|
|
data-student-name="<?= htmlspecialchars($name) ?>"
|
|
hx-get="<?= htmlspecialchars($previewUrl) ?>"
|
|
hx-target="#student-popover"
|
|
hx-trigger="mouseenter"
|
|
hx-swap="innerHTML">
|
|
<?= htmlspecialchars($name) ?>
|
|
</a>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</ul>
|
|
<?php
|
|
}
|
|
|
|
// ── Column definitions ──────────────────────────────────────────────────────
|
|
$hx = 'hx-target="#rep-students" 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']);
|
|
|
|
$noResults = $anyActive && empty($repData['matched_ids']);
|
|
|
|
$filterColumns = [
|
|
['dataKey' => 'years', 'dim' => 'years', 'heading' => 'Années'],
|
|
['dataKey' => 'ap_programs', 'dim' => 'ap', 'heading' => 'Ateliers Pluridisciplinaires'],
|
|
['dataKey' => 'orientations', 'dim' => 'or', 'heading' => 'Orientations'],
|
|
['dataKey' => 'finality_types', 'dim' => 'fi', 'heading' => 'Finalité du Master'],
|
|
['dataKey' => 'keywords', 'dim' => 'kw', 'heading' => 'Mots-clés'],
|
|
];
|
|
|
|
// Render order: students column is inserted between fi and kw
|
|
$renderOrder = ['years', 'ap', 'or', 'fi', 'students', 'kw'];
|
|
|
|
// ── OOB response: only <ul> elements, no section chrome ─────────────────────
|
|
if ($isOob):
|
|
foreach ($renderOrder as $colKey):
|
|
if ($colKey === 'students'):
|
|
renderStudentsList($studentWorks);
|
|
else:
|
|
$col = array_values(array_filter($filterColumns, fn($c) => $c['dim'] === $colKey))[0];
|
|
$listId = 'rep-list-' . $colKey;
|
|
?>
|
|
<ul id="<?= $listId ?>" hx-swap-oob="true">
|
|
<?php foreach ($repData[$col['dataKey']] as $item):
|
|
repFilterEntry($item, $col['dim'], $activeSets, $anyActive, $noResults, $hx);
|
|
endforeach; ?>
|
|
</ul>
|
|
<?php endif;
|
|
endforeach;
|
|
return; // renderRepertoirePartial will exit() after include
|
|
endif;
|
|
|
|
// ── Full page load ──────────────────────────────────────────────────────────
|
|
?>
|
|
<div id="repertoire-index" class="repertoire-index">
|
|
|
|
<?php
|
|
foreach ($renderOrder as $colKey):
|
|
if ($colKey === 'students'): ?>
|
|
<!-- ÉTUDIANTES -->
|
|
<section class="repertoire-col rep-accordion" data-col="students">
|
|
<h2>
|
|
<span class="rep-accordion__heading-text">Étudiant·es</span>
|
|
<button type="button" class="rep-accordion__toggle" aria-expanded="false">
|
|
Étudiant·es
|
|
<span class="rep-accordion__chevron" aria-hidden="true"></span>
|
|
</button>
|
|
</h2>
|
|
<div class="rep-accordion__panel">
|
|
<?php renderStudentsList($studentWorks); ?>
|
|
</div>
|
|
</section>
|
|
<?php else:
|
|
$col = array_values(array_filter($filterColumns, fn($c) => $c['dim'] === $colKey))[0];
|
|
$activeCount = count($activeSets[$col['dim']]);
|
|
$listId = 'rep-list-' . $colKey;
|
|
?>
|
|
<section class="repertoire-col rep-accordion" data-col="<?= $col['dim'] ?>">
|
|
<h2>
|
|
<span class="rep-accordion__heading-text"><?= $col['heading'] ?></span>
|
|
<button type="button" class="rep-accordion__toggle" aria-expanded="false">
|
|
<?= $col['heading'] ?>
|
|
<?php if ($activeCount > 0): ?>
|
|
<span class="rep-accordion__badge"><?= $activeCount ?></span>
|
|
<?php endif; ?>
|
|
<span class="rep-accordion__chevron" aria-hidden="true"></span>
|
|
</button>
|
|
</h2>
|
|
<div class="rep-accordion__panel">
|
|
<ul id="<?= $listId ?>">
|
|
<?php foreach ($repData[$col['dataKey']] as $item):
|
|
repFilterEntry($item, $col['dim'], $activeSets, $anyActive, $noResults, $hx);
|
|
endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
</section>
|
|
<?php endif;
|
|
endforeach; ?>
|
|
|
|
</div>
|