Fixes: U4-2941 Sort dialog YSODs on root node and updates media GetChildren to be the same as content with options/sorting/filtering.

This commit is contained in:
Shannon
2013-09-26 16:26:05 +10:00
parent 18c1ec8ae7
commit 4212199226
6 changed files with 123 additions and 31 deletions

View File

@@ -211,15 +211,71 @@ function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) {
},
getChildren: function (parentId) {
/**
* @ngdoc method
* @name umbraco.resources.mediaResource#getChildren
* @methodOf umbraco.resources.mediaResource
*
* @description
* Gets children of a media item with a given id
*
* ##usage
* <pre>
* mediaResource.getChildren(1234, {pageSize: 10, pageNumber: 2})
* .then(function(contentArray) {
* var children = contentArray;
* alert('they are here!');
* });
* </pre>
*
* @param {Int} parentid id of content item to return children of
* @param {Object} options optional options object
* @param {Int} options.pageSize if paging data, number of nodes per page, default = 0
* @param {Int} options.pageNumber if paging data, current page index, default = 0
* @param {String} options.filter if provided, query will only return those with names matching the filter
* @param {String} options.orderDirection can be `Ascending` or `Descending` - Default: `Ascending`
* @param {String} options.orderBy property to order items by, default: `SortOrder`
* @returns {Promise} resourcePromise object containing an array of content items.
*
*/
getChildren: function (parentId, options) {
var defaults = {
pageSize: 0,
pageNumber: 0,
filter: '',
orderDirection: "Ascending",
orderBy: "SortOrder"
};
if (options === undefined) {
options = {};
}
//overwrite the defaults if there are any specified
angular.extend(defaults, options);
//now copy back to the options we will use
options = defaults;
//change asc/desct
if (options.orderDirection === "asc") {
options.orderDirection = "Ascending";
}
else if (options.orderDirection === "desc") {
options.orderDirection = "Descending";
}
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"mediaApiBaseUrl",
"GetChildren",
[{ parentId: parentId }])),
'Failed to retreive data for root media');
$http.get(
umbRequestHelper.getApiUrl(
"mediaApiBaseUrl",
"GetChildren",
[
{ id: parentId },
{ pageNumber: options.pageNumber },
{ pageSize: options.pageSize },
{ orderBy: options.orderBy },
{ orderDirection: options.orderDirection },
{ filter: options.filter }
])),
'Failed to retreive children for media item ' + parentId);
},
/** saves or updates a media object */

View File

@@ -45,7 +45,7 @@ angular.module("umbraco")
$scope.images = [];
$scope.searchTerm = "";
$scope.images = data;
$scope.images = data.items;
//update the thumbnail property
_.each($scope.images, function(img) {
img.thumbnail = imageHelper.getThumbnail({ imageModel: img, scope: $scope });

View File

@@ -15,12 +15,12 @@ function MediaSortController($scope, mediaResource, treeService) {
mediaResource.getChildren($scope.currentNode.id).then(function (data) {
$scope.sortableModel.itemsToSort = [];
for (var i = 0; i < data.length; i++) {
for (var i = 0; i < data.items.length; i++) {
$scope.sortableModel.itemsToSort.push({
id: data[i].id,
column1: data[i].name,
column2: data[i].updateDate,
column3: data[i].sortOrder
id: data.items[i].id,
column1: data.items[i].name,
column2: data.items[i].updateDate,
column3: data.items[i].sortOrder
});
}
});

View File

@@ -32,7 +32,7 @@ angular.module("umbraco")
$scope.loadChildren = function(id){
mediaResource.getChildren(id)
.then(function(data) {
$scope.images = data;
$scope.images = data.items;
});
};

View File

@@ -122,21 +122,18 @@ namespace Umbraco.Web.Editors
Direction orderDirection = Direction.Ascending,
string filter = "")
{
//TODO: Not sure how to handle 'filter' just yet!
//TODO: Not sure how to handle 'filter' just yet! - SD: have implemented this for EntityService so I just need to get it working here,
// will be a post filter though.
//TODO: This will be horribly inefficient for paging! This is because our datasource/repository
// doesn't support paging at the SQL level... and it'll be pretty interesting to try to make that work.
var foundContent = Services.ContentService.GetById(id);
if (foundContent == null)
{
HandleContentNotFound(id);
}
var totalChildren = ((ContentService) Services.ContentService).CountChildren(id);
var result = foundContent.Children()
.Select(Mapper.Map<IContent, ContentItemBasic<ContentPropertyBasic, IContent>>)
.AsQueryable();
var children = Services.ContentService.GetChildren(id).ToArray();
var totalChildren = children.Length;
var result = children
.Select(Mapper.Map<IContent, ContentItemBasic<ContentPropertyBasic, IContent>>)
.AsQueryable();
var orderedResult = orderDirection == Direction.Ascending
? result.OrderBy(orderBy)

View File

@@ -10,12 +10,15 @@ using System.Web.Http;
using System.Web.Http.ModelBinding;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Dynamics;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Editors;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Core.Services;
using Umbraco.Web.Models;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Models.Mapping;
using Umbraco.Web.Mvc;
@@ -117,13 +120,49 @@ namespace Umbraco.Web.Editors
/// <summary>
/// Returns the child media objects
/// </summary>
[FilterAllowedOutgoingMedia(typeof(IEnumerable<ContentItemBasic<ContentPropertyBasic, IMedia>>))]
public IEnumerable<ContentItemBasic<ContentPropertyBasic, IMedia>> GetChildren(int parentId)
[FilterAllowedOutgoingMedia(typeof(IEnumerable<ContentItemBasic<ContentPropertyBasic, IMedia>>), "Items")]
public PagedResult<ContentItemBasic<ContentPropertyBasic, IMedia>> GetChildren(int id,
int pageNumber = 0,
int pageSize = 0,
string orderBy = "SortOrder",
Direction orderDirection = Direction.Ascending,
string filter = "")
{
//TODO: Change this to be like content with paged params
return Services.MediaService.GetChildren(parentId)
.Select(Mapper.Map<IMedia, ContentItemBasic<ContentPropertyBasic, IMedia>>);
//TODO: Not sure how to handle 'filter' just yet! - SD: have implemented this for EntityService so I just need to get it working here,
// will be a post filter though.
//TODO: This will be horribly inefficient for paging! This is because our datasource/repository
// doesn't support paging at the SQL level... and it'll be pretty interesting to try to make that work.
var children = Services.MediaService.GetChildren(id).ToArray();
var totalChildren = children.Length;
var result = children
.Select(Mapper.Map<IMedia, ContentItemBasic<ContentPropertyBasic, IMedia>>)
.AsQueryable();
var orderedResult = orderDirection == Direction.Ascending
? result.OrderBy(orderBy)
: result.OrderByDescending(orderBy);
var pagedResult = new PagedResult<ContentItemBasic<ContentPropertyBasic, IMedia>>(
totalChildren,
pageNumber,
pageSize);
if (pageNumber > 0 && pageSize > 0)
{
pagedResult.Items = orderedResult
.Skip(pagedResult.SkipSize)
.Take(pageSize);
}
else
{
pagedResult.Items = orderedResult;
}
return pagedResult;
}
/// <summary>