This commit is contained in:
Bozhidar 2024-05-09 15:14:31 +03:00
parent 538246e795
commit 079f18f728
3 changed files with 41 additions and 2 deletions

View file

@ -7,6 +7,7 @@ use App\Filament\Enums\BackupStatus;
use App\Filament\Enums\HostingSubscriptionBackupType;
use App\Filament\Resources\Blog\PostResource;
use App\Filament\Resources\HostingSubscriptionResource;
use App\Helpers;
use App\Models\Backup;
use App\Models\DatabaseUser;
use App\Models\HostingSubscriptionBackup;
@ -22,6 +23,7 @@ use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\File;
use JaOcero\RadioDeck\Forms\Components\RadioDeck;
class ManageHostingSubscriptionBackups extends ManageRelatedRecords
@ -118,7 +120,7 @@ class ManageHostingSubscriptionBackups extends ManageRelatedRecords
Tables\Columns\TextColumn::make('size')
->state(function (HostingSubscriptionBackup $backup) {
return $backup->size ? $backup->size : 'N/A';
return ($backup->size > 0) ? Helpers::getHumanReadableSize($backup->size) : 'N/A';
}),
])
@ -146,6 +148,18 @@ class ManageHostingSubscriptionBackups extends ManageRelatedRecords
Tables\Actions\Action::make('viewLog')
->label('View Log')
->icon('heroicon-o-document')
->hidden(function (HostingSubscriptionBackup $backup) {
$hide = false;
if ($backup->status === BackupStatus::Completed) {
$hide = true;
}
return $hide;
})
->modalFooterActions([
Tables\Actions\Action::make('Close')
->color('secondary')
->action(fn () => $this->closeTableActionModal()),
])
->modalContent(function (HostingSubscriptionBackup $backup) {
return view('filament.modals.view-livewire-component', [
'component' => 'hosting-subscription-backup-log',

View file

@ -37,4 +37,23 @@ class Helpers
return 0;
}
public static function getHumanReadableSize($size, $unit = null, $decemals = 2) {
$size = intval($size);
$byteUnits = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
if (!is_null($unit) && !in_array($unit, $byteUnits)) {
$unit = null;
}
$extent = 1;
foreach ($byteUnits as $rank) {
if ((is_null($unit) && ($size < $extent <<= 10)) || ($rank == $unit)) {
break;
}
}
return number_format($size / ($extent >> 10), $decemals) . $rank;
}
}

View file

@ -1,7 +1,13 @@
<div>
<div id="js-backup-log" wire:poll="pullBackupLog" class="text-left text-sm font-medium text-gray-950 dark:text-yellow-500 h-[20rem] overflow-y-scroll">
{!! $this->backupLog !!}
@if($this->backupLog == '')
<div class="text-center text-gray-500 dark:text-gray-400">
{{ __('No backup log available.') }}
</div>
@else
{!! $this->backupLog !!}
@endif
</div>