From 7377b7614e15398865a5e0bc8c9cc001404a4e18 Mon Sep 17 00:00:00 2001 From: Shannon Date: Sun, 4 Jun 2017 22:52:18 +0200 Subject: [PATCH] Renders blueprints underneath their associated document types, removes preview button --- .../Repositories/ContentTypeRepository.cs | 13 +++++ .../Interfaces/IContentTypeRepository.cs | 2 + .../Services/ContentTypeService.cs | 9 +++ .../Services/IContentTypeService.cs | 7 +++ src/Umbraco.Web/Editors/ContentController.cs | 5 ++ .../Trees/ContentBlueprintTreeController.cs | 56 +++++++++++++------ 6 files changed, 76 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs index 985f9446b7..96641ba715 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs @@ -110,6 +110,19 @@ namespace Umbraco.Core.Persistence.Repositories return Database.Fetch(sql); } + public IEnumerable GetAllContentTypeIds(string[] aliases) + { + if (aliases.Length == 0) return Enumerable.Empty(); + + var sql = new Sql().Select("cmsContentType.nodeId") + .From(SqlSyntax) + .InnerJoin(SqlSyntax) + .On(SqlSyntax, dto => dto.NodeId, dto => dto.NodeId) + .Where(dto => aliases.Contains(dto.Alias), SqlSyntax); + + return Database.Fetch(sql); + } + protected override Sql GetBaseQuery(bool isCount) { var sql = new Sql(); diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentTypeRepository.cs index f118be3b76..5cb3faebbb 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentTypeRepository.cs @@ -47,5 +47,7 @@ namespace Umbraco.Core.Persistence.Repositories /// The original alias with a number appended to it, so that it is unique. /// /// Unique accross all content, media and member types. string GetUniqueAlias(string alias); + + IEnumerable GetAllContentTypeIds(string[] aliases); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Services/ContentTypeService.cs b/src/Umbraco.Core/Services/ContentTypeService.cs index 1b6735153d..895d97f658 100644 --- a/src/Umbraco.Core/Services/ContentTypeService.cs +++ b/src/Umbraco.Core/Services/ContentTypeService.cs @@ -367,6 +367,15 @@ namespace Umbraco.Core.Services } } + public IEnumerable GetAllContentTypeIds(string[] aliases) + { + using (var uow = UowProvider.GetUnitOfWork(readOnly: true)) + { + var repository = RepositoryFactory.CreateContentTypeRepository(uow); + return repository.GetAllContentTypeIds(aliases); + } + } + /// /// Copies a content type as a child under the specified parent if specified (otherwise to the root) /// diff --git a/src/Umbraco.Core/Services/IContentTypeService.cs b/src/Umbraco.Core/Services/IContentTypeService.cs index 46ee8520c6..f470bbce05 100644 --- a/src/Umbraco.Core/Services/IContentTypeService.cs +++ b/src/Umbraco.Core/Services/IContentTypeService.cs @@ -61,6 +61,13 @@ namespace Umbraco.Core.Services /// /// IEnumerable GetAllContentTypeAliases(params Guid[] objectTypes); + + /// + /// Returns all content type Ids for the aliases given + /// + /// + /// + IEnumerable GetAllContentTypeIds(string[] aliases); /// /// Copies a content type as a child under the specified parent if specified (otherwise to the root) diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index c0f863d086..a0b8382437 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -115,6 +115,11 @@ namespace Umbraco.Web.Editors var content = Mapper.Map(foundContent); + content.AllowPreview = false; + + //set a custom path since the tree that renders this has the content type id as the parent + content.Path = string.Format("-1,{0},{1}", foundContent.ContentTypeId, content.Id); + content.AllowedActions = new[] {'A'}; var excludeProps = new[] {"_umb_urls", "_umb_releasedate", "_umb_expiredate", "_umb_template"}; diff --git a/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs b/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs index 7b18b015ea..65538778e4 100644 --- a/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs @@ -35,28 +35,48 @@ namespace Umbraco.Web.Trees { var nodes = new TreeNodeCollection(); - //check if we're rendering the root + //get all blueprints + var entities = Services.EntityService.GetChildren(Constants.System.Root, UmbracoObjectTypes.DocumentBlueprint).ToArray(); + + //check if we're rendering the root in which case we'll render the content types that have blueprints if (id == Constants.System.Root.ToInvariantString()) { - var altStartId = string.Empty; + //get all blueprint content types + var contentTypeAliases = entities.Select(x => ((UmbracoEntity) x).ContentTypeAlias).Distinct(); + //get the ids + var contentTypeIds = Services.ContentTypeService.GetAllContentTypeIds(contentTypeAliases.ToArray()); + //now get the entities ... it's a bit round about but still smaller queries than getting all document types + var docTypeEntities = Services.EntityService.GetAll(UmbracoObjectTypes.DocumentType, contentTypeIds.ToArray()).ToArray(); - if (queryStrings.HasKey(TreeQueryStringParameters.StartNodeId)) - altStartId = queryStrings.GetValue(TreeQueryStringParameters.StartNodeId); - - //check if a request has been made to render from a specific start node - if (string.IsNullOrEmpty(altStartId) == false && altStartId != "undefined" && altStartId != Constants.System.Root.ToString(CultureInfo.InvariantCulture)) - { - id = altStartId; - } - - var entities = Services.EntityService.GetChildren(Constants.System.Root, UmbracoObjectTypes.DocumentBlueprint).ToArray(); - - nodes.AddRange(entities - .Select(entity => CreateTreeNode(entity, Constants.ObjectTypes.DocumentBlueprintGuid, id, queryStrings, "icon-blueprint", false)) - .Where(node => node != null)); + nodes.AddRange(docTypeEntities + .Select(entity => + { + var treeNode = CreateTreeNode(entity, Constants.ObjectTypes.DocumentBlueprintGuid, id, queryStrings, "icon-item-arrangement", true); + treeNode.Path = string.Format("-1,{0}", entity.Id); + treeNode.NodeType = "contentType"; + //TODO: This isn't the best way to ensure a noop process for clicking a node but it works for now. + treeNode.AdditionalData["jsClickCallback"] = "javascript:void(0);"; + return treeNode; + })); return nodes; } + else + { + var intId = id.TryConvertTo(); + //Get the content type + var ct = Services.ContentTypeService.GetContentType(intId.Result); + if (ct == null) return nodes; + + var blueprintsForDocType = entities.Where(x => ct.Alias == ((UmbracoEntity) x).ContentTypeAlias); + nodes.AddRange(blueprintsForDocType + .Select(entity => + { + var treeNode = CreateTreeNode(entity, Constants.ObjectTypes.DocumentBlueprintGuid, id, queryStrings, "icon-blueprint", false); + treeNode.Path = string.Format("-1,{0},{1}", ct.Id, entity.Id); + return treeNode; + })); + } return nodes; } @@ -71,9 +91,13 @@ namespace Umbraco.Web.Trees menu.Items.Add(Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)), true); return menu; } + var ct = Services.EntityService.Get(int.Parse(id), UmbracoObjectTypes.DocumentType); + //no menu if it's a content type + if (ct != null) return null; menu.Items.Add(Services.TextService.Localize(string.Format("actions/{0}", ActionDelete.Instance.Alias))); + return menu; }