diff --git a/app/Console/Commands/CacheImageInfo.php b/app/Console/Commands/CacheImageInfo.php new file mode 100644 index 00000000..379d2ec7 --- /dev/null +++ b/app/Console/Commands/CacheImageInfo.php @@ -0,0 +1,27 @@ +withProgressBar(Artwork::active()->get(), function (Artwork $artwork) { + $this->damsImageService->getImage($artwork); + }); + } +} diff --git a/app/Console/Commands/CacheJsonCommand.php b/app/Console/Commands/CacheJsonCommand.php index f165da5c..44c81d47 100644 --- a/app/Console/Commands/CacheJsonCommand.php +++ b/app/Console/Commands/CacheJsonCommand.php @@ -42,12 +42,21 @@ public function handle() $this->themeRepository->active()->with( [ 'prompts' => fn (Builder $query) => $query->active(), - 'prompts.artworks' => fn (Builder $query) => $query->active()->limit(8), + 'prompts.artworks' => fn (Builder $query) => $query->active(), ] )->get() ), ]; + // Limit the number of artworks per prompt to 8 + // This can be removed once we upgrade to Laravel 11 + // https://github.com/laravel/framework/pull/49695 + foreach ($data['themes'] as $themeKey => $theme) { + foreach ($theme['prompts'] as $promptKey => $prompt) { + $data['themes'][$themeKey]['prompts'][$promptKey]['artworks'] = $prompt['artworks']->take(8); + } + } + Cache::put($key, json_encode($data)); }); } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index b440711b..b2cb4417 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -16,6 +16,10 @@ protected function schedule(Schedule $schedule): void ->command('app:cache-json') ->everyFiveMinutes() ->withoutOverlapping(); + + $schedule + ->command('app:cache-image-info') + ->daily(); } /** diff --git a/app/Http/Controllers/Twill/ThemeController.php b/app/Http/Controllers/Twill/ThemeController.php index 53884b99..2054cace 100644 --- a/app/Http/Controllers/Twill/ThemeController.php +++ b/app/Http/Controllers/Twill/ThemeController.php @@ -25,6 +25,8 @@ protected function setUpController(): void $this->disableBulkPublish(); $this->disableBulkRestore(); $this->disableBulkForceDelete(); + $this->disableSortable(); + $this->enableReorder(); } public function getCreateForm(): Form diff --git a/app/Http/Controllers/Twill/ThemePromptController.php b/app/Http/Controllers/Twill/ThemePromptController.php index 7fef4b2a..d224b5c9 100644 --- a/app/Http/Controllers/Twill/ThemePromptController.php +++ b/app/Http/Controllers/Twill/ThemePromptController.php @@ -30,6 +30,8 @@ protected function setUpController(): void $this->disableBulkPublish(); $this->disableBulkRestore(); $this->disableBulkForceDelete(); + $this->disableSortable(); + $this->enableReorder(); if (request('theme')) { $this->setBreadcrumbs( diff --git a/app/Models/Theme.php b/app/Models/Theme.php index 7c47c139..967d3bb8 100644 --- a/app/Models/Theme.php +++ b/app/Models/Theme.php @@ -91,6 +91,13 @@ class Theme extends Model implements Sortable ], ]; + protected static function booted(): void + { + static::addGlobalScope('order', function (Builder $builder) { + $builder->orderBy('position'); + }); + } + public function prompts() { return $this->hasMany(ThemePrompt::class); diff --git a/app/Models/ThemePrompt.php b/app/Models/ThemePrompt.php index 25e6c064..0f2a19eb 100644 --- a/app/Models/ThemePrompt.php +++ b/app/Models/ThemePrompt.php @@ -27,6 +27,13 @@ class ThemePrompt extends Model implements Sortable 'subtitle', ]; + protected static function booted(): void + { + static::addGlobalScope('order', function (Builder $builder) { + $builder->orderBy('position'); + }); + } + public function theme() { return $this->belongsTo(Theme::class); @@ -34,7 +41,7 @@ public function theme() public function artworks() { - return $this->hasMany(ThemePromptArtwork::class)->orderBy('position'); + return $this->hasMany(ThemePromptArtwork::class); } public function scopeActive(Builder $query): void diff --git a/app/Models/ThemePromptArtwork.php b/app/Models/ThemePromptArtwork.php index 47852889..aa512e66 100644 --- a/app/Models/ThemePromptArtwork.php +++ b/app/Models/ThemePromptArtwork.php @@ -31,6 +31,13 @@ class ThemePromptArtwork extends Model implements Sortable 'activity_instructions', ]; + protected static function booted(): void + { + static::addGlobalScope('order', function (Builder $builder) { + $builder->orderBy('position'); + }); + } + public function artwork() { return $this->belongsTo(Artwork::class); diff --git a/resources/views/forms/prompts.blade.php b/resources/views/forms/prompts.blade.php index 85f5a767..00972e9e 100644 --- a/resources/views/forms/prompts.blade.php +++ b/resources/views/forms/prompts.blade.php @@ -7,9 +7,17 @@ @endphp
-