mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	status converted to module
This commit is contained in:
		
							parent
							
								
									ad7803f9dc
								
							
						
					
					
						commit
						60a3abdea9
					
				@ -1,40 +1,47 @@
 | 
				
			|||||||
const treeEl = $("#tree");
 | 
					const status = (function() {
 | 
				
			||||||
 | 
					    const treeEl = $("#tree");
 | 
				
			||||||
 | 
					    const $changesToPushCountEl = $("#changesToPushCount");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function checkStatus() {
 | 
					    async function checkStatus() {
 | 
				
			||||||
    const resp = await $.ajax({
 | 
					        const resp = await $.ajax({
 | 
				
			||||||
        url: baseApiUrl + 'status',
 | 
					            url: baseApiUrl + 'status',
 | 
				
			||||||
        type: 'POST',
 | 
					            type: 'POST',
 | 
				
			||||||
        contentType: "application/json",
 | 
					            contentType: "application/json",
 | 
				
			||||||
        data: JSON.stringify({
 | 
					            data: JSON.stringify({
 | 
				
			||||||
            treeLoadTime: noteTree.getTreeLoadTime(),
 | 
					                treeLoadTime: noteTree.getTreeLoadTime(),
 | 
				
			||||||
            currentNoteId: noteEditor.getCurrentNoteId(),
 | 
					                currentNoteId: noteEditor.getCurrentNoteId(),
 | 
				
			||||||
            currentNoteDateModified: noteEditor.getCurrentNoteLoadTime()
 | 
					                currentNoteDateModified: noteEditor.getCurrentNoteLoadTime()
 | 
				
			||||||
        }),
 | 
					            }),
 | 
				
			||||||
        statusCode: {
 | 
					            statusCode: {
 | 
				
			||||||
            401: () => {
 | 
					                401: () => {
 | 
				
			||||||
                // if the user got logged out then we should display the page
 | 
					                    // 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
 | 
					                    // here we do that by reloading which will force the redirect if the user is really logged out
 | 
				
			||||||
                window.location.reload(true);
 | 
					                    window.location.reload(true);
 | 
				
			||||||
            },
 | 
					                },
 | 
				
			||||||
            409: () => {
 | 
					                409: () => {
 | 
				
			||||||
                // 409 means we need to migrate database, reload will take care of it
 | 
					                    // 409 means we need to migrate database, reload will take care of it
 | 
				
			||||||
                window.location.reload(true);
 | 
					                    window.location.reload(true);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (resp.changedTree) {
 | 
				
			||||||
 | 
					            const treeResp = await noteTree.loadTree();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            console.log("Reloading tree because of background changes");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // this will also reload the note content
 | 
				
			||||||
 | 
					            await treeEl.fancytree('getTree').reload(treeResp.notes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            encryption.decryptTreeItems();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (resp.changedTree) {
 | 
					        $changesToPushCountEl.html(resp.changesToPushCount);
 | 
				
			||||||
        const treeResp = await noteTree.loadTree();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        console.log("Reloading tree because of background changes");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // this will also reload the note content
 | 
					 | 
				
			||||||
        await treeEl.fancytree('getTree').reload(treeResp.notes);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        encryption.decryptTreeItems();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $("#changesToPushCount").html(resp.changesToPushCount);
 | 
					    setInterval(checkStatus, 5 * 1000);
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
setInterval(checkStatus, 5 * 1000);
 | 
					    return {
 | 
				
			||||||
 | 
					        checkStatus
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					})();
 | 
				
			||||||
@ -4,7 +4,7 @@ function syncNow() {
 | 
				
			|||||||
        type: 'POST',
 | 
					        type: 'POST',
 | 
				
			||||||
        success: result => {
 | 
					        success: result => {
 | 
				
			||||||
            if (result.success) {
 | 
					            if (result.success) {
 | 
				
			||||||
                checkStatus();
 | 
					                status.checkStatus();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                message("Sync triggered.");
 | 
					                message("Sync triggered.");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user