From 855f294ed2eab01a126ac6e67366cd411bf7e948 Mon Sep 17 00:00:00 2001 From: Ace Date: Sat, 16 Dec 2017 10:03:02 +0530 Subject: [PATCH 1/5] improving notifications management --- .../api/NotificationManagementService.java | 28 +++++++++++++ .../NotificationManagementServiceImpl.java | 12 ++++++ .../mgt/NotificationManagementService.java | 10 +++++ .../NotificationManagementServiceImpl.java | 21 ++++++++++ .../notification/mgt/dao/NotificationDAO.java | 8 ++++ .../dao/impl/AbstractNotificationDAOImpl.java | 21 ++++++++++ .../cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs | 6 ++- .../public/js/nav-menu.js | 42 +++++++++++++++++-- .../public/templates/notifications.hbs | 33 ++++++++++----- .../public/css/custom-desktop.css | 6 ++- 10 files changed, 172 insertions(+), 15 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java index 62db9aacd8..8610aa3461 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java @@ -209,4 +209,32 @@ public interface NotificationManagementService { defaultValue = "1") @PathParam("id") @Max(45) int id); + + + @PUT + @Path("/clear-all") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Clear all notifications", + notes = "When a user needs to mark all the notifications as checked/read this " + + "function can be used to clear all notifications", + tags = "Device Notification Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:notifications:mark-checked") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK"), + @ApiResponse( + code = 500, + message = "Error occurred while clearing notifications.") + } + ) + Response clearAllNotifications(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java index 8e2322cd0a..b39493d6a0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java @@ -102,4 +102,16 @@ public class NotificationManagementServiceImpl implements NotificationManagement } } + @Override + public Response clearAllNotifications() { + Notification.Status status = Notification.Status.CHECKED; + try { + DeviceMgtAPIUtils.getNotificationManagementService().updateAllNotifications(status); + return Response.status(Response.Status.OK).build(); + } catch (NotificationManagementException e) { + log.error("Error encountered while trying to clear all notifications.", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java index d2a0cfcf6d..429f9d30e3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java @@ -63,6 +63,16 @@ public interface NotificationManagementService { boolean updateNotificationStatus(int notificationId, Notification.Status status) throws NotificationManagementException; + /** + * Method for updating status all notifications. + * + * @return boolean status of the operation. + * @throws NotificationManagementException + * if something goes wrong while updating the Notification. + */ + boolean updateAllNotifications(Notification.Status status) throws + NotificationManagementException; + /** * Method to fetch all the notifications in the database. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java index 09e1eca4f9..493fc21989 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java @@ -141,6 +141,27 @@ public class NotificationManagementServiceImpl implements NotificationManagement return true; } + @Override + public boolean updateAllNotifications(Notification.Status status) throws NotificationManagementException { + if (log.isDebugEnabled()) { + log.debug("Attempting to clear all notifications"); + } + try { + NotificationManagementDAOFactory.beginTransaction(); + notificationDAO.updateAllNotifications(status); + NotificationManagementDAOFactory.commitTransaction(); + } catch (TransactionManagementException e) { + NotificationManagementDAOFactory.rollbackTransaction(); + throw new NotificationManagementException("Error occurred while updating notification", e); + } finally { + NotificationManagementDAOFactory.closeConnection(); + } + if (log.isDebugEnabled()) { + log.debug("All notifications updated successfully."); + } + return true; + } + @Override public List getAllNotifications() throws NotificationManagementException { try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java index f9787b4501..59034c159f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java @@ -61,6 +61,14 @@ public interface NotificationDAO { int updateNotificationStatus(int notificationId, Notification.Status status) throws NotificationManagementException; + /** + * Update status of all notifications. + * + * @return returns the no of updated records. + * @throws NotificationManagementException + */ + int updateAllNotifications(Notification.Status status) throws NotificationManagementException; + /** * This method is used to get all notifications based on tenant-id. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java index 9ae0a693f4..6b7d325289 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java @@ -142,6 +142,27 @@ public abstract class AbstractNotificationDAOImpl implements NotificationDAO { return rows; } + @Override + public int updateAllNotifications(Notification.Status status) + throws NotificationManagementException { + Connection conn; + PreparedStatement stmt = null; + int rows; + try { + conn = NotificationManagementDAOFactory.getConnection(); + String sql = "UPDATE DM_NOTIFICATION SET STATUS = ?"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, status.toString()); + rows = stmt.executeUpdate(); + } catch (Exception e) { + throw new NotificationManagementException("Error while trying to clear all " + + "notifications", e); + } finally { + NotificationDAOUtil.cleanupResources(stmt, null); + } + return rows; + } + @Override public List getAllNotifications(int tenantId) throws NotificationManagementException { Connection conn; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs index 2ec63e3b73..d18685ec40 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs @@ -158,7 +158,11 @@ data-side="right" data-width="320" data-sidebar-fixed="true" data-top="90" data-fixed-offset="90" data-offset-top="50" data-spy="affix"> - + + {{/zone}} {{#zone "bottomJs"}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js index 4f10b1bd39..f622790e49 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js @@ -425,18 +425,24 @@ $.fn.collapse_nav_sub = function () { $(document).ready(function () { loadNotificationsPanel(); - $("#right-sidebar").on("click", ".new-notification", function () { - var notificationId = $(this).data("id"); + $("#right-sidebar").on("click", ".new-notification", function (e) { + e.preventDefault(); + var notificationId = $(this).parents('li').find('h4 a').data('id'); var redirectUrl = $(this).data("url"); var markAsReadNotificationsAPI = "/api/device-mgt/v1.0/notifications/" + notificationId + "/mark-checked"; var messageSideBar = ".sidebar-messages"; + var clickEvent = $(this).data('click-event'); + var eventHandler = $(this); invokerUtil.put( markAsReadNotificationsAPI, null, function (data) { data = JSON.parse(data); - if (data.statusCode == responseCodes["ACCEPTED"]) { + if(clickEvent && clickEvent === 'remove-notification'){ + $(eventHandler).parents('li').slideUp(); + $("#notification-bubble").html(parseInt($("#notification-bubble").text()) - 1); + }else { location.href = redirectUrl; } }, function () { @@ -448,6 +454,36 @@ $(document).ready(function () { ); }); + $("#right-sidebar").on("click", ".btn", function (e) { + + var clickEvent = $(this).data('click-event'); + + if(clickEvent == "clear-notification"){ + e.preventDefault(); + var markAsReadNotificationsAPI = "/api/device-mgt/v1.0/notifications/clear-all"; + var messageSideBar = ".sidebar-messages"; + var clickEvent = $(this).data('click-event'); + var eventHandler = $(this); + console.log(clickEvent); + + invokerUtil.put( + markAsReadNotificationsAPI, + null, + function (data) { + console.log(data); + $('.message').remove(); + $("#notification-bubble").html(0); + }, function () { + var content = "
  • Warning

    " + + "

    Unexpected error occurred while loading notification. Please refresh the page and" + + " try again

  • "; + $(messageSideBar).html(content); + } + ); + } + + }); + if (typeof $.fn.collapse == 'function') { $('.navbar-collapse.tiles').on('shown.bs.collapse', function () { $(this).collapse_nav_sub(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs index e209e093ed..f447dc9a73 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs @@ -1,14 +1,27 @@ {{#each notifications}}
  • -

    - - - {{deviceType}} : {{deviceName}} - -

    -

    {{description}}

    + + + +
    +

    + + + {{deviceType}} : {{deviceName}} + +

    +

    {{description}}

    +
    + + + + + + + +
  • {{/each}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css index 6f917a9eb5..b661f08b22 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css @@ -1178,8 +1178,12 @@ header .fw-user:before{ right: 0; } +.all-notifications{ + margin-bottom: 10px !important; +} + .sidebar-wrapper.toggled a.btn{ - margin-bottom: 70px; + margin-bottom: 70px; } .sidebar-wrapper-animation-fix { From c506d906981259f90bc9b714efb6c090f97cd4f9 Mon Sep 17 00:00:00 2001 From: Ace Date: Sat, 16 Dec 2017 11:27:28 +0530 Subject: [PATCH 2/5] removing un-necessary logs --- .../app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js | 1 - 1 file changed, 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js index f622790e49..b9e4e1215b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js @@ -464,7 +464,6 @@ $(document).ready(function () { var messageSideBar = ".sidebar-messages"; var clickEvent = $(this).data('click-event'); var eventHandler = $(this); - console.log(clickEvent); invokerUtil.put( markAsReadNotificationsAPI, From 29c069228699df9705da04320753bed55726aae9 Mon Sep 17 00:00:00 2001 From: Ace Date: Sat, 16 Dec 2017 11:29:10 +0530 Subject: [PATCH 3/5] removing un-necessary logs --- .../app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js | 1 - 1 file changed, 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js index b9e4e1215b..c13d4ca235 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js @@ -469,7 +469,6 @@ $(document).ready(function () { markAsReadNotificationsAPI, null, function (data) { - console.log(data); $('.message').remove(); $("#notification-bubble").html(0); }, function () { From fb6c98b96999783554dd50faed5f222668e9c417 Mon Sep 17 00:00:00 2001 From: Ace Date: Mon, 18 Dec 2017 12:43:37 +0530 Subject: [PATCH 4/5] Restricting clear notifications to tenant domain only --- .../service/impl/NotificationManagementServiceImpl.java | 5 ++++- .../notification/mgt/NotificationManagementService.java | 2 +- .../notification/mgt/NotificationManagementServiceImpl.java | 5 +++-- .../mgt/core/notification/mgt/dao/NotificationDAO.java | 3 ++- .../mgt/dao/impl/AbstractNotificationDAOImpl.java | 5 +++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java index b39493d6a0..8bfbb0cd7d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; @@ -106,7 +107,9 @@ public class NotificationManagementServiceImpl implements NotificationManagement public Response clearAllNotifications() { Notification.Status status = Notification.Status.CHECKED; try { - DeviceMgtAPIUtils.getNotificationManagementService().updateAllNotifications(status); + int loggedinUserTenantId = CarbonContext.getThreadLocalCarbonContext() + .getTenantId(); + DeviceMgtAPIUtils.getNotificationManagementService().updateAllNotifications(status, loggedinUserTenantId); return Response.status(Response.Status.OK).build(); } catch (NotificationManagementException e) { log.error("Error encountered while trying to clear all notifications.", e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java index 429f9d30e3..2f4837a4a4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/NotificationManagementService.java @@ -70,7 +70,7 @@ public interface NotificationManagementService { * @throws NotificationManagementException * if something goes wrong while updating the Notification. */ - boolean updateAllNotifications(Notification.Status status) throws + boolean updateAllNotifications(Notification.Status status, int tenantID) throws NotificationManagementException; /** diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java index 493fc21989..2660ba757d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java @@ -142,13 +142,14 @@ public class NotificationManagementServiceImpl implements NotificationManagement } @Override - public boolean updateAllNotifications(Notification.Status status) throws NotificationManagementException { + public boolean updateAllNotifications(Notification.Status status, int tenantID) throws + NotificationManagementException { if (log.isDebugEnabled()) { log.debug("Attempting to clear all notifications"); } try { NotificationManagementDAOFactory.beginTransaction(); - notificationDAO.updateAllNotifications(status); + notificationDAO.updateAllNotifications(status, tenantID); NotificationManagementDAOFactory.commitTransaction(); } catch (TransactionManagementException e) { NotificationManagementDAOFactory.rollbackTransaction(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java index 59034c159f..4c47d7c90e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/NotificationDAO.java @@ -67,7 +67,8 @@ public interface NotificationDAO { * @return returns the no of updated records. * @throws NotificationManagementException */ - int updateAllNotifications(Notification.Status status) throws NotificationManagementException; + int updateAllNotifications(Notification.Status status, int tenantID) throws + NotificationManagementException; /** * This method is used to get all notifications based on tenant-id. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java index 6b7d325289..74d63ee159 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java @@ -143,16 +143,17 @@ public abstract class AbstractNotificationDAOImpl implements NotificationDAO { } @Override - public int updateAllNotifications(Notification.Status status) + public int updateAllNotifications(Notification.Status status, int tenantID) throws NotificationManagementException { Connection conn; PreparedStatement stmt = null; int rows; try { conn = NotificationManagementDAOFactory.getConnection(); - String sql = "UPDATE DM_NOTIFICATION SET STATUS = ?"; + String sql = "UPDATE DM_NOTIFICATION SET STATUS = ? WHERE TENANT_ID= ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, status.toString()); + stmt.setInt(2, tenantID); rows = stmt.executeUpdate(); } catch (Exception e) { throw new NotificationManagementException("Error while trying to clear all " + From e2ce619166cf13115bad741b326a286d69e34c45 Mon Sep 17 00:00:00 2001 From: Ace Date: Tue, 19 Dec 2017 11:16:55 +0530 Subject: [PATCH 5/5] Adding UI enhancements and including unit tests --- ...otificationManagementServiceImplTests.java | 7 ++ .../listing.hbs | 24 ++---- .../public/js/notification-listing.js | 73 ++++++++++++++---- .../templates/notification-listing-all.hbs | 42 +++++++++++ .../templates/notification-listing-new.hbs | 44 +++++++++++ .../public/templates/notification-listing.hbs | 75 ------------------- .../cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs | 2 +- .../public/js/nav-menu.js | 6 -- .../public/templates/notifications.hbs | 2 +- 9 files changed, 159 insertions(+), 116 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing-all.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing-new.hbs delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java index 21e729293d..ad174a51e2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImplTests.java @@ -216,5 +216,12 @@ public class NotificationManagementServiceImplTests { " as added no. of records."); } + @Test(dependsOnMethods = "updateStatusofAllNotification", description = "this tries to " + + "update the status of all notifications") + public void updateStatusOfAllNotifications() throws NotificationManagementException { + Assert.assertTrue(notificationManagementService.updateAllNotifications(Notification + .Status.CHECKED, -1234)); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/listing.hbs index 3f29f25235..8d5b105188 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/listing.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/listing.hbs @@ -44,21 +44,6 @@
    - - - - - -
    -
    - No unread messages -
    -
    - -
    @@ -68,8 +53,13 @@ {{/zone}} {{#zone "bottomJs"}} - + {{js "js/notification-listing.js"}} {{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js index d5b776e747..ce06cd5d4f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js @@ -29,30 +29,74 @@ function InitiateViewOption() { } function loadNotifications() { - var deviceListing = $("#notification-listing"); - var deviceListingSrc = deviceListing.attr("src"); - var currentUser = deviceListing.data("currentUser"); + var deviceListingNew = $("#notification-listing-new"); + var deviceListingNewSrc = deviceListingNew.attr("src"); + + var deviceListingAll = $("#notification-listing-all"); + var deviceListingAllSrc = deviceListingAll.attr("src"); + $.template( - "notification-listing", - deviceListingSrc, + "notification-listing-new", + deviceListingNewSrc, function (template) { invokerUtil.get( - deviceMgtAPIBaseURI + "/notifications", + deviceMgtAPIBaseURI + "/notifications?status=NEW", // on success function (data, textStatus, jqXHR) { if (jqXHR.status == 200 && data) { data = JSON.parse(data); - if (data["notifications"] && data["notifications"].length > 0) { + if (data["notifications"]) { notificationsAvailable = true; var viewModel = {}; viewModel["notifications"] = data["notifications"]; viewModel["appContext"] = context; var content = template(viewModel); - $("#ast-container").html(content); + $("#ast-container").append(content); var settings = { "sorting" : false }; $("#unread-notifications").datatables_extended(settings); + + /** + * append advance operations to list table toolbar + */ + $('#unread-notifications_wrapper').find('.dataTablesTop' + + ' .dataTables_toolbar').html( + "Clear All" + + " Notifications" + ); + } + } + }, + // on error + function (jqXHR) { + console.log(jqXHR.status); + } + ); + } + ); + + $.template( + "notification-listing-all", + deviceListingAllSrc, + function (template) { + invokerUtil.get( + deviceMgtAPIBaseURI + "/notifications", + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + data = JSON.parse(data); + if (data["notifications"]) { + notificationsAvailable = true; + var viewModel = {}; + viewModel["notifications"] = data["notifications"]; + viewModel["appContext"] = context; + var content = template(viewModel); + $("#ast-container").append(content); + var settings = { + "sorting" : false + }; $("#all-notifications").datatables_extended(settings); } } @@ -70,16 +114,9 @@ function loadNotifications() { function showAdvanceOperation(operation, button) { $(button).addClass('selected'); $(button).siblings().removeClass('selected'); - if ($(button).attr("id") == 'allNotifications') { - $("#noNotificationtxt").html('You do not have any notifications '); - } else if ($(button).attr("id") == 'unReadNotifications') { - $("#noNotificationtxt").html('You do not have any unread notifications '); - } else { - $("#noNotificationtxt").html('You do not have any unread notifications '); - } var hiddenOperation = ".wr-hidden-operations-content > div"; - $(hiddenOperation + '[data-operation="' + operation + '"]').show(); $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); + $(hiddenOperation + '[data-operation="' + operation + '"]').show(); } $(document).ready(function () { @@ -143,6 +180,10 @@ $(document).ready(function () { function (data) { $('.message').remove(); $("#notification-bubble").html(0); + var undreadNotifications = $("#unread-notifications"); + undreadNotifications.find("tbody").empty(); + undreadNotifications.find("tbody").append("No data" + + " available in table"); }, function () { var content = "
  • Warning

    " + "

    Unexpected error occurred while loading notification. Please refresh the page and" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing-all.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing-all.hbs new file mode 100644 index 0000000000..b5a6adab35 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing-all.hbs @@ -0,0 +1,42 @@ + +

    +
    +
    + + + + + + + + + + + {{#if notifications}} + {{#each notifications}} + + + + + {{/each}} + {{else}} +
    + You do not have any notifications +
    + {{/if}} +
    + +
    DescriptionAction
    {{description}} + + + + + + +
    +
    +
    +
    + \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing-new.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing-new.hbs new file mode 100644 index 0000000000..8bdc4a5276 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing-new.hbs @@ -0,0 +1,44 @@ + +
    +
    +
    + + + + + + + + + + + {{#if notifications}} + {{#each notifications}} + {{#equal "NEW" status }} + + + + + {{/equal}} + {{/each}} + {{else}} +
    + You do not have any unread notifications +
    + {{/if}} +
    + +
    DescriptionAction
    {{description}} + + + + + + +
    +
    +
    +
    + \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs deleted file mode 100644 index cd1f8196ce..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs +++ /dev/null @@ -1,75 +0,0 @@ - -
    -
    -
    - - - - - - - - - - - {{#each notifications}} - {{#equal "NEW" status }} - - - - - {{/equal}} - {{/each}} -
    - -
    DescriptionAction
    {{description}} - - - - - - -
    -
    -
    -
    - - - -
    -
    -
    - - - - - - - - - - - {{#each notifications}} - - - - - {{/each}} -
    - -
    DescriptionAction
    {{description}} - - - - - - -
    -
    -
    -
    - \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs index a486eafe7f..886bb4ccbe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs @@ -160,7 +160,7 @@ - {{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js index 3fb25289ac..0e4fb7b580 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/js/nav-menu.js @@ -21,7 +21,6 @@ var modalPopupContainer = modalPopup + " .modal-content"; var modalPopupContent = modalPopup + " .modal-content"; var backendEndBasePath = "/api/device-mgt/v1.0"; -var notificationsAvailable = false; /* * set popup maximum height function. @@ -102,7 +101,6 @@ function loadNewNotifications() { viewModel.context = context; viewModel.notifications = responsePayload.notifications; if (responsePayload.count > 0) { - notificationsAvailable = true; $(messageSideBar).html(template(viewModel)); } else { $(messageSideBar).html( @@ -456,10 +454,6 @@ $(document).ready(function () { ); }); - if(notificationsAvailable) { - $("#right-side-pane-notifications-clear").removeClass("hidden"); - } - $("#right-sidebar").on("click", ".btn", function (e) { var clickEvent = $(this).data('click-event'); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs index f447dc9a73..21fbb9b0b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/public/templates/notifications.hbs @@ -6,7 +6,7 @@ {{deviceType}} : {{deviceName}}