Separated TreeNode stuff from the commonMapper to allow move of more mappers

This commit is contained in:
Bjarke Berg
2020-02-26 10:33:05 +01:00
parent 57aa93959a
commit 8d76499969
12 changed files with 95 additions and 41 deletions
@@ -1,18 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;
using Umbraco.Core.Models.Identity;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services;
using Umbraco.Web.ContentApps;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Trees;
using UserProfile = Umbraco.Web.Models.ContentEditing.UserProfile;
namespace Umbraco.Web.Models.Mapping
@@ -23,17 +20,15 @@ namespace Umbraco.Web.Models.Mapping
private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider;
private readonly ContentAppFactoryCollection _contentAppDefinitions;
private readonly ILocalizedTextService _localizedTextService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
public CommonMapper(IUserService userService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor,
ContentAppFactoryCollection contentAppDefinitions, ILocalizedTextService localizedTextService, IHttpContextAccessor httpContextAccessor)
ContentAppFactoryCollection contentAppDefinitions, ILocalizedTextService localizedTextService)
{
_userService = userService;
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
_contentAppDefinitions = contentAppDefinitions;
_localizedTextService = localizedTextService;
_httpContextAccessor = httpContextAccessor;
_umbracoContextAccessor = umbracoContextAccessor;
}
@@ -64,25 +59,6 @@ namespace Umbraco.Web.Models.Mapping
return null;
}
public string GetTreeNodeUrl<TController>(IContentBase source)
where TController : ContentTreeControllerBase
{
var httpContext = _httpContextAccessor.HttpContext;
if (httpContext == null) return null;
var urlHelper = new UrlHelper(httpContext.Request.RequestContext);
return urlHelper.GetUmbracoApiService<TController>(controller => controller.GetTreeNode(source.Key.ToString("N"), null));
}
public string GetMemberTreeNodeUrl(IContentBase source)
{
var httpContext = _httpContextAccessor.HttpContext;
if (httpContext == null) return null;
var urlHelper = new UrlHelper(httpContext.Request.RequestContext);
return urlHelper.GetUmbracoApiService<MemberTreeController>(controller => controller.GetTreeNode(source.Key.ToString("N"), null));
}
public IEnumerable<ContentApp> GetContentApps(IContentBase source)
{
var apps = _contentAppDefinitions.GetContentAppsFor(source).ToArray();
@@ -11,7 +11,7 @@ using Umbraco.Examine;
namespace Umbraco.Web.Models.Mapping
{
internal class EntityMapDefinition : IMapDefinition
public class EntityMapDefinition : IMapDefinition
{
public void DefineMaps(UmbracoMapper mapper)
{
@@ -236,7 +236,7 @@ namespace Umbraco.Web.Models.Mapping
return memberEntity.ContentTypeIcon.IfNullOrWhiteSpace(Constants.Icons.Member);
case IContentEntitySlim contentEntity:
// NOTE: this case covers both content and media entities
return contentEntity.ContentTypeIcon;
return contentEntity.ContentTypeIcon;
}
return null;
@@ -32,6 +32,7 @@ namespace Umbraco.Web.Composing.CompositionExtensions
.Add<IdentityMapDefinition>();;
composition.Register<CommonMapper>();
composition.Register<CommonTreeNodeMapper>();
composition.Register<MemberTabsAndPropertiesMapper>();
return composition;
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services;
using Umbraco.Web.ContentApps;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Trees;
using Umbraco.Web.WebApi;
using UserProfile = Umbraco.Web.Models.ContentEditing.UserProfile;
namespace Umbraco.Web.Models.Mapping
{
public class CommonTreeNodeMapper
{
private readonly IHttpContextAccessor _httpContextAccessor;
public CommonTreeNodeMapper(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public string GetTreeNodeUrl<TController>(IContentBase source)
where TController : UmbracoApiController, ITreeNodeController
{
var httpContext = _httpContextAccessor.HttpContext;
if (httpContext == null) return null;
var urlHelper = new UrlHelper(httpContext.Request.RequestContext);
return urlHelper.GetUmbracoApiService<TController>(controller => controller.GetTreeNode(source.Key.ToString("N"), null));
}
}
}
@@ -21,6 +21,7 @@ namespace Umbraco.Web.Models.Mapping
internal class ContentMapDefinition : IMapDefinition
{
private readonly CommonMapper _commonMapper;
private readonly CommonTreeNodeMapper _commonTreeNodeMapper;
private readonly ICultureDictionary _cultureDictionary;
private readonly ILocalizedTextService _localizedTextService;
private readonly IContentService _contentService;
@@ -41,11 +42,12 @@ namespace Umbraco.Web.Models.Mapping
private readonly ContentVariantMapper _contentVariantMapper;
public ContentMapDefinition(CommonMapper commonMapper, ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService, IContentService contentService, IContentTypeService contentTypeService,
public ContentMapDefinition(CommonMapper commonMapper, CommonTreeNodeMapper commonTreeNodeMapper, ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService, IContentService contentService, IContentTypeService contentTypeService,
IFileService fileService, IUmbracoContextAccessor umbracoContextAccessor, IPublishedRouter publishedRouter, ILocalizationService localizationService, ILogger logger,
IUserService userService, IVariationContextAccessor variationContextAccessor, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, UriUtility uriUtility, IPublishedUrlProvider publishedUrlProvider, IEntityService entityService)
{
_commonMapper = commonMapper;
_commonTreeNodeMapper = commonTreeNodeMapper;
_cultureDictionary = cultureDictionary;
_localizedTextService = localizedTextService;
_contentService = contentService;
@@ -105,7 +107,7 @@ namespace Umbraco.Web.Models.Mapping
target.TemplateAlias = GetDefaultTemplate(source);
target.TemplateId = source.TemplateId ?? default;
target.Trashed = source.Trashed;
target.TreeNodeUrl = _commonMapper.GetTreeNodeUrl<ContentTreeController>(source);
target.TreeNodeUrl = _commonTreeNodeMapper.GetTreeNodeUrl<ContentTreeController>(source);
target.Udi = Udi.Create(source.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document, source.Key);
target.UpdateDate = source.UpdateDate;
target.Updater = _commonMapper.GetCreator(source, context);
@@ -18,16 +18,18 @@ namespace Umbraco.Web.Models.Mapping
public class MediaMapDefinition : IMapDefinition
{
private readonly CommonMapper _commonMapper;
private readonly CommonTreeNodeMapper _commonTreeNodeMapper;
private readonly IMediaService _mediaService;
private readonly IMediaTypeService _mediaTypeService;
private readonly MediaUrlGeneratorCollection _mediaUrlGenerators;
private readonly TabsAndPropertiesMapper<IMedia> _tabsAndPropertiesMapper;
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
public MediaMapDefinition(ICultureDictionary cultureDictionary, CommonMapper commonMapper, IMediaService mediaService, IMediaTypeService mediaTypeService,
public MediaMapDefinition(ICultureDictionary cultureDictionary, CommonMapper commonMapper, CommonTreeNodeMapper commonTreeNodeMapper, IMediaService mediaService, IMediaTypeService mediaTypeService,
ILocalizedTextService localizedTextService, MediaUrlGeneratorCollection mediaUrlGenerators, IUmbracoSettingsSection umbracoSettingsSection, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider)
{
_commonMapper = commonMapper;
_commonTreeNodeMapper = commonTreeNodeMapper;
_mediaService = mediaService;
_mediaTypeService = mediaTypeService;
_mediaUrlGenerators = mediaUrlGenerators;
@@ -71,7 +73,7 @@ namespace Umbraco.Web.Models.Mapping
target.State = null;
target.Tabs = _tabsAndPropertiesMapper.Map(source, context);
target.Trashed = source.Trashed;
target.TreeNodeUrl = _commonMapper.GetTreeNodeUrl<MediaTreeController>(source);
target.TreeNodeUrl = _commonTreeNodeMapper.GetTreeNodeUrl<MediaTreeController>(source);
target.Udi = Udi.Create(Constants.UdiEntityType.Media, source.Key);
target.UpdateDate = source.UpdateDate;
target.VariesByCulture = source.ContentType.VariesByCulture();
@@ -1,7 +1,9 @@
using Umbraco.Core;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Trees;
namespace Umbraco.Web.Models.Mapping
{
@@ -11,13 +13,17 @@ namespace Umbraco.Web.Models.Mapping
public class MemberMapDefinition : IMapDefinition
{
private readonly CommonMapper _commonMapper;
private readonly CommonTreeNodeMapper _commonTreeNodeMapper;
private readonly MemberTabsAndPropertiesMapper _tabsAndPropertiesMapper;
private readonly IHttpContextAccessor _httpContextAccessor;
public MemberMapDefinition(CommonMapper commonMapper, MemberTabsAndPropertiesMapper tabsAndPropertiesMapper)
public MemberMapDefinition(CommonMapper commonMapper, CommonTreeNodeMapper commonTreeNodeMapper, MemberTabsAndPropertiesMapper tabsAndPropertiesMapper, IHttpContextAccessor httpContextAccessor)
{
_commonMapper = commonMapper;
_commonTreeNodeMapper = commonTreeNodeMapper;
_tabsAndPropertiesMapper = tabsAndPropertiesMapper;
_httpContextAccessor = httpContextAccessor;
}
public void DefineMaps(UmbracoMapper mapper)
@@ -48,7 +54,7 @@ namespace Umbraco.Web.Models.Mapping
target.SortOrder = source.SortOrder;
target.State = null;
target.Tabs = _tabsAndPropertiesMapper.Map(source, context);
target.TreeNodeUrl = _commonMapper.GetMemberTreeNodeUrl(source);
target.TreeNodeUrl = _commonTreeNodeMapper.GetTreeNodeUrl<MemberTreeController>(source);
target.Udi = Udi.Create(Constants.UdiEntityType.Member, source.Key);
target.UpdateDate = source.UpdateDate;
target.Username = source.Username;
@@ -92,5 +98,7 @@ namespace Umbraco.Web.Models.Mapping
target.Properties = context.MapEnumerable<IProperty, ContentPropertyDto>(source.Properties);
}
}
}
@@ -12,7 +12,6 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.WebApi.Filters;
using System.Globalization;
using Umbraco.Core.Models.Entities;
using System.Web.Http.ModelBinding;
using Umbraco.Web.Actions;
@@ -26,7 +25,7 @@ using Umbraco.Web.Routing;
namespace Umbraco.Web.Trees
{
public abstract class ContentTreeControllerBase : TreeController
public abstract class ContentTreeControllerBase : TreeController, ITreeNodeController
{
public IMenuItemCollectionFactory MenuItemCollectionFactory { get; }
@@ -0,0 +1,22 @@
using System.Net.Http.Formatting;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.WebApi.Filters;
using System.Web.Http.ModelBinding;
namespace Umbraco.Web.Trees
{
/// <summary>
/// Represents an TreeNodeController
/// </summary>
public interface ITreeNodeController
{
/// <summary>
/// Gets an individual tree node
/// </summary>
/// <param name="id"></param>
/// <param name="queryStrings"></param>
/// <returns></returns>
TreeNode GetTreeNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]
FormDataCollection queryStrings);
}
}
+1 -1
View File
@@ -37,7 +37,7 @@ namespace Umbraco.Web.Trees
[PluginController("UmbracoTrees")]
[CoreTree]
[SearchableTree("searchResultFormatter", "configureMediaResult", 20)]
public class MediaTreeController : ContentTreeControllerBase, ISearchableTree
public class MediaTreeController : ContentTreeControllerBase, ISearchableTree, ITreeNodeController
{
private readonly UmbracoTreeSearcher _treeSearcher;
@@ -37,7 +37,7 @@ namespace Umbraco.Web.Trees
[PluginController("UmbracoTrees")]
[CoreTree]
[SearchableTree("searchResultFormatter", "configureMemberResult")]
public class MemberTreeController : TreeController, ISearchableTree
public class MemberTreeController : TreeController, ISearchableTree, ITreeNodeController
{
+5 -2
View File
@@ -55,6 +55,9 @@
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>C:\Users\Bjarke\.nuget\packages\microsoft.aspnet.mvc\5.2.7\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Services" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
@@ -167,9 +170,8 @@
<Compile Include="Models\Identity\IdentityMapDefinition.cs" />
<Compile Include="Models\Identity\IdentityUser.cs" />
<Compile Include="Models\Identity\UserLoginInfoWrapper.cs" />
<Compile Include="Models\Mapping\CommonMapper.cs" />
<Compile Include="Models\Mapping\CommonTreeNodeMapper.cs" />
<Compile Include="Models\Mapping\ContentMapDefinition.cs" />
<Compile Include="Models\Mapping\EntityMapDefinition.cs" />
<Compile Include="Models\Mapping\MediaMapDefinition.cs" />
<Compile Include="Models\Mapping\MemberMapDefinition.cs" />
<Compile Include="Models\Membership\UmbracoMembershipMember.cs" />
@@ -203,6 +205,7 @@
<Compile Include="Security\UmbracoMembershipProviderBase.cs" />
<Compile Include="Security\UserAwarePasswordHasher.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="Trees\ITreeNodeController.cs" />
<Compile Include="Trees\TreeCollectionBuilder.cs" />
<Compile Include="UmbracoContext.cs" />
<Compile Include="UmbracoContextFactory.cs" />