Sort content template tree items alphabetically, exclude element types (#14454)

This commit is contained in:
Callum Whyte
2023-07-31 20:44:02 +01:00
committed by GitHub
parent 3572642873
commit b2831dcd5e
2 changed files with 25 additions and 23 deletions

View File

@@ -549,7 +549,8 @@ public class ContentTypeController : ContentTypeControllerBase<IContentType>
[Authorize(Policy = AuthorizationPolicies.TreeAccessDocumentsOrDocumentTypes)]
public IEnumerable<ContentTypeBasic> GetAll()
{
IEnumerable<IContentType> types = _contentTypeService.GetAll();
IEnumerable<IContentType> types = _contentTypeService.GetAll().Where(x => x.IsElement == false);
IEnumerable<ContentTypeBasic> basics = types.Select(_umbracoMapper.Map<IContentType, ContentTypeBasic>)
.WhereNotNull();

View File

@@ -69,7 +69,6 @@ public class ContentBlueprintTreeController : TreeController
root.HasChildren = _contentService.GetBlueprintsForContentTypes()?.Any() ?? false;
}
return root;
}
@@ -78,34 +77,34 @@ public class ContentBlueprintTreeController : TreeController
var nodes = new TreeNodeCollection();
//get all blueprints
IEntitySlim[] entities = _entityService.GetChildren(Constants.System.Root, UmbracoObjectTypes.DocumentBlueprint)
.ToArray();
IEnumerable<IEntitySlim> entities = _entityService.GetChildren(Constants.System.Root, UmbracoObjectTypes.DocumentBlueprint);
//check if we're rendering the root in which case we'll render the content types that have blueprints
if (id == Constants.System.RootString)
{
//get all blueprint content types
IEnumerable<string> contentTypeAliases =
entities.Select(x => ((IContentEntitySlim)x).ContentTypeAlias).Distinct();
IEnumerable<string> contentTypeAliases = entities.Select(x => ((IContentEntitySlim)x).ContentTypeAlias).Distinct();
//get the ids
var contentTypeIds = _contentTypeService.GetAllContentTypeIds(contentTypeAliases.ToArray()).ToArray();
//now get the entities ... it's a bit round about but still smaller queries than getting all document types
IEntitySlim[] docTypeEntities = contentTypeIds.Length == 0
? new IEntitySlim[0]
: _entityService.GetAll(UmbracoObjectTypes.DocumentType, contentTypeIds).ToArray();
if (contentTypeIds.Any())
{
//now get the entities ... it's a bit round about but still smaller queries than getting all document types
IEnumerable<IEntitySlim> docTypeEntities = _entityService.GetAll(UmbracoObjectTypes.DocumentType, contentTypeIds);
nodes.AddRange(docTypeEntities
.Select(entity =>
{
TreeNode treeNode = CreateTreeNode(entity, Constants.ObjectTypes.DocumentBlueprint, id,
queryStrings, Constants.Icons.ContentType, true);
treeNode.Path = $"-1,{entity.Id}";
treeNode.NodeType = "document-type-blueprints";
// TODO: This isn't the best way to ensure a no operation process for clicking a node but it works for now.
treeNode.AdditionalData["jsClickCallback"] = "javascript:void(0);";
return treeNode;
}));
nodes.AddRange(docTypeEntities
.OrderBy(entity => entity.Name)
.Select(entity =>
{
TreeNode treeNode = CreateTreeNode(entity, Constants.ObjectTypes.DocumentBlueprint, id, queryStrings, Constants.Icons.ContentType, true);
treeNode.Path = $"-1,{entity.Id}";
treeNode.NodeType = "document-type-blueprints";
// TODO: This isn't the best way to ensure a no operation process for clicking a node but it works for now.
treeNode.AdditionalData["jsClickCallback"] = "javascript:void(0);";
return treeNode;
}));
}
return nodes;
}
@@ -117,14 +116,16 @@ public class ContentBlueprintTreeController : TreeController
//Get the content type
IContentType? ct = _contentTypeService.Get(intId);
if (ct == null)
{
return nodes;
}
IEnumerable<IEntitySlim> blueprintsForDocType =
entities.Where(x => ct.Alias == ((IContentEntitySlim)x).ContentTypeAlias);
IEnumerable<IEntitySlim> blueprintsForDocType = entities.Where(x => ct.Alias == ((IContentEntitySlim)x).ContentTypeAlias);
nodes.AddRange(blueprintsForDocType
.OrderBy(entity => entity.Name)
.Select(entity =>
{
TreeNode treeNode = CreateTreeNode(entity, Constants.ObjectTypes.DocumentBlueprint, id, queryStrings,