From b99b9b7a6b41acc59582203db491619ae9bfb5be Mon Sep 17 00:00:00 2001 From: Shannon Date: Sun, 4 Jun 2017 17:31:31 +0200 Subject: [PATCH] adds blueprints dictionary to ContentTypeBasic result --- src/Umbraco.Core/Services/ContentService.cs | 2 +- src/Umbraco.Core/Services/IContentService.cs | 2 +- src/Umbraco.Tests/Services/ContentServiceTests.cs | 10 +++++----- src/Umbraco.Web/Editors/ContentTypeController.cs | 13 ++++++++++++- .../Models/ContentEditing/ContentTypeBasic.cs | 10 ++++++++++ .../Models/Mapping/ContentTypeModelMapper.cs | 9 ++++++--- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index ab15f6acc4..97972c178f 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -1852,7 +1852,7 @@ namespace Umbraco.Core.Services return true; } - public IEnumerable GetDocumentBlueprints(params int[] documentTypeIds) + public IEnumerable GetBlueprintsForContentTypes(params int[] documentTypeIds) { using (var uow = UowProvider.GetUnitOfWork(readOnly: true)) { diff --git a/src/Umbraco.Core/Services/IContentService.cs b/src/Umbraco.Core/Services/IContentService.cs index f497eea5bc..5e949b0b89 100644 --- a/src/Umbraco.Core/Services/IContentService.cs +++ b/src/Umbraco.Core/Services/IContentService.cs @@ -96,7 +96,7 @@ namespace Umbraco.Core.Services /// public interface IContentService : IContentServiceBase { - IEnumerable GetDocumentBlueprints(params int[] documentTypeIds); + IEnumerable GetBlueprintsForContentTypes(params int[] documentTypeIds); void SaveBlueprint(IContent content, int userId = 0); void DeleteBlueprint(IContent content, int userId = 0); IContent CreateContentFromBlueprint(IContent blueprint, string name, int userId = 0); diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs index 71eacdcf04..d521219918 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs @@ -68,7 +68,7 @@ namespace Umbraco.Tests.Services contentService.SaveBlueprint(blueprint); - var found = contentService.GetDocumentBlueprints().ToArray(); + var found = contentService.GetBlueprintsForContentTypes().ToArray(); Assert.AreEqual(1, found.Length); //ensures it's not found by normal content @@ -95,7 +95,7 @@ namespace Umbraco.Tests.Services contentService.DeleteBlueprint(blueprint); - var found = contentService.GetDocumentBlueprints().ToArray(); + var found = contentService.GetBlueprintsForContentTypes().ToArray(); Assert.AreEqual(0, found.Length); } @@ -143,13 +143,13 @@ namespace Umbraco.Tests.Services contentService.SaveBlueprint(blueprint); } - var found = contentService.GetDocumentBlueprints().ToArray(); + var found = contentService.GetBlueprintsForContentTypes().ToArray(); Assert.AreEqual(10, found.Length); - found = contentService.GetDocumentBlueprints(ct1.Id).ToArray(); + found = contentService.GetBlueprintsForContentTypes(ct1.Id).ToArray(); Assert.AreEqual(5, found.Length); - found = contentService.GetDocumentBlueprints(ct2.Id).ToArray(); + found = contentService.GetBlueprintsForContentTypes(ct2.Id).ToArray(); Assert.AreEqual(5, found.Length); } diff --git a/src/Umbraco.Web/Editors/ContentTypeController.cs b/src/Umbraco.Web/Editors/ContentTypeController.cs index 720eca184b..f0e67ac14b 100644 --- a/src/Umbraco.Web/Editors/ContentTypeController.cs +++ b/src/Umbraco.Web/Editors/ContentTypeController.cs @@ -302,7 +302,18 @@ namespace Umbraco.Web.Editors { basic.Name = localizedTextService.UmbracoDictionaryTranslate(basic.Name); basic.Description = localizedTextService.UmbracoDictionaryTranslate(basic.Description); - } + } + + //map the blueprints + var blueprints = Services.ContentService.GetBlueprintsForContentTypes(types.Select(x => x.Id).ToArray()).ToArray(); + foreach (var basic in basics) + { + var docTypeBluePrints = blueprints.Where(x => x.ContentTypeId == (int) basic.Id).ToArray(); + foreach (var blueprint in docTypeBluePrints) + { + basic.Blueprints[blueprint.Id] = blueprint.Name; + } + } return basics; } diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentTypeBasic.cs b/src/Umbraco.Web/Models/ContentEditing/ContentTypeBasic.cs index 8dde1f1f97..938c7de657 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentTypeBasic.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentTypeBasic.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Runtime.Serialization; @@ -18,6 +19,11 @@ namespace Umbraco.Web.Models.ContentEditing [DataContract(Name = "contentType", Namespace = "")] public class ContentTypeBasic : EntityBasic { + public ContentTypeBasic() + { + Blueprints = new Dictionary(); + } + /// /// Overridden to apply our own validation attributes since this is not always required for other classes /// @@ -105,5 +111,9 @@ namespace Umbraco.Web.Models.ContentEditing : IOHelper.ResolveUrl("~/umbraco/images/thumbnails/" + Thumbnail); } } + + [DataMember(Name = "blueprints")] + [ReadOnly(true)] + public IDictionary Blueprints { get; set; } } } diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapper.cs b/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapper.cs index 24620509e9..1d9b4fedda 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentTypeModelMapper.cs @@ -163,11 +163,14 @@ namespace Umbraco.Web.Models.Mapping }); config.CreateMap() - .ForMember(x => x.Udi, expression => expression.MapFrom(content => Udi.Create(Constants.UdiEntityType.MemberType, content.Key))); + .ForMember(x => x.Udi, expression => expression.MapFrom(content => Udi.Create(Constants.UdiEntityType.MemberType, content.Key))) + .ForMember(x => x.Blueprints, expression => expression.Ignore()); config.CreateMap() - .ForMember(x => x.Udi, expression => expression.MapFrom(content => Udi.Create(Constants.UdiEntityType.MediaType, content.Key))); + .ForMember(x => x.Udi, expression => expression.MapFrom(content => Udi.Create(Constants.UdiEntityType.MediaType, content.Key))) + .ForMember(x => x.Blueprints, expression => expression.Ignore()); config.CreateMap() - .ForMember(x => x.Udi, expression => expression.MapFrom(content => Udi.Create(Constants.UdiEntityType.DocumentType, content.Key))); + .ForMember(x => x.Udi, expression => expression.MapFrom(content => Udi.Create(Constants.UdiEntityType.DocumentType, content.Key))) + .ForMember(x => x.Blueprints, expression => expression.Ignore()); config.CreateMap()