-
Notifications
You must be signed in to change notification settings - Fork 2
Move Activity Tab state from cookie to localStorage #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ var XNAT = getObject(XNAT); | |
| return factory(); | ||
| } | ||
| }(function(){ | ||
| let activityTab, cookieTag; | ||
| let activityTab, storageTag; | ||
| const minimized = 'minimized', | ||
| processes = 'processes'; | ||
|
|
||
|
|
@@ -33,12 +33,16 @@ var XNAT = getObject(XNAT); | |
| XNAT.app.activityTab = activityTab = | ||
| getObject(XNAT.app.activityTab || {}); | ||
|
|
||
| XNAT.app.activityTab.cookieTag = cookieTag = 'activities' + XNAT.sub64.dlxEnc(window.username).encoded; | ||
| XNAT.app.activityTab.storageTag = storageTag = 'activities' + XNAT.sub64.dlxEnc(window.username).encoded; | ||
|
|
||
| activityTab.pollers = []; | ||
|
|
||
| function getActivities() { | ||
| return JSON.parse(XNAT.cookie.get(cookieTag) || '{"' + minimized + '": false, "' + processes + '": {}}'); | ||
| return JSON.parse(localStorage.getItem(storageTag) || '{"' + minimized + '": false, "' + processes + '": {}}'); | ||
| } | ||
|
|
||
| function saveActivities(activities) { | ||
| localStorage.setItem(storageTag, JSON.stringify(activities)); | ||
| } | ||
|
Comment on lines
+44
to
46
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thinking as the read above — we already use localStorage elsewhere without guarding, and the data here is tiny so quota isn't a realistic concern. Leaving it for consistency. |
||
|
|
||
| activityTab.init = function() { | ||
|
|
@@ -68,7 +72,7 @@ var XNAT = getObject(XNAT); | |
| timeout: timeout | ||
| }; | ||
| activities[processes][key] = item; | ||
| XNAT.cookie.set(cookieTag, activities, {}); | ||
| saveActivities(activities); | ||
| activityTab.startPoll(item, key); | ||
| }; | ||
|
|
||
|
|
@@ -108,12 +112,12 @@ var XNAT = getObject(XNAT); | |
| } | ||
| } | ||
| if ($.isEmptyObject(activities[processes])) { | ||
| XNAT.cookie.remove(cookieTag); | ||
| localStorage.removeItem(storageTag); | ||
| const tab = $('#activity-tab'); | ||
|
Comment on lines
112
to
116
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this one's a false alarm — |
||
| tab.css('visibility', 'hidden'); | ||
| tab.find('div.item').remove(); | ||
| } else { | ||
| XNAT.cookie.set(cookieTag, activities, {}); | ||
| saveActivities(activities); | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -295,11 +299,11 @@ var XNAT = getObject(XNAT); | |
| return callback; | ||
| } | ||
|
|
||
| function setMinimized(isMinimized, updateCookie) { | ||
| function setMinimized(isMinimized, updateStorage) { | ||
| let activities = getActivities(); | ||
| if (updateCookie) { | ||
| if (updateStorage) { | ||
| activities[minimized] = isMinimized; | ||
| XNAT.cookie.set(cookieTag, activities, {}); | ||
| saveActivities(activities); | ||
| } | ||
| if (isMinimized) { | ||
| $('#activity-tab .panel-header span.count').text('(' + Object.keys(activities[processes]).length + ')'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to leave this as-is. XNAT already assumes localStorage is available — storage.js writes to it on page load with no guard — so if storage were actually blocked, the app would break well before it got here. Adding a guard just in this spot would be inconsistent with the rest of the app.