diff --git a/app/Livewire/Components/Modules/Jobs/Feedback.php b/app/Livewire/Components/Modules/Jobs/Feedback.php index 9348281abe..1b9819cc87 100644 --- a/app/Livewire/Components/Modules/Jobs/Feedback.php +++ b/app/Livewire/Components/Modules/Jobs/Feedback.php @@ -30,7 +30,7 @@ public function mount(): void } $this->open = Configs::getValueAsBool('current_job_processing_visible'); - $this->display = true; + $this->display = Configs::getValueAsBool('job_processing_queue_visible'); } /** diff --git a/app/Livewire/Components/Pages/Gallery/Album.php b/app/Livewire/Components/Pages/Gallery/Album.php index effd8783c0..68de8f29a8 100644 --- a/app/Livewire/Components/Pages/Gallery/Album.php +++ b/app/Livewire/Components/Pages/Gallery/Album.php @@ -14,6 +14,7 @@ use App\Livewire\DTO\AlbumRights; use App\Livewire\DTO\Layouts; use App\Livewire\DTO\PhotoFlags; +use App\Livewire\DTO\ProtectedCollection; use App\Livewire\DTO\SessionFlags; use App\Models\Album as ModelsAlbum; use App\Models\Configs; @@ -24,7 +25,6 @@ use App\Policies\AlbumPolicy; use App\Policies\PhotoPolicy; use Illuminate\Database\Eloquent\RelationNotFoundException; -use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Gate; use Illuminate\View\View; @@ -41,6 +41,7 @@ class Album extends BaseAlbumComponent implements Reloadable { private AlbumFactory $albumFactory; + private AlbumFormatted $formatted; #[Locked] public bool $is_search_accessible = false; public ?AbstractAlbum $album = null; @@ -54,6 +55,8 @@ public function boot(): void { $this->albumFactory = resolve(AlbumFactory::class); $this->layouts = new Layouts(); + $this->albumsCollection = new ProtectedCollection(type: 'album'); + $this->photosCollection = new ProtectedCollection(type: 'photo'); } public function mount(string $albumId, string $photoId = ''): void @@ -74,18 +77,28 @@ final public function render(): View { $this->sessionFlags = SessionFlags::get(); $this->rights = AlbumRights::make($this->album); + $this->num_albums = 0; + $this->num_albums = 0; if ($this->flags->is_accessible) { + $this->formatted = new AlbumFormatted($this->album, $this->fetchHeaderUrl()?->url); $this->num_users = User::count(); - $this->header_url ??= $this->fetchHeaderUrl()?->url; - $this->num_albums = $this->album instanceof ModelsAlbum ? $this->album->children->count() : 0; - $this->num_photos = $this->album->photos->count(); + + $this->photosCollection->set($this->album->photos); + $this->num_photos = $this->photosCollection->get()->count(); // No photos, no frame if ($this->num_photos === 0) { $this->flags->is_mod_frame_enabled = false; } + if ($this->album instanceof ModelsAlbum) { + $this->albumsCollection->set($this->album->children()->getResults()); + $this->num_albums = $this->albumsCollection->get()->count(); + } else { + $this->albumsCollection->set(null); + } + $is_latitude_longitude_found = false; if ($this->album instanceof ModelsAlbum) { $is_latitude_longitude_found = $this->album->all_photos()->whereNotNull('latitude')->whereNotNull('longitude')->count() > 0; @@ -103,6 +116,9 @@ final public function render(): View can_rotate: Configs::getValueAsBool('editor_enabled'), can_edit: $this->rights->can_edit, ); + } else { + $this->albumsCollection->set(null); + $this->photosCollection->set(collect([])); } return view('livewire.pages.gallery.album'); @@ -133,41 +149,6 @@ public function reloadPage(): void } } - /** - * Return the photoIDs. - * - * @return Collection - */ - public function getPhotosProperty(): Collection - { - return $this->album->photos; - } - - /** - * @return Collection|null - */ - public function getAlbumsProperty(): Collection|null - { - if ($this->album instanceof ModelsAlbum) { - /** @var Collection $res */ - $res = $this->album->children()->getResults(); - - return $res; - } - - return null; - } - - /** - * Used in the JS front-end to manage the selected albums. - * - * @return string[] - */ - public function getAlbumIDsProperty(): array - { - return $this->getAlbumsProperty()?->map(fn ($v, $k) => $v->id)?->all() ?? []; - } - /** * Fetch the header url. * @@ -282,7 +263,7 @@ public function setAsCover(string $albumID): void public function getAlbumFormattedProperty(): AlbumFormatted { - return new AlbumFormatted($this->album, $this->fetchHeaderUrl()?->url); + return $this->formatted; } public function getNoImagesAlbumsMessageProperty(): string diff --git a/app/Livewire/Components/Pages/Gallery/Albums.php b/app/Livewire/Components/Pages/Gallery/Albums.php index ec7719e959..ddaa2a5a60 100644 --- a/app/Livewire/Components/Pages/Gallery/Albums.php +++ b/app/Livewire/Components/Pages/Gallery/Albums.php @@ -87,7 +87,6 @@ public function getSmartAlbumsProperty(): Collection { return $this->topAlbums->smart_albums ->concat($this->topAlbums->tag_albums); - // ->reject(fn ($album) => $album === null); } /** diff --git a/app/Livewire/Components/Pages/Gallery/BaseAlbumComponent.php b/app/Livewire/Components/Pages/Gallery/BaseAlbumComponent.php index c17c2ca8ed..c92235a6ec 100644 --- a/app/Livewire/Components/Pages/Gallery/BaseAlbumComponent.php +++ b/app/Livewire/Components/Pages/Gallery/BaseAlbumComponent.php @@ -11,6 +11,7 @@ use App\Livewire\DTO\AlbumRights; use App\Livewire\DTO\Layouts; use App\Livewire\DTO\PhotoFlags; +use App\Livewire\DTO\ProtectedCollection; use App\Livewire\DTO\SessionFlags; use App\Livewire\Traits\AlbumsPhotosContextMenus; use App\Livewire\Traits\Notify; @@ -41,9 +42,14 @@ abstract class BaseAlbumComponent extends Component protected Layouts $layouts; + /** @var ProtectedCollection */ + protected ?ProtectedCollection $albumsCollection; + + /** @var ProtectedCollection<\App\Models\Photo> */ + protected ?ProtectedCollection $photosCollection; + #[Locked] public ?string $albumId = null; #[Locked] public ?string $photoId = null; - #[Locked] public ?string $header_url = null; #[Locked] public int $num_albums = 0; #[Locked] public int $num_photos = 0; #[Locked] public int $num_users = 0; @@ -74,21 +80,30 @@ final public function getPhotosResourceProperty(): PhotoCollectionResource * * @return Collection|LengthAwarePaginator */ - abstract public function getPhotosProperty(): Collection|LengthAwarePaginator; + public function getPhotosProperty(): Collection|LengthAwarePaginator + { + return $this->photosCollection->get(); + } /** * Return the albums. * * @return Collection|null */ - abstract public function getAlbumsProperty(): Collection|null; + final public function getAlbumsProperty(): Collection|null + { + return $this->albumsCollection->get(); + } /** * Used in the JS front-end to manage the selected albums. * * @return string[] */ - abstract public function getAlbumIDsProperty(): array; + final public function getAlbumIDsProperty(): array + { + return $this->albumsCollection->get()?->map(fn ($v, $_k) => $v->id)?->all() ?? []; + } /** * Back property used to retrieve the URL to step back and back arrow. diff --git a/app/Livewire/Components/Pages/Gallery/Search.php b/app/Livewire/Components/Pages/Gallery/Search.php index ba3fe6098b..39e9c78e90 100644 --- a/app/Livewire/Components/Pages/Gallery/Search.php +++ b/app/Livewire/Components/Pages/Gallery/Search.php @@ -11,6 +11,7 @@ use App\Livewire\DTO\AlbumRights; use App\Livewire\DTO\Layouts; use App\Livewire\DTO\PhotoFlags; +use App\Livewire\DTO\ProtectedCollection; use App\Livewire\DTO\SessionFlags; use App\Models\Album as ModelsAlbum; use App\Models\Configs; @@ -35,8 +36,6 @@ class Search extends BaseAlbumComponent /** @var LengthAwarePaginator */ private LengthAwarePaginator $photos; - /** @var Collection */ - private Collection $albums; #[Locked] #[Url(history: true)] @@ -56,8 +55,9 @@ public function boot(): void $this->layouts = new Layouts(); $this->albumSearch = resolve(AlbumSearch::class); $this->photoSearch = resolve(PhotoSearch::class); + $this->albumsCollection = new ProtectedCollection(type: 'album', is_loaded: true, collection: collect([])); + $this->photosCollection = new ProtectedCollection(type: 'photo'); $this->photos = new LengthAwarePaginator([], 0, 200); - $this->albums = collect([]); $this->num_albums = 0; $this->num_photos = 0; $this->search_minimum_length_required = Configs::getValueAsInt('search_minimum_length_required'); @@ -127,14 +127,14 @@ public function render(): View ->paginate(Configs::getValueAsInt('search_pagination_limit')) ->withQueryString(); $this->photos = $photoResults; - /** @var Collection $albumResults */ $albumResults = $this->albumSearch->queryAlbums($this->terms); - $this->albums = $albumResults; - $this->num_albums = $this->albums->count(); + $this->albumsCollection->set($albumResults); + $this->num_albums = $this->albumsCollection->get()->count(); $this->num_photos = $this->photos->count(); $this->albumId = ''; $this->photoId = ''; } + /** @var Collection $albumResults */ return view('livewire.pages.gallery.search'); } @@ -149,16 +149,6 @@ public function getPhotosProperty(): Collection return collect($this->photos->items()); } - public function getAlbumsProperty(): ?Collection - { - return $this->albums; - } - - public function getAlbumIDsProperty(): array - { - return $this->albums->map(fn ($v, $k) => $v->id)->all(); - } - // For now, simple public function getBackProperty(): string { diff --git a/app/Livewire/DTO/ProtectedCollection.php b/app/Livewire/DTO/ProtectedCollection.php new file mode 100644 index 0000000000..0939188005 --- /dev/null +++ b/app/Livewire/DTO/ProtectedCollection.php @@ -0,0 +1,52 @@ +|null $collection + * + * @return void + */ + public function __construct( + private string $type, + private bool $is_loaded = false, + private ?Collection $collection = null, + ) { + } + + /** + * @return Collection|null collection encapsulated + * + * @throws LycheeLogicException we queried it too early + */ + public function get(): Collection|null + { + if ($this->is_loaded) { + return $this->collection; + } + + throw new LycheeLogicException(sprintf('Collection %s data is not available.', $this->type)); + } + + /** + * Set the collection. + * + * @param Collection|null $collection + * + * @return void + */ + public function set(Collection|null $collection) + { + $this->is_loaded = true; + $this->collection = $collection; + } +} \ No newline at end of file diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 1fe8ea9a89..376958767d 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -121,6 +121,7 @@ public function boot() try { $lang = Configs::getValueAsString('lang'); + /** @disregard P1013 Undefined method setLocale() (stupid intelephense) */ app()->setLocale($lang); } catch (\Throwable $e) { /** Ignore. diff --git a/database/migrations/2024_06_08_093403_primary_key_job_history.php b/database/migrations/2024_06_08_093403_primary_key_job_history.php new file mode 100644 index 0000000000..56acd46e22 --- /dev/null +++ b/database/migrations/2024_06_08_093403_primary_key_job_history.php @@ -0,0 +1,25 @@ +index(['owner_id', 'status']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // We cannot remove index key because owner_id is used for FK constraint. + } +}; diff --git a/database/migrations/2024_06_08_103842_add_config_display_processing_queue.php b/database/migrations/2024_06_08_103842_add_config_display_processing_queue.php new file mode 100644 index 0000000000..64e481ef76 --- /dev/null +++ b/database/migrations/2024_06_08_103842_add_config_display_processing_queue.php @@ -0,0 +1,22 @@ + 'job_processing_queue_visible', + 'value' => '1', + 'is_secret' => false, + 'cat' => self::PROCESSING, + 'type_range' => self::BOOL, + 'description' => 'Enable the processing queue in the bottom left corner.', + ], + ]; + } +}; diff --git a/resources/views/livewire/forms/album/properties.blade.php b/resources/views/livewire/forms/album/properties.blade.php index a94c1a12c3..046726af8d 100644 --- a/resources/views/livewire/forms/album/properties.blade.php +++ b/resources/views/livewire/forms/album/properties.blade.php @@ -21,7 +21,7 @@ - +
{{ __('lychee.ALBUM_SET_LICENSE') }}