From 08b4b25f4ea6e23aaa7aeee4b0b894f4a9129fcc Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 25 Aug 2020 07:21:24 +0000 Subject: [PATCH] Return count of unread notifications. #474 --- public/assets/js/notification.js | 7 +++---- src/Controller/NotificationController.php | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/public/assets/js/notification.js b/public/assets/js/notification.js index 1758ade3..9a4b169c 100644 --- a/public/assets/js/notification.js +++ b/public/assets/js/notification.js @@ -23,9 +23,8 @@ class NotificationHandler { var data = JSON.parse(xhr.responseText); var notifs = data.notifications; - // update notification count - // TODO: notification count is total count or total unread count? - var count_html = data.count; + // update notification unread count + var count_html = data.unread_count; document.getElementById('notif-count').innerHTML = count_html; // do we have any notifications? @@ -41,7 +40,6 @@ class NotificationHandler { var notif_html = '
'; notif_html += ''; notif_html += ''; - //notif_html += '' + notif.text + ''; notif_html += '' + notif.text + '' notif_html += ''; notif_html += ''; @@ -61,6 +59,7 @@ class NotificationHandler { window.location.href = notif.link; }); }); + notif_index++; }); } diff --git a/src/Controller/NotificationController.php b/src/Controller/NotificationController.php index 6414ce55..64150c51 100644 --- a/src/Controller/NotificationController.php +++ b/src/Controller/NotificationController.php @@ -56,10 +56,12 @@ class NotificationController extends AbstractController $notifs = $em->getRepository(Notification::class)->findBy(['user_id' => 0]); $notif_data = []; - // TODO: count how many notifs are unread and return the count - + $unread_count = 0; foreach ($notifs as $notif) { + if (!($notif->isRead())) + $unread_count++; + $notif_data[] = [ 'id' => $notif->getID(), 'type' => 'jo_new', @@ -74,6 +76,7 @@ class NotificationController extends AbstractController $sample_data = [ 'count' => count($notif_data), + 'unread_count' => $unread_count, 'notifications' => $notif_data, ];