mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-13 06:56:48 +00:00
publishing library items
This commit is contained in:
52
app/Nova/Actions/SetStatusAction.php
Normal file
52
app/Nova/Actions/SetStatusAction.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Nova\Actions;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Nova\Actions\Action;
|
||||
use Laravel\Nova\Fields\ActionFields;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
|
||||
class SetStatusAction extends Action
|
||||
{
|
||||
use InteractsWithQueue, Queueable;
|
||||
|
||||
/**
|
||||
* Perform the action on the given models.
|
||||
*
|
||||
* @param \Laravel\Nova\Fields\ActionFields $fields
|
||||
* @param \Illuminate\Support\Collection $models
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(ActionFields $fields, Collection $models)
|
||||
{
|
||||
foreach ($models as $model) {
|
||||
|
||||
// The normal function to set the Status
|
||||
$model->setStatus($fields->status);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fields available on the action.
|
||||
*
|
||||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields(NovaRequest $request)
|
||||
{
|
||||
return [
|
||||
Select::make('Status')
|
||||
->options([
|
||||
'draft' => 'DRAFT',
|
||||
'published' => 'PUBLISHED',
|
||||
])
|
||||
->displayUsingLabels()
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Nova;
|
||||
|
||||
use App\Enums\LibraryItemType;
|
||||
use App\Notifications\ModelCreatedNotification;
|
||||
use App\Nova\Actions\SetStatusAction;
|
||||
use Ebess\AdvancedNovaMediaLibrary\Fields\Files;
|
||||
use Ebess\AdvancedNovaMediaLibrary\Fields\Images;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -17,6 +18,7 @@ use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
use Spatie\LaravelOptions\Options;
|
||||
use Spatie\TagsField\Tags;
|
||||
use WesselPerik\StatusField\StatusField;
|
||||
|
||||
class LibraryItem extends Resource
|
||||
{
|
||||
@@ -67,6 +69,25 @@ class LibraryItem extends Resource
|
||||
ID::make()
|
||||
->sortable(),
|
||||
|
||||
StatusField::make('Status',)
|
||||
->icons([
|
||||
'clock' => $this->status === 'draft',
|
||||
'check-circle' => $this->status === 'published',
|
||||
])
|
||||
->tooltip([
|
||||
'clock' => 'Pending publication',
|
||||
'check-circle' => 'Published'
|
||||
])
|
||||
->info([
|
||||
'clock' => 'Pending publication.',
|
||||
'check-circle' => 'Published.'
|
||||
])
|
||||
->color([
|
||||
'clock' => 'blue-500',
|
||||
'check-circle' => 'green-500'
|
||||
])
|
||||
->exceptOnForms(),
|
||||
|
||||
Images::make(__('Main picture'), 'main')
|
||||
->conversionOnIndexView('thumb'),
|
||||
|
||||
@@ -160,6 +181,8 @@ class LibraryItem extends Resource
|
||||
*/
|
||||
public function actions(Request $request)
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
new SetStatusAction(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user