refactor: unify FilePond edit previews + clean upload UI and shared fragments

* Move shared `fichiers-fragment.php` from `partage/` to `templates/partials/form/`
  and update all include/require references
* `.gitignore`: exclude SQLite WAL/SHM journal files
* FilePond UI:

  * change uploaded file block border state from yellow to green
  * restyle image previews to use site light-theme colors
* Edit mode:

  * remove custom existing-file preview list implementation
  * preload existing files directly into FilePond pools
  * include `cover` and `note_intention` assets in FilePond-managed state
* Remove obsolete upload progress bar UI and related JS includes
* Remove deprecated `Écriture` + `Image` format types from upload flow/configuration
This commit is contained in:
Pontoporeia
2026-05-12 12:27:36 +02:00
parent 6e7c0c00e3
commit 8bb0b3a1f2
58 changed files with 1807 additions and 307 deletions

View File

@@ -143,8 +143,7 @@ $checkedFormatsForSiteWeb = $checkedFormatsForSiteWeb ?? [];
<?php endif; ?>
<?php endif; ?>
<form action="<?= $formAction ?>" method="post" enctype="multipart/form-data" class="admin-form" data-beforeunload-guard data-upload-progress>
<input type="hidden" name="progress_token" value="<?= bin2hex(random_bytes(8)) ?>">
<form action="<?= $formAction ?>" method="post" enctype="multipart/form-data" class="admin-form" data-beforeunload-guard>
<input type="hidden" name="filepond_mode" value="1">
<?= $hiddenFields ?>
@@ -308,16 +307,21 @@ $checkedFormatsForSiteWeb = $checkedFormatsForSiteWeb ?? [];
<!-- ═══════════════════ Format(s) + Fichiers ═══════════════════ -->
<?php
// Helper: build existing-files JSON for FilePond TFE pool (including PeerTube)
$_buildExistingFilesJson = function (array $files): array {
// Helper: build existing-files JSON for a specific FilePond queue type.
$_buildQueueFilesJson = function (array $files, string $queueType): array {
$result = [];
foreach ($files as $f) {
$ft = $f['file_type'] ?? '';
$fp = $f['file_path'] ?? '';
// Skip cover (handled separately) and website URLs (no actual file)
if ($ft === 'cover' || str_starts_with($fp, 'http://') || str_starts_with($fp, 'https://')) {
// Skip website URLs (no actual file)
if (str_starts_with($fp, 'http://') || str_starts_with($fp, 'https://')) {
continue;
}
// Only include files matching the requested queue type
if ($queueType === 'cover' && $ft !== 'cover') continue;
if ($queueType === 'note_intention' && $ft !== 'note_intention') continue;
if ($queueType === 'tfe' && ($ft === 'cover' || $ft === 'note_intention' || $ft === 'annex')) continue;
if ($queueType === 'annexe' && $ft !== 'annex') continue;
// Include PeerTube files too — load.php now handles them
$result[] = [
'source' => (string)((int)$f['id']),
@@ -343,9 +347,12 @@ if ($filesMode === 'add'): ?>
$_POST['admin_mode'] = $adminMode ? '1' : '0';
$_POST['has_annexes'] = $formData['has_annexes'] ?? null;
$existingFilesJsonForTfe = $_buildExistingFilesJson($currentFiles ?? []);
$existingFilesJsonForCover = [];
$existingFilesJsonForNoteIntention = [];
$existingFilesJsonForTfe = [];
$existingFilesJsonForAnnexe = [];
include APP_ROOT . '/public/partage/fichiers-fragment.php';
include APP_ROOT . '/templates/partials/form/fichiers-fragment.php';
$_POST = $_savedPost;
unset($_savedPost);
?>
@@ -359,13 +366,15 @@ if ($filesMode === 'add'): ?>
$_POST['website_label'] = $existingWebsiteLabel;
$_POST['admin_mode'] = $adminMode ? '1' : '0';
$_POST['edit_mode'] = '1';
$_POST['_cover'] = $currentCover['file_path'] ?? null;
$_POST['has_annexes'] = $formData['has_annexes'] ?? null;
// Build existing-files JSON for FilePond edit mode (all files including PeerTube)
$existingFilesJsonForTfe = $_buildExistingFilesJson($currentFiles ?? []);
// Build per-queue-type existing-files JSON for FilePond edit mode
$existingFilesJsonForCover = $_buildQueueFilesJson($currentFiles ?? [], 'cover');
$existingFilesJsonForNoteIntention = $_buildQueueFilesJson($currentFiles ?? [], 'note_intention');
$existingFilesJsonForTfe = $_buildQueueFilesJson($currentFiles ?? [], 'tfe');
$existingFilesJsonForAnnexe = $_buildQueueFilesJson($currentFiles ?? [], 'annexe');
include APP_ROOT . '/public/partage/fichiers-fragment.php';
include APP_ROOT . '/templates/partials/form/fichiers-fragment.php';
$_POST = $_savedPost;
unset($_savedPost);
?>
@@ -512,12 +521,6 @@ if ($filesMode === 'add'): ?>
<?php endif; ?>
<div class="form-footer admin-form-footer">
<fieldset id="upload-progress-wrap" style="display:none;">
<legend><span id="upload-progress-label">Téléversement en cours…</span></legend>
<progress id="upload-progress-bar" value="0" max="100"></progress>
<p id="upload-progress-file" style="font-size:var(--step--1);color:var(--text-secondary);margin:var(--space-2xs) 0 0 0;"></p>
<small style="display:block;color:var(--text-tertiary);margin-top:var(--space-2xs);">Cette opération peut prendre plusieurs minutes selon la taille des fichiers. Ne fermez pas la page.</small>
</fieldset>
<button type="submit" name="go" class="btn btn--primary"><?= $mode === 'edit' ? 'Enregistrer' : 'Soumettre' ?></button>
<?php if ($mode === 'add' || $mode === 'edit'): ?>
<a href="/admin/" class="btn btn--secondary">Annuler</a>