109 lines
3.9 KiB
Twig
109 lines
3.9 KiB
Twig
{% extends "layout.twig" %}
|
||
|
||
{% block title %}Tableau de bord – Articles{% endblock %}
|
||
|
||
{% block content %}
|
||
<h2>Gestion des articles</h2>
|
||
|
||
{% include 'partials/_admin_nav.twig' %}
|
||
|
||
<p>
|
||
<a href="/admin/posts/edit/0" class="btn btn--primary">+ Ajouter un article</a>
|
||
</p>
|
||
|
||
<form method="get" action="/admin/posts" class="search-bar">
|
||
{% if activeCategory %}
|
||
<input type="hidden" name="categorie" value="{{ activeCategory.slug }}">
|
||
{% endif %}
|
||
<input type="search" name="q" value="{{ searchQuery }}"
|
||
placeholder="Rechercher un article…" class="search-bar__input" aria-label="Recherche">
|
||
<button type="submit" class="search-bar__btn">Rechercher</button>
|
||
{% if searchQuery %}
|
||
<a href="/admin/posts{% if activeCategory %}?categorie={{ activeCategory.slug }}{% endif %}" class="search-bar__reset">✕</a>
|
||
{% endif %}
|
||
</form>
|
||
|
||
{% if searchQuery %}
|
||
<p class="search-bar__info">
|
||
{% if totalPosts > 0 %}
|
||
{{ totalPosts }} résultat{{ totalPosts > 1 ? 's' : '' }} pour « {{ searchQuery }} »
|
||
{% else %}
|
||
Aucun résultat pour « {{ searchQuery }} »
|
||
{% endif %}
|
||
</p>
|
||
{% endif %}
|
||
|
||
{% if categories is not empty %}
|
||
<nav class="category-filter">
|
||
<a href="/admin/posts"
|
||
class="category-filter__item{% if activeCategory is null %} category-filter__item--active{% endif %}">
|
||
Tous
|
||
</a>
|
||
{% for category in categories %}
|
||
<a href="/admin/posts?categorie={{ category.slug }}"
|
||
class="category-filter__item{% if activeCategory and activeCategory.id == category.id %} category-filter__item--active{% endif %}">
|
||
{{ category.name }}
|
||
</a>
|
||
{% endfor %}
|
||
</nav>
|
||
{% endif %}
|
||
|
||
{% if error %}
|
||
<div class="alert alert--danger">{{ error }}</div>
|
||
{% endif %}
|
||
|
||
{% if success %}
|
||
<div class="alert alert--success">{{ success }}</div>
|
||
{% endif %}
|
||
|
||
{% if posts is not empty %}
|
||
<table class="admin-table">
|
||
<thead>
|
||
<tr>
|
||
<th>Titre</th>
|
||
<th>Catégorie</th>
|
||
<th>Auteur</th>
|
||
<th>Créé le</th>
|
||
<th>Modifié le</th>
|
||
<th>Actions</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{% for post in posts %}
|
||
<tr>
|
||
<td data-label="Titre"><strong>{{ post.title }}</strong></td>
|
||
<td data-label="Catégorie">
|
||
{% if post.categoryName %}
|
||
<a href="/admin/posts?categorie={{ post.categorySlug }}" class="badge badge--category">{{ post.categoryName }}</a>
|
||
{% else %}
|
||
<span class="admin-table__muted">—</span>
|
||
{% endif %}
|
||
</td>
|
||
<td data-label="Auteur">{{ post.authorUsername ?? 'inconnu' }}</td>
|
||
<td data-label="Créé le">{{ post.createdAt|date("d/m/Y H:i") }}</td>
|
||
<td data-label="Modifié le">{{ post.updatedAt|date("d/m/Y H:i") }}</td>
|
||
<td data-label="Actions">
|
||
<div class="u-inline-actions">
|
||
<a href="/admin/posts/edit/{{ post.id }}" class="btn btn--sm btn--secondary">Éditer</a>
|
||
|
||
<form method="post" action="/admin/posts/delete/{{ post.id }}" class="u-inline-form">
|
||
<input type="hidden" name="{{ csrf.keys.name }}" value="{{ csrf.name }}">
|
||
<input type="hidden" name="{{ csrf.keys.value }}" value="{{ csrf.value }}">
|
||
<button type="submit" class="btn btn--sm btn--danger"
|
||
onclick="return confirm('Supprimer cet article ?')">
|
||
Supprimer
|
||
</button>
|
||
</form>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
{% endfor %}
|
||
</tbody>
|
||
</table>
|
||
|
||
{% include 'partials/_pagination.twig' with { pagination: pagination } %}
|
||
{% else %}
|
||
<p><em>{% if searchQuery %}Aucun résultat pour « {{ searchQuery }} ».{% else %}Aucun article à gérer.{% endif %}</em></p>
|
||
{% endif %}
|
||
{% endblock %}
|