feat : tri par titre et date dans /admin/articles (v1.6.9)

En-têtes "Titre" et "Date" cliquables, indicateur ↑/↓, paramètres sort/dir
préservés lors du filtrage. Tri appliqué après filtres côté PHP.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-15 21:14:22 +02:00
parent fa00f61ee0
commit 04a7713286
4 changed files with 59 additions and 5 deletions
+34 -2
View File
@@ -205,8 +205,30 @@ function adminStatusBadge(array $a, int $now): string
<!-- ─────────────────────────── ARTICLES ─────────────────────────── -->
<?php elseif ($tab === 'articles'): ?>
<?php
$_sortBy = $adminData['sort_by'] ?? 'updated';
$_sortDir = $adminData['sort_dir'] ?? 'desc';
$_mkSortUrl = function (string $col) use ($_sortBy, $_sortDir, $adminData): string {
$dir = ($_sortBy === $col && $_sortDir === 'asc') ? 'desc' : 'asc';
$p = array_filter([
'filter_author' => $adminData['filter_author'] ?? '',
'filter_category' => $adminData['filter_category'] ?? '',
'filter_status' => $adminData['filter_status'] ?? '',
], fn ($v) => $v !== '');
$p['sort'] = $col;
$p['dir'] = $dir;
return '/admin/articles?' . http_build_query($p);
};
$_sortIcon = function (string $col) use ($_sortBy, $_sortDir): string {
if ($_sortBy !== $col) { return '<span class="text-muted ms-1" style="font-size:.75em">↕</span>'; }
return '<span class="ms-1" style="font-size:.75em">' . ($_sortDir === 'asc' ? '↑' : '↓') . '</span>';
};
?>
<!-- Filtres -->
<form class="row g-2 align-items-center mb-3" method="get" action="/admin/articles">
<input type="hidden" name="sort" value="<?= htmlspecialchars($_sortBy) ?>">
<input type="hidden" name="dir" value="<?= htmlspecialchars($_sortDir) ?>">
<?php if (isAdmin() && !empty($adminData['filter_authors'])): ?>
<div class="col-auto">
<select name="filter_author" class="form-select form-select-sm">
@@ -273,11 +295,21 @@ function adminStatusBadge(array $a, int $now): string
<thead>
<tr>
<th style="width:2rem"></th>
<th>Titre</th>
<th>
<a href="<?= htmlspecialchars($_mkSortUrl('title')) ?>"
class="text-decoration-none text-reset">
Titre<?= $_sortIcon('title') ?>
</a>
</th>
<?php if (isAdmin()): ?><th>Auteur</th><?php endif; ?>
<th>Catégorie</th>
<th>Statut</th>
<th>Date</th>
<th>
<a href="<?= htmlspecialchars($_mkSortUrl('published')) ?>"
class="text-decoration-none text-reset">
Date<?= $_sortIcon('published') ?>
</a>
</th>
<th></th>
</tr>
</thead>