more fine grained handling of conflicts without having to reload whole page most of the time

This commit is contained in:
azivner
2017-11-01 22:36:26 -04:00
parent 962c078bbc
commit 1cf247f164
7 changed files with 172 additions and 111 deletions

View File

@@ -1,14 +1,27 @@
function checkStatus() {
$.ajax({
url: baseApiUrl + 'status/' + globalFullLoadTime,
type: 'GET',
url: baseApiUrl + 'status',
type: 'POST',
contentType: "application/json",
data: JSON.stringify({
treeLoadTime: globalTreeLoadTime,
currentNoteId: globalCurrentNote ? globalCurrentNote.detail.note_id : null,
currentNoteDateModified: globalCurrentNoteLoadTime
}),
success: resp => {
if (resp.changed) {
window.location.reload(true);
if (resp.changedTree) {
loadTree().then(resp => {
console.log("Reloading tree because of background changes");
globalTree.fancytree('getTree').reload(resp.notes);
});
}
else {
$("#changesToPushCount").html(resp.changesToPushCount);
if (resp.changedCurrentNote) {
alert("Current note has been changed in different window / computer. Please reload the application and resolve the conflict manually.");
}
$("#changesToPushCount").html(resp.changesToPushCount);
},
statusCode: {
401: () => {
@@ -24,4 +37,4 @@ function checkStatus() {
});
}
setInterval(checkStatus, 10 * 1000);
setInterval(checkStatus, 5 * 1000);