Compare commits
No commits in common. "88286fe596d9b3bc53d0b5468743a9f857571607" and "8528a3258d8effe211bda84cfa34161cac00b251" have entirely different histories.
88286fe596
...
8528a3258d
@ -1,21 +0,0 @@
|
|||||||
<?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',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
<?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,7 +8,6 @@
|
|||||||
use App\Models\Assignment;
|
use App\Models\Assignment;
|
||||||
use App\Services\Admin\AcademicClasses\AssignmentService;
|
use App\Services\Admin\AcademicClasses\AssignmentService;
|
||||||
use App\Services\Admin\Manage\CourseClassService;
|
use App\Services\Admin\Manage\CourseClassService;
|
||||||
use App\Services\Admin\Master\AcademicTermService;
|
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
use Inertia\Response;
|
use Inertia\Response;
|
||||||
@ -18,28 +17,17 @@ class AssignmentController extends Controller
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly AssignmentService $service,
|
private readonly AssignmentService $service,
|
||||||
private readonly CourseClassService $courseClassService,
|
private readonly CourseClassService $courseClassService,
|
||||||
private readonly AcademicTermService $academicTermService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function index(PaginatedRequest $request): Response
|
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', [
|
return Inertia::render('admin/academic-classes/assignments/index', [
|
||||||
'assignments' => Inertia::scroll(fn () => $this->service->paginated(
|
'assignments' => $this->service->paginated(
|
||||||
$request->user(),
|
|
||||||
...$request->validatedWithDefaults(),
|
...$request->validatedWithDefaults(),
|
||||||
courseClassId: $request->validated('course_class_id'),
|
courseClassId: $request->validated('course_class_id'),
|
||||||
academicTermId: $academicTermId,
|
),
|
||||||
)),
|
'courseClasses' => $this->courseClassService->getAllForSelect(),
|
||||||
'courseClasses' => $this->courseClassService->getAllForSelect($request->user()),
|
'filters' => $request->only(['course_class_id']),
|
||||||
'academicTerms' => $this->academicTermService->getAllForSelect(),
|
|
||||||
'filters' => [
|
|
||||||
'course_class_id' => $request->validated('course_class_id'),
|
|
||||||
'academic_term_id' => $academicTermId ? (string) $academicTermId : null,
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,9 +6,8 @@
|
|||||||
use App\Http\Requests\Admin\AcademicClasses\AttendanceStoreRequest;
|
use App\Http\Requests\Admin\AcademicClasses\AttendanceStoreRequest;
|
||||||
use App\Models\CourseClass;
|
use App\Models\CourseClass;
|
||||||
use App\Services\Admin\AcademicClasses\AttendanceService;
|
use App\Services\Admin\AcademicClasses\AttendanceService;
|
||||||
use App\Services\Admin\Master\AcademicTermService;
|
use App\Services\Admin\Manage\CourseClassService;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
use Inertia\Response;
|
use Inertia\Response;
|
||||||
|
|
||||||
@ -16,52 +15,19 @@ class AttendanceController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly AttendanceService $service,
|
private readonly AttendanceService $service,
|
||||||
private readonly AcademicTermService $academicTermService,
|
private readonly CourseClassService $courseClassService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function index(Request $request): Response
|
public function index(): Response
|
||||||
{
|
{
|
||||||
$academicTermId = $request->has('academic_term_id')
|
|
||||||
? $request->integer('academic_term_id')
|
|
||||||
: $this->academicTermService->getActive()?->id;
|
|
||||||
|
|
||||||
return Inertia::render('admin/academic-classes/attendances/index', [
|
return Inertia::render('admin/academic-classes/attendances/index', [
|
||||||
'courseClasses' => $this->service->courseClassesForUser($request->user(), $academicTermId),
|
'sessions' => $this->service->sessions(),
|
||||||
'academicTerms' => $this->academicTermService->getAllForSelect(),
|
'courseClasses' => $this->courseClassService->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
|
public function session(CourseClass $courseClass, int $meetingNumber): Response
|
||||||
{
|
{
|
||||||
$this->abortUnlessLecturerOwnsClass($courseClass);
|
|
||||||
|
|
||||||
$courseClass->load('course');
|
$courseClass->load('course');
|
||||||
$data = $this->service->session($courseClass, $meetingNumber);
|
$data = $this->service->session($courseClass, $meetingNumber);
|
||||||
|
|
||||||
@ -84,25 +50,10 @@ public function store(AttendanceStoreRequest $request, CourseClass $courseClass,
|
|||||||
|
|
||||||
public function destroy(CourseClass $courseClass, int $meetingNumber): RedirectResponse
|
public function destroy(CourseClass $courseClass, int $meetingNumber): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->abortUnlessLecturerOwnsClass($courseClass);
|
|
||||||
|
|
||||||
$this->service->deleteSession($courseClass->id, $meetingNumber);
|
$this->service->deleteSession($courseClass->id, $meetingNumber);
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Sesi kehadiran berhasil dihapus.']);
|
Inertia::flash('toast', ['type' => 'success', 'message' => 'Sesi kehadiran berhasil dihapus.']);
|
||||||
|
|
||||||
return to_route('admin.academic-classes.attendances.show', [$courseClass->id]);
|
return to_route('admin.academic-classes.attendances.index');
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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,11 +23,10 @@ public function index(PaginatedRequest $request): Response
|
|||||||
{
|
{
|
||||||
return Inertia::render('admin/academic-classes/materials/index', [
|
return Inertia::render('admin/academic-classes/materials/index', [
|
||||||
'materials' => $this->service->paginated(
|
'materials' => $this->service->paginated(
|
||||||
$request->user(),
|
|
||||||
...$request->validatedWithDefaults(),
|
...$request->validatedWithDefaults(),
|
||||||
courseClassId: $request->validated('course_class_id'),
|
courseClassId: $request->validated('course_class_id'),
|
||||||
),
|
),
|
||||||
'courseClasses' => $this->courseClassService->getAllForSelect($request->user()),
|
'courseClasses' => $this->courseClassService->getAllForSelect(),
|
||||||
'filters' => $request->only(['course_class_id']),
|
'filters' => $request->only(['course_class_id']),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,9 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Admin\AcademicClasses\ScheduleRequest;
|
use App\Http\Requests\Admin\AcademicClasses\ScheduleRequest;
|
||||||
use App\Http\Requests\PaginatedRequest;
|
|
||||||
use App\Models\Schedule;
|
use App\Models\Schedule;
|
||||||
use App\Services\Admin\AcademicClasses\ScheduleService;
|
use App\Services\Admin\AcademicClasses\ScheduleService;
|
||||||
use App\Services\Admin\Master\AcademicTermService;
|
use App\Services\Admin\Manage\CourseClassService;
|
||||||
use App\Services\Admin\Master\CourseService;
|
|
||||||
use App\Services\Admin\Master\DepartmentService;
|
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
use Inertia\Response;
|
use Inertia\Response;
|
||||||
@ -18,37 +15,14 @@ class ScheduleController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly ScheduleService $service,
|
private readonly ScheduleService $service,
|
||||||
private readonly AcademicTermService $academicTermService,
|
private readonly CourseClassService $courseClassService,
|
||||||
private readonly DepartmentService $departmentService,
|
|
||||||
private readonly CourseService $courseService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function index(PaginatedRequest $request): Response
|
public function index(): 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', [
|
return Inertia::render('admin/academic-classes/schedules/index', [
|
||||||
'schedules' => $this->service->all(
|
'schedules' => $this->service->all(),
|
||||||
$user,
|
'courseClasses' => $this->courseClassService->getAllForSelect(),
|
||||||
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,8 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Admin\AcademicClasses;
|
namespace App\Http\Controllers\Admin\AcademicClasses;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Admin\AcademicClasses\GradeSubmissionRequest;
|
use App\Http\Requests\Admin\AcademicClasses\SubmissionRequest;
|
||||||
use App\Http\Requests\Admin\AcademicClasses\SubmitAssignmentRequest;
|
|
||||||
use App\Models\Assignment;
|
use App\Models\Assignment;
|
||||||
use App\Models\Submission;
|
use App\Models\Submission;
|
||||||
use App\Services\Admin\AcademicClasses\SubmissionService;
|
use App\Services\Admin\AcademicClasses\SubmissionService;
|
||||||
@ -20,42 +19,33 @@ public function __construct(
|
|||||||
|
|
||||||
public function index(Assignment $assignment): Response
|
public function index(Assignment $assignment): Response
|
||||||
{
|
{
|
||||||
$this->abortUnlessLecturerOwnsAssignment($assignment);
|
|
||||||
|
|
||||||
$assignment->load(['courseClass.course', 'courseClass.lecturer.user.profile', 'courseClass.academicTerm']);
|
$assignment->load(['courseClass.course', 'courseClass.lecturer.user.profile', 'courseClass.academicTerm']);
|
||||||
|
|
||||||
return Inertia::render('admin/academic-classes/assignments/submissions', [
|
return Inertia::render('admin/academic-classes/assignments/submissions', [
|
||||||
'assignment' => $assignment,
|
'assignment' => $assignment,
|
||||||
'submissions' => $this->service->forAssignment($assignment),
|
'submissions' => $this->service->forAssignment($assignment),
|
||||||
|
'availableStudents' => $this->service->availableStudents($assignment),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function grade(GradeSubmissionRequest $request, Assignment $assignment, Submission $submission): RedirectResponse
|
public function store(SubmissionRequest $request, Assignment $assignment): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->grade($submission, $request->validated('score'));
|
$this->service->create($assignment, $request->validated(), $request->file('file'));
|
||||||
|
|
||||||
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Nilai berhasil disimpan.'])->back();
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengumpulan berhasil ditambahkan.'])->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function submit(SubmitAssignmentRequest $request, Assignment $assignment): RedirectResponse
|
public function update(SubmissionRequest $request, Assignment $assignment, Submission $submission): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->service->submitForStudent($assignment, $request->user()->student, $request->validated(), $request->file('file'));
|
$this->service->update($submission, $request->validated(), $request->file('file'));
|
||||||
|
|
||||||
Inertia::flash('toast', ['type' => 'success', 'message' => 'Tugas berhasil dikumpulkan.']);
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengumpulan berhasil diperbarui.'])->back();
|
||||||
|
|
||||||
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
|
|
||||||
{
|
{
|
||||||
$user = request()->user();
|
$this->service->delete($submission);
|
||||||
|
|
||||||
abort_if(
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Pengumpulan berhasil dihapus.'])->back();
|
||||||
$user->hasRole('dosen') && $assignment->courseClass?->lecturer_id !== $user->lecturer?->id,
|
|
||||||
403,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests\Admin\AcademicClasses;
|
namespace App\Http\Requests\Admin\AcademicClasses;
|
||||||
|
|
||||||
use App\Enums\AssignmentStatus;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
@ -15,20 +14,11 @@ public function authorize(): bool
|
|||||||
|
|
||||||
public function rules(): array
|
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 [
|
return [
|
||||||
'course_class_id' => ['required', 'integer', $courseClassRule],
|
'course_class_id' => ['required', 'integer', Rule::exists('course_classes', 'id')],
|
||||||
'title' => ['required', 'string', 'max:150'],
|
'title' => ['required', 'string', 'max:150'],
|
||||||
'description' => ['nullable', 'string'],
|
'description' => ['nullable', 'string'],
|
||||||
'deadline' => ['required', 'date'],
|
'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'],
|
'attachment' => ['nullable', 'file', 'max:10240', 'mimes:pdf,doc,docx,ppt,pptx,xls,xlsx,jpg,jpeg,png,mp4,zip'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,18 +10,7 @@ class AttendanceStoreRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
if (! $this->user()->can('create-attendances')) {
|
return $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
|
public function rules(): array
|
||||||
|
|||||||
@ -1,31 +0,0 @@
|
|||||||
<?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,16 +14,8 @@ public function authorize(): bool
|
|||||||
|
|
||||||
public function rules(): array
|
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 [
|
return [
|
||||||
'course_class_id' => ['required', 'integer', $courseClassRule],
|
'course_class_id' => ['required', 'integer', Rule::exists('course_classes', 'id')],
|
||||||
'title' => ['required', 'string', 'max:150'],
|
'title' => ['required', 'string', 'max:150'],
|
||||||
'description' => ['nullable', 'string'],
|
'description' => ['nullable', 'string'],
|
||||||
'meeting_number' => ['nullable', 'integer', 'min:1'],
|
'meeting_number' => ['nullable', 'integer', 'min:1'],
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests\Admin\AcademicClasses;
|
namespace App\Http\Requests\Admin\AcademicClasses;
|
||||||
|
|
||||||
use App\Enums\DayOfWeek;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
@ -17,9 +16,9 @@ public function rules(): array
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'course_class_id' => ['required', 'integer', Rule::exists('course_classes', 'id')],
|
'course_class_id' => ['required', 'integer', Rule::exists('course_classes', 'id')],
|
||||||
'day_of_week' => ['required', 'string', Rule::in(DayOfWeek::values())],
|
'day_of_week' => ['nullable', 'string', 'max:15'],
|
||||||
'start_time' => ['required', 'date_format:H:i'],
|
'start_time' => ['nullable', 'date_format:H:i'],
|
||||||
'end_time' => ['required', 'date_format:H:i', 'after:start_time'],
|
'end_time' => ['nullable', 'date_format:H:i', 'after:start_time'],
|
||||||
'room' => ['nullable', 'string', 'max:20'],
|
'room' => ['nullable', 'string', 'max:20'],
|
||||||
'online_link' => ['nullable', 'string', 'max:255', 'url'],
|
'online_link' => ['nullable', 'string', 'max:255', 'url'],
|
||||||
];
|
];
|
||||||
|
|||||||
@ -0,0 +1,41 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,60 +0,0 @@
|
|||||||
<?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,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Enums\AssignmentStatus;
|
|
||||||
use Illuminate\Database\Eloquent\Attributes\Appends;
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
@ -24,7 +23,6 @@ protected function casts(): array
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'deadline' => 'datetime',
|
'deadline' => 'datetime',
|
||||||
'status' => AssignmentStatus::class,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Enums\DayOfWeek;
|
|
||||||
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@ -13,13 +12,6 @@ class Schedule extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected function casts(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'day_of_week' => DayOfWeek::class,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function courseClass(): BelongsTo
|
public function courseClass(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(CourseClass::class);
|
return $this->belongsTo(CourseClass::class);
|
||||||
|
|||||||
@ -2,39 +2,20 @@
|
|||||||
|
|
||||||
namespace App\Services\Admin\AcademicClasses;
|
namespace App\Services\Admin\AcademicClasses;
|
||||||
|
|
||||||
use App\Enums\AssignmentStatus;
|
|
||||||
use App\Enums\RegistrationStatus;
|
|
||||||
use App\Models\Assignment;
|
use App\Models\Assignment;
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
|
|
||||||
class AssignmentService
|
class AssignmentService
|
||||||
{
|
{
|
||||||
public function paginated(User $user, int $perPage = 25, string $search = '', ?int $courseClassId = null, ?int $academicTermId = null): LengthAwarePaginator
|
public function paginated(int $perPage = 25, string $search = '', ?int $courseClassId = null): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
return Assignment::query()
|
return Assignment::query()
|
||||||
->select(['id', 'course_class_id', 'title', 'description', 'deadline', 'status'])
|
->select(['id', 'course_class_id', 'title', 'description', 'deadline'])
|
||||||
->withCount([
|
->withCount('submissions')
|
||||||
'submissions',
|
->with('courseClass.course:id,code,name')
|
||||||
'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($search, fn ($q) => $q->where('title', 'like', "%{$search}%"))
|
||||||
->when($courseClassId, fn ($q) => $q->where('course_class_id', $courseClassId))
|
->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()
|
->latest()
|
||||||
->paginate($perPage);
|
->paginate($perPage);
|
||||||
}
|
}
|
||||||
@ -46,7 +27,6 @@ public function create(array $data, ?UploadedFile $file): Assignment
|
|||||||
'title' => $data['title'],
|
'title' => $data['title'],
|
||||||
'description' => $data['description'] ?? null,
|
'description' => $data['description'] ?? null,
|
||||||
'deadline' => $data['deadline'],
|
'deadline' => $data['deadline'],
|
||||||
'status' => $data['status'] ?? AssignmentStatus::Open,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($file) {
|
if ($file) {
|
||||||
@ -62,7 +42,6 @@ public function update(Assignment $assignment, array $data, ?UploadedFile $file)
|
|||||||
$assignment->title = $data['title'];
|
$assignment->title = $data['title'];
|
||||||
$assignment->description = $data['description'] ?? null;
|
$assignment->description = $data['description'] ?? null;
|
||||||
$assignment->deadline = $data['deadline'];
|
$assignment->deadline = $data['deadline'];
|
||||||
$assignment->status = $data['status'] ?? $assignment->status;
|
|
||||||
$assignment->update();
|
$assignment->update();
|
||||||
|
|
||||||
if ($file) {
|
if ($file) {
|
||||||
|
|||||||
@ -5,60 +5,22 @@
|
|||||||
use App\Enums\AttendanceStatus;
|
use App\Enums\AttendanceStatus;
|
||||||
use App\Models\Attendance;
|
use App\Models\Attendance;
|
||||||
use App\Models\CourseClass;
|
use App\Models\CourseClass;
|
||||||
use App\Models\Student;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Support\Collection as BaseCollection;
|
|
||||||
|
|
||||||
class AttendanceService
|
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()
|
return Attendance::query()
|
||||||
->select(['meeting_number', 'date'])
|
->select(['course_class_id', 'meeting_number', 'date'])
|
||||||
->selectRaw('COUNT(*) as total_count')
|
->selectRaw('COUNT(*) as total_count')
|
||||||
->selectRaw("SUM(CASE WHEN status = 'present' THEN 1 ELSE 0 END) as present_count")
|
->selectRaw("SUM(CASE WHEN status = 'present' THEN 1 ELSE 0 END) as present_count")
|
||||||
->where('course_class_id', $courseClass->id)
|
->with('courseClass.course:id,code,name')
|
||||||
->groupBy('meeting_number', 'date')
|
->groupBy('course_class_id', 'meeting_number', 'date')
|
||||||
->orderByDesc('meeting_number')
|
->orderByDesc('date')
|
||||||
->get();
|
->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
|
public function session(CourseClass $courseClass, int $meetingNumber): array
|
||||||
{
|
{
|
||||||
$existing = Attendance::query()
|
$existing = Attendance::query()
|
||||||
@ -112,36 +74,4 @@ public function deleteSession(int $courseClassId, int $meetingNumber): void
|
|||||||
->where('meeting_number', $meetingNumber)
|
->where('meeting_number', $meetingNumber)
|
||||||
->delete();
|
->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,28 +2,19 @@
|
|||||||
|
|
||||||
namespace App\Services\Admin\AcademicClasses;
|
namespace App\Services\Admin\AcademicClasses;
|
||||||
|
|
||||||
use App\Enums\RegistrationStatus;
|
|
||||||
use App\Models\Material;
|
use App\Models\Material;
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
|
|
||||||
class MaterialService
|
class MaterialService
|
||||||
{
|
{
|
||||||
public function paginated(User $user, int $perPage = 25, string $search = '', ?int $courseClassId = null): LengthAwarePaginator
|
public function paginated(int $perPage = 25, string $search = '', ?int $courseClassId = null): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
return Material::query()
|
return Material::query()
|
||||||
->select(['id', 'course_class_id', 'title', 'description', 'meeting_number'])
|
->select(['id', 'course_class_id', 'title', 'description', 'meeting_number'])
|
||||||
->with('courseClass.course:id,code,name')
|
->with('courseClass.course:id,code,name')
|
||||||
->when($search, fn ($q) => $q->where('title', 'like', "%{$search}%"))
|
->when($search, fn ($q) => $q->where('title', 'like', "%{$search}%"))
|
||||||
->when($courseClassId, fn ($q) => $q->where('course_class_id', $courseClassId))
|
->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()
|
->latest()
|
||||||
->paginate($perPage);
|
->paginate($perPage);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,72 +2,27 @@
|
|||||||
|
|
||||||
namespace App\Services\Admin\AcademicClasses;
|
namespace App\Services\Admin\AcademicClasses;
|
||||||
|
|
||||||
use App\Enums\RegistrationStatus;
|
|
||||||
use App\Models\CourseClass;
|
|
||||||
use App\Models\Schedule;
|
use App\Models\Schedule;
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
|
||||||
class ScheduleService
|
class ScheduleService
|
||||||
{
|
{
|
||||||
public function all(User $user, ?int $academicTermId = null, ?int $departmentId = null, ?int $semesterNumber = null): Collection
|
public function all(): Collection
|
||||||
{
|
{
|
||||||
return Schedule::query()
|
return Schedule::query()
|
||||||
->select(['id', 'course_class_id', 'day_of_week', 'start_time', 'end_time', 'room', 'online_link'])
|
->select(['id', 'course_class_id', 'day_of_week', 'start_time', 'end_time', 'room', 'online_link'])
|
||||||
->with([
|
->with('courseClass.course:id,code,name')
|
||||||
'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')
|
->orderBy('start_time')
|
||||||
->get();
|
->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
|
public function create(array $data): Schedule
|
||||||
{
|
{
|
||||||
return Schedule::create([
|
return Schedule::create([
|
||||||
'course_class_id' => $data['course_class_id'],
|
'course_class_id' => $data['course_class_id'],
|
||||||
'day_of_week' => $data['day_of_week'],
|
'day_of_week' => $data['day_of_week'] ?? null,
|
||||||
'start_time' => $data['start_time'],
|
'start_time' => $data['start_time'] ?? null,
|
||||||
'end_time' => $data['end_time'],
|
'end_time' => $data['end_time'] ?? null,
|
||||||
'room' => $data['room'] ?? null,
|
'room' => $data['room'] ?? null,
|
||||||
'online_link' => $data['online_link'] ?? null,
|
'online_link' => $data['online_link'] ?? null,
|
||||||
]);
|
]);
|
||||||
@ -76,9 +31,9 @@ public function create(array $data): Schedule
|
|||||||
public function update(Schedule $schedule, array $data): Schedule
|
public function update(Schedule $schedule, array $data): Schedule
|
||||||
{
|
{
|
||||||
$schedule->course_class_id = $data['course_class_id'];
|
$schedule->course_class_id = $data['course_class_id'];
|
||||||
$schedule->day_of_week = $data['day_of_week'];
|
$schedule->day_of_week = $data['day_of_week'] ?? null;
|
||||||
$schedule->start_time = $data['start_time'];
|
$schedule->start_time = $data['start_time'] ?? null;
|
||||||
$schedule->end_time = $data['end_time'];
|
$schedule->end_time = $data['end_time'] ?? null;
|
||||||
$schedule->room = $data['room'] ?? null;
|
$schedule->room = $data['room'] ?? null;
|
||||||
$schedule->online_link = $data['online_link'] ?? null;
|
$schedule->online_link = $data['online_link'] ?? null;
|
||||||
$schedule->update();
|
$schedule->update();
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Services\Admin\AcademicClasses;
|
namespace App\Services\Admin\AcademicClasses;
|
||||||
|
|
||||||
use App\Enums\SubmissionStatus;
|
|
||||||
use App\Models\Assignment;
|
use App\Models\Assignment;
|
||||||
use App\Models\Student;
|
use App\Models\Student;
|
||||||
use App\Models\Submission;
|
use App\Models\Submission;
|
||||||
@ -11,29 +10,6 @@
|
|||||||
|
|
||||||
class SubmissionService
|
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
|
public function forAssignment(Assignment $assignment): Collection
|
||||||
{
|
{
|
||||||
return $assignment->submissions()
|
return $assignment->submissions()
|
||||||
@ -42,11 +18,51 @@ public function forAssignment(Assignment $assignment): Collection
|
|||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function grade(Submission $submission, ?float $score): Submission
|
public function availableStudents(Assignment $assignment): Collection
|
||||||
{
|
{
|
||||||
$submission->score = $score;
|
return Student::query()
|
||||||
$submission->update();
|
->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;
|
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->update();
|
||||||
|
|
||||||
|
if ($file) {
|
||||||
|
$submission->addMedia($file)->toMediaCollection('submission_file');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $submission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(Submission $submission): bool
|
||||||
|
{
|
||||||
|
return $submission->delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,32 +3,16 @@
|
|||||||
namespace App\Services\Admin\Manage;
|
namespace App\Services\Admin\Manage;
|
||||||
|
|
||||||
use App\Models\CourseClass;
|
use App\Models\CourseClass;
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class CourseClassService
|
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::query()
|
return CourseClass::select(['id', 'course_id', 'academic_term_id'])
|
||||||
->select(['course_classes.id', 'course_classes.course_id', 'course_classes.lecturer_id', 'course_classes.academic_term_id'])
|
->with('course:id,code,name,semester_number,department_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();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,19 +41,15 @@ public function departmentSummary(): Collection
|
|||||||
public function paginated(int $perPage = 25, string $search = '', ?int $departmentId = null, ?int $advisorLecturerId = null, ?array $ledDepartmentIds = null): LengthAwarePaginator
|
public function paginated(int $perPage = 25, string $search = '', ?int $departmentId = null, ?int $advisorLecturerId = null, ?array $ledDepartmentIds = null): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
$paginator = Student::query()
|
$paginator = Student::query()
|
||||||
->select(['students.id', 'students.user_id', 'students.student_number', 'students.department_id'])
|
->select(['id', 'user_id', 'student_number', 'department_id'])
|
||||||
->join('departments', 'departments.id', '=', 'students.department_id')
|
->where('status', StudentStatus::Active)
|
||||||
->join('users', 'users.id', '=', 'students.user_id')
|
->when($ledDepartmentIds !== null, fn ($q) => $q->whereIn('department_id', $ledDepartmentIds))
|
||||||
->join('user_profiles', 'user_profiles.user_id', '=', 'users.id')
|
->when($departmentId, fn ($q) => $q->where('department_id', $departmentId))
|
||||||
->where('students.status', StudentStatus::Active)
|
->when($advisorLecturerId, fn ($q) => $q->where('academic_advisor_id', $advisorLecturerId))
|
||||||
->when($ledDepartmentIds !== null, fn ($q) => $q->whereIn('students.department_id', $ledDepartmentIds))
|
->when($search, fn ($q) => $q->where('student_number', 'like', "%{$search}%")
|
||||||
->when($departmentId, fn ($q) => $q->where('students.department_id', $departmentId))
|
->orWhereHas('user.profile', fn ($q) => $q->where('full_name', 'like', "%{$search}%")))
|
||||||
->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'])
|
->with(['user.profile', 'department:id,name'])
|
||||||
->orderBy('departments.name')
|
->orderBy('student_number')
|
||||||
->orderBy('user_profiles.full_name')
|
|
||||||
->paginate($perPage);
|
->paginate($perPage);
|
||||||
|
|
||||||
return $paginator->through(fn (Student $student) => [
|
return $paginator->through(fn (Student $student) => [
|
||||||
|
|||||||
@ -14,15 +14,12 @@ class LecturerService
|
|||||||
{
|
{
|
||||||
public function getAllForSelect(): Collection
|
public function getAllForSelect(): Collection
|
||||||
{
|
{
|
||||||
return Lecturer::select(['lecturers.id', 'lecturers.user_id', 'lecturers.lecturer_number'])
|
return Lecturer::select(['id', 'user_id', 'lecturer_number'])
|
||||||
->join('users', 'users.id', '=', 'lecturers.user_id')
|
|
||||||
->join('user_profiles', 'user_profiles.user_id', '=', 'users.id')
|
|
||||||
->with([
|
->with([
|
||||||
'user:id,username',
|
'user:id,username',
|
||||||
'user.profile:id,user_id,full_name',
|
'user.profile:id,user_id,full_name',
|
||||||
'departments:id,name',
|
'departments:id,name',
|
||||||
])
|
])
|
||||||
->orderBy('user_profiles.full_name')
|
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,19 +14,13 @@ class StudentService
|
|||||||
{
|
{
|
||||||
public function getAllForSelect(?string $status = null): Collection
|
public function getAllForSelect(?string $status = null): Collection
|
||||||
{
|
{
|
||||||
return Student::select(['students.id', 'students.user_id', 'students.student_number', 'students.department_id', 'students.current_semester'])
|
return Student::select(['id', 'user_id', 'student_number', 'department_id', '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([
|
->with([
|
||||||
'user:id,username',
|
'user:id,username',
|
||||||
'user.profile:id,user_id,full_name',
|
'user.profile:id,user_id,full_name',
|
||||||
'department:id,name',
|
'department:id,name',
|
||||||
])
|
])
|
||||||
->when($status, fn ($q) => $q->where('students.status', $status))
|
->when($status, fn ($q) => $q->where('status', $status))
|
||||||
->orderBy('departments.name')
|
|
||||||
->orderBy('students.current_semester')
|
|
||||||
->orderBy('user_profiles.full_name')
|
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,10 +15,9 @@ class PermissionCatalog
|
|||||||
public const ACADEMIC_CLASSES = [
|
public const ACADEMIC_CLASSES = [
|
||||||
'view-materials', 'create-materials', 'update-materials', 'delete-materials',
|
'view-materials', 'create-materials', 'update-materials', 'delete-materials',
|
||||||
'view-assignments', 'create-assignments', 'update-assignments', 'delete-assignments',
|
'view-assignments', 'create-assignments', 'update-assignments', 'delete-assignments',
|
||||||
'view-assignment-submissions', 'update-assignment-submissions',
|
'view-assignment-submissions', 'create-assignment-submissions', 'update-assignment-submissions', 'delete-assignment-submissions',
|
||||||
'submit-assignments',
|
|
||||||
'view-schedules', 'create-schedules', 'update-schedules', 'delete-schedules',
|
'view-schedules', 'create-schedules', 'update-schedules', 'delete-schedules',
|
||||||
'view-attendances', 'create-attendances', 'delete-attendances', 'view-own-attendances',
|
'view-attendances', 'create-attendances', 'delete-attendances',
|
||||||
];
|
];
|
||||||
|
|
||||||
public const MANAGE = [
|
public const MANAGE = [
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
<?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,11 +46,6 @@ public function run(): void
|
|||||||
'create-letter-requests',
|
'create-letter-requests',
|
||||||
'update-letter-requests',
|
'update-letter-requests',
|
||||||
'delete-letter-requests',
|
'delete-letter-requests',
|
||||||
'view-schedules',
|
|
||||||
'view-materials',
|
|
||||||
'view-assignments',
|
|
||||||
'submit-assignments',
|
|
||||||
'view-own-attendances',
|
|
||||||
...$feedbackSelfService,
|
...$feedbackSelfService,
|
||||||
],
|
],
|
||||||
'dosen' => [
|
'dosen' => [
|
||||||
@ -61,20 +56,6 @@ public function run(): void
|
|||||||
'view-course-registrations',
|
'view-course-registrations',
|
||||||
'approve-course-registrations',
|
'approve-course-registrations',
|
||||||
'reject-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,
|
...$feedbackSelfService,
|
||||||
],
|
],
|
||||||
'staff-admin' => [
|
'staff-admin' => [
|
||||||
|
|||||||
@ -36,10 +36,7 @@ import {
|
|||||||
SidebarMenuItem,
|
SidebarMenuItem,
|
||||||
} from '@/components/ui/sidebar';
|
} from '@/components/ui/sidebar';
|
||||||
import { index as assignmentsRoute } from '@/routes/admin/academic-classes/assignments';
|
import { index as assignmentsRoute } from '@/routes/admin/academic-classes/assignments';
|
||||||
import {
|
import { index as attendancesRoute } from '@/routes/admin/academic-classes/attendances';
|
||||||
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 materialsRoute } from '@/routes/admin/academic-classes/materials';
|
||||||
import { index as schedulesRoute } from '@/routes/admin/academic-classes/schedules';
|
import { index as schedulesRoute } from '@/routes/admin/academic-classes/schedules';
|
||||||
import { index as logsRoute } from '@/routes/admin/developer/logs';
|
import { index as logsRoute } from '@/routes/admin/developer/logs';
|
||||||
@ -175,15 +172,6 @@ function buildNavMain({
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
...(can('view-own-attendances')
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
name: 'Riwayat Kehadiran',
|
|
||||||
url: myAttendancesRoute.url(),
|
|
||||||
icon: ClipboardCheck,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const keuanganItems: NavItem[] = [
|
const keuanganItems: NavItem[] = [
|
||||||
|
|||||||
@ -1,105 +0,0 @@
|
|||||||
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,17 +1,6 @@
|
|||||||
import { Filter, X } from 'lucide-react';
|
import { Filter, X } from 'lucide-react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
|
||||||
Combobox,
|
|
||||||
ComboboxCollection,
|
|
||||||
ComboboxContent,
|
|
||||||
ComboboxEmpty,
|
|
||||||
ComboboxGroup,
|
|
||||||
ComboboxInput,
|
|
||||||
ComboboxItem,
|
|
||||||
ComboboxLabel,
|
|
||||||
ComboboxList,
|
|
||||||
} from '@/components/ui/combobox';
|
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@ -33,88 +22,19 @@ export type FilterOption = {
|
|||||||
label: string;
|
label: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FilterOptionGroup = {
|
export type FilterField = {
|
||||||
|
key: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
placeholder?: string;
|
||||||
options: FilterOption[];
|
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 = {
|
type FilterDialogProps = {
|
||||||
fields: FilterField[];
|
fields: FilterField[];
|
||||||
activeFilters: Record<string, string | undefined>;
|
activeFilters: Record<string, string | undefined>;
|
||||||
onApply: (filters: Record<string, string>) => void;
|
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({
|
export function FilterDialog({
|
||||||
fields,
|
fields,
|
||||||
activeFilters,
|
activeFilters,
|
||||||
@ -172,48 +92,33 @@ export function FilterDialog({
|
|||||||
{fields.map((field) => (
|
{fields.map((field) => (
|
||||||
<div className="grid gap-2" key={field.key}>
|
<div className="grid gap-2" key={field.key}>
|
||||||
<Label>{field.label}</Label>
|
<Label>{field.label}</Label>
|
||||||
{field.type === 'combobox' ? (
|
<Select
|
||||||
<ComboboxFilterField
|
value={activeFilters[field.key] ?? 'all'}
|
||||||
field={field}
|
onValueChange={(value) =>
|
||||||
value={
|
handleChange(field.key, value)
|
||||||
activeFilters[field.key] ?? 'all'
|
}
|
||||||
}
|
>
|
||||||
onChange={(value) =>
|
<SelectTrigger className="w-full">
|
||||||
handleChange(field.key, value)
|
<SelectValue
|
||||||
}
|
placeholder={
|
||||||
/>
|
field.placeholder ?? 'Semua'
|
||||||
) : (
|
}
|
||||||
<Select
|
/>
|
||||||
value={
|
</SelectTrigger>
|
||||||
activeFilters[field.key] ?? 'all'
|
<SelectContent>
|
||||||
}
|
<SelectItem value="all">
|
||||||
onValueChange={(value) =>
|
Semua
|
||||||
handleChange(field.key, value)
|
</SelectItem>
|
||||||
}
|
{field.options.map((option) => (
|
||||||
>
|
<SelectItem
|
||||||
<SelectTrigger className="w-full">
|
key={option.value}
|
||||||
<SelectValue
|
value={option.value}
|
||||||
placeholder={
|
>
|
||||||
field.placeholder ??
|
{option.label}
|
||||||
'Semua'
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
<SelectItem value="all">
|
|
||||||
Semua
|
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
{field.options.map((option) => (
|
))}
|
||||||
<SelectItem
|
</SelectContent>
|
||||||
key={option.value}
|
</Select>
|
||||||
value={option.value}
|
|
||||||
>
|
|
||||||
{option.label}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,63 +0,0 @@
|
|||||||
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,12 +7,6 @@ type UseServerTableOptions = {
|
|||||||
pagination: PaginationState;
|
pagination: PaginationState;
|
||||||
filters?: Record<string, string | undefined>;
|
filters?: Record<string, string | undefined>;
|
||||||
filterWithParams?: boolean;
|
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({
|
export function useServerTable({
|
||||||
@ -20,11 +14,8 @@ export function useServerTable({
|
|||||||
pagination,
|
pagination,
|
||||||
filters,
|
filters,
|
||||||
filterWithParams = true,
|
filterWithParams = true,
|
||||||
resetKeys,
|
|
||||||
}: UseServerTableOptions) {
|
}: UseServerTableOptions) {
|
||||||
const [search, setSearch] = useState(
|
const [search, setSearch] = useState('');
|
||||||
() => new URLSearchParams(window.location.search).get('search') ?? '',
|
|
||||||
);
|
|
||||||
const [filterOpen, setFilterOpen] = useState(false);
|
const [filterOpen, setFilterOpen] = useState(false);
|
||||||
|
|
||||||
const handlePageChange = useCallback(
|
const handlePageChange = useCallback(
|
||||||
@ -70,14 +61,10 @@ export function useServerTable({
|
|||||||
per_page: pagination.per_page,
|
per_page: pagination.per_page,
|
||||||
search: value,
|
search: value,
|
||||||
},
|
},
|
||||||
{
|
{ preserveState: true, replace: true },
|
||||||
preserveState: true,
|
|
||||||
replace: true,
|
|
||||||
...(resetKeys ? { reset: resetKeys } : {}),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[route, filters, pagination.per_page, resetKeys],
|
[route, filters, pagination.per_page],
|
||||||
);
|
);
|
||||||
|
|
||||||
function applyFilter(key: string, value: string) {
|
function applyFilter(key: string, value: string) {
|
||||||
@ -99,11 +86,7 @@ export function useServerTable({
|
|||||||
search,
|
search,
|
||||||
}
|
}
|
||||||
: newFilters,
|
: newFilters,
|
||||||
{
|
{ preserveState: true, replace: true },
|
||||||
preserveState: true,
|
|
||||||
replace: true,
|
|
||||||
...(resetKeys ? { reset: resetKeys } : {}),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,11 +101,7 @@ export function useServerTable({
|
|||||||
search,
|
search,
|
||||||
}
|
}
|
||||||
: newFilters,
|
: newFilters,
|
||||||
{
|
{ preserveState: true, replace: true },
|
||||||
preserveState: true,
|
|
||||||
replace: true,
|
|
||||||
...(resetKeys ? { reset: resetKeys } : {}),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,11 +115,7 @@ export function useServerTable({
|
|||||||
search,
|
search,
|
||||||
}
|
}
|
||||||
: {},
|
: {},
|
||||||
{
|
{ preserveState: true, replace: true },
|
||||||
preserveState: true,
|
|
||||||
replace: true,
|
|
||||||
...(resetKeys ? { reset: resetKeys } : {}),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
setFilterOpen(false);
|
setFilterOpen(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,143 @@
|
|||||||
|
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,48 +1,17 @@
|
|||||||
import { Head, InfiniteScroll, router } from '@inertiajs/react';
|
import { Head, router } from '@inertiajs/react';
|
||||||
import { format } from 'date-fns';
|
import { Plus } from 'lucide-react';
|
||||||
import {
|
|
||||||
Clock,
|
|
||||||
ClipboardList,
|
|
||||||
Paperclip,
|
|
||||||
Pencil,
|
|
||||||
Plus,
|
|
||||||
Trash2,
|
|
||||||
Upload,
|
|
||||||
} from 'lucide-react';
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { AttachmentPreviewDialog } from '@/components/attachment-preview-dialog';
|
import type { PaginationState } from '@/components/data-table';
|
||||||
|
import { DataTable } from '@/components/data-table';
|
||||||
import { DateTimeField } from '@/components/datetime-field';
|
import { DateTimeField } from '@/components/datetime-field';
|
||||||
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
||||||
import { FileUploadField } from '@/components/file-upload-field';
|
import { FileUploadField } from '@/components/file-upload-field';
|
||||||
import type {
|
import type { FilterField } from '@/components/filter-dialog';
|
||||||
FilterField,
|
|
||||||
FilterOptionGroup,
|
|
||||||
} from '@/components/filter-dialog';
|
|
||||||
import { FilterDialog } from '@/components/filter-dialog';
|
import { FilterDialog } from '@/components/filter-dialog';
|
||||||
import { FormDialog } from '@/components/form-dialog';
|
import { FormDialog } from '@/components/form-dialog';
|
||||||
import InputError from '@/components/input-error';
|
import InputError from '@/components/input-error';
|
||||||
import { PageHeader } from '@/components/page-header';
|
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 { 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 { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import {
|
import {
|
||||||
@ -59,31 +28,14 @@ import {
|
|||||||
index as assignmentIndex,
|
index as assignmentIndex,
|
||||||
destroy,
|
destroy,
|
||||||
store,
|
store,
|
||||||
submit,
|
|
||||||
update,
|
update,
|
||||||
} from '@/routes/admin/academic-classes/assignments';
|
} 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 type { Assignment } from '@/types/assignment';
|
||||||
import { AssignmentStatusLabels, AssignmentStatuses } from '@/types/assignment';
|
import { createAssignmentColumns } from './columns';
|
||||||
|
|
||||||
type CourseClassOption = {
|
type CourseClassOption = {
|
||||||
id: number;
|
id: number;
|
||||||
course: {
|
course: { id: number; code: string; name: string } | null;
|
||||||
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 = {
|
type Props = {
|
||||||
@ -95,179 +47,61 @@ type Props = {
|
|||||||
total: number;
|
total: number;
|
||||||
};
|
};
|
||||||
courseClasses: CourseClassOption[];
|
courseClasses: CourseClassOption[];
|
||||||
academicTerms: AcademicTermOption[];
|
|
||||||
highlight?: number;
|
highlight?: number;
|
||||||
filters: {
|
filters: {
|
||||||
course_class_id?: string;
|
course_class_id?: string;
|
||||||
academic_term_id?: string;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function courseClassLabel(courseClass: CourseClassOption): 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({
|
export default function AssignmentIndex({
|
||||||
assignments,
|
assignments,
|
||||||
courseClasses,
|
courseClasses,
|
||||||
academicTerms,
|
|
||||||
highlight,
|
highlight,
|
||||||
filters,
|
filters,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
const [editing, setEditing] = useState<Assignment | null>(null);
|
const [editing, setEditing] = useState<Assignment | null>(null);
|
||||||
const [deleting, setDeleting] = useState<Assignment | null>(null);
|
const [deleting, setDeleting] = useState<Assignment | null>(null);
|
||||||
const [submitting, setSubmitting] = useState<Assignment | null>(null);
|
|
||||||
const { hasPermission } = usePermissions();
|
const { hasPermission } = usePermissions();
|
||||||
const canCreate = hasPermission('create-assignments');
|
const canCreate = hasPermission('create-assignments');
|
||||||
const canUpdate = hasPermission('update-assignments');
|
const canUpdate = hasPermission('update-assignments');
|
||||||
const canDelete = hasPermission('delete-assignments');
|
const canDelete = hasPermission('delete-assignments');
|
||||||
const canViewSubmissions = hasPermission('view-assignment-submissions');
|
const canViewSubmissions = hasPermission('view-assignment-submissions');
|
||||||
const canSubmit = hasPermission('submit-assignments');
|
|
||||||
|
|
||||||
const filterFields: FilterField[] = [
|
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',
|
key: 'course_class_id',
|
||||||
label: 'Kelas',
|
label: 'Kelas',
|
||||||
type: 'combobox' as const,
|
options: courseClasses.map((courseClass) => ({
|
||||||
groups: courseClassFilterGroups(courseClasses),
|
value: String(courseClass.id),
|
||||||
|
label: courseClassLabel(courseClass),
|
||||||
|
})),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const pagination = {
|
const pagination: PaginationState = {
|
||||||
current_page: assignments.current_page,
|
current_page: assignments.current_page,
|
||||||
last_page: assignments.last_page,
|
last_page: assignments.last_page,
|
||||||
per_page: assignments.per_page,
|
per_page: assignments.per_page,
|
||||||
total: assignments.total,
|
total: assignments.total,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { search, handleSearchChange, applyFilters } = useServerTable({
|
const {
|
||||||
|
search,
|
||||||
|
handlePageChange,
|
||||||
|
handlePerPageChange,
|
||||||
|
handleSearchChange,
|
||||||
|
applyFilters,
|
||||||
|
} = useServerTable({
|
||||||
route: () => assignmentIndex.url(),
|
route: () => assignmentIndex.url(),
|
||||||
pagination,
|
pagination,
|
||||||
filters,
|
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() {
|
function handleDelete() {
|
||||||
if (!deleting) {
|
if (!deleting) {
|
||||||
return;
|
return;
|
||||||
@ -278,6 +112,14 @@ export default function AssignmentIndex({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const columns = createAssignmentColumns({
|
||||||
|
handleEdit: (assignment) => setEditing(assignment),
|
||||||
|
handleDeleteClick: (assignment) => setDeleting(assignment),
|
||||||
|
canUpdate,
|
||||||
|
canDelete,
|
||||||
|
canViewSubmissions,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head title="Tugas" />
|
<Head title="Tugas" />
|
||||||
@ -340,269 +182,24 @@ export default function AssignmentIndex({
|
|||||||
courseClasses={courseClasses}
|
courseClasses={courseClasses}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SubmitForm
|
<DataTable
|
||||||
key={submitting?.id}
|
columns={columns}
|
||||||
open={submitting !== null}
|
data={assignments.data}
|
||||||
onOpenChange={(open) => {
|
searchKey="title"
|
||||||
if (!open) {
|
pagination={pagination}
|
||||||
setSubmitting(null);
|
onPageChange={handlePageChange}
|
||||||
}
|
onPerPageChange={handlePerPageChange}
|
||||||
}}
|
onSearchChange={handleSearchChange}
|
||||||
assignment={submitting}
|
searchValue={search}
|
||||||
|
toolbar={
|
||||||
|
<FilterDialog
|
||||||
|
fields={filterFields}
|
||||||
|
activeFilters={filters}
|
||||||
|
onApply={applyFilters}
|
||||||
|
/>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<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={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
|
<DeleteConfirmDialog
|
||||||
target={deleting}
|
target={deleting}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
@ -630,10 +227,6 @@ function CreateForm({
|
|||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
courseClasses: CourseClassOption[];
|
courseClasses: CourseClassOption[];
|
||||||
}) {
|
}) {
|
||||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormDialog
|
<FormDialog
|
||||||
open={open}
|
open={open}
|
||||||
@ -641,10 +234,7 @@ function CreateForm({
|
|||||||
title="Tambah Tugas"
|
title="Tambah Tugas"
|
||||||
action={store()}
|
action={store()}
|
||||||
resetOnSuccess
|
resetOnSuccess
|
||||||
onSuccess={() => {
|
onSuccess={() => onOpenChange(false)}
|
||||||
onOpenChange(false);
|
|
||||||
setCourseClass(null);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{({ errors }) => (
|
{({ errors }) => (
|
||||||
<div className="grid gap-4">
|
<div className="grid gap-4">
|
||||||
@ -652,16 +242,22 @@ function CreateForm({
|
|||||||
<Label>
|
<Label>
|
||||||
Kelas <span className="text-destructive">*</span>
|
Kelas <span className="text-destructive">*</span>
|
||||||
</Label>
|
</Label>
|
||||||
<input
|
<input type="hidden" name="course_class_id" />
|
||||||
type="hidden"
|
<Select name="course_class_id">
|
||||||
name="course_class_id"
|
<SelectTrigger className="w-full">
|
||||||
value={courseClass?.id ?? ''}
|
<SelectValue placeholder="Pilih kelas" />
|
||||||
/>
|
</SelectTrigger>
|
||||||
<CourseClassField
|
<SelectContent>
|
||||||
courseClasses={courseClasses}
|
{courseClasses.map((courseClass) => (
|
||||||
value={courseClass}
|
<SelectItem
|
||||||
onChange={setCourseClass}
|
key={courseClass.id}
|
||||||
/>
|
value={String(courseClass.id)}
|
||||||
|
>
|
||||||
|
{courseClassLabel(courseClass)}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
<InputError message={errors.course_class_id} />
|
<InputError message={errors.course_class_id} />
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
@ -714,13 +310,6 @@ function EditForm({
|
|||||||
editing: Assignment | null;
|
editing: Assignment | null;
|
||||||
courseClasses: CourseClassOption[];
|
courseClasses: CourseClassOption[];
|
||||||
}) {
|
}) {
|
||||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
|
||||||
editing
|
|
||||||
? (courseClasses.find((c) => c.id === editing.course_class_id) ??
|
|
||||||
null)
|
|
||||||
: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormDialog
|
<FormDialog
|
||||||
open={open}
|
open={open}
|
||||||
@ -738,16 +327,24 @@ function EditForm({
|
|||||||
Kelas{' '}
|
Kelas{' '}
|
||||||
<span className="text-destructive">*</span>
|
<span className="text-destructive">*</span>
|
||||||
</Label>
|
</Label>
|
||||||
<input
|
<Select
|
||||||
type="hidden"
|
|
||||||
name="course_class_id"
|
name="course_class_id"
|
||||||
value={courseClass?.id ?? ''}
|
defaultValue={String(editing.course_class_id)}
|
||||||
/>
|
>
|
||||||
<CourseClassField
|
<SelectTrigger className="w-full">
|
||||||
courseClasses={courseClasses}
|
<SelectValue placeholder="Pilih kelas" />
|
||||||
value={courseClass}
|
</SelectTrigger>
|
||||||
onChange={setCourseClass}
|
<SelectContent>
|
||||||
/>
|
{courseClasses.map((courseClass) => (
|
||||||
|
<SelectItem
|
||||||
|
key={courseClass.id}
|
||||||
|
value={String(courseClass.id)}
|
||||||
|
>
|
||||||
|
{courseClassLabel(courseClass)}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
<InputError message={errors.course_class_id} />
|
<InputError message={errors.course_class_id} />
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
@ -781,30 +378,6 @@ function EditForm({
|
|||||||
placeholder="Pilih tanggal batas waktu"
|
placeholder="Pilih tanggal batas waktu"
|
||||||
error={errors.deadline}
|
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
|
<FileUploadField
|
||||||
name="attachment"
|
name="attachment"
|
||||||
label="Lampiran"
|
label="Lampiran"
|
||||||
@ -818,49 +391,3 @@ function EditForm({
|
|||||||
</FormDialog>
|
</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,96 +1,68 @@
|
|||||||
import { Head, Link, router } from '@inertiajs/react';
|
import { Head, Link, router } from '@inertiajs/react';
|
||||||
import type { ColumnDef } from '@tanstack/react-table';
|
import type { ColumnDef } from '@tanstack/react-table';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import { ArrowLeft, Save } from 'lucide-react';
|
import { ArrowLeft, Pencil, Plus, Trash2 } from 'lucide-react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { DataTable } from '@/components/data-table';
|
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 { PageHeader } from '@/components/page-header';
|
||||||
|
import { RowActions } from '@/components/row-actions';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Input } from '@/components/ui/input';
|
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 { usePermissions } from '@/hooks/use-permissions';
|
||||||
import { index as assignmentIndex } from '@/routes/admin/academic-classes/assignments';
|
import { index as assignmentIndex } from '@/routes/admin/academic-classes/assignments';
|
||||||
import { grade } from '@/routes/admin/academic-classes/assignments/submissions';
|
import {
|
||||||
import { AssignmentStatusLabels } from '@/types/assignment';
|
destroy,
|
||||||
|
store,
|
||||||
|
update,
|
||||||
|
} from '@/routes/admin/academic-classes/assignments/submissions';
|
||||||
import type { Assignment } from '@/types/assignment';
|
import type { Assignment } from '@/types/assignment';
|
||||||
import type { Submission } from '@/types/submission';
|
import type { Submission, SubmissionStudent } from '@/types/submission';
|
||||||
import { SubmissionStatusLabels } from '@/types/submission';
|
import { SubmissionStatusLabels, SubmissionStatuses } from '@/types/submission';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
assignment: Assignment;
|
assignment: Assignment;
|
||||||
submissions: Submission[];
|
submissions: Submission[];
|
||||||
|
availableStudents: SubmissionStudent[];
|
||||||
};
|
};
|
||||||
|
|
||||||
function ScoreCell({
|
export default function SubmissionIndex({
|
||||||
assignmentId,
|
assignment,
|
||||||
submission,
|
submissions,
|
||||||
canUpdate,
|
availableStudents,
|
||||||
}: {
|
}: Props) {
|
||||||
assignmentId: number;
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
submission: Submission;
|
const [editing, setEditing] = useState<Submission | null>(null);
|
||||||
canUpdate: boolean;
|
const [deleting, setDeleting] = useState<Submission | null>(null);
|
||||||
}) {
|
|
||||||
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 { hasPermission } = usePermissions();
|
||||||
|
const canCreate = hasPermission('create-assignment-submissions');
|
||||||
const canUpdate = hasPermission('update-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>[] = [
|
const columns: ColumnDef<Submission>[] = [
|
||||||
{
|
{
|
||||||
@ -150,19 +122,46 @@ export default function SubmissionIndex({ assignment, submissions }: Props) {
|
|||||||
accessorKey: 'score',
|
accessorKey: 'score',
|
||||||
header: () => <span className="block text-center">Nilai</span>,
|
header: () => <span className="block text-center">Nilai</span>,
|
||||||
meta: {
|
meta: {
|
||||||
className: 'w-[140px] text-center',
|
className: 'w-[90px] text-center',
|
||||||
headerClassName: 'w-[140px] text-center',
|
headerClassName: 'w-[90px] text-center',
|
||||||
},
|
},
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<ScoreCell
|
<div className="text-center">{row.original.score ?? '-'}</div>
|
||||||
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head title="Pengumpulan Tugas" />
|
<Head title="Pengumpulan Tugas" />
|
||||||
@ -181,17 +180,8 @@ export default function SubmissionIndex({ assignment, submissions }: Props) {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-start justify-between gap-2">
|
<CardHeader>
|
||||||
<CardTitle>{assignment.title}</CardTitle>
|
<CardTitle>{assignment.title}</CardTitle>
|
||||||
<Badge
|
|
||||||
variant={
|
|
||||||
assignment.status === 'open'
|
|
||||||
? 'secondary'
|
|
||||||
: 'destructive'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{AssignmentStatusLabels[assignment.status]}
|
|
||||||
</Badge>
|
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="grid gap-1 text-sm text-muted-foreground">
|
<CardContent className="grid gap-1 text-sm text-muted-foreground">
|
||||||
<p>
|
<p>
|
||||||
@ -209,10 +199,237 @@ export default function SubmissionIndex({ assignment, submissions }: Props) {
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<h2 className="text-lg font-semibold">Daftar Pengumpulan</h2>
|
<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>
|
||||||
|
|
||||||
<DataTable columns={columns} data={submissions} />
|
<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>
|
</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}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,255 +0,0 @@
|
|||||||
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,73 +1,60 @@
|
|||||||
import { Head, Link } from '@inertiajs/react';
|
import { Head, Link, router } from '@inertiajs/react';
|
||||||
import type { FilterField } from '@/components/filter-dialog';
|
import { format } from 'date-fns';
|
||||||
import { FilterDialog } from '@/components/filter-dialog';
|
import { ClipboardCheck, Pencil, Plus, Trash2, X } from 'lucide-react';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { useServerTable } from '@/hooks/use-server-table';
|
|
||||||
import {
|
import {
|
||||||
index as attendanceIndex,
|
Dialog,
|
||||||
show,
|
DialogContent,
|
||||||
} from '@/routes/admin/academic-classes/attendances';
|
DialogFooter,
|
||||||
import { formatAcademicTermLabel } from '@/types/academic-term';
|
DialogHeader,
|
||||||
import type { AttendanceCourseClassOverview } from '@/types/attendance';
|
DialogTitle,
|
||||||
|
} from '@/components/ui/dialog';
|
||||||
type AcademicTermOption = {
|
import { Input } from '@/components/ui/input';
|
||||||
id: number;
|
import { Label } from '@/components/ui/label';
|
||||||
academic_year: string;
|
import {
|
||||||
semester: string;
|
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';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
courseClasses: AttendanceCourseClassOverview[];
|
sessions: AttendanceSession[];
|
||||||
academicTerms: AcademicTermOption[];
|
courseClasses: AttendanceCourseClass[];
|
||||||
filters: {
|
|
||||||
academic_term_id?: string;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function courseClassLabel(courseClass: AttendanceCourseClassOverview): string {
|
function courseClassLabel(courseClass: AttendanceCourseClass): string {
|
||||||
return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`;
|
return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function AttendanceIndex({
|
export default function AttendanceIndex({ sessions, courseClasses }: Props) {
|
||||||
courseClasses,
|
const [newSessionOpen, setNewSessionOpen] = useState(false);
|
||||||
academicTerms,
|
const [deleting, setDeleting] = useState<AttendanceSession | null>(null);
|
||||||
filters,
|
const { hasPermission } = usePermissions();
|
||||||
}: Props) {
|
const canCreate = hasPermission('create-attendances');
|
||||||
const filterFields: FilterField[] = [
|
const canDelete = hasPermission('delete-attendances');
|
||||||
{
|
|
||||||
key: 'academic_term_id',
|
|
||||||
label: 'Periode Akademik',
|
|
||||||
options: academicTerms.map((term) => ({
|
|
||||||
value: String(term.id),
|
|
||||||
label: formatAcademicTermLabel(term),
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const { applyFilters } = useServerTable({
|
function handleDelete() {
|
||||||
route: () => attendanceIndex.url(),
|
if (!deleting || deleting.meeting_number === null) {
|
||||||
pagination: {
|
return;
|
||||||
current_page: 1,
|
}
|
||||||
last_page: 1,
|
|
||||||
per_page: 999999,
|
|
||||||
total: courseClasses.length,
|
|
||||||
},
|
|
||||||
filters,
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleApplyFilters(newFilters: Record<string, string>) {
|
router.delete(
|
||||||
// Tanpa `academic_term_id` eksplisit, backend akan kembali ke
|
destroy([deleting.course_class_id, deleting.meeting_number]).url,
|
||||||
// periode aktif, jadi menghapus filter ini perlu dikirim eksplisit
|
{ onSuccess: () => setDeleting(null) },
|
||||||
// alih-alih hanya menghilangkan key-nya.
|
);
|
||||||
const clearedAcademicTerm =
|
|
||||||
Boolean(filters.academic_term_id) && !newFilters.academic_term_id;
|
|
||||||
|
|
||||||
applyFilters({
|
|
||||||
...newFilters,
|
|
||||||
...(clearedAcademicTerm ? { academic_term_id: '' } : {}),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -78,65 +65,218 @@ export default function AttendanceIndex({
|
|||||||
<PageHeader
|
<PageHeader
|
||||||
title="Kehadiran"
|
title="Kehadiran"
|
||||||
actions={
|
actions={
|
||||||
<FilterDialog
|
canCreate && (
|
||||||
fields={filterFields}
|
<Button onClick={() => setNewSessionOpen(true)}>
|
||||||
activeFilters={filters}
|
<Plus className="h-4 w-4" />
|
||||||
onApply={handleApplyFilters}
|
Ambil Kehadiran
|
||||||
/>
|
</Button>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{courseClasses.length === 0 ? (
|
{sessions.length === 0 ? (
|
||||||
<p className="rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
Tidak ada kelas untuk periode ini.
|
Belum ada data kehadiran.
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3">
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
{courseClasses.map((courseClass) => (
|
{sessions.map((item) => {
|
||||||
<Link
|
const key = `${item.course_class_id}-${item.meeting_number}-${item.date}`;
|
||||||
key={courseClass.id}
|
const canOpen = item.meeting_number !== null;
|
||||||
href={show(courseClass.id).url}
|
|
||||||
>
|
return (
|
||||||
<Card className="h-full transition-colors hover:border-primary">
|
<Card key={key}>
|
||||||
<CardHeader>
|
<CardHeader className="flex flex-row items-start justify-between gap-2">
|
||||||
<CardTitle className="text-base leading-tight">
|
<CardTitle className="text-sm leading-tight">
|
||||||
{courseClassLabel(courseClass)}
|
{item.course_class
|
||||||
|
? courseClassLabel(
|
||||||
|
item.course_class,
|
||||||
|
)
|
||||||
|
: '-'}
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
|
<Badge variant="secondary">
|
||||||
|
{item.present_count}/
|
||||||
|
{item.total_count} Hadir
|
||||||
|
</Badge>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex flex-col gap-2">
|
<CardContent className="flex flex-col gap-2">
|
||||||
<div className="flex flex-wrap items-center gap-1.5">
|
<p className="text-xs text-muted-foreground">
|
||||||
<Badge
|
Pertemuan ke-
|
||||||
variant="secondary"
|
{item.meeting_number ?? '-'}{' '}
|
||||||
className="w-fit text-[10px] font-normal"
|
·{' '}
|
||||||
>
|
{format(
|
||||||
{courseClass.meetings_count}{' '}
|
new Date(item.date),
|
||||||
Pertemuan
|
'd MMM yyyy',
|
||||||
</Badge>
|
)}
|
||||||
<Badge
|
</p>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="w-fit text-[10px] font-normal"
|
size="sm"
|
||||||
|
asChild
|
||||||
|
disabled={!canOpen}
|
||||||
>
|
>
|
||||||
{courseClass.enrollments_count}{' '}
|
{canOpen ? (
|
||||||
Mahasiswa
|
<Link
|
||||||
</Badge>
|
href={
|
||||||
{courseClass.academic_term && (
|
session([
|
||||||
<Badge
|
item.course_class_id,
|
||||||
variant="outline"
|
item.meeting_number as number,
|
||||||
className="w-fit text-[10px] font-normal"
|
]).url
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Pencil className="h-4 w-4" />
|
||||||
|
Lihat / Edit
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<span>
|
||||||
|
<Pencil className="h-4 w-4" />
|
||||||
|
Lihat / Edit
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
{canDelete && (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
disabled={!canOpen}
|
||||||
|
onClick={() =>
|
||||||
|
setDeleting(item)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{formatAcademicTermLabel(
|
<Trash2 className="h-4 w-4 text-destructive" />
|
||||||
courseClass.academic_term,
|
</Button>
|
||||||
)}
|
|
||||||
</Badge>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</Link>
|
);
|
||||||
))}
|
})}
|
||||||
</div>
|
</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>
|
</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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,150 +0,0 @@
|
|||||||
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,7 +8,10 @@ import { Button } from '@/components/ui/button';
|
|||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import { usePermissions } from '@/hooks/use-permissions';
|
import { usePermissions } from '@/hooks/use-permissions';
|
||||||
import { show, store } from '@/routes/admin/academic-classes/attendances';
|
import {
|
||||||
|
index as attendanceIndex,
|
||||||
|
store,
|
||||||
|
} from '@/routes/admin/academic-classes/attendances';
|
||||||
import type {
|
import type {
|
||||||
AttendanceCourseClass,
|
AttendanceCourseClass,
|
||||||
AttendanceRosterEntry,
|
AttendanceRosterEntry,
|
||||||
@ -86,7 +89,7 @@ export default function AttendanceSession({
|
|||||||
title="Kehadiran"
|
title="Kehadiran"
|
||||||
actions={
|
actions={
|
||||||
<Button variant="outline" asChild>
|
<Button variant="outline" asChild>
|
||||||
<Link href={show(courseClass.id).url}>
|
<Link href={attendanceIndex.url()}>
|
||||||
<ArrowLeft className="h-4 w-4" />
|
<ArrowLeft className="h-4 w-4" />
|
||||||
Kembali
|
Kembali
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import type { ColumnDef } from '@tanstack/react-table';
|
import type { ColumnDef } from '@tanstack/react-table';
|
||||||
import { Pencil, Trash2 } from 'lucide-react';
|
import { Paperclip, Pencil, Trash2 } from 'lucide-react';
|
||||||
import { AttachmentPreviewDialog } from '@/components/attachment-preview-dialog';
|
|
||||||
import { RowActions } from '@/components/row-actions';
|
import { RowActions } from '@/components/row-actions';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import type { Material } from '@/types/material';
|
import type { Material } from '@/types/material';
|
||||||
@ -70,15 +69,20 @@ export function createMaterialColumns(
|
|||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const material = row.original;
|
const material = row.original;
|
||||||
|
|
||||||
if (!material.file_url || !material.file_name) {
|
if (!material.file_url) {
|
||||||
return <span className="text-muted-foreground">-</span>;
|
return <span className="text-muted-foreground">-</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AttachmentPreviewDialog
|
<a
|
||||||
fileUrl={material.file_url}
|
href={material.file_url}
|
||||||
fileName={material.file_name}
|
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>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -5,25 +5,21 @@ import type { PaginationState } from '@/components/data-table';
|
|||||||
import { DataTable } from '@/components/data-table';
|
import { DataTable } from '@/components/data-table';
|
||||||
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog';
|
||||||
import { FileUploadField } from '@/components/file-upload-field';
|
import { FileUploadField } from '@/components/file-upload-field';
|
||||||
import type { FilterOptionGroup } from '@/components/filter-dialog';
|
import type { FilterField } from '@/components/filter-dialog';
|
||||||
import { FilterDialog } from '@/components/filter-dialog';
|
import { FilterDialog } from '@/components/filter-dialog';
|
||||||
import { FormDialog } from '@/components/form-dialog';
|
import { FormDialog } from '@/components/form-dialog';
|
||||||
import InputError from '@/components/input-error';
|
import InputError from '@/components/input-error';
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
import { Button } from '@/components/ui/button';
|
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 { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@/components/ui/select';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { usePermissions } from '@/hooks/use-permissions';
|
import { usePermissions } from '@/hooks/use-permissions';
|
||||||
import { useServerTable } from '@/hooks/use-server-table';
|
import { useServerTable } from '@/hooks/use-server-table';
|
||||||
@ -38,17 +34,9 @@ import { createMaterialColumns } from './columns';
|
|||||||
|
|
||||||
type CourseClassOption = {
|
type CourseClassOption = {
|
||||||
id: number;
|
id: number;
|
||||||
course: {
|
course: { id: number; code: string; name: string } | null;
|
||||||
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 = {
|
type Props = {
|
||||||
materials: {
|
materials: {
|
||||||
data: Material[];
|
data: Material[];
|
||||||
@ -65,80 +53,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function courseClassLabel(courseClass: CourseClassOption): string {
|
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({
|
export default function MaterialIndex({
|
||||||
@ -155,12 +70,14 @@ export default function MaterialIndex({
|
|||||||
const canUpdate = hasPermission('update-materials');
|
const canUpdate = hasPermission('update-materials');
|
||||||
const canDelete = hasPermission('delete-materials');
|
const canDelete = hasPermission('delete-materials');
|
||||||
|
|
||||||
const filterFields = [
|
const filterFields: FilterField[] = [
|
||||||
{
|
{
|
||||||
key: 'course_class_id',
|
key: 'course_class_id',
|
||||||
label: 'Kelas',
|
label: 'Kelas',
|
||||||
type: 'combobox' as const,
|
options: courseClasses.map((courseClass) => ({
|
||||||
groups: courseClassFilterGroups(courseClasses),
|
value: String(courseClass.id),
|
||||||
|
label: courseClassLabel(courseClass),
|
||||||
|
})),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -307,10 +224,6 @@ function CreateForm({
|
|||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
courseClasses: CourseClassOption[];
|
courseClasses: CourseClassOption[];
|
||||||
}) {
|
}) {
|
||||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormDialog
|
<FormDialog
|
||||||
open={open}
|
open={open}
|
||||||
@ -318,10 +231,7 @@ function CreateForm({
|
|||||||
title="Tambah Materi"
|
title="Tambah Materi"
|
||||||
action={store()}
|
action={store()}
|
||||||
resetOnSuccess
|
resetOnSuccess
|
||||||
onSuccess={() => {
|
onSuccess={() => onOpenChange(false)}
|
||||||
onOpenChange(false);
|
|
||||||
setCourseClass(null);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{({ errors }) => (
|
{({ errors }) => (
|
||||||
<div className="grid gap-4">
|
<div className="grid gap-4">
|
||||||
@ -329,16 +239,22 @@ function CreateForm({
|
|||||||
<Label>
|
<Label>
|
||||||
Kelas <span className="text-destructive">*</span>
|
Kelas <span className="text-destructive">*</span>
|
||||||
</Label>
|
</Label>
|
||||||
<input
|
<input type="hidden" name="course_class_id" />
|
||||||
type="hidden"
|
<Select name="course_class_id">
|
||||||
name="course_class_id"
|
<SelectTrigger className="w-full">
|
||||||
value={courseClass?.id ?? ''}
|
<SelectValue placeholder="Pilih kelas" />
|
||||||
/>
|
</SelectTrigger>
|
||||||
<CourseClassField
|
<SelectContent>
|
||||||
courseClasses={courseClasses}
|
{courseClasses.map((courseClass) => (
|
||||||
value={courseClass}
|
<SelectItem
|
||||||
onChange={setCourseClass}
|
key={courseClass.id}
|
||||||
/>
|
value={String(courseClass.id)}
|
||||||
|
>
|
||||||
|
{courseClassLabel(courseClass)}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
<InputError message={errors.course_class_id} />
|
<InputError message={errors.course_class_id} />
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
@ -394,13 +310,6 @@ function EditForm({
|
|||||||
editing: Material | null;
|
editing: Material | null;
|
||||||
courseClasses: CourseClassOption[];
|
courseClasses: CourseClassOption[];
|
||||||
}) {
|
}) {
|
||||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
|
||||||
editing
|
|
||||||
? (courseClasses.find((c) => c.id === editing.course_class_id) ??
|
|
||||||
null)
|
|
||||||
: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormDialog
|
<FormDialog
|
||||||
open={open}
|
open={open}
|
||||||
@ -418,16 +327,24 @@ function EditForm({
|
|||||||
Kelas{' '}
|
Kelas{' '}
|
||||||
<span className="text-destructive">*</span>
|
<span className="text-destructive">*</span>
|
||||||
</Label>
|
</Label>
|
||||||
<input
|
<Select
|
||||||
type="hidden"
|
|
||||||
name="course_class_id"
|
name="course_class_id"
|
||||||
value={courseClass?.id ?? ''}
|
defaultValue={String(editing.course_class_id)}
|
||||||
/>
|
>
|
||||||
<CourseClassField
|
<SelectTrigger className="w-full">
|
||||||
courseClasses={courseClasses}
|
<SelectValue placeholder="Pilih kelas" />
|
||||||
value={courseClass}
|
</SelectTrigger>
|
||||||
onChange={setCourseClass}
|
<SelectContent>
|
||||||
/>
|
{courseClasses.map((courseClass) => (
|
||||||
|
<SelectItem
|
||||||
|
key={courseClass.id}
|
||||||
|
value={String(courseClass.id)}
|
||||||
|
>
|
||||||
|
{courseClassLabel(courseClass)}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
<InputError message={errors.course_class_id} />
|
<InputError message={errors.course_class_id} />
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
|
|||||||
@ -1,17 +1,4 @@
|
|||||||
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 { 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 { FormDialog } from '@/components/form-dialog';
|
||||||
import InputError from '@/components/input-error';
|
import InputError from '@/components/input-error';
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
@ -19,17 +6,6 @@ import { RowActions } from '@/components/row-actions';
|
|||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
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 { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import {
|
import {
|
||||||
@ -40,119 +16,35 @@ import {
|
|||||||
SelectValue,
|
SelectValue,
|
||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
import { usePermissions } from '@/hooks/use-permissions';
|
import { usePermissions } from '@/hooks/use-permissions';
|
||||||
import { useServerTable } from '@/hooks/use-server-table';
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import {
|
import {
|
||||||
destroy,
|
destroy,
|
||||||
index as scheduleIndex,
|
|
||||||
store,
|
store,
|
||||||
update,
|
update,
|
||||||
} from '@/routes/admin/academic-classes/schedules';
|
} 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 type { Schedule } from '@/types/schedule';
|
||||||
import { DayOfWeekLabels, DaysOfWeek } 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 = {
|
type CourseClassOption = {
|
||||||
id: number;
|
id: number;
|
||||||
course: {
|
course: { id: number; code: string; name: string } | null;
|
||||||
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 = {
|
type Props = {
|
||||||
schedules: Schedule[];
|
schedules: Schedule[];
|
||||||
courseClasses: CourseClassOption[];
|
courseClasses: CourseClassOption[];
|
||||||
academicTerms: AcademicTermOption[];
|
|
||||||
departments: DepartmentOption[];
|
|
||||||
semesterNumbers: number[];
|
|
||||||
isPersonalView: boolean;
|
|
||||||
highlight?: number;
|
highlight?: number;
|
||||||
filters: {
|
|
||||||
academic_term_id?: string;
|
|
||||||
department_id?: string;
|
|
||||||
semester_number?: string;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const UNSCHEDULED = '__unscheduled__';
|
const UNSCHEDULED = '__unscheduled__';
|
||||||
|
|
||||||
const BOARD_COLUMNS = [...DaysOfWeek, UNSCHEDULED] as const;
|
const BOARD_COLUMNS = [...DaysOfWeek, UNSCHEDULED] as const;
|
||||||
|
|
||||||
const DEPARTMENT_PALETTE = [
|
function courseClassLabel(courseClass: CourseClassOption): string {
|
||||||
{ border: 'border-l-blue-500 bg-blue-50/60 dark:bg-blue-950/20', dot: 'bg-blue-500' },
|
return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`;
|
||||||
{ 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 {
|
function toTimeInput(value: string | null): string {
|
||||||
@ -162,12 +54,7 @@ function toTimeInput(value: string | null): string {
|
|||||||
export default function ScheduleIndex({
|
export default function ScheduleIndex({
|
||||||
schedules,
|
schedules,
|
||||||
courseClasses,
|
courseClasses,
|
||||||
academicTerms,
|
|
||||||
departments,
|
|
||||||
semesterNumbers,
|
|
||||||
isPersonalView,
|
|
||||||
highlight,
|
highlight,
|
||||||
filters,
|
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
const [editing, setEditing] = useState<Schedule | null>(null);
|
const [editing, setEditing] = useState<Schedule | null>(null);
|
||||||
@ -177,61 +64,6 @@ export default function ScheduleIndex({
|
|||||||
const canUpdate = hasPermission('update-schedules');
|
const canUpdate = hasPermission('update-schedules');
|
||||||
const canDelete = hasPermission('delete-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() {
|
function handleDelete() {
|
||||||
if (!deleting) {
|
if (!deleting) {
|
||||||
return;
|
return;
|
||||||
@ -254,15 +86,6 @@ export default function ScheduleIndex({
|
|||||||
day !== UNSCHEDULED || (grouped.get(UNSCHEDULED)?.length ?? 0) > 0,
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head title="Jadwal" />
|
<Head title="Jadwal" />
|
||||||
@ -271,52 +94,23 @@ export default function ScheduleIndex({
|
|||||||
<PageHeader
|
<PageHeader
|
||||||
title="Jadwal"
|
title="Jadwal"
|
||||||
actions={
|
actions={
|
||||||
<div className="flex items-center gap-2">
|
canCreate && (
|
||||||
<FilterDialog
|
<Button asChild>
|
||||||
fields={filterFields}
|
<button
|
||||||
activeFilters={filters}
|
type="button"
|
||||||
onApply={handleApplyFilters}
|
onClick={() => setCreateOpen(true)}
|
||||||
/>
|
>
|
||||||
{canCreate && (
|
<Plus className="h-4 w-4" />
|
||||||
<Button asChild>
|
Tambah
|
||||||
<button
|
</button>
|
||||||
type="button"
|
</Button>
|
||||||
onClick={() => setCreateOpen(true)}
|
)
|
||||||
>
|
|
||||||
<Plus className="h-4 w-4" />
|
|
||||||
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">
|
||||||
<p className="hidden text-xs text-muted-foreground md:block">
|
Geser ke samping untuk melihat hari lainnya.
|
||||||
Geser ke samping untuk melihat hari lainnya.
|
</p>
|
||||||
</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
|
<CreateForm
|
||||||
open={createOpen}
|
open={createOpen}
|
||||||
@ -371,14 +165,7 @@ export default function ScheduleIndex({
|
|||||||
<Card
|
<Card
|
||||||
key={schedule.id}
|
key={schedule.id}
|
||||||
className={cn(
|
className={cn(
|
||||||
'gap-3 border-l-4 py-4',
|
'gap-3 py-4',
|
||||||
departmentPalette(
|
|
||||||
schedule
|
|
||||||
.course_class
|
|
||||||
?.course
|
|
||||||
?.department
|
|
||||||
?.id,
|
|
||||||
).border,
|
|
||||||
highlight ===
|
highlight ===
|
||||||
schedule.id &&
|
schedule.id &&
|
||||||
'ring-2 ring-primary',
|
'ring-2 ring-primary',
|
||||||
@ -388,6 +175,7 @@ export default function ScheduleIndex({
|
|||||||
<CardTitle className="text-sm leading-tight">
|
<CardTitle className="text-sm leading-tight">
|
||||||
{courseClassLabel(
|
{courseClassLabel(
|
||||||
schedule.course_class ?? {
|
schedule.course_class ?? {
|
||||||
|
id: 0,
|
||||||
course: null,
|
course: null,
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
@ -436,19 +224,6 @@ export default function ScheduleIndex({
|
|||||||
) || '-'}
|
) || '-'}
|
||||||
</span>
|
</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 && (
|
{schedule.room && (
|
||||||
<span className="inline-flex items-center gap-1.5">
|
<span className="inline-flex items-center gap-1.5">
|
||||||
<MapPin className="h-3.5 w-3.5 shrink-0" />
|
<MapPin className="h-3.5 w-3.5 shrink-0" />
|
||||||
@ -468,22 +243,6 @@ export default function ScheduleIndex({
|
|||||||
Link Online
|
Link Online
|
||||||
</a>
|
</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>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
))
|
))
|
||||||
@ -513,60 +272,6 @@ 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({
|
function CreateForm({
|
||||||
open,
|
open,
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
@ -576,10 +281,6 @@ function CreateForm({
|
|||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
courseClasses: CourseClassOption[];
|
courseClasses: CourseClassOption[];
|
||||||
}) {
|
}) {
|
||||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormDialog
|
<FormDialog
|
||||||
open={open}
|
open={open}
|
||||||
@ -587,10 +288,7 @@ function CreateForm({
|
|||||||
title="Tambah Jadwal"
|
title="Tambah Jadwal"
|
||||||
action={store()}
|
action={store()}
|
||||||
resetOnSuccess
|
resetOnSuccess
|
||||||
onSuccess={() => {
|
onSuccess={() => onOpenChange(false)}
|
||||||
onOpenChange(false);
|
|
||||||
setCourseClass(null);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{({ errors }) => (
|
{({ errors }) => (
|
||||||
<div className="grid gap-4">
|
<div className="grid gap-4">
|
||||||
@ -598,22 +296,26 @@ function CreateForm({
|
|||||||
<Label>
|
<Label>
|
||||||
Kelas <span className="text-destructive">*</span>
|
Kelas <span className="text-destructive">*</span>
|
||||||
</Label>
|
</Label>
|
||||||
<input
|
<input type="hidden" name="course_class_id" />
|
||||||
type="hidden"
|
<Select name="course_class_id">
|
||||||
name="course_class_id"
|
<SelectTrigger className="w-full">
|
||||||
value={courseClass?.id ?? ''}
|
<SelectValue placeholder="Pilih kelas" />
|
||||||
/>
|
</SelectTrigger>
|
||||||
<CourseClassField
|
<SelectContent>
|
||||||
courseClasses={courseClasses}
|
{courseClasses.map((courseClass) => (
|
||||||
value={courseClass}
|
<SelectItem
|
||||||
onChange={setCourseClass}
|
key={courseClass.id}
|
||||||
/>
|
value={String(courseClass.id)}
|
||||||
|
>
|
||||||
|
{courseClassLabel(courseClass)}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
<InputError message={errors.course_class_id} />
|
<InputError message={errors.course_class_id} />
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label>
|
<Label>Hari</Label>
|
||||||
Hari <span className="text-destructive">*</span>
|
|
||||||
</Label>
|
|
||||||
<input type="hidden" name="day_of_week" />
|
<input type="hidden" name="day_of_week" />
|
||||||
<Select name="day_of_week">
|
<Select name="day_of_week">
|
||||||
<SelectTrigger className="w-full">
|
<SelectTrigger className="w-full">
|
||||||
@ -631,10 +333,7 @@ function CreateForm({
|
|||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor="start_time">
|
<Label htmlFor="start_time">Jam Mulai</Label>
|
||||||
Jam Mulai{' '}
|
|
||||||
<span className="text-destructive">*</span>
|
|
||||||
</Label>
|
|
||||||
<Input
|
<Input
|
||||||
id="start_time"
|
id="start_time"
|
||||||
name="start_time"
|
name="start_time"
|
||||||
@ -643,10 +342,7 @@ function CreateForm({
|
|||||||
<InputError message={errors.start_time} />
|
<InputError message={errors.start_time} />
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor="end_time">
|
<Label htmlFor="end_time">Jam Selesai</Label>
|
||||||
Jam Selesai{' '}
|
|
||||||
<span className="text-destructive">*</span>
|
|
||||||
</Label>
|
|
||||||
<Input id="end_time" name="end_time" type="time" />
|
<Input id="end_time" name="end_time" type="time" />
|
||||||
<InputError message={errors.end_time} />
|
<InputError message={errors.end_time} />
|
||||||
</div>
|
</div>
|
||||||
@ -686,13 +382,6 @@ function EditForm({
|
|||||||
editing: Schedule | null;
|
editing: Schedule | null;
|
||||||
courseClasses: CourseClassOption[];
|
courseClasses: CourseClassOption[];
|
||||||
}) {
|
}) {
|
||||||
const [courseClass, setCourseClass] = useState<CourseClassOption | null>(
|
|
||||||
editing
|
|
||||||
? (courseClasses.find((c) => c.id === editing.course_class_id) ??
|
|
||||||
null)
|
|
||||||
: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormDialog
|
<FormDialog
|
||||||
open={open}
|
open={open}
|
||||||
@ -710,23 +399,28 @@ function EditForm({
|
|||||||
Kelas{' '}
|
Kelas{' '}
|
||||||
<span className="text-destructive">*</span>
|
<span className="text-destructive">*</span>
|
||||||
</Label>
|
</Label>
|
||||||
<input
|
<Select
|
||||||
type="hidden"
|
|
||||||
name="course_class_id"
|
name="course_class_id"
|
||||||
value={courseClass?.id ?? ''}
|
defaultValue={String(editing.course_class_id)}
|
||||||
/>
|
>
|
||||||
<CourseClassField
|
<SelectTrigger className="w-full">
|
||||||
courseClasses={courseClasses}
|
<SelectValue placeholder="Pilih kelas" />
|
||||||
value={courseClass}
|
</SelectTrigger>
|
||||||
onChange={setCourseClass}
|
<SelectContent>
|
||||||
/>
|
{courseClasses.map((courseClass) => (
|
||||||
|
<SelectItem
|
||||||
|
key={courseClass.id}
|
||||||
|
value={String(courseClass.id)}
|
||||||
|
>
|
||||||
|
{courseClassLabel(courseClass)}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
<InputError message={errors.course_class_id} />
|
<InputError message={errors.course_class_id} />
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label>
|
<Label>Hari</Label>
|
||||||
Hari{' '}
|
|
||||||
<span className="text-destructive">*</span>
|
|
||||||
</Label>
|
|
||||||
<Select
|
<Select
|
||||||
name="day_of_week"
|
name="day_of_week"
|
||||||
defaultValue={editing.day_of_week ?? undefined}
|
defaultValue={editing.day_of_week ?? undefined}
|
||||||
@ -747,10 +441,7 @@ function EditForm({
|
|||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor="edit-start_time">
|
<Label htmlFor="edit-start_time">
|
||||||
Jam Mulai{' '}
|
Jam Mulai
|
||||||
<span className="text-destructive">
|
|
||||||
*
|
|
||||||
</span>
|
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
id="edit-start_time"
|
id="edit-start_time"
|
||||||
@ -764,10 +455,7 @@ function EditForm({
|
|||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor="edit-end_time">
|
<Label htmlFor="edit-end_time">
|
||||||
Jam Selesai{' '}
|
Jam Selesai
|
||||||
<span className="text-destructive">
|
|
||||||
*
|
|
||||||
</span>
|
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
id="edit-end_time"
|
id="edit-end_time"
|
||||||
|
|||||||
@ -32,13 +32,10 @@ import {
|
|||||||
ComboboxChip,
|
ComboboxChip,
|
||||||
ComboboxChips,
|
ComboboxChips,
|
||||||
ComboboxChipsInput,
|
ComboboxChipsInput,
|
||||||
ComboboxCollection,
|
|
||||||
ComboboxContent,
|
ComboboxContent,
|
||||||
ComboboxEmpty,
|
ComboboxEmpty,
|
||||||
ComboboxGroup,
|
|
||||||
ComboboxInput,
|
ComboboxInput,
|
||||||
ComboboxItem,
|
ComboboxItem,
|
||||||
ComboboxLabel,
|
|
||||||
ComboboxList,
|
ComboboxList,
|
||||||
useComboboxAnchor,
|
useComboboxAnchor,
|
||||||
} from '@/components/ui/combobox';
|
} from '@/components/ui/combobox';
|
||||||
@ -111,28 +108,6 @@ function studentLabel(student: TuitionInvoiceStudent): string {
|
|||||||
return `${student.user?.profile?.full_name ?? 'N/A'} - ${student.student_number}`;
|
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({
|
export default function TuitionInvoiceIndex({
|
||||||
invoices,
|
invoices,
|
||||||
summary,
|
summary,
|
||||||
@ -404,7 +379,6 @@ function CreateForm({
|
|||||||
!student.invoiced_term_ids?.includes(Number(academicTermId)),
|
!student.invoiced_term_ids?.includes(Number(academicTermId)),
|
||||||
)
|
)
|
||||||
: [];
|
: [];
|
||||||
const studentGroups = groupStudentsByDepartmentAndSemester(availableStudents);
|
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
setAcademicTermId('');
|
setAcademicTermId('');
|
||||||
@ -494,7 +468,7 @@ function CreateForm({
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<Combobox
|
<Combobox
|
||||||
items={studentGroups}
|
items={availableStudents}
|
||||||
multiple
|
multiple
|
||||||
disabled={!academicTermId}
|
disabled={!academicTermId}
|
||||||
value={selectedStudents}
|
value={selectedStudents}
|
||||||
@ -527,27 +501,13 @@ function CreateForm({
|
|||||||
Mahasiswa tidak ditemukan.
|
Mahasiswa tidak ditemukan.
|
||||||
</ComboboxEmpty>
|
</ComboboxEmpty>
|
||||||
<ComboboxList>
|
<ComboboxList>
|
||||||
{(group: StudentGroup) => (
|
{(student: TuitionInvoiceStudent) => (
|
||||||
<ComboboxGroup
|
<ComboboxItem
|
||||||
key={group.value}
|
key={student.id}
|
||||||
items={group.items}
|
value={student}
|
||||||
>
|
>
|
||||||
<ComboboxLabel>
|
{studentLabel(student)}
|
||||||
{group.value}
|
</ComboboxItem>
|
||||||
</ComboboxLabel>
|
|
||||||
<ComboboxCollection>
|
|
||||||
{(
|
|
||||||
student: TuitionInvoiceStudent,
|
|
||||||
) => (
|
|
||||||
<ComboboxItem
|
|
||||||
key={student.id}
|
|
||||||
value={student}
|
|
||||||
>
|
|
||||||
{studentLabel(student)}
|
|
||||||
</ComboboxItem>
|
|
||||||
)}
|
|
||||||
</ComboboxCollection>
|
|
||||||
</ComboboxGroup>
|
|
||||||
)}
|
)}
|
||||||
</ComboboxList>
|
</ComboboxList>
|
||||||
</ComboboxContent>
|
</ComboboxContent>
|
||||||
@ -609,7 +569,6 @@ function EditForm({
|
|||||||
const [student, setStudent] = useState<TuitionInvoiceStudent | null>(
|
const [student, setStudent] = useState<TuitionInvoiceStudent | null>(
|
||||||
students.find((s) => s.id === editing?.student_id) ?? null,
|
students.find((s) => s.id === editing?.student_id) ?? null,
|
||||||
);
|
);
|
||||||
const studentGroups = groupStudentsByDepartmentAndSemester(students);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormDialog
|
<FormDialog
|
||||||
@ -659,7 +618,7 @@ function EditForm({
|
|||||||
value={student?.id ?? ''}
|
value={student?.id ?? ''}
|
||||||
/>
|
/>
|
||||||
<Combobox
|
<Combobox
|
||||||
items={studentGroups}
|
items={students}
|
||||||
value={student}
|
value={student}
|
||||||
onValueChange={setStudent}
|
onValueChange={setStudent}
|
||||||
itemToStringLabel={studentLabel}
|
itemToStringLabel={studentLabel}
|
||||||
@ -674,29 +633,13 @@ function EditForm({
|
|||||||
Mahasiswa tidak ditemukan.
|
Mahasiswa tidak ditemukan.
|
||||||
</ComboboxEmpty>
|
</ComboboxEmpty>
|
||||||
<ComboboxList>
|
<ComboboxList>
|
||||||
{(group: StudentGroup) => (
|
{(option: TuitionInvoiceStudent) => (
|
||||||
<ComboboxGroup
|
<ComboboxItem
|
||||||
key={group.value}
|
key={option.id}
|
||||||
items={group.items}
|
value={option}
|
||||||
>
|
>
|
||||||
<ComboboxLabel>
|
{studentLabel(option)}
|
||||||
{group.value}
|
</ComboboxItem>
|
||||||
</ComboboxLabel>
|
|
||||||
<ComboboxCollection>
|
|
||||||
{(
|
|
||||||
option: TuitionInvoiceStudent,
|
|
||||||
) => (
|
|
||||||
<ComboboxItem
|
|
||||||
key={option.id}
|
|
||||||
value={option}
|
|
||||||
>
|
|
||||||
{studentLabel(
|
|
||||||
option,
|
|
||||||
)}
|
|
||||||
</ComboboxItem>
|
|
||||||
)}
|
|
||||||
</ComboboxCollection>
|
|
||||||
</ComboboxGroup>
|
|
||||||
)}
|
)}
|
||||||
</ComboboxList>
|
</ComboboxList>
|
||||||
</ComboboxContent>
|
</ComboboxContent>
|
||||||
|
|||||||
@ -26,6 +26,11 @@ export function createCourseRegistrationColumns(): ColumnDef<CourseRegistrationR
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'department',
|
||||||
|
header: () => <span>Jurusan</span>,
|
||||||
|
cell: ({ row }) => row.original.student?.department?.name ?? '-',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
header: () => <span className="block text-center">Aksi</span>,
|
header: () => <span className="block text-center">Aksi</span>,
|
||||||
|
|||||||
@ -79,9 +79,6 @@ export default function CourseRegistrationIndex({
|
|||||||
onSearchChange={handleSearchChange}
|
onSearchChange={handleSearchChange}
|
||||||
searchValue={search}
|
searchValue={search}
|
||||||
searchKey="student"
|
searchKey="student"
|
||||||
groupBy={(row) =>
|
|
||||||
row.student?.department?.name ?? 'Tanpa Jurusan'
|
|
||||||
}
|
|
||||||
toolbar={
|
toolbar={
|
||||||
<FilterDialog
|
<FilterDialog
|
||||||
fields={filterFields}
|
fields={filterFields}
|
||||||
|
|||||||
@ -1,47 +1,16 @@
|
|||||||
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 = {
|
export type Assignment = {
|
||||||
id: number;
|
id: number;
|
||||||
course_class_id: number;
|
course_class_id: number;
|
||||||
course_class: {
|
course_class: {
|
||||||
id: number;
|
id: number;
|
||||||
course: { id: number; code: string; name: string } | null;
|
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;
|
} | null;
|
||||||
title: string;
|
title: string;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
deadline: string;
|
deadline: string;
|
||||||
/** Governs whether students can still submit — independent of the deadline. */
|
|
||||||
status: AssignmentStatus;
|
|
||||||
attachment_url: string | null;
|
attachment_url: string | null;
|
||||||
attachment_name: string | null;
|
attachment_name: string | null;
|
||||||
submissions_count: number;
|
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;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -10,20 +10,12 @@ export const AttendanceStatusLabels: Record<AttendanceStatus, string> = {
|
|||||||
export type AttendanceCourseClass = {
|
export type AttendanceCourseClass = {
|
||||||
id: number;
|
id: number;
|
||||||
course: { id: number; code: string; name: string } | null;
|
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 = {
|
export type AttendanceSession = {
|
||||||
meeting_number: number;
|
course_class_id: number;
|
||||||
|
course_class: AttendanceCourseClass | null;
|
||||||
|
meeting_number: number | null;
|
||||||
date: string;
|
date: string;
|
||||||
total_count: number;
|
total_count: number;
|
||||||
present_count: number;
|
present_count: number;
|
||||||
@ -40,17 +32,3 @@ export type AttendanceRosterEntry = {
|
|||||||
student: AttendanceRosterStudent | null;
|
student: AttendanceRosterStudent | null;
|
||||||
status: AttendanceStatus;
|
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,17 +25,7 @@ export type Schedule = {
|
|||||||
course_class_id: number;
|
course_class_id: number;
|
||||||
course_class: {
|
course_class: {
|
||||||
id: number;
|
id: number;
|
||||||
method: string | null;
|
course: { id: number; code: string; name: 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;
|
} | null;
|
||||||
day_of_week: string | null;
|
day_of_week: string | null;
|
||||||
start_time: string | null;
|
start_time: string | null;
|
||||||
|
|||||||
@ -2,7 +2,6 @@ export type TuitionInvoiceStudent = {
|
|||||||
id: number;
|
id: number;
|
||||||
student_number: string;
|
student_number: string;
|
||||||
department: { id: number; name: string } | null;
|
department: { id: number; name: string } | null;
|
||||||
current_semester: number;
|
|
||||||
user: { profile: { full_name: string } | null } | null;
|
user: { profile: { full_name: string } | null } | null;
|
||||||
invoiced_term_ids?: number[];
|
invoiced_term_ids?: number[];
|
||||||
};
|
};
|
||||||
|
|||||||
@ -68,13 +68,11 @@
|
|||||||
|
|
||||||
Route::prefix('assignments/{assignment}/submissions')->name('assignments.submissions.')->group(function () {
|
Route::prefix('assignments/{assignment}/submissions')->name('assignments.submissions.')->group(function () {
|
||||||
Route::get('/', [SubmissionController::class, 'index'])->name('index')->middleware('permission:view-assignment-submissions');
|
Route::get('/', [SubmissionController::class, 'index'])->name('index')->middleware('permission:view-assignment-submissions');
|
||||||
Route::patch('{submission}/grade', [SubmissionController::class, 'grade'])->name('grade')->middleware('permission:update-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::post('assignments/{assignment}/submit', [SubmissionController::class, 'submit'])
|
|
||||||
->name('assignments.submit')
|
|
||||||
->middleware('permission:submit-assignments');
|
|
||||||
|
|
||||||
Route::resource('schedules', ScheduleController::class)
|
Route::resource('schedules', ScheduleController::class)
|
||||||
->except(['create', 'edit', 'show'])
|
->except(['create', 'edit', 'show'])
|
||||||
->middlewareFor(['index'], 'permission:view-schedules')
|
->middlewareFor(['index'], 'permission:view-schedules')
|
||||||
@ -84,8 +82,6 @@
|
|||||||
|
|
||||||
Route::prefix('attendances')->name('attendances.')->group(function () {
|
Route::prefix('attendances')->name('attendances.')->group(function () {
|
||||||
Route::get('/', [AttendanceController::class, 'index'])->name('index')->middleware('permission:view-attendances');
|
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'])
|
Route::get('{course_class}/{meeting_number}', [AttendanceController::class, 'session'])
|
||||||
->whereNumber('meeting_number')
|
->whereNumber('meeting_number')
|
||||||
->name('session')
|
->name('session')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user