locked podcasts

This commit is contained in:
Benjamin Takats
2022-12-06 21:38:08 +01:00
parent bf31480989
commit 3b4af17e49
4 changed files with 27 additions and 9 deletions

View File

@@ -3,7 +3,9 @@
namespace App\Nova; namespace App\Nova;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Laravel\Nova\Fields\Avatar; use Laravel\Nova\Fields\Avatar;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\Code; use Laravel\Nova\Fields\Code;
use Laravel\Nova\Fields\HasMany; use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\ID;
@@ -41,6 +43,8 @@ class Podcast extends Resource
*/ */
public function fields(Request $request) public function fields(Request $request)
{ {
$guid = $this->guid ?? Str::uuid();
return [ return [
ID::make() ID::make()
->sortable(), ->sortable(),
@@ -48,8 +52,19 @@ class Podcast extends Resource
Avatar::make('Image') Avatar::make('Image')
->squared() ->squared()
->thumbnail(function () { ->thumbnail(function () {
return $this->data['image']; return $this?->data['image'] ?? '';
}), })
->exceptOnForms(),
Boolean::make('Locked', 'locked', fn($value) => $value ?? false),
Text::make('Guid', 'guid', function ($value) use ($guid) {
if ($value) {
return $value;
} else {
return $guid;
}
}),
Text::make('Title') Text::make('Title')
->rules('required', 'string'), ->rules('required', 'string'),

View File

@@ -41,7 +41,7 @@ class PodcastPolicy
*/ */
public function create(User $user) public function create(User $user)
{ {
return false; return true;
} }
/** /**
@@ -53,7 +53,7 @@ class PodcastPolicy
*/ */
public function update(User $user, Podcast $podcast) public function update(User $user, Podcast $podcast)
{ {
return false; return !$podcast->locked;
} }
/** /**
@@ -65,7 +65,7 @@ class PodcastPolicy
*/ */
public function delete(User $user, Podcast $podcast) public function delete(User $user, Podcast $podcast)
{ {
return false; return !$podcast->locked;
} }
/** /**
@@ -77,7 +77,7 @@ class PodcastPolicy
*/ */
public function restore(User $user, Podcast $podcast) public function restore(User $user, Podcast $podcast)
{ {
return false; return !$podcast->locked;
} }
/** /**
@@ -89,6 +89,6 @@ class PodcastPolicy
*/ */
public function forceDelete(User $user, Podcast $podcast) public function forceDelete(User $user, Podcast $podcast)
{ {
return false; return !$podcast->locked;
} }
} }

View File

@@ -16,10 +16,13 @@ class CreatePodcastsTable extends Migration
$table->id(); $table->id();
$table->string('guid') $table->string('guid')
->unique(); ->unique();
$table->boolean('locked')
->default(true);
$table->string('title'); $table->string('title');
$table->string('link'); $table->string('link');
$table->string('language_code'); $table->string('language_code');
$table->json('data'); $table->json('data')
->nullable();
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@@ -13,7 +13,7 @@
@endphp @endphp
<a <a
class="{{ $activeClass }} flex relative flex-col flex-shrink-0 justify-between py-1 px-3 w-full h-20 border-0 border-solid duration-300 ease-in-out cursor-pointer bg-opacity-[0.07]" class="{{ $activeClass }} flex relative flex-col flex-shrink-0 justify-between py-1 px-3 w-full h-20 border-0 border-solid duration-300 ease-in-out cursor-pointer bg-opacity-[0.07]"
href="{{ route('library', ['country' => $country, 'table' => ['filters' => ['tag' => [$tag->id]]]]) }}" href="{{ route(request()->route()->getName(), ['country' => $country, 'table' => ['filters' => ['tag' => [$tag->id]]]]) }}"
> >
<div <div
class="flex flex-1 items-center p-0 m-0 text-center align-baseline border-0 border-solid" class="flex flex-1 items-center p-0 m-0 text-center align-baseline border-0 border-solid"