mirror of https://github.com/abpframework/abp.git
committed by
GitHub
53 changed files with 2136 additions and 1129 deletions
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,8 @@ |
|||||
|
namespace Volo.CmsKit.Admin.GlobalResources; |
||||
|
|
||||
|
public class GlobalResourcesDto |
||||
|
{ |
||||
|
public string StyleContent { get; set; } |
||||
|
|
||||
|
public string ScriptContent { get; set; } |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
namespace Volo.CmsKit.Admin.GlobalResources; |
||||
|
|
||||
|
public class GlobalResourcesUpdateDto |
||||
|
{ |
||||
|
public string Style { get; set; } |
||||
|
|
||||
|
public string Script { get; set; } |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.GlobalResources; |
||||
|
|
||||
|
public interface IGlobalResourceAdminAppService : IApplicationService |
||||
|
{ |
||||
|
Task<GlobalResourcesDto> GetAsync(); |
||||
|
|
||||
|
Task SetGlobalResourcesAsync(GlobalResourcesUpdateDto input); |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
using Volo.CmsKit.GlobalFeatures; |
||||
|
using Volo.CmsKit.GlobalResources; |
||||
|
using Volo.CmsKit.Permissions; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.GlobalResources; |
||||
|
|
||||
|
[RequiresGlobalFeature(typeof(GlobalResourcesFeature))] |
||||
|
[Authorize(CmsKitAdminPermissions.GlobalResources.Default)] |
||||
|
public class GlobalResourceAdminAppService : ApplicationService, IGlobalResourceAdminAppService |
||||
|
{ |
||||
|
public GlobalResourceManager GlobalResourceManager { get; } |
||||
|
|
||||
|
public GlobalResourceAdminAppService(GlobalResourceManager globalResourceManager) |
||||
|
{ |
||||
|
GlobalResourceManager = globalResourceManager; |
||||
|
} |
||||
|
|
||||
|
public async Task<GlobalResourcesDto> GetAsync() |
||||
|
{ |
||||
|
return new GlobalResourcesDto { |
||||
|
StyleContent = (await GlobalResourceManager.GetGlobalStyleAsync()).Value, |
||||
|
ScriptContent = (await GlobalResourceManager.GetGlobalScriptAsync()).Value |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
public async Task SetGlobalResourcesAsync(GlobalResourcesUpdateDto input) |
||||
|
{ |
||||
|
await GlobalResourceManager.SetGlobalStyleAsync(input.Style); |
||||
|
await GlobalResourceManager.SetGlobalScriptAsync(input.Script); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
// This file is automatically generated by ABP framework to use MVC Controllers from CSharp
|
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Http.Client; |
||||
|
using Volo.Abp.Http.Modeling; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Http.Client.ClientProxying; |
||||
|
using Volo.CmsKit.Admin.GlobalResources; |
||||
|
|
||||
|
// ReSharper disable once CheckNamespace
|
||||
|
namespace Volo.CmsKit.Admin.GlobalResources.ClientProxies; |
||||
|
|
||||
|
[Dependency(ReplaceServices = true)] |
||||
|
[ExposeServices(typeof(IGlobalResourceAdminAppService), typeof(GlobalResourceAdminClientProxy))] |
||||
|
public partial class GlobalResourceAdminClientProxy : ClientProxyBase<IGlobalResourceAdminAppService>, IGlobalResourceAdminAppService |
||||
|
{ |
||||
|
public virtual async Task<GlobalResourcesDto> GetAsync() |
||||
|
{ |
||||
|
return await RequestAsync<GlobalResourcesDto>(nameof(GetAsync)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task SetGlobalResourcesAsync(GlobalResourcesUpdateDto input) |
||||
|
{ |
||||
|
await RequestAsync(nameof(SetGlobalResourcesAsync), new ClientProxyRequestTypeValue |
||||
|
{ |
||||
|
{ typeof(GlobalResourcesUpdateDto), input } |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
// This file is part of GlobalResourceAdminClientProxy, you can customize it here
|
||||
|
// ReSharper disable once CheckNamespace
|
||||
|
namespace Volo.CmsKit.Admin.GlobalResources.ClientProxies; |
||||
|
|
||||
|
public partial class GlobalResourceAdminClientProxy |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
using Volo.CmsKit.GlobalFeatures; |
||||
|
using Volo.CmsKit.Permissions; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.GlobalResources; |
||||
|
|
||||
|
[RequiresGlobalFeature(typeof(GlobalResourcesFeature))] |
||||
|
[RemoteService(Name = CmsKitAdminRemoteServiceConsts.RemoteServiceName)] |
||||
|
[Area(CmsKitAdminRemoteServiceConsts.ModuleName)] |
||||
|
[Authorize(CmsKitAdminPermissions.Menus.Default)] |
||||
|
[Route("api/cms-kit-admin/global-resources")] |
||||
|
public class GlobalResourceAdminController: CmsKitAdminController, IGlobalResourceAdminAppService |
||||
|
{ |
||||
|
private readonly IGlobalResourceAdminAppService _globalResourceAdminAppService; |
||||
|
|
||||
|
public GlobalResourceAdminController(IGlobalResourceAdminAppService globalResourceAdminAppService) |
||||
|
{ |
||||
|
_globalResourceAdminAppService = globalResourceAdminAppService; |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
public Task<GlobalResourcesDto> GetAsync() |
||||
|
{ |
||||
|
return _globalResourceAdminAppService.GetAsync(); |
||||
|
} |
||||
|
|
||||
|
[HttpPost] |
||||
|
public Task SetGlobalResourcesAsync(GlobalResourcesUpdateDto input) |
||||
|
{ |
||||
|
return _globalResourceAdminAppService.SetGlobalResourcesAsync(input); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
@page |
||||
|
|
||||
|
@using Microsoft.AspNetCore.Mvc.Localization |
||||
|
@using Volo.Abp.AspNetCore.Mvc.UI.Layout |
||||
|
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.GlobalResources |
||||
|
@using Volo.CmsKit.Admin.Web.Menus |
||||
|
@using Volo.CmsKit.Localization |
||||
|
|
||||
|
@inject IPageLayout PageLayout |
||||
|
@inject IHtmlLocalizer<CmsKitResource> L |
||||
|
|
||||
|
@model IndexModel |
||||
|
|
||||
|
@{ |
||||
|
PageLayout.Content.Title = L["GlobalResources"].Value; |
||||
|
PageLayout.Content.BreadCrumb.Add(L["Menu:CMS"].Value); |
||||
|
PageLayout.Content.MenuItemName = CmsKitAdminMenus.GlobalResources.GlobalResourcesMenu; |
||||
|
} |
||||
|
|
||||
|
@section scripts { |
||||
|
<abp-script-bundle> |
||||
|
<abp-script src="/client-proxies/cms-kit-common-proxy.js"/> |
||||
|
<abp-script src="/client-proxies/cms-kit-admin-proxy.js"/> |
||||
|
<abp-script src="/Pages/CmsKit/GlobalResources/index.js"/> |
||||
|
</abp-script-bundle> |
||||
|
} |
||||
|
|
||||
|
<abp-card> |
||||
|
<abp-card-body> |
||||
|
<abp-tabs> |
||||
|
<abp-tab title="@L["Script"].Value"> |
||||
|
<abp-input asp-for="ScriptContent" suppress-label="true"></abp-input> |
||||
|
</abp-tab> |
||||
|
<abp-tab title="@L["Style"].Value"> |
||||
|
<abp-input asp-for="StyleContent" suppress-label="true"></abp-input> |
||||
|
</abp-tab> |
||||
|
</abp-tabs> |
||||
|
</abp-card-body> |
||||
|
<abp-card-footer> |
||||
|
<abp-button button-type="Primary" id="SaveResourcesButton" class="float-end">@L["SaveChanges"]</abp-button> |
||||
|
</abp-card-footer> |
||||
|
</abp-card> |
||||
@ -0,0 +1,30 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; |
||||
|
using Volo.CmsKit.Admin.GlobalResources; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.GlobalResources; |
||||
|
|
||||
|
public class IndexModel : CmsKitAdminPageModel |
||||
|
{ |
||||
|
private readonly IGlobalResourceAdminAppService _globalResourceAdminAppService; |
||||
|
|
||||
|
[TextArea(Rows = 30)] |
||||
|
public string ScriptContent { get; set; } |
||||
|
|
||||
|
[TextArea(Rows = 30)] |
||||
|
public string StyleContent { get; set; } |
||||
|
|
||||
|
public IndexModel(IGlobalResourceAdminAppService globalResourceAdminAppService) |
||||
|
{ |
||||
|
_globalResourceAdminAppService = globalResourceAdminAppService; |
||||
|
} |
||||
|
|
||||
|
public async Task OnGetAsync() |
||||
|
{ |
||||
|
var resources = await _globalResourceAdminAppService.GetAsync(); |
||||
|
|
||||
|
ScriptContent = resources.ScriptContent; |
||||
|
StyleContent = resources.StyleContent; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
$(function (){ |
||||
|
var l = abp.localization.getResource("CmsKit"); |
||||
|
|
||||
|
var service = volo.cmsKit.admin.globalResources.globalResourceAdmin; |
||||
|
|
||||
|
$('#SaveResourcesButton').on('click','',function(){ |
||||
|
service.setGlobalResources( |
||||
|
{ |
||||
|
style: $('#StyleContent').val(), |
||||
|
script: $('#ScriptContent').val() |
||||
|
} |
||||
|
).then(function () { |
||||
|
abp.message.success(l("SavedSuccessfully")); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,16 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
|
||||
|
namespace Volo.CmsKit.GlobalFeatures; |
||||
|
|
||||
|
[GlobalFeatureName(Name)] |
||||
|
public class GlobalResourcesFeature : GlobalFeature |
||||
|
{ |
||||
|
public const string Name = "CmsKit.GlobalResources"; |
||||
|
|
||||
|
internal GlobalResourcesFeature( |
||||
|
[NotNull] GlobalCmsKitFeatures cmsKit |
||||
|
) : base(cmsKit) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
namespace Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
public class GlobalResourceConsts |
||||
|
{ |
||||
|
public const string GlobalStyleName = "GlobalStyle"; |
||||
|
|
||||
|
public const string GlobalScriptName = "GlobalScript"; |
||||
|
|
||||
|
public static int MaxNameLength { get; set; } = 128; |
||||
|
|
||||
|
public static int MaxValueLength { get; set; } = int.MaxValue; |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Entities.Auditing; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
public class GlobalResource : AuditedAggregateRoot<Guid>, IMultiTenant |
||||
|
{ |
||||
|
public virtual string Name { get; } |
||||
|
|
||||
|
public virtual string Value { get; private set; } |
||||
|
|
||||
|
public virtual Guid? TenantId { get; protected set; } |
||||
|
|
||||
|
|
||||
|
protected GlobalResource() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
internal GlobalResource( |
||||
|
Guid id, |
||||
|
[NotNull] string name, |
||||
|
[CanBeNull] string value, |
||||
|
Guid? tenantId = null) : base(id) |
||||
|
{ |
||||
|
Name = Check.NotNullOrEmpty(name, nameof(name), GlobalResourceConsts.MaxNameLength); |
||||
|
Value = Check.Length(value, nameof(value), GlobalResourceConsts.MaxValueLength); |
||||
|
|
||||
|
TenantId = tenantId; |
||||
|
} |
||||
|
|
||||
|
public virtual void SetValue(string value) |
||||
|
{ |
||||
|
Check.Length(value, nameof(value), GlobalResourceConsts.MaxValueLength); |
||||
|
|
||||
|
Value = value; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,69 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Services; |
||||
|
|
||||
|
namespace Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
public class GlobalResourceManager : DomainService |
||||
|
{ |
||||
|
private readonly IGlobalResourceRepository _globalResourceRepository; |
||||
|
|
||||
|
public GlobalResourceManager(IGlobalResourceRepository globalResourceRepository) |
||||
|
{ |
||||
|
_globalResourceRepository = globalResourceRepository; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<GlobalResource> SetGlobalStyleAsync(string value) |
||||
|
{ |
||||
|
return await SetGlobalResourceAsync(GlobalResourceConsts.GlobalStyleName, value); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<GlobalResource> SetGlobalScriptAsync(string value) |
||||
|
{ |
||||
|
return await SetGlobalResourceAsync(GlobalResourceConsts.GlobalScriptName, value); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<GlobalResource> GetGlobalStyleAsync() |
||||
|
{ |
||||
|
return await GetOrCreateResourceAsync(GlobalResourceConsts.GlobalStyleName); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<GlobalResource> GetGlobalScriptAsync() |
||||
|
{ |
||||
|
return await GetOrCreateResourceAsync(GlobalResourceConsts.GlobalScriptName); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<GlobalResource> SetGlobalResourceAsync(string name, string value) |
||||
|
{ |
||||
|
var resource = await _globalResourceRepository.FindByNameAsync(name); |
||||
|
|
||||
|
if (resource == null) |
||||
|
{ |
||||
|
return await CreateResourceAsync(name, value); |
||||
|
} |
||||
|
|
||||
|
resource.SetValue(value); |
||||
|
|
||||
|
await _globalResourceRepository.UpdateAsync(resource); |
||||
|
|
||||
|
return resource; |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<GlobalResource> GetOrCreateResourceAsync(string name) |
||||
|
{ |
||||
|
var resource = await _globalResourceRepository.FindByNameAsync(name); |
||||
|
|
||||
|
if (resource == null) |
||||
|
{ |
||||
|
return await CreateResourceAsync(name, string.Empty); |
||||
|
} |
||||
|
|
||||
|
return resource; |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<GlobalResource> CreateResourceAsync(string name, string value) |
||||
|
{ |
||||
|
return await _globalResourceRepository.InsertAsync( |
||||
|
new GlobalResource(GuidGenerator.Create(), name, value, CurrentTenant.Id) |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
|
namespace Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
public interface IGlobalResourceRepository: IBasicRepository<GlobalResource, Guid> |
||||
|
{ |
||||
|
Task<GlobalResource> FindByNameAsync([NotNull] string name, CancellationToken cancellationToken = default); |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.CmsKit.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
public class EfCoreGlobalResourceRepository: EfCoreRepository<ICmsKitDbContext, GlobalResource, Guid>, IGlobalResourceRepository |
||||
|
{ |
||||
|
public EfCoreGlobalResourceRepository(IDbContextProvider<ICmsKitDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public Task<GlobalResource> FindByNameAsync(string name, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
Check.NotNullOrEmpty(name, nameof(name)); |
||||
|
return FindAsync(x => x.Name == name, cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
namespace Volo.CmsKit.MongoDB.GlobalResources; |
||||
|
|
||||
|
public class MongoGlobalResourceRepository: MongoDbRepository<ICmsKitMongoDbContext, GlobalResource, Guid>, IGlobalResourceRepository |
||||
|
{ |
||||
|
public MongoGlobalResourceRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public Task<GlobalResource> FindByNameAsync(string name, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
Check.NotNullOrEmpty(name, nameof(name)); |
||||
|
return FindAsync(x => x.Name == name, cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
namespace Volo.CmsKit.Public.GlobalResources; |
||||
|
|
||||
|
public class GlobalResourceDto |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public string Value { get; set; } |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
|
||||
|
namespace Volo.CmsKit.Public.GlobalResources; |
||||
|
|
||||
|
public interface IGlobalResourcePublicAppService : IApplicationService |
||||
|
{ |
||||
|
Task<GlobalResourceDto> GetGlobalScriptAsync(); |
||||
|
|
||||
|
Task<GlobalResourceDto> GetGlobalStyleAsync(); |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
using Volo.CmsKit.GlobalFeatures; |
||||
|
using Volo.CmsKit.GlobalResources; |
||||
|
|
||||
|
namespace Volo.CmsKit.Public.GlobalResources; |
||||
|
|
||||
|
[RequiresGlobalFeature(typeof(GlobalResourcesFeature))] |
||||
|
public class GlobalResourcePublicAppService : ApplicationService, IGlobalResourcePublicAppService |
||||
|
{ |
||||
|
public GlobalResourceManager GlobalResourceManager { get; } |
||||
|
|
||||
|
public GlobalResourcePublicAppService(GlobalResourceManager globalResourceManager) |
||||
|
{ |
||||
|
GlobalResourceManager = globalResourceManager; |
||||
|
} |
||||
|
|
||||
|
public async Task<GlobalResourceDto> GetGlobalScriptAsync() |
||||
|
{ |
||||
|
var globalScript = await GlobalResourceManager.GetGlobalScriptAsync(); |
||||
|
|
||||
|
return ObjectMapper.Map<GlobalResource, GlobalResourceDto>(globalScript); |
||||
|
} |
||||
|
|
||||
|
public async Task<GlobalResourceDto> GetGlobalStyleAsync() |
||||
|
{ |
||||
|
var globalStyle = await GlobalResourceManager.GetGlobalStyleAsync(); |
||||
|
|
||||
|
return ObjectMapper.Map<GlobalResource, GlobalResourceDto>(globalStyle); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Entities.Events; |
||||
|
using Volo.Abp.EventBus; |
||||
|
using Volo.Abp.ObjectMapping; |
||||
|
using Volo.CmsKit.GlobalResources; |
||||
|
using Volo.CmsKit.Public.GlobalResources; |
||||
|
|
||||
|
namespace Volo.CmsKit.Public.GlobalResources.Handlers; |
||||
|
|
||||
|
public class GlobalResourceEventHandler: |
||||
|
ILocalEventHandler<EntityUpdatedEventData<GlobalResource>>, |
||||
|
ITransientDependency |
||||
|
{ |
||||
|
public IObjectMapper ObjectMapper { get; } |
||||
|
private readonly IDistributedCache<GlobalResourceDto> _resourceCache; |
||||
|
|
||||
|
public GlobalResourceEventHandler( |
||||
|
IDistributedCache<GlobalResourceDto> resourceCache, |
||||
|
IObjectMapper objectMapper) |
||||
|
{ |
||||
|
ObjectMapper = objectMapper; |
||||
|
_resourceCache = resourceCache; |
||||
|
} |
||||
|
|
||||
|
public async Task HandleEventAsync(EntityUpdatedEventData<GlobalResource> eventData) |
||||
|
{ |
||||
|
await _resourceCache.SetAsync( |
||||
|
eventData.Entity.Name, |
||||
|
ObjectMapper.Map<GlobalResource, GlobalResourceDto>(eventData.Entity)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
using Volo.CmsKit.GlobalFeatures; |
||||
|
|
||||
|
namespace Volo.CmsKit.Public.GlobalResources; |
||||
|
|
||||
|
[RequiresGlobalFeature(typeof(GlobalResourcesFeature))] |
||||
|
[RemoteService(Name = CmsKitPublicRemoteServiceConsts.RemoteServiceName)] |
||||
|
[Area(CmsKitPublicRemoteServiceConsts.ModuleName)] |
||||
|
[Route("api/cms-kit-public/global-resources")] |
||||
|
public class GlobalResourcePublicController: CmsKitPublicControllerBase, IGlobalResourcePublicAppService |
||||
|
{ |
||||
|
private readonly IGlobalResourcePublicAppService _globalResourcePublicAppService; |
||||
|
|
||||
|
public GlobalResourcePublicController(IGlobalResourcePublicAppService globalResourcePublicAppService) |
||||
|
{ |
||||
|
_globalResourcePublicAppService = globalResourcePublicAppService; |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("script")] |
||||
|
public Task<GlobalResourceDto> GetGlobalScriptAsync() |
||||
|
{ |
||||
|
return _globalResourcePublicAppService.GetGlobalScriptAsync(); |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("style")] |
||||
|
public Task<GlobalResourceDto> GetGlobalStyleAsync() |
||||
|
{ |
||||
|
return _globalResourcePublicAppService.GetGlobalStyleAsync(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,62 @@ |
|||||
|
using System; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Microsoft.Extensions.Caching.Distributed; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.CmsKit.GlobalResources; |
||||
|
using Volo.CmsKit.Public.GlobalResources; |
||||
|
|
||||
|
namespace Volo.CmsKit.Public.Web.Controllers; |
||||
|
|
||||
|
[Route("cms-kit/global-resources")] |
||||
|
public class CmsKitPublicGlobalResourcesController: AbpController |
||||
|
{ |
||||
|
private readonly IGlobalResourcePublicAppService _globalResourcePublicAppService; |
||||
|
private readonly IDistributedCache<GlobalResourceDto> _resourceCache; |
||||
|
|
||||
|
public CmsKitPublicGlobalResourcesController( |
||||
|
IGlobalResourcePublicAppService globalResourcePublicAppService, |
||||
|
IDistributedCache<GlobalResourceDto> resourceCache) |
||||
|
{ |
||||
|
_globalResourcePublicAppService = globalResourcePublicAppService; |
||||
|
_resourceCache = resourceCache; |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("style")] |
||||
|
public async Task<IActionResult> GetGlobalStyleAsync() |
||||
|
{ |
||||
|
var style = await _resourceCache.GetOrAddAsync( |
||||
|
GlobalResourceConsts.GlobalStyleName, //Cache key
|
||||
|
async () => await _globalResourcePublicAppService.GetGlobalStyleAsync(), |
||||
|
() => new DistributedCacheEntryOptions |
||||
|
{ |
||||
|
AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(2) |
||||
|
} |
||||
|
); |
||||
|
|
||||
|
return new FileContentResult( |
||||
|
Encoding.ASCII.GetBytes(style.Value), |
||||
|
"text/css"); |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("script")] |
||||
|
public async Task<IActionResult> GetGlobalScriptAsync() |
||||
|
{ |
||||
|
var script = await _resourceCache.GetOrAddAsync( |
||||
|
GlobalResourceConsts.GlobalScriptName, //Cache key
|
||||
|
async () => await _globalResourcePublicAppService.GetGlobalScriptAsync(), |
||||
|
() => new DistributedCacheEntryOptions |
||||
|
{ |
||||
|
AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(2) |
||||
|
} |
||||
|
); |
||||
|
|
||||
|
return new FileContentResult( |
||||
|
Encoding.ASCII.GetBytes(script.Value), |
||||
|
"application/javascript"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1 @@ |
|||||
|
<script src="/cms-kit/global-resources/script"></script> |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
|
||||
|
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.GlobalResources.Script; |
||||
|
|
||||
|
public class GlobalScriptViewComponent : AbpViewComponent |
||||
|
{ |
||||
|
public async Task<IViewComponentResult> InvokeAsync() |
||||
|
{ |
||||
|
return View("~/Pages/CmsKit/Shared/Components/GlobalResources/Script/Default.cshtml"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1 @@ |
|||||
|
<link rel="stylesheet" href="/cms-kit/global-resources/style"/> |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
|
||||
|
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.GlobalResources.Style; |
||||
|
|
||||
|
public class GlobalStyleViewComponent : AbpViewComponent |
||||
|
{ |
||||
|
public async Task<IViewComponentResult> InvokeAsync() |
||||
|
{ |
||||
|
return View("~/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml"); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue