Allow image previews in the dashboard edit list

This commit is contained in:
Kevin MacMartin 2022-07-25 17:16:55 -04:00
parent f8f90ec15e
commit d16f5ebbce
3 changed files with 59 additions and 2 deletions

View file

@ -61,6 +61,7 @@ class DashboardController extends Controller {
'paramdisplay' => $data['paramdisplay'], 'paramdisplay' => $data['paramdisplay'],
'query' => $model_class::getQueryString(), 'query' => $model_class::getQueryString(),
'display' => $model_class::$dashboard_display, 'display' => $model_class::$dashboard_display,
'columns' => $model_class::$dashboard_columns,
'button' => $model_class::$dashboard_button, 'button' => $model_class::$dashboard_button,
'idlink' => $model_class::$dashboard_id_link, 'idlink' => $model_class::$dashboard_id_link,
'sortcol' => $model_class::$dashboard_reorder ? $model_class::$dashboard_sort_column : false, 'sortcol' => $model_class::$dashboard_reorder ? $model_class::$dashboard_sort_column : false,

View file

@ -792,6 +792,7 @@ body {
@include media-breakpoint-up(md) { @include media-breakpoint-up(md) {
overflow: hidden; overflow: hidden;
display: flex;
flex-grow: 1; flex-grow: 1;
white-space: nowrap; white-space: nowrap;
} }
@ -842,6 +843,23 @@ body {
.column { .column {
display: inline-block; 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 { .spacer {
@ -851,6 +869,7 @@ body {
} }
@include media-breakpoint-up(md) { @include media-breakpoint-up(md) {
margin: 0px pxrem(5);
display: inline-block; display: inline-block;
} }
} }

View file

@ -128,8 +128,45 @@
@endif @endif
@foreach($display as $index => $display_column) @foreach($display as $index => $display_column)
@if($row[$display_column] != '') @php
<div class="column">{{ $row[$display_column] }}</div> $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))
<div class="column">
@if($type == 'image')
<a
class="image-preview"
href="{{ $image }}"
target="_blank"
style="background-image: url({{ $thumbnail }})">
</a>
@else
{{ $row[$display_column] }}
@endif
</div>
@if($index < count($display) - 1) @if($index < count($display) - 1)
<div class="spacer">|</div> <div class="spacer">|</div>