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(this.note.getAppDataItem("prefersPlainEditor") == true) {
this.note.setAppDataItem("prefersPlainEditor", false);
this.note.setDirty(true);
modelManager.setItemDirty(this.note, true);
}
this.associateComponentWithCurrentNote(editor);
} else {
// Note prefers plain editor
if(!this.note.getAppDataItem("prefersPlainEditor")) {
this.note.setAppDataItem("prefersPlainEditor", true);
this.note.setDirty(true);
modelManager.setItemDirty(this.note, true);
}
$timeout(() => {
this.reloadFont();
@@ -249,7 +249,7 @@ angular.module('app')
this.saveNote = function(note, callback, updateClientModified, dontUpdatePreviews) {
// 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) {
let limit = 80;
@@ -688,20 +688,12 @@ angular.module('app')
if(data.item.content_type == "Tag") {
var tag = modelManager.findItem(data.item.uuid);
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") {
var tag = modelManager.findItem(data.item.uuid);
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") {
@@ -785,7 +777,7 @@ angular.module('app')
component.disassociatedItemIds.push(this.note.uuid);
}
component.setDirty(true);
modelManager.setItemDirty(component, true);
syncManager.sync();
}
@@ -796,7 +788,7 @@ angular.module('app')
component.associatedItemIds.push(this.note.uuid);
}
component.setDirty(true);
modelManager.setItemDirty(component, true);
syncManager.sync();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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