mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-09-25 01:53:03 +02:00
feat: allow exporting an empty CSV template for imports
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -44,3 +44,6 @@
|
||||
- [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: 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,6 +20,7 @@ require_once APP_ROOT . '/src/ErrorHandler.php';
|
||||
$doCsv = !empty($_GET['csv']);
|
||||
$doFiles = !empty($_GET['files']);
|
||||
$doDb = !empty($_GET['db']);
|
||||
$doTemplate = !empty($_GET['template']);
|
||||
|
||||
// Optional: filter by selected thesis IDs (bulk selection export)
|
||||
$idsRaw = $_GET['ids'] ?? '';
|
||||
@@ -33,12 +34,30 @@ if ($idsRaw !== '') {
|
||||
}
|
||||
}
|
||||
|
||||
if (!$doCsv && !$doFiles && !$doDb) {
|
||||
if (!$doCsv && !$doFiles && !$doDb && !$doTemplate) {
|
||||
$doCsv = true;
|
||||
}
|
||||
|
||||
$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) {
|
||||
AdminLogger::make()->logCsvExport();
|
||||
|
||||
|
||||
@@ -581,8 +581,8 @@ if ($isHtmx) {
|
||||
include APP_ROOT . '/templates/admin/index-table.php';
|
||||
}
|
||||
} else {
|
||||
$extraCssAdmin = [];
|
||||
$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'];
|
||||
$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', '/assets/js/app/file-upload-filepond.js'];
|
||||
require_once APP_ROOT . '/templates/head.php';
|
||||
include APP_ROOT . '/templates/header.php';
|
||||
if ($tab === 'trash') {
|
||||
|
||||
@@ -757,6 +757,15 @@ th.admin-ap-col {
|
||||
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" */
|
||||
.admin-error-list {
|
||||
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']) ?>">
|
||||
|
||||
<div>
|
||||
<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">
|
||||
⤓ Télécharger un modèle CSV vide
|
||||
</a>
|
||||
</div>
|
||||
<div class="admin-file-input">
|
||||
<input type="file" id="csv_file"
|
||||
name="csv_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
|
||||
> `/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
|
||||
|
||||
Reference in New Issue
Block a user