Skip to content

Commit

Permalink
full support of per-album-copyright
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Apr 28, 2024
1 parent 7c1363e commit adefdd3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/Livewire/Components/Forms/Album/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use App\Models\Album as ModelsAlbum;
use App\Models\Extensions\BaseAlbum;
use App\Policies\AlbumPolicy;
use App\Rules\CopyrightRule;
use App\Rules\TitleRule;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
Expand All @@ -44,6 +45,7 @@ class Properties extends Component
public string $album_sorting_order = ''; // ! wired
public string $album_aspect_ratio = ''; // ! wired
public string $license = 'none'; // ! wired
public string $copyright = ''; // ! wired

/**
* This is the equivalent of the constructor for Livewire Components.
Expand All @@ -63,6 +65,7 @@ public function mount(BaseAlbum $album): void
$this->description = $album->description ?? '';
$this->photo_sorting_column = $album->photo_sorting?->column->value ?? '';
$this->photo_sorting_order = $album->photo_sorting?->order->value ?? '';
$this->copyright = $album->copyright ?? '';
if ($this->is_model_album) {
/** @var ModelsAlbum $album */
$this->license = $album->license->value;
Expand Down Expand Up @@ -94,6 +97,7 @@ public function submit(AlbumFactory $albumFactory): void
...SetPhotoSortingRuleSet::rules(),
...SetAlbumSortingRuleSet::rules(),
RequestAttribute::ALBUM_ASPECT_RATIO_ATTRIBUTE => ['present', 'nullable', new Enum(AspectRatioType::class)],
RequestAttribute::COPYRIGHT_ATTRIBUTE => ['present', 'nullable', new CopyrightRule()],
];

if (!$this->areValid($rules)) {
Expand All @@ -106,12 +110,17 @@ public function submit(AlbumFactory $albumFactory): void
$baseAlbum->title = $this->title;
$baseAlbum->description = $this->description;

$this->copyright = trim($this->copyright);

// Not super pretty but whatever.
$column = ColumnSortingPhotoType::tryFrom($this->photo_sorting_column);
$order = OrderSortingType::tryFrom($this->photo_sorting_order);
$photoSortingCriterion = $column === null ? null : new PhotoSortingCriterion($column->toColumnSortingType(), $order);
$baseAlbum->photo_sorting = $photoSortingCriterion;

// If left empty, we set to null
$baseAlbum->copyright = $this->copyright === '' ? null : $this->copyright;

if ($this->is_model_album) {
/** @var ModelsAlbum $baseAlbum */
$baseAlbum->license = LicenseType::from($this->license);
Expand Down
2 changes: 1 addition & 1 deletion app/Rules/CopyrightRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class CopyrightRule extends StringRule
{
public function __construct()
{
parent::__construct(false, 300);
parent::__construct(true, 300);
}
}
2 changes: 1 addition & 1 deletion resources/views/components/gallery/album/details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@endif
@if($this->AlbumFormatted->copyright !== null && $this->AlbumFormatted->copyright !== '')
<span class="block text-text-main-200 text-sm">
{{ $this->AlbumFormatted->copyright }}
{{ __('lychee.ALBUM_COPYRIGHT') }} {{ $this->AlbumFormatted->copyright }}
</span>
@endif
@if($this->num_albums > 0)
Expand Down
5 changes: 5 additions & 0 deletions resources/views/livewire/forms/album/properties.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<span class="font-bold">{{ __('lychee.ALBUM_SET_LICENSE') }}</span>
<x-forms.dropdown class="mx-2" :options="$this->licenses" id="license_dialog_select" wire:model='license'/>
</div>
<div class="mb-4 flex">
<span class="inline-block font-bold shrink-0 pr-2">{{ __('lychee.ALBUM_SET_COPYRIGHT') }}:</span>
<x-forms.inputs.text class="-mt-1 w-full" wire:model='copyright' id="copyright" />
<x-forms.error-message field='copyright' />
</div>
<div class="h-10">
<span class="font-bold">Set album thumbs aspect ratio</span>
<x-forms.dropdown class="mx-2" :options="$this->aspectRatios" id="aspect_ratio_dialog_select" wire:model='album_aspect_ratio'/>
Expand Down
26 changes: 26 additions & 0 deletions tests/Livewire/Forms/Album/PropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Tests\Livewire\Forms\Album;

use App\Livewire\Components\Forms\Album\Properties;
use App\Models\Album;
use Livewire\Livewire;
use Tests\Livewire\Base\BaseLivewireTest;

Expand Down Expand Up @@ -40,4 +41,29 @@ public function testPropertiesLoggedIn(): void
->assertOk()
->assertNotDispatched('notify', self::notifySuccess());
}

public function testSetCopyright(): void
{
Livewire::actingAs($this->admin)->test(Properties::class, ['album' => $this->album1])
->assertOk()
->assertViewIs('livewire.forms.album.properties')
->set('copyright', 'something')
->call('submit')
->assertOk()
->assertDispatched('notify', self::notifySuccess());

$copyright = Album::findOrFail($this->album1->id)->copyright;

Check failure on line 55 in tests/Livewire/Forms/Album/PropertiesTest.php

View workflow job for this annotation

GitHub Actions / 2️⃣ PHP 8.2 - PHPStan

Access to an undefined property Illuminate\Database\Eloquent\Model::$copyright.
$this->assertEquals('something', $copyright);

Livewire::actingAs($this->admin)->test(Properties::class, ['album' => $this->album1])
->assertOk()
->assertViewIs('livewire.forms.album.properties')
->set('copyright', '')
->call('submit')
->assertOk()
->assertDispatched('notify', self::notifySuccess());

$copyright = Album::findOrFail($this->album1->id)->copyright;

Check failure on line 66 in tests/Livewire/Forms/Album/PropertiesTest.php

View workflow job for this annotation

GitHub Actions / 2️⃣ PHP 8.2 - PHPStan

Access to an undefined property Illuminate\Database\Eloquent\Model::$copyright.
$this->assertEquals(null, $copyright);
}
}

0 comments on commit adefdd3

Please sign in to comment.