From b55fdd60e5397f3b9d95160d78d2a34a85ba2a7f Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Sun, 24 May 2020 22:08:58 +0200 Subject: [PATCH] Update listviews after sorting children --- .../src/views/content/content.sort.controller.js | 3 ++- .../src/views/media/media.sort.controller.js | 3 ++- .../listview/listview.controller.js | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) 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 bd501a5b07..f3113f5c8f 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 @@ -1,7 +1,7 @@ (function () { "use strict"; - function ContentSortController($scope, $filter, $routeParams, contentResource, navigationService) { + function ContentSortController($scope, $filter, $routeParams, contentResource, navigationService, eventsService) { var vm = this; var id = $scope.currentNode.id; @@ -50,6 +50,7 @@ navigationService.syncTree({ tree: "content", path: $scope.currentNode.path, forceReload: true }) .then(() => navigationService.reloadNode($scope.currentNode)); + eventsService.emit("sortCompleted", { id: id }); vm.saveButtonState = "success"; }, function(error) { vm.error = error; diff --git a/src/Umbraco.Web.UI.Client/src/views/media/media.sort.controller.js b/src/Umbraco.Web.UI.Client/src/views/media/media.sort.controller.js index 4ad1fc8aab..95aeb239b9 100644 --- a/src/Umbraco.Web.UI.Client/src/views/media/media.sort.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/media/media.sort.controller.js @@ -1,7 +1,7 @@ (function () { "use strict"; - function MediaSortController($scope, $filter, mediaResource, navigationService) { + function MediaSortController($scope, $filter, mediaResource, navigationService, eventsService) { var vm = this; var id = $scope.currentNode.id; @@ -50,6 +50,7 @@ navigationService.syncTree({ tree: "media", path: $scope.currentNode.path, forceReload: true }) .then(() => navigationService.reloadNode($scope.currentNode)); + eventsService.emit("sortCompleted", { id: id }); vm.saveButtonState = "success"; }, function(error) { vm.error = error; diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/listview/listview.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/listview/listview.controller.js index 16c1be98a0..9a86dc575a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/listview/listview.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/listview/listview.controller.js @@ -1,4 +1,4 @@ -function listViewController($scope, $interpolate, $routeParams, $injector, $timeout, currentUserResource, notificationsService, iconHelper, editorState, localizationService, appState, $location, listViewHelper, navigationService, editorService, overlayService, languageResource, mediaHelper) { +function listViewController($scope, $interpolate, $routeParams, $injector, $timeout, currentUserResource, notificationsService, iconHelper, editorState, localizationService, appState, $location, listViewHelper, navigationService, editorService, overlayService, languageResource, mediaHelper, eventsService) { //this is a quick check to see if we're in create mode, if so just exit - we cannot show children for content // that isn't created yet, if we continue this will use the parent id in the route params which isn't what @@ -838,6 +838,19 @@ function listViewController($scope, $interpolate, $routeParams, $injector, $time $scope.toggleDropdown = toggleDropdown; $scope.leaveDropdown = leaveDropdown; + // if this listview has sort order in it, make sure it is updated when sorting is performed on the current content + if (_.find($scope.options.includeProperties, property => property.alias === "sortOrder")) { + var eventSubscription = eventsService.on("sortCompleted", function (e, args) { + if (parseInt(args.id) === parseInt($scope.contentId)) { + $scope.reloadView($scope.contentId); + } + }); + + $scope.$on('$destroy', function () { + eventsService.unsubscribe(eventSubscription); + }); + } + //GO! initView(); }