From e016622fe3322e64c701d368d557f716b7d7c8b2 Mon Sep 17 00:00:00 2001 From: Claus Date: Mon, 11 Jan 2016 11:57:52 +0100 Subject: [PATCH] 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). --- .../Mapping/ContentTypeModelMappingTests.cs | 2 +- .../ContentEditing/ContentTypeDisplay.cs | 57 +++++++++---------- .../Models/Mapping/ContentTypeModelMapper.cs | 8 ++- .../Mapping/FirstContentTypeResolver.cs | 24 ++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + 5 files changed, 60 insertions(+), 32 deletions(-) create mode 100644 src/Umbraco.Web/Models/Mapping/FirstContentTypeResolver.cs diff --git a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs index 76d1220ea3..e066f03da4 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs @@ -63,7 +63,7 @@ namespace Umbraco.Tests.Models.Mapping Mapper.Initialize(configuration => { //initialize our content type mapper - var mapper = new ContentTypeModelMapper(new Lazy(() => _propertyEditorResolver.Object)); + var mapper = new ContentTypeModelMapper(new Lazy(() => _propertyEditorResolver.Object), new Lazy(() => appContext.Services.ContentTypeService)); mapper.ConfigureMappings(configuration, appContext); var entityMapper = new EntityModelMapper(); entityMapper.ConfigureMappings(configuration, appContext); diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentTypeDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/ContentTypeDisplay.cs index e0165450ed..d5166a9180 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentTypeDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentTypeDisplay.cs @@ -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(); - } - - //name, alias, icon, thumb, desc, inherited from the content type - - // Templates - [DataMember(Name = "allowedTemplates")] - public IEnumerable AllowedTemplates { get; set; } - - [DataMember(Name = "defaultTemplate")] - public EntityBasic DefaultTemplate { get; set; } - - } -} + public ContentTypeDisplay() + { + //initialize collections so at least their never null + AllowedTemplates = new List(); + } + + //name, alias, icon, thumb, desc, inherited from the content type + + // Templates + [DataMember(Name = "allowedTemplates")] + public IEnumerable AllowedTemplates { get; set; } + + [DataMember(Name = "defaultTemplate")] + public EntityBasic DefaultTemplate { get; set; } + + [DataMember(Name = "firstContentType")] + public bool FirstContentType { get; set; } + } +} diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapper.cs b/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapper.cs index 39f4a57b32..1152284068 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapper.cs @@ -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; + private readonly Lazy _contentTypeService; //default ctor public ContentTypeModelMapper() { _propertyEditorResolver = new Lazy(() => PropertyEditorResolver.Current); + _contentTypeService = new Lazy(() => ApplicationContext.Current.Services.ContentTypeService); } //ctor can be used for testing - public ContentTypeModelMapper(Lazy propertyEditorResolver) + public ContentTypeModelMapper(Lazy propertyEditorResolver, Lazy 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 diff --git a/src/Umbraco.Web/Models/Mapping/FirstContentTypeResolver.cs b/src/Umbraco.Web/Models/Mapping/FirstContentTypeResolver.cs new file mode 100644 index 0000000000..406c5e2681 --- /dev/null +++ b/src/Umbraco.Web/Models/Mapping/FirstContentTypeResolver.cs @@ -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 + { + private readonly Lazy _contentTypeService; + + public FirstContentTypeResolver(Lazy contentTypeService) + { + _contentTypeService = contentTypeService; + } + + protected override bool ResolveCore(IContentType source) + { + var contentTypes = _contentTypeService.Value.GetAllContentTypes(); + return contentTypes.Any() == false; + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 89780c9aae..30100d78f6 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -309,6 +309,7 @@ +