Skip to content

Commit

Permalink
ordering and move to new slideshow
Browse files Browse the repository at this point in the history
  • Loading branch information
bastihilger committed Jul 11, 2022
1 parent 67976bf commit 183b3ca
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 33 deletions.
30 changes: 22 additions & 8 deletions composer.lock

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

1 change: 1 addition & 0 deletions config/nova-cms-portfolio.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'has_custom_portfolio_image' => true,
'has_embed_code' => true,
'has_move_to_slideshow' => false,
'has_move_to_new_slideshow' => false,
'has_select_portfolio_image' => true,
'has_projects_zip_upload' => false,
'has_quick_upload' => true,
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/nova-cms-portfolio/de/works.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
'embed_url' => 'Embed URL (Youtube, Vimeo etc.)',
'is_artist_discipline_image' => 'Repräsentiert Künstler in Disziplin',
'is_artist_portfolio_image' => 'Ist Künstler-Portfolio-Bild',
'move_to_different_project' => 'In anderes :attribute verschieben',
'move_to_different_slideshow' => 'In andere(s) :attribute verschieben',
'move_to_new_slideshow' => 'In neue(s) :attribute verschieben',
'overview_categories' => 'Kat. (Übersicht)',
'representation_categories' => 'Kat. (Repräsentiert...)',
'represents_artist_in_discipline_category' => 'In allgemeiner Kategorie-Übersicht zeigen',
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/nova-cms-portfolio/en/works.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
'embed_url' => 'Embed URL (Youtube, Vimeo etc.)',
'is_artist_discipline_image' => 'represents artist in discipline',
'is_artist_portfolio_image' => 'is artist portfolio image',
'move_to_different_project' => 'move to different :attribute',
'move_to_different_slideshow' => 'move to different :attribute',
'move_to_new_slideshow' => 'move to new :attribute',
'overview_categories' => 'category prio in overview',
'representation_categories' => 'cat. (represents...)',
'represents_artist_in_discipline_category' => 'represents artist on frontpage category',
Expand Down
144 changes: 144 additions & 0 deletions src/Nova/Actions/MoveToNewSlideshow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

namespace Kraenkvisuell\NovaCmsPortfolio\Nova\Actions;

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Kraenkvisuell\NovaCmsPortfolio\Models\Category;
use Kraenkvisuell\NovaCmsPortfolio\Models\Slideshow;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Slug;
use Laravel\Nova\Fields\Text;

class MoveToNewSlideshow extends Action
{
public function name()
{
return ucfirst(__(
'nova-cms-portfolio::works.move_to_new_slideshow',
[
'attribute' => config('nova-cms-portfolio.custom_slideshow_label')
?: ucfirst(__('nova-cms-portfolio::slideshows.slideshow')),
]
));
}

public function handle(ActionFields $fields, Collection $works)
{
$oldSlideshow = Slideshow::find($works->first()->slideshow_id);

$newSlideshow = Slideshow::create([
'artist_id' => $oldSlideshow->artist_id,
'title' => $fields->title,
'slug' => $fields->slug,
'is_published' => $fields->is_published,
'is_visible_in_overview' => $fields->is_visible_in_overview,
]);

foreach ($works as $work) {
$work->slideshow_id = $newSlideshow->id;
$work->sort_order += 1000;
$work->save();
}

$newSlideshow->categories()->attach($fields->category_id);

$oldSlideshow->refreshWorksOrder();
$newSlideshow->refreshWorksOrder();

if ($fields->afterwards == 'go_to_other_slideshow') {
return Action::push('/resources/slideshows/'.$newSlideshow->id);
}
}

public function fields()
{
$currentSlideshow = Slideshow::where('id', request()->input('viaResourceId'))
->with([
'categories',
])
->first();

$categoryOptions = Category::all()->sortBy('title')->pluck('title', 'id');

$visibleInArtistOverviewLabel = config('nova-cms-portfolio.custom_visible_in_artist_overview_label')
?: ucfirst(__('nova-cms-portfolio::slideshows.visible_in_artist_overview'));

return [
Text::make(__('nova-cms::pages.title'), 'title')
->required()
->rules('required'),

Slug::make(__('nova-cms::pages.slug'), 'slug')->from('title')
->rules('required'),

Select::make(
__('nova-cms-portfolio::categories.category'),
'category_id'
)
->required()
->rules('required')
->options($categoryOptions)
->default($currentSlideshow->categories->first()->id),

Boolean::make(ucfirst(__('nova-cms-portfolio::portfolio.published')), 'is_published')
->default(true),

Boolean::make($visibleInArtistOverviewLabel, 'is_visible_in_overview')
->default(true),

Select::make(
ucfirst(__('nova-cms-portfolio::portfolio.afterwards')),
'afterwards'
)
->required()
->rules('required')
->options([
'go_to_other_slideshow' => __(
'nova-cms-portfolio::portfolio.go_where_moved_to'
),
'stay_on_this_slideshow' => __(
'nova-cms-portfolio::portfolio.stay_here'
),

])
->default('go_to_other_slideshow'),

];
}

protected function getSlideshows()
{
return Cache::remember(
'nova.artist.projects.'.request()->input('viaResourceId'),
now()->addSeconds(5),
function () {
$currentSlideshow = Slideshow::where('id', request()->input('viaResourceId'))
->with([
'artist.slideshows',
'artist.categories',
'categories',
])
->first();

$slideshows = [];

foreach ($currentSlideshow->artist->categories as $category) {
foreach ($currentSlideshow->artist->slideshows as $slideshow) {
if (
$currentSlideshow->id != $slideshow->id
&& $slideshow->categories->firstWhere('id', $category->id)
) {
$slideshows[$slideshow->id] = $category->title.': '.$slideshow->title;
}
}
}

return $slideshows;
}
);
}
}
2 changes: 1 addition & 1 deletion src/Nova/Actions/MoveToSlideshow.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MoveToSlideshow extends Action
public function name()
{
return ucfirst(__(
'nova-cms-portfolio::works.move_to_different_project',
'nova-cms-portfolio::works.move_to_different_slideshow',
[
'attribute' => config('nova-cms-portfolio.custom_slideshow_label')
?: ucfirst(__('nova-cms-portfolio::slideshows.slideshow')),
Expand Down
26 changes: 4 additions & 22 deletions src/Nova/Slideshow.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,6 @@ class="w-auto h-12 mr-1 inline-block"

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

// Line::make('', function () {
// if ($this->works->where('is_artist_discipline_image', true)->count()) {
// return '<div class="text-xs font-bold uppercase">'
// .__('nova-cms-portfolio::works.is_artist_discipline_image')
// .'</div>';
// }

// return '';
// })->asHtml(),

// Line::make('', function () {
// if ($this->works->where('is_artist_portfolio_image', true)->count()) {
// return '<div class="text-xs font-bold uppercase">'
// .__('nova-cms-portfolio::works.is_artist_portfolio_image')
// .'</div>';
// }

// return '';
// })->asHtml(),
])
->onlyOnIndex();

Expand All @@ -205,10 +185,12 @@ class="btn btn-xs

$fields[] = Slug::make(__('nova-cms::pages.slug'), 'slug')->from('title')
->rules('required')
->onlyOnForms();
->onlyOnForms()
->default(true);

$fields[] = Boolean::make(ucfirst(__('nova-cms-portfolio::portfolio.published')), 'is_published')
->onlyOnForms();
->onlyOnForms()
->default(true);

if (config('nova-cms-portfolio.has_visible_in_artist_overview')) {
$fields[] = Boolean::make($visibleInArtistOverviewLabel, 'is_visible_in_overview')
Expand Down
5 changes: 5 additions & 0 deletions src/Nova/Work.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\Cache;
use Kraenkvisuell\NovaCmsMedia\MediaLibrary;
use Kraenkvisuell\NovaCmsPortfolio\Models\Slideshow;
use Kraenkvisuell\NovaCmsPortfolio\Nova\Actions\MoveToNewSlideshow;
use Kraenkvisuell\NovaCmsPortfolio\Nova\Actions\MoveToSlideshow;
use Kraenkvisuell\NovaCmsPortfolio\Nova\Actions\ToggleArtistPortfolioImage;
use Kraenkvisuell\NovaCmsPortfolio\Nova\Actions\ToggleRepresentsArtistInCategory;
Expand Down Expand Up @@ -299,6 +300,10 @@ public function actions(Request $request)
$actions[] = MoveToSlideshow::make();
}

if (config('nova-cms-portfolio.has_move_to_new_slideshow')) {
$actions[] = MoveToNewSlideshow::make();
}

if (config('nova-cms-portfolio.has_select_portfolio_image')) {
$actions[] = ToggleArtistPortfolioImage::make()
->onlyOnTableRow()
Expand Down

0 comments on commit 183b3ca

Please sign in to comment.