Allows the tree collection to be manipulated by devs on startup, renames some things
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
using System.Web;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using Examine;
|
||||
using Microsoft.AspNet.SignalR;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Components;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.ContentEditing;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.PropertyEditors.ValueConverters;
|
||||
@@ -23,9 +21,7 @@ using Umbraco.Web.Dictionary;
|
||||
using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.Features;
|
||||
using Umbraco.Web.HealthCheck;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Models.PublishedContent;
|
||||
using Umbraco.Web.Models.Trees;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
@@ -207,12 +203,13 @@ namespace Umbraco.Web.Runtime
|
||||
.Append<TranslationBackOfficeSection>();
|
||||
|
||||
// register back office trees
|
||||
foreach (var treeControllerType in umbracoApiControllerTypes)
|
||||
foreach (var treeControllerType in umbracoApiControllerTypes
|
||||
.Where(x => typeof(TreeControllerBase).IsAssignableFrom(x)))
|
||||
{
|
||||
var attribute = treeControllerType.GetCustomAttribute<TreeAttribute>(false);
|
||||
if (attribute == null) continue;
|
||||
var tree = new Tree(attribute.SortOrder, attribute.ApplicationAlias, attribute.TreeAlias, attribute.TreeTitle, treeControllerType, attribute.IsSingleNodeTree);
|
||||
composition.WithCollectionBuilder<TreeCollectionBuilder>().AddTree(tree);
|
||||
composition.WithCollectionBuilder<TreeCollectionBuilder>().Trees.Add(tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,16 +26,16 @@ namespace Umbraco.Web.Services
|
||||
/// <summary>
|
||||
/// Gets the application tree for the applcation with the specified alias
|
||||
/// </summary>
|
||||
/// <param name="applicationAlias">The application alias.</param>
|
||||
/// <param name="sectionAlias">The application alias.</param>
|
||||
/// <returns>Returns a ApplicationTree Array</returns>
|
||||
IEnumerable<Tree> GetApplicationTrees(string applicationAlias);
|
||||
IEnumerable<Tree> GetTrees(string sectionAlias);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the grouped application trees for the application with the specified alias
|
||||
/// </summary>
|
||||
/// <param name="applicationAlias"></param>
|
||||
/// <param name="sectionAlias"></param>
|
||||
/// <returns></returns>
|
||||
IDictionary<string, IEnumerable<Tree>> GetGroupedApplicationTrees(string applicationAlias);
|
||||
IDictionary<string, IEnumerable<Tree>> GetGroupedTrees(string sectionAlias);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ namespace Umbraco.Web.Services
|
||||
public IEnumerable<Tree> GetAll() => _treeCollection;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<Tree> GetApplicationTrees(string applicationAlias)
|
||||
=> GetAll().Where(x => x.ApplicationAlias.InvariantEquals(applicationAlias)).OrderBy(x => x.SortOrder).ToList();
|
||||
public IEnumerable<Tree> GetTrees(string sectionAlias)
|
||||
=> GetAll().Where(x => x.ApplicationAlias.InvariantEquals(sectionAlias)).OrderBy(x => x.SortOrder).ToList();
|
||||
|
||||
public IDictionary<string, IEnumerable<Tree>> GetGroupedApplicationTrees(string applicationAlias)
|
||||
public IDictionary<string, IEnumerable<Tree>> GetGroupedTrees(string sectionAlias)
|
||||
{
|
||||
var result = new Dictionary<string, IEnumerable<Tree>>();
|
||||
var foundTrees = GetApplicationTrees(applicationAlias).ToList();
|
||||
var foundTrees = GetTrees(sectionAlias).ToList();
|
||||
foreach(var treeGroup in _groupedTrees.Value)
|
||||
{
|
||||
List<Tree> resultGroup = null;
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Umbraco.Web.Trees
|
||||
if (string.IsNullOrEmpty(application)) throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
|
||||
//find all tree definitions that have the current application alias
|
||||
var groupedTrees = _treeService.GetGroupedApplicationTrees(application);
|
||||
var groupedTrees = _treeService.GetGroupedTrees(application);
|
||||
var allTrees = groupedTrees.Values.SelectMany(x => x).ToList();
|
||||
|
||||
if (string.IsNullOrEmpty(tree) == false || allTrees.Count == 1)
|
||||
|
||||
@@ -12,12 +12,6 @@ namespace Umbraco.Web.Trees
|
||||
{
|
||||
protected override BackOfficeSectionCollectionBuilder This => this;
|
||||
|
||||
// need to inject dependencies in the collection, so override creation
|
||||
public override BackOfficeSectionCollection CreateCollection(IFactory factory)
|
||||
{
|
||||
return new BackOfficeSectionCollection(CreateItems(factory));
|
||||
}
|
||||
|
||||
protected override IEnumerable<IBackOfficeSection> CreateItems(IFactory factory)
|
||||
{
|
||||
// get the manifest parser just-in-time - injecting it in the ctor would mean that
|
||||
@@ -25,7 +19,8 @@ namespace Umbraco.Web.Trees
|
||||
// its dependencies too, and that can create cycles or other oddities
|
||||
var manifestParser = factory.GetInstance<ManifestParser>();
|
||||
|
||||
return base.CreateItems(factory).Concat(manifestParser.Manifest.Sections.Select(x => new ManifestBackOfficeSection(x.Key, x.Value)));
|
||||
return base.CreateItems(factory)
|
||||
.Concat(manifestParser.Manifest.Sections.Select(x => new ManifestBackOfficeSection(x.Key, x.Value)));
|
||||
}
|
||||
|
||||
private class ManifestBackOfficeSection : IBackOfficeSection
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
namespace Umbraco.Web.Trees
|
||||
{
|
||||
//fixme - we don't really use this, it is nice to have the treecontroller, attribute and ApplicationTree streamlined to implement this but it's not used
|
||||
public interface ITree
|
||||
//leave as internal for now, maybe we'll use in the future, means we could pass around ITree
|
||||
internal interface ITree
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the sort order.
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Umbraco.Web.Trees
|
||||
|
||||
public Type TreeControllerType { get; }
|
||||
|
||||
public static string GetRootNodeDisplayName(ITree tree, ILocalizedTextService textService)
|
||||
internal static string GetRootNodeDisplayName(ITree tree, ILocalizedTextService textService)
|
||||
{
|
||||
var label = $"[{tree.TreeAlias}]";
|
||||
|
||||
|
||||
@@ -3,16 +3,15 @@ using Umbraco.Core.Composing;
|
||||
|
||||
namespace Umbraco.Web.Trees
|
||||
{
|
||||
//fixme - how will we allow users to modify these items? they will need to be able to change the ApplicationTree's registered (i.e. sort order, section)
|
||||
public class TreeCollectionBuilder : CollectionBuilderBase<TreeCollectionBuilder, TreeCollection, Tree>
|
||||
public class TreeCollectionBuilder : ICollectionBuilder<TreeCollection, Tree>
|
||||
{
|
||||
private readonly List<Tree> _instances = new List<Tree>();
|
||||
/// <summary>
|
||||
/// expose the list of trees which developers can manipulate before the collection is created
|
||||
/// </summary>
|
||||
public List<Tree> Trees { get; } = new List<Tree>();
|
||||
|
||||
public void AddTree(Tree tree)
|
||||
{
|
||||
_instances.Add(tree);
|
||||
}
|
||||
public TreeCollection CreateCollection(IFactory factory) => new TreeCollection(Trees);
|
||||
|
||||
protected override IEnumerable<Tree> CreateItems(IFactory factory) => _instances;
|
||||
public void RegisterWith(IRegister register) => register.Register(CreateCollection, Lifetime.Singleton);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user