Got the media tree converted to new tree structure.

This commit is contained in:
Shannon
2013-08-05 19:22:00 +10:00
parent 603e698621
commit ab594db5fc
7 changed files with 115 additions and 44 deletions

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.ModelBinding;
using System.ComponentModel.DataAnnotations;
namespace Umbraco.Core.Models.Validation
{

View File

@@ -13,5 +13,15 @@ namespace Umbraco.Core.Services
{
return contentService.GetContentInRecycleBin().Any();
}
/// <summary>
/// Returns true if there is any media in the recycle bin
/// </summary>
/// <param name="mediaService"></param>
/// <returns></returns>
public static bool RecycleBinSmells(this IMediaService mediaService)
{
return mediaService.GetMediaInRecycleBin().Any();
}
}
}

View File

@@ -4,8 +4,8 @@
<!--<add application="content" alias="content" title="Content" type="umbraco.loadContent, umbraco" iconClosed=".sprTreeFolder" iconOpen=".sprTreeFolder_o" silent="true" sortOrder="0" />
<add application="content" alias="contentRecycleBin" title="RecycleBin" type="umbraco.cms.presentation.Trees.ContentRecycleBin, umbraco" iconClosed="folder.gif" iconOpen="folder_o.gif" initialize="false" sortOrder="0" />-->
<!--Media-->
<add application="media" alias="media" title="Media" type="umbraco.loadMedia, umbraco" iconClosed=".sprTreeFolder" iconOpen=".sprTreeFolder_o" sortOrder="0" />
<add application="media" alias="mediaRecycleBin" title="RecycleBin" type="umbraco.cms.presentation.Trees.MediaRecycleBin, umbraco" iconClosed="folder.gif" iconOpen="folder_o.gif" initialize="false" sortOrder="0" />
<!--<add application="media" alias="media" title="Media" type="umbraco.loadMedia, umbraco" iconClosed=".sprTreeFolder" iconOpen=".sprTreeFolder_o" sortOrder="0" />
<add application="media" alias="mediaRecycleBin" title="RecycleBin" type="umbraco.cms.presentation.Trees.MediaRecycleBin, umbraco" iconClosed="folder.gif" iconOpen="folder_o.gif" initialize="false" sortOrder="0" />-->
<!--Settings-->
<add application="settings" alias="stylesheets" title="Stylesheets" type="umbraco.loadStylesheets, umbraco" iconClosed=".sprTreeFolder" iconOpen=".sprTreeFolder_o" sortOrder="0" />
<add application="settings" alias="stylesheetProperty" title="Stylesheet Property" type="umbraco.loadStylesheetProperty, umbraco" iconClosed="" iconOpen="" initialize="false" sortOrder="0" />
@@ -41,4 +41,6 @@
iconClosed=".sprTreeFolder" iconOpen=".sprTreeFolder_o" sortOrder="10" />-->
<add initialize="true" sortOrder="0" alias="content" application="content" title="Content" iconClosed="icon-folder" iconOpen="icon-folder-open" type="Umbraco.Web.Trees.ContentTreeController, umbraco" action="" />
<add initialize="false" sortOrder="0" alias="contentRecycleBin" application="content" title="Recycle Bin" iconClosed="folder.gif" iconOpen="folder_o.gif" type="umbraco.cms.presentation.Trees.ContentRecycleBin, umbraco" action="" />
<add initialize="true" sortOrder="0" alias="media" application="media" title="Media" iconClosed="icon-folder" iconOpen="icon-folder-open" type="Umbraco.Web.Trees.MediaTreeController, umbraco" />
<add initialize="false" sortOrder="0" alias="mediaRecycleBin" application="media" title="Recycle Bin" iconClosed="folder.gif" iconOpen="folder_o.gif" type="umbraco.cms.presentation.Trees.MediaRecycleBin, umbraco" />
</trees>

View File

@@ -17,20 +17,6 @@ using umbraco.interfaces;
namespace Umbraco.Web.Trees
{
//[Tree(Constants.Applications.Content, Constants.Trees.Content, "Content")]
//public class MediaTreeController : ContentTreeControllerBase
//{
// protected override TreeNodeCollection GetTreeData(string id, FormDataCollection queryStrings)
// {
// throw new NotImplementedException();
// }
// protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
// {
// throw new NotImplementedException();
// }
//}
[Tree(Constants.Applications.Content, Constants.Trees.Content, "Content")]
public class ContentTreeController : ContentTreeControllerBase
{
@@ -74,26 +60,10 @@ namespace Umbraco.Web.Trees
protected override TreeNodeCollection PerformGetTreeNodes(string id, FormDataCollection queryStrings)
{
int iid;
if (int.TryParse(id, out iid) == false)
{
throw new InvalidCastException("The id for the content tree must be an integer");
}
var entities = GetChildEntities(id);
var nodes = new TreeNodeCollection();
IEnumerable<IUmbracoEntity> entities;
//if a request is made for the root node data but the user's start node is not the default, then
// we need to return their start node data
if (iid == Constants.System.Root && UmbracoUser.StartNodeId != Constants.System.Root)
{
entities = Services.EntityService.GetChildren(UmbracoUser.StartNodeId, UmbracoObjectTypes.Document).ToArray();
}
else
{
entities = Services.EntityService.GetChildren(iid, UmbracoObjectTypes.Document).ToArray();
}
foreach (var entity in entities)
{
var e = (UmbracoEntity)entity;
@@ -124,8 +94,11 @@ namespace Umbraco.Web.Trees
UmbracoUser.GetPermissions(Constants.System.Root.ToInvariantString()))
.Select(x => new MenuItem(x));
//these two are the standard items
menu.AddMenuItem<ActionNew>();
menu.AddMenuItem<ActionSort>();
//filter the standard items
var allowedMenu = GetUserAllowedMenuItems(menu, nodeActions);
if (allowedMenu.Any())
@@ -133,9 +106,9 @@ namespace Umbraco.Web.Trees
allowedMenu.Last().SeperatorBefore = true;
}
// default actions for all users
// add default actions for *all* users
allowedMenu.AddMenuItem<ActionRePublish>();
menu.AddMenuItem<RefreshNodeMenuItem, ActionRefresh>(true);
allowedMenu.AddMenuItem<RefreshNodeMenuItem, ActionRefresh>(true);
return allowedMenu;
}
@@ -156,6 +129,11 @@ namespace Umbraco.Web.Trees
GetUserMenuItemsForNode(item));
}
protected override UmbracoObjectTypes UmbracoObjectType
{
get { return UmbracoObjectTypes.Document; }
}
protected IEnumerable<MenuItem> CreateAllowedActions()
{
var menu = new MenuItemCollection();

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Formatting;
using Umbraco.Core;
@@ -26,6 +27,26 @@ namespace Umbraco.Web.Trees
protected abstract MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings);
protected abstract UmbracoObjectTypes UmbracoObjectType { get; }
protected IEnumerable<IUmbracoEntity> GetChildEntities(string id)
{
int iid;
if (int.TryParse(id, out iid) == false)
{
throw new InvalidCastException("The id for the media tree must be an integer");
}
//if a request is made for the root node data but the user's start node is not the default, then
// we need to return their start node data
if (iid == Constants.System.Root && UmbracoUser.StartNodeId != Constants.System.Root)
{
return Services.EntityService.GetChildren(UmbracoUser.StartNodeId, UmbracoObjectType).ToArray();
}
return Services.EntityService.GetChildren(iid, UmbracoObjectType).ToArray();
}
/// <summary>
/// This will automatically check if the recycle bin needs to be rendered (i.e. its the first level)
/// and will automatically append it to the result of GetChildNodes.

View File

@@ -0,0 +1,65 @@
using System.Linq;
using System.Net.Http.Formatting;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Trees.Menu;
using umbraco.BusinessLogic.Actions;
namespace Umbraco.Web.Trees
{
[Tree(Constants.Applications.Media, Constants.Trees.Media, "Media")]
public class MediaTreeController : ContentTreeControllerBase
{
protected override int RecycleBinId
{
get { return Constants.System.RecycleBinContent; }
}
protected override bool RecycleBinSmells
{
get { return Services.MediaService.RecycleBinSmells(); }
}
protected override TreeNodeCollection PerformGetTreeNodes(string id, FormDataCollection queryStrings)
{
var entities = GetChildEntities(id);
var nodes = new TreeNodeCollection();
nodes.AddRange(
entities.Cast<UmbracoEntity>()
.Select(e => CreateTreeNode(e.Id.ToInvariantString(), queryStrings, e.Name, e.ContentTypeIcon, e.HasChildren)));
return nodes;
}
protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();
if (id == Constants.System.Root.ToInvariantString())
{
// default actions for all users
menu.AddMenuItem<ActionNew>();
menu.AddMenuItem<ActionSort>(true);
menu.AddMenuItem<RefreshNodeMenuItem, ActionRefresh>(true);
return menu;
}
//return a normal node menu:
menu.AddMenuItem<ActionNew>();
menu.AddMenuItem<ActionMove>();
menu.AddMenuItem<ActionDelete>();
menu.AddMenuItem<ActionSort>();
menu.AddMenuItem<ActionRefresh>(true);
return menu;
}
protected override UmbracoObjectTypes UmbracoObjectType
{
get { return UmbracoObjectTypes.Media; }
}
}
}

View File

@@ -343,6 +343,7 @@
<Compile Include="PropertyEditors\TextAreaPropertyEditor.cs" />
<Compile Include="PropertyEditors\TextStringPropertyEditor.cs" />
<Compile Include="PropertyEditors\TrueFalsePropertyEditor.cs" />
<Compile Include="Trees\MediaTreeController.cs" />
<Compile Include="Trees\Menu\ActionMenuItem.cs" />
<Compile Include="Trees\Menu\ActionMenuItemAttribute.cs" />
<Compile Include="Trees\ActionUrlMethod.cs" />