-
Notifications
You must be signed in to change notification settings - Fork 2.8k
WIP: POC for global elements (CRUD + folders + API) #19877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
AndyButland
wants to merge
15
commits into
main
Choose a base branch
from
v16/temp/element-poc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
148ac51
CRUD + folders + API
kjac b25ee76
Merge branch 'main' into v16/temp/element-poc
kjac eea3c57
Fix infinite recursion
kjac d2e0416
Distributed cache handling for Elements
kjac 70b5c52
Publishing for Elements (incl. refactor)
kjac 251b8a4
Fix bad file name
kjac fd59a8b
Added "foldersOnly" option to the siblings endpoint
kjac eadd6ec
Update src/Umbraco.Core/Models/UmbracoObjectTypes.cs
kjac 523d96a
Merge branch 'main' into v16/temp/element-poc
kjac d6b5d57
API for publishing elements
kjac 632b89d
Published element cache (WIP)
kjac ca9f0bd
Fix delete at repo level
kjac feb07a2
Fixing up a little tests
kjac 3a53a9b
Element picker property editor
kjac d7b4fad
Added tests to prove published element status
kjac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/Umbraco.Cms.Api.Management/Controllers/Element/ByKeyElementController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.ViewModels.Document; | ||
using Umbraco.Cms.Api.Management.ViewModels.Element; | ||
using Umbraco.Cms.Core.Mapping; | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element; | ||
|
||
[ApiVersion("1.0")] | ||
public class ByKeyElementController : ElementControllerBase | ||
{ | ||
private readonly IUmbracoMapper _umbracoMapper; | ||
private readonly IElementService _elementService; | ||
|
||
public ByKeyElementController(IUmbracoMapper umbracoMapper, IElementService elementService) | ||
{ | ||
_umbracoMapper = umbracoMapper; | ||
_elementService = elementService; | ||
} | ||
|
||
[HttpGet("{id:guid}")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(typeof(DocumentResponseModel), StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
public Task<IActionResult> ByKey(CancellationToken cancellationToken, Guid id) | ||
{ | ||
// TODO ELEMENTS: move logic to a presentation factory | ||
IElement? element = _elementService.GetById(id); | ||
if (element is null) | ||
{ | ||
return Task.FromResult(ContentEditingOperationStatusResult(ContentEditingOperationStatus.NotFound)); | ||
} | ||
|
||
ContentScheduleCollection contentScheduleCollection = _elementService.GetContentScheduleByContentId(id); | ||
|
||
var model = new ElementResponseModel(); | ||
_umbracoMapper.Map(element, model); | ||
_umbracoMapper.Map(contentScheduleCollection, model); | ||
|
||
return Task.FromResult<IActionResult>(Ok(model)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Umbraco.Cms.Api.Management/Controllers/Element/CreateElementController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.Factories; | ||
using Umbraco.Cms.Api.Management.ViewModels.Element; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Models.ContentEditing; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element; | ||
|
||
[ApiVersion("1.0")] | ||
public class CreateElementController : ElementControllerBase | ||
{ | ||
private readonly IElementEditingPresentationFactory _elementEditingPresentationFactory; | ||
private readonly IElementEditingService _elementEditingService; | ||
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
|
||
public CreateElementController( | ||
IElementEditingPresentationFactory elementEditingPresentationFactory, | ||
IElementEditingService elementEditingService, | ||
IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
{ | ||
_elementEditingPresentationFactory = elementEditingPresentationFactory; | ||
_elementEditingService = elementEditingService; | ||
_backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
} | ||
|
||
[HttpPost] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(StatusCodes.Status201Created)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
public async Task<IActionResult> Create(CancellationToken cancellationToken, CreateElementRequestModel requestModel) | ||
{ | ||
ElementCreateModel model = _elementEditingPresentationFactory.MapCreateModel(requestModel); | ||
Attempt<ElementCreateResult, ContentEditingOperationStatus> result = | ||
await _elementEditingService.CreateAsync(model, CurrentUserKey(_backOfficeSecurityAccessor)); | ||
|
||
return result.Success | ||
? CreatedAtId<ByKeyElementController>(controller => nameof(controller.ByKey), result.Result.Content!.Key) | ||
: ContentEditingOperationStatusResult(result.Status); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Umbraco.Cms.Api.Management/Controllers/Element/DeleteElementController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element; | ||
|
||
[ApiVersion("1.0")] | ||
public class DeleteElementController : ElementControllerBase | ||
{ | ||
private readonly IElementEditingService _elementEditingService; | ||
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
|
||
public DeleteElementController( | ||
IElementEditingService elementEditingService, | ||
IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
{ | ||
_elementEditingService = elementEditingService; | ||
_backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
} | ||
|
||
[HttpDelete("{id:guid}")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
public async Task<IActionResult> Delete(CancellationToken cancellationToken, Guid id) | ||
{ | ||
Attempt<IElement?, ContentEditingOperationStatus> result = await _elementEditingService.DeleteAsync(id, CurrentUserKey(_backOfficeSecurityAccessor)); | ||
|
||
return result.Success | ||
? Ok() | ||
: ContentEditingOperationStatusResult(result.Status); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Umbraco.Cms.Api.Management/Controllers/Element/ElementControllerBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.Controllers.Content; | ||
using Umbraco.Cms.Api.Management.Routing; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Web.Common.Authorization; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element; | ||
|
||
[VersionedApiBackOfficeRoute(Constants.UdiEntityType.Element)] | ||
[ApiExplorerSettings(GroupName = nameof(Constants.UdiEntityType.Element))] | ||
// TODO ELEMENTS: backoffice authorization policies | ||
[Authorize(Policy = AuthorizationPolicies.TreeAccessDocuments)] | ||
public class ElementControllerBase : ContentControllerBase | ||
{ | ||
} |
25 changes: 25 additions & 0 deletions
25
...o.Cms.Api.Management/Controllers/Element/Folder/ByKeyDocumentBlueprintFolderController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.ViewModels.Folder; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Services; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element.Folder; | ||
|
||
[ApiVersion("1.0")] | ||
public class ByKeyElementFolderController : ElementFolderControllerBase | ||
{ | ||
public ByKeyElementFolderController( | ||
IBackOfficeSecurityAccessor backOfficeSecurityAccessor, | ||
IElementContainerService elementContainerService) | ||
: base(backOfficeSecurityAccessor, elementContainerService) | ||
{ | ||
} | ||
|
||
[HttpGet("{id:guid}")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(typeof(FolderResponseModel), StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
public async Task<IActionResult> ByKey(CancellationToken cancellationToken, Guid id) => await GetFolderAsync(id); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Umbraco.Cms.Api.Management/Controllers/Element/Folder/CreateElementFolderController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.ViewModels.Folder; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Services; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element.Folder; | ||
|
||
[ApiVersion("1.0")] | ||
public class CreateElementFolderController : ElementFolderControllerBase | ||
{ | ||
public CreateElementFolderController( | ||
IBackOfficeSecurityAccessor backOfficeSecurityAccessor, | ||
IElementContainerService elementContainerService) | ||
: base(backOfficeSecurityAccessor, elementContainerService) | ||
{ | ||
} | ||
|
||
[HttpPost] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(StatusCodes.Status201Created)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
public async Task<IActionResult> Create(CancellationToken cancellationToken, CreateFolderRequestModel createFolderRequestModel) | ||
=> await CreateFolderAsync<ByKeyElementFolderController>( | ||
createFolderRequestModel, | ||
controller => nameof(controller.ByKey)); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Umbraco.Cms.Api.Management/Controllers/Element/Folder/DeleteElementFolderController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Services; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element.Folder; | ||
|
||
[ApiVersion("1.0")] | ||
public class DeleteElementFolderController : ElementFolderControllerBase | ||
{ | ||
public DeleteElementFolderController( | ||
IBackOfficeSecurityAccessor backOfficeSecurityAccessor, | ||
IElementContainerService elementContainerService) | ||
: base(backOfficeSecurityAccessor, elementContainerService) | ||
{ | ||
} | ||
|
||
[HttpDelete("{id:guid}")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
public async Task<IActionResult> Delete(CancellationToken cancellationToken, Guid id) => await DeleteFolderAsync(id); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Umbraco.Cms.Api.Management/Controllers/Element/Folder/ElementFolderControllerBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.Routing; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Services; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element.Folder; | ||
|
||
[VersionedApiBackOfficeRoute($"{Constants.UdiEntityType.Element}/folder")] | ||
[ApiExplorerSettings(GroupName = nameof(Constants.UdiEntityType.Element))] | ||
// TODO ELEMENTS: backoffice authorization policies | ||
public abstract class ElementFolderControllerBase : FolderManagementControllerBase<IElement> | ||
{ | ||
protected ElementFolderControllerBase( | ||
IBackOfficeSecurityAccessor backOfficeSecurityAccessor, | ||
IElementContainerService elementContainerService) | ||
: base(backOfficeSecurityAccessor, elementContainerService) | ||
{ | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Umbraco.Cms.Api.Management/Controllers/Element/Folder/UpdateElementFolderController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.ViewModels.Folder; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Services; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element.Folder; | ||
|
||
[ApiVersion("1.0")] | ||
public class UpdateElementFolderController : ElementFolderControllerBase | ||
{ | ||
public UpdateElementFolderController( | ||
IBackOfficeSecurityAccessor backOfficeSecurityAccessor, | ||
IElementContainerService elementContainerService) | ||
: base(backOfficeSecurityAccessor, elementContainerService) | ||
{ | ||
} | ||
|
||
[HttpPut("{id:guid}")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
public async Task<IActionResult> Update(CancellationToken cancellationToken, Guid id, UpdateFolderResponseModel updateFolderResponseModel) | ||
=> await UpdateFolderAsync(id, updateFolderResponseModel); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Umbraco.Cms.Api.Management/Controllers/Element/Tree/AncestorsElementTreeController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.ViewModels.Tree; | ||
using Umbraco.Cms.Core.Mapping; | ||
using Umbraco.Cms.Core.Services; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element.Tree; | ||
|
||
[ApiVersion("1.0")] | ||
public class AncestorsElementTreeController : ElementTreeControllerBase | ||
{ | ||
public AncestorsElementTreeController(IEntityService entityService, IUmbracoMapper umbracoMapper) | ||
: base(entityService, umbracoMapper) | ||
{ | ||
} | ||
|
||
[HttpGet("ancestors")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(typeof(IEnumerable<ElementTreeItemResponseModel>), StatusCodes.Status200OK)] | ||
public async Task<ActionResult<IEnumerable<ElementTreeItemResponseModel>>> Ancestors(CancellationToken cancellationToken, Guid descendantId) | ||
=> await GetAncestors(descendantId); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Umbraco.Cms.Api.Management/Controllers/Element/Tree/ChildrenElementTreeController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Common.ViewModels.Pagination; | ||
using Umbraco.Cms.Api.Management.ViewModels.Tree; | ||
using Umbraco.Cms.Core.Mapping; | ||
using Umbraco.Cms.Core.Services; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element.Tree; | ||
|
||
[ApiVersion("1.0")] | ||
public class ChildrenElementTreeController : ElementTreeControllerBase | ||
{ | ||
public ChildrenElementTreeController(IEntityService entityService, IUmbracoMapper umbracoMapper) | ||
: base(entityService, umbracoMapper) | ||
{ | ||
} | ||
|
||
[HttpGet("children")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(typeof(PagedViewModel<ElementTreeItemResponseModel>), StatusCodes.Status200OK)] | ||
public async Task<ActionResult<PagedViewModel<ElementTreeItemResponseModel>>> Children(CancellationToken cancellationToken, Guid parentId, int skip = 0, int take = 100, bool foldersOnly = false) | ||
kjac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
RenderFoldersOnly(foldersOnly); | ||
return await GetChildren(parentId, skip, take); | ||
} | ||
Check warning on line 26 in src/Umbraco.Cms.Api.Management/Controllers/Element/Tree/ChildrenElementTreeController.cs
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/Umbraco.Cms.Api.Management/Controllers/Element/Tree/ElementTreeControllerBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.Controllers.Tree; | ||
using Umbraco.Cms.Api.Management.Routing; | ||
using Umbraco.Cms.Api.Management.ViewModels.DocumentType; | ||
using Umbraco.Cms.Api.Management.ViewModels.Tree; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Mapping; | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.Models.Entities; | ||
using Umbraco.Cms.Core.Services; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Element.Tree; | ||
|
||
[VersionedApiBackOfficeRoute($"{Constants.Web.RoutePath.Tree}/{Constants.UdiEntityType.Element}")] | ||
[ApiExplorerSettings(GroupName = nameof(Constants.UdiEntityType.Element))] | ||
// TODO ELEMENTS: backoffice authorization policies | ||
public class ElementTreeControllerBase : FolderTreeControllerBase<ElementTreeItemResponseModel> | ||
{ | ||
private readonly IUmbracoMapper _umbracoMapper; | ||
|
||
public ElementTreeControllerBase(IEntityService entityService, IUmbracoMapper umbracoMapper) | ||
: base(entityService) | ||
=> _umbracoMapper = umbracoMapper; | ||
|
||
protected override UmbracoObjectTypes ItemObjectType => UmbracoObjectTypes.Element; | ||
|
||
protected override UmbracoObjectTypes FolderObjectType => UmbracoObjectTypes.ElementContainer; | ||
|
||
protected override Ordering ItemOrdering | ||
{ | ||
get | ||
{ | ||
var ordering = Ordering.By(nameof(Infrastructure.Persistence.Dtos.NodeDto.NodeObjectType), Direction.Descending); // We need to override to change direction | ||
ordering.Next = Ordering.By(nameof(Infrastructure.Persistence.Dtos.NodeDto.Text)); | ||
|
||
return ordering; | ||
} | ||
} | ||
|
||
protected override ElementTreeItemResponseModel[] MapTreeItemViewModels(Guid? parentKey, IEntitySlim[] entities) | ||
=> entities.Select(entity => | ||
{ | ||
ElementTreeItemResponseModel responseModel = MapTreeItemViewModel(parentKey, entity); | ||
if (entity is IContentEntitySlim contentEntitySlim) | ||
{ | ||
responseModel.HasChildren = entity.HasChildren; | ||
responseModel.ElementType = _umbracoMapper.Map<DocumentTypeReferenceResponseModel>(contentEntitySlim)!; | ||
} | ||
|
||
return responseModel; | ||
}).ToArray(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.