From fda327a60442da87ab7eed2a669d58bab5878101 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 21 Nov 2018 16:40:13 +1100 Subject: [PATCH] removes $routeParams from a dependency on content.resource, fixes event ordering during nav init, fixes tree re-syncing after sorting, removes some obsolete/old code --- .../src/common/resources/content.resource.js | 7 ++--- .../src/common/services/navigation.service.js | 5 ++-- .../src/controllers/navigation.controller.js | 30 ++++++++----------- .../views/content/content.sort.controller.js | 4 ++- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js index 3e70b76845..06ef8748a0 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js @@ -23,7 +23,7 @@ * **/ -function contentResource($q, $http, $routeParams, umbDataFormatter, umbRequestHelper) { +function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { /** internal method process the saving of data and post processing the result */ function saveContentItem(content, action, files, restApiUrl, showNotifications) { @@ -607,10 +607,7 @@ function contentResource($q, $http, $routeParams, umbDataFormatter, umbRequestHe else if (options.orderDirection === "desc") { options.orderDirection = "Descending"; } - if (!options.cultureName) { - // must send a culture to the content API to handle variant data correctly - options.cultureName = $routeParams.mculture; - } + //converts the value to a js bool function toBool(v) { if (angular.isNumber(v)) { 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 838d9670e2..0ecfa375d4 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 @@ -13,7 +13,7 @@ * Section navigation and search, and maintain their state for the entire application lifetime * */ -function navigationService($rootScope, $routeParams, $location, $q, $timeout, $injector, eventsService, umbModelMapper, treeService, appState) { +function navigationService($routeParams, $location, $q, $timeout, $injector, eventsService, umbModelMapper, treeService, appState) { //the promise that will be resolved when the navigation is ready var navReadyPromise = $q.defer(); @@ -311,7 +311,6 @@ function navigationService($rootScope, $routeParams, $location, $q, $timeout, $i * @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 - * @param {Boolean} args.activate optional, specifies whether to set the synced node to be the active node, this will default to true if not specified */ syncTree: function (args) { if (!args) { @@ -332,6 +331,8 @@ function navigationService($rootScope, $routeParams, $location, $q, $timeout, $i /** 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 + + TODO: Delete this if not required */ _syncPath: function(path, forceReload) { return navReadyPromise.promise.then(function () { diff --git a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js index 9e3448f3b3..8c521ca35e 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js @@ -113,16 +113,6 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar return treeInitPromise.promise; } - //TODO: Remove this, this is not healthy - // Put the navigation service on this scope so we can use it's methods/properties in the view. - // IMPORTANT: all properties assigned to this scope are generally available on the scope object on dialogs since - // when we create a dialog we pass in this scope to be used for the dialog's scope instead of creating a new one. - $scope.nav = navigationService; - // TODO: Remove this, this is not healthy - // it is less than ideal to be passing in the navigationController scope to something else to be used as it's scope, - // this is going to lead to problems/confusion. I really don't think passing scope's around is very good practice. - $rootScope.nav = navigationService; - //set up our scope vars $scope.showContextMenuDialog = false; $scope.showContextMenu = false; @@ -147,7 +137,8 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar navigationService.showSearch(); }); - $scope.selectedId = navigationService.currentId; + ////TODO: remove this it's not a thing + //$scope.selectedId = navigationService.currentId; var evts = []; @@ -180,7 +171,7 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar } })); - //Listen for section state changes + //Listen for tree state changes evts.push(eventsService.on("appState.treeState.changed", function (e, args) { if (args.key === "currentRootNode") { @@ -197,15 +188,18 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar //Listen for section state changes evts.push(eventsService.on("appState.sectionState.changed", function (e, args) { + //section changed if (args.key === "currentSection" && $scope.currentSection != args.value) { - $scope.currentSection = args.value; - - //load the tree - configureTreeAndLanguages(); - $scope.treeApi.load({ section: $scope.currentSection, customTreeParams: $scope.customTreeParams, cacheKey: $scope.treeCacheKey }); - + //before loading the main tree we need to ensure that the nav is ready + navigationService.waitForNavReady().then(() => { + $scope.currentSection = args.value; + //load the tree + configureTreeAndLanguages(); + $scope.treeApi.load({ section: $scope.currentSection, customTreeParams: $scope.customTreeParams, cacheKey: $scope.treeCacheKey }); + }); } + //show/hide search results if (args.key === "showSearchResults") { $scope.showSearchResults = args.value; diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.sort.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.sort.controller.js index d7f4cd9879..1e6bf28a75 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.sort.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.sort.controller.js @@ -48,7 +48,9 @@ contentResource.sort(args) .then(function(){ - navigationService.syncTree({ tree: "content", path: $scope.currentNode.path, forceReload: true, activate: false }); + navigationService.syncTree({ tree: "content", path: $scope.currentNode.path, forceReload: true }) + .then(() => navigationService.reloadNode($scope.currentNode)); + vm.saveButtonState = "success"; }, function(error) { vm.error = error;