-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
PackagesTreeController.cs
71 lines (61 loc) · 2.57 KB
/
PackagesTreeController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Cms.Web.Common.Authorization;
using Constants = Umbraco.Cms.Core.Constants;
namespace Umbraco.Cms.Web.BackOffice.Trees
{
[Authorize(Policy = AuthorizationPolicies.TreeAccessPackages)]
[Tree(Constants.Applications.Packages, Constants.Trees.Packages, SortOrder = 0, IsSingleNodeTree = true)]
[PluginController(Constants.Web.Mvc.BackOfficeTreeArea)]
[CoreTree]
public class PackagesTreeController : TreeController
{
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
public PackagesTreeController(
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory;
}
/// <summary>
/// Helper method to create a root model for a tree
/// </summary>
/// <returns></returns>
protected override ActionResult<TreeNode?> CreateRootNode(FormCollection queryStrings)
{
var rootResult = base.CreateRootNode(queryStrings);
if (!(rootResult.Result is null))
{
return rootResult;
}
var root = rootResult.Value;
if (root is not null)
{
// This will load in a custom UI instead of the dashboard for the root node
root.RoutePath = $"{Constants.Applications.Packages}/{Constants.Trees.Packages}/repo";
root.Icon = Constants.Icons.Packages;
root.HasChildren = false;
}
return root;
}
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
//full screen app without tree nodes
return TreeNodeCollection.Empty;
}
protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
{
//doesn't have a menu, this is a full screen app without tree nodes
return _menuItemCollectionFactory.Create();
}
}
}