Replaced static events in TreeControllerBase with IEventAggregator notifications

This commit is contained in:
Kenn Jacobsen
2021-02-23 16:09:36 +01:00
parent 7ecb141581
commit b05d71f76c
35 changed files with 195 additions and 175 deletions

View File

@@ -265,7 +265,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
}
var controller = (TreeControllerBase)result.Value;
var rootNodeResult = controller.GetRootNode(querystring);
var rootNodeResult = await controller.GetRootNode(querystring);
if (!(rootNodeResult.Result is null))
{
return rootNodeResult.Result;
@@ -305,7 +305,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
}
var controller = (TreeControllerBase)controllerResult.Value;
return controller.GetNodes(id.ToInvariantString(), querystring);
return await controller.GetNodes(id.ToInvariantString(), querystring);
}
/// <summary>

View File

@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Core.Models.Trees;
@@ -40,8 +41,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
IMenuItemCollectionFactory menuItemCollectionFactory,
IContentService contentService,
IContentTypeService contentTypeService,
IEntityService entityService)
: base(localizedTextService, umbracoApiControllerTypeCollection)
IEntityService entityService,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory ?? throw new ArgumentNullException(nameof(menuItemCollectionFactory));
_contentService = contentService ?? throw new ArgumentNullException(nameof(contentService));

View File

@@ -9,6 +9,7 @@ using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Entities;
@@ -58,8 +59,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
IOptions<GlobalSettings> globalSettings,
IContentService contentService,
IPublicAccessService publicAccessService,
ILocalizationService localizationService)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, entityService, backofficeSecurityAccessor, logger, actionCollection, userService, dataTypeService)
ILocalizationService localizationService,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, entityService, backofficeSecurityAccessor, logger, actionCollection, userService, dataTypeService, eventAggregator)
{
_treeSearcher = treeSearcher;
_actions = actions;

View File

@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Core.Models.Trees;
@@ -39,9 +40,10 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
ILogger<ContentTreeControllerBase> logger,
ActionCollection actionCollection,
IUserService userService,
IDataTypeService dataTypeService
IDataTypeService dataTypeService,
IEventAggregator eventAggregator
)
: base(localizedTextService, umbracoApiControllerTypeCollection)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_entityService = entityService;
_backofficeSecurityAccessor = backofficeSecurityAccessor;

View File

@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Trees;
@@ -30,7 +31,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
private readonly IContentTypeService _contentTypeService;
private readonly IEntityService _entityService;
public ContentTypeTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, UmbracoTreeSearcher treeSearcher, IMenuItemCollectionFactory menuItemCollectionFactory, IContentTypeService contentTypeService, IEntityService entityService) : base(localizedTextService, umbracoApiControllerTypeCollection)
public ContentTypeTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, UmbracoTreeSearcher treeSearcher, IMenuItemCollectionFactory menuItemCollectionFactory, IContentTypeService contentTypeService, IEntityService entityService, IEventAggregator eventAggregator) : base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_treeSearcher = treeSearcher;
_menuItemCollectionFactory = menuItemCollectionFactory;

View File

@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Trees;
@@ -31,7 +32,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
private readonly IDataTypeService _dataTypeService;
public DataTypeTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, UmbracoTreeSearcher treeSearcher, IMenuItemCollectionFactory menuItemCollectionFactory, IEntityService entityService, IDataTypeService dataTypeService) : base(localizedTextService, umbracoApiControllerTypeCollection)
public DataTypeTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, UmbracoTreeSearcher treeSearcher, IMenuItemCollectionFactory menuItemCollectionFactory, IEntityService entityService, IDataTypeService dataTypeService, IEventAggregator eventAggregator) : base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_treeSearcher = treeSearcher;
_menuItemCollectionFactory = menuItemCollectionFactory;

View File

@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Trees;
using Umbraco.Cms.Core.Services;
@@ -28,7 +29,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
private readonly ILocalizationService _localizationService;
public DictionaryTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IMenuItemCollectionFactory menuItemCollectionFactory, ILocalizationService localizationService) : base(localizedTextService, umbracoApiControllerTypeCollection)
public DictionaryTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IMenuItemCollectionFactory menuItemCollectionFactory, ILocalizationService localizationService, IEventAggregator eventAggregator) : base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory;
_localizationService = localizationService;

View File

@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Models.Trees;
using Umbraco.Cms.Core.Services;
@@ -20,9 +21,10 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
protected FileSystemTreeController(
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory
IMenuItemCollectionFactory menuItemCollectionFactory,
IEventAggregator eventAggregator
)
: base(localizedTextService, umbracoApiControllerTypeCollection)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
MenuItemCollectionFactory = menuItemCollectionFactory;
}

View File

@@ -1,4 +1,5 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
@@ -18,8 +19,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
IPhysicalFileSystem fileSystem)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory)
IPhysicalFileSystem fileSystem,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, eventAggregator)
{
FileSystem = fileSystem;
}

View File

@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.Common.Attributes;
@@ -19,8 +20,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
public LanguageTreeController(
ILocalizedTextService textService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection)
: base(textService, umbracoApiControllerTypeCollection)
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IEventAggregator eventAggregator)
: base(textService, umbracoApiControllerTypeCollection, eventAggregator)
{
}
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)

View File

@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.Common.Attributes;
@@ -18,8 +19,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
{
public LogViewerTreeController(
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection)
: base(localizedTextService, umbracoApiControllerTypeCollection)
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
}

View File

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.Trees;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
@@ -22,7 +23,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
private readonly IMacroService _macroService;
public MacrosTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IMenuItemCollectionFactory menuItemCollectionFactory, IMacroService macroService) : base(localizedTextService, umbracoApiControllerTypeCollection)
public MacrosTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IMenuItemCollectionFactory menuItemCollectionFactory, IMacroService macroService, IEventAggregator eventAggregator) : base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory;
_macroService = macroService;

View File

@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Entities;
@@ -45,8 +46,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
IUserService userService,
IDataTypeService dataTypeService,
UmbracoTreeSearcher treeSearcher,
IMediaService mediaService)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, entityService, backofficeSecurityAccessor, logger, actionCollection, userService, dataTypeService)
IMediaService mediaService,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, entityService, backofficeSecurityAccessor, logger, actionCollection, userService, dataTypeService, eventAggregator)
{
_treeSearcher = treeSearcher;
_mediaService = mediaService;

View File

@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Trees;
@@ -30,7 +31,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
private readonly IMediaTypeService _mediaTypeService;
private readonly IEntityService _entityService;
public MediaTypeTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, UmbracoTreeSearcher treeSearcher, IMenuItemCollectionFactory menuItemCollectionFactory, IMediaTypeService mediaTypeService, IEntityService entityService) : base(localizedTextService, umbracoApiControllerTypeCollection)
public MediaTypeTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, UmbracoTreeSearcher treeSearcher, IMenuItemCollectionFactory menuItemCollectionFactory, IMediaTypeService mediaTypeService, IEntityService entityService, IEventAggregator eventAggregator) : base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_treeSearcher = treeSearcher;
_menuItemCollectionFactory = menuItemCollectionFactory;

View File

@@ -1,9 +1,10 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.Common.Attributes;
@@ -24,8 +25,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
IMemberGroupService memberGroupService)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory)
IMemberGroupService memberGroupService,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, eventAggregator)
{
_memberGroupService = memberGroupService;
}

View File

@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Trees;
@@ -41,8 +42,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
IMenuItemCollectionFactory menuItemCollectionFactory,
IMemberService memberService,
IMemberTypeService memberTypeService,
IBackOfficeSecurityAccessor backofficeSecurityAccessor)
: base(localizedTextService, umbracoApiControllerTypeCollection)
IBackOfficeSecurityAccessor backofficeSecurityAccessor,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_treeSearcher = treeSearcher;
_menuItemCollectionFactory = menuItemCollectionFactory;

View File

@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.Trees;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
@@ -20,8 +21,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
protected MemberTypeAndGroupTreeControllerBase(
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory)
: base(localizedTextService, umbracoApiControllerTypeCollection)
IMenuItemCollectionFactory menuItemCollectionFactory,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
MenuItemCollectionFactory = menuItemCollectionFactory;
}

View File

@@ -1,9 +1,10 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Services;
@@ -29,8 +30,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
UmbracoTreeSearcher treeSearcher,
IMemberTypeService memberTypeService)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory)
IMemberTypeService memberTypeService,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, eventAggregator)
{
_treeSearcher = treeSearcher;
_memberTypeService = memberTypeService;

View File

@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Http;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Trees;
namespace Umbraco.Cms.Web.BackOffice.Trees
{
/// <summary>
/// A notification that allows developers to modify the menu that is being rendered
/// </summary>
/// <remarks>
/// Developers can add/remove/replace/insert/update/etc... any of the tree items in the collection.
/// </remarks>
public class MenuRendering : INotification
{
public MenuRendering(string nodeId, MenuItemCollection menu, FormCollection queryStrings)
{
NodeId = nodeId;
Menu = menu;
QueryStrings = queryStrings;
}
/// <summary>
/// The tree node id that the menu is rendering for
/// </summary>
public string NodeId { get; }
/// <summary>
/// The menu being rendered
/// </summary>
public MenuItemCollection Menu { get; }
public FormCollection QueryStrings { get; }
}
}

View File

@@ -1,25 +0,0 @@
using Microsoft.AspNetCore.Http;
using Umbraco.Cms.Core.Trees;
namespace Umbraco.Cms.Web.BackOffice.Trees
{
public class MenuRenderingEventArgs : TreeRenderingEventArgs
{
/// <summary>
/// The tree node id that the menu is rendering for
/// </summary>
public string NodeId { get; private set; }
/// <summary>
/// The menu being rendered
/// </summary>
public MenuItemCollection Menu { get; private set; }
public MenuRenderingEventArgs(string nodeId, MenuItemCollection menu, FormCollection queryStrings)
: base(queryStrings)
{
NodeId = nodeId;
Menu = menu;
}
}
}

View File

@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.Common.Attributes;
@@ -21,8 +22,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
public PackagesTreeController(
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory)
: base(localizedTextService, umbracoApiControllerTypeCollection)
IMenuItemCollectionFactory menuItemCollectionFactory,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory;
}

View File

@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
@@ -30,8 +31,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
IFileSystems fileSystems)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, fileSystems)
IFileSystems fileSystems,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, fileSystems, eventAggregator)
{
FileSystem = fileSystems.MacroPartialsFileSystem;
}

View File

@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
@@ -30,8 +31,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
IFileSystems fileSystems)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory)
IFileSystems fileSystems,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, eventAggregator)
{
FileSystem = fileSystems.PartialViewsFileSystem;
}

View File

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.Trees;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
@@ -27,8 +28,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
IRelationService relationService)
: base(localizedTextService, umbracoApiControllerTypeCollection)
IRelationService relationService,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory;
_relationService = relationService;

View File

@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Http;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Trees;
namespace Umbraco.Cms.Web.BackOffice.Trees
{
/// <summary>
/// A notification that allows developer to modify the root tree node that is being rendered
/// </summary>
public class RootNodeRendering : INotification
{
public TreeNode Node { get; }
public FormCollection QueryStrings { get; }
public RootNodeRendering(TreeNode node, FormCollection queryStrings)
{
Node = node;
QueryStrings = queryStrings;
}
}
}

View File

@@ -1,4 +1,5 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
@@ -22,8 +23,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
IFileSystems fileSystems)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory)
IFileSystems fileSystems,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, eventAggregator)
{
FileSystem = fileSystems.ScriptsFileSystem;
}

View File

@@ -1,4 +1,5 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
@@ -22,8 +23,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IMenuItemCollectionFactory menuItemCollectionFactory,
IFileSystems fileSystems)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory)
IFileSystems fileSystems,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, eventAggregator)
{
FileSystem = fileSystems.StylesheetsFileSystem;
}

View File

@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Entities;
@@ -35,8 +36,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
IMenuItemCollectionFactory menuItemCollectionFactory,
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IFileService fileService
) : base(localizedTextService, umbracoApiControllerTypeCollection)
IFileService fileService,
IEventAggregator eventAggregator
) : base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_treeSearcher = treeSearcher;
_menuItemCollectionFactory = menuItemCollectionFactory;

View File

@@ -1,6 +1,7 @@
using System;
using System;
using System.Collections.Concurrent;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Extensions;
@@ -18,8 +19,8 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
protected ILocalizedTextService LocalizedTextService { get; }
protected TreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection)
: base(umbracoApiControllerTypeCollection)
protected TreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IEventAggregator eventAggregator)
: base(umbracoApiControllerTypeCollection, eventAggregator)
{
LocalizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
_treeAttribute = GetTreeAttribute();

View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
@@ -27,10 +28,12 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
// TODO: Need to set this, but from where?
// Presumably not injecting as this will be a base controller for package/solution developers.
private readonly UmbracoApiControllerTypeCollection _apiControllers;
private readonly IEventAggregator _eventAggregator;
protected TreeControllerBase(UmbracoApiControllerTypeCollection apiControllers)
protected TreeControllerBase(UmbracoApiControllerTypeCollection apiControllers, IEventAggregator eventAggregator)
{
_apiControllers = apiControllers;
_eventAggregator = eventAggregator;
}
/// <summary>
@@ -85,7 +88,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// </summary>
/// <param name="queryStrings"></param>
/// <returns></returns>
public ActionResult<TreeNode> GetRootNode([ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings)
public async Task<ActionResult<TreeNode>> GetRootNode([ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings)
{
if (queryStrings == null) queryStrings = FormCollection.Empty;
var nodeResult = CreateRootNode(queryStrings);
@@ -109,7 +112,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
if (IsDialog(queryStrings))
node.RoutePath = "#";
OnRootNodeRendering(this, new TreeNodeRenderingEventArgs(node, queryStrings));
await _eventAggregator.PublishAsync(new RootNodeRendering(node, queryStrings));
return node;
}
@@ -126,7 +129,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// We are allowing an arbitrary number of query strings to be passed in so that developers are able to persist custom data from the front-end
/// to the back end to be used in the query for model data.
/// </remarks>
public ActionResult<TreeNodeCollection> GetNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings)
public async Task<ActionResult<TreeNodeCollection>> GetNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings)
{
if (queryStrings == null) queryStrings = FormCollection.Empty;
var nodesResult = GetTreeNodes(id, queryStrings);
@@ -147,7 +150,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
node.RoutePath = "#";
//raise the event
OnTreeNodesRendering(this, new TreeNodesRenderingEventArgs(nodes, queryStrings));
await _eventAggregator.PublishAsync(new TreeNodesRendering(nodes, queryStrings));
return nodes;
}
@@ -158,7 +161,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// <param name="id"></param>
/// <param name="queryStrings"></param>
/// <returns></returns>
public ActionResult<MenuItemCollection> GetMenu(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings)
public async Task<ActionResult<MenuItemCollection>> GetMenu(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings)
{
if (queryStrings == null) queryStrings = FormCollection.Empty;
var menuResult = GetMenuForNode(id, queryStrings);
@@ -169,7 +172,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
var menu = menuResult.Value;
//raise the event
OnMenuRendering(this, new MenuRenderingEventArgs(id, menu, queryStrings));
await _eventAggregator.PublishAsync(new MenuRendering(id, menu, queryStrings));
return menu;
}
@@ -374,45 +377,5 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
queryStrings.TryGetValue(TreeQueryStringParameters.Use, out var use);
return use == "dialog";
}
/// <summary>
/// An event that allows developers to modify the tree node collection that is being rendered
/// </summary>
/// <remarks>
/// Developers can add/remove/replace/insert/update/etc... any of the tree items in the collection.
/// </remarks>
public static event TypedEventHandler<TreeControllerBase, TreeNodesRenderingEventArgs> TreeNodesRendering;
private static void OnTreeNodesRendering(TreeControllerBase instance, TreeNodesRenderingEventArgs e)
{
var handler = TreeNodesRendering;
handler?.Invoke(instance, e);
}
/// <summary>
/// An event that allows developer to modify the root tree node that is being rendered
/// </summary>
public static event TypedEventHandler<TreeControllerBase, TreeNodeRenderingEventArgs> RootNodeRendering;
// internal for temp class below - kill eventually!
internal static void OnRootNodeRendering(TreeControllerBase instance, TreeNodeRenderingEventArgs e)
{
var handler = RootNodeRendering;
handler?.Invoke(instance, e);
}
/// <summary>
/// An event that allows developers to modify the menu that is being rendered
/// </summary>
/// <remarks>
/// Developers can add/remove/replace/insert/update/etc... any of the tree items in the collection.
/// </remarks>
public static event TypedEventHandler<TreeControllerBase, MenuRenderingEventArgs> MenuRendering;
private static void OnMenuRendering(TreeControllerBase instance, MenuRenderingEventArgs e)
{
var handler = MenuRendering;
handler?.Invoke(instance, e);
}
}
}

View File

@@ -1,16 +0,0 @@
using Microsoft.AspNetCore.Http;
using Umbraco.Cms.Core.Trees;
namespace Umbraco.Cms.Web.BackOffice.Trees
{
public class TreeNodeRenderingEventArgs : TreeRenderingEventArgs
{
public TreeNode Node { get; private set; }
public TreeNodeRenderingEventArgs(TreeNode node, FormCollection queryStrings)
: base(queryStrings)
{
Node = node;
}
}
}

View File

@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Http;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Trees;
namespace Umbraco.Cms.Web.BackOffice.Trees
{
/// <summary>
/// A notification that allows developers to modify the tree node collection that is being rendered
/// </summary>
/// <remarks>
/// Developers can add/remove/replace/insert/update/etc... any of the tree items in the collection.
/// </remarks>
public class TreeNodesRendering : INotification
{
public TreeNodeCollection Nodes { get; }
public FormCollection QueryStrings { get; }
public TreeNodesRendering(TreeNodeCollection nodes, FormCollection queryStrings)
{
Nodes = nodes;
QueryStrings = queryStrings;
}
}
}

View File

@@ -1,16 +0,0 @@
using Microsoft.AspNetCore.Http;
using Umbraco.Cms.Core.Trees;
namespace Umbraco.Cms.Web.BackOffice.Trees
{
public class TreeNodesRenderingEventArgs : TreeRenderingEventArgs
{
public TreeNodeCollection Nodes { get; private set; }
public TreeNodesRenderingEventArgs(TreeNodeCollection nodes, FormCollection queryStrings)
: base(queryStrings)
{
Nodes = nodes;
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
using Microsoft.AspNetCore.Http;
namespace Umbraco.Cms.Web.BackOffice.Trees
{
public class TreeRenderingEventArgs : EventArgs
{
public FormCollection QueryStrings { get; private set; }
public TreeRenderingEventArgs(FormCollection queryStrings)
{
QueryStrings = queryStrings;
}
}
}

View File

@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.Common.Attributes;
@@ -21,8 +22,9 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
public UserTreeController(
IMenuItemCollectionFactory menuItemCollectionFactory,
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection
) : base(localizedTextService, umbracoApiControllerTypeCollection)
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IEventAggregator eventAggregator
) : base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory;
}