diff --git a/src/public/javascripts/services/ws.js b/src/public/javascripts/services/ws.js index df3c54679..9e0517e81 100644 --- a/src/public/javascripts/services/ws.js +++ b/src/public/javascripts/services/ws.js @@ -1,6 +1,5 @@ import utils from './utils.js'; import toastService from "./toast.js"; -import treeService from "./tree.js"; const $outstandingSyncsCount = $("#outstanding-syncs-count"); @@ -159,6 +158,21 @@ setTimeout(() => { }, 1000); }, 0); +subscribeToMessages(message => { + if (message.type === 'sync-pull-in-progress') { + toastService.showPersistent({ + id: 'sync', + title: "Sync status", + message: "Sync update in progress", + icon: "refresh" + }); + } + + if (message.type === 'sync-pull-finished') { + toastService.closePersistent('sync'); + } +}); + export default { logError, subscribeToMessages, diff --git a/src/services/sync.js b/src/services/sync.js index 02a98e293..0c9f4677c 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -138,6 +138,8 @@ async function pullSync(syncContext) { log.info("Pulled " + rows.length + " changes from " + changesUri + " in " + (Date.now() - startDate.getTime()) + "ms"); + ws.syncPullInProgress(); + for (const {sync, entity} of rows) { if (!sourceIdService.isLocalSourceId(sync.sourceId)) { await syncUpdateService.updateEntity(sync, entity, syncContext.sourceId); @@ -150,6 +152,8 @@ async function pullSync(syncContext) { await setLastSyncedPull(rows[rows.length - 1].sync.id); } + ws.syncPullFinished(); + log.info("Finished pull"); } @@ -167,9 +171,6 @@ async function pushSync(syncContext) { const filteredSyncs = syncs.filter(sync => { if (sync.sourceId === syncContext.sourceId) { - // too noisy - //log.info(`Skipping push #${sync.id} ${sync.entityName} ${sync.entityId} because it originates from sync target`); - // this may set lastSyncedPush beyond what's actually sent (because of size limit) // so this is applied to the database only if there's no actual update // TODO: it would be better to simplify this somehow diff --git a/src/services/ws.js b/src/services/ws.js index b6cd706ac..41089d23c 100644 --- a/src/services/ws.js +++ b/src/services/ws.js @@ -99,8 +99,18 @@ async function refreshTree() { await sendMessageToAllClients({ type: 'refresh-tree' }); } +async function syncPullInProgress() { + await sendMessageToAllClients({ type: 'sync-pull-in-progress' }); +} + +async function syncPullFinished() { + await sendMessageToAllClients({ type: 'sync-pull-finished' }); +} + module.exports = { init, sendMessageToAllClients, - refreshTree + refreshTree, + syncPullInProgress, + syncPullFinished }; \ No newline at end of file