Reverting code to add additional meta data on compositions.

Added locked compositions to content type object.
Changed UI to use the lockedCompositeContentTypes instead.
This commit is contained in:
Claus
2016-01-08 12:57:50 +01:00
parent 4db1599bcb
commit 3676de0fe8
8 changed files with 51 additions and 16 deletions

View File

@@ -21,7 +21,7 @@
</umb-empty-state>
<ul class="umb-checkbox-list">
<li class="umb-checkbox-list__item" ng-repeat="compositeContentType in model.availableCompositeContentTypes | filter:searchTerm" ng-class="{ '-selected': model.compositeContentTypes.indexOf(compositeContentType.alias)+1, '-disabled': compositeContentType.metaData.compositionIsInheritedFromAncestors }">
<li class="umb-checkbox-list__item" ng-repeat="compositeContentType in model.availableCompositeContentTypes | filter:searchTerm" ng-class="{ '-selected': model.compositeContentTypes.indexOf(compositeContentType.alias)+1, '-disabled': model.lockedCompositeContentTypes.indexOf(compositeContentType.alias)+1 }">
<div class="umb-checkbox-list__item-checkbox" ng-class="{ '-selected': model.compositeContentTypes.indexOf(compositeContentType.alias)+1 }">
<input type="checkbox"

View File

@@ -132,21 +132,12 @@ namespace Umbraco.Web.Editors
if (parent != null)
ancestorIds = parent.Path.Split(',').Select(int.Parse).ToArray();
}
// add all ancestors as compositions (since they are implicitly compositions by inheritance)
// add all ancestors as compositions (since they are implicitly "compositions" by inheritance and should
// be in the list even though they can't be deselected)
foreach (var x in allContentTypes)
if (ancestorIds.Contains(x.Id))
list.Add(x);
// get the ids of compositions that are inherited from ancestors and add metadata to those compositions
var inheritedFromAncestorsIds = usableContentTypes.Select(x => x.Id) // those we can use
.Except(indirectContentTypes.Select(x => x.Id)) // except those that are indirectly used
.Where(x => ancestorIds.Contains(x) == false) // but not the parents
.Distinct()
.ToArray();
foreach (var x in list)
if (inheritedFromAncestorsIds.Contains(x.Id) == false)
x.AdditionalData["compositionIsInheritedFromAncestors"] = true;
}
return list
.Where(x => x.Id != contentTypeId)

View File

@@ -44,6 +44,10 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "compositeContentTypes")]
public IEnumerable<string> CompositeContentTypes { get; set; }
//Locked compositions
[DataMember(Name = "lockedCompositeContentTypes")]
public IEnumerable<string> LockedCompositeContentTypes { get; set; }
[DataMember(Name = "allowAsRoot")]
public bool AllowAsRoot { get; set; }

View File

@@ -81,6 +81,10 @@ namespace Umbraco.Web.Models.Mapping
dto => dto.CompositeContentTypes,
expression => expression.MapFrom(dto => dto.ContentTypeComposition))
.ForMember(
dto => dto.LockedCompositeContentTypes,
expression => expression.ResolveUsing(new LockedCompositionsResolver(applicationContext)))
.ForMember(
dto => dto.Groups,
expression => expression.ResolveUsing(new PropertyTypeGroupResolver(applicationContext, propertyEditorResolver)));

View File

@@ -72,8 +72,8 @@ namespace Umbraco.Web.Models.Mapping
config.CreateMap<IContentTypeComposition, EntityBasic>()
.ForMember(basic => basic.Path, expression => expression.MapFrom(x => x.Path))
.ForMember(basic => basic.ParentId, expression => expression.MapFrom(x => x.ParentId))
.ForMember(dto => dto.Trashed, expression => expression.Ignore());
//.ForMember(x => x.AdditionalData, expression => expression.Ignore());
.ForMember(dto => dto.Trashed, expression => expression.Ignore())
.ForMember(x => x.AdditionalData, expression => expression.Ignore());
config.CreateMap<SearchResult, EntityBasic>()
//default to document icon

View File

@@ -0,0 +1,36 @@
using AutoMapper;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
namespace Umbraco.Web.Models.Mapping
{
internal class LockedCompositionsResolver : ValueResolver<IContentTypeComposition, IEnumerable<string>>
{
private readonly ApplicationContext _applicationContext;
public LockedCompositionsResolver(ApplicationContext applicationContext)
{
_applicationContext = applicationContext;
}
protected override IEnumerable<string> ResolveCore(IContentTypeComposition source)
{
// get ancestor ids from path (exclude current node id)
var ancestorIds = source.Path.Substring(0, source.Path.LastIndexOf(',')).Split(',').Select(int.Parse);
var aliases = new List<string>();
// loop through all content types and return ordered aliases of ancestors
var allContentTypes = _applicationContext.Services.ContentTypeService.GetAllContentTypes().ToArray();
foreach (var ancestorId in ancestorIds)
{
var ancestor = allContentTypes.FirstOrDefault(x => x.Id == ancestorId);
if (ancestor != null)
{
aliases.Add(ancestor.Alias);
}
}
return aliases.OrderBy(x => x);
}
}
}

View File

@@ -65,7 +65,6 @@ namespace Umbraco.Web.Trees
var enableInheritedDocumentTypes = UmbracoConfig.For.UmbracoSettings().Content.EnableInheritedDocumentTypes;
if (id == Constants.System.Root.ToInvariantString())
{
//set the default to create

View File

@@ -309,6 +309,7 @@
<Compile Include="Models\ContentEditing\PropertyTypeBasic.cs" />
<Compile Include="Models\ContentEditing\SimpleNotificationModel.cs" />
<Compile Include="Models\Mapping\ContentTypeModelMapperExtensions.cs" />
<Compile Include="Models\Mapping\LockedCompositionsResolver.cs" />
<Compile Include="Models\PublishedContentWithKeyBase.cs" />
<Compile Include="Mvc\IRenderController.cs" />
<Compile Include="Mvc\RenderIndexActionSelectorAttribute.cs" />