sync update persistent notification

This commit is contained in:
zadam 2019-10-25 22:20:14 +02:00
parent edc23940d0
commit 22d48b0586
3 changed files with 30 additions and 5 deletions

View file

@ -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,

View file

@ -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

View file

@ -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
};