updating to use includeProperties, fixing modifier keywords for methods, and passing includeProperties from list views.

This commit is contained in:
Claus
2018-04-17 08:36:36 +02:00
parent 5380b62504
commit 0c191a3ef7
4 changed files with 49 additions and 25 deletions

View File

@@ -57,7 +57,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
saveModel),
'Failed to save permissions');
},
getRecycleBin: function () {
return umbRequestHelper.resourcePromise(
@@ -424,7 +424,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
$http.get(
umbRequestHelper.getApiUrl(
"contentApiBaseUrl",
"GetEmpty",
"GetEmpty",
[{ blueprintId: blueprintId }, { parentId: parentId}])),
'Failed to retrieve blueprint for id ' + blueprintId);
},
@@ -488,6 +488,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
getChildren: function (parentId, options) {
var defaults = {
includeProperties: [],
pageSize: 0,
pageNumber: 0,
filter: '',
@@ -531,6 +532,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
"GetChildren",
{
id: parentId,
includeProperties: _.pluck(options.includeProperties, 'alias').join(","),
pageNumber: options.pageNumber,
pageSize: options.pageSize,
orderBy: options.orderBy,
@@ -580,7 +582,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
"contentApiBaseUrl",
"GetDetailedPermissions", { contentId: contentId })),
'Failed to retrieve permissions for content item ' + contentId);
},
},
getPermissions: function (nodeIds) {
return umbRequestHelper.resourcePromise(
@@ -741,11 +743,11 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
createBlueprintFromContent: function (contentId, name) {
return umbRequestHelper.resourcePromise(
$http.post(
$http.post(
umbRequestHelper.getApiUrl("contentApiBaseUrl", "CreateBlueprintFromContent", {
contentId: contentId, name: name
})
),
})
),
"Failed to create blueprint from content with id " + contentId
);
}

View File

@@ -389,7 +389,25 @@ namespace Umbraco.Web.Editors
Direction orderDirection = Direction.Ascending,
bool orderBySystemField = true,
string filter = "")
{
{
return GetChildren(id, null, pageNumber, pageSize, orderBy, orderDirection, orderBySystemField, filter);
}
/// <summary>
/// Gets the children for the content id passed in
/// </summary>
/// <returns></returns>
[FilterAllowedOutgoingContent(typeof(IEnumerable<ContentItemBasic<ContentPropertyBasic, IContent>>), "Items")]
public PagedResult<ContentItemBasic<ContentPropertyBasic, IContent>> GetChildren(
int id,
string includeProperties,
int pageNumber = 0, //TODO: This should be '1' as it's not the index
int pageSize = 0,
string orderBy = "SortOrder",
Direction orderDirection = Direction.Ascending,
bool orderBySystemField = true,
string filter = "")
{
long totalChildren;
IContent[] children;
if (pageNumber > 0 && pageSize > 0)
@@ -409,13 +427,17 @@ namespace Umbraco.Web.Editors
return new PagedResult<ContentItemBasic<ContentPropertyBasic, IContent>>(0, 0, 0);
}
// Note that we're excluding mapping of complex properties here to ensure that getting a larger amount of
// children for listviews and other similar cases, will not make everything halt when it tries to deserialize a
// complex property such as Nested Content.
var pagedResult = new PagedResult<ContentItemBasic<ContentPropertyBasic, IContent>>(totalChildren, pageNumber, pageSize);
pagedResult.Items = children.Select(content =>
Mapper.Map<IContent, ContentItemBasic<ContentPropertyBasic, IContent>>(content,
opts => { opts.Items["ExcludeComplexProperties"] = true; }));
opts =>
{
// if there's a list of property aliases to map - we will make sure to store this in the mapping context.
if (String.IsNullOrWhiteSpace(includeProperties) == false)
{
opts.Items["IncludeProperties"] = includeProperties.Split(new[] { ", ", "," }, StringSplitOptions.RemoveEmptyEntries);
}
}));
return pagedResult;
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Logging;
@@ -30,7 +31,7 @@ namespace Umbraco.Web.Models.Mapping
/// Assigns the PropertyEditor, Id, Alias and Value to the property
/// </summary>
/// <returns></returns>
public T Convert(ResolutionContext context)
public virtual T Convert(ResolutionContext context)
{
var property = context.SourceValue as Property;
if (property == null)
@@ -55,19 +56,19 @@ namespace Umbraco.Web.Models.Mapping
Editor = editor.Alias
};
// Complex properties such as Nested Content do not need to be mapped for simpler things like list views,
// where they will not make sense to use anyways. To avoid having to do unnecessary mapping on large
// collections of items in list views - we allow excluding mapping of certain properties.
var excludeComplexProperties = false;
if (context.Options.Items.ContainsKey("ExcludeComplexProperties"))
// if there's a set of property aliases specified, we will check if the current property's value should be mapped.
// if it isn't one of the ones specified in 'includeProperties', we will just return the result without mapping the Value.
if (context.Options.Items.ContainsKey("IncludeProperties"))
{
excludeComplexProperties = System.Convert.ToBoolean(context.Options.Items["ExcludeComplexProperties"]);
var includeProperties = context.Options.Items["IncludeProperties"] as IEnumerable<string>;
if (includeProperties != null && includeProperties.Contains(property.Alias) == false)
{
return result;
}
}
if (excludeComplexProperties == false || ComplexPropertyTypeAliases.Contains(property.PropertyType.PropertyEditorAlias) == false)
{
result.Value = editor.ValueEditor.ConvertDbToEditor(property, property.PropertyType, DataTypeService);
}
// if no 'IncludeProperties' were specified or this property is set to be included - we will map the value and return.
result.Value = editor.ValueEditor.ConvertDbToEditor(property, property.PropertyType, DataTypeService);
return result;
}
}

View File

@@ -18,8 +18,7 @@ namespace Umbraco.Web.Models.Mapping
{
_textService = textService;
}
public new ContentPropertyDisplay Convert(ResolutionContext context)
public override ContentPropertyDisplay Convert(ResolutionContext context)
{
var display = base.Convert(context);