From c8991a2a02a0852def5ffb78f90206b21e0e3972 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 30 Nov 2014 04:04:56 -0800 Subject: [PATCH] GUAC-932: Remove localStorageUtility entirely. --- .../app/home/controllers/homeController.js | 18 ++-- .../app/util/services/localStorageUtility.js | 97 ------------------- .../src/main/webapp/app/util/utilModule.js | 2 +- 3 files changed, 10 insertions(+), 107 deletions(-) delete mode 100644 guacamole/src/main/webapp/app/util/services/localStorageUtility.js diff --git a/guacamole/src/main/webapp/app/home/controllers/homeController.js b/guacamole/src/main/webapp/app/home/controllers/homeController.js index d4f85318b..303ff9e5a 100644 --- a/guacamole/src/main/webapp/app/home/controllers/homeController.js +++ b/guacamole/src/main/webapp/app/home/controllers/homeController.js @@ -31,7 +31,7 @@ angular.module('home').controller('homeController', ['$scope', '$injector', // Get the dependencies commonJS style var connectionGroupService = $injector.get("connectionGroupService"); - var localStorageUtility = $injector.get("localStorageUtility"); + var guacHistory = $injector.get("guacHistory"); // All the connections and connection groups in root $scope.connectionsAndGroups = []; @@ -48,14 +48,14 @@ angular.module('home').controller('homeController', ['$scope', '$injector', connectionGroupService.getAllGroupsAndConnections($scope.connectionsAndGroups) .then(function findRecentConnections() { - // Try to parse out the recent connections from local storage - var recentConnections; - try { - recentConnections = JSON.parse(localStorageUtility.get(GUAC_HISTORY_STORAGE_KEY)); - } catch(e) { - - // The recent history is corrupted - clear it - localStorageUtility.clear(GUAC_HISTORY_STORAGE_KEY); + // TODONT: Munch the guacHistory recentConnections list into a legacy-style object + var recentConnections = {}; + for (var i=0; i < guacHistory.recentConnections.length; i++) { + var entry = guacHistory.recentConnections[i]; + recentConnections[encodeURIComponent(entry.id)] = { + id : entry.id, + thumbnail : entry.thumbnail + }; } // Figure out which recent connection entries are valid diff --git a/guacamole/src/main/webapp/app/util/services/localStorageUtility.js b/guacamole/src/main/webapp/app/util/services/localStorageUtility.js deleted file mode 100644 index 5841d14fc..000000000 --- a/guacamole/src/main/webapp/app/util/services/localStorageUtility.js +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2014 Glyptodon LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/** - * A service for handling storage and retrieval of values on localStorage. - * If local storage is not available, cookies will be used as a fallback. - */ -angular.module('util').factory('localStorageUtility', ['$cookieStore', - function localStorageUtility($cookieStore) { - - var service = {}; - - // The prefix to use when storing cookies - var COOKIE_PREFIX = "guacamole.ui.localstorage."; - - // Check if we can actually use localStorage - var localStorageEnabled; - try { - window.localStorage.setItem("test", "test"); - window.localStorage.removeItem("test"); - localStorageEnabled = true; - } catch(e) { - localStorageEnabled = false; - } - - var getFunc, setFunc; - - if(localStorageEnabled) { - - // Just a passthrough to localStorage - getFunc = function getFromLocalStorage(key) { - return window.localStorage.getItem(key); - }; - - setFunc = function setOnLocalStorage(key, value) { - return window.localStorage.setItem(key, value); - }; - } - else { - - // Store the values as cookies - getFunc = function getValueFromCookie(key) { - return $cookieStore.get(COOKIE_PREFIX + key); - }; - - setFunc = function setValueOnCookie(key, value) { - return $cookieStore.put(COOKIE_PREFIX + key, value); - } - } - - /** - * Gets a value from the persistent local store. - * - * @param {string} key The key to use as an index into the map. - * - * @returns {string} The value, if found. - */ - service.get = getFunc; - - /** - * Sets a value on the persistent local store. - * - * @param {string} key The key to use as an index into the map. - * @param {string} value The value to store in the map. - */ - service.set = setFunc; - - /** - * Clear a value from the persistent local store. - * - * @param {string} key The key to clear from the map. - */ - service.clear = function clear(key) { - return service.set(key, undefined); - }; - - return service; -}]); diff --git a/guacamole/src/main/webapp/app/util/utilModule.js b/guacamole/src/main/webapp/app/util/utilModule.js index b86ffb432..89429303c 100644 --- a/guacamole/src/main/webapp/app/util/utilModule.js +++ b/guacamole/src/main/webapp/app/util/utilModule.js @@ -23,4 +23,4 @@ /** * A module for miscellaneous services and utilities that don't belong elsewhere. */ -angular.module('util', ['ngCookies']); +angular.module('util', []);