JS tweaks needed to deal with a collection of SectionRootNodes returning from the API
This commit is contained in:
@@ -15,21 +15,21 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
// a tab and have the trees where they used to be - supposed that is kind of nice but would mean we'd have to store the parent
|
||||
// as a nodeid reference instead of a variable with a getParent() method.
|
||||
var treeCache = {};
|
||||
|
||||
|
||||
var standardCssClass = 'icon umb-tree-icon sprTree';
|
||||
|
||||
function getCacheKey(args) {
|
||||
//if there is no cache key they return null - it won't be cached.
|
||||
if (!args || !args.cacheKey) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
var cacheKey = args.cacheKey;
|
||||
cacheKey += "_" + args.section;
|
||||
return cacheKey;
|
||||
}
|
||||
|
||||
return {
|
||||
return {
|
||||
|
||||
/** Internal method to return the tree cache */
|
||||
_getTreeCache: function() {
|
||||
@@ -70,10 +70,10 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/** Internal method that ensures there's a routePath, parent and level property on each tree node and adds some icon specific properties so that the nodes display properly */
|
||||
_formatNodeDataForUseInUI: function (parentNode, treeNodes, section, level) {
|
||||
//if no level is set, then we make it 1
|
||||
//if no level is set, then we make it 1
|
||||
var childLevel = (level ? level : 1);
|
||||
//set the section if it's not already set
|
||||
if (!parentNode.section) {
|
||||
@@ -91,13 +91,14 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
var funcParent = function() {
|
||||
return parentNode;
|
||||
};
|
||||
|
||||
for (var i = 0; i < treeNodes.length; i++) {
|
||||
|
||||
var treeNode = treeNodes[i];
|
||||
|
||||
treeNode.level = childLevel;
|
||||
|
||||
//create a function to get the parent node, we could assign the parent node but
|
||||
//create a function to get the parent node, we could assign the parent node but
|
||||
// then we cannot serialize this entity because we have a cyclical reference.
|
||||
// Instead we just make a function to return the parentNode.
|
||||
treeNode.parent = funcParent;
|
||||
@@ -108,17 +109,17 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
//if there is not route path specified, then set it automatically,
|
||||
//if this is a tree root node then we want to route to the section's dashboard
|
||||
if (!treeNode.routePath) {
|
||||
|
||||
|
||||
if (treeNode.metaData && treeNode.metaData["treeAlias"]) {
|
||||
//this is a root node
|
||||
treeNode.routePath = section;
|
||||
treeNode.routePath = section;
|
||||
}
|
||||
else {
|
||||
var treeAlias = this.getTreeAlias(treeNode);
|
||||
treeNode.routePath = section + "/" + treeAlias + "/edit/" + treeNode.id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//now, format the icon data
|
||||
if (treeNode.iconIsClass === undefined || treeNode.iconIsClass) {
|
||||
var converted = iconHelper.convertFromLegacyTreeNodeIcon(treeNode);
|
||||
@@ -155,10 +156,10 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
* @description
|
||||
* Determines if the current tree is a plugin tree and if so returns the package folder it has declared
|
||||
* so we know where to find it's views, otherwise it will just return undefined.
|
||||
*
|
||||
*
|
||||
* @param {String} treeAlias The tree alias to check
|
||||
*/
|
||||
getTreePackageFolder: function(treeAlias) {
|
||||
getTreePackageFolder: function(treeAlias) {
|
||||
//we determine this based on the server variables
|
||||
if (Umbraco.Sys.ServerVariables.umbracoPlugins &&
|
||||
Umbraco.Sys.ServerVariables.umbracoPlugins.trees &&
|
||||
@@ -167,7 +168,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
var found = _.find(Umbraco.Sys.ServerVariables.umbracoPlugins.trees, function(item) {
|
||||
return item.alias === treeAlias;
|
||||
});
|
||||
|
||||
|
||||
return found ? found.packageFolder : undefined;
|
||||
}
|
||||
return undefined;
|
||||
@@ -181,7 +182,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
*
|
||||
* @description
|
||||
* Clears the tree cache - with optional cacheKey, optional section or optional filter.
|
||||
*
|
||||
*
|
||||
* @param {Object} args arguments
|
||||
* @param {String} args.cacheKey optional cachekey - this is used to clear specific trees in dialogs
|
||||
* @param {String} args.section optional section alias - clear tree for a given section
|
||||
@@ -205,7 +206,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
if (!args.cacheKey) {
|
||||
throw "args.cacheKey is required if args.childrenOf is supplied";
|
||||
}
|
||||
//this will clear out all children for the parentId passed in to this parameter, we'll
|
||||
//this will clear out all children for the parentId passed in to this parameter, we'll
|
||||
// do this by recursing and specifying a filter
|
||||
var self = this;
|
||||
this.clearCache({
|
||||
@@ -238,7 +239,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
//set the result to the filtered data
|
||||
treeCache[args.cacheKey] = result;
|
||||
}
|
||||
else {
|
||||
else {
|
||||
//remove the cache
|
||||
treeCache = _.omit(treeCache, args.cacheKey);
|
||||
}
|
||||
@@ -261,7 +262,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
return k.endsWith("_" + args.section);
|
||||
});
|
||||
treeCache = _.omit(treeCache, toRemove2);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -285,7 +286,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
if (!args.node) {
|
||||
throw "No node defined on args object for loadNodeChildren";
|
||||
}
|
||||
|
||||
|
||||
this.removeChildNodes(args.node);
|
||||
args.node.loading = true;
|
||||
|
||||
@@ -312,7 +313,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
//in case of error, emit event
|
||||
eventsService.emit("treeService.treeNodeLoadError", {error: reason } );
|
||||
|
||||
//stop show the loading indicator
|
||||
//stop show the loading indicator
|
||||
args.node.loading = false;
|
||||
|
||||
//tell notications about the error
|
||||
@@ -342,9 +343,9 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
throw "Cannot remove a node that doesn't have a parent";
|
||||
}
|
||||
//remove the current item from it's siblings
|
||||
treeNode.parent().children.splice(treeNode.parent().children.indexOf(treeNode), 1);
|
||||
treeNode.parent().children.splice(treeNode.parent().children.indexOf(treeNode), 1);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.services.treeService#removeChildNodes
|
||||
@@ -352,7 +353,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Removes all child nodes from a given tree node
|
||||
* Removes all child nodes from a given tree node
|
||||
* @param {object} treeNode the node to remove children from
|
||||
*/
|
||||
removeChildNodes : function(treeNode) {
|
||||
@@ -426,7 +427,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
//check each child of this node
|
||||
if (!treeNode.children) {
|
||||
return null;
|
||||
@@ -442,7 +443,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//not found
|
||||
return found === undefined ? null : found;
|
||||
},
|
||||
@@ -464,9 +465,9 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
|
||||
//all root nodes have metadata key 'treeAlias'
|
||||
var root = null;
|
||||
var current = treeNode;
|
||||
var current = treeNode;
|
||||
while (root === null && current) {
|
||||
|
||||
|
||||
if (current.metaData && current.metaData["treeAlias"]) {
|
||||
root = current;
|
||||
}
|
||||
@@ -491,7 +492,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Gets the node's tree alias, this is done by looking up the meta-data of the current node's root node
|
||||
* Gets the node's tree alias, this is done by looking up the meta-data of the current node's root node
|
||||
* @param {object} treeNode to retrive tree alias from
|
||||
*/
|
||||
getTreeAlias : function(treeNode) {
|
||||
@@ -509,7 +510,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* gets the tree, returns a promise
|
||||
* gets the tree, returns a promise
|
||||
* @param {object} args Arguments
|
||||
* @param {string} args.section Section alias
|
||||
* @param {string} args.cacheKey Optional cachekey
|
||||
@@ -525,7 +526,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
}
|
||||
|
||||
var cacheKey = getCacheKey(args);
|
||||
|
||||
|
||||
//return the cache if it exists
|
||||
if (cacheKey && treeCache[cacheKey] !== undefined) {
|
||||
return $q.when(treeCache[cacheKey]);
|
||||
@@ -540,8 +541,13 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
alias: args.section,
|
||||
root: data
|
||||
};
|
||||
//we need to format/modify some of the node data to be used in our app.
|
||||
self._formatNodeDataForUseInUI(result.root, result.root.children, args.section);
|
||||
|
||||
for (var i = 0; i < result.root.length; i++) {
|
||||
var group = result.root[i];
|
||||
|
||||
//we need to format/modify some of the node data to be used in our app.
|
||||
self._formatNodeDataForUseInUI(group, group.children, args.section);
|
||||
}
|
||||
|
||||
//cache this result if a cache key is specified - generally a cache key should ONLY
|
||||
// be specified for application trees, dialog trees should not be cached.
|
||||
@@ -584,7 +590,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
return data;
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.services.treeService#getChildren
|
||||
@@ -592,7 +598,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Gets the children from the server for a given node
|
||||
* Gets the children from the server for a given node
|
||||
* @param {object} args Arguments
|
||||
* @param {object} args.node tree node object to retrieve the children for
|
||||
* @param {string} args.section current section alias
|
||||
@@ -618,7 +624,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
return $q.when(data);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.services.treeService#reloadNode
|
||||
@@ -639,7 +645,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
if (!node.section) {
|
||||
throw "cannot reload a single node without an assigned node.section";
|
||||
}
|
||||
|
||||
|
||||
//set the node to loading
|
||||
node.loading = true;
|
||||
|
||||
@@ -663,7 +669,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
//just update as per normal - this means styles, etc.. won't be applied
|
||||
_.extend(node.parent().children[index], found);
|
||||
}
|
||||
|
||||
|
||||
//set the node loading
|
||||
node.parent().children[index].loading = false;
|
||||
//return
|
||||
@@ -684,12 +690,12 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* This will return the current node's path by walking up the tree
|
||||
* This will return the current node's path by walking up the tree
|
||||
* @param {object} node Tree node to retrieve path for
|
||||
*/
|
||||
getPath: function(node) {
|
||||
if (!node) {
|
||||
throw "node cannot be null";
|
||||
throw "node cannot be null";
|
||||
}
|
||||
if (!angular.isFunction(node.parent)) {
|
||||
throw "node.parent is not a function, the path cannot be resolved";
|
||||
@@ -698,7 +704,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
var reversePath = [];
|
||||
var current = node;
|
||||
while (current != null) {
|
||||
reversePath.push(current.id);
|
||||
reversePath.push(current.id);
|
||||
if (current.metaData && current.metaData["treeAlias"]) {
|
||||
current = null;
|
||||
}
|
||||
@@ -710,7 +716,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
},
|
||||
|
||||
syncTree: function(args) {
|
||||
|
||||
|
||||
if (!args) {
|
||||
throw "No args object defined for syncTree";
|
||||
}
|
||||
@@ -733,7 +739,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
if (!root) {
|
||||
throw "Could not get the root tree node based on the node passed in";
|
||||
}
|
||||
|
||||
|
||||
//now we want to loop through the ids in the path, first we'll check if the first part
|
||||
//of the path is the root node, otherwise we'll search it's children.
|
||||
var currPathIndex = 0;
|
||||
@@ -748,7 +754,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
currPathIndex = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//now that we have the first id to lookup, we can start the process
|
||||
|
||||
var self = this;
|
||||
@@ -778,7 +784,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
}
|
||||
}
|
||||
else {
|
||||
//couldn't find it in the
|
||||
//couldn't find it in the
|
||||
return self.loadNodeChildren({ node: node, section: node.section }).then(function (children) {
|
||||
//ok, got the children, let's find it
|
||||
var found = self.getChildNode(node, args.path[currPathIndex]);
|
||||
@@ -810,7 +816,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, eventsS
|
||||
return doSync();
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -184,9 +184,15 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
|
||||
|
||||
//Listen for section state changes
|
||||
evts.push(eventsService.on("appState.treeState.changed", function (e, args) {
|
||||
var f = args;
|
||||
if (args.value.root && args.value.root.metaData.containsTrees === false) {
|
||||
$rootScope.emptySection = true;
|
||||
if (args.value.root.length > 0)
|
||||
{
|
||||
for (var i = 0; i < args.value.root.length; i++) {
|
||||
var group = args.value.root[i];
|
||||
|
||||
if(group.metaData.containsTrees === false){
|
||||
$rootScope.emptySection = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$rootScope.emptySection = false;
|
||||
@@ -422,7 +428,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
|
||||
|
||||
//this reacts to the options item in the tree
|
||||
//TODO: migrate to nav service
|
||||
//TODO: is this used?
|
||||
//TODO: is this used?
|
||||
$scope.searchShowMenu = function (ev, args) {
|
||||
//always skip default
|
||||
args.skipDefault = true;
|
||||
|
||||
Reference in New Issue
Block a user