diff --git a/app/Models/Study.php b/app/Models/Study.php index 7d88ccb..7fb1141 100644 --- a/app/Models/Study.php +++ b/app/Models/Study.php @@ -15,6 +15,7 @@ use Illuminate\Support\Str; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; +use Spatie\MediaLibrary\MediaCollections\Models\Media; class Study extends BaseModel implements HasMedia { @@ -22,6 +23,7 @@ class Study extends BaseModel implements HasMedia use InteractsWithMedia; public const string MEDIA_COLLECTION = 'attachments'; + public const string FALLBACK_IMAGE = 'imgs/pdf.png'; public function details(): HasOne { @@ -265,6 +267,26 @@ public function getPriorityIcon(): string }; } + public function registerMediaConversions(?Media $media = null): void + { + // $media->extension + $this->addMediaConversion('tn') + ->width(48) + ->height(48) + ->sharpen(10) + ->performOnCollections(Study::MEDIA_COLLECTION) + ->nonQueued(); + } + + public function registerMediaCollections(): void + { + $this->addMediaCollection(self::MEDIA_COLLECTION) + ->useFallbackUrl(asset(self::FALLBACK_IMAGE)) + ->useFallbackUrl(asset(self::FALLBACK_IMAGE), 'tn') + ->useFallbackPath(public_path(self::FALLBACK_IMAGE)) + ->useFallbackPath(public_path(self::FALLBACK_IMAGE), 'tn'); + } + protected function casts(): array { return [ diff --git a/app/helpers.php b/app/helpers.php index d24fc58..ad826bc 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -2,6 +2,7 @@ use App\Models\User; use App\Services\AuditTrail\ActivityLogger; +use Spatie\MediaLibrary\MediaCollections\Models\Media; if (! function_exists('_h')) { function _h(int $key): string @@ -72,10 +73,11 @@ function may(BackedEnum|iterable|string $perm): bool return auth()->user()->can($perm); } } + if (! function_exists('human_filesize')) { function human_filesize(int $bytes, $dec = 0): string { - $size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + $size = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; $factor = floor((strlen($bytes) - 1) / 3); if ($factor == 0) { $dec = 0; @@ -84,3 +86,28 @@ function human_filesize(int $bytes, $dec = 0): string return sprintf("%.{$dec}f %s", $bytes / (1024 ** $factor), $size[$factor]); } } + +if (! function_exists('chomp')) { + function chomp(string $s, int $len, int $right = 6): string + { + $length = strlen($s); + if ($length <= ($len + $right)) { + return $s; + } + $start = substr($s, 0, $len); + $end = substr($s, -$right); + + return $start . '...' . $end; + } +} + +if (! function_exists('thumb_url')) { + function thumb_url(Media $media): string + { + if ($media->mime_type === 'application/pdf') { + return asset('imgs/pdf.png'); + } + + return $media->getUrl('tn') ?? asset('imgs/pdf.png'); + } +} diff --git a/resources/imgs/pdf.png b/resources/imgs/pdf.png new file mode 100644 index 0000000..39d5881 Binary files /dev/null and b/resources/imgs/pdf.png differ diff --git a/resources/views/staff/history/edit.blade.php b/resources/views/staff/history/edit.blade.php index c0ec7bb..c0cb7ae 100644 --- a/resources/views/staff/history/edit.blade.php +++ b/resources/views/staff/history/edit.blade.php @@ -12,12 +12,13 @@ @extends('layouts.layoutMaster') -@section('title', 'Worklist') +@section('title', 'Info') @section('vendor-style') @vite([ 'resources/fontawesome/scss/fontawesome.scss', 'resources/fontawesome/scss/light.scss', + 'resources/assets/vendor/libs/dropzone/dropzone.scss' ]) - + @endsection @section('page-script') @endsection @section('content') -
File | +Size | +Uploaded | ++ |
---|---|---|---|
+
+
+
+
+
+
+
+ |
+
+ + {{ $media->human_readable_size }} + | + ++ {{ $media->created_at->format('d.m.Y h:iA') }} + | + +
+
+
+
+ |
+