From 3a31104b5c661e3d8cd2d1a88164fad536772831 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 13 May 2022 19:33:14 -0700 Subject: [PATCH] Fixed #11052 - add file sizes to upload displays Signed-off-by: snipe --- app/Helpers/Helper.php | 30 ++++++++ resources/lang/en/general.php | 1 + resources/views/hardware/view.blade.php | 28 ++++---- resources/views/licenses/view.blade.php | 40 ++++++----- resources/views/users/view.blade.php | 95 ++++++++++++++++++------- 5 files changed, 138 insertions(+), 56 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 528e8851e0..b8a34ed8c1 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1059,4 +1059,34 @@ class Helper return $file_name; } + + public static function formatFilesizeUnits($bytes) + { + if ($bytes >= 1073741824) + { + $bytes = number_format($bytes / 1073741824, 2) . ' GB'; + } + elseif ($bytes >= 1048576) + { + $bytes = number_format($bytes / 1048576, 2) . ' MB'; + } + elseif ($bytes >= 1024) + { + $bytes = number_format($bytes / 1024, 2) . ' KB'; + } + elseif ($bytes > 1) + { + $bytes = $bytes . ' bytes'; + } + elseif ($bytes == 1) + { + $bytes = $bytes . ' byte'; + } + else + { + $bytes = '0 bytes'; + } + + return $bytes; + } } diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 5140861fc4..d93bc43bfe 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -115,6 +115,7 @@ return [ 'files' => 'Files', 'file_name' => 'File', 'file_type' => 'File Type', + 'filesize' => 'File Size', 'file_uploads' => 'File Uploads', 'file_upload' => 'File Upload', 'generate' => 'Generate', diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 7e61ea00d1..1ec14f0d82 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -1122,6 +1122,7 @@ data-id-table="assetFileHistory" data-search="true" data-side-pagination="client" + data-sortable="true" data-show-columns="true" data-show-refresh="true" data-sort-order="desc" @@ -1134,12 +1135,13 @@ data-cookie-id-table="assetFileHistory"> - {{trans('general.file_type')}} - {{ trans('general.notes') }} + {{trans('general.file_type')}} {{ trans('general.image') }} - {{ trans('general.file_name') }} - {{ trans('general.download') }} - {{ trans('general.created_at') }} + {{ trans('general.file_name') }} + {{ trans('general.filesize') }} + {{ trans('general.notes') }} + {{ trans('general.download') }} + {{ trans('general.created_at') }} {{ trans('table.actions') }} @@ -1148,11 +1150,6 @@ @foreach ($asset->uploads as $file) - - @if ($file->note) - {{ $file->note }} - @endif - @if ( Helper::checkUploadIsImage($file->get_src('assets'))) @@ -1163,6 +1160,14 @@ {{ $file->filename }} + + {{ Helper::formatFilesizeUnits(filesize(storage_path('private_uploads/assets/').$file->filename)) }} + + + @if ($file->note) + {{ $file->note }} + @endif + @if ($file->filename) @@ -1170,14 +1175,11 @@ @endif - @if ($file->created_at) {{ Helper::getFormattedDateObject($file->created_at, 'datetime', false) }} @endif - - @can('update', \App\Models\Asset::class) diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php index 3abd007afb..0248bbc756 100755 --- a/resources/views/licenses/view.blade.php +++ b/resources/views/licenses/view.blade.php @@ -454,13 +454,14 @@ }'> - {{ trans('admin/hardware/table.icon') }} - {{ trans('general.file_name') }} - {{ trans('general.notes') }} - {{ trans('general.created_at') }} - {{ trans('general.image') }} - {{ trans('general.download') }} - {{ trans('general.delete') }} + {{trans('general.file_type')}} + {{ trans('general.image') }} + {{ trans('general.file_name') }} + {{ trans('general.filesize') }} + {{ trans('general.notes') }} + {{ trans('general.download') }} + {{ trans('general.created_at') }} + {{ trans('table.actions') }} @@ -473,22 +474,24 @@ - {{ $file->filename }} - + @if ($file->filename) + @if ( Helper::checkUploadIsImage($file->get_src('licenses'))) + + @endif + @endif + + {{ $file->filename }} + + + {{ Helper::formatFilesizeUnits(filesize(storage_path('private_uploads/licenses/').$file->filename)) }} + + @if ($file->note) {{ $file->note }} @endif - {{ $file->created_at }} - - @if ($file->filename) - @if ( Helper::checkUploadIsImage($file->get_src('licenses'))) - - @endif - @endif - @if ($file->filename) @@ -497,6 +500,7 @@ @endif + {{ $file->created_at }} @@ -507,7 +511,7 @@ @endforeach @else - {{ trans('general.no_results') }} + {{ trans('general.no_results') }} @endif diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index 14fbd966df..101d6f01d5 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -757,38 +757,83 @@
- +
+ - - - - + + + + + + + + @foreach ($user->uploads as $file) - - - - - - + + + + + + + + + + + @endforeach +
{{ trans('general.notes') }}{{ trans('general.file_name') }}{{ trans('general.download') }}{{ trans('general.delete') }}{{trans('general.file_type')}}{{ trans('general.image') }}{{ trans('general.file_name') }}{{ trans('general.filesize') }}{{ trans('general.notes') }}{{ trans('general.download') }}{{ trans('general.created_at') }}{{ trans('table.actions') }}
- @if ($file->note) - {{ $file->note }} - @endif - - {{ $file->filename }} - - @if ($file->filename) - {{ trans('general.download') }} - @endif - - @can('update', $user) - Delete - @endcan -
+ + {{ Helper::filetype_icon($file->filename) }} + + + @if ($file->filename) + @if ( Helper::checkUploadIsImage($file->get_src('users'))) + + @endif + @endif + + {{ $file->filename }} + + {{ Helper::formatFilesizeUnits(filesize(storage_path('private_uploads/users/').$file->filename)) }} + + @if ($file->note) + {{ $file->note }} + @endif + + @if ($file->filename) + + + {{ trans('general.download') }} + + @endif + {{ $file->created_at }} + + + {{ trans('general.delete') }} + +