diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index ec39726..14c3767 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -138,8 +138,13 @@ public function index(Request $request) return [ 'id' => $notification->id, 'data' => $notification->data, + 'timestamp' => $notification->updated_at->format('Y-m-d H:i') . ' UTC', ]; }) + ->sortBy([ + ['timestamp', 'desc'] + ]) + ->values() ->all(); return view('home.index', compact( diff --git a/app/Notifications/HealthCheckIssue.php b/app/Notifications/HealthCheckIssue.php index 5fd7e71..05dcbba 100644 --- a/app/Notifications/HealthCheckIssue.php +++ b/app/Notifications/HealthCheckIssue.php @@ -8,12 +8,14 @@ use App\Models\YnhServer; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; +use Illuminate\Support\Str; class HealthCheckIssue extends Notification { use Queueable; private YnhServer $server; + private string $group; /** * Create a new notification instance. @@ -21,6 +23,7 @@ class HealthCheckIssue extends Notification public function __construct(YnhServer $server) { $this->server = $server; + $this->group = Str::random(10); } /** @@ -50,6 +53,7 @@ public function via(object $notifiable): array public function toArray(object $notifiable): array { return [ + 'group' => $this->group, 'type' => NotificationTypeEnum::HEALTHCHECK_ISSUE->value, 'level' => NotificationLevelEnum::DANGER->value, 'message' => "A health check issue has been detected: no metrics have been recorded in the past 20 minutes.", diff --git a/resources/views/layouts/_notifications.blade.php b/resources/views/layouts/_notifications.blade.php index 05bb156..180b95d 100644 --- a/resources/views/layouts/_notifications.blade.php +++ b/resources/views/layouts/_notifications.blade.php @@ -14,18 +14,21 @@ let notifications = @json($notifications); function dismissNotification(notificationId) { - axios.get(`{{ url('/notification/${notificationId}/dismiss') }}`).then(response => { + axios.get(`{{ url('/notifications/${notificationId}/dismiss') }}`).then(response => { toaster.el.toast('The notification has been dismissed!', 'success'); }).catch(error => { toaster.el.toast('An error occurred.', 'danger'); console.error('Error:', error); }); - notifications = notifications.filter(notification => notification.id !== notificationId); - drawer25.redraw(); + const notification = notifications.find(notif => notif.id === notificationId); + if (notification) { + notifications = notifications.filter(notif => notif.data.group !== notification.data.group); + } + drawer33.redraw(); } function showNotifications() { - drawer25.render = () => { + drawer33.render = () => { const rows = notifications.map(notification => { let details = ''; for (let key in notification.data.details) { @@ -40,7 +43,7 @@ function showNotifications() { return `
${notification.data.message}