Skip to content

Commit

Permalink
feat: added document, avatar & banner facets (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrch authored Apr 24, 2024
1 parent 5100f13 commit 99153cb
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/Actions/Storage/Admin/Dump/DumpWikiAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use App\Pivots\Wiki\ArtistMember;
use App\Pivots\Wiki\ArtistResource;
use App\Pivots\Wiki\ArtistSong;
use App\Pivots\Wiki\SongResource;
use App\Pivots\Wiki\StudioImage;
use App\Pivots\Wiki\StudioResource;
use Illuminate\Support\Facades\Date;
Expand Down Expand Up @@ -69,6 +70,7 @@ protected function allowedTables(): array
Image::TABLE,
Series::TABLE,
Song::TABLE,
SongResource::TABLE,
Studio::TABLE,
StudioImage::TABLE,
StudioResource::TABLE,
Expand Down
3 changes: 3 additions & 0 deletions app/Enums/Models/Wiki/ImageFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ enum ImageFacet: int
case COVER_SMALL = 0;
case COVER_LARGE = 1;
case GRILL = 2;
case DOCUMENT = 3;
case AVATAR = 4;
case BANNER = 5;
}
19 changes: 13 additions & 6 deletions app/Nova/Actions/Models/Wiki/AttachImageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function handle(ActionFields $fields, Collection $models): Collection
$images = $this->createImages($fields, $models->first());

foreach ($images as $image) {
if (in_array($image->facet, [ImageFacet::GRILL, ImageFacet::DOCUMENT])) continue;

$relation = $this->relation($image);

$relation->attach($models);
Expand All @@ -70,10 +72,10 @@ public function handle(ActionFields $fields, Collection $models): Collection
* Create the images.
*
* @param ActionFields $fields
* @param Model $model
* @param Model|null $model
* @return Image[]
*/
protected function createImages(ActionFields $fields, Model $model): array
protected function createImages(ActionFields $fields, ?Model $model): array
{
$images = [];

Expand Down Expand Up @@ -101,11 +103,16 @@ protected function createImages(ActionFields $fields, Model $model): array
* Path to storage image in filesystem.
*
* @param ImageFacet $facet
* @param Model $model
* @param Model|null $model
* @return string
*/
protected function path(ImageFacet $facet, Model $model): string
protected function path(ImageFacet $facet, ?Model $model): string
{
if (in_array($facet, [ImageFacet::GRILL, ImageFacet::DOCUMENT])) {
return Str::of(Str::kebab($facet->localize()))
->__toString();
}

return Str::of(Str::kebab(class_basename($model)))
->append(DIRECTORY_SEPARATOR)
->append(Str::kebab($facet->localize()))
Expand All @@ -116,9 +123,9 @@ protected function path(ImageFacet $facet, Model $model): string
* Get the relation to the action models.
*
* @param Image $image
* @return BelongsToMany
* @return BelongsToMany|Image
*/
abstract protected function relation(Image $image): BelongsToMany;
abstract protected function relation(Image $image): BelongsToMany|Image;

/**
* Get the fields available on the action.
Expand Down
25 changes: 25 additions & 0 deletions app/Nova/Actions/Models/Wiki/Image/AttachImageAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Nova\Actions\Models\Wiki\Image;

use App\Models\Wiki\Image;
use App\Nova\Actions\Models\Wiki\AttachImageAction as AttachImageActionAction;

/**
* Class AttachImageAction.
*/
class AttachImageAction extends AttachImageActionAction
{
/**
* Get the relation to the action models.
*
* @param Image $image
* @return Image
*/
protected function relation(Image $image): Image
{
return $image;
}
}
27 changes: 27 additions & 0 deletions app/Nova/Resources/Wiki/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Enums\Models\Wiki\ImageFacet;
use App\Models\Wiki\Image as ImageModel;
use App\Nova\Actions\Models\Wiki\Image\AttachImageAction;
use App\Nova\Lenses\Image\ImageUnlinkedLens;
use App\Nova\Resources\BaseResource;
use App\Nova\Resources\List\Playlist;
Expand Down Expand Up @@ -227,6 +228,32 @@ protected function fileProperties(): array
];
}

/**
* Get the actions available for the resource.
*
* @param NovaRequest $request
* @return array
*/
public function actions(NovaRequest $request): array
{
$facets = [
ImageFacet::GRILL,
ImageFacet::DOCUMENT,
];

return array_merge(
parent::actions($request),
[
(new AttachImageAction($facets))
->confirmButtonText(__('nova.actions.models.wiki.attach_image.confirmButtonText'))
->cancelButtonText(__('nova.actions.base.cancelButtonText'))
->onlyOnIndex()
->standalone()
->canSeeWhen('create', ImageModel::class),
]
);
}

/**
* Get the lenses available for the resource.
*
Expand Down
1 change: 1 addition & 0 deletions app/Nova/Resources/Wiki/Studio.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public function actions(NovaRequest $request): array
];

$facets = [
ImageFacet::COVER_SMALL,
ImageFacet::COVER_LARGE,
];

Expand Down
Loading

0 comments on commit 99153cb

Please sign in to comment.