New backoffice: Cleanup management API routes (#13296)
* Rename ModelsBuilderDashboard folder to ModelsBuilder * Fix modelsbuilder paths and related naming * Rename analytics route to telemetry * Fix controller bases - routes and tags * Fix items route * Fix more controllerbase routes * Fix route * Fix OpenApi file * Merging DictionaryItem and Dictionary * Fix TrackedReferences naming * Update OpenApi file * Rename Analytics* related types to Telemetry* * New Backoffice: Return AnalyticsLevelViewModel from Telemetry/ (#13298) * Return TelemetryLevelViewModel instead of TelemetryLevel * Fix schema * Change telemetry/current to telemetry/level (cherry picked from commit f2b8494c669cbbf04b623753abbf1be211973aa9) * Add contants for tree and recycle-bin subpaths (cherry picked from commit 4449f56bc00832ea6d357a3854b454791c80e0e2) Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
This commit is contained in:
committed by
GitHub
parent
86d9e51039
commit
6ff4d27d47
@@ -0,0 +1,53 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NSwag.Annotations;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.ManagementApi.Controllers.Tree;
|
||||
using Umbraco.Cms.ManagementApi.ViewModels.Tree;
|
||||
using Umbraco.New.Cms.Web.Common.Routing;
|
||||
|
||||
namespace Umbraco.Cms.ManagementApi.Controllers.Dictionary.Tree;
|
||||
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[VersionedApiBackOfficeRoute($"{Constants.Web.RoutePath.Tree}/dictionary")]
|
||||
[OpenApiTag("Dictionary")]
|
||||
// NOTE: at the moment dictionary items (renamed to dictionary tree) aren't supported by EntityService, so we have little use of the
|
||||
// tree controller base. We'll keep it though, in the hope that we can mend EntityService.
|
||||
public class DictionaryTreeControllerBase : EntityTreeControllerBase<EntityTreeItemViewModel>
|
||||
{
|
||||
public DictionaryTreeControllerBase(IEntityService entityService, ILocalizationService localizationService)
|
||||
: base(entityService) =>
|
||||
LocalizationService = localizationService;
|
||||
|
||||
// dictionary items do not currently have a known UmbracoObjectType, so we'll settle with Unknown for now
|
||||
protected override UmbracoObjectTypes ItemObjectType => UmbracoObjectTypes.Unknown;
|
||||
|
||||
protected ILocalizationService LocalizationService { get; }
|
||||
|
||||
protected EntityTreeItemViewModel[] MapTreeItemViewModels(Guid? parentKey, IDictionaryItem[] dictionaryItems)
|
||||
=> dictionaryItems.Select(dictionaryItem => new EntityTreeItemViewModel
|
||||
{
|
||||
Icon = Constants.Icons.RelationType,
|
||||
Name = dictionaryItem.ItemKey,
|
||||
Key = dictionaryItem.Key,
|
||||
Type = Constants.UdiEntityType.DictionaryItem,
|
||||
HasChildren = false,
|
||||
IsContainer = LocalizationService.GetDictionaryItemChildren(dictionaryItem.Key).Any(),
|
||||
ParentKey = parentKey
|
||||
}).ToArray();
|
||||
|
||||
// localization service does not (yet) allow pagination of dictionary items, we have to do it in memory for now
|
||||
protected IDictionaryItem[] PaginatedDictionaryItems(long pageNumber, int pageSize, IEnumerable<IDictionaryItem> allDictionaryItems, out long totalItems)
|
||||
{
|
||||
IDictionaryItem[] allDictionaryItemsAsArray = allDictionaryItems.ToArray();
|
||||
|
||||
totalItems = allDictionaryItemsAsArray.Length;
|
||||
return allDictionaryItemsAsArray
|
||||
.OrderBy(item => item.ItemKey)
|
||||
.Skip((int)pageNumber * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user