From 86bf145fa307acca6f894262ee1805206937ed9f Mon Sep 17 00:00:00 2001 From: Dominik Prabucki Date: Fri, 6 Sep 2024 14:12:19 +0200 Subject: [PATCH 001/199] Add invite vue, controller, resource for admin panel --- app/Http/Controllers/InviteController.php | 20 +++++++++++++++ app/Http/Resources/InviteResource.php | 27 ++++++++++++++++++++ resources/js/Layouts/AdminLayout.vue | 1 + resources/js/Pages/Admin/Invite.vue | 31 +++++++++++++++++++++++ resources/js/Types/Invite.d.ts | 8 ++++++ routes/web.php | 3 +++ 6 files changed, 90 insertions(+) create mode 100644 app/Http/Controllers/InviteController.php create mode 100644 app/Http/Resources/InviteResource.php create mode 100644 resources/js/Pages/Admin/Invite.vue create mode 100644 resources/js/Types/Invite.d.ts diff --git a/app/Http/Controllers/InviteController.php b/app/Http/Controllers/InviteController.php new file mode 100644 index 00000000..da3a720f --- /dev/null +++ b/app/Http/Controllers/InviteController.php @@ -0,0 +1,20 @@ +role("user")->with("school")->orderBy("id")->get(); + return Inertia::render("Admin/Invite",[ + "users" => UserResource::collection($users), + ]); + } +} diff --git a/app/Http/Resources/InviteResource.php b/app/Http/Resources/InviteResource.php new file mode 100644 index 00000000..c19239e9 --- /dev/null +++ b/app/Http/Resources/InviteResource.php @@ -0,0 +1,27 @@ + + */ + public function toArray(Request $request): array + { + return [ + "user" => [ + "id" => $this->user->id, + "name" => $this->user->name, + "surname" => $this->user->surname, + "school" => $this->user->school, + ], + "points" => $this->points, + ]; + } +} diff --git a/resources/js/Layouts/AdminLayout.vue b/resources/js/Layouts/AdminLayout.vue index c4550ae6..56d0757d 100644 --- a/resources/js/Layouts/AdminLayout.vue +++ b/resources/js/Layouts/AdminLayout.vue @@ -10,6 +10,7 @@ const pages: Page[] = [ { title: 'Testy', href: '/admin/quizzes' }, { title: 'Szkoły', href: '/admin/schools' }, { title: 'Uczniowie', href: '/admin/users' }, + { title: 'Zapraszanie', href: '/admin/invite' }, ] if (props.user?.isSuperAdmin) { diff --git a/resources/js/Pages/Admin/Invite.vue b/resources/js/Pages/Admin/Invite.vue new file mode 100644 index 00000000..69520d0d --- /dev/null +++ b/resources/js/Pages/Admin/Invite.vue @@ -0,0 +1,31 @@ + + + diff --git a/resources/js/Types/Invite.d.ts b/resources/js/Types/Invite.d.ts new file mode 100644 index 00000000..558a975c --- /dev/null +++ b/resources/js/Types/Invite.d.ts @@ -0,0 +1,8 @@ +import {type School} from '@/Types/School' + +export interface Invite { + id: number + name: string | null + surname: string | null + school: School +} diff --git a/routes/web.php b/routes/web.php index d8c0f025..de365f61 100644 --- a/routes/web.php +++ b/routes/web.php @@ -7,6 +7,7 @@ use App\Http\Controllers\AuthenticateSessionController; use App\Http\Controllers\ContestController; use App\Http\Controllers\EmailVerifyController; +use App\Http\Controllers\InviteController; use App\Http\Controllers\PasswordResetLinkController; use App\Http\Controllers\ProfileUserController; use App\Http\Controllers\QuestionAnswerController; @@ -83,6 +84,8 @@ Route::get("/users/{user}/edit", [UserController::class, "edit"])->name("admin.users.edit"); Route::patch("/users/{user}", [UserController::class, "update"])->name("admin.users.update"); + Route::get("/invite", [InviteController::class, "index"])->name("admin.invite.index"); + Route::middleware(["role:super_admin"])->group(function (): void { Route::get("/admins", [AdminController::class, "index"])->name("admin.admins.index"); Route::get("/admins/create", [AdminController::class, "create"])->name("admin.admins.create"); From 656d05363a8c5ae28c26b25c01b7b15013040f68 Mon Sep 17 00:00:00 2001 From: Dominik Prabucki Date: Fri, 6 Sep 2024 14:12:30 +0200 Subject: [PATCH 002/199] fix code style --- app/Http/Controllers/InviteController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/InviteController.php b/app/Http/Controllers/InviteController.php index da3a720f..a7fd709a 100644 --- a/app/Http/Controllers/InviteController.php +++ b/app/Http/Controllers/InviteController.php @@ -1,5 +1,7 @@ role("user")->with("school")->orderBy("id")->get(); - return Inertia::render("Admin/Invite",[ + + return Inertia::render("Admin/Invite", [ "users" => UserResource::collection($users), ]); } From 3fd3a2f498da432c5cdd38c264984533feef6f6d Mon Sep 17 00:00:00 2001 From: Dominik Prabucki Date: Mon, 9 Sep 2024 10:59:00 +0200 Subject: [PATCH 003/199] add pagination --- app/Http/Controllers/InviteController.php | 4 ++-- resources/js/Pages/Admin/Invite.vue | 13 ++++++++---- resources/js/Types/Pagination.d.ts | 26 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 resources/js/Types/Pagination.d.ts diff --git a/app/Http/Controllers/InviteController.php b/app/Http/Controllers/InviteController.php index a7fd709a..de04239c 100644 --- a/app/Http/Controllers/InviteController.php +++ b/app/Http/Controllers/InviteController.php @@ -14,10 +14,10 @@ class InviteController extends Controller { public function index(Request $request): Response { - $users = User::query()->role("user")->with("school")->orderBy("id")->get(); + $users = User::query()->role("user")->with("school")->orderBy("id"); return Inertia::render("Admin/Invite", [ - "users" => UserResource::collection($users), + "users" => UserResource::collection($users->paginate(100)), ]); } } diff --git a/resources/js/Pages/Admin/Invite.vue b/resources/js/Pages/Admin/Invite.vue index 69520d0d..8a6af041 100644 --- a/resources/js/Pages/Admin/Invite.vue +++ b/resources/js/Pages/Admin/Invite.vue @@ -1,12 +1,14 @@ diff --git a/resources/js/Types/Pagination.d.ts b/resources/js/Types/Pagination.d.ts new file mode 100644 index 00000000..d04bfe34 --- /dev/null +++ b/resources/js/Types/Pagination.d.ts @@ -0,0 +1,26 @@ +export interface PaginationLink { + active: boolean + label: string + url?: string +} + + +export interface Pagination { + data: T[] + links: { + first: string + last: string + next?: string + prev?: string + } + meta: { + current_page: number + from: number + last_pag: number + path: string + per_page: number + to: number + total: number + links: PaginationLink[] + } +} From 0a2ffbc9368de2fbb2a94e9fb92658938da20056 Mon Sep 17 00:00:00 2001 From: Dominik Prabucki Date: Mon, 9 Sep 2024 12:47:36 +0200 Subject: [PATCH 004/199] Move logic to quiz --- app/Http/Controllers/InviteController.php | 5 +++-- resources/js/Layouts/AdminLayout.vue | 1 - resources/js/Pages/Admin/Invite.vue | 9 +++++++-- routes/web.php | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/InviteController.php b/app/Http/Controllers/InviteController.php index de04239c..c7e56dcc 100644 --- a/app/Http/Controllers/InviteController.php +++ b/app/Http/Controllers/InviteController.php @@ -5,19 +5,20 @@ namespace App\Http\Controllers; use App\Http\Resources\UserResource; +use App\Models\Quiz; use App\Models\User; -use Illuminate\Http\Request; use Inertia\Inertia; use Inertia\Response; class InviteController extends Controller { - public function index(Request $request): Response + public function index(Quiz $quiz): Response { $users = User::query()->role("user")->with("school")->orderBy("id"); return Inertia::render("Admin/Invite", [ "users" => UserResource::collection($users->paginate(100)), + "quiz" => $quiz, ]); } } diff --git a/resources/js/Layouts/AdminLayout.vue b/resources/js/Layouts/AdminLayout.vue index 56d0757d..c4550ae6 100644 --- a/resources/js/Layouts/AdminLayout.vue +++ b/resources/js/Layouts/AdminLayout.vue @@ -10,7 +10,6 @@ const pages: Page[] = [ { title: 'Testy', href: '/admin/quizzes' }, { title: 'Szkoły', href: '/admin/schools' }, { title: 'Uczniowie', href: '/admin/users' }, - { title: 'Zapraszanie', href: '/admin/invite' }, ] if (props.user?.isSuperAdmin) { diff --git a/resources/js/Pages/Admin/Invite.vue b/resources/js/Pages/Admin/Invite.vue index 8a6af041..0d66e6fc 100644 --- a/resources/js/Pages/Admin/Invite.vue +++ b/resources/js/Pages/Admin/Invite.vue @@ -1,13 +1,18 @@