nova book cases

This commit is contained in:
Benjamin Takats
2022-12-07 19:19:44 +01:00
parent 351c9047a9
commit f79d0e9ff0
9 changed files with 245 additions and 29 deletions

View File

@@ -68,6 +68,22 @@ class BookCaseTable extends DataTableComponent
Column::make("Adresse", "address")
->sortable()
->searchable(),
Column::make("Bitcoin-Bücher")
->label(
fn(
$row,
Column $column
) => $row->orangePills->sum('amount')
),
Column::make("Letzter Input")
->label(
fn(
$row,
Column $column
) => $row->orangePills()
->latest()
->first()?->date->asDate()
),
Column::make("Link")
->label(
fn(

View File

@@ -60,12 +60,12 @@ class BookCase extends Model implements HasMedia
}
/*
* This string will be used in notifications on what a new comment
* was made.
*/
* This string will be used in notifications on what a new comment
* was made.
*/
public function commentableName(): string
{
//
return __('Bookcase');
}
/*
@@ -74,6 +74,6 @@ class BookCase extends Model implements HasMedia
*/
public function commentUrl(): string
{
return url()->route('comment.bookcase', ['bookCase' => $this->id]);
}
}

View File

@@ -2,58 +2,63 @@
namespace App\Nova;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Code;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\Code;
use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\MorphMany;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
class BookCase extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \App\Models\BookCase::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'id';
public static $title = 'title';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id',
'title',
];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
ID::make()
->sortable(),
Text::make('Title')
->rules('required', 'string'),
Number::make('Lat')
->rules('required', 'numeric'),
Number::make('Latitude')
->rules('required', 'numeric')
->step(0.000001)
->hideFromIndex(),
Code::make('Lon')
->rules('required', 'json')
->json(),
Number::make('Longitude')
->rules('required', 'numeric')
->step(0.000001)
->hideFromIndex(),
Text::make('Address')
->rules('required', 'string'),
@@ -62,35 +67,47 @@ class BookCase extends Resource
->rules('required', 'string'),
Text::make('Open')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Text::make('Comment')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Text::make('Contact')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Text::make('Bcz')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Boolean::make('Digital')
->rules('required'),
->rules('required')
->hideFromIndex(),
Text::make('Icontype')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Boolean::make('Deactivated')
->rules('required'),
->rules('required'),
Text::make('Deactreason')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Text::make('Entrytype')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
Text::make('Homepage')
->rules('required', 'string'),
->rules('required', 'string')
->hideFromIndex(),
HasMany::make('OrangePills'),
MorphMany::make('Comments'),
];
}
@@ -99,6 +116,7 @@ class BookCase extends Resource
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function cards(Request $request)
@@ -110,6 +128,7 @@ class BookCase extends Resource
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function filters(Request $request)
@@ -121,6 +140,7 @@ class BookCase extends Resource
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function lenses(Request $request)
@@ -132,6 +152,7 @@ class BookCase extends Resource
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)

53
app/Nova/Comment.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
namespace App\Nova;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\Markdown;
use Laravel\Nova\Fields\MorphTo;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Spatie\Comments\Models\Comment as CommentModel;
class Comment extends Resource
{
public static $model = CommentModel::class;
public static $search = [
'id', 'text',
];
public function fields(NovaRequest $request)
{
return [
Text::make('title', function (CommentModel $comment) {
return $comment->topLevel()->commentable?->commentableName() ?? 'Deleted...';
})->readonly(),
MorphTo::make('Commentator')->types([
User::class,
]),
Markdown::make('Original text'),
Text::make('', function (CommentModel $comment) {
if (! $url = $comment?->commentUrl()) {
return '';
}
return "<a target=\"show_comment\" href=\"{$url}\">Show</a>";
})->asHtml(),
Text::make('status', function(CommentModel $comment) {
if ($comment->isApproved()) {
return "<div class='inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-green-100 text-green-800'>Approved</div>";
}
return "<div class='inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800'>Pending</div>";
})->asHtml(),
DateTime::make('Created at'),
];
}
}

View File

@@ -17,6 +17,11 @@ class OrangePill extends Resource
*/
public static $model = \App\Models\OrangePill::class;
public static function label()
{
return 'Inputs';
}
/**
* The single value that should be used to represent the resource when being displayed.
*

View File

@@ -0,0 +1,101 @@
<?php
namespace App\Policies;
use App\Models\BookCase;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class BookCasePolicy extends BasePolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view any models.
*
* @param \App\Models\User $user
*
* @return \Illuminate\Auth\Access\Response|bool
*/
public function viewAny(User $user)
{
return true;
}
/**
* Determine whether the user can view the model.
*
* @param \App\Models\User $user
* @param \App\Models\BookCase $bookCase
*
* @return \Illuminate\Auth\Access\Response|bool
*/
public function view(User $user, BookCase $bookCase)
{
return true;
}
/**
* Determine whether the user can create models.
*
* @param \App\Models\User $user
*
* @return \Illuminate\Auth\Access\Response|bool
*/
public function create(User $user)
{
return false;
}
/**
* Determine whether the user can update the model.
*
* @param \App\Models\User $user
* @param \App\Models\BookCase $bookCase
*
* @return \Illuminate\Auth\Access\Response|bool
*/
public function update(User $user, BookCase $bookCase)
{
return false;
}
/**
* Determine whether the user can delete the model.
*
* @param \App\Models\User $user
* @param \App\Models\BookCase $bookCase
*
* @return \Illuminate\Auth\Access\Response|bool
*/
public function delete(User $user, BookCase $bookCase)
{
return false;
}
/**
* Determine whether the user can restore the model.
*
* @param \App\Models\User $user
* @param \App\Models\BookCase $bookCase
*
* @return \Illuminate\Auth\Access\Response|bool
*/
public function restore(User $user, BookCase $bookCase)
{
return false;
}
/**
* Determine whether the user can permanently delete the model.
*
* @param \App\Models\User $user
* @param \App\Models\BookCase $bookCase
*
* @return \Illuminate\Auth\Access\Response|bool
*/
public function forceDelete(User $user, BookCase $bookCase)
{
return false;
}
}

View File

@@ -2,8 +2,10 @@
namespace App\Providers;
use App\Nova\BookCase;
use App\Nova\Category;
use App\Nova\City;
use App\Nova\Comment;
use App\Nova\Country;
use App\Nova\Course;
use App\Nova\Dashboards\Main;
@@ -12,6 +14,7 @@ use App\Nova\Event;
use App\Nova\Lecturer;
use App\Nova\Library;
use App\Nova\LibraryItem;
use App\Nova\OrangePill;
use App\Nova\Participant;
use App\Nova\Podcast;
use App\Nova\Registration;
@@ -68,6 +71,19 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
->icon('microphone')
->collapsable(),
MenuSection::make('Books', [
MenuItem::resource(BookCase::class),
MenuItem::resource(OrangePill::class),
])
->icon('book-open')
->collapsable(),
MenuSection::make('Comments', [
MenuItem::resource(Comment::class),
])
->icon('chat')
->collapsable(),
MenuSection::make('Admin', [
MenuItem::resource(Category::class),
MenuItem::resource(Country::class),

View File

@@ -1,6 +1,7 @@
{
"Orange Pill Book Case": "Wie viele Bitcoin-Bücher hast du hinzu gefügt?",
"Book": "Buch",
"Bookcase": "Bücher-Schrank",
"Article": "Artikel",
"Markdown Article": "Interner Artikel",
"Youtube Video": "Youtube Video",

View File

@@ -24,6 +24,9 @@
<x-jet-nav-link href="/nova/resources/library-items" target="_blank">
{{ __('Inhalte eintragen') }}
</x-jet-nav-link>
<x-jet-nav-link href="/nova/resources/library-items" target="_blank">
{{ __('Bücher-Schränke verwalten') }}
</x-jet-nav-link>
<x-jet-nav-link href="{{ route('profile.show') }}" :active="request()->routeIs('profile.show')">
{{ __('Mein Profil') }}
</x-jet-nav-link>