From 592ce3b8d305a6b84060010be6e33dc0428db8b5 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 23 Apr 2015 13:57:44 -0700 Subject: [PATCH] GUAC-1161: Store notification state in session-local storage. --- .../app/notification/notificationModule.js | 4 +- .../notification/services/guacNotification.js | 85 +++++++++++++------ guacamole/src/main/webapp/index.html | 6 +- 3 files changed, 63 insertions(+), 32 deletions(-) diff --git a/guacamole/src/main/webapp/app/notification/notificationModule.js b/guacamole/src/main/webapp/app/notification/notificationModule.js index 54c64fdfb..d4008200f 100644 --- a/guacamole/src/main/webapp/app/notification/notificationModule.js +++ b/guacamole/src/main/webapp/app/notification/notificationModule.js @@ -23,4 +23,6 @@ /** * The module for code used to display arbitrary notifications. */ -angular.module('notification', []); +angular.module('notification', [ + 'storage' +]); diff --git a/guacamole/src/main/webapp/app/notification/services/guacNotification.js b/guacamole/src/main/webapp/app/notification/services/guacNotification.js index b5f5c9872..eb9b15c62 100644 --- a/guacamole/src/main/webapp/app/notification/services/guacNotification.js +++ b/guacamole/src/main/webapp/app/notification/services/guacNotification.js @@ -23,34 +23,49 @@ /** * Service for displaying notifications and modal status dialogs. */ -angular.module('notification').factory('guacNotification', ['$rootScope', - function guacNotification($rootScope) { +angular.module('notification').factory('guacNotification', ['$injector', + function guacNotification($injector) { + + // Required services + var $rootScope = $injector.get('$rootScope'); + var sessionStorageFactory = $injector.get('sessionStorageFactory'); var service = {}; /** - * The current status notification, or false if no status is currently - * shown. + * Getter/setter which retrieves or sets the current status notification, + * which may simply be false if no status is currently shown. + * + * @type Function + */ + var storedStatus = sessionStorageFactory.create(false); + + /** + * Getter/setter which retrieves or sets an array of all currently-visible + * notifications. + * + * @type Function + */ + var storedNotifications = sessionStorageFactory.create([]); + + /** + * Getter/setter which retrieves or sets the ID of the most recently shown + * notification, or 0 if no notifications have yet been shown. + * + * @type Function + */ + var storedNotificationUniqueID = sessionStorageFactory.create(0); + + /** + * Retrieves the current status notification, which may simply be false if + * no status is currently shown. * * @type Notification|Boolean */ - service.status = false; + service.getStatus = function getStatus() { + return storedStatus(); + }; - /** - * All currently-visible notifications. - * - * @type Notification[] - */ - service.notifications = []; - - /** - * The ID of the most recently shown notification, or 0 if no notifications - * have yet been shown. - * - * @type Number - */ - var notificationUniqueID = 0; - /** * Shows or hides the given notification as a modal status. If a status * notification is currently shown, no further statuses will be shown @@ -77,10 +92,20 @@ angular.module('notification').factory('guacNotification', ['$rootScope', * guacNotification.showStatus(false); */ service.showStatus = function showStatus(status) { - if (!service.status || !status) - service.status = status; + if (!storedStatus() || !status) + storedStatus(status); }; - + + /** + * Returns an array of all currently-visible notifications. + * + * @returns {Notification[]} + * An array of all currently-visible notifications. + */ + service.getNotifications = function getNotifications() { + return storedNotifications(); + }; + /** * Adds a notification to the the list of notifications shown. * @@ -104,9 +129,9 @@ angular.module('notification').factory('guacNotification', ['$rootScope', * }); */ service.addNotification = function addNotification(notification) { - var id = ++notificationUniqueID; + var id = storedNotificationUniqueID(storedNotificationUniqueID() + 1); - service.notifications.push({ + storedNotifications().push({ notification : notification, id : id }); @@ -122,12 +147,16 @@ angular.module('notification').factory('guacNotification', ['$rootScope', * from the initial call to addNotification. */ service.removeNotification = function removeNotification(id) { - for (var i = 0; i < service.notifications.length; i++) { - if (service.notifications[i].id === id) { - service.notifications.splice(i, 1); + + var notifications = storedNotifications(); + + for (var i = 0; i < notifications.length; i++) { + if (notifications[i].id === id) { + notifications.splice(i, 1); return; } } + }; // Hide status upon navigation diff --git a/guacamole/src/main/webapp/index.html b/guacamole/src/main/webapp/index.html index 86d4ef8ea..41fec33d2 100644 --- a/guacamole/src/main/webapp/index.html +++ b/guacamole/src/main/webapp/index.html @@ -38,9 +38,9 @@ THE SOFTWARE.
-
+
- +
@@ -49,7 +49,7 @@ THE SOFTWARE.
-
+