From f123c58c791225486fdc7a3dabee5533371e76c3 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 11 Nov 2013 17:12:09 +1100 Subject: [PATCH] Fixes up some more tree sync, streamlines naming conventions, adds more doc/comments to the code and specifies what is internal (only to be used by legacy code). syncTree method now takes an object to sync and both sets the active tree and the path at the same time and fixes setting the active tree to search the root node and children because content/media trees are single section trees. --- .../lib/umbraco/LegacyUmbClientMgr.js | 8 +-- .../src/common/services/navigation.service.js | 59 +++++++++++++------ .../views/content/content.copy.controller.js | 2 +- .../views/content/content.edit.controller.js | 9 +-- .../views/content/content.move.controller.js | 5 +- .../datatype/datatype.edit.controller.js | 9 ++- .../src/views/media/media.edit.controller.js | 7 ++- .../views/member/member.edit.controller.js | 3 +- 8 files changed, 63 insertions(+), 39 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js b/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js index aff778b84e..bfc7ddebac 100644 --- a/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js +++ b/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js @@ -90,12 +90,12 @@ Umbraco.Sys.registerNamespace("Umbraco.Application"); var tree = { setActiveTreeType: function (treeType) { angularHelper.safeApply($rootScope, function() { - navService.setActiveTreeType(treeType); + navService._setActiveTreeType(treeType); }); }, syncTree: function (path, forceReload) { angularHelper.safeApply($rootScope, function() { - navService.syncPath(path, forceReload); + navService._syncPath(path, forceReload); }); }, clearTreeCache: function(){ @@ -111,7 +111,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Application"); }, refreshTree: function (treeAlias) { angularHelper.safeApply($rootScope, function() { - navService.setActiveTreeType(treeAlias); + navService._setActiveTreeType(treeAlias, true); }); }, moveNode: function (id, path) { @@ -126,7 +126,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Application"); } } } - navService.syncPath(path, true); + navService._syncPath(path, true); }); }, getActionNode: function () { diff --git a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js index 3e1ec7b5df..2d459c7413 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js @@ -166,18 +166,17 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo * @methodOf umbraco.services.navigationService * * @description - * Shows the tree for a given tree alias but turning on the containing dom element + * Displays the tree for a given section alias but turning on the containing dom element * only changes if the section is different from the current one - * @param {string} sectionAlias The alias of the section the tree should load data from + * @param {string} sectionAlias The alias of the section to load + * @param {Object} syncArgs Optional object of arguments for syncing the tree for the section being shown */ - showTree: function(sectionAlias, treeAlias, path) { + showTree: function (sectionAlias, syncArgs) { if (sectionAlias !== this.ui.currentSection) { this.ui.currentSection = sectionAlias; - if (treeAlias) { - this.setActiveTreeType(treeAlias); - } - if (path) { - this.syncpath(path, true); + + if (syncArgs) { + this.syncTree(syncArgs); } } setMode("tree"); @@ -288,22 +287,44 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo }, /** * @ngdoc method - * @name umbraco.services.navigationService#syncPath + * @name umbraco.services.navigationService#syncTreePath * @methodOf umbraco.services.navigationService * * @description - * Syncs the tree with a given path + * Syncs a tree with a given path * The path format is: ["itemId","itemId"], and so on * so to sync to a specific document type node do: *
-         * navigationService.syncPath(["-1","123d"], true);  
+         * navigationService.syncTreePath({tree: 'content', path: ["-1","123d"], forceReload: true});  
          * 
- * @param {array} path array of ascendant ids, ex: ["1023","1243"] (loads a specific document type into the settings tree) - * @param {bool} forceReload forces a reload of data from the server + * @param {Object} args arguments passed to the function + * @param {String} args.tree the tree alias to sync to + * @param {Array} args.path the path to sync the tree to + * @param {Boolean} args.forceReload optional, specifies whether to force reload the node data from the server even if it already exists in the tree currently */ - syncPath: function(path, forceReload) { + syncTree: function (args) { + if (!args) { + throw "args cannot be null"; + } + if (!args.path) { + throw "args.path cannot be null"; + } + if (!args.tree) { + throw "args.tree cannot be null"; + } + if (this.ui.treeEventHandler) { - this.ui.treeEventHandler.syncPath(path, forceReload); + this.ui.treeEventHandler.syncTree(args); + } + }, + + /** + Internal method that should ONLY be used by the legacy API wrapper, the legacy API used to + have to set an active tree and then sync, the new API does this in one method by using syncTree + */ + _syncPath: function(path, forceReload) { + if (this.ui.treeEventHandler) { + this.ui.treeEventHandler.syncTree({ path: path, forceReload: forceReload }); } }, @@ -320,9 +341,13 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo } }, - setActiveTreeType: function(treeAlias) { + /** + Internal method that should ONLY be used by the legacy API wrapper, the legacy API used to + have to set an active tree and then sync, the new API does this in one method by using syncTreePath + */ + _setActiveTreeType: function (treeAlias, loadChildren) { if (this.ui.treeEventHandler) { - this.ui.treeEventHandler.setActiveTreeType(treeAlias); + this.ui.treeEventHandler._setActiveTreeType(treeAlias, loadChildren); } }, diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.copy.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.copy.controller.js index 7082cff032..3b4a2cdbed 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.copy.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.copy.controller.js @@ -36,7 +36,7 @@ angular.module("umbraco") $scope.error = false; $scope.success = true; - navigationService.syncPath(path, true); + navigationService.syncTree({ tree: "content", path: path, forceReload: true }); },function(err){ $scope.success = false; diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js index f3fdd6aab7..98af9e1d62 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js @@ -116,7 +116,7 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, cont configureButtons(data); - navigationService.syncPath(data.path.split(","), true); + navigationService.syncTree({ tree: "content", path: data.path.split(","), forceReload: true }); deferred.resolve(data); @@ -155,9 +155,6 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, cont $scope.loaded = true; $scope.content = data; configureButtons($scope.content); - - //just get the cached version, no need to force a reload - navigationService.syncPath(data.path.split(","), false); //in one particular special case, after we've created a new item we redirect back to the edit // route but there might be server validation errors in the collection which we need to display @@ -165,7 +162,7 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, cont // if there are any and then clear them so the collection no longer persists them. serverValidationManager.executeAndClearAllSubscriptions(); - + navigationService.syncTree({ tree: "content", path: data.path.split(","), forceReload: true }); }); } @@ -187,7 +184,7 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, cont configureButtons(data); - navigationService.syncPath(data.path.split(","), true); + navigationService.syncTree({ tree: "content", path: data.path.split(","), forceReload: true }); }); } diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.move.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.move.controller.js index e097578b48..7a44e6d580 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.move.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.move.controller.js @@ -41,8 +41,9 @@ angular.module("umbraco").controller("Umbraco.Editors.Content.MoveController", //reloads the parent navigationService.reloadNode(dialogOptions.currentNode.parent); - //reloads the target - navigationService.syncPath(path, true); + //reloads the target + navigationService.syncTree({ tree: "content", path: path, forceReload: true }); + },function(err){ $scope.success = false; $scope.error = err; diff --git a/src/Umbraco.Web.UI.Client/src/views/datatype/datatype.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/datatype/datatype.edit.controller.js index 69abf6ad33..99aa4a0ea4 100644 --- a/src/Umbraco.Web.UI.Client/src/views/datatype/datatype.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/datatype/datatype.edit.controller.js @@ -6,7 +6,7 @@ * @description * The controller for the content editor */ -function DataTypeEditController($scope, $routeParams, $location, navigationService, treeService, dataTypeResource, notificationsService, navigationService, angularHelper, serverValidationManager, contentEditingHelper, formHelper) { +function DataTypeEditController($scope, $routeParams, $location, navigationService, treeService, dataTypeResource, notificationsService, angularHelper, serverValidationManager, contentEditingHelper, formHelper) { $scope.nav = navigationService; //method used to configure the pre-values when we retreive them from the server @@ -57,9 +57,6 @@ function DataTypeEditController($scope, $routeParams, $location, navigationServi $scope.preValuesLoaded = true; $scope.content = data; - navigationService.setActiveTreeType("datatype"); - navigationService.syncPath([String(data.id)]); - createPreValueProps($scope.content.preValues); //in one particular special case, after we've created a new item we redirect back to the edit @@ -67,6 +64,8 @@ function DataTypeEditController($scope, $routeParams, $location, navigationServi // after the redirect, so we will bind all subscriptions which will show the server validation errors // if there are any and then clear them so the collection no longer persists them. serverValidationManager.executeAndClearAllSubscriptions(); + + navigationService.syncTree({ tree: "datatype", path: [String(data.id)], forceReload: true }); }); } @@ -115,7 +114,7 @@ function DataTypeEditController($scope, $routeParams, $location, navigationServi } }); - navigationService.syncPath([String(data.id)]); + navigationService.syncTree({ tree: "datatype", path: [String(data.id)], forceReload: true }); }, function(err) { diff --git a/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js index 01268d2e8e..49fdb99d3c 100644 --- a/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js @@ -29,7 +29,9 @@ function mediaEditController($scope, $routeParams, mediaResource, navigationServ // after the redirect, so we will bind all subscriptions which will show the server validation errors // if there are any and then clear them so the collection no longer persists them. serverValidationManager.executeAndClearAllSubscriptions(); - navigationService.syncPath(data.path, true); + + navigationService.syncTree({ tree: "media", path: data.path, forceReload: true }); + }); } @@ -61,7 +63,8 @@ function mediaEditController($scope, $routeParams, mediaResource, navigationServ rebindCallback: contentEditingHelper.reBindChangedProperties($scope.content, data) }); - navigationService.syncPath(data.path, true); + navigationService.syncTree({ tree: "media", path: data.path, forceReload: true }); + }, function(err) { contentEditingHelper.handleSaveError({ diff --git a/src/Umbraco.Web.UI.Client/src/views/member/member.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/member/member.edit.controller.js index 20f1abc007..7c39e3b017 100644 --- a/src/Umbraco.Web.UI.Client/src/views/member/member.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/member/member.edit.controller.js @@ -42,8 +42,7 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, memb var path = data.name[0]+"," + data.key; path = path.replace(/-/g,''); - navigationService.setActiveTreeType("member"); - navigationService.syncPath(path.split(","), true); + navigationService.syncTree({ tree: "member", path: path.split(","), forceReload: true }); //in one particular special case, after we've created a new item we redirect back to the edit // route but there might be server validation errors in the collection which we need to display