diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs index b7b4ddd583..e56f06e0e0 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs @@ -118,7 +118,7 @@ namespace Umbraco.Core.Persistence.Repositories if (objectTypes.Any()) { - sql = sql.Where("umbracoNode.nodeObjectType IN (@objectTypes)", objectTypes); + sql = sql.Where("umbracoNode.nodeObjectType IN (@objectTypes)", new {objectTypes = objectTypes}); } return Database.Fetch(sql); diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/media.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/media.resource.js index 4b56e55801..c0aee7280d 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/media.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/media.resource.js @@ -438,7 +438,7 @@ function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) { * * @param {int} parentId Id of the media item to query for child folders * @returns {Promise} resourcePromise object. - * + * @deprecated This method is no longer used and shouldn't be because it performs poorly when there are a lot of media items */ getChildFolders: function (parentId) { if (!parentId) { diff --git a/src/Umbraco.Web.UI.Client/src/common/services/mediatypehelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/mediatypehelper.service.js index 20e5e3799b..b06a5ca8e3 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/mediatypehelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/mediatypehelper.service.js @@ -7,6 +7,19 @@ function mediaTypeHelper(mediaTypeResource, $q) { var mediaTypeHelperService = { + isFolderType: function(mediaEntity) { + if (!mediaEntity) { + throw "mediaEntity is null"; + } + if (!mediaEntity.contentTypeAlias) { + throw "mediaEntity.contentTypeAlias is null"; + } + + //if you create a media type, which has an alias that ends with ...Folder then its a folder: ex: "secureFolder", "bannerFolder", "Folder" + //this is the exact same logic that is performed in MediaController.GetChildFolders + return mediaEntity.contentTypeAlias.endsWith("Folder"); + }, + getAllowedImagetypes: function (mediaId){ // Get All allowedTypes 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 0a1a14fc44..40ab5ce35f 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($rootScope, $scope, $routeParams, $injector, $cookieStore, notificationsService, iconHelper, dialogService, editorState, localizationService, $location, appState, $timeout, $q, mediaResource, listViewHelper, userService, navigationService, treeService) { +function listViewController($rootScope, $scope, $routeParams, $injector, $cookieStore, mediaTypeHelper, notificationsService, iconHelper, dialogService, editorState, localizationService, $location, appState, $timeout, $q, mediaResource, listViewHelper, userService, navigationService, treeService) { //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 @@ -261,24 +261,25 @@ function listViewController($rootScope, $scope, $routeParams, $injector, $cookie $scope.actionInProgress = false; $scope.listViewResultSet = data; - //update all values for display + //reset + $scope.folders = []; + + //update all values for display if ($scope.listViewResultSet.items) { _.each($scope.listViewResultSet.items, function (e, index) { - setPropertyValues(e); + setPropertyValues(e); + + //special case, we need to check if any of these types are folder types + //and add them to the folders collection + if ($scope.entityType === 'media') { + if (mediaTypeHelper.isFolderType(e)) { + $scope.folders.push(e); + } + } }); } - if ($scope.entityType === 'media') { - - mediaResource.getChildFolders($scope.contentId) - .then(function (folders) { - $scope.folders = folders; - $scope.viewLoaded = true; - }); - - } else { - $scope.viewLoaded = true; - } + $scope.viewLoaded = true; //NOTE: This might occur if we are requesting a higher page number than what is actually available, for example // if you have more than one page and you delete all items on the last page. In this case, we need to reset to the last diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs index 77ab9ff6e5..d00a26333e 100644 --- a/src/Umbraco.Web/Editors/MediaController.cs +++ b/src/Umbraco.Web/Editors/MediaController.cs @@ -160,19 +160,25 @@ namespace Umbraco.Web.Editors } /// - /// Returns media items known to be a container of other media items + /// Returns media items known to be of a "Folder" type /// /// /// + [Obsolete("This is no longer used and shouldn't be because it performs poorly when there are a lot of media items")] [FilterAllowedOutgoingMedia(typeof(IEnumerable>))] public IEnumerable> GetChildFolders(int id = -1) { //Suggested convention for folder mediatypes - we can make this more or less complicated as long as we document it... //if you create a media type, which has an alias that ends with ...Folder then its a folder: ex: "secureFolder", "bannerFolder", "Folder" - var folderTypes = Services.ContentTypeService.GetAllMediaTypes().ToArray().Where(x => x.Alias.EndsWith("Folder")).Select(x => x.Id); + var folderTypes = Services.ContentTypeService + .GetAllContentTypeAliases(Constants.ObjectTypes.MediaTypeGuid) + .Where(x => x.EndsWith("Folder")); + + var children = (id < 0) + ? Services.MediaService.GetRootMedia() + : Services.MediaService.GetChildren(id); - var children = (id < 0) ? Services.MediaService.GetRootMedia() : Services.MediaService.GetById(id).Children(); - return children.Where(x => folderTypes.Contains(x.ContentTypeId)).Select(Mapper.Map>); + return children.Where(x => folderTypes.Contains(x.ContentType.Alias)).Select(Mapper.Map>); } ///