diff --git a/app/Filament/Pages/System/Changelog/Index.php b/app/Filament/Pages/System/Changelog/Index.php index 3cd87a1..f1e30f2 100644 --- a/app/Filament/Pages/System/Changelog/Index.php +++ b/app/Filament/Pages/System/Changelog/Index.php @@ -9,8 +9,10 @@ use App\Filament\Pages\System\Changelog\Actions\MarkAsReadAction; use App\Filament\Support\SystemNotification; use App\Models\Changelog; +use App\Models\Student; use BackedEnum; use BezhanSalleh\FilamentShield\Traits\HasPageShield; +use Carbon\Carbon; use Filament\Actions\Action; use Filament\Actions\Concerns\InteractsWithActions; use Filament\Actions\Contracts\HasActions; @@ -23,6 +25,7 @@ use Filament\Forms\Contracts\HasForms; use Filament\Pages\Page; use Filament\Schemas\Components\Grid; +use Filament\Support\Enums\Width; use Illuminate\Support\Collection; use Livewire\Attributes\Computed; use UnitEnum; @@ -80,10 +83,10 @@ public function changelogs(): Collection return Changelog::with([ 'users' => fn ($query) => $query->where('user_id', auth()->id()), ]) + ->orderBy('version', 'desc') ->get() ->sortBy([ fn ($a, $b) => $a->is_read <=> $b->is_read, - ['release_date', 'desc'], ]) ->values(); } @@ -113,6 +116,44 @@ public function markAsReadAction(): Action return MarkAsReadAction::make(); } + public function viewReadersAction(): Action + { + return Action::make('viewReaders') + ->label('Lihat') + ->icon('heroicon-o-eye') + ->color('info') + ->link() + ->tooltip('Daftar Mahasiswa') + ->modalHeading('Daftar Mahasiswa yang Melihat') + ->modalWidth(Width::TwoExtraLarge) + ->modalSubmitAction(false) + ->modalCancelActionLabel('Tutup') + ->visible(fn () => auth()->user()?->can('Update:Changelog')) + ->modalContent(function (array $arguments) { + $record = Changelog::find($arguments['record'] ?? null); + + if (! $record) { + return null; + } + + $students = Student::with('user')->get(); + $readUsersMap = $record->users()->withPivot('read_at')->get()->keyBy('id'); + + $records = $students->map(fn ($student) => (object) [ + 'student' => $student, + 'is_read' => $readUsersMap->has($student->user_id), + 'read_at' => $readUsersMap->get($student->user_id)?->pivot?->read_at + ? Carbon::parse($readUsersMap->get($student->user_id)->pivot->read_at)->translatedFormat('d F Y H:i') + : null, + ]); + + return view('filament.pages.system.changelog.view-readers', [ + 'records' => $records, + 'readCount' => $readUsersMap->count(), + ]); + }); + } + #[Computed] public function emptyHeading(): string { diff --git a/resources/views/filament/pages/system/changelog/index.blade.php b/resources/views/filament/pages/system/changelog/index.blade.php index 33b8618..7c1bbb8 100644 --- a/resources/views/filament/pages/system/changelog/index.blade.php +++ b/resources/views/filament/pages/system/changelog/index.blade.php @@ -137,6 +137,7 @@ class="w-5 h-5 text-gray-400 transition duration-300" @canAny(['Update:Changelog', 'Delete:Changelog'])
| Mahasiswa | +Status | +Waktu Lihat | +
|---|---|---|
|
+
+ {{ $item->student->full_name }}
+
+ NIM: {{ $item->student->student_number }}
+
+
+ |
+ + @if ($item->is_read) + + Sudah Melihat + + @else + + Belum Melihat + + @endif + | ++ @if ($item->is_read) + + {{ $item->read_at }} + + @else + + - + + @endif + | +
+ Total Mahasiswa: {{ $records->count() }} + | + Sudah Melihat: {{ $readCount }} +
+