From 6eb260001d3d4045f4c29ef6e26d85d27c1e4ce8 Mon Sep 17 00:00:00 2001 From: mcl-sz Date: Sun, 21 Feb 2021 17:22:28 +0100 Subject: [PATCH] Ensure that upload file(s) in the MediaPicker is returned (#9367) The onUploadComplete function returns the last files that are added to a mediafolder. While this works correct by default and in most situations, it doesn't work as expected when a diffrent sorting is used for Media-items. For example, we've added events to sort Media-items automatically by name alphabetically when they are created/uploaded to keep them better organised. By sorting the $scope.files array by the Id-property, it ensures that the function returns the uploaded files, instead of the last files in the folder. --- .../infiniteeditors/mediapicker/mediapicker.controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/mediapicker/mediapicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/mediapicker/mediapicker.controller.js index 6f9ce6ee34..fec2e632c5 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/mediapicker/mediapicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/mediapicker/mediapicker.controller.js @@ -327,10 +327,10 @@ angular.module("umbraco") gotoFolder($scope.currentFolder).then(function () { $timeout(function () { if ($scope.multiPicker) { - var images = _.rest($scope.images, $scope.images.length - files.length); + var images = _.rest(_.sortBy($scope.images, 'id'), $scope.images.length - files.length); images.forEach(image => selectMedia(image)); } else { - var image = $scope.images[$scope.images.length - 1]; + var image = _.sortBy($scope.images, 'id')[$scope.images.length - 1]; clickHandler(image); } });