feat: Add attendance history table to the Manage Attendances page with filtering and sorting capabilities.
This commit is contained in:
parent
d76fa6ac49
commit
244230a989
@ -2,16 +2,29 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Learning\Attendances\Pages;
|
namespace App\Filament\Resources\Learning\Attendances\Pages;
|
||||||
|
|
||||||
|
use App\Enums\RoleEnum;
|
||||||
use App\Filament\Resources\Learning\Attendances\AttendanceResource;
|
use App\Filament\Resources\Learning\Attendances\AttendanceResource;
|
||||||
use App\Filament\Support\SystemNotification;
|
use App\Filament\Support\SystemNotification;
|
||||||
use App\Models\Attendance;
|
use App\Models\Attendance;
|
||||||
|
use App\Models\Course;
|
||||||
use App\Models\CourseSchedule;
|
use App\Models\CourseSchedule;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Settings\GeneralSettings;
|
use App\Settings\GeneralSettings;
|
||||||
|
use Filament\Forms\Concerns\InteractsWithForms;
|
||||||
|
use Filament\Forms\Contracts\HasForms;
|
||||||
use Filament\Resources\Pages\Page;
|
use Filament\Resources\Pages\Page;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Concerns\InteractsWithTable;
|
||||||
|
use Filament\Tables\Contracts\HasTable;
|
||||||
|
use Filament\Tables\Filters\SelectFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
class ManageAttendances extends Page
|
class ManageAttendances extends Page implements HasForms, HasTable
|
||||||
{
|
{
|
||||||
|
use InteractsWithForms, InteractsWithTable;
|
||||||
|
|
||||||
protected static string $resource = AttendanceResource::class;
|
protected static string $resource = AttendanceResource::class;
|
||||||
|
|
||||||
protected static ?string $title = 'Presensi Kuliah';
|
protected static ?string $title = 'Presensi Kuliah';
|
||||||
@ -22,7 +35,9 @@ class ManageAttendances extends Page
|
|||||||
|
|
||||||
public function getSchedules()
|
public function getSchedules()
|
||||||
{
|
{
|
||||||
$student = auth()->user()->student;
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$student = $user->student;
|
||||||
|
|
||||||
if (! $student) {
|
if (! $student) {
|
||||||
return collect();
|
return collect();
|
||||||
@ -74,7 +89,7 @@ public function getScheduleCards()
|
|||||||
'id' => $schedule->id,
|
'id' => $schedule->id,
|
||||||
'course_name' => $schedule->course->name,
|
'course_name' => $schedule->course->name,
|
||||||
'lecturer_name' => $schedule->course->lecturer?->full_name ?? 'Belum Ditentukan',
|
'lecturer_name' => $schedule->course->lecturer?->full_name ?? 'Belum Ditentukan',
|
||||||
'time_range' => $schedule->start_time->format('H:i').' - '.$schedule->end_time->format('H:i'),
|
'time_range' => $schedule->start_time->format('H:i') . ' - ' . $schedule->end_time->format('H:i'),
|
||||||
'is_attended' => $isAttended,
|
'is_attended' => $isAttended,
|
||||||
'can_attend' => $canAttend && ! $isAttended,
|
'can_attend' => $canAttend && ! $isAttended,
|
||||||
'status_label' => $statusLabel,
|
'status_label' => $statusLabel,
|
||||||
@ -144,4 +159,58 @@ public function attend(int $scheduleId): void
|
|||||||
'Kehadiran Anda telah berhasil direkam ke dalam sistem.'
|
'Kehadiran Anda telah berhasil direkam ke dalam sistem.'
|
||||||
)->send();
|
)->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function table(Table $table): Table
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
|
return $table
|
||||||
|
->query(AttendanceResource::getEloquentQuery())
|
||||||
|
->modifyQueryUsing(fn(Builder $query) => $query->where('student_id', $user->student?->id))
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('student.full_name')
|
||||||
|
->label('Mahasiswa')
|
||||||
|
->sortable()
|
||||||
|
->searchable()
|
||||||
|
->visible(fn() => $user->hasRole([RoleEnum::Developer, RoleEnum::Kosma])),
|
||||||
|
|
||||||
|
TextColumn::make('date')
|
||||||
|
->label('Tanggal')
|
||||||
|
->date('l, d F Y')
|
||||||
|
->sortable()
|
||||||
|
->description(fn(Attendance $record): string => $record->attended_at->format('H:i') . ' WIB')
|
||||||
|
->color('gray'),
|
||||||
|
|
||||||
|
TextColumn::make('courseSchedule.course.name')
|
||||||
|
->label('Mata Kuliah')
|
||||||
|
->searchable()
|
||||||
|
->sortable()
|
||||||
|
->wrap()
|
||||||
|
->description(fn(Attendance $record): string => $record->courseSchedule->course->lecturer->full_name),
|
||||||
|
])
|
||||||
|
->defaultSort('date', 'desc')
|
||||||
|
->filters([
|
||||||
|
SelectFilter::make('course_id')
|
||||||
|
->label('Mata Kuliah')
|
||||||
|
->options(function () {
|
||||||
|
return Course::query()
|
||||||
|
->where('semester', app(GeneralSettings::class)->current_semester)
|
||||||
|
->pluck('name', 'id')
|
||||||
|
->toArray();
|
||||||
|
})
|
||||||
|
->query(function (Builder $query, array $data) {
|
||||||
|
return $query->when(
|
||||||
|
$data['value'],
|
||||||
|
fn(Builder $query) => $query->whereHas('courseSchedule', fn($q) => $q->where('course_id', $data['value']))
|
||||||
|
);
|
||||||
|
})
|
||||||
|
->searchable(),
|
||||||
|
])
|
||||||
|
->emptyStateIcon(Heroicon::OutlinedCheckCircle)
|
||||||
|
->emptyStateDescription('Setelah Anda membuat data pertama, maka akan muncul disini.')
|
||||||
|
->deferFilters(false)
|
||||||
|
->paginated([25, 50, 100, 'all'])
|
||||||
|
->defaultPaginationPageOption(25);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,4 +138,11 @@ class="text-[10px] font-bold text-gray-400 uppercase tracking-widest leading-non
|
|||||||
</x-filament::empty-state>
|
</x-filament::empty-state>
|
||||||
@endif
|
@endif
|
||||||
</x-filament::section>
|
</x-filament::section>
|
||||||
|
|
||||||
|
<x-filament::section>
|
||||||
|
<x-slot name="heading">Riwayat Presensi</x-slot>
|
||||||
|
<x-slot name="description">Berikut adalah riwayat kehadiran Anda pada sesi perkuliahan.</x-slot>
|
||||||
|
|
||||||
|
{{ $this->table }}
|
||||||
|
</x-filament::section>
|
||||||
</x-filament-panels::page>
|
</x-filament-panels::page>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user