mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	number of sync changes to push next to "sync now" button
This commit is contained in:
		
							parent
							
								
									72905a9854
								
							
						
					
					
						commit
						962c078bbc
					
				
							
								
								
									
										4
									
								
								app.js
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								app.js
									
									
									
									
									
								
							@ -20,7 +20,7 @@ const migrationRoute = require('./routes/migration');
 | 
				
			|||||||
const treeApiRoute = require('./routes/api/tree');
 | 
					const treeApiRoute = require('./routes/api/tree');
 | 
				
			||||||
const notesApiRoute = require('./routes/api/notes');
 | 
					const notesApiRoute = require('./routes/api/notes');
 | 
				
			||||||
const notesMoveApiRoute = require('./routes/api/notes_move');
 | 
					const notesMoveApiRoute = require('./routes/api/notes_move');
 | 
				
			||||||
const auditApiRoute = require('./routes/api/audit');
 | 
					const statusApiRoute = require('./routes/api/status');
 | 
				
			||||||
const noteHistoryApiRoute = require('./routes/api/note_history');
 | 
					const noteHistoryApiRoute = require('./routes/api/note_history');
 | 
				
			||||||
const recentChangesApiRoute = require('./routes/api/recent_changes');
 | 
					const recentChangesApiRoute = require('./routes/api/recent_changes');
 | 
				
			||||||
const settingsApiRoute = require('./routes/api/settings');
 | 
					const settingsApiRoute = require('./routes/api/settings');
 | 
				
			||||||
@ -88,7 +88,7 @@ app.use('/migration', migrationRoute);
 | 
				
			|||||||
app.use('/api/tree', treeApiRoute);
 | 
					app.use('/api/tree', treeApiRoute);
 | 
				
			||||||
app.use('/api/notes', notesApiRoute);
 | 
					app.use('/api/notes', notesApiRoute);
 | 
				
			||||||
app.use('/api/notes', notesMoveApiRoute);
 | 
					app.use('/api/notes', notesMoveApiRoute);
 | 
				
			||||||
app.use('/api/audit', auditApiRoute);
 | 
					app.use('/api/status', statusApiRoute);
 | 
				
			||||||
app.use('/api/notes-history', noteHistoryApiRoute);
 | 
					app.use('/api/notes-history', noteHistoryApiRoute);
 | 
				
			||||||
app.use('/api/recent-changes', recentChangesApiRoute);
 | 
					app.use('/api/recent-changes', recentChangesApiRoute);
 | 
				
			||||||
app.use('/api/settings', settingsApiRoute);
 | 
					app.use('/api/settings', settingsApiRoute);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										27
									
								
								public/javascripts/status.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								public/javascripts/status.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					function checkStatus() {
 | 
				
			||||||
 | 
					    $.ajax({
 | 
				
			||||||
 | 
					        url: baseApiUrl + 'status/' + globalFullLoadTime,
 | 
				
			||||||
 | 
					        type: 'GET',
 | 
				
			||||||
 | 
					        success: resp => {
 | 
				
			||||||
 | 
					            if (resp.changed) {
 | 
				
			||||||
 | 
					                window.location.reload(true);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else {
 | 
				
			||||||
 | 
					                $("#changesToPushCount").html(resp.changesToPushCount);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        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);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					setInterval(checkStatus, 10 * 1000);
 | 
				
			||||||
@ -4,7 +4,7 @@ function syncNow() {
 | 
				
			|||||||
        type: 'POST',
 | 
					        type: 'POST',
 | 
				
			||||||
        success: result => {
 | 
					        success: result => {
 | 
				
			||||||
            if (result.success) {
 | 
					            if (result.success) {
 | 
				
			||||||
                checkAudit();
 | 
					                checkStatus();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                message("Sync finished successfully");
 | 
					                message("Sync finished successfully");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -88,31 +88,6 @@ let globalEncryptionSessionTimeout;
 | 
				
			|||||||
let globalEncryptedDataKey;
 | 
					let globalEncryptedDataKey;
 | 
				
			||||||
let globalFullLoadTime;
 | 
					let globalFullLoadTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function checkAudit() {
 | 
					 | 
				
			||||||
    $.ajax({
 | 
					 | 
				
			||||||
        url: baseApiUrl + 'audit/' + globalFullLoadTime,
 | 
					 | 
				
			||||||
        type: 'GET',
 | 
					 | 
				
			||||||
        success: resp => {
 | 
					 | 
				
			||||||
            if (resp.changed) {
 | 
					 | 
				
			||||||
                window.location.reload(true);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        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);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
setInterval(checkAudit, 10 * 1000);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
$(() => {
 | 
					$(() => {
 | 
				
			||||||
    $.get(baseApiUrl + 'tree').then(resp => {
 | 
					    $.get(baseApiUrl + 'tree').then(resp => {
 | 
				
			||||||
        const notes = resp.notes;
 | 
					        const notes = resp.notes;
 | 
				
			||||||
 | 
				
			|||||||
@ -10,11 +10,15 @@ router.get('/:full_load_time', auth.checkApiAuth, async (req, res, next) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const browserId = req.get('x-browser-id');
 | 
					    const browserId = req.get('x-browser-id');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const row = await sql.getSingleResult("SELECT COUNT(*) AS 'count' FROM audit_log WHERE (browser_id IS NULL OR browser_id != ?) " +
 | 
					    const rowCount = await sql.getSingleValue("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != ?) " +
 | 
				
			||||||
        "AND date_modified >= ?", [browserId, fullLoadTime]);
 | 
					        "AND date_modified >= ?", [browserId, fullLoadTime]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const lastSyncedPush = await sql.getOption('last_synced_push');
 | 
				
			||||||
 | 
					    const changesToPushCount = await sql.getSingleValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res.send({
 | 
					    res.send({
 | 
				
			||||||
        'changed': row.count > 0
 | 
					        'changed': rowCount > 0,
 | 
				
			||||||
 | 
					        'changesToPushCount': changesToPushCount
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -55,11 +55,11 @@ async function setOption(optName, optValue) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getSingleResult(query, params = []) {
 | 
					async function getSingleResult(query, params = []) {
 | 
				
			||||||
    return await db.get(query, ...params);
 | 
					    return await wrap(async () => db.get(query, ...params));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getSingleResultOrNull(query, params = []) {
 | 
					async function getSingleResultOrNull(query, params = []) {
 | 
				
			||||||
    const all = await db.all(query, ...params);
 | 
					    const all = await wrap(async () => db.all(query, ...params));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return all.length > 0 ? all[0] : null;
 | 
					    return all.length > 0 ? all[0] : null;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -75,7 +75,7 @@ async function getSingleValue(query, params = []) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getResults(query, params = []) {
 | 
					async function getResults(query, params = []) {
 | 
				
			||||||
    return await db.all(query, ...params);
 | 
					    return await wrap(async () => db.all(query, ...params));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getFlattenedResults(key, query, params = []) {
 | 
					async function getFlattenedResults(key, query, params = []) {
 | 
				
			||||||
@ -90,11 +90,11 @@ async function getFlattenedResults(key, query, params = []) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function execute(query, params = []) {
 | 
					async function execute(query, params = []) {
 | 
				
			||||||
    return await db.run(query, ...params);
 | 
					    return await wrap(async () => db.run(query, ...params));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function executeScript(query) {
 | 
					async function executeScript(query) {
 | 
				
			||||||
    return await db.exec(query);
 | 
					    return await wrap(async () => db.exec(query));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function remove(tableName, noteId) {
 | 
					async function remove(tableName, noteId) {
 | 
				
			||||||
@ -145,6 +145,19 @@ async function addEntitySync(entityName, entityId, sourceId) {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function wrap(func) {
 | 
				
			||||||
 | 
					    const error = new Error();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        return await func();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    catch (e) {
 | 
				
			||||||
 | 
					        log.error("Error executing transaction, executing rollback. Inner exception: " + e.stack + error.stack);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        throw e;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function doInTransaction(func) {
 | 
					async function doInTransaction(func) {
 | 
				
			||||||
    const error = new Error(); // to capture correct stack trace in case of exception
 | 
					    const error = new Error(); // to capture correct stack trace in case of exception
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -178,9 +178,9 @@ async function sync() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        const cookieJar = await login(syncLog);
 | 
					        const cookieJar = await login(syncLog);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await pushSync(cookieJar, syncLog);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        await pullSync(cookieJar, syncLog);
 | 
					        await pullSync(cookieJar, syncLog);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await pushSync(cookieJar, syncLog);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (e) {
 | 
					    catch (e) {
 | 
				
			||||||
        logSync("sync failed: " + e.stack, syncLog);
 | 
					        logSync("sync failed: " + e.stack, syncLog);
 | 
				
			||||||
 | 
				
			|||||||
@ -21,7 +21,7 @@
 | 
				
			|||||||
          <span id="top-message"></span>
 | 
					          <span id="top-message"></span>
 | 
				
			||||||
          <span id="error-message"></span>
 | 
					          <span id="error-message"></span>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          <button class="btn btn-xs" onclick="syncNow();">Sync now</button>
 | 
					          <button class="btn btn-xs" onclick="syncNow();">Sync now (<span id="changesToPushCount">0</span>)</button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          <button class="btn btn-xs" onclick="displaySettings();">Settings</button>
 | 
					          <button class="btn btn-xs" onclick="displaySettings();">Settings</button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -276,6 +276,7 @@
 | 
				
			|||||||
    <script src="javascripts/note_history.js"></script>
 | 
					    <script src="javascripts/note_history.js"></script>
 | 
				
			||||||
    <script src="javascripts/recent_changes.js"></script>
 | 
					    <script src="javascripts/recent_changes.js"></script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <script src="javascripts/status.js"></script>
 | 
				
			||||||
    <script src="javascripts/sync.js"></script>
 | 
					    <script src="javascripts/sync.js"></script>
 | 
				
			||||||
    <script src="javascripts/utils.js"></script>
 | 
					    <script src="javascripts/utils.js"></script>
 | 
				
			||||||
  </body>
 | 
					  </body>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user