Initial PoC

This commit is contained in:
Kenn Jacobsen
2019-02-09 15:41:30 +01:00
parent 1703c918d9
commit 89a701c865
6 changed files with 112 additions and 18 deletions

View File

@@ -503,10 +503,14 @@ namespace Umbraco.Web.Editors
return new PagedResult<EntityBasic>(0, 0, 0);
}
var culture = Request.ClientCulture();
var pagedResult = new PagedResult<EntityBasic>(totalRecords, pageNumber, pageSize)
{
Items = entities.Select(entity => Mapper.Map<IEntitySlim, EntityBasic>(entity, options =>
options.AfterMap((src, dest) => { dest.AdditionalData["hasChildren"] = src.HasChildren; })
{
options.SetCulture(culture);
options.AfterMap((src, dest) => { dest.AdditionalData["hasChildren"] = src.HasChildren; });
}
)
)
};
@@ -585,7 +589,7 @@ namespace Umbraco.Web.Editors
var pagedResult = new PagedResult<EntityBasic>(totalRecords, pageNumber, pageSize)
{
Items = entities.Select(Mapper.Map<EntityBasic>)
Items = entities.Select(MapEntities())
};
return pagedResult;
@@ -632,7 +636,7 @@ namespace Umbraco.Web.Editors
return Services.EntityService.GetChildren(id, objectType.Value)
.WhereNotNull()
.Select(Mapper.Map<EntityBasic>);
.Select(MapEntities());
}
//now we need to convert the unknown ones
switch (entityType)
@@ -693,7 +697,7 @@ namespace Umbraco.Web.Editors
: Services.EntityService.GetAll(objectType.Value, ids)
.WhereNotNull()
.OrderBy(x => x.Level)
.Select(x => Mapper.Map<EntityBasic>(x, opts => { opts.SetCulture(culture);}));
.Select(MapEntities(culture));
}
//now we need to convert the unknown ones
switch (entityType)
@@ -719,7 +723,7 @@ namespace Umbraco.Web.Editors
{
var entities = Services.EntityService.GetAll(objectType.Value, keys)
.WhereNotNull()
.Select(Mapper.Map<EntityBasic>);
.Select(MapEntities());
// entities are in "some" order, put them back in order
var xref = entities.ToDictionary(x => x.Key);
@@ -751,7 +755,7 @@ namespace Umbraco.Web.Editors
{
var entities = Services.EntityService.GetAll(objectType.Value, ids)
.WhereNotNull()
.Select(Mapper.Map<EntityBasic>);
.Select(MapEntities());
// entities are in "some" order, put them back in order
var xref = entities.ToDictionary(x => x.Id);
@@ -815,7 +819,7 @@ namespace Umbraco.Web.Editors
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return Mapper.Map<EntityBasic>(found);
return MapEntity(found);
}
//now we need to convert the unknown ones
switch (entityType)
@@ -886,7 +890,7 @@ namespace Umbraco.Web.Editors
if (objectType.HasValue)
{
// TODO: Should we order this by something ?
var entities = Services.EntityService.GetAll(objectType.Value).WhereNotNull().Select(Mapper.Map<EntityBasic>);
var entities = Services.EntityService.GetAll(objectType.Value).WhereNotNull().Select(MapEntities());
return ExecutePostFilter(entities, postFilter);
}
//now we need to convert the unknown ones
@@ -895,13 +899,13 @@ namespace Umbraco.Web.Editors
case UmbracoEntityTypes.Template:
var templates = Services.FileService.GetTemplates();
var filteredTemplates = ExecutePostFilter(templates, postFilter);
return filteredTemplates.Select(Mapper.Map<EntityBasic>);
return filteredTemplates.Select(MapEntities());
case UmbracoEntityTypes.Macro:
//Get all macros from the macro service
var macros = Services.MacroService.GetAll().WhereNotNull().OrderBy(x => x.Name);
var filteredMacros = ExecutePostFilter(macros, postFilter);
return filteredMacros.Select(Mapper.Map<EntityBasic>);
return filteredMacros.Select(MapEntities());
case UmbracoEntityTypes.PropertyType:
@@ -936,14 +940,14 @@ namespace Umbraco.Web.Editors
if (!postFilter.IsNullOrWhiteSpace())
throw new NotSupportedException("Filtering on stylesheets is not currently supported");
return Services.FileService.GetStylesheets().Select(Mapper.Map<EntityBasic>);
return Services.FileService.GetStylesheets().Select(MapEntities());
case UmbracoEntityTypes.Language:
if (!postFilter.IsNullOrWhiteSpace() )
throw new NotSupportedException("Filtering on languages is not currently supported");
return Services.LocalizationService.GetAllLanguages().Select(Mapper.Map<EntityBasic>);
return Services.LocalizationService.GetAllLanguages().Select(MapEntities());
case UmbracoEntityTypes.DictionaryItem:
if (!postFilter.IsNullOrWhiteSpace())
@@ -1039,8 +1043,17 @@ namespace Umbraco.Web.Editors
return queryCondition;
}
private Func<object, EntityBasic> MapEntities(string culture = null)
{
culture = culture ?? Request.ClientCulture();
return x => MapEntity(x, culture);
}
private EntityBasic MapEntity(object entity, string culture = null)
{
culture = culture ?? Request.ClientCulture();
return Mapper.Map<EntityBasic>(entity, opts => { opts.SetCulture(culture); });
}
#region Methods to get all dictionary items
private IEnumerable<EntityBasic> GetAllDictionaryItems()