From 7f5ebb42b5712460fd29fb086b0734ccba1aacd9 Mon Sep 17 00:00:00 2001
From: Christopher Speller <crspeller@gmail.com>
Date: Wed, 8 Jul 2015 09:55:24 -0400
Subject: Modifying all storage to use session storage. Also adding an
 abstraction layer to add current user id as a prefix to most keys.

---
 web/react/stores/browser_store.jsx | 48 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 web/react/stores/browser_store.jsx

(limited to 'web/react/stores/browser_store.jsx')

diff --git a/web/react/stores/browser_store.jsx b/web/react/stores/browser_store.jsx
new file mode 100644
index 000000000..dd9b09c9f
--- /dev/null
+++ b/web/react/stores/browser_store.jsx
@@ -0,0 +1,48 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var UserStore = require('../stores/user_store.jsx');
+var BROWSER_STORE_VERSION = '.1';
+
+module.exports.initalize = function() {
+	var currentVersion = localStorage.getItem("local_storage_version");
+	if (currentVersion !== BROWSER_STORE_VERSION) {
+		localStorage.clear();
+		sessionStorage.clear();
+		localStorage.setItem("local_storage_version", BROWSER_STORE_VERSION);
+	}
+}
+
+module.exports.setItem = function(name, value) {
+	var user_id = UserStore.getCurrentId();
+	localStorage.setItem(user_id + "_" + name, value);
+};
+
+module.exports.getItem = function(name) {
+	var user_id = UserStore.getCurrentId();
+	return localStorage.getItem(user_id + "_" + name);
+};
+
+module.exports.removeItem = function(name) {
+	var user_id = UserStore.getCurrentId();
+	localStorage.removeItem(user_id + "_" + name);
+};
+
+module.exports.clear = function() {
+	localStorage.clear();
+	sessionStorage.clear();
+};
+
+// Preforms the given action on each item that has the given prefix
+// Signiture for action is action(key, value)
+module.exports.actionOnItemsWithPrefix = function (prefix, action) {
+	var user_id = UserStore.getCurrentId();
+	var id_len = user_id.length;
+	var prefix_len = prefix.length;
+    for (key in localStorage) {
+        if (key.substring(id_len, id_len + prefix_len) === prefix) {
+			var userkey = key.substring(id_len);
+			action(userkey, BrowserStore.getItem(key));
+        }
+    }
+};
-- 
cgit v1.2.3-1-g7c22


From d5785ee9017aedbe6410f23486660fa6ec948c23 Mon Sep 17 00:00:00 2001
From: Christopher Speller <crspeller@gmail.com>
Date: Wed, 8 Jul 2015 12:38:14 -0400
Subject: Finishing centralization of BrowserStore

---
 web/react/stores/browser_store.jsx | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

(limited to 'web/react/stores/browser_store.jsx')

diff --git a/web/react/stores/browser_store.jsx b/web/react/stores/browser_store.jsx
index dd9b09c9f..770f7a289 100644
--- a/web/react/stores/browser_store.jsx
+++ b/web/react/stores/browser_store.jsx
@@ -28,6 +28,18 @@ module.exports.removeItem = function(name) {
 	localStorage.removeItem(user_id + "_" + name);
 };
 
+module.exports.setGlobalItem = function(name, value) {
+	localStorage.setItem(name, value);
+};
+
+module.exports.getGlobalItem = function(name) {
+	return localStorage.getItem(name);
+};
+
+module.exports.removeGlobalItem = function(name) {
+	localStorage.removeItem(name);
+};
+
 module.exports.clear = function() {
 	localStorage.clear();
 	sessionStorage.clear();
@@ -46,3 +58,18 @@ module.exports.actionOnItemsWithPrefix = function (prefix, action) {
         }
     }
 };
+
+module.exports.isLocalStorageSupported = function() {
+    try {
+        sessionStorage.setItem("testSession", '1');
+        sessionStorage.removeItem("testSession");
+
+        localStorage.setItem("testLocal", '1');
+        localStorage.removeItem("testLocal", '1');
+
+        return true;
+    } 
+    catch (e) {
+        return false;
+    }
+}
-- 
cgit v1.2.3-1-g7c22


From ce5639a6290bcb2403376cabfffe784283ac5b5a Mon Sep 17 00:00:00 2001
From: Christopher Speller <crspeller@gmail.com>
Date: Wed, 8 Jul 2015 12:43:23 -0400
Subject: Adding comments to change versions in sync

---
 web/react/stores/browser_store.jsx | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'web/react/stores/browser_store.jsx')

diff --git a/web/react/stores/browser_store.jsx b/web/react/stores/browser_store.jsx
index 770f7a289..b3e54cad5 100644
--- a/web/react/stores/browser_store.jsx
+++ b/web/react/stores/browser_store.jsx
@@ -2,6 +2,8 @@
 // See License.txt for license information.
 
 var UserStore = require('../stores/user_store.jsx');
+
+// Also change model/utils.go ETAG_ROOT_VERSION
 var BROWSER_STORE_VERSION = '.1';
 
 module.exports.initalize = function() {
-- 
cgit v1.2.3-1-g7c22

