From e53da7b39f954537aa1eccbc953458233b69a57a Mon Sep 17 00:00:00 2001 From: TLTimeplex Date: Sun, 29 Sep 2024 12:48:18 +0200 Subject: [PATCH 01/11] Init commit for #45 + Added gallery path to project --- .../Controllers/GALLERY/GalleryController.php | 15 +++++++++++++++ bootstrap/app.php | 4 ++++ resources/js/Pages/Gallery/Index.vue | 13 +++++++++++++ routes/gallery.php | 9 +++++++++ 4 files changed, 41 insertions(+) create mode 100644 app/Http/Controllers/GALLERY/GalleryController.php create mode 100644 resources/js/Pages/Gallery/Index.vue create mode 100644 routes/gallery.php diff --git a/app/Http/Controllers/GALLERY/GalleryController.php b/app/Http/Controllers/GALLERY/GalleryController.php new file mode 100644 index 00000000..153a7045 --- /dev/null +++ b/app/Http/Controllers/GALLERY/GalleryController.php @@ -0,0 +1,15 @@ +name('pos.auth.') ->middleware('web') ->group(base_path('routes/pos-auth.php')); + \Illuminate\Support\Facades\Route::prefix('gallery') + ->name('gallery.') + ->middleware('web') + ->group(base_path('routes/gallery.php')); } ) ->withMiddleware(function (Middleware $middleware) { diff --git a/resources/js/Pages/Gallery/Index.vue b/resources/js/Pages/Gallery/Index.vue new file mode 100644 index 00000000..f46fdda6 --- /dev/null +++ b/resources/js/Pages/Gallery/Index.vue @@ -0,0 +1,13 @@ + + + diff --git a/routes/gallery.php b/routes/gallery.php new file mode 100644 index 00000000..fb770871 --- /dev/null +++ b/routes/gallery.php @@ -0,0 +1,9 @@ +middleware('auth')->name('dashboard'); From 18c4fed9ea1d1e20130293ab516bcb0cc25cbef0 Mon Sep 17 00:00:00 2001 From: TLTimeplex Date: Wed, 2 Oct 2024 00:08:02 +0200 Subject: [PATCH 02/11] Added images to the gallery * Renamed page component to a more clear name + Added default route (May change later to QUERY) + Added custom db query to connect fursuits with the score + Added page separation for splitting the gallery + Added image details on click to show further information (currently only the score + For the "full" image view the user can now click in the detailed view on the image to resolve in the image_url * Modified responsibility to help mobile (Still wonky) --- .../Controllers/GALLERY/GalleryController.php | 57 +++++++++- resources/js/Components/GalleryItem.vue | 47 ++++++++ resources/js/Pages/Gallery/GalleryIndex.vue | 103 ++++++++++++++++++ resources/js/Pages/Gallery/Index.vue | 13 --- routes/gallery.php | 5 +- 5 files changed, 209 insertions(+), 16 deletions(-) create mode 100644 resources/js/Components/GalleryItem.vue create mode 100644 resources/js/Pages/Gallery/GalleryIndex.vue delete mode 100644 resources/js/Pages/Gallery/Index.vue diff --git a/app/Http/Controllers/GALLERY/GalleryController.php b/app/Http/Controllers/GALLERY/GalleryController.php index 153a7045..a692472a 100644 --- a/app/Http/Controllers/GALLERY/GalleryController.php +++ b/app/Http/Controllers/GALLERY/GalleryController.php @@ -3,13 +3,66 @@ namespace App\Http\Controllers\GALLERY; use App\Http\Controllers\Controller; +use App\Models\FCEA\UserCatch; +use App\Models\Fursuit\Fursuit; +use Database\Factories\Fursuit\FursuitFactory; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; use Inertia\Inertia; class GalleryController extends Controller { - public function index() { - return Inertia::render('Gallery/Index'); + const IMAGES_PER_SITE = 3 * 3; // 10 rows with 3 images each // TODO: Reverse to 10 * 3 + + public function index(int $site, Request $request) + { + if ($site < 1) { + return redirect()->route('gallery.site', ['site' => 1]); + } + + // Get the number of images + $imageCount = Fursuit::query() + ->where('status', "approved") + ->where('published', true) + ->count(); + + $MAX_SITE = ceil($imageCount / self::IMAGES_PER_SITE); + + if ($site > $MAX_SITE) { + return redirect()->route('gallery.site', ['site' => $MAX_SITE]); + } + + $fursuits = Fursuit::query() + ->with('species') + ->where('status', "approved") + ->where('published', true) + ->withCount('catchedByUsers') + ->orderBy('catched_by_users_count', 'desc') + ->orderBy('name', 'asc') + ->offset(($site - 1) * self::IMAGES_PER_SITE) + ->limit(self::IMAGES_PER_SITE) + ->get(); + + if ($fursuits->isEmpty()) { + return redirect()->route('gallery.site', ['site' => 1]); + } + + + return Inertia::render('Gallery/GalleryIndex', [ + 'fursuit' => $fursuits + ->map(function ($fursuit) { + return [ + 'id' => $fursuit->id, + 'name' => $fursuit->name, + 'species' => $fursuit->species->name, + 'image' => $fursuit->image_url, + 'scoring' => $fursuit->catched_by_users_count, + ]; + }), + 'site' => $site, + 'maxSite' => $MAX_SITE, + ]); } } diff --git a/resources/js/Components/GalleryItem.vue b/resources/js/Components/GalleryItem.vue new file mode 100644 index 00000000..179227e2 --- /dev/null +++ b/resources/js/Components/GalleryItem.vue @@ -0,0 +1,47 @@ + + + + + + diff --git a/resources/js/Pages/Gallery/GalleryIndex.vue b/resources/js/Pages/Gallery/GalleryIndex.vue new file mode 100644 index 00000000..3584a0c6 --- /dev/null +++ b/resources/js/Pages/Gallery/GalleryIndex.vue @@ -0,0 +1,103 @@ + + + + + diff --git a/resources/js/Pages/Gallery/Index.vue b/resources/js/Pages/Gallery/Index.vue deleted file mode 100644 index f46fdda6..00000000 --- a/resources/js/Pages/Gallery/Index.vue +++ /dev/null @@ -1,13 +0,0 @@ - - - diff --git a/routes/gallery.php b/routes/gallery.php index fb770871..de384853 100644 --- a/routes/gallery.php +++ b/routes/gallery.php @@ -6,4 +6,7 @@ * CONTAINS ALL ROUTES FOR THE GALLERY */ -Route::get('/', [\App\Http\Controllers\GALLERY\GalleryController::class, 'index'])->middleware('auth')->name('dashboard'); +Route::get('/{site}', [\App\Http\Controllers\GALLERY\GalleryController::class, 'index'])->middleware('auth')->name('site'); + + +Route::redirect('/', '/gallery/1/')->name('index'); // TODO: Make Permanent From 99b9e0da51057d3b0f635aa209f8958b1d5652af Mon Sep 17 00:00:00 2001 From: TLTimeplex Date: Wed, 2 Oct 2024 14:49:45 +0200 Subject: [PATCH 03/11] Code Refactor + Pulled out Pagnation component * Put all related components into their own folder + Added ts interface for Fursuits --- .../js/Components/Gallery/GalleryItem.vue | 60 +++++++++++++ .../js/Components/Gallery/Pagination.vue | 49 +++++++++++ resources/js/Components/GalleryItem.vue | 47 ----------- resources/js/Pages/Gallery/GalleryIndex.vue | 84 +++++++++---------- 4 files changed, 149 insertions(+), 91 deletions(-) create mode 100644 resources/js/Components/Gallery/GalleryItem.vue create mode 100644 resources/js/Components/Gallery/Pagination.vue delete mode 100644 resources/js/Components/GalleryItem.vue diff --git a/resources/js/Components/Gallery/GalleryItem.vue b/resources/js/Components/Gallery/GalleryItem.vue new file mode 100644 index 00000000..9ef100af --- /dev/null +++ b/resources/js/Components/Gallery/GalleryItem.vue @@ -0,0 +1,60 @@ + + + + + + + diff --git a/resources/js/Components/Gallery/Pagination.vue b/resources/js/Components/Gallery/Pagination.vue new file mode 100644 index 00000000..5cfa373a --- /dev/null +++ b/resources/js/Components/Gallery/Pagination.vue @@ -0,0 +1,49 @@ + + + + + diff --git a/resources/js/Components/GalleryItem.vue b/resources/js/Components/GalleryItem.vue deleted file mode 100644 index 179227e2..00000000 --- a/resources/js/Components/GalleryItem.vue +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - diff --git a/resources/js/Pages/Gallery/GalleryIndex.vue b/resources/js/Pages/Gallery/GalleryIndex.vue index 3584a0c6..4d98a358 100644 --- a/resources/js/Pages/Gallery/GalleryIndex.vue +++ b/resources/js/Pages/Gallery/GalleryIndex.vue @@ -1,29 +1,37 @@ - - diff --git a/resources/js/Pages/Gallery/GalleryIndex.vue b/resources/js/Pages/Gallery/GalleryIndex.vue index bb60547a..67206f7e 100644 --- a/resources/js/Pages/Gallery/GalleryIndex.vue +++ b/resources/js/Pages/Gallery/GalleryIndex.vue @@ -7,7 +7,34 @@ import GalleryItem from "@/Components/Gallery/GalleryItem.vue"; import Pagination from "@/Components/Gallery/Pagination.vue"; import {Head, router} from '@inertiajs/vue3' import {ref} from "vue"; -import Fursuit from "../../../interface/Gallery/Fursuit"; + +/** + * API Item for the gallery used by the backend + * + * Fursuit interface for usage for the gallery items + */ +interface Fursuit { + /** + * Database ID of the fursuit + */ + id: number, + /** + * Name of the fursuit + */ + name: string, + /** + * Species of the fursuit + */ + species: string, + /** + * Image url of the fursuit (Temporary link) + */ + image: string, + /** + * Fursuit got caught X times + */ + scoring: number, +} defineOptions({layout: Layout}) From d4bcfb18a642c7efb21b5ca5f19074a1c5ac634f Mon Sep 17 00:00:00 2001 From: TLTimeplex Date: Wed, 2 Oct 2024 23:50:48 +0200 Subject: [PATCH 06/11] Added search function for fursuit name * Changed page change procedure to hold on the search term + Added Search bar + Added Counter for amount of fursuits in gallery (Currently counting only displayable) + Added the button for sorting (Not implemented yet ^^) - Removed unused logic in controller + Added db query to get the highest ranking users (Top 3) --- .../Controllers/GALLERY/GalleryController.php | 34 ++++++++++--- .../js/Components/Gallery/GalleryItem.vue | 2 +- resources/js/Pages/Gallery/GalleryIndex.vue | 49 +++++++++++++++++-- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/GALLERY/GalleryController.php b/app/Http/Controllers/GALLERY/GalleryController.php index a692472a..79fbd577 100644 --- a/app/Http/Controllers/GALLERY/GalleryController.php +++ b/app/Http/Controllers/GALLERY/GalleryController.php @@ -4,7 +4,9 @@ use App\Http\Controllers\Controller; use App\Models\FCEA\UserCatch; +use App\Models\FCEA\UserCatchRanking; use App\Models\Fursuit\Fursuit; +use App\Models\User; use Database\Factories\Fursuit\FursuitFactory; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -17,26 +19,32 @@ class GalleryController extends Controller public function index(int $site, Request $request) { + + $searchTerm = $request->input('s') ?? ""; + $search = "%" . $searchTerm . "%"; + if ($site < 1) { - return redirect()->route('gallery.site', ['site' => 1]); + return redirect()->route('gallery.site', ['site' => 1, 's' => $searchTerm]); } // Get the number of images $imageCount = Fursuit::query() ->where('status', "approved") ->where('published', true) + ->whereRaw('LOWER(name) LIKE ?', [$search]) ->count(); $MAX_SITE = ceil($imageCount / self::IMAGES_PER_SITE); - if ($site > $MAX_SITE) { - return redirect()->route('gallery.site', ['site' => $MAX_SITE]); + if ($site > $MAX_SITE && $imageCount > 0) { + return redirect()->route('gallery.site', ['site' => $MAX_SITE, 's' => $searchTerm]); } $fursuits = Fursuit::query() ->with('species') ->where('status', "approved") ->where('published', true) + ->whereRaw('LOWER(name) LIKE ?', [$search]) ->withCount('catchedByUsers') ->orderBy('catched_by_users_count', 'desc') ->orderBy('name', 'asc') @@ -44,10 +52,12 @@ public function index(int $site, Request $request) ->limit(self::IMAGES_PER_SITE) ->get(); - if ($fursuits->isEmpty()) { - return redirect()->route('gallery.site', ['site' => 1]); - } - + $topRankings = UserCatchRanking::query() + ->whereNotNull('user_id') + ->orderBy('rank', 'desc') + ->limit(3) + ->with('user') + ->get(); return Inertia::render('Gallery/GalleryIndex', [ 'fursuit' => $fursuits @@ -62,6 +72,16 @@ public function index(int $site, Request $request) }), 'site' => $site, 'maxSite' => $MAX_SITE, + 'ranking' => $topRankings + ->map(function ($ranking) { + return [ + 'user' => $ranking->user->name, + 'rank' => $ranking->rank, + 'catches' => $ranking->score, + ]; + }), + 'suiteAmount' => $imageCount, + 'search' => $searchTerm, ]); } diff --git a/resources/js/Components/Gallery/GalleryItem.vue b/resources/js/Components/Gallery/GalleryItem.vue index 59d7d305..cfecfee2 100644 --- a/resources/js/Components/Gallery/GalleryItem.vue +++ b/resources/js/Components/Gallery/GalleryItem.vue @@ -6,7 +6,7 @@ const props = defineProps({