Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support async in TreeController #12016

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -349,7 +349,7 @@ private async Task<ActionResult<object>> 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);
Expand Down
37 changes: 34 additions & 3 deletions src/Umbraco.Web.BackOffice/Trees/TreeControllerBase.cs
Expand Up @@ -57,6 +57,37 @@ protected TreeControllerBase(UmbracoApiControllerTypeCollection apiControllers,
/// <returns></returns>
protected abstract ActionResult<MenuItemCollection> GetMenuForNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings);

/// <summary>
/// The method called to render the contents of the tree structure
/// </summary>
/// <param name="id"></param>
/// <param name="queryStrings">
/// All of the query string parameters passed from jsTree
/// </param>
/// <remarks>
/// 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.
/// </remarks>
protected virtual async Task<ActionResult<TreeNodeCollection>> GetTreeNodesAsync(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings)
{
return GetTreeNodes(id, queryStrings);
}

/// <summary>
/// Returns the menu structure for the node
/// </summary>
/// <param name="id"></param>
/// <param name="queryStrings"></param>
/// <returns></returns>
/// <remarks>
/// If overriden, GetMenuForNode will not be called
/// </remarks>
protected virtual async Task<ActionResult<MenuItemCollection>> GetMenuForNodeAsync(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings)
{
return GetMenuForNode(id, queryStrings);
}

/// <summary>
/// The name to display on the root node
/// </summary>
Expand Down Expand Up @@ -132,7 +163,7 @@ public async Task<ActionResult<TreeNode>> GetRootNode([ModelBinder(typeof(HttpQu
public async Task<ActionResult<TreeNodeCollection>> 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))
{
Expand All @@ -150,7 +181,7 @@ public async Task<ActionResult<TreeNodeCollection>> 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;
}
Expand All @@ -164,7 +195,7 @@ public async Task<ActionResult<TreeNodeCollection>> GetNodes(string id, [ModelBi
public async Task<ActionResult<MenuItemCollection>> 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;
Expand Down
Expand Up @@ -26,11 +26,17 @@ public class TreeNodesRenderingNotification : INotification
/// </summary>
public string TreeAlias { get; }

public TreeNodesRenderingNotification(TreeNodeCollection nodes, FormCollection queryString, string treeAlias)
/// <summary>
/// Gets id of the node rendered
/// </summary>
public string Id { get; }

public TreeNodesRenderingNotification(TreeNodeCollection nodes, FormCollection queryString, string treeAlias, string id)
nzdev marked this conversation as resolved.
Show resolved Hide resolved
{
Nodes = nodes;
QueryString = queryString;
TreeAlias = treeAlias;
Id = id;
}
}
}