Files
Umbraco-CMS/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs

119 lines
5.4 KiB
C#
Raw Normal View History

2018-06-29 19:52:40 +02:00
using System.Linq;
using System.Net.Http.Formatting;
using Umbraco.Core;
using Umbraco.Core.Services;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi.Filters;
using Umbraco.Web._Legacy.Actions;
using Constants = Umbraco.Core.Constants;
namespace Umbraco.Web.Trees
{
/// <summary>
/// The content blueprint tree controller
/// </summary>
/// <remarks>
/// This authorizes based on access to the content section even though it exists in the settings
/// </remarks>
[UmbracoApplicationAuthorize(Constants.Applications.Content)]
Merge remote-tracking branch 'origin/dev-v7' into temp8 (after fixing) # Conflicts: # build/Modules/Umbraco.Build/Build-UmbracoDocs.ps1 # src/SolutionInfo.cs # src/Umbraco.Core/Configuration/UmbracoVersion.cs # src/Umbraco.Core/Constants-Applications.cs # src/Umbraco.Core/Models/Rdbms/ConsentDto.cs # src/Umbraco.Core/Persistence/DatabaseSchemaHelper.cs # src/Umbraco.Core/Persistence/Repositories/AuditRepository.cs # src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs # src/Umbraco.Core/Services/ConsentService.cs # src/Umbraco.Core/Services/IRelationService.cs # src/Umbraco.Core/Services/RelationService.cs # src/Umbraco.Tests/Plugins/PluginManagerTests.cs # src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs # src/Umbraco.Tests/Services/ConsentServiceTests.cs # src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js # src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorheader.directive.js # src/Umbraco.Web.UI.Client/src/common/directives/components/tree/umbtree.directive.js # src/Umbraco.Web.UI.Client/src/common/resources/contenttype.resource.js # src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js # src/Umbraco.Web.UI.Client/src/common/services/tree.service.js # src/Umbraco.Web.UI.Client/src/less/application/grid.less # src/Umbraco.Web.UI.Client/src/less/forms.less # src/Umbraco.Web.UI.Client/src/less/main.less # src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.controller.js # src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html # src/Umbraco.Web.UI.Client/src/views/common/overlays/iconpicker/iconpicker.controller.js # src/Umbraco.Web.UI.Client/src/views/common/overlays/iconpicker/iconpicker.html # src/Umbraco.Web.UI.Client/src/views/common/overlays/mediaPicker/mediapicker.controller.js # src/Umbraco.Web.UI.Client/src/views/common/overlays/treepicker/treepicker.controller.js # src/Umbraco.Web.UI.Client/src/views/components/content/umb-content-node-info.html # src/Umbraco.Web.UI.Client/src/views/components/html/umb-control-group.html # src/Umbraco.Web.UI.Client/src/views/components/users/change-password.html # src/Umbraco.Web.UI.Client/src/views/content/content.copy.controller.js # src/Umbraco.Web.UI.Client/src/views/content/content.move.controller.js # src/Umbraco.Web.UI.Client/src/views/datatypes/datatype.edit.controller.js # src/Umbraco.Web.UI.Client/src/views/datatypes/edit.html # src/Umbraco.Web.UI.Client/src/views/documenttypes/views/permissions/permissions.html # src/Umbraco.Web.UI.Client/src/views/media/media.move.controller.js # src/Umbraco.Web.UI.Client/src/views/mediatypes/edit.controller.js # src/Umbraco.Web.UI.Client/src/views/mediatypes/views/permissions/permissions.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/boolean/boolean.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js # src/Umbraco.Web.UI.Client/src/views/users/views/user/details.html # src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/RegisterMember.cshtml # src/Umbraco.Web.UI/config/EmbeddedMedia.Release.config # src/Umbraco.Web.UI/config/EmbeddedMedia.config # src/Umbraco.Web.UI/config/trees.Release.config # src/Umbraco.Web.UI/config/trees.config # src/Umbraco.Web.UI/config/umbracoSettings.config # src/Umbraco.Web.UI/umbraco/Views/Default.cshtml # src/Umbraco.Web.UI/umbraco/config/create/UI.xml # src/Umbraco.Web.UI/umbraco/config/lang/da.xml # src/Umbraco.Web.UI/umbraco/config/lang/en.xml # src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml # src/Umbraco.Web.UI/umbraco/config/lang/it.xml # src/Umbraco.Web.UI/umbraco/config/lang/nl.xml # src/Umbraco.Web.UI/umbraco/config/lang/ru.xml # src/Umbraco.Web/Editors/BackOfficeController.cs # src/Umbraco.Web/Editors/BackOfficeServerVariables.cs # src/Umbraco.Web/Editors/ContentTypeController.cs # src/Umbraco.Web/Editors/MacroController.cs # src/Umbraco.Web/Editors/MemberController.cs # src/Umbraco.Web/Models/RegisterModel.cs # src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs # src/Umbraco.Web/PropertyEditors/ValueConverters/MacroContainerValueConverter.cs # src/Umbraco.Web/PublishedContentExtensions.cs # src/Umbraco.Web/Trees/ContentTreeController.cs # src/Umbraco.Web/Trees/ContentTreeControllerBase.cs # src/Umbraco.Web/Trees/TreeControllerBase.cs # src/Umbraco.Web/UmbracoHelper.cs # src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx # src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs # src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.designer.cs
2018-07-11 15:58:48 +10:00
[Tree(Constants.Applications.Settings, Constants.Trees.ContentBlueprints, null, sortOrder: 10)]
2018-06-29 19:52:40 +02:00
[PluginController("UmbracoTrees")]
[CoreTree(TreeGroup = Constants.Trees.Groups.Settings)]
2018-06-29 19:52:40 +02:00
public class ContentBlueprintTreeController : TreeController
{
protected override TreeNode CreateRootNode(FormDataCollection queryStrings)
{
var root = base.CreateRootNode(queryStrings);
//this will load in a custom UI instead of the dashboard for the root node
root.RoutePath = string.Format("{0}/{1}/{2}", Constants.Applications.Settings, Constants.Trees.ContentBlueprints, "intro");
return root;
}
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{
var nodes = new TreeNodeCollection();
//get all blueprints
var entities = Services.EntityService.GetChildren(Constants.System.Root, UmbracoObjectTypes.DocumentBlueprint).ToArray();
//check if we're rendering the root in which case we'll render the content types that have blueprints
if (id == Constants.System.Root.ToInvariantString())
{
//get all blueprint content types
var contentTypeAliases = entities.Select(x => ((ContentEntitySlim) x).ContentTypeAlias).Distinct();
//get the ids
var contentTypeIds = Services.ContentTypeService.GetAllContentTypeIds(contentTypeAliases.ToArray()).ToArray();
//now get the entities ... it's a bit round about but still smaller queries than getting all document types
var docTypeEntities = contentTypeIds.Length == 0
? new IUmbracoEntity[0]
: Services.EntityService.GetAll(UmbracoObjectTypes.DocumentType, contentTypeIds).ToArray();
nodes.AddRange(docTypeEntities
.Select(entity =>
{
var treeNode = CreateTreeNode(entity, Constants.ObjectTypes.DocumentBlueprint, id, queryStrings, "icon-item-arrangement", true);
treeNode.Path = string.Format("-1,{0}", entity.Id);
treeNode.NodeType = "document-type-blueprints";
//TODO: This isn't the best way to ensure a noop process for clicking a node but it works for now.
treeNode.AdditionalData["jsClickCallback"] = "javascript:void(0);";
return treeNode;
}));
return nodes;
}
var intId = id.TryConvertTo<int>();
//Get the content type
var ct = Services.ContentTypeService.Get(intId.Result);
if (ct == null) return nodes;
var blueprintsForDocType = entities.Where(x => ct.Alias == ((ContentEntitySlim) x).ContentTypeAlias);
nodes.AddRange(blueprintsForDocType
.Select(entity =>
{
var treeNode = CreateTreeNode(entity, Constants.ObjectTypes.DocumentBlueprint, id, queryStrings, "icon-blueprint", false);
treeNode.Path = $"-1,{ct.Id},{entity.Id}";
return treeNode;
}));
return nodes;
}
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();
if (id == Constants.System.Root.ToInvariantString())
{
// 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)), true);
return menu;
}
var cte = Services.EntityService.Get(int.Parse(id), UmbracoObjectTypes.DocumentType);
//only refresh & create if it's a content type
if (cte != null)
{
var ct = Services.ContentTypeService.Get(cte.Id);
var createItem = menu.Items.Add<ActionCreateBlueprintFromContent>(Services.TextService.Localize($"actions/{ActionCreateBlueprintFromContent.Instance.Alias}"));
createItem.NavigateToRoute("/settings/contentBlueprints/edit/-1?create=true&doctype=" + ct.Alias);
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize($"actions/{ActionRefresh.Instance.Alias}"), true);
return menu;
}
menu.Items.Add<ActionDelete>(Services.TextService.Localize($"actions/{ActionDelete.Instance.Alias}"));
return menu;
}
}
}