Compare commits
8 Commits
8528a3258d
...
88286fe596
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88286fe596 | ||
|
|
4980ad95b3 | ||
|
|
a809307272 | ||
|
|
be0897ad6e | ||
|
|
2b7b4e2ab0 | ||
|
|
753e7735a7 | ||
|
|
fa4c4f37f3 | ||
|
|
53afdb1fec |
21
app/Enums/AssignmentStatus.php
Normal file
21
app/Enums/AssignmentStatus.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Enums\Concerns\HasValues;
|
||||
|
||||
enum AssignmentStatus: string
|
||||
{
|
||||
use HasValues;
|
||||
|
||||
case Open = 'open';
|
||||
case Closed = 'closed';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Open => 'Dibuka',
|
||||
self::Closed => 'Ditutup',
|
||||
};
|
||||
}
|
||||
}
|
||||
31
app/Enums/DayOfWeek.php
Normal file
31
app/Enums/DayOfWeek.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Enums\Concerns\HasValues;
|
||||
|
||||
enum DayOfWeek: string
|
||||
{
|
||||
use HasValues;
|
||||
|
||||
case Monday = 'Monday';
|
||||
case Tuesday = 'Tuesday';
|
||||
case Wednesday = 'Wednesday';
|
||||
case Thursday = 'Thursday';
|
||||
case Friday = 'Friday';
|
||||
case Saturday = 'Saturday';
|
||||
case Sunday = 'Sunday';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Monday => 'Senin',
|
||||
self::Tuesday => 'Selasa',
|
||||
self::Wednesday => 'Rabu',
|
||||
self::Thursday => 'Kamis',
|
||||
self::Friday => 'Jumat',
|
||||
self::Saturday => 'Sabtu',
|
||||
self::Sunday => 'Minggu',
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,7 @@
|
||||
use App\Models\Assignment;
|
||||
use App\Services\Admin\AcademicClasses\AssignmentService;
|
||||
use App\Services\Admin\Manage\CourseClassService;
|
||||
use App\Services\Admin\Master\AcademicTermService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
@ -17,17 +18,28 @@ class AssignmentController extends Controller
|
||||
public function __construct(
|
||||
private readonly AssignmentService $service,
|
||||
private readonly CourseClassService $courseClassService,
|
||||
private readonly AcademicTermService $academicTermService,
|
||||
) {}
|
||||
|
||||
public function index(PaginatedRequest $request): Response
|
||||
{
|
||||
$academicTermId = $request->has('academic_term_id')
|
||||
? $request->validated('academic_term_id')
|
||||
: $this->academicTermService->getActive()?->id;
|
||||
|
||||
return Inertia::render('admin/academic-classes/assignments/index', [
|
||||
'assignments' => $this->service->paginated(
|
||||
'assignments' => Inertia::scroll(fn () => $this->service->paginated(
|
||||
$request->user(),
|
||||
...$request->validatedWithDefaults(),
|
||||
courseClassId: $request->validated('course_class_id'),
|
||||
),
|
||||
'courseClasses' => $this->courseClassService->getAllForSelect(),
|
||||
'filters' => $request->only(['course_class_id']),
|
||||
academicTermId: $academicTermId,
|
||||
)),
|
||||
'courseClasses' => $this->courseClassService->getAllForSelect($request->user()),
|
||||
'academicTerms' => $this->academicTermService->getAllForSelect(),
|
||||
'filters' => [
|
||||
'course_class_id' => $request->validated('course_class_id'),
|
||||
'academic_term_id' => $academicTermId ? (string) $academicTermId : null,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -6,8 +6,9 @@
|
||||
use App\Http\Requests\Admin\AcademicClasses\AttendanceStoreRequest;
|
||||
use App\Models\CourseClass;
|
||||
use App\Services\Admin\AcademicClasses\AttendanceService;
|
||||
use App\Services\Admin\Manage\CourseClassService;
|
||||
use App\Services\Admin\Master\AcademicTermService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
@ -15,19 +16,52 @@ class AttendanceController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AttendanceService $service,
|
||||
private readonly CourseClassService $courseClassService,
|
||||
private readonly AcademicTermService $academicTermService,
|
||||
) {}
|
||||
|
||||
public function index(): Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$academicTermId = $request->has('academic_term_id')
|
||||
? $request->integer('academic_term_id')
|
||||
: $this->academicTermService->getActive()?->id;
|
||||
|
||||
return Inertia::render('admin/academic-classes/attendances/index', [
|
||||
'sessions' => $this->service->sessions(),
|
||||
'courseClasses' => $this->courseClassService->getAllForSelect(),
|
||||
'courseClasses' => $this->service->courseClassesForUser($request->user(), $academicTermId),
|
||||
'academicTerms' => $this->academicTermService->getAllForSelect(),
|
||||
'filters' => [
|
||||
'academic_term_id' => $academicTermId ? (string) $academicTermId : null,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function mine(Request $request): Response
|
||||
{
|
||||
$student = $request->user()->student;
|
||||
|
||||
abort_if(! $student, 403);
|
||||
|
||||
return Inertia::render('admin/academic-classes/attendances/mine', [
|
||||
'summaries' => $this->service->forStudent($student),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(CourseClass $courseClass): Response
|
||||
{
|
||||
$this->abortUnlessLecturerOwnsClass($courseClass);
|
||||
|
||||
$courseClass->load(['course', 'academicTerm']);
|
||||
|
||||
return Inertia::render('admin/academic-classes/attendances/course-class', [
|
||||
'courseClass' => $courseClass,
|
||||
'sessions' => $this->service->sessionsForClass($courseClass),
|
||||
'nextMeetingNumber' => $this->service->nextMeetingNumber($courseClass),
|
||||
]);
|
||||
}
|
||||
|
||||
public function session(CourseClass $courseClass, int $meetingNumber): Response
|
||||
{
|
||||
$this->abortUnlessLecturerOwnsClass($courseClass);
|
||||
|
||||
$courseClass->load('course');
|
||||
$data = $this->service->session($courseClass, $meetingNumber);
|
||||
|
||||
@ -50,10 +84,25 @@ public function store(AttendanceStoreRequest $request, CourseClass $courseClass,
|
||||
|
||||
public function destroy(CourseClass $courseClass, int $meetingNumber): RedirectResponse
|
||||
{
|
||||
$this->abortUnlessLecturerOwnsClass($courseClass);
|
||||
|
||||
$this->service->deleteSession($courseClass->id, $meetingNumber);
|
||||
|
||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Sesi kehadiran berhasil dihapus.']);
|
||||
|
||||
return to_route('admin.academic-classes.attendances.index');
|
||||
return to_route('admin.academic-classes.attendances.show', [$courseClass->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A dosen may only take or manage attendance for classes they lecture.
|
||||
*/
|
||||
private function abortUnlessLecturerOwnsClass(CourseClass $courseClass): void
|
||||
{
|
||||
$user = request()->user();
|
||||
|
||||
abort_if(
|
||||
$user->hasRole('dosen') && $courseClass->lecturer_id !== $user->lecturer?->id,
|
||||
403,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,10 +23,11 @@ public function index(PaginatedRequest $request): Response
|
||||
{
|
||||
return Inertia::render('admin/academic-classes/materials/index', [
|
||||
'materials' => $this->service->paginated(
|
||||
$request->user(),
|
||||
...$request->validatedWithDefaults(),
|
||||
courseClassId: $request->validated('course_class_id'),
|
||||
),
|
||||
'courseClasses' => $this->courseClassService->getAllForSelect(),
|
||||
'courseClasses' => $this->courseClassService->getAllForSelect($request->user()),
|
||||
'filters' => $request->only(['course_class_id']),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -4,9 +4,12 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\AcademicClasses\ScheduleRequest;
|
||||
use App\Http\Requests\PaginatedRequest;
|
||||
use App\Models\Schedule;
|
||||
use App\Services\Admin\AcademicClasses\ScheduleService;
|
||||
use App\Services\Admin\Manage\CourseClassService;
|
||||
use App\Services\Admin\Master\AcademicTermService;
|
||||
use App\Services\Admin\Master\CourseService;
|
||||
use App\Services\Admin\Master\DepartmentService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
@ -15,14 +18,37 @@ class ScheduleController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ScheduleService $service,
|
||||
private readonly CourseClassService $courseClassService,
|
||||
private readonly AcademicTermService $academicTermService,
|
||||
private readonly DepartmentService $departmentService,
|
||||
private readonly CourseService $courseService,
|
||||
) {}
|
||||
|
||||
public function index(): Response
|
||||
public function index(PaginatedRequest $request): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
$isPersonalView = $user->hasRole('mahasiswa') || $user->hasRole('dosen');
|
||||
|
||||
$academicTermId = $request->has('academic_term_id')
|
||||
? $request->validated('academic_term_id')
|
||||
: $this->academicTermService->getActive()?->id;
|
||||
|
||||
return Inertia::render('admin/academic-classes/schedules/index', [
|
||||
'schedules' => $this->service->all(),
|
||||
'courseClasses' => $this->courseClassService->getAllForSelect(),
|
||||
'schedules' => $this->service->all(
|
||||
$user,
|
||||
academicTermId: $academicTermId,
|
||||
departmentId: $request->validated('department_id'),
|
||||
semesterNumber: $request->validated('semester_number'),
|
||||
),
|
||||
'courseClasses' => $this->service->courseClassOptions(),
|
||||
'academicTerms' => $this->academicTermService->getAllForSelect(),
|
||||
'departments' => $this->departmentService->getAllForSelect(),
|
||||
'semesterNumbers' => $this->courseService->getSemesterNumbers(),
|
||||
'isPersonalView' => $isPersonalView,
|
||||
'filters' => [
|
||||
'academic_term_id' => $academicTermId ? (string) $academicTermId : null,
|
||||
'department_id' => $request->validated('department_id'),
|
||||
'semester_number' => $request->validated('semester_number'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
namespace App\Http\Controllers\Admin\AcademicClasses;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\AcademicClasses\SubmissionRequest;
|
||||
use App\Http\Requests\Admin\AcademicClasses\GradeSubmissionRequest;
|
||||
use App\Http\Requests\Admin\AcademicClasses\SubmitAssignmentRequest;
|
||||
use App\Models\Assignment;
|
||||
use App\Models\Submission;
|
||||
use App\Services\Admin\AcademicClasses\SubmissionService;
|
||||
@ -19,33 +20,42 @@ public function __construct(
|
||||
|
||||
public function index(Assignment $assignment): Response
|
||||
{
|
||||
$this->abortUnlessLecturerOwnsAssignment($assignment);
|
||||
|
||||
$assignment->load(['courseClass.course', 'courseClass.lecturer.user.profile', 'courseClass.academicTerm']);
|
||||
|
||||
return Inertia::render('admin/academic-classes/assignments/submissions', [
|
||||
'assignment' => $assignment,
|
||||
'submissions' => $this->service->forAssignment($assignment),
|
||||
'availableStudents' => $this->service->availableStudents($assignment),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(SubmissionRequest $request, Assignment $assignment): RedirectResponse
|
||||
public function grade(GradeSubmissionRequest $request, Assignment $assignment, Submission $submission): RedirectResponse
|
||||
{
|
||||
$this->service->create($assignment, $request->validated(), $request->file('file'));
|
||||
$this->service->grade($submission, $request->validated('score'));
|
||||
|
||||
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengumpulan berhasil ditambahkan.'])->back();
|
||||
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Nilai berhasil disimpan.'])->back();
|
||||
}
|
||||
|
||||
public function update(SubmissionRequest $request, Assignment $assignment, Submission $submission): RedirectResponse
|
||||
public function submit(SubmitAssignmentRequest $request, Assignment $assignment): RedirectResponse
|
||||
{
|
||||
$this->service->update($submission, $request->validated(), $request->file('file'));
|
||||
$this->service->submitForStudent($assignment, $request->user()->student, $request->validated(), $request->file('file'));
|
||||
|
||||
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengumpulan berhasil diperbarui.'])->back();
|
||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Tugas berhasil dikumpulkan.']);
|
||||
|
||||
return to_route('admin.academic-classes.assignments.index');
|
||||
}
|
||||
|
||||
public function destroy(Assignment $assignment, Submission $submission): RedirectResponse
|
||||
/**
|
||||
* A dosen may only manage submissions for classes they lecture.
|
||||
*/
|
||||
private function abortUnlessLecturerOwnsAssignment(Assignment $assignment): void
|
||||
{
|
||||
$this->service->delete($submission);
|
||||
$user = request()->user();
|
||||
|
||||
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengumpulan berhasil dihapus.'])->back();
|
||||
abort_if(
|
||||
$user->hasRole('dosen') && $assignment->courseClass?->lecturer_id !== $user->lecturer?->id,
|
||||
403,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests\Admin\AcademicClasses;
|
||||
|
||||
use App\Enums\AssignmentStatus;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@ -14,11 +15,20 @@ public function authorize(): bool
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
$courseClassRule = Rule::exists('course_classes', 'id');
|
||||
|
||||
if ($user->hasRole('dosen')) {
|
||||
$courseClassRule->where('lecturer_id', $user->lecturer?->id);
|
||||
}
|
||||
|
||||
return [
|
||||
'course_class_id' => ['required', 'integer', Rule::exists('course_classes', 'id')],
|
||||
'course_class_id' => ['required', 'integer', $courseClassRule],
|
||||
'title' => ['required', 'string', 'max:150'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'deadline' => ['required', 'date'],
|
||||
'status' => ['nullable', Rule::enum(AssignmentStatus::class)],
|
||||
'attachment' => ['nullable', 'file', 'max:10240', 'mimes:pdf,doc,docx,ppt,pptx,xls,xlsx,jpg,jpeg,png,mp4,zip'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -10,7 +10,18 @@ class AttendanceStoreRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can('create-attendances');
|
||||
if (! $this->user()->can('create-attendances')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $this->user();
|
||||
$courseClass = $this->route('course_class');
|
||||
|
||||
if ($user->hasRole('dosen') && $courseClass?->lecturer_id !== $user->lecturer?->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\AcademicClasses;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class GradeSubmissionRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
if (! $this->user()->can('update-assignment-submissions')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $this->user();
|
||||
$assignment = $this->route('assignment');
|
||||
|
||||
if ($user->hasRole('dosen') && $assignment?->courseClass?->lecturer_id !== $user->lecturer?->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'score' => ['nullable', 'numeric', 'min:0', 'max:100'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -14,8 +14,16 @@ public function authorize(): bool
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
$courseClassRule = Rule::exists('course_classes', 'id');
|
||||
|
||||
if ($user->hasRole('dosen')) {
|
||||
$courseClassRule->where('lecturer_id', $user->lecturer?->id);
|
||||
}
|
||||
|
||||
return [
|
||||
'course_class_id' => ['required', 'integer', Rule::exists('course_classes', 'id')],
|
||||
'course_class_id' => ['required', 'integer', $courseClassRule],
|
||||
'title' => ['required', 'string', 'max:150'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'meeting_number' => ['nullable', 'integer', 'min:1'],
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests\Admin\AcademicClasses;
|
||||
|
||||
use App\Enums\DayOfWeek;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@ -16,9 +17,9 @@ public function rules(): array
|
||||
{
|
||||
return [
|
||||
'course_class_id' => ['required', 'integer', Rule::exists('course_classes', 'id')],
|
||||
'day_of_week' => ['nullable', 'string', 'max:15'],
|
||||
'start_time' => ['nullable', 'date_format:H:i'],
|
||||
'end_time' => ['nullable', 'date_format:H:i', 'after:start_time'],
|
||||
'day_of_week' => ['required', 'string', Rule::in(DayOfWeek::values())],
|
||||
'start_time' => ['required', 'date_format:H:i'],
|
||||
'end_time' => ['required', 'date_format:H:i', 'after:start_time'],
|
||||
'room' => ['nullable', 'string', 'max:20'],
|
||||
'online_link' => ['nullable', 'string', 'max:255', 'url'],
|
||||
];
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\AcademicClasses;
|
||||
|
||||
use App\Enums\SubmissionStatus;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SubmissionRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->can($this->isMethod('post') ? 'create-assignment-submissions' : 'update-assignment-submissions');
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$assignment = $this->route('assignment');
|
||||
$submission = $this->route('submission');
|
||||
|
||||
$rules = [
|
||||
'notes' => ['nullable', 'string'],
|
||||
'status' => ['required', Rule::enum(SubmissionStatus::class)],
|
||||
'submitted_at' => ['nullable', 'date'],
|
||||
'score' => ['nullable', 'numeric', 'min:0', 'max:100'],
|
||||
'lecturer_feedback' => ['nullable', 'string'],
|
||||
'file' => ['nullable', 'file', 'max:10240', 'mimes:pdf,doc,docx,ppt,pptx,xls,xlsx,jpg,jpeg,png,mp4,zip'],
|
||||
];
|
||||
|
||||
if (! $submission) {
|
||||
$rules['student_id'] = [
|
||||
'required',
|
||||
'integer',
|
||||
Rule::exists('class_enrollments', 'student_id')->where('course_class_id', $assignment->course_class_id),
|
||||
Rule::unique('submissions', 'student_id')->where('assignment_id', $assignment->id),
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\AcademicClasses;
|
||||
|
||||
use App\Enums\AssignmentStatus;
|
||||
use App\Enums\RegistrationStatus;
|
||||
use App\Models\Submission;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SubmitAssignmentRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
if (! $this->user()->can('submit-assignments')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$student = $this->user()->student;
|
||||
$assignment = $this->route('assignment');
|
||||
|
||||
if (! $student || ! $assignment) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Whether the assignment still accepts submissions is governed by its
|
||||
// status, not the deadline — a lecturer closes it explicitly.
|
||||
if ($assignment->status !== AssignmentStatus::Open) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $assignment->courseClass()
|
||||
->whereHas('registrations', function ($q) use ($student) {
|
||||
$q->where('student_id', $student->id)
|
||||
->whereHas('submission', fn ($q) => $q->where('status', RegistrationStatus::Approved));
|
||||
})
|
||||
->exists();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$assignment = $this->route('assignment');
|
||||
$student = $this->user()->student;
|
||||
|
||||
$hasExistingFile = Submission::query()
|
||||
->where('assignment_id', $assignment->id)
|
||||
->where('student_id', $student?->id)
|
||||
->whereHas('media')
|
||||
->exists();
|
||||
|
||||
return [
|
||||
'notes' => ['nullable', 'string'],
|
||||
'file' => [
|
||||
$hasExistingFile ? 'nullable' : 'required',
|
||||
'file',
|
||||
'max:10240',
|
||||
'mimes:pdf,doc,docx,ppt,pptx,xls,xlsx,jpg,jpeg,png,mp4,zip',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\AssignmentStatus;
|
||||
use Illuminate\Database\Eloquent\Attributes\Appends;
|
||||
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
@ -23,6 +24,7 @@ protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'deadline' => 'datetime',
|
||||
'status' => AssignmentStatus::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\DayOfWeek;
|
||||
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@ -12,6 +13,13 @@ class Schedule extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'day_of_week' => DayOfWeek::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function courseClass(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CourseClass::class);
|
||||
|
||||
@ -2,20 +2,39 @@
|
||||
|
||||
namespace App\Services\Admin\AcademicClasses;
|
||||
|
||||
use App\Enums\AssignmentStatus;
|
||||
use App\Enums\RegistrationStatus;
|
||||
use App\Models\Assignment;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
|
||||
class AssignmentService
|
||||
{
|
||||
public function paginated(int $perPage = 25, string $search = '', ?int $courseClassId = null): LengthAwarePaginator
|
||||
public function paginated(User $user, int $perPage = 25, string $search = '', ?int $courseClassId = null, ?int $academicTermId = null): LengthAwarePaginator
|
||||
{
|
||||
return Assignment::query()
|
||||
->select(['id', 'course_class_id', 'title', 'description', 'deadline'])
|
||||
->withCount('submissions')
|
||||
->with('courseClass.course:id,code,name')
|
||||
->select(['id', 'course_class_id', 'title', 'description', 'deadline', 'status'])
|
||||
->withCount([
|
||||
'submissions',
|
||||
'submissions as graded_submissions_count' => fn ($q) => $q->whereNotNull('score'),
|
||||
])
|
||||
->with(['courseClass' => fn ($q) => $q->withCount('enrollments')
|
||||
->with(['course:id,code,name', 'academicTerm:id,academic_year,semester,start_date,end_date'])])
|
||||
->when($user->hasRole('mahasiswa'), fn ($q) => $q->with(['submissions' => function ($q) use ($user) {
|
||||
$q->select(['id', 'assignment_id', 'student_id', 'notes', 'status', 'submitted_at'])
|
||||
->where('student_id', $user->student?->id);
|
||||
}]))
|
||||
->when($search, fn ($q) => $q->where('title', 'like', "%{$search}%"))
|
||||
->when($courseClassId, fn ($q) => $q->where('course_class_id', $courseClassId))
|
||||
->when($academicTermId, fn ($q) => $q->whereHas('courseClass', fn ($q) => $q->where('academic_term_id', $academicTermId)))
|
||||
->when($user->hasRole('dosen'), fn ($q) => $q->whereHas('courseClass', fn ($q) => $q->where('lecturer_id', $user->lecturer?->id)))
|
||||
->when($user->hasRole('mahasiswa'), fn ($q) => $q->whereHas('courseClass', function ($q) use ($user) {
|
||||
$q->whereHas('registrations', function ($q) use ($user) {
|
||||
$q->where('student_id', $user->student?->id)
|
||||
->whereHas('submission', fn ($q) => $q->where('status', RegistrationStatus::Approved));
|
||||
});
|
||||
}))
|
||||
->latest()
|
||||
->paginate($perPage);
|
||||
}
|
||||
@ -27,6 +46,7 @@ public function create(array $data, ?UploadedFile $file): Assignment
|
||||
'title' => $data['title'],
|
||||
'description' => $data['description'] ?? null,
|
||||
'deadline' => $data['deadline'],
|
||||
'status' => $data['status'] ?? AssignmentStatus::Open,
|
||||
]);
|
||||
|
||||
if ($file) {
|
||||
@ -42,6 +62,7 @@ public function update(Assignment $assignment, array $data, ?UploadedFile $file)
|
||||
$assignment->title = $data['title'];
|
||||
$assignment->description = $data['description'] ?? null;
|
||||
$assignment->deadline = $data['deadline'];
|
||||
$assignment->status = $data['status'] ?? $assignment->status;
|
||||
$assignment->update();
|
||||
|
||||
if ($file) {
|
||||
|
||||
@ -5,22 +5,60 @@
|
||||
use App\Enums\AttendanceStatus;
|
||||
use App\Models\Attendance;
|
||||
use App\Models\CourseClass;
|
||||
use App\Models\Student;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Collection as BaseCollection;
|
||||
|
||||
class AttendanceService
|
||||
{
|
||||
public function sessions(): Collection
|
||||
/**
|
||||
* Classes to show on the attendance overview: a dosen only sees classes
|
||||
* they lecture, optionally narrowed down to one academic term.
|
||||
*/
|
||||
public function courseClassesForUser(User $user, ?int $academicTermId): Collection
|
||||
{
|
||||
return CourseClass::query()
|
||||
->select(['course_classes.id', 'course_classes.course_id', 'course_classes.lecturer_id', 'course_classes.academic_term_id'])
|
||||
->withCount('enrollments')
|
||||
->with([
|
||||
'course:id,code,name',
|
||||
'academicTerm:id,academic_year,semester,start_date,end_date',
|
||||
'attendances' => fn ($q) => $q->select('course_class_id', 'meeting_number')->distinct(),
|
||||
])
|
||||
->when($user->hasRole('dosen'), fn ($q) => $q->where('lecturer_id', $user->lecturer?->id))
|
||||
->when($academicTermId, fn ($q) => $q->where('academic_term_id', $academicTermId))
|
||||
->orderBy('course_id')
|
||||
->get()
|
||||
->each(function (CourseClass $courseClass) {
|
||||
$courseClass->setAttribute('meetings_count', $courseClass->attendances->count());
|
||||
$courseClass->unsetRelation('attendances');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Every meeting recorded so far for a single class.
|
||||
*/
|
||||
public function sessionsForClass(CourseClass $courseClass): Collection
|
||||
{
|
||||
return Attendance::query()
|
||||
->select(['course_class_id', 'meeting_number', 'date'])
|
||||
->select(['meeting_number', 'date'])
|
||||
->selectRaw('COUNT(*) as total_count')
|
||||
->selectRaw("SUM(CASE WHEN status = 'present' THEN 1 ELSE 0 END) as present_count")
|
||||
->with('courseClass.course:id,code,name')
|
||||
->groupBy('course_class_id', 'meeting_number', 'date')
|
||||
->orderByDesc('date')
|
||||
->where('course_class_id', $courseClass->id)
|
||||
->groupBy('meeting_number', 'date')
|
||||
->orderByDesc('meeting_number')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* The meeting number a new session for this class should default to.
|
||||
*/
|
||||
public function nextMeetingNumber(CourseClass $courseClass): int
|
||||
{
|
||||
return (Attendance::query()->where('course_class_id', $courseClass->id)->max('meeting_number') ?? 0) + 1;
|
||||
}
|
||||
|
||||
public function session(CourseClass $courseClass, int $meetingNumber): array
|
||||
{
|
||||
$existing = Attendance::query()
|
||||
@ -74,4 +112,36 @@ public function deleteSession(int $courseClassId, int $meetingNumber): void
|
||||
->where('meeting_number', $meetingNumber)
|
||||
->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-class attendance summary for a student's own classes: every class
|
||||
* they're enrolled in, with their recorded meetings and a present/total
|
||||
* tally, even for classes with no attendance taken yet.
|
||||
*/
|
||||
public function forStudent(Student $student): BaseCollection
|
||||
{
|
||||
$enrollments = $student->enrollments()
|
||||
->with([
|
||||
'courseClass.course:id,code,name',
|
||||
'courseClass.academicTerm:id,academic_year,semester,start_date,end_date',
|
||||
])
|
||||
->get();
|
||||
|
||||
$recordsByClass = Attendance::query()
|
||||
->where('student_id', $student->id)
|
||||
->orderBy('meeting_number')
|
||||
->get(['course_class_id', 'meeting_number', 'date', 'status'])
|
||||
->groupBy('course_class_id');
|
||||
|
||||
return $enrollments->map(function ($enrollment) use ($recordsByClass) {
|
||||
$records = $recordsByClass->get($enrollment->course_class_id, new Collection);
|
||||
|
||||
return [
|
||||
'course_class' => $enrollment->courseClass,
|
||||
'records' => $records->values(),
|
||||
'present_count' => $records->where('status', AttendanceStatus::Present)->count(),
|
||||
'total_count' => $records->count(),
|
||||
];
|
||||
})->values();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,19 +2,28 @@
|
||||
|
||||
namespace App\Services\Admin\AcademicClasses;
|
||||
|
||||
use App\Enums\RegistrationStatus;
|
||||
use App\Models\Material;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
|
||||
class MaterialService
|
||||
{
|
||||
public function paginated(int $perPage = 25, string $search = '', ?int $courseClassId = null): LengthAwarePaginator
|
||||
public function paginated(User $user, int $perPage = 25, string $search = '', ?int $courseClassId = null): LengthAwarePaginator
|
||||
{
|
||||
return Material::query()
|
||||
->select(['id', 'course_class_id', 'title', 'description', 'meeting_number'])
|
||||
->with('courseClass.course:id,code,name')
|
||||
->when($search, fn ($q) => $q->where('title', 'like', "%{$search}%"))
|
||||
->when($courseClassId, fn ($q) => $q->where('course_class_id', $courseClassId))
|
||||
->when($user->hasRole('dosen'), fn ($q) => $q->whereHas('courseClass', fn ($q) => $q->where('lecturer_id', $user->lecturer?->id)))
|
||||
->when($user->hasRole('mahasiswa'), fn ($q) => $q->whereHas('courseClass', function ($q) use ($user) {
|
||||
$q->whereHas('registrations', function ($q) use ($user) {
|
||||
$q->where('student_id', $user->student?->id)
|
||||
->whereHas('submission', fn ($q) => $q->where('status', RegistrationStatus::Approved));
|
||||
});
|
||||
}))
|
||||
->latest()
|
||||
->paginate($perPage);
|
||||
}
|
||||
|
||||
@ -2,27 +2,72 @@
|
||||
|
||||
namespace App\Services\Admin\AcademicClasses;
|
||||
|
||||
use App\Enums\RegistrationStatus;
|
||||
use App\Models\CourseClass;
|
||||
use App\Models\Schedule;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ScheduleService
|
||||
{
|
||||
public function all(): Collection
|
||||
public function all(User $user, ?int $academicTermId = null, ?int $departmentId = null, ?int $semesterNumber = null): Collection
|
||||
{
|
||||
return Schedule::query()
|
||||
->select(['id', 'course_class_id', 'day_of_week', 'start_time', 'end_time', 'room', 'online_link'])
|
||||
->with('courseClass.course:id,code,name')
|
||||
->with([
|
||||
'courseClass:id,course_id,lecturer_id,academic_term_id,method',
|
||||
'courseClass.course:id,code,name,department_id',
|
||||
'courseClass.course.department:id,name',
|
||||
'courseClass.lecturer:id,user_id,lecturer_number',
|
||||
'courseClass.lecturer.user:id,username',
|
||||
'courseClass.lecturer.user.profile:id,user_id,full_name',
|
||||
])
|
||||
->whereHas('courseClass', function ($q) use ($user, $academicTermId, $departmentId, $semesterNumber) {
|
||||
$q->when($academicTermId, fn ($q) => $q->where('academic_term_id', $academicTermId))
|
||||
->when($departmentId, fn ($q) => $q->whereHas('course', fn ($q) => $q->where('department_id', $departmentId)))
|
||||
->when($semesterNumber, fn ($q) => $q->whereHas('course', fn ($q) => $q->where('semester_number', $semesterNumber)))
|
||||
->when($user->hasRole('mahasiswa'), fn ($q) => $q->whereHas('registrations', function ($q) use ($user) {
|
||||
$q->where('student_id', $user->student?->id)
|
||||
->whereHas('submission', fn ($q) => $q->where('status', RegistrationStatus::Approved));
|
||||
}))
|
||||
->when($user->hasRole('dosen'), fn ($q) => $q->where('lecturer_id', $user->lecturer?->id));
|
||||
})
|
||||
->orderBy('start_time')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Course classes for the schedule form's picker, grouped by department and
|
||||
* semester and ordered alphabetically to match the course-class picker
|
||||
* pattern used elsewhere.
|
||||
*/
|
||||
public function courseClassOptions(): Collection
|
||||
{
|
||||
return CourseClass::query()
|
||||
->select(['course_classes.id', 'course_classes.course_id', 'course_classes.lecturer_id', 'course_classes.academic_term_id'])
|
||||
->join('courses', 'courses.id', '=', 'course_classes.course_id')
|
||||
->join('departments', 'departments.id', '=', 'courses.department_id')
|
||||
->with([
|
||||
'course:id,code,name,department_id,semester_number',
|
||||
'course.department:id,name',
|
||||
'lecturer:id,user_id,lecturer_number',
|
||||
'lecturer.user:id,username',
|
||||
'lecturer.user.profile:id,user_id,full_name',
|
||||
'academicTerm:id,academic_year,semester,start_date,end_date',
|
||||
])
|
||||
->orderBy('departments.name')
|
||||
->orderBy('courses.semester_number')
|
||||
->orderBy('courses.name')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function create(array $data): Schedule
|
||||
{
|
||||
return Schedule::create([
|
||||
'course_class_id' => $data['course_class_id'],
|
||||
'day_of_week' => $data['day_of_week'] ?? null,
|
||||
'start_time' => $data['start_time'] ?? null,
|
||||
'end_time' => $data['end_time'] ?? null,
|
||||
'day_of_week' => $data['day_of_week'],
|
||||
'start_time' => $data['start_time'],
|
||||
'end_time' => $data['end_time'],
|
||||
'room' => $data['room'] ?? null,
|
||||
'online_link' => $data['online_link'] ?? null,
|
||||
]);
|
||||
@ -31,9 +76,9 @@ public function create(array $data): Schedule
|
||||
public function update(Schedule $schedule, array $data): Schedule
|
||||
{
|
||||
$schedule->course_class_id = $data['course_class_id'];
|
||||
$schedule->day_of_week = $data['day_of_week'] ?? null;
|
||||
$schedule->start_time = $data['start_time'] ?? null;
|
||||
$schedule->end_time = $data['end_time'] ?? null;
|
||||
$schedule->day_of_week = $data['day_of_week'];
|
||||
$schedule->start_time = $data['start_time'];
|
||||
$schedule->end_time = $data['end_time'];
|
||||
$schedule->room = $data['room'] ?? null;
|
||||
$schedule->online_link = $data['online_link'] ?? null;
|
||||
$schedule->update();
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services\Admin\AcademicClasses;
|
||||
|
||||
use App\Enums\SubmissionStatus;
|
||||
use App\Models\Assignment;
|
||||
use App\Models\Student;
|
||||
use App\Models\Submission;
|
||||
@ -10,6 +11,29 @@
|
||||
|
||||
class SubmissionService
|
||||
{
|
||||
/**
|
||||
* Self-service submission by the student themselves: creates their
|
||||
* submission for this assignment, or updates it if they already
|
||||
* submitted before (e.g. resubmitting).
|
||||
*/
|
||||
public function submitForStudent(Assignment $assignment, Student $student, array $data, ?UploadedFile $file): Submission
|
||||
{
|
||||
$submission = Submission::query()->updateOrCreate(
|
||||
['assignment_id' => $assignment->id, 'student_id' => $student->id],
|
||||
[
|
||||
'notes' => $data['notes'] ?? null,
|
||||
'status' => SubmissionStatus::Submitted,
|
||||
'submitted_at' => now(),
|
||||
],
|
||||
);
|
||||
|
||||
if ($file) {
|
||||
$submission->addMedia($file)->toMediaCollection('submission_file');
|
||||
}
|
||||
|
||||
return $submission;
|
||||
}
|
||||
|
||||
public function forAssignment(Assignment $assignment): Collection
|
||||
{
|
||||
return $assignment->submissions()
|
||||
@ -18,51 +42,11 @@ public function forAssignment(Assignment $assignment): Collection
|
||||
->get();
|
||||
}
|
||||
|
||||
public function availableStudents(Assignment $assignment): Collection
|
||||
public function grade(Submission $submission, ?float $score): Submission
|
||||
{
|
||||
return Student::query()
|
||||
->whereHas('enrollments', fn ($q) => $q->where('course_class_id', $assignment->course_class_id))
|
||||
->whereDoesntHave('submissions', fn ($q) => $q->where('assignment_id', $assignment->id))
|
||||
->with(['user.profile', 'department'])
|
||||
->get();
|
||||
}
|
||||
|
||||
public function create(Assignment $assignment, array $data, ?UploadedFile $file): Submission
|
||||
{
|
||||
$submission = $assignment->submissions()->create([
|
||||
'student_id' => $data['student_id'],
|
||||
'notes' => $data['notes'] ?? null,
|
||||
'status' => $data['status'],
|
||||
'submitted_at' => $data['submitted_at'] ?? null,
|
||||
'score' => $data['score'] ?? null,
|
||||
'lecturer_feedback' => $data['lecturer_feedback'] ?? null,
|
||||
]);
|
||||
|
||||
if ($file) {
|
||||
$submission->addMedia($file)->toMediaCollection('submission_file');
|
||||
}
|
||||
|
||||
return $submission;
|
||||
}
|
||||
|
||||
public function update(Submission $submission, array $data, ?UploadedFile $file): Submission
|
||||
{
|
||||
$submission->notes = $data['notes'] ?? null;
|
||||
$submission->status = $data['status'];
|
||||
$submission->submitted_at = $data['submitted_at'] ?? null;
|
||||
$submission->score = $data['score'] ?? null;
|
||||
$submission->lecturer_feedback = $data['lecturer_feedback'] ?? null;
|
||||
$submission->score = $score;
|
||||
$submission->update();
|
||||
|
||||
if ($file) {
|
||||
$submission->addMedia($file)->toMediaCollection('submission_file');
|
||||
}
|
||||
|
||||
return $submission;
|
||||
}
|
||||
|
||||
public function delete(Submission $submission): bool
|
||||
{
|
||||
return $submission->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,16 +3,32 @@
|
||||
namespace App\Services\Admin\Manage;
|
||||
|
||||
use App\Models\CourseClass;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CourseClassService
|
||||
{
|
||||
public function getAllForSelect(): Collection
|
||||
/**
|
||||
* When $user is a dosen, only their own assigned classes are returned.
|
||||
* When $user is a mahasiswa, only classes from their own department are returned.
|
||||
*/
|
||||
public function getAllForSelect(?User $user = null): Collection
|
||||
{
|
||||
return CourseClass::select(['id', 'course_id', 'academic_term_id'])
|
||||
->with('course:id,code,name,semester_number,department_id')
|
||||
return CourseClass::query()
|
||||
->select(['course_classes.id', 'course_classes.course_id', 'course_classes.lecturer_id', 'course_classes.academic_term_id'])
|
||||
->join('courses', 'courses.id', '=', 'course_classes.course_id')
|
||||
->join('departments', 'departments.id', '=', 'courses.department_id')
|
||||
->with([
|
||||
'course:id,code,name,semester_number,department_id',
|
||||
'course.department:id,name',
|
||||
])
|
||||
->when($user?->hasRole('dosen'), fn ($q) => $q->where('course_classes.lecturer_id', $user->lecturer?->id))
|
||||
->when($user?->hasRole('mahasiswa'), fn ($q) => $q->where('courses.department_id', $user->student?->department_id))
|
||||
->orderBy('departments.name')
|
||||
->orderBy('courses.semester_number')
|
||||
->orderBy('courses.name')
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
@ -41,15 +41,19 @@ public function departmentSummary(): Collection
|
||||
public function paginated(int $perPage = 25, string $search = '', ?int $departmentId = null, ?int $advisorLecturerId = null, ?array $ledDepartmentIds = null): LengthAwarePaginator
|
||||
{
|
||||
$paginator = Student::query()
|
||||
->select(['id', 'user_id', 'student_number', 'department_id'])
|
||||
->where('status', StudentStatus::Active)
|
||||
->when($ledDepartmentIds !== null, fn ($q) => $q->whereIn('department_id', $ledDepartmentIds))
|
||||
->when($departmentId, fn ($q) => $q->where('department_id', $departmentId))
|
||||
->when($advisorLecturerId, fn ($q) => $q->where('academic_advisor_id', $advisorLecturerId))
|
||||
->when($search, fn ($q) => $q->where('student_number', 'like', "%{$search}%")
|
||||
->orWhereHas('user.profile', fn ($q) => $q->where('full_name', 'like', "%{$search}%")))
|
||||
->select(['students.id', 'students.user_id', 'students.student_number', 'students.department_id'])
|
||||
->join('departments', 'departments.id', '=', 'students.department_id')
|
||||
->join('users', 'users.id', '=', 'students.user_id')
|
||||
->join('user_profiles', 'user_profiles.user_id', '=', 'users.id')
|
||||
->where('students.status', StudentStatus::Active)
|
||||
->when($ledDepartmentIds !== null, fn ($q) => $q->whereIn('students.department_id', $ledDepartmentIds))
|
||||
->when($departmentId, fn ($q) => $q->where('students.department_id', $departmentId))
|
||||
->when($advisorLecturerId, fn ($q) => $q->where('students.academic_advisor_id', $advisorLecturerId))
|
||||
->when($search, fn ($q) => $q->where('students.student_number', 'like', "%{$search}%")
|
||||
->orWhere('user_profiles.full_name', 'like', "%{$search}%"))
|
||||
->with(['user.profile', 'department:id,name'])
|
||||
->orderBy('student_number')
|
||||
->orderBy('departments.name')
|
||||
->orderBy('user_profiles.full_name')
|
||||
->paginate($perPage);
|
||||
|
||||
return $paginator->through(fn (Student $student) => [
|
||||
|
||||
@ -14,12 +14,15 @@ class LecturerService
|
||||
{
|
||||
public function getAllForSelect(): Collection
|
||||
{
|
||||
return Lecturer::select(['id', 'user_id', 'lecturer_number'])
|
||||
return Lecturer::select(['lecturers.id', 'lecturers.user_id', 'lecturers.lecturer_number'])
|
||||
->join('users', 'users.id', '=', 'lecturers.user_id')
|
||||
->join('user_profiles', 'user_profiles.user_id', '=', 'users.id')
|
||||
->with([
|
||||
'user:id,username',
|
||||
'user.profile:id,user_id,full_name',
|
||||
'departments:id,name',
|
||||
])
|
||||
->orderBy('user_profiles.full_name')
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
@ -14,13 +14,19 @@ class StudentService
|
||||
{
|
||||
public function getAllForSelect(?string $status = null): Collection
|
||||
{
|
||||
return Student::select(['id', 'user_id', 'student_number', 'department_id', 'current_semester'])
|
||||
return Student::select(['students.id', 'students.user_id', 'students.student_number', 'students.department_id', 'students.current_semester'])
|
||||
->join('departments', 'departments.id', '=', 'students.department_id')
|
||||
->join('users', 'users.id', '=', 'students.user_id')
|
||||
->join('user_profiles', 'user_profiles.user_id', '=', 'users.id')
|
||||
->with([
|
||||
'user:id,username',
|
||||
'user.profile:id,user_id,full_name',
|
||||
'department:id,name',
|
||||
])
|
||||
->when($status, fn ($q) => $q->where('status', $status))
|
||||
->when($status, fn ($q) => $q->where('students.status', $status))
|
||||
->orderBy('departments.name')
|
||||
->orderBy('students.current_semester')
|
||||
->orderBy('user_profiles.full_name')
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
@ -15,9 +15,10 @@ class PermissionCatalog
|
||||
public const ACADEMIC_CLASSES = [
|
||||
'view-materials', 'create-materials', 'update-materials', 'delete-materials',
|
||||
'view-assignments', 'create-assignments', 'update-assignments', 'delete-assignments',
|
||||
'view-assignment-submissions', 'create-assignment-submissions', 'update-assignment-submissions', 'delete-assignment-submissions',
|
||||
'view-assignment-submissions', 'update-assignment-submissions',
|
||||
'submit-assignments',
|
||||
'view-schedules', 'create-schedules', 'update-schedules', 'delete-schedules',
|
||||
'view-attendances', 'create-attendances', 'delete-attendances',
|
||||
'view-attendances', 'create-attendances', 'delete-attendances', 'view-own-attendances',
|
||||
];
|
||||
|
||||
public const MANAGE = [
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\AssignmentStatus;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('assignments', function (Blueprint $table) {
|
||||
$table->enum('status', AssignmentStatus::values())
|
||||
->default(AssignmentStatus::Open->value)
|
||||
->after('deadline');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('assignments', function (Blueprint $table) {
|
||||
$table->dropColumn('status');
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -46,6 +46,11 @@ public function run(): void
|
||||
'create-letter-requests',
|
||||
'update-letter-requests',
|
||||
'delete-letter-requests',
|
||||
'view-schedules',
|
||||
'view-materials',
|
||||
'view-assignments',
|
||||
'submit-assignments',
|
||||
'view-own-attendances',
|
||||
...$feedbackSelfService,
|
||||
],
|
||||
'dosen' => [
|
||||
@ -56,6 +61,20 @@ public function run(): void
|
||||
'view-course-registrations',
|
||||
'approve-course-registrations',
|
||||
'reject-course-registrations',
|
||||
'view-schedules',
|
||||
'view-materials',
|
||||
'create-materials',
|
||||
'update-materials',
|
||||
'delete-materials',
|
||||
'view-assignments',
|
||||
'create-assignments',
|
||||
'update-assignments',
|
||||
'delete-assignments',
|
||||
'view-assignment-submissions',
|
||||
'update-assignment-submissions',
|
||||
'view-attendances',
|
||||
'create-attendances',
|
||||
'delete-attendances',
|
||||
...$feedbackSelfService,
|
||||
],
|
||||
'staff-admin' => [
|
||||
|
||||
@ -36,7 +36,10 @@ import {
|
||||
SidebarMenuItem,
|
||||
} from '@/components/ui/sidebar';
|
||||
import { index as assignmentsRoute } from '@/routes/admin/academic-classes/assignments';
|
||||
import { index as attendancesRoute } from '@/routes/admin/academic-classes/attendances';
|
||||
import {
|
||||
index as attendancesRoute,
|
||||
mine as myAttendancesRoute,
|
||||
} from '@/routes/admin/academic-classes/attendances';
|
||||
import { index as materialsRoute } from '@/routes/admin/academic-classes/materials';
|
||||
import { index as schedulesRoute } from '@/routes/admin/academic-classes/schedules';
|
||||
import { index as logsRoute } from '@/routes/admin/developer/logs';
|
||||
@ -172,6 +175,15 @@ function buildNavMain({
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(can('view-own-attendances')
|
||||
? [
|
||||
{
|
||||
name: 'Riwayat Kehadiran',
|
||||
url: myAttendancesRoute.url(),
|
||||
icon: ClipboardCheck,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
|
||||
const keuanganItems: NavItem[] = [
|
||||
|
||||
105
resources/js/components/attachment-preview-dialog.tsx
Normal file
105
resources/js/components/attachment-preview-dialog.tsx
Normal file
@ -0,0 +1,105 @@
|
||||
import { Paperclip } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
||||
const VIDEO_EXTENSIONS = ['mp4', 'webm'];
|
||||
|
||||
function fileExtension(fileName: string): string {
|
||||
return fileName.split('.').pop()?.toLowerCase() ?? '';
|
||||
}
|
||||
|
||||
type AttachmentPreviewDialogProps = {
|
||||
fileUrl: string;
|
||||
fileName: string;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export function AttachmentPreviewDialog({
|
||||
fileUrl,
|
||||
fileName,
|
||||
className,
|
||||
}: AttachmentPreviewDialogProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const extension = fileExtension(fileName);
|
||||
const isImage = IMAGE_EXTENSIONS.includes(extension);
|
||||
const isVideo = VIDEO_EXTENSIONS.includes(extension);
|
||||
const isPdf = extension === 'pdf';
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(true)}
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1 text-primary underline underline-offset-4 hover:text-primary/80',
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<Paperclip className="h-3.5 w-3.5 shrink-0" />
|
||||
<span className="truncate">{fileName}</span>
|
||||
</button>
|
||||
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogContent
|
||||
className={cn(
|
||||
'flex flex-col overflow-hidden',
|
||||
isPdf
|
||||
? 'h-[90vh] max-h-[90vh] w-[95vw] max-w-6xl sm:max-w-6xl'
|
||||
: 'max-h-[85vh] sm:max-w-lg',
|
||||
)}
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="truncate pr-6">
|
||||
{fileName}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex min-h-0 flex-1 items-center justify-center overflow-auto rounded-md bg-muted/30">
|
||||
{isImage && (
|
||||
<img
|
||||
src={fileUrl}
|
||||
alt={fileName}
|
||||
className="max-h-[70vh] max-w-full object-contain"
|
||||
/>
|
||||
)}
|
||||
{isVideo && (
|
||||
<video
|
||||
src={fileUrl}
|
||||
controls
|
||||
className="max-h-[70vh] w-full"
|
||||
/>
|
||||
)}
|
||||
{isPdf && (
|
||||
<iframe
|
||||
src={fileUrl}
|
||||
title={fileName}
|
||||
className="h-full w-full border-0"
|
||||
/>
|
||||
)}
|
||||
{!isImage && !isVideo && !isPdf && (
|
||||
<div className="flex flex-col items-center gap-3 py-16 text-center text-sm text-muted-foreground">
|
||||
<Paperclip className="h-8 w-8" />
|
||||
<p>Pratinjau tidak tersedia untuk file ini.</p>
|
||||
<a
|
||||
href={fileUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="text-primary underline underline-offset-4 hover:text-primary/80"
|
||||
>
|
||||
Buka / unduh file
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@ -1,6 +1,17 @@
|
||||
import { Filter, X } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Combobox,
|
||||
ComboboxCollection,
|
||||
ComboboxContent,
|
||||
ComboboxEmpty,
|
||||
ComboboxGroup,
|
||||
ComboboxInput,
|
||||
ComboboxItem,
|
||||
ComboboxLabel,
|
||||
ComboboxList,
|
||||
} from '@/components/ui/combobox';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@ -22,11 +33,25 @@ export type FilterOption = {
|
||||
label: string;
|
||||
};
|
||||
|
||||
export type FilterField = {
|
||||
export type FilterOptionGroup = {
|
||||
label: string;
|
||||
options: FilterOption[];
|
||||
};
|
||||
|
||||
export type FilterField =
|
||||
| {
|
||||
key: string;
|
||||
label: string;
|
||||
placeholder?: string;
|
||||
type?: 'select';
|
||||
options: FilterOption[];
|
||||
}
|
||||
| {
|
||||
key: string;
|
||||
label: string;
|
||||
placeholder?: string;
|
||||
type: 'combobox';
|
||||
groups: FilterOptionGroup[];
|
||||
};
|
||||
|
||||
type FilterDialogProps = {
|
||||
@ -35,6 +60,61 @@ type FilterDialogProps = {
|
||||
onApply: (filters: Record<string, string>) => void;
|
||||
};
|
||||
|
||||
function ComboboxFilterField({
|
||||
field,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
field: Extract<FilterField, { type: 'combobox' }>;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
}) {
|
||||
const selected =
|
||||
field.groups
|
||||
.flatMap((group) => group.options)
|
||||
.find((option) => option.value === value) ?? null;
|
||||
|
||||
return (
|
||||
<Combobox
|
||||
items={field.groups}
|
||||
value={selected}
|
||||
onValueChange={(option: FilterOption | null) =>
|
||||
onChange(option ? option.value : 'all')
|
||||
}
|
||||
itemToStringLabel={(option: FilterOption) => option.label}
|
||||
isItemEqualToValue={(a: FilterOption, b: FilterOption) =>
|
||||
a.value === b.value
|
||||
}
|
||||
>
|
||||
<ComboboxInput
|
||||
placeholder={field.placeholder ?? 'Semua'}
|
||||
showClear
|
||||
className="w-full"
|
||||
/>
|
||||
<ComboboxContent>
|
||||
<ComboboxEmpty>Tidak ditemukan.</ComboboxEmpty>
|
||||
<ComboboxList>
|
||||
{(group: FilterOptionGroup) => (
|
||||
<ComboboxGroup key={group.label} items={group.options}>
|
||||
<ComboboxLabel>{group.label}</ComboboxLabel>
|
||||
<ComboboxCollection>
|
||||
{(option: FilterOption) => (
|
||||
<ComboboxItem
|
||||
key={option.value}
|
||||
value={option}
|
||||
>
|
||||
{option.label}
|
||||
</ComboboxItem>
|
||||
)}
|
||||
</ComboboxCollection>
|
||||
</ComboboxGroup>
|
||||
)}
|
||||
</ComboboxList>
|
||||
</ComboboxContent>
|
||||
</Combobox>
|
||||
);
|
||||
}
|
||||
|
||||
export function FilterDialog({
|
||||
fields,
|
||||
activeFilters,
|
||||
@ -92,8 +172,21 @@ export function FilterDialog({
|
||||
{fields.map((field) => (
|
||||
<div className="grid gap-2" key={field.key}>
|
||||
<Label>{field.label}</Label>
|
||||
{field.type === 'combobox' ? (
|
||||
<ComboboxFilterField
|
||||
field={field}
|
||||
value={
|
||||
activeFilters[field.key] ?? 'all'
|
||||
}
|
||||
onChange={(value) =>
|
||||
handleChange(field.key, value)
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<Select
|
||||
value={activeFilters[field.key] ?? 'all'}
|
||||
value={
|
||||
activeFilters[field.key] ?? 'all'
|
||||
}
|
||||
onValueChange={(value) =>
|
||||
handleChange(field.key, value)
|
||||
}
|
||||
@ -101,7 +194,8 @@ export function FilterDialog({
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue
|
||||
placeholder={
|
||||
field.placeholder ?? 'Semua'
|
||||
field.placeholder ??
|
||||
'Semua'
|
||||
}
|
||||
/>
|
||||
</SelectTrigger>
|
||||
@ -119,6 +213,7 @@ export function FilterDialog({
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
63
resources/js/components/ui/accordion.tsx
Normal file
63
resources/js/components/ui/accordion.tsx
Normal file
@ -0,0 +1,63 @@
|
||||
import { ChevronDownIcon } from "lucide-react"
|
||||
import { Accordion as AccordionPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Accordion({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
|
||||
return <AccordionPrimitive.Root data-slot="accordion" {...props} />
|
||||
}
|
||||
|
||||
function AccordionItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
|
||||
return (
|
||||
<AccordionPrimitive.Item
|
||||
data-slot="accordion-item"
|
||||
className={cn("border-b last:border-b-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AccordionTrigger({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
|
||||
return (
|
||||
<AccordionPrimitive.Header className="flex">
|
||||
<AccordionPrimitive.Trigger
|
||||
data-slot="accordion-trigger"
|
||||
className={cn(
|
||||
"flex flex-1 items-start justify-between gap-4 rounded-md py-3 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronDownIcon className="pointer-events-none size-4 shrink-0 translate-y-0.5 text-muted-foreground transition-transform duration-200" />
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
)
|
||||
}
|
||||
|
||||
function AccordionContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
|
||||
return (
|
||||
<AccordionPrimitive.Content
|
||||
data-slot="accordion-content"
|
||||
className="overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
|
||||
{...props}
|
||||
>
|
||||
<div className={cn("pt-0 pb-3", className)}>{children}</div>
|
||||
</AccordionPrimitive.Content>
|
||||
)
|
||||
}
|
||||
|
||||
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger }
|
||||
@ -7,6 +7,12 @@ type UseServerTableOptions = {
|
||||
pagination: PaginationState;
|
||||
filters?: Record<string, string | undefined>;
|
||||
filterWithParams?: boolean;
|
||||
/**
|
||||
* Prop keys to pass as Inertia's `reset` visit option whenever search or
|
||||
* filters change, so mergeable props (e.g. `Inertia::scroll()` used for
|
||||
* infinite scroll) are replaced instead of appended to.
|
||||
*/
|
||||
resetKeys?: string[];
|
||||
};
|
||||
|
||||
export function useServerTable({
|
||||
@ -14,8 +20,11 @@ export function useServerTable({
|
||||
pagination,
|
||||
filters,
|
||||
filterWithParams = true,
|
||||
resetKeys,
|
||||
}: UseServerTableOptions) {
|
||||
const [search, setSearch] = useState('');
|
||||
const [search, setSearch] = useState(
|
||||
() => new URLSearchParams(window.location.search).get('search') ?? '',
|
||||
);
|
||||
const [filterOpen, setFilterOpen] = useState(false);
|
||||
|
||||
const handlePageChange = useCallback(
|
||||
@ -61,10 +70,14 @@ export function useServerTable({
|
||||
per_page: pagination.per_page,
|
||||
search: value,
|
||||
},
|
||||
{ preserveState: true, replace: true },
|
||||
{
|
||||
preserveState: true,
|
||||
replace: true,
|
||||
...(resetKeys ? { reset: resetKeys } : {}),
|
||||
},
|
||||
);
|
||||
},
|
||||
[route, filters, pagination.per_page],
|
||||
[route, filters, pagination.per_page, resetKeys],
|
||||
);
|
||||
|
||||
function applyFilter(key: string, value: string) {
|
||||
@ -86,7 +99,11 @@ export function useServerTable({
|
||||
search,
|
||||
}
|
||||
: newFilters,
|
||||
{ preserveState: true, replace: true },
|
||||
{
|
||||
preserveState: true,
|
||||
replace: true,
|
||||
...(resetKeys ? { reset: resetKeys } : {}),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -101,7 +118,11 @@ export function useServerTable({
|
||||
search,
|
||||
}
|
||||
: newFilters,
|
||||
{ preserveState: true, replace: true },
|
||||
{
|
||||
preserveState: true,
|
||||
replace: true,
|
||||
...(resetKeys ? { reset: resetKeys } : {}),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -115,7 +136,11 @@ export function useServerTable({
|
||||
search,
|
||||
}
|
||||
: {},
|
||||
{ preserveState: true, replace: true },
|
||||
{
|
||||
preserveState: true,
|
||||
replace: true,
|
||||
...(resetKeys ? { reset: resetKeys } : {}),
|
||||
},
|
||||
);
|
||||
setFilterOpen(false);
|
||||
}
|
||||
|
||||
@ -1,143 +0,0 @@
|
||||
import type { ColumnDef } from '@tanstack/react-table';
|
||||
import { format } from 'date-fns';
|
||||
import { ClipboardList, Paperclip, Pencil, Trash2 } from 'lucide-react';
|
||||
import { RowActions } from '@/components/row-actions';
|
||||
import { index as submissionsIndex } from '@/routes/admin/academic-classes/assignments/submissions';
|
||||
import type { Assignment } from '@/types/assignment';
|
||||
|
||||
export type { Assignment } from '@/types/assignment';
|
||||
|
||||
type CreateColumnsParams = {
|
||||
handleEdit: (assignment: Assignment) => void;
|
||||
handleDeleteClick: (assignment: Assignment) => void;
|
||||
canUpdate: boolean;
|
||||
canDelete: boolean;
|
||||
canViewSubmissions: boolean;
|
||||
};
|
||||
|
||||
export function createAssignmentColumns(
|
||||
params: CreateColumnsParams,
|
||||
): ColumnDef<Assignment>[] {
|
||||
const {
|
||||
handleEdit,
|
||||
handleDeleteClick,
|
||||
canUpdate,
|
||||
canDelete,
|
||||
canViewSubmissions,
|
||||
} = params;
|
||||
|
||||
const columns: ColumnDef<Assignment>[] = [
|
||||
{
|
||||
accessorKey: 'title',
|
||||
header: () => <span>Judul</span>,
|
||||
cell: ({ row }) => (
|
||||
<span className="font-medium">
|
||||
{row.getValue('title') as string}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'course_class.course.name',
|
||||
header: () => <span>Kelas</span>,
|
||||
cell: ({ row }) => {
|
||||
const courseClass = row.original.course_class;
|
||||
|
||||
if (!courseClass) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'deadline',
|
||||
header: () => <span>Batas Waktu</span>,
|
||||
cell: ({ row }) => {
|
||||
const deadline = row.getValue('deadline') as string;
|
||||
|
||||
return format(new Date(deadline), 'd MMM yyyy, HH:mm');
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'attachment_name',
|
||||
header: () => <span>Lampiran</span>,
|
||||
cell: ({ row }) => {
|
||||
const assignment = row.original;
|
||||
|
||||
if (!assignment.attachment_url) {
|
||||
return <span className="text-muted-foreground">-</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<a
|
||||
href={assignment.attachment_url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-flex items-center gap-1 text-primary underline underline-offset-4 hover:text-primary/80"
|
||||
>
|
||||
<Paperclip className="h-3.5 w-3.5" />
|
||||
{assignment.attachment_name}
|
||||
</a>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'submissions_count',
|
||||
header: () => (
|
||||
<span className="block text-center">Pengumpulan</span>
|
||||
),
|
||||
meta: {
|
||||
className: 'w-[120px] text-center',
|
||||
headerClassName: 'w-[120px] text-center',
|
||||
},
|
||||
cell: ({ row }) => (
|
||||
<div className="text-center">
|
||||
{row.original.submissions_count}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
if (canViewSubmissions || canUpdate || canDelete) {
|
||||
columns.push({
|
||||
id: 'actions',
|
||||
header: () => <span className="block text-center">Aksi</span>,
|
||||
meta: {
|
||||
className: 'w-[130px] text-center',
|
||||
headerClassName: 'w-[130px] text-center',
|
||||
},
|
||||
cell: ({ row }) => {
|
||||
const assignment = row.original;
|
||||
|
||||
return (
|
||||
<RowActions
|
||||
actions={[
|
||||
{
|
||||
label: 'Pengumpulan',
|
||||
icon: <ClipboardList className="h-4 w-4" />,
|
||||
show: canViewSubmissions,
|
||||
href: submissionsIndex.url(assignment.id),
|
||||
},
|
||||
{
|
||||
label: 'Edit',
|
||||
icon: <Pencil className="h-4 w-4" />,
|
||||
show: canUpdate,
|
||||
onClick: () => handleEdit(assignment),
|
||||
},
|
||||
{
|
||||
label: 'Hapus',
|
||||
icon: (
|
||||
<Trash2 className="h-4 w-4 text-destructive" />
|
||||
),
|
||||
show: canDelete,
|
||||
onClick: () => handleDeleteClick(assignment),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return columns;
|
||||
}
|
||||
@ -1,17 +1,48 @@
|
||||
import { Head, router } from '@inertiajs/react';
|
||||
import { Plus } from 'lucide-react';
|
||||
import { Head, InfiniteScroll, router } from '@inertiajs/react';
|
||||
import { format } from 'date-fns';
|
||||
import {
|
||||
Clock,
|
||||
ClipboardList,
|
||||
Paperclip,
|
||||
Pencil,
|
||||
Plus,
|
||||
Trash2,
|
||||
Upload,
|
||||
} from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import type { PaginationState } from '@/components/data-table';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { AttachmentPreviewDialog } from '@/components/attachment-preview-dialog';
|
||||
import { DateTimeField } from '@/components/datetime-field';
|
||||
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
||||
import { FileUploadField } from '@/components/file-upload-field';
|
||||
import type { FilterField } from '@/components/filter-dialog';
|
||||
import type {
|
||||
FilterField,
|
||||
FilterOptionGroup,
|
||||
} from '@/components/filter-dialog';
|
||||
import { FilterDialog } from '@/components/filter-dialog';
|
||||
import { FormDialog } from '@/components/form-dialog';
|
||||
import InputError from '@/components/input-error';
|
||||
import { PageHeader } from '@/components/page-header';
|
||||
import { RowActions } from '@/components/row-actions';
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionItem,
|
||||
AccordionTrigger,
|
||||
} from '@/components/ui/accordion';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import {
|
||||
Combobox,
|
||||
ComboboxCollection,
|
||||
ComboboxContent,
|
||||
ComboboxEmpty,
|
||||
ComboboxGroup,
|
||||
ComboboxInput,
|
||||
ComboboxItem,
|
||||
ComboboxLabel,
|
||||
ComboboxList,
|
||||
} from '@/components/ui/combobox';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import {
|
||||
@ -28,14 +59,31 @@ import {
|
||||
index as assignmentIndex,
|
||||
destroy,
|
||||
store,
|
||||
submit,
|
||||
update,
|
||||
} from '@/routes/admin/academic-classes/assignments';
|
||||
import { index as submissionsIndex } from '@/routes/admin/academic-classes/assignments/submissions';
|
||||
import { formatAcademicTermLabel } from '@/types/academic-term';
|
||||
import type { Assignment } from '@/types/assignment';
|
||||
import { createAssignmentColumns } from './columns';
|
||||
import { AssignmentStatusLabels, AssignmentStatuses } from '@/types/assignment';
|
||||
|
||||
type CourseClassOption = {
|
||||
id: number;
|
||||
course: { id: number; code: string; name: string } | null;
|
||||
course: {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
semester_number: number | null;
|
||||
department: { id: number; name: string } | null;
|
||||
} | null;
|
||||
};
|
||||
|
||||
type CourseClassGroup = { value: string; items: CourseClassOption[] };
|
||||
|
||||
type AcademicTermOption = {
|
||||
id: number;
|
||||
academic_year: string;
|
||||
semester: string;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
@ -47,61 +95,179 @@ type Props = {
|
||||
total: number;
|
||||
};
|
||||
courseClasses: CourseClassOption[];
|
||||
academicTerms: AcademicTermOption[];
|
||||
highlight?: number;
|
||||
filters: {
|
||||
course_class_id?: string;
|
||||
academic_term_id?: string;
|
||||
};
|
||||
};
|
||||
|
||||
function courseClassLabel(courseClass: CourseClassOption): string {
|
||||
return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`;
|
||||
return `${courseClass.course?.code ?? ''} - ${courseClass.course?.name ?? ''}`;
|
||||
}
|
||||
|
||||
function percentageOf(part: number, total: number): number {
|
||||
return total > 0 ? Math.round((part / total) * 100) : 0;
|
||||
}
|
||||
|
||||
/** Turns red as the deadline passes, amber once it's within 3 days. */
|
||||
function deadlineTextClass(deadline: string): string {
|
||||
const hoursLeft = (new Date(deadline).getTime() - Date.now()) / 3_600_000;
|
||||
|
||||
if (hoursLeft <= 0) {
|
||||
return 'font-medium text-destructive';
|
||||
}
|
||||
|
||||
if (hoursLeft <= 24) {
|
||||
return 'text-destructive';
|
||||
}
|
||||
|
||||
if (hoursLeft <= 72) {
|
||||
return 'text-amber-600 dark:text-amber-500';
|
||||
}
|
||||
|
||||
return 'text-muted-foreground';
|
||||
}
|
||||
|
||||
function groupCourseClassesByDepartment(
|
||||
options: CourseClassOption[],
|
||||
): CourseClassGroup[] {
|
||||
const groups: CourseClassGroup[] = [];
|
||||
let currentKey: string | null = null;
|
||||
|
||||
for (const option of options) {
|
||||
const key = `${option.course?.department?.name ?? 'Tanpa Jurusan'} — Semester ${option.course?.semester_number ?? 'Tidak ditentukan'}`;
|
||||
|
||||
if (key !== currentKey) {
|
||||
currentKey = key;
|
||||
groups.push({ value: key, items: [] });
|
||||
}
|
||||
|
||||
groups[groups.length - 1].items.push(option);
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
function courseClassFilterGroups(
|
||||
courseClasses: CourseClassOption[],
|
||||
): FilterOptionGroup[] {
|
||||
return groupCourseClassesByDepartment(courseClasses).map((group) => ({
|
||||
label: group.value,
|
||||
options: group.items.map((option) => ({
|
||||
value: String(option.id),
|
||||
label: courseClassLabel(option),
|
||||
})),
|
||||
}));
|
||||
}
|
||||
|
||||
function CourseClassField({
|
||||
courseClasses,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
courseClasses: CourseClassOption[];
|
||||
value: CourseClassOption | null;
|
||||
onChange: (value: CourseClassOption | null) => void;
|
||||
}) {
|
||||
const groups = groupCourseClassesByDepartment(courseClasses);
|
||||
|
||||
return (
|
||||
<Combobox
|
||||
items={groups}
|
||||
value={value}
|
||||
onValueChange={onChange}
|
||||
itemToStringLabel={courseClassLabel}
|
||||
isItemEqualToValue={(a, b) => a.id === b.id}
|
||||
>
|
||||
<ComboboxInput placeholder="Pilih kelas" className="w-full" />
|
||||
<ComboboxContent>
|
||||
<ComboboxEmpty>Kelas tidak ditemukan.</ComboboxEmpty>
|
||||
<ComboboxList>
|
||||
{(group: CourseClassGroup) => (
|
||||
<ComboboxGroup key={group.value} items={group.items}>
|
||||
<ComboboxLabel>{group.value}</ComboboxLabel>
|
||||
<ComboboxCollection>
|
||||
{(option: CourseClassOption) => (
|
||||
<ComboboxItem
|
||||
key={option.id}
|
||||
value={option}
|
||||
>
|
||||
{courseClassLabel(option)}
|
||||
</ComboboxItem>
|
||||
)}
|
||||
</ComboboxCollection>
|
||||
</ComboboxGroup>
|
||||
)}
|
||||
</ComboboxList>
|
||||
</ComboboxContent>
|
||||
</Combobox>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AssignmentIndex({
|
||||
assignments,
|
||||
courseClasses,
|
||||
academicTerms,
|
||||
highlight,
|
||||
filters,
|
||||
}: Props) {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Assignment | null>(null);
|
||||
const [deleting, setDeleting] = useState<Assignment | null>(null);
|
||||
const [submitting, setSubmitting] = useState<Assignment | null>(null);
|
||||
const { hasPermission } = usePermissions();
|
||||
const canCreate = hasPermission('create-assignments');
|
||||
const canUpdate = hasPermission('update-assignments');
|
||||
const canDelete = hasPermission('delete-assignments');
|
||||
const canViewSubmissions = hasPermission('view-assignment-submissions');
|
||||
const canSubmit = hasPermission('submit-assignments');
|
||||
|
||||
const filterFields: FilterField[] = [
|
||||
{
|
||||
key: 'academic_term_id',
|
||||
label: 'Periode Akademik',
|
||||
options: academicTerms.map((term) => ({
|
||||
value: String(term.id),
|
||||
label: formatAcademicTermLabel(term),
|
||||
})),
|
||||
},
|
||||
{
|
||||
key: 'course_class_id',
|
||||
label: 'Kelas',
|
||||
options: courseClasses.map((courseClass) => ({
|
||||
value: String(courseClass.id),
|
||||
label: courseClassLabel(courseClass),
|
||||
})),
|
||||
type: 'combobox' as const,
|
||||
groups: courseClassFilterGroups(courseClasses),
|
||||
},
|
||||
];
|
||||
|
||||
const pagination: PaginationState = {
|
||||
const pagination = {
|
||||
current_page: assignments.current_page,
|
||||
last_page: assignments.last_page,
|
||||
per_page: assignments.per_page,
|
||||
total: assignments.total,
|
||||
};
|
||||
|
||||
const {
|
||||
search,
|
||||
handlePageChange,
|
||||
handlePerPageChange,
|
||||
handleSearchChange,
|
||||
applyFilters,
|
||||
} = useServerTable({
|
||||
const { search, handleSearchChange, applyFilters } = useServerTable({
|
||||
route: () => assignmentIndex.url(),
|
||||
pagination,
|
||||
filters,
|
||||
resetKeys: ['assignments'],
|
||||
});
|
||||
|
||||
function handleApplyFilters(newFilters: Record<string, string>) {
|
||||
// Tanpa `academic_term_id` eksplisit, backend akan kembali ke
|
||||
// periode aktif, jadi menghapus filter ini perlu dikirim eksplisit
|
||||
// alih-alih hanya menghilangkan key-nya.
|
||||
const clearedAcademicTerm =
|
||||
Boolean(filters.academic_term_id) && !newFilters.academic_term_id;
|
||||
|
||||
applyFilters({
|
||||
...newFilters,
|
||||
...(clearedAcademicTerm ? { academic_term_id: '' } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
function handleDelete() {
|
||||
if (!deleting) {
|
||||
return;
|
||||
@ -112,14 +278,6 @@ export default function AssignmentIndex({
|
||||
});
|
||||
}
|
||||
|
||||
const columns = createAssignmentColumns({
|
||||
handleEdit: (assignment) => setEditing(assignment),
|
||||
handleDeleteClick: (assignment) => setDeleting(assignment),
|
||||
canUpdate,
|
||||
canDelete,
|
||||
canViewSubmissions,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head title="Tugas" />
|
||||
@ -182,23 +340,268 @@ export default function AssignmentIndex({
|
||||
courseClasses={courseClasses}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={assignments.data}
|
||||
searchKey="title"
|
||||
pagination={pagination}
|
||||
onPageChange={handlePageChange}
|
||||
onPerPageChange={handlePerPageChange}
|
||||
onSearchChange={handleSearchChange}
|
||||
searchValue={search}
|
||||
toolbar={
|
||||
<SubmitForm
|
||||
key={submitting?.id}
|
||||
open={submitting !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
setSubmitting(null);
|
||||
}
|
||||
}}
|
||||
assignment={submitting}
|
||||
/>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
placeholder="Cari judul tugas..."
|
||||
value={search}
|
||||
onChange={(event) =>
|
||||
handleSearchChange(event.target.value)
|
||||
}
|
||||
className="max-w-sm"
|
||||
/>
|
||||
<FilterDialog
|
||||
fields={filterFields}
|
||||
activeFilters={filters}
|
||||
onApply={applyFilters}
|
||||
onApply={handleApplyFilters}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{assignments.data.length === 0 ? (
|
||||
<p className="rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground">
|
||||
Belum ada tugas.
|
||||
</p>
|
||||
) : (
|
||||
<InfiniteScroll
|
||||
data="assignments"
|
||||
as="div"
|
||||
buffer={300}
|
||||
className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3"
|
||||
loading={() => (
|
||||
<p className="col-span-full py-4 text-center text-sm text-muted-foreground">
|
||||
Memuat tugas...
|
||||
</p>
|
||||
)}
|
||||
>
|
||||
{assignments.data.map((assignment) => {
|
||||
const mySubmission = assignment.submissions?.[0];
|
||||
|
||||
return (
|
||||
<Card
|
||||
key={assignment.id}
|
||||
className={
|
||||
highlight === assignment.id
|
||||
? 'ring-2 ring-primary'
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<CardHeader className="flex flex-row items-start justify-between gap-2">
|
||||
<div className="flex flex-col gap-1">
|
||||
<CardTitle className="text-base leading-tight">
|
||||
{assignment.title}
|
||||
</CardTitle>
|
||||
{assignment.course_class && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{assignment.course_class
|
||||
.course?.code ??
|
||||
''}{' '}
|
||||
{assignment.course_class
|
||||
.course?.name ?? ''}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<RowActions
|
||||
wrapperClassName="-mt-1 -mr-2 flex items-center gap-1"
|
||||
actions={[
|
||||
{
|
||||
label:
|
||||
mySubmission?.status ===
|
||||
'submitted'
|
||||
? 'Kumpulkan Ulang'
|
||||
: 'Kumpulkan Tugas',
|
||||
icon: (
|
||||
<Upload className="h-3.5 w-3.5" />
|
||||
),
|
||||
show:
|
||||
canSubmit &&
|
||||
assignment.status ===
|
||||
'open',
|
||||
onClick: () =>
|
||||
setSubmitting(
|
||||
assignment,
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'Pengumpulan',
|
||||
icon: (
|
||||
<ClipboardList className="h-3.5 w-3.5" />
|
||||
),
|
||||
show: canViewSubmissions,
|
||||
href: submissionsIndex.url(
|
||||
assignment.id,
|
||||
),
|
||||
},
|
||||
{
|
||||
label: 'Edit',
|
||||
icon: (
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
),
|
||||
show: canUpdate,
|
||||
onClick: () =>
|
||||
setEditing(assignment),
|
||||
},
|
||||
{
|
||||
label: 'Hapus',
|
||||
icon: (
|
||||
<Trash2 className="h-3.5 w-3.5 text-destructive" />
|
||||
),
|
||||
show: canDelete,
|
||||
onClick: () =>
|
||||
setDeleting(assignment),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-2 text-xs text-muted-foreground">
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<Badge
|
||||
variant={
|
||||
assignment.status === 'open'
|
||||
? 'secondary'
|
||||
: 'destructive'
|
||||
}
|
||||
className="w-fit text-[10px] font-normal"
|
||||
>
|
||||
{
|
||||
AssignmentStatusLabels[
|
||||
assignment.status
|
||||
]
|
||||
}
|
||||
</Badge>
|
||||
{assignment.course_class
|
||||
?.academic_term && (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="w-fit text-[10px] font-normal"
|
||||
>
|
||||
{formatAcademicTermLabel(
|
||||
assignment.course_class
|
||||
.academic_term,
|
||||
)}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<span
|
||||
className={`inline-flex items-center gap-1.5 ${deadlineTextClass(assignment.deadline)}`}
|
||||
>
|
||||
<Clock className="h-3.5 w-3.5 shrink-0" />
|
||||
{format(
|
||||
new Date(assignment.deadline),
|
||||
'd MMM yyyy, HH:mm',
|
||||
)}
|
||||
</span>
|
||||
{assignment.attachment_url &&
|
||||
assignment.attachment_name ? (
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Paperclip className="h-3.5 w-3.5 shrink-0" />
|
||||
<AttachmentPreviewDialog
|
||||
fileUrl={
|
||||
assignment.attachment_url
|
||||
}
|
||||
fileName={
|
||||
assignment.attachment_name
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="flex flex-wrap items-center gap-1.5 pt-1">
|
||||
{canSubmit ? (
|
||||
<Badge
|
||||
variant={
|
||||
mySubmission?.status ===
|
||||
'submitted'
|
||||
? 'default'
|
||||
: 'secondary'
|
||||
}
|
||||
>
|
||||
{mySubmission?.status ===
|
||||
'submitted'
|
||||
? 'Sudah Mengumpulkan'
|
||||
: 'Belum Mengumpulkan'}
|
||||
</Badge>
|
||||
) : (
|
||||
<>
|
||||
<Badge variant="secondary">
|
||||
{assignment.submissions_count.toLocaleString(
|
||||
'id-ID',
|
||||
)}{' '}
|
||||
/{' '}
|
||||
{(
|
||||
assignment
|
||||
.course_class
|
||||
?.enrollments_count ??
|
||||
0
|
||||
).toLocaleString(
|
||||
'id-ID',
|
||||
)}{' '}
|
||||
Pengumpulan (
|
||||
{percentageOf(
|
||||
assignment.submissions_count,
|
||||
assignment
|
||||
.course_class
|
||||
?.enrollments_count ??
|
||||
0,
|
||||
)}
|
||||
%)
|
||||
</Badge>
|
||||
<Badge variant="outline">
|
||||
{assignment.graded_submissions_count.toLocaleString(
|
||||
'id-ID',
|
||||
)}{' '}
|
||||
/{' '}
|
||||
{assignment.submissions_count.toLocaleString(
|
||||
'id-ID',
|
||||
)}{' '}
|
||||
Dinilai (
|
||||
{percentageOf(
|
||||
assignment.graded_submissions_count,
|
||||
assignment.submissions_count,
|
||||
)}
|
||||
%)
|
||||
</Badge>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{assignment.description && (
|
||||
<Accordion
|
||||
type="single"
|
||||
collapsible
|
||||
className="-mx-6 -mb-6 border-t"
|
||||
>
|
||||
<AccordionItem
|
||||
value="description"
|
||||
className="border-b-0"
|
||||
>
|
||||
<AccordionTrigger className="px-6 text-xs font-medium text-foreground hover:no-underline">
|
||||
Deskripsi
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-6">
|
||||
<p className="text-sm whitespace-pre-line text-foreground">
|
||||
{
|
||||
assignment.description
|
||||
}
|
||||
</p>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</InfiniteScroll>
|
||||
)}
|
||||
|
||||
<DeleteConfirmDialog
|
||||
target={deleting}
|
||||
@ -227,6 +630,10 @@ function CreateForm({
|
||||
onOpenChange: (open: boolean) => void;
|
||||
courseClasses: CourseClassOption[];
|
||||
}) {
|
||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
return (
|
||||
<FormDialog
|
||||
open={open}
|
||||
@ -234,7 +641,10 @@ function CreateForm({
|
||||
title="Tambah Tugas"
|
||||
action={store()}
|
||||
resetOnSuccess
|
||||
onSuccess={() => onOpenChange(false)}
|
||||
onSuccess={() => {
|
||||
onOpenChange(false);
|
||||
setCourseClass(null);
|
||||
}}
|
||||
>
|
||||
{({ errors }) => (
|
||||
<div className="grid gap-4">
|
||||
@ -242,22 +652,16 @@ function CreateForm({
|
||||
<Label>
|
||||
Kelas <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<input type="hidden" name="course_class_id" />
|
||||
<Select name="course_class_id">
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Pilih kelas" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{courseClasses.map((courseClass) => (
|
||||
<SelectItem
|
||||
key={courseClass.id}
|
||||
value={String(courseClass.id)}
|
||||
>
|
||||
{courseClassLabel(courseClass)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<input
|
||||
type="hidden"
|
||||
name="course_class_id"
|
||||
value={courseClass?.id ?? ''}
|
||||
/>
|
||||
<CourseClassField
|
||||
courseClasses={courseClasses}
|
||||
value={courseClass}
|
||||
onChange={setCourseClass}
|
||||
/>
|
||||
<InputError message={errors.course_class_id} />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
@ -310,6 +714,13 @@ function EditForm({
|
||||
editing: Assignment | null;
|
||||
courseClasses: CourseClassOption[];
|
||||
}) {
|
||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
||||
editing
|
||||
? (courseClasses.find((c) => c.id === editing.course_class_id) ??
|
||||
null)
|
||||
: null,
|
||||
);
|
||||
|
||||
return (
|
||||
<FormDialog
|
||||
open={open}
|
||||
@ -327,24 +738,16 @@ function EditForm({
|
||||
Kelas{' '}
|
||||
<span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
<input
|
||||
type="hidden"
|
||||
name="course_class_id"
|
||||
defaultValue={String(editing.course_class_id)}
|
||||
>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Pilih kelas" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{courseClasses.map((courseClass) => (
|
||||
<SelectItem
|
||||
key={courseClass.id}
|
||||
value={String(courseClass.id)}
|
||||
>
|
||||
{courseClassLabel(courseClass)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
value={courseClass?.id ?? ''}
|
||||
/>
|
||||
<CourseClassField
|
||||
courseClasses={courseClasses}
|
||||
value={courseClass}
|
||||
onChange={setCourseClass}
|
||||
/>
|
||||
<InputError message={errors.course_class_id} />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
@ -378,6 +781,30 @@ function EditForm({
|
||||
placeholder="Pilih tanggal batas waktu"
|
||||
error={errors.deadline}
|
||||
/>
|
||||
<div className="grid gap-2">
|
||||
<Label>
|
||||
Status{' '}
|
||||
<span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<input type="hidden" name="status" />
|
||||
<Select name="status" defaultValue={editing.status}>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Pilih status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{AssignmentStatuses.map((status) => (
|
||||
<SelectItem key={status} value={status}>
|
||||
{AssignmentStatusLabels[status]}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Menutup tugas akan mencegah mahasiswa
|
||||
mengumpulkan, terlepas dari batas waktu.
|
||||
</p>
|
||||
<InputError message={errors.status} />
|
||||
</div>
|
||||
<FileUploadField
|
||||
name="attachment"
|
||||
label="Lampiran"
|
||||
@ -391,3 +818,49 @@ function EditForm({
|
||||
</FormDialog>
|
||||
);
|
||||
}
|
||||
|
||||
function SubmitForm({
|
||||
open,
|
||||
onOpenChange,
|
||||
assignment,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
assignment: Assignment | null;
|
||||
}) {
|
||||
const mySubmission = assignment?.submissions?.[0];
|
||||
|
||||
return (
|
||||
<FormDialog
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
title="Kumpulkan Tugas"
|
||||
action={assignment ? submit(assignment.id) : ''}
|
||||
resetOnSuccess
|
||||
submitLabel="Kumpulkan"
|
||||
submittingLabel="Mengumpulkan..."
|
||||
onSuccess={() => onOpenChange(false)}
|
||||
>
|
||||
{({ errors }) => (
|
||||
<div className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="notes">Catatan</Label>
|
||||
<Textarea
|
||||
id="notes"
|
||||
name="notes"
|
||||
placeholder="Catatan untuk dosen (opsional)"
|
||||
defaultValue={mySubmission?.notes ?? ''}
|
||||
/>
|
||||
<InputError message={errors.notes} />
|
||||
</div>
|
||||
<FileUploadField
|
||||
label="File Tugas"
|
||||
existingFileName={mySubmission?.file_name}
|
||||
existingFileUrl={mySubmission?.file_url}
|
||||
error={errors.file}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</FormDialog>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,68 +1,96 @@
|
||||
import { Head, Link, router } from '@inertiajs/react';
|
||||
import type { ColumnDef } from '@tanstack/react-table';
|
||||
import { format } from 'date-fns';
|
||||
import { ArrowLeft, Pencil, Plus, Trash2 } from 'lucide-react';
|
||||
import { ArrowLeft, Save } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { DateTimeField } from '@/components/datetime-field';
|
||||
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
||||
import { FileUploadField } from '@/components/file-upload-field';
|
||||
import { FormDialog } from '@/components/form-dialog';
|
||||
import InputError from '@/components/input-error';
|
||||
import { PageHeader } from '@/components/page-header';
|
||||
import { RowActions } from '@/components/row-actions';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { usePermissions } from '@/hooks/use-permissions';
|
||||
import { index as assignmentIndex } from '@/routes/admin/academic-classes/assignments';
|
||||
import {
|
||||
destroy,
|
||||
store,
|
||||
update,
|
||||
} from '@/routes/admin/academic-classes/assignments/submissions';
|
||||
import { grade } from '@/routes/admin/academic-classes/assignments/submissions';
|
||||
import { AssignmentStatusLabels } from '@/types/assignment';
|
||||
import type { Assignment } from '@/types/assignment';
|
||||
import type { Submission, SubmissionStudent } from '@/types/submission';
|
||||
import { SubmissionStatusLabels, SubmissionStatuses } from '@/types/submission';
|
||||
import type { Submission } from '@/types/submission';
|
||||
import { SubmissionStatusLabels } from '@/types/submission';
|
||||
|
||||
type Props = {
|
||||
assignment: Assignment;
|
||||
submissions: Submission[];
|
||||
availableStudents: SubmissionStudent[];
|
||||
};
|
||||
|
||||
export default function SubmissionIndex({
|
||||
assignment,
|
||||
submissions,
|
||||
availableStudents,
|
||||
}: Props) {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Submission | null>(null);
|
||||
const [deleting, setDeleting] = useState<Submission | null>(null);
|
||||
function ScoreCell({
|
||||
assignmentId,
|
||||
submission,
|
||||
canUpdate,
|
||||
}: {
|
||||
assignmentId: number;
|
||||
submission: Submission;
|
||||
canUpdate: boolean;
|
||||
}) {
|
||||
const normalizedScore = submission.score ?? '';
|
||||
const [value, setValue] = useState(normalizedScore);
|
||||
const [savedScore, setSavedScore] = useState(normalizedScore);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
// Sync local state when the score changes externally (e.g. after save).
|
||||
if (normalizedScore !== savedScore) {
|
||||
setSavedScore(normalizedScore);
|
||||
setValue(normalizedScore);
|
||||
}
|
||||
|
||||
if (!canUpdate) {
|
||||
return <div className="text-center">{submission.score ?? '-'}</div>;
|
||||
}
|
||||
|
||||
const dirty = value !== normalizedScore;
|
||||
|
||||
function handleSave() {
|
||||
setSaving(true);
|
||||
router.patch(
|
||||
grade.url([assignmentId, submission.id]),
|
||||
{ score: value === '' ? null : value },
|
||||
{
|
||||
preserveScroll: true,
|
||||
preserveState: true,
|
||||
onFinish: () => setSaving(false),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-center gap-1">
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
step="0.01"
|
||||
value={value}
|
||||
onChange={(event) => setValue(event.target.value)}
|
||||
className="h-8 w-20 text-center"
|
||||
/>
|
||||
{dirty && (
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-8 w-8 shrink-0"
|
||||
disabled={saving}
|
||||
onClick={handleSave}
|
||||
>
|
||||
<Save className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function SubmissionIndex({ assignment, submissions }: Props) {
|
||||
const { hasPermission } = usePermissions();
|
||||
const canCreate = hasPermission('create-assignment-submissions');
|
||||
const canUpdate = hasPermission('update-assignment-submissions');
|
||||
const canDelete = hasPermission('delete-assignment-submissions');
|
||||
|
||||
function handleDelete() {
|
||||
if (!deleting) {
|
||||
return;
|
||||
}
|
||||
|
||||
router.delete(destroy([assignment.id, deleting.id]), {
|
||||
onSuccess: () => setDeleting(null),
|
||||
});
|
||||
}
|
||||
|
||||
const columns: ColumnDef<Submission>[] = [
|
||||
{
|
||||
@ -122,46 +150,19 @@ export default function SubmissionIndex({
|
||||
accessorKey: 'score',
|
||||
header: () => <span className="block text-center">Nilai</span>,
|
||||
meta: {
|
||||
className: 'w-[90px] text-center',
|
||||
headerClassName: 'w-[90px] text-center',
|
||||
className: 'w-[140px] text-center',
|
||||
headerClassName: 'w-[140px] text-center',
|
||||
},
|
||||
cell: ({ row }) => (
|
||||
<div className="text-center">{row.original.score ?? '-'}</div>
|
||||
<ScoreCell
|
||||
assignmentId={assignment.id}
|
||||
submission={row.original}
|
||||
canUpdate={canUpdate}
|
||||
/>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
if (canUpdate || canDelete) {
|
||||
columns.push({
|
||||
id: 'actions',
|
||||
header: () => <span className="block text-center">Aksi</span>,
|
||||
meta: {
|
||||
className: 'w-[100px] text-center',
|
||||
headerClassName: 'w-[100px] text-center',
|
||||
},
|
||||
cell: ({ row }) => (
|
||||
<RowActions
|
||||
actions={[
|
||||
{
|
||||
label: 'Edit',
|
||||
icon: <Pencil className="h-4 w-4" />,
|
||||
show: canUpdate,
|
||||
onClick: () => setEditing(row.original),
|
||||
},
|
||||
{
|
||||
label: 'Hapus',
|
||||
icon: (
|
||||
<Trash2 className="h-4 w-4 text-destructive" />
|
||||
),
|
||||
show: canDelete,
|
||||
onClick: () => setDeleting(row.original),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head title="Pengumpulan Tugas" />
|
||||
@ -180,8 +181,17 @@ export default function SubmissionIndex({
|
||||
/>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardHeader className="flex flex-row items-start justify-between gap-2">
|
||||
<CardTitle>{assignment.title}</CardTitle>
|
||||
<Badge
|
||||
variant={
|
||||
assignment.status === 'open'
|
||||
? 'secondary'
|
||||
: 'destructive'
|
||||
}
|
||||
>
|
||||
{AssignmentStatusLabels[assignment.status]}
|
||||
</Badge>
|
||||
</CardHeader>
|
||||
<CardContent className="grid gap-1 text-sm text-muted-foreground">
|
||||
<p>
|
||||
@ -199,237 +209,10 @@ export default function SubmissionIndex({
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-lg font-semibold">
|
||||
Daftar Pengumpulan
|
||||
</h2>
|
||||
{canCreate && (
|
||||
<Button
|
||||
onClick={() => setCreateOpen(true)}
|
||||
disabled={availableStudents.length === 0}
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
Tambah Pengumpulan
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<h2 className="text-lg font-semibold">Daftar Pengumpulan</h2>
|
||||
|
||||
<DataTable columns={columns} data={submissions} />
|
||||
|
||||
<CreateForm
|
||||
open={createOpen}
|
||||
onOpenChange={setCreateOpen}
|
||||
assignmentId={assignment.id}
|
||||
availableStudents={availableStudents}
|
||||
/>
|
||||
|
||||
<EditForm
|
||||
key={editing?.id}
|
||||
open={editing !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
setEditing(null);
|
||||
}
|
||||
}}
|
||||
assignmentId={assignment.id}
|
||||
editing={editing}
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
target={deleting}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
setDeleting(null);
|
||||
}
|
||||
}}
|
||||
title="Hapus Pengumpulan"
|
||||
description={(submission) =>
|
||||
`Apakah Anda yakin ingin menghapus pengumpulan "${submission.student?.user?.profile?.full_name ?? 'mahasiswa ini'}"? Tindakan ini tidak dapat dibatalkan.`
|
||||
}
|
||||
onConfirm={handleDelete}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function CreateForm({
|
||||
open,
|
||||
onOpenChange,
|
||||
assignmentId,
|
||||
availableStudents,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
assignmentId: number;
|
||||
availableStudents: SubmissionStudent[];
|
||||
}) {
|
||||
return (
|
||||
<FormDialog
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
title="Tambah Pengumpulan"
|
||||
action={store(assignmentId)}
|
||||
resetOnSuccess
|
||||
onSuccess={() => onOpenChange(false)}
|
||||
>
|
||||
{({ errors }) => (
|
||||
<div className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label>
|
||||
Mahasiswa{' '}
|
||||
<span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<input type="hidden" name="student_id" />
|
||||
<Select name="student_id">
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Pilih mahasiswa" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{availableStudents.map((student) => (
|
||||
<SelectItem
|
||||
key={student.id}
|
||||
value={String(student.id)}
|
||||
>
|
||||
{student.user?.profile?.full_name ??
|
||||
'N/A'}{' '}
|
||||
- {student.student_number}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<InputError message={errors.student_id} />
|
||||
</div>
|
||||
<SubmissionFields
|
||||
errors={errors}
|
||||
resetKey={open ? 'open' : 'closed'}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</FormDialog>
|
||||
);
|
||||
}
|
||||
|
||||
function EditForm({
|
||||
open,
|
||||
onOpenChange,
|
||||
assignmentId,
|
||||
editing,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
assignmentId: number;
|
||||
editing: Submission | null;
|
||||
}) {
|
||||
return (
|
||||
<FormDialog
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
title="Edit Pengumpulan"
|
||||
action={editing ? update([assignmentId, editing.id]) : ''}
|
||||
resetOnSuccess
|
||||
onSuccess={() => onOpenChange(false)}
|
||||
>
|
||||
{({ errors }) =>
|
||||
editing && (
|
||||
<div className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label>Mahasiswa</Label>
|
||||
<p className="text-sm font-medium">
|
||||
{editing.student?.user?.profile?.full_name ??
|
||||
'N/A'}{' '}
|
||||
- {editing.student?.student_number}
|
||||
</p>
|
||||
</div>
|
||||
<SubmissionFields errors={errors} editing={editing} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</FormDialog>
|
||||
);
|
||||
}
|
||||
|
||||
function SubmissionFields({
|
||||
errors,
|
||||
editing,
|
||||
resetKey,
|
||||
}: {
|
||||
errors: Record<string, string>;
|
||||
editing?: Submission;
|
||||
resetKey?: string;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="notes">Catatan</Label>
|
||||
<Textarea
|
||||
id="notes"
|
||||
name="notes"
|
||||
placeholder="Catatan dari mahasiswa"
|
||||
defaultValue={editing?.notes ?? ''}
|
||||
/>
|
||||
<InputError message={errors.notes} />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label>
|
||||
Status <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<input type="hidden" name="status" />
|
||||
<Select
|
||||
name="status"
|
||||
defaultValue={editing?.status ?? 'not_submitted'}
|
||||
>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Pilih status" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{SubmissionStatuses.map((status) => (
|
||||
<SelectItem key={status} value={status}>
|
||||
{SubmissionStatusLabels[status]}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<InputError message={errors.status} />
|
||||
</div>
|
||||
<DateTimeField
|
||||
label="Waktu Kumpul"
|
||||
name="submitted_at"
|
||||
defaultValue={editing?.submitted_at}
|
||||
placeholder="Pilih waktu kumpul"
|
||||
error={errors.submitted_at}
|
||||
/>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="score">Nilai</Label>
|
||||
<Input
|
||||
id="score"
|
||||
name="score"
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
step="0.01"
|
||||
placeholder="0 - 100"
|
||||
defaultValue={editing?.score ?? undefined}
|
||||
/>
|
||||
<InputError message={errors.score} />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="lecturer_feedback">Feedback Dosen</Label>
|
||||
<Textarea
|
||||
id="lecturer_feedback"
|
||||
name="lecturer_feedback"
|
||||
placeholder="Masukkan feedback untuk mahasiswa"
|
||||
defaultValue={editing?.lecturer_feedback ?? ''}
|
||||
/>
|
||||
<InputError message={errors.lecturer_feedback} />
|
||||
</div>
|
||||
<FileUploadField
|
||||
key={resetKey}
|
||||
label="File Pengumpulan"
|
||||
existingFileName={editing?.file_name}
|
||||
existingFileUrl={editing?.file_url}
|
||||
error={errors.file}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@ -0,0 +1,255 @@
|
||||
import { Head, Link, router } from '@inertiajs/react';
|
||||
import { format } from 'date-fns';
|
||||
import { ArrowLeft, ClipboardCheck, Pencil, Plus, Trash2 } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
||||
import { PageHeader } from '@/components/page-header';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { usePermissions } from '@/hooks/use-permissions';
|
||||
import {
|
||||
destroy,
|
||||
index as attendanceIndex,
|
||||
session,
|
||||
} from '@/routes/admin/academic-classes/attendances';
|
||||
import { formatAcademicTermLabel } from '@/types/academic-term';
|
||||
import type {
|
||||
AttendanceCourseClass,
|
||||
AttendanceSession,
|
||||
} from '@/types/attendance';
|
||||
|
||||
type Props = {
|
||||
courseClass: AttendanceCourseClass;
|
||||
sessions: AttendanceSession[];
|
||||
nextMeetingNumber: number;
|
||||
};
|
||||
|
||||
function courseClassLabel(courseClass: AttendanceCourseClass): string {
|
||||
return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`;
|
||||
}
|
||||
|
||||
export default function AttendanceCourseClass({
|
||||
courseClass,
|
||||
sessions,
|
||||
nextMeetingNumber,
|
||||
}: Props) {
|
||||
const [newSessionOpen, setNewSessionOpen] = useState(false);
|
||||
const [deleting, setDeleting] = useState<AttendanceSession | null>(null);
|
||||
const { hasPermission } = usePermissions();
|
||||
const canCreate = hasPermission('create-attendances');
|
||||
const canDelete = hasPermission('delete-attendances');
|
||||
|
||||
function handleDelete() {
|
||||
if (!deleting) {
|
||||
return;
|
||||
}
|
||||
|
||||
router.delete(destroy([courseClass.id, deleting.meeting_number]).url, {
|
||||
onSuccess: () => setDeleting(null),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head title="Kehadiran" />
|
||||
|
||||
<div className="flex h-full flex-1 flex-col gap-6 p-4 md:p-6">
|
||||
<PageHeader
|
||||
title={courseClassLabel(courseClass)}
|
||||
description={
|
||||
courseClass.academic_term && (
|
||||
<Badge variant="outline" className="mt-1 w-fit">
|
||||
{formatAcademicTermLabel(
|
||||
courseClass.academic_term,
|
||||
)}
|
||||
</Badge>
|
||||
)
|
||||
}
|
||||
actions={
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="outline" asChild>
|
||||
<Link href={attendanceIndex.url()}>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
Kembali
|
||||
</Link>
|
||||
</Button>
|
||||
{canCreate && (
|
||||
<Button onClick={() => setNewSessionOpen(true)}>
|
||||
<Plus className="h-4 w-4" />
|
||||
Tambah Pertemuan
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
{sessions.length === 0 ? (
|
||||
<p className="rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground">
|
||||
Belum ada pertemuan yang tercatat.
|
||||
</p>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{sessions.map((item) => (
|
||||
<Card key={item.meeting_number}>
|
||||
<CardHeader className="flex flex-row items-start justify-between gap-2">
|
||||
<CardTitle className="text-sm leading-tight">
|
||||
Pertemuan ke-{item.meeting_number}
|
||||
</CardTitle>
|
||||
<Badge variant="secondary">
|
||||
{item.present_count}/{item.total_count}{' '}
|
||||
Hadir
|
||||
</Badge>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-2">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{format(
|
||||
new Date(item.date),
|
||||
'd MMM yyyy',
|
||||
)}
|
||||
</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
asChild
|
||||
>
|
||||
<Link
|
||||
href={
|
||||
session([
|
||||
courseClass.id,
|
||||
item.meeting_number,
|
||||
]).url
|
||||
}
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
Lihat / Edit
|
||||
</Link>
|
||||
</Button>
|
||||
{canDelete && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
setDeleting(item)
|
||||
}
|
||||
>
|
||||
<Trash2 className="h-4 w-4 text-destructive" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<NewSessionDialog
|
||||
open={newSessionOpen}
|
||||
onOpenChange={setNewSessionOpen}
|
||||
courseClassId={courseClass.id}
|
||||
defaultMeetingNumber={nextMeetingNumber}
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
target={deleting}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
setDeleting(null);
|
||||
}
|
||||
}}
|
||||
title="Hapus Sesi Kehadiran"
|
||||
description={(item) =>
|
||||
`Apakah Anda yakin ingin menghapus seluruh data kehadiran pertemuan ke-${item.meeting_number}? Tindakan ini tidak dapat dibatalkan.`
|
||||
}
|
||||
onConfirm={handleDelete}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function NewSessionDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
courseClassId,
|
||||
defaultMeetingNumber,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
courseClassId: number;
|
||||
defaultMeetingNumber: number;
|
||||
}) {
|
||||
const [meetingNumber, setMeetingNumber] = useState(
|
||||
String(defaultMeetingNumber),
|
||||
);
|
||||
|
||||
function handleOpenSession() {
|
||||
if (!meetingNumber) {
|
||||
return;
|
||||
}
|
||||
|
||||
router.get(session([courseClassId, Number(meetingNumber)]).url);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(value) => {
|
||||
onOpenChange(value);
|
||||
|
||||
if (!value) {
|
||||
setMeetingNumber(String(defaultMeetingNumber));
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Tambah Pertemuan</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-4 py-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="meeting_number">
|
||||
Pertemuan Ke-{' '}
|
||||
<span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="meeting_number"
|
||||
type="number"
|
||||
min={1}
|
||||
value={meetingNumber}
|
||||
onChange={(e) => setMeetingNumber(e.target.value)}
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => onOpenChange(false)}
|
||||
>
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={!meetingNumber}
|
||||
onClick={handleOpenSession}
|
||||
>
|
||||
<ClipboardCheck className="h-4 w-4" />
|
||||
Buka Kehadiran
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@ -1,60 +1,73 @@
|
||||
import { Head, Link, router } from '@inertiajs/react';
|
||||
import { format } from 'date-fns';
|
||||
import { ClipboardCheck, Pencil, Plus, Trash2, X } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
||||
import { Head, Link } from '@inertiajs/react';
|
||||
import type { FilterField } from '@/components/filter-dialog';
|
||||
import { FilterDialog } from '@/components/filter-dialog';
|
||||
import { PageHeader } from '@/components/page-header';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { useServerTable } from '@/hooks/use-server-table';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { usePermissions } from '@/hooks/use-permissions';
|
||||
import { destroy, session } from '@/routes/admin/academic-classes/attendances';
|
||||
import type {
|
||||
AttendanceCourseClass,
|
||||
AttendanceSession,
|
||||
} from '@/types/attendance';
|
||||
index as attendanceIndex,
|
||||
show,
|
||||
} from '@/routes/admin/academic-classes/attendances';
|
||||
import { formatAcademicTermLabel } from '@/types/academic-term';
|
||||
import type { AttendanceCourseClassOverview } from '@/types/attendance';
|
||||
|
||||
type Props = {
|
||||
sessions: AttendanceSession[];
|
||||
courseClasses: AttendanceCourseClass[];
|
||||
type AcademicTermOption = {
|
||||
id: number;
|
||||
academic_year: string;
|
||||
semester: string;
|
||||
};
|
||||
|
||||
function courseClassLabel(courseClass: AttendanceCourseClass): string {
|
||||
type Props = {
|
||||
courseClasses: AttendanceCourseClassOverview[];
|
||||
academicTerms: AcademicTermOption[];
|
||||
filters: {
|
||||
academic_term_id?: string;
|
||||
};
|
||||
};
|
||||
|
||||
function courseClassLabel(courseClass: AttendanceCourseClassOverview): string {
|
||||
return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`;
|
||||
}
|
||||
|
||||
export default function AttendanceIndex({ sessions, courseClasses }: Props) {
|
||||
const [newSessionOpen, setNewSessionOpen] = useState(false);
|
||||
const [deleting, setDeleting] = useState<AttendanceSession | null>(null);
|
||||
const { hasPermission } = usePermissions();
|
||||
const canCreate = hasPermission('create-attendances');
|
||||
const canDelete = hasPermission('delete-attendances');
|
||||
export default function AttendanceIndex({
|
||||
courseClasses,
|
||||
academicTerms,
|
||||
filters,
|
||||
}: Props) {
|
||||
const filterFields: FilterField[] = [
|
||||
{
|
||||
key: 'academic_term_id',
|
||||
label: 'Periode Akademik',
|
||||
options: academicTerms.map((term) => ({
|
||||
value: String(term.id),
|
||||
label: formatAcademicTermLabel(term),
|
||||
})),
|
||||
},
|
||||
];
|
||||
|
||||
function handleDelete() {
|
||||
if (!deleting || deleting.meeting_number === null) {
|
||||
return;
|
||||
}
|
||||
const { applyFilters } = useServerTable({
|
||||
route: () => attendanceIndex.url(),
|
||||
pagination: {
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
per_page: 999999,
|
||||
total: courseClasses.length,
|
||||
},
|
||||
filters,
|
||||
});
|
||||
|
||||
router.delete(
|
||||
destroy([deleting.course_class_id, deleting.meeting_number]).url,
|
||||
{ onSuccess: () => setDeleting(null) },
|
||||
);
|
||||
function handleApplyFilters(newFilters: Record<string, string>) {
|
||||
// Tanpa `academic_term_id` eksplisit, backend akan kembali ke
|
||||
// periode aktif, jadi menghapus filter ini perlu dikirim eksplisit
|
||||
// alih-alih hanya menghilangkan key-nya.
|
||||
const clearedAcademicTerm =
|
||||
Boolean(filters.academic_term_id) && !newFilters.academic_term_id;
|
||||
|
||||
applyFilters({
|
||||
...newFilters,
|
||||
...(clearedAcademicTerm ? { academic_term_id: '' } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
@ -65,218 +78,65 @@ export default function AttendanceIndex({ sessions, courseClasses }: Props) {
|
||||
<PageHeader
|
||||
title="Kehadiran"
|
||||
actions={
|
||||
canCreate && (
|
||||
<Button onClick={() => setNewSessionOpen(true)}>
|
||||
<Plus className="h-4 w-4" />
|
||||
Ambil Kehadiran
|
||||
</Button>
|
||||
)
|
||||
<FilterDialog
|
||||
fields={filterFields}
|
||||
activeFilters={filters}
|
||||
onApply={handleApplyFilters}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
{sessions.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Belum ada data kehadiran.
|
||||
{courseClasses.length === 0 ? (
|
||||
<p className="rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground">
|
||||
Tidak ada kelas untuk periode ini.
|
||||
</p>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{sessions.map((item) => {
|
||||
const key = `${item.course_class_id}-${item.meeting_number}-${item.date}`;
|
||||
const canOpen = item.meeting_number !== null;
|
||||
|
||||
return (
|
||||
<Card key={key}>
|
||||
<CardHeader className="flex flex-row items-start justify-between gap-2">
|
||||
<CardTitle className="text-sm leading-tight">
|
||||
{item.course_class
|
||||
? courseClassLabel(
|
||||
item.course_class,
|
||||
)
|
||||
: '-'}
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3">
|
||||
{courseClasses.map((courseClass) => (
|
||||
<Link
|
||||
key={courseClass.id}
|
||||
href={show(courseClass.id).url}
|
||||
>
|
||||
<Card className="h-full transition-colors hover:border-primary">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base leading-tight">
|
||||
{courseClassLabel(courseClass)}
|
||||
</CardTitle>
|
||||
<Badge variant="secondary">
|
||||
{item.present_count}/
|
||||
{item.total_count} Hadir
|
||||
</Badge>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-2">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Pertemuan ke-
|
||||
{item.meeting_number ?? '-'}{' '}
|
||||
·{' '}
|
||||
{format(
|
||||
new Date(item.date),
|
||||
'd MMM yyyy',
|
||||
)}
|
||||
</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<Badge
|
||||
variant="secondary"
|
||||
className="w-fit text-[10px] font-normal"
|
||||
>
|
||||
{courseClass.meetings_count}{' '}
|
||||
Pertemuan
|
||||
</Badge>
|
||||
<Badge
|
||||
variant="outline"
|
||||
size="sm"
|
||||
asChild
|
||||
disabled={!canOpen}
|
||||
className="w-fit text-[10px] font-normal"
|
||||
>
|
||||
{canOpen ? (
|
||||
<Link
|
||||
href={
|
||||
session([
|
||||
item.course_class_id,
|
||||
item.meeting_number as number,
|
||||
]).url
|
||||
}
|
||||
{courseClass.enrollments_count}{' '}
|
||||
Mahasiswa
|
||||
</Badge>
|
||||
{courseClass.academic_term && (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="w-fit text-[10px] font-normal"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
Lihat / Edit
|
||||
</Link>
|
||||
) : (
|
||||
<span>
|
||||
<Pencil className="h-4 w-4" />
|
||||
Lihat / Edit
|
||||
</span>
|
||||
{formatAcademicTermLabel(
|
||||
courseClass.academic_term,
|
||||
)}
|
||||
</Button>
|
||||
{canDelete && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={!canOpen}
|
||||
onClick={() =>
|
||||
setDeleting(item)
|
||||
}
|
||||
>
|
||||
<Trash2 className="h-4 w-4 text-destructive" />
|
||||
</Button>
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<NewSessionDialog
|
||||
open={newSessionOpen}
|
||||
onOpenChange={setNewSessionOpen}
|
||||
courseClasses={courseClasses}
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
target={deleting}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
setDeleting(null);
|
||||
}
|
||||
}}
|
||||
title="Hapus Sesi Kehadiran"
|
||||
description={(item) =>
|
||||
`Apakah Anda yakin ingin menghapus seluruh data kehadiran pertemuan ke-${item.meeting_number} untuk kelas ini? Tindakan ini tidak dapat dibatalkan.`
|
||||
}
|
||||
onConfirm={handleDelete}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function NewSessionDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
courseClasses,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
courseClasses: AttendanceCourseClass[];
|
||||
}) {
|
||||
const [courseClassId, setCourseClassId] = useState('');
|
||||
const [meetingNumber, setMeetingNumber] = useState('');
|
||||
|
||||
function reset() {
|
||||
setCourseClassId('');
|
||||
setMeetingNumber('');
|
||||
}
|
||||
|
||||
function handleOpenSession() {
|
||||
if (!courseClassId || !meetingNumber) {
|
||||
return;
|
||||
}
|
||||
|
||||
router.get(session([Number(courseClassId), Number(meetingNumber)]).url);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(value) => {
|
||||
onOpenChange(value);
|
||||
|
||||
if (!value) {
|
||||
reset();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Ambil Kehadiran</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-4 py-4">
|
||||
<div className="grid gap-2">
|
||||
<Label>
|
||||
Kelas <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
value={courseClassId}
|
||||
onValueChange={setCourseClassId}
|
||||
>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Pilih kelas" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{courseClasses.map((courseClass) => (
|
||||
<SelectItem
|
||||
key={courseClass.id}
|
||||
value={String(courseClass.id)}
|
||||
>
|
||||
{courseClassLabel(courseClass)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="meeting_number">
|
||||
Pertemuan Ke-{' '}
|
||||
<span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="meeting_number"
|
||||
type="number"
|
||||
min={1}
|
||||
placeholder="Contoh: 1"
|
||||
value={meetingNumber}
|
||||
onChange={(e) => setMeetingNumber(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => onOpenChange(false)}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={!courseClassId || !meetingNumber}
|
||||
onClick={handleOpenSession}
|
||||
>
|
||||
<ClipboardCheck className="h-4 w-4" />
|
||||
Buka Kehadiran
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
150
resources/js/pages/admin/academic-classes/attendances/mine.tsx
Normal file
150
resources/js/pages/admin/academic-classes/attendances/mine.tsx
Normal file
@ -0,0 +1,150 @@
|
||||
import { Head } from '@inertiajs/react';
|
||||
import { format } from 'date-fns';
|
||||
import { PageHeader } from '@/components/page-header';
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionItem,
|
||||
AccordionTrigger,
|
||||
} from '@/components/ui/accordion';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { formatAcademicTermLabel } from '@/types/academic-term';
|
||||
import type { AttendanceClassSummary } from '@/types/attendance';
|
||||
import { AttendanceStatusLabels } from '@/types/attendance';
|
||||
|
||||
type Props = {
|
||||
summaries: AttendanceClassSummary[];
|
||||
};
|
||||
|
||||
function courseClassLabel(
|
||||
courseClass: AttendanceClassSummary['course_class'],
|
||||
): string {
|
||||
return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`;
|
||||
}
|
||||
|
||||
function percentageOf(part: number, total: number): number {
|
||||
return total > 0 ? Math.round((part / total) * 100) : 0;
|
||||
}
|
||||
|
||||
export default function MyAttendance({ summaries }: Props) {
|
||||
return (
|
||||
<>
|
||||
<Head title="Riwayat Kehadiran" />
|
||||
|
||||
<div className="flex h-full flex-1 flex-col gap-6 p-4 md:p-6">
|
||||
<PageHeader title="Riwayat Kehadiran" />
|
||||
|
||||
{summaries.length === 0 ? (
|
||||
<p className="rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground">
|
||||
Belum ada kelas yang terdaftar.
|
||||
</p>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3">
|
||||
{summaries.map((summary) => (
|
||||
<Card key={summary.course_class.id}>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base leading-tight">
|
||||
{courseClassLabel(summary.course_class)}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-2">
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<Badge
|
||||
variant={
|
||||
percentageOf(
|
||||
summary.present_count,
|
||||
summary.total_count,
|
||||
) >= 75
|
||||
? 'secondary'
|
||||
: 'destructive'
|
||||
}
|
||||
className="w-fit text-[10px] font-normal"
|
||||
>
|
||||
Hadir {summary.present_count} /{' '}
|
||||
{summary.total_count} (
|
||||
{percentageOf(
|
||||
summary.present_count,
|
||||
summary.total_count,
|
||||
)}
|
||||
%)
|
||||
</Badge>
|
||||
{summary.course_class.academic_term && (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="w-fit text-[10px] font-normal"
|
||||
>
|
||||
{formatAcademicTermLabel(
|
||||
summary.course_class
|
||||
.academic_term,
|
||||
)}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{summary.records.length > 0 && (
|
||||
<Accordion
|
||||
type="single"
|
||||
collapsible
|
||||
className="-mx-6 -mb-6 border-t"
|
||||
>
|
||||
<AccordionItem
|
||||
value="records"
|
||||
className="border-b-0"
|
||||
>
|
||||
<AccordionTrigger className="px-6 text-xs font-medium text-foreground hover:no-underline">
|
||||
Detail Pertemuan
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-6">
|
||||
<div className="flex flex-col divide-y">
|
||||
{summary.records.map(
|
||||
(record) => (
|
||||
<div
|
||||
key={`${record.course_class_id}-${record.meeting_number}`}
|
||||
className="flex items-center justify-between gap-2 py-2 text-sm"
|
||||
>
|
||||
<span className="text-muted-foreground">
|
||||
Pertemuan
|
||||
ke-
|
||||
{record.meeting_number ??
|
||||
'-'}{' '}
|
||||
·{' '}
|
||||
{format(
|
||||
new Date(
|
||||
record.date,
|
||||
),
|
||||
'd MMM yyyy',
|
||||
)}
|
||||
</span>
|
||||
<Badge
|
||||
variant={
|
||||
record.status ===
|
||||
'present'
|
||||
? 'default'
|
||||
: 'secondary'
|
||||
}
|
||||
>
|
||||
{
|
||||
AttendanceStatusLabels[
|
||||
record
|
||||
.status
|
||||
]
|
||||
}
|
||||
</Badge>
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@ -8,10 +8,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { usePermissions } from '@/hooks/use-permissions';
|
||||
import {
|
||||
index as attendanceIndex,
|
||||
store,
|
||||
} from '@/routes/admin/academic-classes/attendances';
|
||||
import { show, store } from '@/routes/admin/academic-classes/attendances';
|
||||
import type {
|
||||
AttendanceCourseClass,
|
||||
AttendanceRosterEntry,
|
||||
@ -89,7 +86,7 @@ export default function AttendanceSession({
|
||||
title="Kehadiran"
|
||||
actions={
|
||||
<Button variant="outline" asChild>
|
||||
<Link href={attendanceIndex.url()}>
|
||||
<Link href={show(courseClass.id).url}>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
Kembali
|
||||
</Link>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import type { ColumnDef } from '@tanstack/react-table';
|
||||
import { Paperclip, Pencil, Trash2 } from 'lucide-react';
|
||||
import { Pencil, Trash2 } from 'lucide-react';
|
||||
import { AttachmentPreviewDialog } from '@/components/attachment-preview-dialog';
|
||||
import { RowActions } from '@/components/row-actions';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import type { Material } from '@/types/material';
|
||||
@ -69,20 +70,15 @@ export function createMaterialColumns(
|
||||
cell: ({ row }) => {
|
||||
const material = row.original;
|
||||
|
||||
if (!material.file_url) {
|
||||
if (!material.file_url || !material.file_name) {
|
||||
return <span className="text-muted-foreground">-</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<a
|
||||
href={material.file_url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-flex items-center gap-1 text-primary underline underline-offset-4 hover:text-primary/80"
|
||||
>
|
||||
<Paperclip className="h-3.5 w-3.5" />
|
||||
{material.file_name}
|
||||
</a>
|
||||
<AttachmentPreviewDialog
|
||||
fileUrl={material.file_url}
|
||||
fileName={material.file_name}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
@ -5,21 +5,25 @@ import type { PaginationState } from '@/components/data-table';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
||||
import { FileUploadField } from '@/components/file-upload-field';
|
||||
import type { FilterField } from '@/components/filter-dialog';
|
||||
import type { FilterOptionGroup } from '@/components/filter-dialog';
|
||||
import { FilterDialog } from '@/components/filter-dialog';
|
||||
import { FormDialog } from '@/components/form-dialog';
|
||||
import InputError from '@/components/input-error';
|
||||
import { PageHeader } from '@/components/page-header';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Combobox,
|
||||
ComboboxCollection,
|
||||
ComboboxContent,
|
||||
ComboboxEmpty,
|
||||
ComboboxGroup,
|
||||
ComboboxInput,
|
||||
ComboboxItem,
|
||||
ComboboxLabel,
|
||||
ComboboxList,
|
||||
} from '@/components/ui/combobox';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { usePermissions } from '@/hooks/use-permissions';
|
||||
import { useServerTable } from '@/hooks/use-server-table';
|
||||
@ -34,9 +38,17 @@ import { createMaterialColumns } from './columns';
|
||||
|
||||
type CourseClassOption = {
|
||||
id: number;
|
||||
course: { id: number; code: string; name: string } | null;
|
||||
course: {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
semester_number: number | null;
|
||||
department: { id: number; name: string } | null;
|
||||
} | null;
|
||||
};
|
||||
|
||||
type CourseClassGroup = { value: string; items: CourseClassOption[] };
|
||||
|
||||
type Props = {
|
||||
materials: {
|
||||
data: Material[];
|
||||
@ -53,7 +65,80 @@ type Props = {
|
||||
};
|
||||
|
||||
function courseClassLabel(courseClass: CourseClassOption): string {
|
||||
return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`;
|
||||
return `${courseClass.course?.code ?? ''} - ${courseClass.course?.name ?? ''}`;
|
||||
}
|
||||
|
||||
function groupCourseClassesByDepartment(
|
||||
options: CourseClassOption[],
|
||||
): CourseClassGroup[] {
|
||||
const groups: CourseClassGroup[] = [];
|
||||
let currentKey: string | null = null;
|
||||
|
||||
for (const option of options) {
|
||||
const key = `${option.course?.department?.name ?? 'Tanpa Jurusan'} — Semester ${option.course?.semester_number ?? 'Tidak ditentukan'}`;
|
||||
|
||||
if (key !== currentKey) {
|
||||
currentKey = key;
|
||||
groups.push({ value: key, items: [] });
|
||||
}
|
||||
|
||||
groups[groups.length - 1].items.push(option);
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
function CourseClassField({
|
||||
courseClasses,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
courseClasses: CourseClassOption[];
|
||||
value: CourseClassOption | null;
|
||||
onChange: (value: CourseClassOption | null) => void;
|
||||
}) {
|
||||
const groups = groupCourseClassesByDepartment(courseClasses);
|
||||
|
||||
return (
|
||||
<Combobox
|
||||
items={groups}
|
||||
value={value}
|
||||
onValueChange={onChange}
|
||||
itemToStringLabel={courseClassLabel}
|
||||
isItemEqualToValue={(a, b) => a.id === b.id}
|
||||
>
|
||||
<ComboboxInput placeholder="Pilih kelas" className="w-full" />
|
||||
<ComboboxContent>
|
||||
<ComboboxEmpty>Kelas tidak ditemukan.</ComboboxEmpty>
|
||||
<ComboboxList>
|
||||
{(group: CourseClassGroup) => (
|
||||
<ComboboxGroup key={group.value} items={group.items}>
|
||||
<ComboboxLabel>{group.value}</ComboboxLabel>
|
||||
<ComboboxCollection>
|
||||
{(option: CourseClassOption) => (
|
||||
<ComboboxItem key={option.id} value={option}>
|
||||
{courseClassLabel(option)}
|
||||
</ComboboxItem>
|
||||
)}
|
||||
</ComboboxCollection>
|
||||
</ComboboxGroup>
|
||||
)}
|
||||
</ComboboxList>
|
||||
</ComboboxContent>
|
||||
</Combobox>
|
||||
);
|
||||
}
|
||||
|
||||
function courseClassFilterGroups(
|
||||
courseClasses: CourseClassOption[],
|
||||
): FilterOptionGroup[] {
|
||||
return groupCourseClassesByDepartment(courseClasses).map((group) => ({
|
||||
label: group.value,
|
||||
options: group.items.map((option) => ({
|
||||
value: String(option.id),
|
||||
label: courseClassLabel(option),
|
||||
})),
|
||||
}));
|
||||
}
|
||||
|
||||
export default function MaterialIndex({
|
||||
@ -70,14 +155,12 @@ export default function MaterialIndex({
|
||||
const canUpdate = hasPermission('update-materials');
|
||||
const canDelete = hasPermission('delete-materials');
|
||||
|
||||
const filterFields: FilterField[] = [
|
||||
const filterFields = [
|
||||
{
|
||||
key: 'course_class_id',
|
||||
label: 'Kelas',
|
||||
options: courseClasses.map((courseClass) => ({
|
||||
value: String(courseClass.id),
|
||||
label: courseClassLabel(courseClass),
|
||||
})),
|
||||
type: 'combobox' as const,
|
||||
groups: courseClassFilterGroups(courseClasses),
|
||||
},
|
||||
];
|
||||
|
||||
@ -224,6 +307,10 @@ function CreateForm({
|
||||
onOpenChange: (open: boolean) => void;
|
||||
courseClasses: CourseClassOption[];
|
||||
}) {
|
||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
return (
|
||||
<FormDialog
|
||||
open={open}
|
||||
@ -231,7 +318,10 @@ function CreateForm({
|
||||
title="Tambah Materi"
|
||||
action={store()}
|
||||
resetOnSuccess
|
||||
onSuccess={() => onOpenChange(false)}
|
||||
onSuccess={() => {
|
||||
onOpenChange(false);
|
||||
setCourseClass(null);
|
||||
}}
|
||||
>
|
||||
{({ errors }) => (
|
||||
<div className="grid gap-4">
|
||||
@ -239,22 +329,16 @@ function CreateForm({
|
||||
<Label>
|
||||
Kelas <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<input type="hidden" name="course_class_id" />
|
||||
<Select name="course_class_id">
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Pilih kelas" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{courseClasses.map((courseClass) => (
|
||||
<SelectItem
|
||||
key={courseClass.id}
|
||||
value={String(courseClass.id)}
|
||||
>
|
||||
{courseClassLabel(courseClass)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<input
|
||||
type="hidden"
|
||||
name="course_class_id"
|
||||
value={courseClass?.id ?? ''}
|
||||
/>
|
||||
<CourseClassField
|
||||
courseClasses={courseClasses}
|
||||
value={courseClass}
|
||||
onChange={setCourseClass}
|
||||
/>
|
||||
<InputError message={errors.course_class_id} />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
@ -310,6 +394,13 @@ function EditForm({
|
||||
editing: Material | null;
|
||||
courseClasses: CourseClassOption[];
|
||||
}) {
|
||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
||||
editing
|
||||
? (courseClasses.find((c) => c.id === editing.course_class_id) ??
|
||||
null)
|
||||
: null,
|
||||
);
|
||||
|
||||
return (
|
||||
<FormDialog
|
||||
open={open}
|
||||
@ -327,24 +418,16 @@ function EditForm({
|
||||
Kelas{' '}
|
||||
<span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
<input
|
||||
type="hidden"
|
||||
name="course_class_id"
|
||||
defaultValue={String(editing.course_class_id)}
|
||||
>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Pilih kelas" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{courseClasses.map((courseClass) => (
|
||||
<SelectItem
|
||||
key={courseClass.id}
|
||||
value={String(courseClass.id)}
|
||||
>
|
||||
{courseClassLabel(courseClass)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
value={courseClass?.id ?? ''}
|
||||
/>
|
||||
<CourseClassField
|
||||
courseClasses={courseClasses}
|
||||
value={courseClass}
|
||||
onChange={setCourseClass}
|
||||
/>
|
||||
<InputError message={errors.course_class_id} />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
|
||||
@ -1,4 +1,17 @@
|
||||
import { Head, router } from '@inertiajs/react';
|
||||
import {
|
||||
Clock,
|
||||
MapPin,
|
||||
Pencil,
|
||||
Plus,
|
||||
Trash2,
|
||||
User,
|
||||
Video,
|
||||
} from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
||||
import type { FilterField } from '@/components/filter-dialog';
|
||||
import { FilterDialog } from '@/components/filter-dialog';
|
||||
import { FormDialog } from '@/components/form-dialog';
|
||||
import InputError from '@/components/input-error';
|
||||
import { PageHeader } from '@/components/page-header';
|
||||
@ -6,6 +19,17 @@ import { RowActions } from '@/components/row-actions';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import {
|
||||
Combobox,
|
||||
ComboboxCollection,
|
||||
ComboboxContent,
|
||||
ComboboxEmpty,
|
||||
ComboboxGroup,
|
||||
ComboboxInput,
|
||||
ComboboxItem,
|
||||
ComboboxLabel,
|
||||
ComboboxList,
|
||||
} from '@/components/ui/combobox';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import {
|
||||
@ -16,35 +40,119 @@ import {
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { usePermissions } from '@/hooks/use-permissions';
|
||||
import { useServerTable } from '@/hooks/use-server-table';
|
||||
import { cn } from '@/lib/utils';
|
||||
import {
|
||||
destroy,
|
||||
index as scheduleIndex,
|
||||
store,
|
||||
update,
|
||||
} from '@/routes/admin/academic-classes/schedules';
|
||||
import { formatAcademicTermLabel } from '@/types/academic-term';
|
||||
import { ClassMethodLabels } from '@/types/course-class';
|
||||
import type { ClassMethod } from '@/types/course-class';
|
||||
import type { Schedule } from '@/types/schedule';
|
||||
import { DayOfWeekLabels, DaysOfWeek } from '@/types/schedule';
|
||||
import { Head, router } from '@inertiajs/react';
|
||||
import { Clock, MapPin, Pencil, Plus, Trash2, Video } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
|
||||
type CourseClassOption = {
|
||||
id: number;
|
||||
course: { id: number; code: string; name: string } | null;
|
||||
course: {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
semester_number: number | null;
|
||||
department: { id: number; name: string } | null;
|
||||
} | null;
|
||||
lecturer: {
|
||||
id: number;
|
||||
user: { profile: { full_name: string } | null } | null;
|
||||
} | null;
|
||||
academic_term: {
|
||||
id: number;
|
||||
academic_year: string;
|
||||
semester: string;
|
||||
} | null;
|
||||
};
|
||||
|
||||
type CourseClassGroup = { value: string; items: CourseClassOption[] };
|
||||
|
||||
type AcademicTermOption = {
|
||||
id: number;
|
||||
academic_year: string;
|
||||
semester: string;
|
||||
};
|
||||
|
||||
type DepartmentOption = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
schedules: Schedule[];
|
||||
courseClasses: CourseClassOption[];
|
||||
academicTerms: AcademicTermOption[];
|
||||
departments: DepartmentOption[];
|
||||
semesterNumbers: number[];
|
||||
isPersonalView: boolean;
|
||||
highlight?: number;
|
||||
filters: {
|
||||
academic_term_id?: string;
|
||||
department_id?: string;
|
||||
semester_number?: string;
|
||||
};
|
||||
};
|
||||
|
||||
const UNSCHEDULED = '__unscheduled__';
|
||||
|
||||
const BOARD_COLUMNS = [...DaysOfWeek, UNSCHEDULED] as const;
|
||||
|
||||
function courseClassLabel(courseClass: CourseClassOption): string {
|
||||
return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`;
|
||||
const DEPARTMENT_PALETTE = [
|
||||
{ border: 'border-l-blue-500 bg-blue-50/60 dark:bg-blue-950/20', dot: 'bg-blue-500' },
|
||||
{ border: 'border-l-emerald-500 bg-emerald-50/60 dark:bg-emerald-950/20', dot: 'bg-emerald-500' },
|
||||
{ border: 'border-l-amber-500 bg-amber-50/60 dark:bg-amber-950/20', dot: 'bg-amber-500' },
|
||||
{ border: 'border-l-violet-500 bg-violet-50/60 dark:bg-violet-950/20', dot: 'bg-violet-500' },
|
||||
{ border: 'border-l-rose-500 bg-rose-50/60 dark:bg-rose-950/20', dot: 'bg-rose-500' },
|
||||
{ border: 'border-l-cyan-500 bg-cyan-50/60 dark:bg-cyan-950/20', dot: 'bg-cyan-500' },
|
||||
{ border: 'border-l-orange-500 bg-orange-50/60 dark:bg-orange-950/20', dot: 'bg-orange-500' },
|
||||
{ border: 'border-l-fuchsia-500 bg-fuchsia-50/60 dark:bg-fuchsia-950/20', dot: 'bg-fuchsia-500' },
|
||||
] as const;
|
||||
|
||||
function departmentPalette(departmentId: number | undefined) {
|
||||
if (!departmentId) {
|
||||
return { border: 'border-l-border', dot: 'bg-muted-foreground/40' };
|
||||
}
|
||||
|
||||
return DEPARTMENT_PALETTE[departmentId % DEPARTMENT_PALETTE.length];
|
||||
}
|
||||
|
||||
function courseClassLabel(courseClass: {
|
||||
course: { code: string; name: string } | null;
|
||||
} | null): string {
|
||||
return `${courseClass?.course?.code ?? ''} ${courseClass?.course?.name ?? ''}`;
|
||||
}
|
||||
|
||||
function courseClassOptionLabel(option: CourseClassOption): string {
|
||||
return `${option.course?.code ?? ''} - ${option.course?.name ?? ''}`;
|
||||
}
|
||||
|
||||
function groupCourseClassesByDepartment(
|
||||
options: CourseClassOption[],
|
||||
): CourseClassGroup[] {
|
||||
const groups: CourseClassGroup[] = [];
|
||||
let currentKey: string | null = null;
|
||||
|
||||
for (const option of options) {
|
||||
const key = `${option.course?.department?.name ?? 'Tanpa Jurusan'} — Semester ${option.course?.semester_number ?? 'Tidak ditentukan'}`;
|
||||
|
||||
if (key !== currentKey) {
|
||||
currentKey = key;
|
||||
groups.push({ value: key, items: [] });
|
||||
}
|
||||
|
||||
groups[groups.length - 1].items.push(option);
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
function toTimeInput(value: string | null): string {
|
||||
@ -54,7 +162,12 @@ function toTimeInput(value: string | null): string {
|
||||
export default function ScheduleIndex({
|
||||
schedules,
|
||||
courseClasses,
|
||||
academicTerms,
|
||||
departments,
|
||||
semesterNumbers,
|
||||
isPersonalView,
|
||||
highlight,
|
||||
filters,
|
||||
}: Props) {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Schedule | null>(null);
|
||||
@ -64,6 +177,61 @@ export default function ScheduleIndex({
|
||||
const canUpdate = hasPermission('update-schedules');
|
||||
const canDelete = hasPermission('delete-schedules');
|
||||
|
||||
const filterFields: FilterField[] = [
|
||||
{
|
||||
key: 'academic_term_id',
|
||||
label: 'Periode Akademik',
|
||||
options: academicTerms.map((term) => ({
|
||||
value: String(term.id),
|
||||
label: formatAcademicTermLabel(term),
|
||||
})),
|
||||
},
|
||||
...(isPersonalView
|
||||
? []
|
||||
: [
|
||||
{
|
||||
key: 'department_id',
|
||||
label: 'Jurusan',
|
||||
options: departments.map((department) => ({
|
||||
value: String(department.id),
|
||||
label: department.name,
|
||||
})),
|
||||
},
|
||||
{
|
||||
key: 'semester_number',
|
||||
label: 'Semester',
|
||||
options: semesterNumbers.map((semester) => ({
|
||||
value: String(semester),
|
||||
label: String(semester),
|
||||
})),
|
||||
},
|
||||
]),
|
||||
];
|
||||
|
||||
const { applyFilters } = useServerTable({
|
||||
route: () => scheduleIndex.url(),
|
||||
pagination: {
|
||||
current_page: 1,
|
||||
last_page: 1,
|
||||
per_page: 999999,
|
||||
total: schedules.length,
|
||||
},
|
||||
filters,
|
||||
});
|
||||
|
||||
function handleApplyFilters(newFilters: Record<string, string>) {
|
||||
// Without an explicit `academic_term_id`, the backend defaults it back
|
||||
// to the active term, so clearing it needs to be sent explicitly
|
||||
// instead of just omitting the key.
|
||||
const clearedAcademicTerm =
|
||||
Boolean(filters.academic_term_id) && !newFilters.academic_term_id;
|
||||
|
||||
applyFilters({
|
||||
...newFilters,
|
||||
...(clearedAcademicTerm ? { academic_term_id: '' } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
function handleDelete() {
|
||||
if (!deleting) {
|
||||
return;
|
||||
@ -86,6 +254,15 @@ export default function ScheduleIndex({
|
||||
day !== UNSCHEDULED || (grouped.get(UNSCHEDULED)?.length ?? 0) > 0,
|
||||
);
|
||||
|
||||
const departmentsInView = Array.from(
|
||||
new Map(
|
||||
schedules
|
||||
.map((schedule) => schedule.course_class?.course?.department)
|
||||
.filter((department): department is { id: number; name: string } => !!department)
|
||||
.map((department) => [department.id, department]),
|
||||
).values(),
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head title="Jadwal" />
|
||||
@ -94,7 +271,13 @@ export default function ScheduleIndex({
|
||||
<PageHeader
|
||||
title="Jadwal"
|
||||
actions={
|
||||
canCreate && (
|
||||
<div className="flex items-center gap-2">
|
||||
<FilterDialog
|
||||
fields={filterFields}
|
||||
activeFilters={filters}
|
||||
onApply={handleApplyFilters}
|
||||
/>
|
||||
{canCreate && (
|
||||
<Button asChild>
|
||||
<button
|
||||
type="button"
|
||||
@ -104,14 +287,37 @@ export default function ScheduleIndex({
|
||||
Tambah
|
||||
</button>
|
||||
</Button>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<p className="hidden text-xs text-muted-foreground md:block">
|
||||
Geser ke samping untuk melihat hari lainnya.
|
||||
</p>
|
||||
|
||||
{departmentsInView.length > 1 && (
|
||||
<div className="flex flex-wrap items-center gap-3 text-xs text-muted-foreground">
|
||||
{departmentsInView.map((department) => (
|
||||
<span
|
||||
key={department.id}
|
||||
className="inline-flex items-center gap-1.5"
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
'h-2.5 w-2.5 rounded-full',
|
||||
departmentPalette(department.id)
|
||||
.dot,
|
||||
)}
|
||||
/>
|
||||
{department.name}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<CreateForm
|
||||
open={createOpen}
|
||||
onOpenChange={setCreateOpen}
|
||||
@ -165,7 +371,14 @@ export default function ScheduleIndex({
|
||||
<Card
|
||||
key={schedule.id}
|
||||
className={cn(
|
||||
'gap-3 py-4',
|
||||
'gap-3 border-l-4 py-4',
|
||||
departmentPalette(
|
||||
schedule
|
||||
.course_class
|
||||
?.course
|
||||
?.department
|
||||
?.id,
|
||||
).border,
|
||||
highlight ===
|
||||
schedule.id &&
|
||||
'ring-2 ring-primary',
|
||||
@ -175,7 +388,6 @@ export default function ScheduleIndex({
|
||||
<CardTitle className="text-sm leading-tight">
|
||||
{courseClassLabel(
|
||||
schedule.course_class ?? {
|
||||
id: 0,
|
||||
course: null,
|
||||
},
|
||||
)}
|
||||
@ -224,6 +436,19 @@ export default function ScheduleIndex({
|
||||
) || '-'}
|
||||
</span>
|
||||
)}
|
||||
{schedule.course_class
|
||||
?.lecturer && (
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<User className="h-3.5 w-3.5 shrink-0" />
|
||||
{schedule
|
||||
.course_class
|
||||
.lecturer
|
||||
.user
|
||||
?.profile
|
||||
?.full_name ??
|
||||
'N/A'}
|
||||
</span>
|
||||
)}
|
||||
{schedule.room && (
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<MapPin className="h-3.5 w-3.5 shrink-0" />
|
||||
@ -243,6 +468,22 @@ export default function ScheduleIndex({
|
||||
Link Online
|
||||
</a>
|
||||
)}
|
||||
{schedule.course_class
|
||||
?.method && (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="w-fit text-[10px] font-normal"
|
||||
>
|
||||
{ClassMethodLabels[
|
||||
schedule
|
||||
.course_class
|
||||
.method as ClassMethod
|
||||
] ??
|
||||
schedule
|
||||
.course_class
|
||||
.method}
|
||||
</Badge>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
))
|
||||
@ -272,6 +513,60 @@ export default function ScheduleIndex({
|
||||
);
|
||||
}
|
||||
|
||||
function CourseClassField({
|
||||
courseClasses,
|
||||
value,
|
||||
onChange,
|
||||
disabled,
|
||||
}: {
|
||||
courseClasses: CourseClassOption[];
|
||||
value: CourseClassOption | null;
|
||||
onChange: (value: CourseClassOption | null) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const groups = groupCourseClassesByDepartment(courseClasses);
|
||||
|
||||
return (
|
||||
<Combobox
|
||||
items={groups}
|
||||
value={value}
|
||||
onValueChange={onChange}
|
||||
itemToStringLabel={courseClassOptionLabel}
|
||||
isItemEqualToValue={(a, b) => a.id === b.id}
|
||||
disabled={disabled}
|
||||
>
|
||||
<ComboboxInput placeholder="Pilih kelas" className="w-full" />
|
||||
<ComboboxContent>
|
||||
<ComboboxEmpty>Kelas tidak ditemukan.</ComboboxEmpty>
|
||||
<ComboboxList>
|
||||
{(group: CourseClassGroup) => (
|
||||
<ComboboxGroup key={group.value} items={group.items}>
|
||||
<ComboboxLabel>{group.value}</ComboboxLabel>
|
||||
<ComboboxCollection>
|
||||
{(option: CourseClassOption) => (
|
||||
<ComboboxItem key={option.id} value={option}>
|
||||
<div className="flex flex-col">
|
||||
<span>
|
||||
{courseClassOptionLabel(option)}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{option.lecturer?.user?.profile
|
||||
?.full_name ?? 'N/A'}
|
||||
{option.academic_term &&
|
||||
` • ${formatAcademicTermLabel(option.academic_term)}`}
|
||||
</span>
|
||||
</div>
|
||||
</ComboboxItem>
|
||||
)}
|
||||
</ComboboxCollection>
|
||||
</ComboboxGroup>
|
||||
)}
|
||||
</ComboboxList>
|
||||
</ComboboxContent>
|
||||
</Combobox>
|
||||
);
|
||||
}
|
||||
|
||||
function CreateForm({
|
||||
open,
|
||||
onOpenChange,
|
||||
@ -281,6 +576,10 @@ function CreateForm({
|
||||
onOpenChange: (open: boolean) => void;
|
||||
courseClasses: CourseClassOption[];
|
||||
}) {
|
||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
return (
|
||||
<FormDialog
|
||||
open={open}
|
||||
@ -288,7 +587,10 @@ function CreateForm({
|
||||
title="Tambah Jadwal"
|
||||
action={store()}
|
||||
resetOnSuccess
|
||||
onSuccess={() => onOpenChange(false)}
|
||||
onSuccess={() => {
|
||||
onOpenChange(false);
|
||||
setCourseClass(null);
|
||||
}}
|
||||
>
|
||||
{({ errors }) => (
|
||||
<div className="grid gap-4">
|
||||
@ -296,26 +598,22 @@ function CreateForm({
|
||||
<Label>
|
||||
Kelas <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<input type="hidden" name="course_class_id" />
|
||||
<Select name="course_class_id">
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Pilih kelas" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{courseClasses.map((courseClass) => (
|
||||
<SelectItem
|
||||
key={courseClass.id}
|
||||
value={String(courseClass.id)}
|
||||
>
|
||||
{courseClassLabel(courseClass)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<input
|
||||
type="hidden"
|
||||
name="course_class_id"
|
||||
value={courseClass?.id ?? ''}
|
||||
/>
|
||||
<CourseClassField
|
||||
courseClasses={courseClasses}
|
||||
value={courseClass}
|
||||
onChange={setCourseClass}
|
||||
/>
|
||||
<InputError message={errors.course_class_id} />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label>Hari</Label>
|
||||
<Label>
|
||||
Hari <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<input type="hidden" name="day_of_week" />
|
||||
<Select name="day_of_week">
|
||||
<SelectTrigger className="w-full">
|
||||
@ -333,7 +631,10 @@ function CreateForm({
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="start_time">Jam Mulai</Label>
|
||||
<Label htmlFor="start_time">
|
||||
Jam Mulai{' '}
|
||||
<span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="start_time"
|
||||
name="start_time"
|
||||
@ -342,7 +643,10 @@ function CreateForm({
|
||||
<InputError message={errors.start_time} />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="end_time">Jam Selesai</Label>
|
||||
<Label htmlFor="end_time">
|
||||
Jam Selesai{' '}
|
||||
<span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input id="end_time" name="end_time" type="time" />
|
||||
<InputError message={errors.end_time} />
|
||||
</div>
|
||||
@ -382,6 +686,13 @@ function EditForm({
|
||||
editing: Schedule | null;
|
||||
courseClasses: CourseClassOption[];
|
||||
}) {
|
||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
||||
editing
|
||||
? (courseClasses.find((c) => c.id === editing.course_class_id) ??
|
||||
null)
|
||||
: null,
|
||||
);
|
||||
|
||||
return (
|
||||
<FormDialog
|
||||
open={open}
|
||||
@ -399,28 +710,23 @@ function EditForm({
|
||||
Kelas{' '}
|
||||
<span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
<input
|
||||
type="hidden"
|
||||
name="course_class_id"
|
||||
defaultValue={String(editing.course_class_id)}
|
||||
>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Pilih kelas" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{courseClasses.map((courseClass) => (
|
||||
<SelectItem
|
||||
key={courseClass.id}
|
||||
value={String(courseClass.id)}
|
||||
>
|
||||
{courseClassLabel(courseClass)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
value={courseClass?.id ?? ''}
|
||||
/>
|
||||
<CourseClassField
|
||||
courseClasses={courseClasses}
|
||||
value={courseClass}
|
||||
onChange={setCourseClass}
|
||||
/>
|
||||
<InputError message={errors.course_class_id} />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label>Hari</Label>
|
||||
<Label>
|
||||
Hari{' '}
|
||||
<span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
name="day_of_week"
|
||||
defaultValue={editing.day_of_week ?? undefined}
|
||||
@ -441,7 +747,10 @@ function EditForm({
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="edit-start_time">
|
||||
Jam Mulai
|
||||
Jam Mulai{' '}
|
||||
<span className="text-destructive">
|
||||
*
|
||||
</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="edit-start_time"
|
||||
@ -455,7 +764,10 @@ function EditForm({
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="edit-end_time">
|
||||
Jam Selesai
|
||||
Jam Selesai{' '}
|
||||
<span className="text-destructive">
|
||||
*
|
||||
</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="edit-end_time"
|
||||
|
||||
@ -32,10 +32,13 @@ import {
|
||||
ComboboxChip,
|
||||
ComboboxChips,
|
||||
ComboboxChipsInput,
|
||||
ComboboxCollection,
|
||||
ComboboxContent,
|
||||
ComboboxEmpty,
|
||||
ComboboxGroup,
|
||||
ComboboxInput,
|
||||
ComboboxItem,
|
||||
ComboboxLabel,
|
||||
ComboboxList,
|
||||
useComboboxAnchor,
|
||||
} from '@/components/ui/combobox';
|
||||
@ -108,6 +111,28 @@ function studentLabel(student: TuitionInvoiceStudent): string {
|
||||
return `${student.user?.profile?.full_name ?? 'N/A'} - ${student.student_number}`;
|
||||
}
|
||||
|
||||
type StudentGroup = { value: string; items: TuitionInvoiceStudent[] };
|
||||
|
||||
function groupStudentsByDepartmentAndSemester(
|
||||
students: TuitionInvoiceStudent[],
|
||||
): StudentGroup[] {
|
||||
const groups: StudentGroup[] = [];
|
||||
let currentKey: string | null = null;
|
||||
|
||||
for (const student of students) {
|
||||
const key = `${student.department?.name ?? 'Tanpa Jurusan'} — Semester ${student.current_semester ?? 'Tidak ditentukan'}`;
|
||||
|
||||
if (key !== currentKey) {
|
||||
currentKey = key;
|
||||
groups.push({ value: key, items: [] });
|
||||
}
|
||||
|
||||
groups[groups.length - 1].items.push(student);
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
export default function TuitionInvoiceIndex({
|
||||
invoices,
|
||||
summary,
|
||||
@ -379,6 +404,7 @@ function CreateForm({
|
||||
!student.invoiced_term_ids?.includes(Number(academicTermId)),
|
||||
)
|
||||
: [];
|
||||
const studentGroups = groupStudentsByDepartmentAndSemester(availableStudents);
|
||||
|
||||
function reset() {
|
||||
setAcademicTermId('');
|
||||
@ -468,7 +494,7 @@ function CreateForm({
|
||||
/>
|
||||
))}
|
||||
<Combobox
|
||||
items={availableStudents}
|
||||
items={studentGroups}
|
||||
multiple
|
||||
disabled={!academicTermId}
|
||||
value={selectedStudents}
|
||||
@ -501,7 +527,18 @@ function CreateForm({
|
||||
Mahasiswa tidak ditemukan.
|
||||
</ComboboxEmpty>
|
||||
<ComboboxList>
|
||||
{(student: TuitionInvoiceStudent) => (
|
||||
{(group: StudentGroup) => (
|
||||
<ComboboxGroup
|
||||
key={group.value}
|
||||
items={group.items}
|
||||
>
|
||||
<ComboboxLabel>
|
||||
{group.value}
|
||||
</ComboboxLabel>
|
||||
<ComboboxCollection>
|
||||
{(
|
||||
student: TuitionInvoiceStudent,
|
||||
) => (
|
||||
<ComboboxItem
|
||||
key={student.id}
|
||||
value={student}
|
||||
@ -509,6 +546,9 @@ function CreateForm({
|
||||
{studentLabel(student)}
|
||||
</ComboboxItem>
|
||||
)}
|
||||
</ComboboxCollection>
|
||||
</ComboboxGroup>
|
||||
)}
|
||||
</ComboboxList>
|
||||
</ComboboxContent>
|
||||
</Combobox>
|
||||
@ -569,6 +609,7 @@ function EditForm({
|
||||
const [student, setStudent] = useState<TuitionInvoiceStudent | null>(
|
||||
students.find((s) => s.id === editing?.student_id) ?? null,
|
||||
);
|
||||
const studentGroups = groupStudentsByDepartmentAndSemester(students);
|
||||
|
||||
return (
|
||||
<FormDialog
|
||||
@ -618,7 +659,7 @@ function EditForm({
|
||||
value={student?.id ?? ''}
|
||||
/>
|
||||
<Combobox
|
||||
items={students}
|
||||
items={studentGroups}
|
||||
value={student}
|
||||
onValueChange={setStudent}
|
||||
itemToStringLabel={studentLabel}
|
||||
@ -633,14 +674,30 @@ function EditForm({
|
||||
Mahasiswa tidak ditemukan.
|
||||
</ComboboxEmpty>
|
||||
<ComboboxList>
|
||||
{(option: TuitionInvoiceStudent) => (
|
||||
{(group: StudentGroup) => (
|
||||
<ComboboxGroup
|
||||
key={group.value}
|
||||
items={group.items}
|
||||
>
|
||||
<ComboboxLabel>
|
||||
{group.value}
|
||||
</ComboboxLabel>
|
||||
<ComboboxCollection>
|
||||
{(
|
||||
option: TuitionInvoiceStudent,
|
||||
) => (
|
||||
<ComboboxItem
|
||||
key={option.id}
|
||||
value={option}
|
||||
>
|
||||
{studentLabel(option)}
|
||||
{studentLabel(
|
||||
option,
|
||||
)}
|
||||
</ComboboxItem>
|
||||
)}
|
||||
</ComboboxCollection>
|
||||
</ComboboxGroup>
|
||||
)}
|
||||
</ComboboxList>
|
||||
</ComboboxContent>
|
||||
</Combobox>
|
||||
|
||||
@ -26,11 +26,6 @@ export function createCourseRegistrationColumns(): ColumnDef<CourseRegistrationR
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'department',
|
||||
header: () => <span>Jurusan</span>,
|
||||
cell: ({ row }) => row.original.student?.department?.name ?? '-',
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: () => <span className="block text-center">Aksi</span>,
|
||||
|
||||
@ -79,6 +79,9 @@ export default function CourseRegistrationIndex({
|
||||
onSearchChange={handleSearchChange}
|
||||
searchValue={search}
|
||||
searchKey="student"
|
||||
groupBy={(row) =>
|
||||
row.student?.department?.name ?? 'Tanpa Jurusan'
|
||||
}
|
||||
toolbar={
|
||||
<FilterDialog
|
||||
fields={filterFields}
|
||||
|
||||
@ -1,16 +1,47 @@
|
||||
export const AssignmentStatuses = ['open', 'closed'] as const;
|
||||
|
||||
export type AssignmentStatus = (typeof AssignmentStatuses)[number];
|
||||
|
||||
export const AssignmentStatusLabels: Record<AssignmentStatus, string> = {
|
||||
open: 'Dibuka',
|
||||
closed: 'Ditutup',
|
||||
};
|
||||
|
||||
export type MySubmission = {
|
||||
id: number;
|
||||
notes: string | null;
|
||||
status: 'not_submitted' | 'submitted' | null;
|
||||
submitted_at: string | null;
|
||||
file_url: string | null;
|
||||
file_name: string | null;
|
||||
};
|
||||
|
||||
export type Assignment = {
|
||||
id: number;
|
||||
course_class_id: number;
|
||||
course_class: {
|
||||
id: number;
|
||||
course: { id: number; code: string; name: string } | null;
|
||||
academic_term: {
|
||||
id: number;
|
||||
academic_year: string;
|
||||
semester: string;
|
||||
} | null;
|
||||
/** Total students enrolled (approved) in this class. */
|
||||
enrollments_count: number;
|
||||
} | null;
|
||||
title: string;
|
||||
description: string | null;
|
||||
deadline: string;
|
||||
/** Governs whether students can still submit — independent of the deadline. */
|
||||
status: AssignmentStatus;
|
||||
attachment_url: string | null;
|
||||
attachment_name: string | null;
|
||||
submissions_count: number;
|
||||
/** How many of the submissions received already have a score. */
|
||||
graded_submissions_count: number;
|
||||
/** Only present for the logged-in mahasiswa: their own submission, if any. */
|
||||
submissions?: MySubmission[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
@ -10,12 +10,20 @@ export const AttendanceStatusLabels: Record<AttendanceStatus, string> = {
|
||||
export type AttendanceCourseClass = {
|
||||
id: number;
|
||||
course: { id: number; code: string; name: string } | null;
|
||||
academic_term?: {
|
||||
id: number;
|
||||
academic_year: string;
|
||||
semester: string;
|
||||
} | null;
|
||||
};
|
||||
|
||||
export type AttendanceCourseClassOverview = AttendanceCourseClass & {
|
||||
enrollments_count: number;
|
||||
meetings_count: number;
|
||||
};
|
||||
|
||||
export type AttendanceSession = {
|
||||
course_class_id: number;
|
||||
course_class: AttendanceCourseClass | null;
|
||||
meeting_number: number | null;
|
||||
meeting_number: number;
|
||||
date: string;
|
||||
total_count: number;
|
||||
present_count: number;
|
||||
@ -32,3 +40,17 @@ export type AttendanceRosterEntry = {
|
||||
student: AttendanceRosterStudent | null;
|
||||
status: AttendanceStatus;
|
||||
};
|
||||
|
||||
export type AttendanceRecord = {
|
||||
course_class_id: number;
|
||||
meeting_number: number | null;
|
||||
date: string;
|
||||
status: AttendanceStatus;
|
||||
};
|
||||
|
||||
export type AttendanceClassSummary = {
|
||||
course_class: AttendanceCourseClass;
|
||||
records: AttendanceRecord[];
|
||||
present_count: number;
|
||||
total_count: number;
|
||||
};
|
||||
|
||||
@ -25,7 +25,17 @@ export type Schedule = {
|
||||
course_class_id: number;
|
||||
course_class: {
|
||||
id: number;
|
||||
course: { id: number; code: string; name: string } | null;
|
||||
method: string | null;
|
||||
course: {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
department: { id: number; name: string } | null;
|
||||
} | null;
|
||||
lecturer: {
|
||||
id: number;
|
||||
user: { profile: { full_name: string } | null } | null;
|
||||
} | null;
|
||||
} | null;
|
||||
day_of_week: string | null;
|
||||
start_time: string | null;
|
||||
|
||||
@ -2,6 +2,7 @@ export type TuitionInvoiceStudent = {
|
||||
id: number;
|
||||
student_number: string;
|
||||
department: { id: number; name: string } | null;
|
||||
current_semester: number;
|
||||
user: { profile: { full_name: string } | null } | null;
|
||||
invoiced_term_ids?: number[];
|
||||
};
|
||||
|
||||
@ -68,11 +68,13 @@
|
||||
|
||||
Route::prefix('assignments/{assignment}/submissions')->name('assignments.submissions.')->group(function () {
|
||||
Route::get('/', [SubmissionController::class, 'index'])->name('index')->middleware('permission:view-assignment-submissions');
|
||||
Route::post('/', [SubmissionController::class, 'store'])->name('store')->middleware('permission:create-assignment-submissions');
|
||||
Route::put('{submission}', [SubmissionController::class, 'update'])->name('update')->middleware('permission:update-assignment-submissions');
|
||||
Route::delete('{submission}', [SubmissionController::class, 'destroy'])->name('destroy')->middleware('permission:delete-assignment-submissions');
|
||||
Route::patch('{submission}/grade', [SubmissionController::class, 'grade'])->name('grade')->middleware('permission:update-assignment-submissions');
|
||||
});
|
||||
|
||||
Route::post('assignments/{assignment}/submit', [SubmissionController::class, 'submit'])
|
||||
->name('assignments.submit')
|
||||
->middleware('permission:submit-assignments');
|
||||
|
||||
Route::resource('schedules', ScheduleController::class)
|
||||
->except(['create', 'edit', 'show'])
|
||||
->middlewareFor(['index'], 'permission:view-schedules')
|
||||
@ -82,6 +84,8 @@
|
||||
|
||||
Route::prefix('attendances')->name('attendances.')->group(function () {
|
||||
Route::get('/', [AttendanceController::class, 'index'])->name('index')->middleware('permission:view-attendances');
|
||||
Route::get('mine', [AttendanceController::class, 'mine'])->name('mine')->middleware('permission:view-own-attendances');
|
||||
Route::get('{course_class}', [AttendanceController::class, 'show'])->name('show')->middleware('permission:view-attendances');
|
||||
Route::get('{course_class}/{meeting_number}', [AttendanceController::class, 'session'])
|
||||
->whereNumber('meeting_number')
|
||||
->name('session')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user