Skip to content

Commit

Permalink
Merge branch 'inviting-to-quizzes-frontend' of https://github.com/blu…
Browse files Browse the repository at this point in the history
…milksoftware/interns2024b into inviting-to-quizzes-frontend
  • Loading branch information
JokeUrSelf committed Dec 19, 2024
2 parents d30a6e3 + f5836cf commit 6647457
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
30 changes: 10 additions & 20 deletions app/Http/Controllers/InviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use App\Actions\UnassignFromQuizAction;
use App\Helpers\SortHelper;
use App\Http\Requests\InviteQuizRequest;
use App\Http\Resources\QuizResource;
use App\Http\Resources\UserResource;
use App\Models\Quiz;
use App\Models\School;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\RedirectResponse;
Expand All @@ -31,9 +31,17 @@ public function index(Quiz $quiz, SortHelper $sort, Request $request): Response
$query = $this->filterByMode($query, $request);
$query = $this->filterBySchool($query, $request);

$quizzes = Quiz::query()
->select("id", "title")
->whereNotNull("scheduled_at")
->where("scheduled_at", ">", now())
->whereNotNull("locked_at")
->get();

return Inertia::render("Admin/Invite", [
"users" => UserResource::collection($sort->paginate($query)),
"quiz" => $quiz,
"quiz" => QuizResource::make($quiz),
"quizzes" => $quizzes,
"assigned" => $quiz->assignedUsers->pluck("id"),
]);
}
Expand All @@ -60,24 +68,6 @@ public function unassign(Quiz $quiz, InviteQuizRequest $request, UnassignFromQui
->with("status", "Użytkownicy zostali wypisani z testu.");
}

protected function groupBySchool(Builder $query, Request $request): Builder
{
$groupBySchool = $request->query("groupBySchool", "false");

if ($groupBySchool !== "true") {
return $query;
}

$schoolIds = School::query()
->select("id")
->join("users", "schools.id", "=", "users.school_id")
->groupBy("schools.id")
->orderBy("schools.id")
->pluck("id");

return $query->whereIn("school_id", $schoolIds)->orderBy("school_id");
}

private function filterByMode(Builder $query, Request $request)
{
$mode = $request->query("mode", "user");
Expand Down
6 changes: 3 additions & 3 deletions database/seeders/AdminSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function run(): void
"firstname" => "Example",
"surname" => "Super Admin",
"email_verified_at" => Carbon::now(),
"password" => Hash::make("interns2024b"),
"password" => Hash::make("password"),
"remember_token" => Str::random(10),
"school_id" => $school->id,
],
Expand All @@ -48,7 +48,7 @@ public function run(): void
"firstname" => "Example",
"surname" => "Admin",
"email_verified_at" => Carbon::now(),
"password" => Hash::make("interns2024b"),
"password" => Hash::make("password"),
"remember_token" => Str::random(10),
"school_id" => $school->id,
],
Expand All @@ -61,7 +61,7 @@ public function run(): void
"firstname" => "Example",
"surname" => "User",
"email_verified_at" => Carbon::now(),
"password" => Hash::make("interns2024b"),
"password" => Hash::make("password"),
"remember_token" => Str::random(10),
"school_id" => School::factory()->create()->id,
],
Expand Down
43 changes: 32 additions & 11 deletions resources/js/Pages/Admin/Invite.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<script setup lang="ts">
import { ref } from 'vue'
import { Head } from '@inertiajs/vue3'
import { Head, router } from '@inertiajs/vue3'
import { type Errors } from '@inertiajs/core'
import { CheckIcon } from '@heroicons/vue/20/solid'
import { CheckCircleIcon, MinusCircleIcon } from '@heroicons/vue/24/outline'
import { CheckCircleIcon, MinusCircleIcon, UserPlusIcon } from '@heroicons/vue/24/outline'
import FormButton from '@/components/Common/FormButton.vue'
import CrudPage from '@/components/Crud/CrudPage.vue'
import Expand from '@/components/Common/Expand.vue'
import CustomCheckbox from '@/components/Common/CustomCheckbox.vue'
import { keysWrapper } from '@/Helpers/KeysManager'
import Dropdown from '@/components/Common/Dropdown.vue'
defineProps<{
errors: Errors
users: Pagination<User>
quiz: Quiz
assigned: number[]
quizzes: Array<{ id: number, title: string }>
}>()
const selectedUsers = ref<number[]>([])
Expand All @@ -32,23 +34,40 @@ const searchBarModes = keysWrapper([
{ text: 'Według uczniów', name: 'user' },
{ text: 'Według szkół', name: 'school' },
]) as Mode[]
function changeQuiz(id: number) {
router.get(`/admin/quizzes/${id}/invite`)
}
</script>

<template>
<Head title="Zaproszenia - Panel administracyjny" />

<div class="w-full bg-primary text-white text-center font-bold p-1">
Zaproszenie do testu {{ quiz.title }}
</div>


<CrudPage
:items="users"
:options="options"
:resource-name="`quizzes/${quiz.id}/invite`"
:search-bar-modes="searchBarModes"
>
<template #actions>
<Dropdown
pointer-position="left"
:options="quizzes.map(item => ({ key: item.id, text: item.title }))"
@option-click="(option: any) => changeQuiz(option.key)"
>
<div class="flex group items-center gap-2 p-2 hover:bg-primary/5 hover:text-primary rounded-lg duration-200 whitespace-nowrap">
<UserPlusIcon class="icon stroke-gray-800 group-hover:stroke-primary" />

<div class="flex text-gray-800 items-center">
Zaproś do
</div>

<span class="font-bold nowrap">
{{ quiz.title }}
</span>
</div>
</Dropdown>

<Expand class="hidden sm:block" />
</template>

Expand All @@ -60,8 +79,10 @@ const searchBarModes = keysWrapper([
@check="checked => checked ? selectedUsers = users.data.map(user => user.id) : selectedUsers = []"
/>

<span class="hidden md:block">
{{ selectedUsers.length > 0 ? 'Odznacz wszystkich' : 'Wybierz wszystkich' }}
<span class="hidden md:block cursor-pointer select-none">
{{
selectedUsers.length == 0 ? 'Zaznacz wszystkich' : users.data.every(user=>selectedUsers.includes(user.id)) ? 'Odznacz wszystkich' : 'Odznacz zaznaczonych'
}}
</span>
</label>

Expand All @@ -80,7 +101,7 @@ const searchBarModes = keysWrapper([
Przypisz zaznaczonych
</span>
</FormButton>

<FormButton
button-class="!font-medium"
text
Expand All @@ -105,7 +126,7 @@ const searchBarModes = keysWrapper([
>
<div class="flex gap-4">
<CustomCheckbox
:checked="selectedUsers.includes(item.id)"
:checked="selectedUsers.includes(item.id)"
@check="selectedUsers.includes(item.id) ? selectedUsers = selectedUsers.filter(id => id !== item.id) : selectedUsers.push(item.id)"
/>

Expand Down

0 comments on commit 6647457

Please sign in to comment.