2017-11-05 07:38:50 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-05 07:35:39 +08:00
|
|
|
const status = (function() {
|
|
|
|
const treeEl = $("#tree");
|
|
|
|
const $changesToPushCountEl = $("#changesToPushCount");
|
|
|
|
|
|
|
|
async function checkStatus() {
|
|
|
|
const resp = await $.ajax({
|
|
|
|
url: baseApiUrl + 'status',
|
|
|
|
type: 'POST',
|
|
|
|
contentType: "application/json",
|
|
|
|
data: JSON.stringify({
|
|
|
|
treeLoadTime: noteTree.getTreeLoadTime(),
|
|
|
|
currentNoteId: noteEditor.getCurrentNoteId(),
|
2017-11-05 09:02:56 +08:00
|
|
|
currentNoteLoadTime: noteEditor.getCurrentNoteLoadTime()
|
2017-11-05 07:35:39 +08:00
|
|
|
}),
|
|
|
|
statusCode: {
|
|
|
|
401: () => {
|
|
|
|
// if the user got logged out then we should display the page
|
|
|
|
// here we do that by reloading which will force the redirect if the user is really logged out
|
|
|
|
window.location.reload(true);
|
|
|
|
},
|
|
|
|
409: () => {
|
|
|
|
// 409 means we need to migrate database, reload will take care of it
|
|
|
|
window.location.reload(true);
|
|
|
|
}
|
2017-11-02 08:31:44 +08:00
|
|
|
}
|
2017-11-05 07:35:39 +08:00
|
|
|
});
|
2017-11-04 09:20:06 +08:00
|
|
|
|
2017-11-05 07:35:39 +08:00
|
|
|
if (resp.changedTree) {
|
|
|
|
console.log("Reloading tree because of background changes");
|
2017-11-04 09:20:06 +08:00
|
|
|
|
2017-11-05 22:52:28 +08:00
|
|
|
noteTree.reload();
|
2017-11-05 07:35:39 +08:00
|
|
|
}
|
2017-11-04 09:20:06 +08:00
|
|
|
|
2017-11-05 07:35:39 +08:00
|
|
|
$changesToPushCountEl.html(resp.changesToPushCount);
|
2017-11-04 09:20:06 +08:00
|
|
|
}
|
|
|
|
|
2017-11-05 07:35:39 +08:00
|
|
|
setInterval(checkStatus, 5 * 1000);
|
2017-11-02 08:31:44 +08:00
|
|
|
|
2017-11-05 07:35:39 +08:00
|
|
|
return {
|
|
|
|
checkStatus
|
|
|
|
};
|
|
|
|
})();
|