Avoid failing when there are no backups

This commit is contained in:
Giuseppe Criscione 2024-04-27 12:45:38 +02:00
parent 4b7162040b
commit 0245e8ae0e
9 changed files with 37 additions and 28 deletions

View File

@ -3,6 +3,7 @@
namespace Formwork\Panel\Controllers;
use Formwork\Backupper;
use Formwork\Data\Collection;
use Formwork\Http\Response;
use Formwork\Router\RouteParams;
use Formwork\Utils\Arr;
@ -50,7 +51,7 @@ class ToolsController extends AbstractController
'tabs' => $this->tabs,
'current' => 'backups',
]),
'backups' => array_values($backups),
'backups' => Collection::from($backups),
]));
}

View File

@ -9,6 +9,7 @@ date.duration.weeks: ['Woche', 'Wochen']
date.duration.years: ['Jahr', 'Jahre']
date.months.long: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']
date.months.short: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez']
date.never: nie
date.now: jetzt
date.today: Heute
date.weekdays.long: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag']

View File

@ -9,6 +9,7 @@ date.duration.weeks: ['week', 'weeks']
date.duration.years: ['year', 'years']
date.months.long: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
date.months.short: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
date.never: never
date.now: now
date.today: Today
date.weekdays.long: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']

View File

@ -9,6 +9,7 @@ date.duration.weeks: ['semana', 'semanas']
date.duration.years: ['año', 'años']
date.months.long: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']
date.months.short: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic']
date.never: nunca
date.now: ahora
date.today: Hoy
date.weekdays.long: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado']

View File

@ -9,6 +9,7 @@ date.duration.weeks: ['semaine', 'semaines']
date.duration.years: ['an', 'ans']
date.months.long: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre']
date.months.short: ['Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Jun', 'Juil', 'Aou', 'Sep', 'Oct', 'Nov', 'Déc']
date.never: jamais
date.now: maintenant
date.today: Aujourdhui
date.weekdays.long: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi']

View File

@ -9,6 +9,7 @@ date.duration.weeks: ['settimana', 'settimane']
date.duration.years: ['anno', 'anni']
date.months.long: ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre']
date.months.short: ['Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic']
date.never: mai
date.now: adesso
date.today: Oggi
date.weekdays.long: ['Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato']

View File

@ -9,6 +9,7 @@ date.duration.weeks: ['semana', 'semanas']
date.duration.years: ['ano', 'anos']
date.months.long: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro']
date.months.short: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez']
date.never: nunca
date.now: agora
date.today: Hoje
date.weekdays.long: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado']

View File

@ -9,6 +9,7 @@ date.duration.weeks: ['неделя', 'нед']
date.duration.years: ['год', 'г']
date.months.long: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октября', 'Ноябрь', 'Декабрь']
date.months.short: ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек']
date.never: никогда
date.now: теперь
date.today: Сегодня
date.weekdays.long: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота']

View File

@ -8,36 +8,37 @@
<div data-view="backups">
<section class="section">
<button type="button" class="button button-secondary mr-6" data-command="make-backup"><?= $this->icon('clock-rotate-left') ?> <?= $this->translate('panel.backup.backup') ?></button>
<p class="mt-4 mb-0"><?= $this->translate('panel.tools.latestBackup') ?> <span class="text-bold backup-last-time"><?= $this->timedistance($backups[0]['timestamp']) ?></span></p>
<p class="mt-4 mb-0"><?= $this->translate('panel.tools.latestBackup') ?> <span class="text-bold backup-last-time"><?= $backups->isEmpty() ? $this->translate('date.never') : $this->timedistance($backups->first()['timestamp']) ?></span></p>
</section>
<section class="section">
<div class="section-header">
<div class="caption"><?= $this->translate('panel.tools.latestBackups') ?></div>
</div>
<table id="backups-table" class="table table-bordered table-hoverable text-size-sm">
<thead>
<tr>
<th class="table-header truncate" style="width: 100%"><?= $this->translate('panel.tools.backup.file') ?></th>
<th class="table-header truncate text-align-center show-from-md" style="width: 25%"><?= $this->translate('panel.tools.backup.date') ?></th>
<th class="table-header truncate text-align-center show-from-sm" style="width: 15%"><?= $this->translate('panel.tools.backup.size') ?></th>
<th class="table-header text-align-center" style="width: 15%"><?= $this->translate('panel.tools.backup.actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($backups as $backup) : ?>
<?php if (!$backups->isEmpty()) : ?>
<section class="section">
<div class="section-header">
<div class="caption"><?= $this->translate('panel.tools.latestBackups') ?></div>
</div>
<table id="backups-table" class="table table-bordered table-hoverable text-size-sm">
<thead>
<tr>
<td class="table-cell truncate"><?= $this->icon('file-archive') ?> <a href="<?= $panel->uri('/backup/download/' . $backup['encodedName']) . '/' ?>"><?= $backup['name'] ?></a></td>
<td class="table-cell truncate text-align-center show-from-md"><?= $this->datetime($backup['timestamp']) ?></td>
<td class="table-cell truncate text-align-center show-from-sm"><?= $backup['size'] ?></td>
<td class="table-cell text-align-center">
<button type="button" class="button button-link" data-modal="deleteFileModal" data-modal-action="<?= $panel->uri('/backup/delete/' . $backup['encodedName']) . '/' ?>" title="<?= $this->translate('panel.tools.backup.delete') ?>" aria-label="<?= $this->translate('panel.tools.backup.delete') ?>"><?= $this->icon('trash') ?></button>
</td>
<th class="table-header truncate" style="width: 100%"><?= $this->translate('panel.tools.backup.file') ?></th>
<th class="table-header truncate text-align-center show-from-md" style="width: 25%"><?= $this->translate('panel.tools.backup.date') ?></th>
<th class="table-header truncate text-align-center show-from-sm" style="width: 15%"><?= $this->translate('panel.tools.backup.size') ?></th>
<th class="table-header text-align-center" style="width: 15%"><?= $this->translate('panel.tools.backup.actions') ?></th>
</tr>
<?php endforeach ?>
</tbody>
</table>
</section>
</thead>
<tbody>
<?php foreach ($backups as $backup) : ?>
<tr>
<td class="table-cell truncate"><?= $this->icon('file-archive') ?> <a href="<?= $panel->uri('/backup/download/' . $backup['encodedName']) . '/' ?>"><?= $backup['name'] ?></a></td>
<td class="table-cell truncate text-align-center show-from-md"><?= $this->datetime($backup['timestamp']) ?></td>
<td class="table-cell truncate text-align-center show-from-sm"><?= $backup['size'] ?></td>
<td class="table-cell text-align-center">
<button type="button" class="button button-link" data-modal="deleteFileModal" data-modal-action="<?= $panel->uri('/backup/delete/' . $backup['encodedName']) . '/' ?>" title="<?= $this->translate('panel.tools.backup.delete') ?>" aria-label="<?= $this->translate('panel.tools.backup.delete') ?>"><?= $this->icon('trash') ?></button>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
</section>
<?php endif ?>
</div>
<template id="backups-row">