104 lines
4.0 KiB
C#
104 lines
4.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
|
using Microsoft.AspNetCore.Mvc.Routing;
|
|
using Microsoft.AspNetCore.Routing;
|
|
using Nop.Core.Domain.Media;
|
|
using Nop.Services.Common;
|
|
using Nop.Services.Configuration;
|
|
using Nop.Services.Localization;
|
|
using Nop.Services.Plugins;
|
|
using Nop.Services.ScheduleTasks;
|
|
using Nop.Services.Security;
|
|
using Nop.Web.Framework;
|
|
using Nop.Web.Framework.Menu;
|
|
|
|
namespace Nop.Plugin.Misc.SignalRApi
|
|
{
|
|
/// <summary>
|
|
/// Rename this file and change to the correct type
|
|
/// </summary>
|
|
public class MiscSignalRApiPlugin : BasePlugin, IAdminMenuPlugin, IMiscPlugin
|
|
{
|
|
protected readonly IActionContextAccessor _actionContextAccessor;
|
|
protected readonly IPermissionService _permissionService;
|
|
protected readonly ILocalizationService _localizationService;
|
|
protected readonly IUrlHelperFactory _urlHelperFactory;
|
|
|
|
public MiscSignalRApiPlugin(IActionContextAccessor actionContextAccessor,
|
|
ILocalizationService localizationService,
|
|
IPermissionService permissionService,
|
|
IUrlHelperFactory urlHelperFactory)
|
|
{
|
|
_actionContextAccessor = actionContextAccessor;
|
|
_localizationService = localizationService;
|
|
_permissionService = permissionService;
|
|
_urlHelperFactory = urlHelperFactory;
|
|
}
|
|
|
|
public override async Task InstallAsync()
|
|
{
|
|
//await _settingService.SaveSettingAsync(new PayPalStandardPaymentSettings
|
|
//{
|
|
// UseSandbox = true
|
|
//});
|
|
|
|
//await _localizationService.AddOrUpdateLocaleResourceAsync(new Dictionary<string, string>
|
|
//{
|
|
// //add custom translation
|
|
//});
|
|
await base.InstallAsync();
|
|
}
|
|
|
|
public override async Task UninstallAsync()
|
|
{
|
|
await base.UninstallAsync();
|
|
}
|
|
|
|
public async Task ManageSiteMapAsync(SiteMapNode rootNode)
|
|
{
|
|
if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePlugins))
|
|
return;
|
|
|
|
var configurationItem = rootNode.ChildNodes.FirstOrDefault(node => node.SystemName.Equals("Configuration"));
|
|
if (configurationItem is null)
|
|
return;
|
|
|
|
var shippingItem = configurationItem.ChildNodes.FirstOrDefault(node => node.SystemName.Equals("Shipping"));
|
|
var widgetsItem = configurationItem.ChildNodes.FirstOrDefault(node => node.SystemName.Equals("Widgets"));
|
|
if (shippingItem is null && widgetsItem is null)
|
|
return;
|
|
|
|
var index = shippingItem is not null ? configurationItem.ChildNodes.IndexOf(shippingItem) : -1;
|
|
if (index < 0)
|
|
index = widgetsItem is not null ? configurationItem.ChildNodes.IndexOf(widgetsItem) : -1;
|
|
if (index < 0)
|
|
return;
|
|
|
|
configurationItem.ChildNodes.Insert(index + 1, new SiteMapNode
|
|
{
|
|
Visible = true,
|
|
SystemName = "API plugins",
|
|
Title = await _localizationService.GetResourceAsync("Plugins.Misc.SignalRApi.Menu.Api"),
|
|
IconClass = "far fa-dot-circle",
|
|
ChildNodes = new List<SiteMapNode>
|
|
{
|
|
new()
|
|
{
|
|
Visible = true,
|
|
SystemName = PluginDescriptor.SystemName,
|
|
Title = PluginDescriptor.FriendlyName,
|
|
ControllerName = "SignalRApi",
|
|
ActionName = "Configure",
|
|
IconClass = "far fa-circle",
|
|
RouteValues = new RouteValueDictionary { { "area", AreaNames.ADMIN } }
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public override string GetConfigurationPageUrl()
|
|
{
|
|
return _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext).RouteUrl("Plugin.Misc.SignalRApi.Configure");
|
|
}
|
|
}
|
|
} |