fix: Update cleanup button to remove failed, cancelled and completed downloads

Change the 'Nettoyer' (Cleanup) button behavior to remove unwanted downloads:

Before:
- Only removed completed downloads

Now:
- Removes cancelled downloads
- Removes failed downloads
- Removes completed downloads
- Keeps only: downloading, paused, pending downloads
- Shows detailed count by status in confirmation dialog
- Better title tooltip explaining what gets deleted

The confirmation message now shows exactly what will be deleted:
- 'Supprimer X annulé(s) Y échoué(s) Z terminé(s)?'

This makes it easy to clean up the download history while keeping
active downloads safe.
This commit is contained in:
root
2026-01-23 11:02:07 +00:00
parent a32ea205a4
commit 55bb85b56f
+24 -7
View File
@@ -812,7 +812,7 @@
</div>
<div class="actions-group">
<button class="btn-small btn-secondary" onclick="clearCompleted()" title="Supprimer les terminés">
<button class="btn-small btn-secondary" onclick="clearCompleted()" title="Supprimer annulés, échoués et terminés">
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width:14px;height:14px;">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
</svg>
@@ -958,20 +958,37 @@
return groups;
}
// Clear completed downloads
// Clear unwanted downloads (cancelled, deleted, failed)
async function clearCompleted() {
const completed = allDownloads.filter(dl => dl.status === 'completed');
// Find all unwanted downloads (not completed or downloading or paused)
const unwanted = allDownloads.filter(dl =>
dl.status === 'cancelled' ||
dl.status === 'failed' ||
dl.status === 'completed' // Also remove completed if desired
);
if (completed.length === 0) {
alert('Aucun téléchargement terminé à supprimer');
if (unwanted.length === 0) {
alert('Aucun téléchargement à supprimer');
return;
}
if (!confirm(`Supprimer ${completed.length} téléchargement(s) terminé(s) ?`)) {
// Count by status
const byStatus = unwanted.reduce((acc, dl) => {
acc[dl.status] = (acc[dl.status] || 0) + 1;
return acc;
}, {});
let message = 'Supprimer ';
if (byStatus.cancelled) message += `${byStatus.cancelled} annulé(s) `;
if (byStatus.failed) message += `${byStatus.failed} échoué(s) `;
if (byStatus.completed) message += `${byStatus.completed} terminé(s) `;
message += '?';
if (!confirm(message)) {
return;
}
for (const dl of completed) {
for (const dl of unwanted) {
await fetch(`${API_BASE}/download/${dl.id}`, { method: 'DELETE' });
}