From d16f5ebbce48e88279d1862a67a921bc6b10bb4a Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Mon, 25 Jul 2022 17:16:55 -0400 Subject: [PATCH] Allow image previews in the dashboard edit list --- app/Http/Controllers/DashboardController.php | 1 + resources/sass/dashboard.scss | 19 +++++++++ .../views/dashboard/pages/edit-list.blade.php | 41 ++++++++++++++++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index e88a8d4..227c4e1 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -61,6 +61,7 @@ class DashboardController extends Controller { 'paramdisplay' => $data['paramdisplay'], 'query' => $model_class::getQueryString(), 'display' => $model_class::$dashboard_display, + 'columns' => $model_class::$dashboard_columns, 'button' => $model_class::$dashboard_button, 'idlink' => $model_class::$dashboard_id_link, 'sortcol' => $model_class::$dashboard_reorder ? $model_class::$dashboard_sort_column : false, diff --git a/resources/sass/dashboard.scss b/resources/sass/dashboard.scss index 9b4abf9..3ac2b08 100644 --- a/resources/sass/dashboard.scss +++ b/resources/sass/dashboard.scss @@ -792,6 +792,7 @@ body { @include media-breakpoint-up(md) { overflow: hidden; + display: flex; flex-grow: 1; white-space: nowrap; } @@ -842,6 +843,23 @@ body { .column { display: inline-block; + + .image-preview { + @include aspect-ratio(16, 9); + display: block; + background-position: center center; + background-size: cover; + background-repeat: no-repeat; + + @include media-breakpoint-down(md) { + width: pxrem(150); + max-width: 100%; + } + + @include media-breakpoint-up(md) { + width: pxrem(43); + } + } } .spacer { @@ -851,6 +869,7 @@ body { } @include media-breakpoint-up(md) { + margin: 0px pxrem(5); display: inline-block; } } diff --git a/resources/views/dashboard/pages/edit-list.blade.php b/resources/views/dashboard/pages/edit-list.blade.php index 2996476..fa0f1fa 100644 --- a/resources/views/dashboard/pages/edit-list.blade.php +++ b/resources/views/dashboard/pages/edit-list.blade.php @@ -128,8 +128,45 @@ @endif @foreach($display as $index => $display_column) - @if($row[$display_column] != '') -
{{ $row[$display_column] }}
+ @php + $name = null; + $type = null; + + foreach ($columns as $column) { + if ($column['name'] == $display_column) { + $name = $column['name']; + $type = $column['type']; + $ext = array_key_exists('ext', $column) ? $column['ext'] : $row::$default_image_ext; + break; + } + } + + if ($type == 'image') { + $image = $row->getUploadsPath('image') . $row->id . "-$name.$ext"; + $thumbnail = $row->getUploadsPath('thumb') . $row->id . "-$name.$ext"; + + if (!file_exists(public_path($image))) { + $image = null; + $thumbnail = null; + } else if (!file_exists(public_path($thumbnail))) { + $thumbnail = $image; + } + } + @endphp + + @if($name != null && $type != null && ($row[$display_column] != '' || ($type == 'image') && $thumbnail !== null)) +
+ @if($type == 'image') + + + @else + {{ $row[$display_column] }} + @endif +
@if($index < count($display) - 1)
|