Fixes issue that you could not remove a property group, fixes issue that the inherited flag during mapping wasn't set on a standalone parent property group, updated/created tests to support.

This commit is contained in:
Shannon
2015-07-13 15:29:00 +02:00
parent bfe4f79b7c
commit 8521dfb0d7
3 changed files with 166 additions and 12 deletions

View File

@@ -49,15 +49,17 @@ namespace Umbraco.Web.Models.Mapping
//mapped in aftermap
.ForMember(dto => dto.AllowedContentTypes, expression => expression.Ignore())
.ForMember(dto => dto.AllowedTemplates, expression => expression.Ignore())
//ignore, we'll do this in after map
.ForMember(dto => dto.PropertyGroups, expression => expression.Ignore())
.AfterMap((source, dest) =>
{
var addedProperties = new List<string>();
//get all properties from groups that are not generic properties (-666 id)
foreach (var groupDisplay in source.Groups.Where(x => x.Id != -666))
//get all properties from groups that are not generic properties or inhertied (-666 id)
var selfNonGenericGroups = source.Groups.Where(x => x.Inherited == false && x.Id != -666).ToArray();
foreach (var groupDisplay in selfNonGenericGroups)
{
//use underlying logic to add the property group which should wire most things up for us
dest.AddPropertyGroup(groupDisplay.Name);
@@ -70,12 +72,19 @@ namespace Umbraco.Web.Models.Mapping
dest.AddPropertyType(Mapper.Map<PropertyType>(propertyTypeDisplay), groupDisplay.Name);
addedProperties.Add(propertyTypeDisplay.Alias);
}
}
//Groups to remove
var groupsToRemove = dest.PropertyGroups.Select(x => x.Name).Except(selfNonGenericGroups.Select(x => x.Name)).ToArray();
foreach (var toRemove in groupsToRemove)
{
dest.RemovePropertyGroup(toRemove);
}
//add generic properties
var genericProperties = source.Groups.FirstOrDefault(x => x.Id == -666);
if(genericProperties != null){
if(genericProperties != null)
{
foreach (var propertyTypeDisplay in genericProperties.Properties.Where(x => x.Inherited == false))
{
dest.AddPropertyType(Mapper.Map<PropertyType>(propertyTypeDisplay));

View File

@@ -58,6 +58,10 @@ namespace Umbraco.Web.Models.Mapping
{
Id = tab.Id, Inherited = false, Name = tab.Name, SortOrder = tab.SortOrder, ContentTypeId = source.Id
};
if (tab.ParentId.HasValue)
group.ParentGroupId = tab.ParentId.Value;
group.Properties = MapProperties(tab.PropertyTypes, source, tab.Id, false);
groups.Add(tab.Id, group);
}
@@ -73,7 +77,7 @@ namespace Umbraco.Web.Models.Mapping
var group = new PropertyGroupDisplay()
{
Id = tab.Id, Inherited = false, Name = tab.Name, SortOrder = tab.SortOrder, ContentTypeId = composition.Id,
Id = tab.Id, Inherited = true, Name = tab.Name, SortOrder = tab.SortOrder, ContentTypeId = composition.Id,
ParentTabContentTypes = new[] {composition.Id},
ParentTabContentTypeNames = new[] {composition.Name}
};
@@ -87,9 +91,7 @@ namespace Umbraco.Web.Models.Mapping
//process generic properties assigned to this content item (without a group)
//NOTE: -666 is just a thing that is checked for on the front-end... I'm not a fan of this for the mapping
// since this is just for front-end, this could probably be updated to be -666 in the controller which is associated
// with giving the front-end it's data
//NOTE: -666 is just a thing that is checked during mapping the other direction, it's a 'special' id
var entityGenericProperties = source.PropertyTypes.Where(x => x.PropertyGroupId == null);
genericProperties.AddRange(MapProperties(entityGenericProperties, source, -666, false));