From 789b640b9bb8979c9620d46c678573a510b9a52e Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 23 Oct 2015 16:28:42 -0700 Subject: [PATCH] Refactored dismiss and minimize out of NotificationService and on to returned Notification type --- .../src/NotificationLaunchController.js | 19 +- .../general/res/templates/message-banner.html | 18 +- .../src/controllers/BannerController.js | 9 +- .../src/NotificationIndicatorController.js | 6 +- .../notification/src/NotificationService.js | 233 +++++++++++------- .../test/NotificationServiceSpec.js | 47 +++- 6 files changed, 218 insertions(+), 114 deletions(-) diff --git a/example/notifications/src/NotificationLaunchController.js b/example/notifications/src/NotificationLaunchController.js index 7d0618ada4..851e0575f5 100644 --- a/example/notifications/src/NotificationLaunchController.js +++ b/example/notifications/src/NotificationLaunchController.js @@ -130,7 +130,7 @@ define( */ $scope.newProgress = function(){ - var notification = { + var notificationModel = { title: "Progress notification example", severity: "info", progress: 0, @@ -142,17 +142,18 @@ define( * Simulate an ongoing process and update the progress bar. * @param notification */ - function incrementProgress(notification) { - notification.progress = Math.min(100, Math.floor(notification.progress + Math.random() * 30)); - notification.progressText = ["Estimated time remaining:" + - " about ", 60 - Math.floor((notification.progress / 100) * 60), " seconds"].join(" "); - if (notification.progress < 100) { - $timeout(function(){incrementProgress(notification);}, 1000); + function incrementProgress(notificationModel) { + notificationModel.progress = Math.min(100, Math.floor(notificationModel.progress + Math.random() * 30)); + notificationModel.progressText = ["Estimated time" + + " remaining:" + + " about ", 60 - Math.floor((notificationModel.progress / 100) * 60), " seconds"].join(" "); + if (notificationModel.progress < 100) { + $timeout(function(){incrementProgress(notificationModel);}, 1000); } } - notificationService.notify(notification); - incrementProgress(notification); + notificationService.notify(notificationModel); + incrementProgress(notificationModel); }; /** diff --git a/platform/commonUI/general/res/templates/message-banner.html b/platform/commonUI/general/res/templates/message-banner.html index 29b107126e..44c7f915b6 100644 --- a/platform/commonUI/general/res/templates/message-banner.html +++ b/platform/commonUI/general/res/templates/message-banner.html @@ -1,20 +1,20 @@
- + - diff --git a/platform/commonUI/general/src/controllers/BannerController.js b/platform/commonUI/general/src/controllers/BannerController.js index 068b5cda81..4be9304cc6 100644 --- a/platform/commonUI/general/src/controllers/BannerController.js +++ b/platform/commonUI/general/src/controllers/BannerController.js @@ -52,14 +52,15 @@ define( }; $scope.dismiss = function(notification, $event) { $event.stopPropagation(); - notificationService.dismissOrMinimize(notification); + notification.dismissOrMinimize(); }; $scope.maximize = function(notification) { - if (notification.severity !== "info"){ - notification.cancel = function(){ + if (notification.model.severity !== "info"){ + + notification.model.cancel = function(){ dialogService.dismiss(); }; - dialogService.showBlockingMessage(notification); + dialogService.showBlockingMessage(notification.model); } }; } diff --git a/platform/commonUI/notification/src/NotificationIndicatorController.js b/platform/commonUI/notification/src/NotificationIndicatorController.js index 66ad825a32..e58b0a606b 100644 --- a/platform/commonUI/notification/src/NotificationIndicatorController.js +++ b/platform/commonUI/notification/src/NotificationIndicatorController.js @@ -48,7 +48,11 @@ define( dialogService.getDialogResponse('overlay-message-list', { dialog: { title: "Messages", - messages: notificationService.notifications + //Launch the message list dialog with the models + // from the notifications + messages: notificationService.notifications && notificationService.notifications.map(function(notification){ + return notification.model; + }) }, cancel: function(){ dialogService.dismiss(); diff --git a/platform/commonUI/notification/src/NotificationService.js b/platform/commonUI/notification/src/NotificationService.js index 140c4537c8..cff2d57d7a 100644 --- a/platform/commonUI/notification/src/NotificationService.js +++ b/platform/commonUI/notification/src/NotificationService.js @@ -29,7 +29,7 @@ * dialogs so that the same information can be provided in a dialog * and then minimized to a banner notification if needed. * - * @namespace platform/commonUI/dialog + * @namespace platform/commonUI/notification */ define( [], @@ -54,11 +54,10 @@ define( * dialogs so that the same information can be provided in a dialog * and then minimized to a banner notification if needed. * - * @typedef {object} Notification + * @typedef {object} NotificationModel * @property {string} title The title of the message - * @property {string} severity The importance of the - * message (one of 'info', 'alert', or 'error' where info < alert < - * error) + * @property {string} severity The importance of the message (one of + * 'info', 'alert', or 'error' where info < alert