mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
publishing library items
This commit is contained in:
@@ -153,6 +153,7 @@ class LibraryItemTable extends DataTableComponent
|
||||
fn($query) => $query->where('libraries.name', $this->currentTab)))
|
||||
->withCount([
|
||||
'lecturer',
|
||||
]);
|
||||
])
|
||||
->currentStatus('published');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ use Spatie\Image\Manipulations;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use Spatie\ModelStatus\HasStatuses;
|
||||
use Spatie\Tags\HasTags;
|
||||
|
||||
class LibraryItem extends Model implements HasMedia, Sortable
|
||||
@@ -18,6 +19,7 @@ class LibraryItem extends Model implements HasMedia, Sortable
|
||||
use InteractsWithMedia;
|
||||
use HasTags;
|
||||
use SortableTrait;
|
||||
use HasStatuses;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
|
||||
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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
"spatie/laravel-google-fonts": "^1.2",
|
||||
"spatie/laravel-markdown": "^2.2",
|
||||
"spatie/laravel-medialibrary": "^10.0.0",
|
||||
"spatie/laravel-model-status": "^1.11",
|
||||
"spatie/laravel-options": "^1.0",
|
||||
"spatie/laravel-ray": "^1.31",
|
||||
"spatie/laravel-sluggable": "^3.4",
|
||||
@@ -44,6 +45,7 @@
|
||||
"stijnvanouplines/blade-country-flags": "^1.0",
|
||||
"symfony/http-client": "^6.2",
|
||||
"symfony/mailgun-mailer": "^6.2",
|
||||
"wesselperik/nova-status-field": "^2.1",
|
||||
"wireui/wireui": "^1.17",
|
||||
"ziffmedia/nova-select-plus": "^2.0"
|
||||
},
|
||||
|
||||
120
composer.lock
generated
120
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "f361449843e880ec16cbc06c10871928",
|
||||
"content-hash": "910dfec50f7d5534308b74a252331b64",
|
||||
"packages": [
|
||||
{
|
||||
"name": "akuechler/laravel-geoly",
|
||||
@@ -7539,6 +7539,77 @@
|
||||
],
|
||||
"time": "2022-12-06T07:29:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "spatie/laravel-model-status",
|
||||
"version": "1.11.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/spatie/laravel-model-status.git",
|
||||
"reference": "6380fa82ac98ab755b08a034d2c1608212e26478"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/spatie/laravel-model-status/zipball/6380fa82ac98ab755b08a034d2c1608212e26478",
|
||||
"reference": "6380fa82ac98ab755b08a034d2c1608212e26478",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/support": "^8.71|^9.0",
|
||||
"php": "^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"orchestra/testbench": "^6.23|^7.0",
|
||||
"phpunit/phpunit": "^9.4"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Spatie\\ModelStatus\\ModelStatusServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Spatie\\ModelStatus\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Thomas Verhelst",
|
||||
"email": "tvke91@gmail.com",
|
||||
"homepage": "https://spatie.be",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Freek Van der Herten",
|
||||
"email": "freek@spatie.be",
|
||||
"homepage": "https://spatie.be",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "A package to enable assigning statuses to Eloquent Models",
|
||||
"homepage": "https://github.com/spatie/laravel-model-status",
|
||||
"keywords": [
|
||||
"laravel-status",
|
||||
"spatie"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/spatie/laravel-model-status/issues",
|
||||
"source": "https://github.com/spatie/laravel-model-status/tree/1.11.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://spatie.be/open-source/support-us",
|
||||
"type": "custom"
|
||||
}
|
||||
],
|
||||
"time": "2022-02-03T07:36:04+00:00"
|
||||
},
|
||||
{
|
||||
"name": "spatie/laravel-options",
|
||||
"version": "1.0.3",
|
||||
@@ -11803,6 +11874,53 @@
|
||||
},
|
||||
"time": "2022-06-03T18:03:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "wesselperik/nova-status-field",
|
||||
"version": "2.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/wesselperik/nova-status-field.git",
|
||||
"reference": "1b59ca03b658a2ed73b086df7d41394326fe80ef"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/wesselperik/nova-status-field/zipball/1b59ca03b658a2ed73b086df7d41394326fe80ef",
|
||||
"reference": "1b59ca03b658a2ed73b086df7d41394326fe80ef",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"laravel/nova": "^4.0",
|
||||
"php": "^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"WesselPerik\\StatusField\\FieldServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"WesselPerik\\StatusField\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "A Laravel Nova field for displaying statuses.",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
"nova",
|
||||
"status"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/wesselperik/nova-status-field/issues",
|
||||
"source": "https://github.com/wesselperik/nova-status-field/tree/2.1.2"
|
||||
},
|
||||
"time": "2022-09-14T19:06:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "wireui/wireui",
|
||||
"version": "v1.17.7",
|
||||
|
||||
18
config/model-status.php
Normal file
18
config/model-status.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
* The class name of the status model that holds all statuses.
|
||||
*
|
||||
* The model must be or extend `Spatie\ModelStatus\Status`.
|
||||
*/
|
||||
'status_model' => Spatie\ModelStatus\Status::class,
|
||||
|
||||
/*
|
||||
* The name of the column which holds the ID of the model related to the statuses.
|
||||
*
|
||||
* You can change this value if you have set a different name in the migration for the statuses table.
|
||||
*/
|
||||
'model_primary_key_attribute' => 'model_id',
|
||||
];
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateStatusesTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('statuses', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
$table->text('reason')->nullable();
|
||||
$table->morphs('model');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('statuses');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user