Skip to content

Commit

Permalink
images thumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
bastihilger committed Jul 19, 2021
1 parent 94e6a5a commit d2ec55e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 34 deletions.
34 changes: 17 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 51 additions & 17 deletions src/Nova/Slideshow.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Laravel\Nova\Fields\Slug;
use Laravel\Nova\Fields\Stack;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Resource;
use OptimistDigital\NovaSortable\Traits\HasSortableRows;
use OwenMelbz\RadioField\RadioButton;
Expand Down Expand Up @@ -47,6 +48,11 @@ public static function singularLabel()
?: ucfirst(__('nova-cms-portfolio::slideshows.slideshow'));
}

public static function indexQuery(NovaRequest $request, $query)
{
return $query->with(['works']);
}

public function fields(Request $request)
{
$workLabel = __(config('nova-cms-portfolio.custom_works_label'))
Expand All @@ -59,6 +65,51 @@ public function fields(Request $request)
Text::make(__('nova-cms::pages.title'), 'title')
->rules('required'),

BelongsToManyField::make(__('nova-cms-portfolio::categories.categories'), 'categories', Category::class)
->optionsLabel('title'),

Stack::make($workLabel, [
Line::make('', function () {
$html = '<a
href="/nova/resources/slideshows/'.$this->id.'"
class=""
>';
foreach ($this->works->take(3) as $work) {
if (nova_cms_mime($work->file) == 'video') {
$html .= '<video
autoplay muted loop playsinline
class="w-auto h-12 mr-1 inline-block"
>
<source src="'.nova_cms_file($work->file).'" type="video/'.nova_cms_extension($work->file).'">
</video>';
} else {
$html .= '<img
class="w-auto h-12 mr-1 inline-block"
src="'.nova_cms_image($work->file, 'thumb').'"
/>';
}
}
$html .= '</a>';

return $html;
})->asHtml(),
])
->onlyOnIndex(),

Stack::make('', [
Line::make('', function () use ($workLabel, $workSingularLabel) {
return '<button
onclick="window.location.href=\'/nova/resources/slideshows/'.$this->id.'\'"
class="btn btn-xs
'.($this->works->count() ? 'btn-primary' : 'btn-danger').'
"
>'
.$this->works->count().' '.($this->works->count() != 1 ? $workLabel : $workSingularLabel)
.'</button>';
})->asHtml(),
])
->onlyOnIndex(),

Slug::make(__('nova-cms::pages.slug'), 'slug')->from('title')
->rules('required')
->onlyOnForms(),
Expand All @@ -69,9 +120,6 @@ public function fields(Request $request)
Boolean::make(ucfirst(__('nova-cms-portfolio::slideshows.visible_in_artist_overview')), 'is_visible_in_overview')
->onlyOnForms(),

BelongsToManyField::make(__('nova-cms-portfolio::categories.categories'), 'categories', Category::class)
->optionsLabel('title'),

Select::make(__('nova-cms-portfolio::works.title_position'), 'title_position')
->options([
'bottom_left' => 'bottom left',
Expand All @@ -81,20 +129,6 @@ public function fields(Request $request)
])
->onlyOnForms(),

Stack::make('', [
Line::make($workLabel, function () use ($workLabel, $workSingularLabel) {
return '<button
onclick="window.location.href=\'/nova/resources/slideshows/'.$this->id.'\'"
class="btn btn-xs
'.($this->works->count() ? 'btn-primary' : 'btn-danger').'
"
>'
.$this->works->count().' '.($this->works->count() != 1 ? $workLabel : $workSingularLabel)
.'</button>';
})->asHtml(),
])
->onlyOnIndex(),

HasMany::make($workLabel, 'works', Work::class),
];

Expand Down

0 comments on commit d2ec55e

Please sign in to comment.