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.
This commit is contained in:
mcl-sz
2021-02-21 17:22:28 +01:00
committed by GitHub
parent d85b6694fe
commit 6eb260001d

View File

@@ -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);
}
});