feat: allow exporting an empty CSV template for imports

This commit is contained in:
Pontoporeia
2026-08-24 11:33:34 +02:00
parent 7938ab39c0
commit 5460041989
7 changed files with 51 additions and 5 deletions
File diff suppressed because one or more lines are too long
+3
View File
@@ -44,3 +44,6 @@
- [x] PDF viewer: add dark transparent violet background behind pages when expanded - [x] PDF viewer: add dark transparent violet background behind pages when expanded
- [x] pdf-viewer: expand to fill right column (not whole page), center pages, freeze column on expand - [x] pdf-viewer: expand to fill right column (not whole page), center pages, freeze column on expand
- [x] pdf-viewer: fix toolbar width (align-self:stretch), hide sibling file items when expanded - [x] pdf-viewer: fix toolbar width (align-self:stretch), hide sibling file items when expanded
- [x] Allow admin to export an empty CSV template (headers only) from the import dialog for use as an import model
- [x] Fix import modal missing FilePond styling: bundling refactor dropped filepond CSS + file-upload-filepond.js wrapper from admin list page (pre-existing regression)
- [x] Move 'download empty CSV template' button onto the same line as the Fichier CSV heading (button on the right, styled as btn)
+20 -1
View File
@@ -20,6 +20,7 @@ require_once APP_ROOT . '/src/ErrorHandler.php';
$doCsv = !empty($_GET['csv']); $doCsv = !empty($_GET['csv']);
$doFiles = !empty($_GET['files']); $doFiles = !empty($_GET['files']);
$doDb = !empty($_GET['db']); $doDb = !empty($_GET['db']);
$doTemplate = !empty($_GET['template']);
// Optional: filter by selected thesis IDs (bulk selection export) // Optional: filter by selected thesis IDs (bulk selection export)
$idsRaw = $_GET['ids'] ?? ''; $idsRaw = $_GET['ids'] ?? '';
@@ -33,12 +34,30 @@ if ($idsRaw !== '') {
} }
} }
if (!$doCsv && !$doFiles && !$doDb) { if (!$doCsv && !$doFiles && !$doDb && !$doTemplate) {
$doCsv = true; $doCsv = true;
} }
$controller = ExportController::create(); $controller = ExportController::create();
// Empty CSV template: stream only the header row (no data).
if ($doTemplate) {
AdminLogger::make()->logCsvExport();
$filename = 'xamxam-template.csv';
header('Content-Type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: no-cache, must-revalidate');
echo "\xEF\xBB\xBF";
$out = fopen('php://output', 'w');
fputcsv($out, ExportController::CSV_HEADERS, ',', '"', '');
fclose($out);
exit;
}
if ($doCsv) { if ($doCsv) {
AdminLogger::make()->logCsvExport(); AdminLogger::make()->logCsvExport();
+2 -2
View File
@@ -581,8 +581,8 @@ if ($isHtmx) {
include APP_ROOT . '/templates/admin/index-table.php'; include APP_ROOT . '/templates/admin/index-table.php';
} }
} else { } else {
$extraCssAdmin = []; $extraCssAdmin = ['/assets/css/filepond.min.css', '/assets/css/filepond-plugin-image-preview.min.css'];
$extraJs = ['/assets/js/vendor/filepond.min.js', '/assets/js/vendor/filepond-plugin-file-validate-type.min.js', '/assets/js/vendor/filepond-plugin-file-validate-size.min.js', '/assets/js/vendor/filepond-plugin-image-preview.min.js', '/assets/js/vendor/filepond-plugin-image-exif-orientation.min.js', '/assets/dist/admin.min.js']; $extraJs = ['/assets/js/vendor/filepond.min.js', '/assets/js/vendor/filepond-plugin-file-validate-type.min.js', '/assets/js/vendor/filepond-plugin-file-validate-size.min.js', '/assets/js/vendor/filepond-plugin-image-preview.min.js', '/assets/js/vendor/filepond-plugin-image-exif-orientation.min.js', '/assets/dist/admin.min.js', '/assets/js/app/file-upload-filepond.js'];
require_once APP_ROOT . '/templates/head.php'; require_once APP_ROOT . '/templates/head.php';
include APP_ROOT . '/templates/header.php'; include APP_ROOT . '/templates/header.php';
if ($tab === 'trash') { if ($tab === 'trash') {
+9
View File
@@ -757,6 +757,15 @@ th.admin-ap-col {
margin-top: var(--space-2xs); margin-top: var(--space-2xs);
} }
/* Import dialog: Fichier CSV heading + empty-CSV-template button on one line (button on the right) */
.admin-file-label-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--space-s);
margin-bottom: var(--space-2xs);
}
/* Error list inside role="alert" */ /* Error list inside role="alert" */
.admin-error-list { .admin-error-list {
margin: var(--space-2xs) 0 0; margin: var(--space-2xs) 0 0;
@@ -49,7 +49,12 @@ if (!class_exists('ExportController')) {
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>"> <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
<div> <div>
<label for="csv_file">Fichier CSV</label> <div class="admin-file-label-row">
<label for="csv_file">Fichier CSV</label>
<a href="/admin/actions/export.php?template=1" download class="btn btn--secondary btn--sm">
&#x2913; Télécharger un modèle CSV vide
</a>
</div>
<div class="admin-file-input"> <div class="admin-file-input">
<input type="file" id="csv_file" <input type="file" id="csv_file"
name="csv_file" name="csv_file"
+10
View File
@@ -6,6 +6,16 @@ Import of theses from the admin panel, plus the CSV structure and behaviour.
> `app/public/admin/index.php` — there is no separate `import.php` action. The > `app/public/admin/index.php` — there is no separate `import.php` action. The
> `/admin/import.php` file only redirects to `/admin/`. > `/admin/import.php` file only redirects to `/admin/`.
### Import modal
The import dialog (`app/templates/admin/partials/dialogs/import.php`) lets the
user pick a CSV file and submit it. It also exposes an **export empty CSV**
button, labelled **“Télécharger un modèle CSV vide”**, shown beside the “Fichier
CSV” label. It links to `/admin/actions/export.php?template=1` and downloads a
blank CSV whose header row matches the export headers (`ExportController::CSV_HEADERS`,
see below) so you can fill it in and re-import it.
--- ---
## File format ## File format