Transition from item.setDirty to modelManager.setItemDirty

This commit is contained in:
Mo Bitar
2019-05-22 18:17:25 -05:00
parent 10022ba87b
commit af85d7c384
12 changed files with 36 additions and 40 deletions

View File

@@ -198,14 +198,14 @@ angular.module('app')
if(editor) { if(editor) {
if(this.note.getAppDataItem("prefersPlainEditor") == true) { if(this.note.getAppDataItem("prefersPlainEditor") == true) {
this.note.setAppDataItem("prefersPlainEditor", false); this.note.setAppDataItem("prefersPlainEditor", false);
this.note.setDirty(true); modelManager.setItemDirty(this.note, true);
} }
this.associateComponentWithCurrentNote(editor); this.associateComponentWithCurrentNote(editor);
} else { } else {
// Note prefers plain editor // Note prefers plain editor
if(!this.note.getAppDataItem("prefersPlainEditor")) { if(!this.note.getAppDataItem("prefersPlainEditor")) {
this.note.setAppDataItem("prefersPlainEditor", true); this.note.setAppDataItem("prefersPlainEditor", true);
this.note.setDirty(true); modelManager.setItemDirty(this.note, true);
} }
$timeout(() => { $timeout(() => {
this.reloadFont(); this.reloadFont();
@@ -249,7 +249,7 @@ angular.module('app')
this.saveNote = function(note, callback, updateClientModified, dontUpdatePreviews) { this.saveNote = function(note, callback, updateClientModified, dontUpdatePreviews) {
// We don't want to update the client modified date if toggling lock for note. // We don't want to update the client modified date if toggling lock for note.
note.setDirty(true, updateClientModified); modelManager.setItemDirty(note, true, updateClientModified);
if(!dontUpdatePreviews) { if(!dontUpdatePreviews) {
let limit = 80; let limit = 80;
@@ -688,20 +688,12 @@ angular.module('app')
if(data.item.content_type == "Tag") { if(data.item.content_type == "Tag") {
var tag = modelManager.findItem(data.item.uuid); var tag = modelManager.findItem(data.item.uuid);
this.addTag(tag); this.addTag(tag);
// Currently extensions are not notified of association until a full server sync completes.
// We need a better system for this, but for now, we'll manually notify observers
modelManager.notifySyncObserversOfModels([tag], SFModelManager.MappingSourceLocalSaved);
} }
} }
else if(action === "deassociate-item") { else if(action === "deassociate-item") {
var tag = modelManager.findItem(data.item.uuid); var tag = modelManager.findItem(data.item.uuid);
this.removeTag(tag); this.removeTag(tag);
// Currently extensions are not notified of association until a full server sync completes.
// We need a better system for this, but for now, we'll manually notify observers
modelManager.notifySyncObserversOfModels([tag], SFModelManager.MappingSourceLocalSaved);
} }
else if(action === "save-items" || action === "save-success" || action == "save-error") { else if(action === "save-items" || action === "save-success" || action == "save-error") {
@@ -785,7 +777,7 @@ angular.module('app')
component.disassociatedItemIds.push(this.note.uuid); component.disassociatedItemIds.push(this.note.uuid);
} }
component.setDirty(true); modelManager.setItemDirty(component, true);
syncManager.sync(); syncManager.sync();
} }
@@ -796,7 +788,7 @@ angular.module('app')
component.associatedItemIds.push(this.note.uuid); component.associatedItemIds.push(this.note.uuid);
} }
component.setDirty(true); modelManager.setItemDirty(component, true);
syncManager.sync(); syncManager.sync();
} }

View File

@@ -172,9 +172,10 @@ angular.module('app')
for(var tagToRemove of toRemove) { for(var tagToRemove of toRemove) {
tagToRemove.removeItemAsRelationship(note); tagToRemove.removeItemAsRelationship(note);
tagToRemove.setDirty(true);
} }
modelManager.setItemsDirty(toRemove, true);
var tags = []; var tags = [];
for(var tagString of stringTags) { for(var tagString of stringTags) {
var existingRelationship = _.find(note.tags, {title: tagString}); var existingRelationship = _.find(note.tags, {title: tagString});
@@ -185,9 +186,10 @@ angular.module('app')
for(var tag of tags) { for(var tag of tags) {
tag.addItemAsRelationship(note); tag.addItemAsRelationship(note);
tag.setDirty(true);
} }
modelManager.setItemsDirty(tags, true);
syncManager.sync(); syncManager.sync();
} }
@@ -219,7 +221,8 @@ angular.module('app')
$scope.removeTag(tag); $scope.removeTag(tag);
return; return;
} }
tag.setDirty(true);
modelManager.setItemDirty(tag, true);
syncManager.sync().then(callback); syncManager.sync().then(callback);
modelManager.resortTag(tag); modelManager.resortTag(tag);
} }
@@ -247,7 +250,7 @@ angular.module('app')
if(!$scope.selectedTag.isSmartTag()) { if(!$scope.selectedTag.isSmartTag()) {
$scope.selectedTag.addItemAsRelationship(note); $scope.selectedTag.addItemAsRelationship(note);
$scope.selectedTag.setDirty(true); modelManager.setItemDirty($scope.selectedTag, true);
} }
} }

View File

@@ -371,7 +371,7 @@ angular.module('app')
this.selectedNote = note; this.selectedNote = note;
if(note.content.conflict_of) { if(note.content.conflict_of) {
note.content.conflict_of = null; // clear conflict note.content.conflict_of = null; // clear conflict
note.setDirty(true); modelManager.setItemDirty(note, true);
syncManager.sync(); syncManager.sync();
} }
this.selectionMade()(note); this.selectionMade()(note);

View File

@@ -108,8 +108,8 @@ angular.module('app')
} }
this.selectedTag = tag; this.selectedTag = tag;
if(tag.content.conflict_of) { if(tag.content.conflict_of) {
tag.content.conflict_of = null; // clear conflict tag.content.conflict_of = null;
tag.setDirty(true); modelManager.setItemDirty(tag, true);
syncManager.sync(); syncManager.sync();
} }
this.selectionMade()(tag); this.selectionMade()(tag);

View File

@@ -10,7 +10,7 @@ class EditorMenu {
}; };
} }
controller($scope, componentManager, syncManager, $timeout) { controller($scope, componentManager, syncManager, modelManager, $timeout) {
'ngInject'; 'ngInject';
$scope.formData = {}; $scope.formData = {};
@@ -27,7 +27,7 @@ class EditorMenu {
if(component) { if(component) {
if(component.content.conflict_of) { if(component.content.conflict_of) {
component.content.conflict_of = null; // clear conflict if applicable component.content.conflict_of = null; // clear conflict if applicable
component.setDirty(true); modelManager.setItemDirty(component, true);
syncManager.sync(); syncManager.sync();
} }
} }
@@ -52,11 +52,11 @@ class EditorMenu {
var currentDefault = componentManager.componentsForArea("editor-editor").filter((e) => {return e.isDefaultEditor()})[0]; var currentDefault = componentManager.componentsForArea("editor-editor").filter((e) => {return e.isDefaultEditor()})[0];
if(currentDefault) { if(currentDefault) {
currentDefault.setAppDataItem("defaultEditor", false); currentDefault.setAppDataItem("defaultEditor", false);
currentDefault.setDirty(true); modelManager.setItemDirty(currentDefault, true);
} }
component.setAppDataItem("defaultEditor", true); component.setAppDataItem("defaultEditor", true);
component.setDirty(true); modelManager.setItemDirty(component, true);
syncManager.sync(); syncManager.sync();
$scope.defaultEditor = component; $scope.defaultEditor = component;
@@ -64,7 +64,7 @@ class EditorMenu {
$scope.removeEditorDefault = function(component) { $scope.removeEditorDefault = function(component) {
component.setAppDataItem("defaultEditor", false); component.setAppDataItem("defaultEditor", false);
component.setDirty(true); modelManager.setItemDirty(component, true);
syncManager.sync(); syncManager.sync();
$scope.defaultEditor = null; $scope.defaultEditor = null;

View File

@@ -78,7 +78,7 @@ class RevisionPreviewModal {
modelManager.mapResponseItemsToLocalModels([item], SFModelManager.MappingSourceRemoteActionRetrieved); modelManager.mapResponseItemsToLocalModels([item], SFModelManager.MappingSourceRemoteActionRetrieved);
} }
item.setDirty(true); modelManager.setItemDirty(item, true);
syncManager.sync(); syncManager.sync();
$scope.dismiss(); $scope.dismiss();

View File

@@ -76,12 +76,12 @@ class ActionsManager {
if(merge) { if(merge) {
var items = this.modelManager.mapResponseItemsToLocalModels([item], SFModelManager.MappingSourceRemoteActionRetrieved); var items = this.modelManager.mapResponseItemsToLocalModels([item], SFModelManager.MappingSourceRemoteActionRetrieved);
for(var mappedItem of items) { for(var mappedItem of items) {
mappedItem.setDirty(true); this.modelManager.setItemDirty(mappedItem, true);
} }
this.syncManager.sync(); this.syncManager.sync();
customCallback({item: item}); customCallback({item: item});
} else { } else {
item = this.modelManager.createItem(item, true /* Dont notify observers */); item = this.modelManager.createItem(item);
customCallback({item: item}); customCallback({item: item});
} }
return true; return true;

View File

@@ -145,7 +145,7 @@ class AuthManager extends SFAuthManager {
// Safe to create. Create and return object. // Safe to create. Create and return object.
var prefs = new SFItem({content_type: prefsContentType}); var prefs = new SFItem({content_type: prefsContentType});
this.modelManager.addItem(prefs); this.modelManager.addItem(prefs);
prefs.setDirty(true); this.modelManager.setItemDirty(prefs, true);
this.$rootScope.sync(); this.$rootScope.sync();
valueCallback(prefs); valueCallback(prefs);
}); });
@@ -157,7 +157,7 @@ class AuthManager extends SFAuthManager {
syncUserPreferences() { syncUserPreferences() {
if(this.userPreferences) { if(this.userPreferences) {
this.userPreferences.setDirty(true); this.modelManager.setItemDirty(this.userPreferences, true);
this.$rootScope.sync(); this.$rootScope.sync();
} }
} }

View File

@@ -112,7 +112,8 @@ class DesktopManager {
this.modelManager.notifySyncObserversOfModels([component], SFModelManager.MappingSourceDesktopInstalled); this.modelManager.notifySyncObserversOfModels([component], SFModelManager.MappingSourceDesktopInstalled);
component.setAppDataItem("installError", null); component.setAppDataItem("installError", null);
} }
component.setDirty(true);
this.modelManager.setItemDirty(component, true);
this.syncManager.sync(); this.syncManager.sync();
this.timeout(() => { this.timeout(() => {

View File

@@ -38,8 +38,8 @@ class MigrationManager extends SFMigrationManager {
} }
}) })
component.setAppDataItem("data", editor.data); component.setAppDataItem("data", editor.data);
component.setDirty(true);
this.modelManager.addItem(component); this.modelManager.addItem(component);
this.modelManager.setItemDirty(component, true);
} }
} }
@@ -76,7 +76,7 @@ class MigrationManager extends SFMigrationManager {
if(clientData) { if(clientData) {
note.setDomainDataItem(component.uuid, clientData, ComponentManager.ClientDataDomain); note.setDomainDataItem(component.uuid, clientData, ComponentManager.ClientDataDomain);
note.setDomainDataItem(component.hosted_url, null, ComponentManager.ClientDataDomain); note.setDomainDataItem(component.hosted_url, null, ComponentManager.ClientDataDomain);
note.setDirty(true); this.modelManager.setItemDirty(note, true);
hasChanges = true; hasChanges = true;
} }
} }
@@ -126,14 +126,14 @@ class MigrationManager extends SFMigrationManager {
let tag = this.modelManager.findItem(reference.uuid); let tag = this.modelManager.findItem(reference.uuid);
if(tag && !tag.hasRelationshipWithItem(note)) { if(tag && !tag.hasRelationshipWithItem(note)) {
tag.addItemAsRelationship(note); tag.addItemAsRelationship(note);
tag.setDirty(true); this.modelManager.setItemDirty(tag, true);
dirtyCount++; dirtyCount++;
} }
} }
if(newReferences.length != references.length) { if(newReferences.length != references.length) {
note.content.references = newReferences; note.content.references = newReferences;
note.setDirty(true); this.modelManager.setItemDirty(note, true);
dirtyCount++; dirtyCount++;
} }
} }

View File

@@ -49,8 +49,8 @@ class ModelManager extends SFModelManager {
var tag = _.find(this.tags, {title: title}) var tag = _.find(this.tags, {title: title})
if(!tag) { if(!tag) {
tag = this.createItem({content_type: "Tag", content: {title: title}}); tag = this.createItem({content_type: "Tag", content: {title: title}});
tag.setDirty(true);
this.addItem(tag); this.addItem(tag);
this.setItemDirty(tag, true);
} }
return tag; return tag;
} }

View File

@@ -49,7 +49,7 @@ class NativeExtManager {
} }
if(needsSync) { if(needsSync) {
resolvedSingleton.setDirty(true); this.modelManager.setItemDirty(resolvedSingleton, true);
this.syncManager.sync(); this.syncManager.sync();
} }
}, (valueCallback) => { }, (valueCallback) => {
@@ -93,7 +93,7 @@ class NativeExtManager {
var component = this.modelManager.createItem(item); var component = this.modelManager.createItem(item);
this.modelManager.addItem(component); this.modelManager.addItem(component);
component.setDirty(true); this.modelManager.setItemDirty(component, true);
this.syncManager.sync(); this.syncManager.sync();
this.systemExtensions.push(component.uuid); this.systemExtensions.push(component.uuid);
@@ -125,7 +125,7 @@ class NativeExtManager {
} }
if(needsSync) { if(needsSync) {
resolvedSingleton.setDirty(true); this.modelManager.setItemDirty(resolvedSingleton, true);
this.syncManager.sync(); this.syncManager.sync();
} }
}, (valueCallback) => { }, (valueCallback) => {
@@ -171,7 +171,7 @@ class NativeExtManager {
var component = this.modelManager.createItem(item); var component = this.modelManager.createItem(item);
this.modelManager.addItem(component); this.modelManager.addItem(component);
component.setDirty(true); this.modelManager.setItemDirty(component, true);
this.syncManager.sync(); this.syncManager.sync();
this.systemExtensions.push(component.uuid); this.systemExtensions.push(component.uuid);