Fixes more tree syncing - setActiveTreeType should *not* perform any tree loading, it should just set the active root tree node. syncTree is always used in conjunction with that call in the legacy API which means we get 2 tree queries loading at once and syncing ends up not working. We'll create a nicer method for our angular views to use to sync the tree, setActiveTreeType will typically only be used by the legacy umbraco wrapper.

This commit is contained in:
Shannon
2013-11-11 16:15:09 +11:00
parent 0be60a5c88
commit 9f613c04f3
3 changed files with 33 additions and 61 deletions

View File

@@ -127,7 +127,6 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat
//helper to load a specific path on the active tree as soon as its ready
function loadPath(path, forceReload) {
function _load(tree, path, forceReload) {
@@ -144,26 +143,23 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat
}
}
//expands the first child with a tree alias as soon as the tree has loaded
//given a tree alias, this will search the current section tree for the specified tree alias and
//set that to the activeTree
function loadActiveTree(treeAlias) {
scope.activeTree = undefined;
function _load(tree, alias) {
function _load(tree) {
scope.activeTree = _.find(tree.children, function(node) { return node.metaData.treeAlias === treeAlias; });
scope.activeTree.expanded = true;
scope.loadChildren(scope.activeTree, false).then(function() {
emitEvent("activeTreeLoaded", { tree: scope.activeTree });
});
emitEvent("activeTreeLoaded", { tree: scope.activeTree });
}
if (scope.tree) {
_load(scope.tree.root, treeAlias);
_load(scope.tree.root);
}
else {
scope.eventhandler.one("treeLoaded", function(e, args) {
_load(args.tree, treeAlias);
_load(args.tree);
});
}
}
@@ -199,12 +195,13 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat
}
}
function syncTree(node, path, forceReload) {
/** syncs the tree, the treeNode can be ANY tree node in the tree that requires syncing */
function syncTree(treeNode, path, forceReload) {
deleteAnimations = false;
treeService.syncTree({
node: node,
node: treeNode,
path: path,
forceReload: forceReload
}).then(function (data) {

View File

@@ -103,7 +103,7 @@ angular.module("umbraco.directives")
}
else {
return {};
}
}
};
/**

View File

@@ -419,9 +419,6 @@ function treeService($q, treeResource, iconHelper, notificationsService, $rootSc
if (!args.path) {
throw "No path defined on args object for syncTree";
}
//if (!current.metaData["treeAlias"] && !args.node.section) {
// throw "No section defined on args.node object for syncTree";
//}
if (!angular.isArray(args.path)) {
throw "Path must be an array";
}
@@ -458,53 +455,31 @@ function treeService($q, treeResource, iconHelper, notificationsService, $rootSc
var self = this;
var node = args.node;
var doSync = function() {
if (node.children) {
//children are loaded, check for the existence
var child = self.getChildNode(node, args.path[currPathIndex]);
if (child) {
if (args.path.length === (currPathIndex + 1)) {
//woot! synced the node
if (!args.forceReload) {
deferred.resolve(child);
}
else {
//even though we've found the node if forceReload is specified
//we want to go update this single node from the server
self.reloadNode(child).then(function (reloaded) {
deferred.resolve(reloaded);
}, function() {
deferred.reject();
});
}
var doSync = function() {
//check if it exists in the already loaded children
var child = self.getChildNode(node, args.path[currPathIndex]);
if (child) {
if (args.path.length === (currPathIndex + 1)) {
//woot! synced the node
if (!args.forceReload) {
deferred.resolve(child);
}
else {
//now we need to recurse with the updated node/currPathIndex
currPathIndex++;
node = child;
//recurse
doSync();
//even though we've found the node if forceReload is specified
//we want to go update this single node from the server
self.reloadNode(child).then(function(reloaded) {
deferred.resolve(reloaded);
}, function() {
deferred.reject();
});
}
}
else {
//we couldn't find the child, if forceReload is true, we can go re-fetch the child collection and try again
if (args.forceReload) {
self.loadNodeChildren({ node: node, section: node.section }).then(function () {
//now we'll check again
child = self.getChildNode(node, args.path[currPathIndex]);
if (child) {
deferred.resolve(child);
}
else {
//fail!
deferred.reject();
}
});
}
else {
//fail!
deferred.reject();
}
//now we need to recurse with the updated node/currPathIndex
currPathIndex++;
node = child;
//recurse
doSync();
}
}
else {
@@ -529,11 +504,11 @@ function treeService($q, treeResource, iconHelper, notificationsService, $rootSc
//fail!
deferred.reject();
}
}, function() {
}, function () {
//fail!
deferred.reject();
});
}
}
};
//start