From c95b02db71d5ff60ad085c4c2d07a88d10c34543 Mon Sep 17 00:00:00 2001 From: Kamil Date: Fri, 10 Nov 2023 10:29:02 +0100 Subject: [PATCH 01/15] #29 - grades page --- .../Controllers/Public/GradeController.php | 38 +++++++ resources/js/Pages/Public/Grade.vue | 102 ++++++++++++++++++ routes/web.php | 2 + 3 files changed, 142 insertions(+) create mode 100644 app/Http/Controllers/Public/GradeController.php create mode 100644 resources/js/Pages/Public/Grade.vue diff --git a/app/Http/Controllers/Public/GradeController.php b/app/Http/Controllers/Public/GradeController.php new file mode 100644 index 0000000..6e3f1e2 --- /dev/null +++ b/app/Http/Controllers/Public/GradeController.php @@ -0,0 +1,38 @@ +courses()->with("course")->get(); + } + + if ($course) { + $groups = $course->groups; + } + + return inertia("Public/Grade", [ + "semesters" => Semester::all(), + "semester" => $semester, + "courses" => $courses, + "course" => $course, + "groups" => $groups, + "group" => $group, + ]); + } +} diff --git a/resources/js/Pages/Public/Grade.vue b/resources/js/Pages/Public/Grade.vue new file mode 100644 index 0000000..856f56e --- /dev/null +++ b/resources/js/Pages/Public/Grade.vue @@ -0,0 +1,102 @@ + + + diff --git a/routes/web.php b/routes/web.php index 2c7c7bc..fc045f2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,6 +19,7 @@ use App\Http\Controllers\Dashboard\SemesterController; use App\Http\Controllers\Dashboard\SettingController; use App\Http\Controllers\Dashboard\StudentController; +use App\Http\Controllers\Public\GradeController as PublicGradeController; use App\Http\Controllers\Public\HomeController; use App\Http\Controllers\Public\LoginController; use App\Http\Controllers\Public\NewsController; @@ -26,6 +27,7 @@ Route::get("/", HomeController::class)->name("main"); Route::get("/aktualnosci", NewsController::class); +Route::get("/oceny/{semester?}/{course?}/{group?}", PublicGradeController::class); Route::middleware("guest")->group(function (): void { Route::get("/login", [LoginController::class, "create"])->name("login"); From d9698fcf9d700cb1eab8ccf1bb4290ac9cec687f Mon Sep 17 00:00:00 2001 From: Kamil Date: Fri, 10 Nov 2023 10:42:06 +0100 Subject: [PATCH 02/15] #29 - some fixes --- app/Http/Controllers/Public/GradeController.php | 2 +- resources/js/Pages/Public/Grade.vue | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Public/GradeController.php b/app/Http/Controllers/Public/GradeController.php index 6e3f1e2..624f808 100644 --- a/app/Http/Controllers/Public/GradeController.php +++ b/app/Http/Controllers/Public/GradeController.php @@ -13,7 +13,7 @@ class GradeController extends Controller { - public function __invoke(Request $request, ?Semester $semester, ?CourseSemester $course, ?Group $group): Response + public function __invoke(Request $request, ?Semester $semester = null, ?CourseSemester $course = null, ?Group $group = null): Response { $courses = []; $groups = []; diff --git a/resources/js/Pages/Public/Grade.vue b/resources/js/Pages/Public/Grade.vue index 856f56e..d5aec20 100644 --- a/resources/js/Pages/Public/Grade.vue +++ b/resources/js/Pages/Public/Grade.vue @@ -41,7 +41,7 @@ defineProps({
@@ -57,7 +57,7 @@ defineProps({
@@ -73,7 +73,7 @@ defineProps({
From bac8b79951f144ba07c32e4d9a9d74cbc6c0360b Mon Sep 17 00:00:00 2001 From: Kamil Date: Sun, 12 Nov 2023 22:08:12 +0100 Subject: [PATCH 03/15] #29 - show view of student grades --- .../Controllers/Public/GradeController.php | 50 +++++++++++++++++- resources/js/Pages/Public/Grade.vue | 51 +++++++++++++++++-- routes/web.php | 2 +- 3 files changed, 97 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Public/GradeController.php b/app/Http/Controllers/Public/GradeController.php index 624f808..620048a 100644 --- a/app/Http/Controllers/Public/GradeController.php +++ b/app/Http/Controllers/Public/GradeController.php @@ -6,17 +6,22 @@ use App\Http\Controllers\Controller; use App\Models\CourseSemester; +use App\Models\Grade; +use App\Models\GradeColumn; use App\Models\Group; use App\Models\Semester; +use App\Models\Student; use Illuminate\Http\Request; use Inertia\Response; class GradeController extends Controller { - public function __invoke(Request $request, ?Semester $semester = null, ?CourseSemester $course = null, ?Group $group = null): Response + public function __invoke(Request $request, ?Semester $semester = null, ?CourseSemester $course = null, ?Group $group = null, ?string $index = null): Response { $courses = []; $groups = []; + $gradeColumns = []; + $students = []; if ($semester) { $courses = $semester->courses()->with("course")->get(); @@ -26,6 +31,45 @@ public function __invoke(Request $request, ?Semester $semester = null, ?CourseSe $groups = $course->groups; } + if ($group) { + $gradeColumns = $group + ->gradeColumns() + ->where("active", true) + ->orderBy("priority") + ->get(); + $studentByIndex = $group->students() + ->where("index_number", $index) + ->first(); + $students = $group->students() + ->whereNot("index_number", $index) + ->inRandomOrder() + ->take(8) + ->get() + ->push($studentByIndex) + ->sortBy("index_number") + ->map(fn(Student $student): array => [ + "student" => $student->id === $studentByIndex->id ? $student->index_number : "", + "grades" => $gradeColumns + ->map(function (GradeColumn $column) use ($student): array { + /** @var Grade $grade */ + $grade = Grade::query() + ->where("grade_column_id", $column->id) + ->where("student_id", $student->id) + ->first(); + + return $grade + ? [ + "present" => $grade->status, + "value" => $grade->value, + ] + : [ + "present" => false, + "value" => null, + ]; + }), + ]); + } + return inertia("Public/Grade", [ "semesters" => Semester::all(), "semester" => $semester, @@ -33,6 +77,10 @@ public function __invoke(Request $request, ?Semester $semester = null, ?CourseSe "course" => $course, "groups" => $groups, "group" => $group, + "index" => $index, + "gradeColumns" => $gradeColumns, + "students" => $students, + "indexExists" => $studentByIndex->exists(), ]); } } diff --git a/resources/js/Pages/Public/Grade.vue b/resources/js/Pages/Public/Grade.vue index d5aec20..d01d928 100644 --- a/resources/js/Pages/Public/Grade.vue +++ b/resources/js/Pages/Public/Grade.vue @@ -4,9 +4,15 @@ import BackgroundGrid from '@/Components/BackgroundGrid.vue' import SectionHeader from '@/Components/SectionHeader.vue' import { Link } from '@inertiajs/inertia-vue3' import TextInput from '@/Shared/Forms/TextInput.vue' -import SubmitButton from '../../Shared/Components/Buttons/SubmitButton.vue' +import SubmitButton from '@/Shared/Components/Buttons/SubmitButton.vue' +import TableWrapper from '@/Shared/Components/Table/TableWrapper.vue' +import TableHeader from '@/Shared/Components/Table/TableHeader.vue' +import TableRow from '@/Shared/Components/Table/TableRow.vue' +import TableCell from '@/Shared/Components/Table/TableCell.vue' +import { Inertia } from '@inertiajs/inertia' +import { ref } from 'vue' -defineProps({ +const props = defineProps({ title: String, semesters: Array, semester: Object, @@ -14,7 +20,19 @@ defineProps({ course: Object, groups: Array, group: Object, + index: String, + gradeColumns: Array, + students: Array, + indexExists: Boolean, }) + +const index = ref(props.index) + +function getIndex() { + Inertia.get(`/oceny/${props.semester.id}/${props.course.id}/${props.group.id}/${index.value}`, {}, { + preserveScroll: true, + }) +}