From c53d074aafc9da8f4ce01e5add7ad4a723afa95f Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 19 May 2016 17:56:11 +0200 Subject: [PATCH] Merge branch 'U4-8195' of https://github.com/Mantus667/Umbraco-CMS into Mantus667-U4-8195 # Conflicts: # src/Umbraco.Web.UI/config/trees.Release.config # src/Umbraco.Web.UI/config/trees.config # src/Umbraco.Web/Umbraco.Web.csproj --- .../config/trees.Release.config | 2 +- src/Umbraco.Web.UI/config/trees.config | 2 +- .../Trees/RelationTypeTreeController.cs | 76 ++++++++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 2 +- .../umbraco/Trees/loadRelationTypes.cs | 99 ------------------- 5 files changed, 79 insertions(+), 102 deletions(-) create mode 100644 src/Umbraco.Web/Trees/RelationTypeTreeController.cs delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadRelationTypes.cs diff --git a/src/Umbraco.Web.UI/config/trees.Release.config b/src/Umbraco.Web.UI/config/trees.Release.config index 844fe9617b..32c188fd9b 100644 --- a/src/Umbraco.Web.UI/config/trees.Release.config +++ b/src/Umbraco.Web.UI/config/trees.Release.config @@ -20,7 +20,7 @@ - + diff --git a/src/Umbraco.Web.UI/config/trees.config b/src/Umbraco.Web.UI/config/trees.config index e2e1e7dc10..57022b7402 100644 --- a/src/Umbraco.Web.UI/config/trees.config +++ b/src/Umbraco.Web.UI/config/trees.config @@ -19,7 +19,7 @@ - + diff --git a/src/Umbraco.Web/Trees/RelationTypeTreeController.cs b/src/Umbraco.Web/Trees/RelationTypeTreeController.cs new file mode 100644 index 0000000000..2ed71b68e9 --- /dev/null +++ b/src/Umbraco.Web/Trees/RelationTypeTreeController.cs @@ -0,0 +1,76 @@ +using System; +using System.Linq; +using System.Net.Http.Formatting; +using Umbraco.Web.Models.Trees; +using Umbraco.Web.WebApi.Filters; +using Umbraco.Core; +using Umbraco.Web._Legacy.Actions; +using Umbraco.Core.Services; +using Umbraco.Core.Models; + +namespace Umbraco.Web.Trees +{ + [UmbracoTreeAuthorize(Constants.Trees.RelationTypes)] + [Tree(Constants.Applications.Developer, Constants.Trees.RelationTypes, null, sortOrder: 4)] + [Mvc.PluginController("UmbracoTrees")] + [CoreTree] + public class RelationTypeTreeController : TreeController + { + protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) + { + var menu = new MenuItemCollection(); + + if (id == Constants.System.Root.ToInvariantString()) + { + //Create the normal create action + menu.Items.Add(Services.TextService.Localize("actions", ActionNew.Instance.Alias)) + //Since we haven't implemented anything for relationtypes in angular, this needs to be converted to + //use the legacy format + .ConvertLegacyMenuItem(null, "initrelationTypes", queryStrings.GetValue("application")); + //refresh action + menu.Items.Add(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true); + + return menu; + } + + var relationType = Services.RelationService.GetRelationTypeById(int.Parse(id)); + if (relationType == null) return new MenuItemCollection(); + + //add delete option for all macros + menu.Items.Add(Services.TextService.Localize("actions", ActionDelete.Instance.Alias)) + //Since we haven't implemented anything for relationtypes in angular, this needs to be converted to + //use the legacy format + .ConvertLegacyMenuItem(new UmbracoEntity + { + Id = relationType.Id, + Level = 1, + ParentId = -1, + Name = relationType.Name + }, "relationTypes", queryStrings.GetValue("application")); + + return menu; + } + + protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) + { + var nodes = new TreeNodeCollection(); + + if (id == Constants.System.Root.ToInvariantString()) + { + nodes.AddRange(Services.RelationService + .GetAllRelationTypes().Select(rt => CreateTreeNode( + rt.Id.ToString(), + id, + queryStrings, + rt.Name, + "icon-trafic", + false, + //TODO: Rebuild the macro editor in angular, then we dont need to have this at all (which is just a path to the legacy editor) + "/" + queryStrings.GetValue("application") + "/framed/" + + Uri.EscapeDataString("/umbraco/developer/RelationTypes/EditRelationType.aspx?id=" + rt.Id) + ))); + } + return nodes; + } + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 0093389468..90e5af5e98 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -334,6 +334,7 @@ + @@ -1496,7 +1497,6 @@ Code - diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadRelationTypes.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadRelationTypes.cs deleted file mode 100644 index ab6a84bfe4..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadRelationTypes.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Web; -using umbraco.cms.businesslogic.relation; -using umbraco.cms.presentation.Trees; -using umbraco.DataLayer; -using umbraco.cms.presentation.developer.RelationTypes.TreeMenu; - -using Umbraco.Core; -using Umbraco.Web.Trees; -using Umbraco.Web._Legacy.Actions; - -namespace umbraco -{ - /// - /// RelationTypes tree for developer section - /// - [Tree(Constants.Applications.Developer, "relationTypes", "Relation Types", sortOrder: 4)] - public class loadRelationTypes : BaseTree - { - /// - /// Initializes a new instance of the RelationTypeTree class. - /// - /// name of umbraco app to which this tree has been added, (in this case "developer") - public loadRelationTypes(string application) - : base(application) - { - } - - /// - /// Builds the javascript methods for use by the nodes in this tree - /// - /// string container for javascript - public override void RenderJS(ref StringBuilder javascript) - { - javascript.Append(@" - function openRelationType(id) { - UmbClientMgr.contentFrame('developer/RelationTypes/EditRelationType.aspx?id=' + id); - }"); - } - - /// - /// This is called if the tree has been expanded, and it's used to render and child nodes for this tree - /// - /// current tree - public override void Render(ref XmlTree tree) - { - XmlTreeNode node; - - foreach (RelationType relationType in RelationType.GetAll().OrderBy(relationType => relationType.Name)) - { - node = XmlTreeNode.Create(this); - node.NodeID = relationType.Id.ToString(); - node.Text = relationType.Name; - node.Icon = "icon-trafic"; - node.Action = string.Concat("javascript:openRelationType('", node.NodeID, "');"); - - tree.Add(node); - } - } - - /// - /// Adds right click context tree actions for each child node - /// - /// collection of actions (expected to be empty) - protected override void CreateAllowedActions(ref List actions) - { - actions.Clear(); - actions.Add(ActionDeleteRelationType.Instance); - } - - /// - /// Adds right click context tree actions for the root 'Relation Types' node - /// - /// collection of actions (expected to be empty) - protected override void CreateRootNodeActions(ref List actions) - { - actions.Clear(); - actions.Add(ActionNewRelationType.Instance); - actions.Add(ContextMenuSeperator.Instance); - actions.Add(ActionRefresh.Instance); - } - - /// - /// Configures root node 'Relation Types' properties - /// - /// the 'Relation Types' root node - protected override void CreateRootNode(ref XmlTreeNode rootNode) - { - rootNode.Text = "Relation Types"; - rootNode.Icon = BaseTree.FolderIcon; - rootNode.OpenIcon = BaseTree.FolderIconOpen; - rootNode.NodeType = this.TreeAlias; // (Was prefixed with init) - rootNode.NodeID = "init"; - } - } -}