ContentType + MediaType trees

This commit is contained in:
Per Ploug Krogslund
2015-08-19 22:37:41 +02:00
parent 5778a45c95
commit a7065d083e
2 changed files with 99 additions and 2 deletions

View File

@@ -52,8 +52,6 @@ namespace Umbraco.Web.Trees
return nodes;
}
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();

View File

@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Formatting;
using System.Text;
using System.Threading.Tasks;
using umbraco;
using umbraco.BusinessLogic.Actions;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.WebApi.Filters;
using Umbraco.Core.Services;
namespace Umbraco.Web.Trees
{
[UmbracoTreeAuthorize(Constants.Trees.DataTypes)]
[Tree(Constants.Applications.Settings, Constants.Trees.MediaTypes, "Media Types")]
[Umbraco.Web.Mvc.PluginController("UmbracoTrees")]
[CoreTree]
public class MediaTypeTreeController : TreeController
{
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{
var intId = id.TryConvertTo<int>();
if (intId == false) throw new InvalidOperationException("Id must be an integer");
var nodes = new TreeNodeCollection();
nodes.AddRange(
Services.EntityService.GetChildren(intId.Result, UmbracoObjectTypes.DocumentTypeContainer)
.OrderBy(entity => entity.Name)
.Select(dt =>
{
var node = CreateTreeNode(dt.Id.ToString(), id, queryStrings, dt.Name, "icon-folder", dt.HasChildren(),
queryStrings.GetValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + dt.Id);
node.Path = dt.Path;
return node;
}));
nodes.AddRange(
Services.EntityService.GetChildren(intId.Result, UmbracoObjectTypes.MediaType)
.OrderBy(entity => entity.Name)
.Select(dt =>
{
var node = CreateTreeNode(dt.Id.ToString(), id, queryStrings, dt.Name, "icon-item-arrangement", false);
node.Path = dt.Path;
return node;
}));
return nodes;
}
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();
if (id == Constants.System.Root.ToInvariantString())
{
//set the default to create
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
// root actions
menu.Items.Add<ActionNew>(Services.TextService.Localize(string.Format("actions/{0}", ActionNew.Instance.Alias)));
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)));
return menu;
}
else
{
var container = Services.EntityService.Get(int.Parse(id), UmbracoObjectTypes.DocumentTypeContainer);
if (container != null)
{
//set the default to create
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
// root actions
menu.Items.Add<ActionNew>(Services.TextService.Localize(string.Format("actions/{0}", ActionNew.Instance.Alias)));
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)));
if (container.HasChildren() == false)
{
//can delete doc type
menu.Items.Add<ActionDelete>(Services.TextService.Localize(string.Format("actions/{0}", ActionDelete.Instance.Alias)));
}
}
else
{
//delete doc type
menu.Items.Add<ActionDelete>(Services.TextService.Localize(string.Format("actions/{0}", ActionDelete.Instance.Alias)));
}
}
return menu;
}
}
}