Adds in new API endpoint in Content Editor - GetContentSortOrder (same logic & SortNode class from the WebService) - this may need to change depending on JSON structure required

This commit is contained in:
Warren
2018-08-02 14:25:46 +01:00
parent fee48e9dee
commit 67b348df92
3 changed files with 57 additions and 3 deletions

View File

@@ -25,12 +25,10 @@ using Umbraco.Core.Persistence.Querying;
using Umbraco.Web.PublishedCache;
using Umbraco.Core.Events;
using Umbraco.Core.Models.Validation;
using Umbraco.Web.Models;
using Umbraco.Web.WebServices;
using Umbraco.Web._Legacy.Actions;
using Constants = Umbraco.Core.Constants;
using ContentVariation = Umbraco.Core.Models.ContentVariation;
using Language = Umbraco.Web.Models.ContentEditing.Language;
using SortNode = Umbraco.Web.Models.ContentEditing.SortNode;
namespace Umbraco.Web.Editors
{
@@ -957,6 +955,35 @@ namespace Umbraco.Web.Editors
return Request.CreateNotificationSuccessResponse(Services.TextService.Localize("defaultdialogs/recycleBinIsEmpty"));
}
/// <summary>
/// Gets child nodes of the current node (parentId) to be sorted
/// </summary>
/// <param name="parentId">The current node in which to sort its children</param>
/// <returns></returns>
[HttpGet]
public SortNode GetContentSortOrder(int parentId)
{
var nodes = new List<SortNode>();
var parent = new SortNode { Id = parentId };
var entityService = Services.EntityService;
// Root node
if (parentId == -1)
{
var rootContent = entityService.GetRootEntities(UmbracoObjectTypes.Document);
nodes.AddRange(rootContent.Select(content => new SortNode(content.Id, content.SortOrder, content.Name, content.CreateDate)));
}
else
{
var children = entityService.GetChildren(parentId);
nodes.AddRange(children.Select(child => new SortNode(child.Id, child.SortOrder, child.Name, child.CreateDate)));
}
parent.SortNodes = nodes.ToArray();
return parent;
}
/// <summary>
/// Change the sort order for content
/// </summary>

View File

@@ -0,0 +1,26 @@
using System;
namespace Umbraco.Web.Models.ContentEditing
{
[Serializable]
public class SortNode
{
public int Id { get; set; }
public int SortOrder { get; set; }
public string Name { get; set; }
public DateTime CreateDate { get; set; }
public SortNode[] SortNodes { get; set; }
public SortNode()
{
}
public SortNode(int id, int sortOrder, string name, DateTime createDate)
{
Id = Id;
SortOrder = sortOrder;
Name = name;
CreateDate = createDate;
}
}
}

View File

@@ -226,6 +226,7 @@
<Compile Include="Models\ContentEditing\Permission.cs" />
<Compile Include="Models\ContentEditing\PostedFolder.cs" />
<Compile Include="Models\ContentEditing\SnippetDisplay.cs" />
<Compile Include="Models\ContentEditing\SortNode.cs" />
<Compile Include="Models\ContentEditing\TemplateDisplay.cs" />
<Compile Include="Models\ContentEditing\TreeSearchResult.cs" />
<Compile Include="Models\ContentEditing\UserDisplay.cs" />