mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
GUAC-1161: Store notification state in session-local storage.
This commit is contained in:
@@ -23,4 +23,6 @@
|
||||
/**
|
||||
* The module for code used to display arbitrary notifications.
|
||||
*/
|
||||
angular.module('notification', []);
|
||||
angular.module('notification', [
|
||||
'storage'
|
||||
]);
|
||||
|
@@ -23,33 +23,48 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
service.getStatus = function getStatus() {
|
||||
return storedStatus();
|
||||
};
|
||||
|
||||
/**
|
||||
* Shows or hides the given notification as a modal status. If a status
|
||||
@@ -77,8 +92,18 @@ 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();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -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
|
||||
|
@@ -38,9 +38,9 @@ THE SOFTWARE.
|
||||
<div ng-if="!expectedCredentials">
|
||||
|
||||
<!-- Global status/error dialog -->
|
||||
<div ng-class="{shown: guacNotification.status}" class="status-outer">
|
||||
<div ng-class="{shown: guacNotification.getStatus()}" class="status-outer">
|
||||
<div class="status-middle">
|
||||
<guac-notification notification="guacNotification.status"></guac-notification>
|
||||
<guac-notification notification="guacNotification.getStatus()"></guac-notification>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -49,7 +49,7 @@ THE SOFTWARE.
|
||||
|
||||
<!-- Notification area -->
|
||||
<div id="notificationArea">
|
||||
<div ng-repeat="wrapper in guacNotification.notifications">
|
||||
<div ng-repeat="wrapper in guacNotification.getNotifications()">
|
||||
<guac-notification notification="wrapper.notification"></guac-notification>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user