Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions xnat-web/src/main/webapp/scripts/xnat/app/activityTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var XNAT = getObject(XNAT);
return factory();
}
}(function(){
let activityTab, cookieTag;
let activityTab, storageTag;
const minimized = 'minimized',
processes = 'processes';

Expand All @@ -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 + '": {}}');
}
Comment on lines 40 to +42

Copy link
Copy Markdown
Contributor Author

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.


function saveActivities(activities) {
localStorage.setItem(storageTag, JSON.stringify(activities));
}
Comment on lines +44 to 46

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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() {
Expand Down Expand Up @@ -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);
};

Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one's a false alarm — for...in over undefined doesn't throw, it just returns true, so the close-all case works fine. It's also pre-existing behavior that this PR didn't change. Leaving as-is.

tab.css('visibility', 'hidden');
tab.find('div.item').remove();
} else {
XNAT.cookie.set(cookieTag, activities, {});
saveActivities(activities);
}
};

Expand Down Expand Up @@ -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 + ')');
Expand Down