diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/GlobalResources/GlobalResourceDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/GlobalResources/GlobalResourceDto.cs new file mode 100644 index 0000000000..16e0575288 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/GlobalResources/GlobalResourceDto.cs @@ -0,0 +1,8 @@ +namespace Volo.CmsKit.Public.GlobalResources; + +public class GlobalResourceDto +{ + public string Name { get; set; } + + public string Value { get; set; } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/GlobalResources/IGlobalResourcePublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/GlobalResources/IGlobalResourcePublicAppService.cs new file mode 100644 index 0000000000..d78347cac7 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/GlobalResources/IGlobalResourcePublicAppService.cs @@ -0,0 +1,11 @@ +using System.Threading.Tasks; +using Volo.Abp.Application.Services; + +namespace Volo.CmsKit.Public.GlobalResources; + +public interface IGlobalResourcePublicAppService : IApplicationService +{ + Task GetGlobalScriptAsync(); + + Task GetGlobalStyleAsync(); +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/GlobalResources/GlobalResourcePublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/GlobalResources/GlobalResourcePublicAppService.cs new file mode 100644 index 0000000000..2debf10ed5 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/GlobalResources/GlobalResourcePublicAppService.cs @@ -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 GetGlobalScriptAsync() + { + var globalScript = await GlobalResourceManager.GetGlobalScriptAsync(); + + return ObjectMapper.Map(globalScript); + } + + public async Task GetGlobalStyleAsync() + { + var globalStyle = await GlobalResourceManager.GetGlobalStyleAsync(); + + return ObjectMapper.Map(globalStyle); + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs index 74a4bf1050..a6b7e497ac 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs @@ -2,10 +2,12 @@ using Volo.Abp.AutoMapper; using Volo.CmsKit.Blogs; using Volo.CmsKit.Comments; +using Volo.CmsKit.GlobalResources; using Volo.CmsKit.Menus; using Volo.CmsKit.Pages; using Volo.CmsKit.Public.Blogs; using Volo.CmsKit.Public.Comments; +using Volo.CmsKit.Public.GlobalResources; using Volo.CmsKit.Public.Pages; using Volo.CmsKit.Public.Ratings; using Volo.CmsKit.Ratings; @@ -33,5 +35,7 @@ public class PublicApplicationAutoMapperProfile : Profile CreateMap(MemberList.None); CreateMap(); + + CreateMap(); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/GlobalResources/GlobalResourcePublicController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/GlobalResources/GlobalResourcePublicController.cs new file mode 100644 index 0000000000..8b58a00f9a --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/GlobalResources/GlobalResourcePublicController.cs @@ -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 GetGlobalScriptAsync() + { + return _globalResourcePublicAppService.GetGlobalScriptAsync(); + } + + [HttpGet] + [Route("style")] + public Task GetGlobalStyleAsync() + { + return _globalResourcePublicAppService.GetGlobalStyleAsync(); + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs index da7e9e249a..2c561f3474 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.Mvc.Localization; +using Volo.Abp.AspNetCore.Mvc.UI.Components.LayoutHook; using Volo.Abp.AutoMapper; using Volo.Abp.GlobalFeatures; using Volo.Abp.Http.ProxyScripting.Generators.JQuery; @@ -12,6 +13,8 @@ using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.Localization; using Volo.CmsKit.Pages; using Volo.CmsKit.Public.Web.Menus; +using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.GlobalResources.Script; +using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.GlobalResources.Style; using Volo.CmsKit.Web; namespace Volo.CmsKit.Public.Web; @@ -85,5 +88,21 @@ public class CmsKitPublicWebModule : AbpModule options.Conventions.AddPageRoute("/Public/CmsKit/Blogs/BlogPost", @"/blogs/{blogSlug}/{blogPostSlug:minlength(1)}"); }); } + + if (GlobalFeatureManager.Instance.IsEnabled()) + { + Configure(options => + { + options.Add( + LayoutHooks.Head.Last, + typeof(GlobalStyleViewComponent) + ); + options.Add( + LayoutHooks.Head.Last, + typeof(GlobalScriptViewComponent) + ); + }); + } + } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Controllers/CmsKitPublicGlobalResourcesController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Controllers/CmsKitPublicGlobalResourcesController.cs new file mode 100644 index 0000000000..4abe1d48d3 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Controllers/CmsKitPublicGlobalResourcesController.cs @@ -0,0 +1,40 @@ +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.CmsKit.Public.GlobalResources; + +namespace Volo.CmsKit.Public.Web.Controllers; + +[Route("global-resources")] +public class CmsKitPublicGlobalResourcesController: AbpController +{ + private readonly IGlobalResourcePublicAppService _globalResourcePublicAppService; + + public CmsKitPublicGlobalResourcesController(IGlobalResourcePublicAppService globalResourcePublicAppService) + { + _globalResourcePublicAppService = globalResourcePublicAppService; + } + + [HttpGet] + [Route("style")] + public async Task GetGlobalStyleAsync(string entityType, string entityId) + { + var style = await _globalResourcePublicAppService.GetGlobalStyleAsync(); + + var contents = Encoding.ASCII.GetBytes(style.Value); + + return new FileContentResult(contents, "text/css"); + } + + [HttpGet] + [Route("script")] + public async Task GetGlobalScriptAsync(string entityType, string entityId) + { + var script = await _globalResourcePublicAppService.GetGlobalScriptAsync(); + + var contents = Encoding.ASCII.GetBytes(script.Value); + + return new FileContentResult(contents, "application/javascript"); + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/Default.cshtml new file mode 100644 index 0000000000..5c22315e9a --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/Default.cshtml @@ -0,0 +1 @@ + diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/GlobalScriptViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/GlobalScriptViewComponent.cs new file mode 100644 index 0000000000..1abf2a4c16 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/GlobalScriptViewComponent.cs @@ -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 InvokeAsync() + { + return View("~/Pages/CmsKit/Shared/Components/GlobalResources/Script/Default.cshtml"); + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml new file mode 100644 index 0000000000..6e0671ec72 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml @@ -0,0 +1 @@ + diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/GlobalStyleViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/GlobalStyleViewComponent.cs new file mode 100644 index 0000000000..3d9bc010c4 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/GlobalStyleViewComponent.cs @@ -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 InvokeAsync() + { + return View("~/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml"); + } +} \ No newline at end of file