2021-02-23 16:09:36 +01:00
|
|
|
using System;
|
2020-06-07 09:34:32 +02:00
|
|
|
using System.Collections.Concurrent;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core;
|
2021-02-23 16:09:36 +01:00
|
|
|
using Umbraco.Cms.Core.Events;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Core.Trees;
|
|
|
|
|
using Umbraco.Extensions;
|
2020-06-07 09:34:32 +02:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Web.BackOffice.Trees
|
2020-06-07 09:34:32 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The base controller for all tree requests
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class TreeController : TreeControllerBase
|
|
|
|
|
{
|
|
|
|
|
private static readonly ConcurrentDictionary<Type, TreeAttribute> _treeAttributeCache = new ConcurrentDictionary<Type, TreeAttribute>();
|
|
|
|
|
|
|
|
|
|
private readonly TreeAttribute _treeAttribute;
|
|
|
|
|
|
2020-06-09 07:49:26 +02:00
|
|
|
protected ILocalizedTextService LocalizedTextService { get; }
|
2020-06-07 09:34:32 +02:00
|
|
|
|
2021-02-23 16:09:36 +01:00
|
|
|
protected TreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IEventAggregator eventAggregator)
|
|
|
|
|
: base(umbracoApiControllerTypeCollection, eventAggregator)
|
2020-06-07 09:34:32 +02:00
|
|
|
{
|
2020-06-09 07:49:26 +02:00
|
|
|
LocalizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
|
2020-06-07 09:34:32 +02:00
|
|
|
_treeAttribute = GetTreeAttribute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2020-06-09 07:49:26 +02:00
|
|
|
public override string RootNodeDisplayName => Tree.GetRootNodeDisplayName(this, LocalizedTextService);
|
2020-06-07 09:34:32 +02:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override string TreeGroup => _treeAttribute.TreeGroup;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override string TreeAlias => _treeAttribute.TreeAlias;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override string TreeTitle => _treeAttribute.TreeTitle;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override TreeUse TreeUse => _treeAttribute.TreeUse;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override string SectionAlias => _treeAttribute.SectionAlias;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override int SortOrder => _treeAttribute.SortOrder;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override bool IsSingleNodeTree => _treeAttribute.IsSingleNodeTree;
|
|
|
|
|
|
|
|
|
|
private TreeAttribute GetTreeAttribute()
|
|
|
|
|
{
|
|
|
|
|
return _treeAttributeCache.GetOrAdd(GetType(), type =>
|
|
|
|
|
{
|
|
|
|
|
var treeAttribute = type.GetCustomAttribute<TreeAttribute>(false);
|
|
|
|
|
if (treeAttribute == null)
|
|
|
|
|
throw new InvalidOperationException("The Tree controller is missing the " + typeof(TreeAttribute).FullName + " attribute");
|
|
|
|
|
return treeAttribute;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|