diff --git a/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs index db714bb675b2..ee7d4807318d 100644 --- a/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs +++ b/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs @@ -349,7 +349,7 @@ private async Task> GetApiControllerProxy(Type controllerTy var actionContext = new ActionContext(HttpContext, routeData, actionDescriptor); var proxyControllerContext = new ControllerContext(actionContext); - var controller = (TreeController)_controllerFactory.CreateController(proxyControllerContext); + var controller = (TreeControllerBase)_controllerFactory.CreateController(proxyControllerContext); // TODO: What about other filters? Will they execute? var isAllowed = await controller.ControllerContext.InvokeAuthorizationFiltersForRequest(actionContext); diff --git a/src/Umbraco.Web.BackOffice/Trees/TreeControllerBase.cs b/src/Umbraco.Web.BackOffice/Trees/TreeControllerBase.cs index b6f294896526..20d0e1a305c1 100644 --- a/src/Umbraco.Web.BackOffice/Trees/TreeControllerBase.cs +++ b/src/Umbraco.Web.BackOffice/Trees/TreeControllerBase.cs @@ -47,6 +47,7 @@ protected TreeControllerBase(UmbracoApiControllerTypeCollection apiControllers, /// We are allowing an arbitrary number of query strings to be passed in so that developers are able to persist custom data from the front-end /// to the back end to be used in the query for model data. /// + [Obsolete("See GetTreeNodesAsync")] protected abstract ActionResult GetTreeNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings); /// @@ -55,8 +56,40 @@ protected TreeControllerBase(UmbracoApiControllerTypeCollection apiControllers, /// /// /// + [Obsolete("See GetMenuForNodeAsync")] protected abstract ActionResult GetMenuForNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings); + /// + /// The method called to render the contents of the tree structure + /// + /// + /// + /// All of the query string parameters passed from jsTree + /// + /// + /// If overriden, GetTreeNodes will not be called + /// We are allowing an arbitrary number of query strings to be passed in so that developers are able to persist custom data from the front-end + /// to the back end to be used in the query for model data. + /// + protected virtual async Task> GetTreeNodesAsync(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings) + { + return GetTreeNodes(id, queryStrings); + } + + /// + /// Returns the menu structure for the node + /// + /// + /// + /// + /// + /// If overriden, GetMenuForNode will not be called + /// + protected virtual async Task> GetMenuForNodeAsync(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings) + { + return GetMenuForNode(id, queryStrings); + } + /// /// The name to display on the root node /// @@ -132,7 +165,7 @@ public async Task> GetRootNode([ModelBinder(typeof(HttpQu public async Task> GetNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings) { if (queryStrings == null) queryStrings = FormCollection.Empty; - var nodesResult = GetTreeNodes(id, queryStrings); + var nodesResult = await GetTreeNodesAsync(id, queryStrings); if (!(nodesResult.Result is null)) { @@ -150,7 +183,7 @@ public async Task> GetNodes(string id, [ModelBi node.RoutePath = "#"; //raise the event - await _eventAggregator.PublishAsync(new TreeNodesRenderingNotification(nodes, queryStrings, TreeAlias)); + await _eventAggregator.PublishAsync(new TreeNodesRenderingNotification(nodes, queryStrings, TreeAlias, id)); return nodes; } @@ -164,7 +197,7 @@ public async Task> GetNodes(string id, [ModelBi public async Task> GetMenu(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings) { if (queryStrings == null) queryStrings = FormCollection.Empty; - var menuResult = GetMenuForNode(id, queryStrings); + var menuResult = await GetMenuForNodeAsync(id, queryStrings); if (!(menuResult.Result is null)) { return menuResult.Result; diff --git a/src/Umbraco.Web.BackOffice/Trees/TreeNodesRenderingNotification.cs b/src/Umbraco.Web.BackOffice/Trees/TreeNodesRenderingNotification.cs index f022b23a2056..b7334c0e5ba2 100644 --- a/src/Umbraco.Web.BackOffice/Trees/TreeNodesRenderingNotification.cs +++ b/src/Umbraco.Web.BackOffice/Trees/TreeNodesRenderingNotification.cs @@ -1,3 +1,4 @@ +using System; using Microsoft.AspNetCore.Http; using Umbraco.Cms.Core.Trees; @@ -11,26 +12,57 @@ namespace Umbraco.Cms.Core.Notifications /// public class TreeNodesRenderingNotification : INotification { - /// - /// The tree nodes being rendered - /// - public TreeNodeCollection Nodes { get; } /// - /// The query string of the current request + /// Initializes a new instance of the class. /// - public FormCollection QueryString { get; } + /// The tree nodes being rendered + /// The query string of the current request + /// The alias of the tree rendered + /// The id of the node rendered + public TreeNodesRenderingNotification(TreeNodeCollection nodes, FormCollection queryString, string treeAlias, string id) + { + Nodes = nodes; + QueryString = queryString; + TreeAlias = treeAlias; + Id = id; + } /// - /// The alias of the tree rendered + /// Initializes a new instance of the class. + /// Constructor /// - public string TreeAlias { get; } - + /// The tree nodes being rendered + /// The query string of the current request + /// The alias of the tree rendered + [Obsolete("Use ctor with all parameters")] public TreeNodesRenderingNotification(TreeNodeCollection nodes, FormCollection queryString, string treeAlias) { Nodes = nodes; QueryString = queryString; TreeAlias = treeAlias; + Id = default; } + + /// + /// Gets the tree nodes being rendered + /// + public TreeNodeCollection Nodes { get; } + + /// + /// Gets the query string of the current request + /// + public FormCollection QueryString { get; } + + /// + /// Gets the alias of the tree rendered + /// + public string TreeAlias { get; } + + /// + /// Gets the id of the node rendered + /// + public string Id { get; } + } }