Fixes alternateUUID callback, component stack association

This commit is contained in:
Mo Bitar
2018-01-20 18:31:29 -06:00
parent 1dbc394c4d
commit 85cdba7a9e
11 changed files with 75 additions and 64 deletions

View File

@@ -92,7 +92,7 @@ angular.module('app')
this.editorForNote = function(note) {
let editors = componentManager.componentsForArea("editor-editor");
for(var editor of editors) {
if(editor.isActiveForItem(note)) {
if(editor.isExplicitlyEnabledForItem(note)) {
return editor;
}
}
@@ -427,7 +427,7 @@ angular.module('app')
}
} else {
// Editor
if(component.active && this.note && (component.isActiveForItem(this.note) || component.isDefaultEditor())) {
if(component.active && this.note && (component.isExplicitlyEnabledForItem(this.note) || component.isDefaultEditor())) {
this.selectedEditor = component;
} else {
this.selectedEditor = null;
@@ -490,24 +490,23 @@ angular.module('app')
var stack = componentManager.componentsForArea("editor-stack");
for(var component of stack) {
var activeForItem = component.isActiveForItem(this.note);
if(activeForItem) {
if(!component.active) {
componentManager.activateComponent(component);
}
} else {
if(component.active) {
componentManager.deactivateComponent(component);
if(component.active) {
var disabledForItem = component.isExplicitlyDisabledForItem(this.note);
if(disabledForItem) {
component.hidden = true;
} else {
component.hidden = false;
}
}
}
}
this.toggleStackComponentForCurrentItem = function(component) {
if(component.isActiveForItem(this.note)) {
componentManager.deactivateComponent(component);
if(component.active) {
component.hidden = true;
this.disassociateComponentWithCurrentNote(component);
} else {
// Inactive
componentManager.activateComponent(component);
componentManager.contextItemDidChangeInArea("editor-stack");
this.associateComponentWithCurrentNote(component);
@@ -517,8 +516,7 @@ angular.module('app')
this.disassociateComponentWithCurrentNote = function(component) {
component.associatedItemIds = component.associatedItemIds.filter((id) => {return id !== this.note.uuid});
// Only disassociative components should modify the disassociatedItemIds
if(!component.isAssociative() && !component.disassociatedItemIds.includes(this.note.uuid)) {
if(!component.disassociatedItemIds.includes(this.note.uuid)) {
component.disassociatedItemIds.push(this.note.uuid);
}
@@ -528,7 +526,7 @@ angular.module('app')
this.associateComponentWithCurrentNote = function(component) {
component.disassociatedItemIds = component.disassociatedItemIds.filter((id) => {return id !== this.note.uuid});
if(component.isAssociative() && !component.associatedItemIds.includes(this.note.uuid)) {
if(!component.associatedItemIds.includes(this.note.uuid)) {
component.associatedItemIds.push(this.note.uuid);
}

View File

@@ -4,7 +4,8 @@ class ComponentView {
this.restrict = "E";
this.templateUrl = "directives/component-view.html";
this.scope = {
component: "="
component: "=",
manualDealloc: "="
};
this.componentManager = componentManager;
@@ -79,7 +80,7 @@ class ComponentView {
$scope.$on("$destroy", function() {
componentManager.deregisterHandler($scope.identifier);
if($scope.component) {
if($scope.component && !$scope.manualDealloc) {
componentManager.deactivateComponent($scope.component);
}
});

View File

@@ -113,11 +113,11 @@ class Component extends Item {
this.associatedItemIds.push(item.uuid);
}
isActiveForItem(item) {
if(this.isAssociative()) {
return this.associatedItemIds.indexOf(item.uuid) !== -1;
} else {
return this.disassociatedItemIds.indexOf(item.uuid) === -1;
}
isExplicitlyEnabledForItem(item) {
return this.associatedItemIds.indexOf(item.uuid) !== -1;
}
isExplicitlyDisabledForItem(item) {
return this.disassociatedItemIds.indexOf(item.uuid) !== -1;
}
}

View File

@@ -593,6 +593,13 @@ class ComponentManager {
}
sendMessageToComponent(component, message) {
if(component.hidden && message.action !== "component-registered") {
if(this.loggingEnabled) {
console.log("Component disabled for current item, not sending any messages.", component.name);
}
return;
}
if(this.loggingEnabled) {
console.log("Web|sendMessageToComponent", component, message);
}

View File

@@ -117,6 +117,8 @@ class ModelManager {
mapResponseItemsToLocalModelsOmittingFields(items, omitFields, source) {
var models = [], processedObjects = [], modelsToNotifyObserversOf = [];
// console.log("mapResponseItemsToLocalModelsOmittingFields");
// first loop should add and process items
for (var json_obj of items) {
if((!json_obj.content_type || !json_obj.content) && !json_obj.deleted && !json_obj.errorDecrypting) {

View File

@@ -109,6 +109,8 @@ class SingletonManager {
this.modelManager.setItemToBeDeleted(d);
}
console.log("Syncing from SM");
this.$rootScope.sync();
// Send remaining item to callback

View File

@@ -191,6 +191,8 @@ class SyncManager {
sync(callback, options = {}) {
console.log("Sync");
var allDirtyItems = this.modelManager.getDirtyItems();
if(this.syncStatus.syncOpInProgress) {
@@ -380,14 +382,13 @@ class SyncManager {
console.log("Handle unsaved", unsaved);
var i = 0;
var handleNext = function() {
var handleNext = () => {
if(i >= unsaved.length) {
// Handled all items
this.sync(null, {additionalFields: ["created_at", "updated_at"]});
return;
}
var handled = false;
var mapping = unsaved[i];
var itemResponse = mapping.item;
EncryptionHelper.decryptMultipleItems([itemResponse], this.authManager.keys());
@@ -403,8 +404,10 @@ class SyncManager {
if(error.tag === "uuid_conflict") {
// UUID conflicts can occur if a user attempts to
// import an old data archive with uuids from the old account into a new account
handled = true;
this.modelManager.alternateUUIDForItem(item, handleNext, true);
this.modelManager.alternateUUIDForItem(item, () => {
i++;
handleNext();
}, true);
}
else if(error.tag === "sync_conflict") {
@@ -419,15 +422,11 @@ class SyncManager {
dup.conflict_of = item.uuid;
dup.setDirty(true);
}
}
++i;
if(!handled) {
i++;
handleNext();
}
}.bind(this);
}
handleNext();
}