From 4d2c61d07cfd4c5be6ae02f56cf3179babb61652 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Wed, 18 Apr 2018 17:10:43 -0500 Subject: [PATCH] Don't clear item as dirty if it was marked dirty after a sync began --- app/assets/javascripts/app/models/api/item.js | 10 ++++++++++ .../javascripts/app/services/syncManager.js | 16 +++++++++++++++- .../templates/directives/account-menu.html.haml | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/models/api/item.js b/app/assets/javascripts/app/models/api/item.js index 324628f21..e6b43a057 100644 --- a/app/assets/javascripts/app/models/api/item.js +++ b/app/assets/javascripts/app/models/api/item.js @@ -64,6 +64,16 @@ class Item { setDirty(dirty) { this.dirty = dirty; + // Allows the syncManager to check if an item has been marked dirty after a sync has been started + // This prevents it from clearing it as a dirty item after sync completion, if someone else has marked it dirty + // again after an ongoing sync. + if(!this.dirtyCount) { this.dirtyCount = 0; } + if(dirty) { + this.dirtyCount++; + } else { + this.dirtyCount = 0; + } + if(dirty) { this.notifyObserversOfChange(); } diff --git a/app/assets/javascripts/app/services/syncManager.js b/app/assets/javascripts/app/services/syncManager.js index 59f2c2d05..092092a09 100644 --- a/app/assets/javascripts/app/services/syncManager.js +++ b/app/assets/javascripts/app/services/syncManager.js @@ -270,6 +270,12 @@ class SyncManager { return itemParams.paramsForSync(); }.bind(this)); + for(var item of subItems) { + // Reset dirty counter to 0, since we're about to sync it. + // This means anyone marking the item as dirty after this will cause it so sync again and not be cleared on sync completion. + item.dirtyCount = 0; + } + params.sync_token = this.syncToken; params.cursor_token = this.cursorToken; @@ -278,7 +284,15 @@ class SyncManager { }.bind(this); var onSyncSuccess = function(response) { - this.modelManager.clearDirtyItems(subItems); + // Check to make sure any subItem hasn't been marked as dirty again while a sync was ongoing + var itemsToClearAsDirty = []; + for(var item of subItems) { + if(item.dirtyCount == 0) { + // Safe to clear as dirty + itemsToClearAsDirty.push(item); + } + } + this.modelManager.clearDirtyItems(itemsToClearAsDirty); this.syncStatus.error = null; this.$rootScope.$broadcast("sync:updated_token", this.syncToken); diff --git a/app/assets/templates/directives/account-menu.html.haml b/app/assets/templates/directives/account-menu.html.haml index 9ddb39cfc..2b188ce75 100644 --- a/app/assets/templates/directives/account-menu.html.haml +++ b/app/assets/templates/directives/account-menu.html.haml @@ -173,6 +173,8 @@ %input{"type" => "file", "style" => "display: none;", "file-change" => "->", "handler" => "importFileSelected(files)"} .label Import From Backup + %span{"ng-if" => "isDesktopApplication()"} Backups are automatically created on desktop and can be managed via the "Backups" top-level menu. + %div{"ng-if" => "importData.requestPassword"} %form.panel-form.stretch{"ng-submit" => "submitImportPassword()"} %p Enter the account password associated with the import file.