diff --git a/app/Filament/Resources/Learning/ClassSessions/Pages/ListCourseSessions.php b/app/Filament/Resources/Learning/ClassSessions/Pages/ListCourseSessions.php index ed2ca53..65caab7 100644 --- a/app/Filament/Resources/Learning/ClassSessions/Pages/ListCourseSessions.php +++ b/app/Filament/Resources/Learning/ClassSessions/Pages/ListCourseSessions.php @@ -2,18 +2,24 @@ namespace App\Filament\Resources\Learning\ClassSessions\Pages; +use App\Filament\Actions\BackAction; use App\Filament\Actions\Cheerful\CreateAction; use App\Filament\Actions\Cheerful\DeleteAction; use App\Filament\Actions\Cheerful\EditAction; use App\Filament\Resources\Learning\ClassSessions\ClassSessionResource; +use App\Filament\Support\SystemNotification; use App\Models\ClassSession; use App\Models\Course; use Filament\Actions\Action; use Filament\Actions\Concerns\InteractsWithActions; use Filament\Actions\Contracts\HasActions; +use Filament\Forms\Components\DatePicker; +use Filament\Forms\Components\TextInput; +use Filament\Forms\Components\TimePicker; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; use Filament\Resources\Pages\Page; +use Filament\Schemas\Components\Grid; use Filament\Support\Enums\Width; use Illuminate\Support\Collection; use Livewire\Attributes\Computed; @@ -24,7 +30,7 @@ class ListCourseSessions extends Page implements HasActions, HasForms protected static string $resource = ClassSessionResource::class; - protected string $view = 'filament.resources.learning.class-sessions.index'; + protected string $view = 'filament.resources.learning.class-sessions.show'; public $courseId; @@ -43,16 +49,52 @@ public function course(): Course public function sessions(): Collection { return $this->course->classSessions() + ->withCount(['attendances', 'materials', 'assignments']) ->orderBy('session_number', 'asc') ->get() ->map(fn ($session) => (object) [ 'id' => $session->id, 'session_number' => $session->session_number, - 'date_formatted' => $session->date->format('l, d F Y'), + 'date_formatted' => $session->date->translatedFormat('l, d F Y'), 'time_range' => $session->start_time->format('H:i').' - '.$session->end_time->format('H:i'), + 'attendances_count' => $session->attendances_count, + 'materials_count' => $session->materials_count, + 'assignments_count' => $session->assignments_count, ]); } + public function formSchema(): array + { + return [ + Grid::make(['default' => 3]) + ->schema([ + TextInput::make('session_number') + ->label('Pertemuan Ke-') + ->numeric() + ->default(fn () => ($this->course->classSessions()->max('session_number') ?? 0) + 1) + ->required(), + DatePicker::make('date') + ->label('Tanggal') + ->default(now()) + ->native(false) + ->required(), + Grid::make(['default' => 2]) + ->schema([ + TimePicker::make('start_time') + ->label('Mulai') + ->native(false) + ->seconds(false) + ->required(), + TimePicker::make('end_time') + ->label('Selesai') + ->native(false) + ->seconds(false) + ->required(), + ])->columnSpan(1), + ]), + ]; + } + #[Computed] public function description(): string { @@ -67,11 +109,16 @@ public function getTitle(): string protected function getHeaderActions(): array { return [ + BackAction::make() + ->url(ManageClassSessions::getUrl()), + + $this->generateSessionsAction(), CreateAction::make() ->label('Tambah Sesi') ->modalHeading('Tambah Sesi') ->modalSubmitActionLabel('Simpan') ->modalCancelActionLabel('Batal') + ->form($this->formSchema()) ->mutateFormDataUsing(function (array $data): array { $data['course_id'] = $this->courseId; @@ -85,10 +132,57 @@ protected function getHeaderActions(): array ]; } + public function generateSessionsAction(): Action + { + return Action::make('generateSessions') + ->label('Generate Sesi') + ->icon('heroicon-o-sparkles') + ->color('warning') + ->requiresConfirmation() + ->modalHeading('Generate Sesi Pembelajaran') + ->modalDescription('Sistem akan men-generate atau memperbarui sesi 1 sampai 16 secara otomatis berdasarkan jadwal mata kuliah ini.') + ->form([ + DatePicker::make('start_date') + ->label('Tanggal Pertemuan Ke-1') + ->default(now()) + ->required() + ->native(false), + ]) + ->action(function (array $data) { + $course = $this->course; + $schedule = $course->courseSchedules()->first(); + + if (! $schedule) { + SystemNotification::danger('Batal!', 'Jadwal belum ditentukan untuk mata kuliah ini.')->send(); + + return; + } + + $startDate = \Carbon\Carbon::parse($data['start_date']); + + for ($i = 1; $i <= 16; $i++) { + ClassSession::updateOrCreate( + [ + 'course_id' => $course->id, + 'session_number' => $i, + ], + [ + 'date' => $startDate->copy()->addWeeks($i - 1)->toDateString(), + 'start_time' => $schedule->start_time, + 'end_time' => $schedule->end_time, + ] + ); + } + + SystemNotification::success('Selesai!', '16 Sesi berhasil digenerate/diperbarui.')->send(); + }); + } + public function editSessionAction(): Action { return EditAction::make('editSession') ->record(fn (array $arguments) => ClassSession::find($arguments['session'])) + ->form($this->formSchema()) ->modalWidth(Width::TwoExtraLarge); } diff --git a/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php b/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php index ed82db6..61c6243 100644 --- a/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php +++ b/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php @@ -26,7 +26,7 @@ class ManageClassSessions extends Page implements HasActions, HasForms protected static ?string $title = 'Sesi Kelas'; - protected string $view = 'filament.pages.learning.class-session.index'; + protected string $view = 'filament.resources.learning.class-sessions.index'; public ?string $search = ''; diff --git a/resources/views/filament/pages/learning/class-session/index.blade.php b/resources/views/filament/pages/learning/class-session/index.blade.php deleted file mode 100644 index be10951..0000000 --- a/resources/views/filament/pages/learning/class-session/index.blade.php +++ /dev/null @@ -1,137 +0,0 @@ - - - -
-
- {{ $this->form }} -
-
-
- - - @if ($this->todaySessions->isNotEmpty()) - - - Sesi Hari Ini - - - Sesi yang dijadwalkan pada {{ $this->today_date }} - - - - - @endif - - - - - Daftar Mata Kuliah Semester Ini - - - Pilih mata kuliah untuk melihat dan mengelola semua riwayat sesi. - - - @if ($this->courses->isNotEmpty()) - - @else - - - @endif - -
diff --git a/resources/views/filament/resources/learning/class-sessions/index.blade.php b/resources/views/filament/resources/learning/class-sessions/index.blade.php index b71f2b4..5062cae 100644 --- a/resources/views/filament/resources/learning/class-sessions/index.blade.php +++ b/resources/views/filament/resources/learning/class-sessions/index.blade.php @@ -1,54 +1,134 @@ -
- - - -
-

- {{ $this->getTitle() }} -

-

- {{ $this->description }} -

-
-
- + - @if ($this->sessions->isNotEmpty()) +
+
+ {{ $this->form }} +
+
+
+ + + @if ($this->todaySessions->isNotEmpty()) + + + Sesi Hari Ini + + + Sesi yang dijadwalkan pada {{ $this->today_date }} + +
- @foreach ($this->sessions as $session) -
-
-
- Sesi - #{{ $session->session_number }} + @foreach ($this->todaySessions as $session) + @if ($session->is_pending) +
+ @else + + @endif +
+
+ Sesi + Ke-{{ $session->session_number }}
-
-@else + @else diff --git a/resources/views/filament/resources/learning/class-sessions/show.blade.php b/resources/views/filament/resources/learning/class-sessions/show.blade.php new file mode 100644 index 0000000..42084ef --- /dev/null +++ b/resources/views/filament/resources/learning/class-sessions/show.blade.php @@ -0,0 +1,55 @@ + + + @if ($this->sessions->isNotEmpty()) +
+ @foreach ($this->sessions as $session) +
+
+
+ Sesi + Ke-{{ $session->session_number }} +
+
+
+
+ + {{ $session->date_formatted }} +
+
+ + {{ $session->time_range }} +
+
+ + {{ $session->attendances_count }} Presensi +
+
+ + {{ $session->materials_count }} Materi +
+
+ + {{ $session->assignments_count }} Tugas +
+
+
+
+ +
+ {{ ($this->editSessionAction)(['session' => $session->id]) }} + {{ ($this->deleteSessionAction)(['session' => $session->id]) }} +
+
+ @endforeach +
+ @else + + + @endif +
+