Fixes: U4-7639 Misleading message on creating first document type and click on "compositions"

Added in FirstContentType property on object returned from GetEmpty to indicate whether this is the first content type being created or not (different error messages in backoffice).
This commit is contained in:
Claus
2016-01-11 11:57:52 +01:00
committed by Shannon
parent 043fb99020
commit e016622fe3
5 changed files with 60 additions and 32 deletions

View File

@@ -63,7 +63,7 @@ namespace Umbraco.Tests.Models.Mapping
Mapper.Initialize(configuration =>
{
//initialize our content type mapper
var mapper = new ContentTypeModelMapper(new Lazy<PropertyEditorResolver>(() => _propertyEditorResolver.Object));
var mapper = new ContentTypeModelMapper(new Lazy<PropertyEditorResolver>(() => _propertyEditorResolver.Object), new Lazy<IContentTypeService>(() => appContext.Services.ContentTypeService));
mapper.ConfigureMappings(configuration, appContext);
var entityMapper = new EntityModelMapper();
entityMapper.ConfigureMappings(configuration, appContext);

View File

@@ -1,31 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "contentType", Namespace = "")]
public class ContentTypeDisplay : ContentTypeCompositionDisplay
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "contentType", Namespace = "")]
public class ContentTypeDisplay : ContentTypeCompositionDisplay
{
public ContentTypeDisplay()
{
//initialize collections so at least their never null
AllowedTemplates = new List<EntityBasic>();
}
//name, alias, icon, thumb, desc, inherited from the content type
// Templates
[DataMember(Name = "allowedTemplates")]
public IEnumerable<EntityBasic> AllowedTemplates { get; set; }
[DataMember(Name = "defaultTemplate")]
public EntityBasic DefaultTemplate { get; set; }
}
}
public ContentTypeDisplay()
{
//initialize collections so at least their never null
AllowedTemplates = new List<EntityBasic>();
}
//name, alias, icon, thumb, desc, inherited from the content type
// Templates
[DataMember(Name = "allowedTemplates")]
public IEnumerable<EntityBasic> AllowedTemplates { get; set; }
[DataMember(Name = "defaultTemplate")]
public EntityBasic DefaultTemplate { get; set; }
[DataMember(Name = "firstContentType")]
public bool FirstContentType { get; set; }
}
}

View File

@@ -9,6 +9,7 @@ using Umbraco.Core.PropertyEditors;
using Umbraco.Web.Models.ContentEditing;
using System.Collections.Generic;
using AutoMapper.Internal;
using Umbraco.Core.Services;
using Property = umbraco.NodeFactory.Property;
namespace Umbraco.Web.Models.Mapping
@@ -19,17 +20,20 @@ namespace Umbraco.Web.Models.Mapping
internal class ContentTypeModelMapper : MapperConfiguration
{
private readonly Lazy<PropertyEditorResolver> _propertyEditorResolver;
private readonly Lazy<IContentTypeService> _contentTypeService;
//default ctor
public ContentTypeModelMapper()
{
_propertyEditorResolver = new Lazy<PropertyEditorResolver>(() => PropertyEditorResolver.Current);
_contentTypeService = new Lazy<IContentTypeService>(() => ApplicationContext.Current.Services.ContentTypeService);
}
//ctor can be used for testing
public ContentTypeModelMapper(Lazy<PropertyEditorResolver> propertyEditorResolver)
public ContentTypeModelMapper(Lazy<PropertyEditorResolver> propertyEditorResolver, Lazy<IContentTypeService> contentTypeService)
{
_propertyEditorResolver = propertyEditorResolver;
_contentTypeService = contentTypeService;
}
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
@@ -114,6 +118,7 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(dto => dto.AllowedTemplates, expression => expression.Ignore())
.ForMember(dto => dto.DefaultTemplate, expression => expression.Ignore())
.ForMember(display => display.Notifications, expression => expression.Ignore())
.ForMember(x => x.FirstContentType, exp => exp.ResolveUsing(new FirstContentTypeResolver(_contentTypeService)))
.AfterMap((source, dest) =>
{
//sync templates
@@ -176,6 +181,7 @@ namespace Umbraco.Web.Models.Mapping
.MapBaseContentTypeSaveToDisplay()
.ForMember(dto => dto.AllowedTemplates, expression => expression.Ignore())
.ForMember(dto => dto.DefaultTemplate, expression => expression.Ignore())
.ForMember(dto => dto.FirstContentType, exp => exp.Ignore())
.AfterMap((source, dest) =>
{
//sync templates

View File

@@ -0,0 +1,24 @@
using System;
using System.Linq;
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace Umbraco.Web.Models.Mapping
{
internal class FirstContentTypeResolver : ValueResolver<IContentType, bool>
{
private readonly Lazy<IContentTypeService> _contentTypeService;
public FirstContentTypeResolver(Lazy<IContentTypeService> contentTypeService)
{
_contentTypeService = contentTypeService;
}
protected override bool ResolveCore(IContentType source)
{
var contentTypes = _contentTypeService.Value.GetAllContentTypes();
return contentTypes.Any() == false;
}
}
}

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\FirstContentTypeResolver.cs" />
<Compile Include="Models\PublishedContentWithKeyBase.cs" />
<Compile Include="Mvc\IRenderController.cs" />
<Compile Include="Mvc\RenderIndexActionSelectorAttribute.cs" />