Browse Source

CmsKit global resources Layout hook implementation

pull/11705/head
Yunus Emre Kalkan 4 years ago
parent
commit
ef7f03a2d4
  1. 8
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/GlobalResources/GlobalResourceDto.cs
  2. 11
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/GlobalResources/IGlobalResourcePublicAppService.cs
  3. 32
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/GlobalResources/GlobalResourcePublicAppService.cs
  4. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs
  5. 35
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/GlobalResources/GlobalResourcePublicController.cs
  6. 19
      modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs
  7. 40
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Controllers/CmsKitPublicGlobalResourcesController.cs
  8. 1
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/Default.cshtml
  9. 13
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/GlobalScriptViewComponent.cs
  10. 1
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml
  11. 13
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/GlobalStyleViewComponent.cs

8
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; }
}

11
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<GlobalResourceDto> GetGlobalScriptAsync();
Task<GlobalResourceDto> GetGlobalStyleAsync();
}

32
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<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);
}
}

4
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<BlogPost, BlogPostPublicDto>(MemberList.None);
CreateMap<MenuItem, MenuItemDto>();
CreateMap<GlobalResource, GlobalResourceDto>();
}
}

35
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<GlobalResourceDto> GetGlobalScriptAsync()
{
return _globalResourcePublicAppService.GetGlobalScriptAsync();
}
[HttpGet]
[Route("style")]
public Task<GlobalResourceDto> GetGlobalStyleAsync()
{
return _globalResourcePublicAppService.GetGlobalStyleAsync();
}
}

19
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<GlobalResourcesFeature>())
{
Configure<AbpLayoutHookOptions>(options =>
{
options.Add(
LayoutHooks.Head.Last,
typeof(GlobalStyleViewComponent)
);
options.Add(
LayoutHooks.Head.Last,
typeof(GlobalScriptViewComponent)
);
});
}
}
}

40
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<IActionResult> 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<IActionResult> GetGlobalScriptAsync(string entityType, string entityId)
{
var script = await _globalResourcePublicAppService.GetGlobalScriptAsync();
var contents = Encoding.ASCII.GetBytes(script.Value);
return new FileContentResult(contents, "application/javascript");
}
}

1
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/Default.cshtml

@ -0,0 +1 @@
<script src="/global-resources/script"></script>

13
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<IViewComponentResult> InvokeAsync()
{
return View("~/Pages/CmsKit/Shared/Components/GlobalResources/Script/Default.cshtml");
}
}

1
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml

@ -0,0 +1 @@
<link rel="stylesheet" href="/global-resources/style"/>

13
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<IViewComponentResult> InvokeAsync()
{
return View("~/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml");
}
}
Loading…
Cancel
Save