Browse Source

cms-kit: Fix global resource feature checking

pull/15882/head
Jadyn 3 years ago
parent
commit
28e296d323
  1. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/Default.cshtml
  2. 14
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/GlobalScriptViewComponent.cs
  3. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml
  4. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/GlobalStyleModel.cs
  5. 28
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/GlobalStyleViewComponent.cs

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

@ -1 +1 @@
<script src="/cms-kit/global-resources/script"></script>
<script src="~/cms-kit/global-resources/script"></script>

14
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Script/GlobalScriptViewComponent.cs

@ -1,13 +1,27 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Features;
using Volo.CmsKit.Features;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.GlobalResources.Script;
public class GlobalScriptViewComponent : AbpViewComponent
{
protected IFeatureChecker FeatureChecker { get; }
public GlobalScriptViewComponent(IFeatureChecker featureChecker)
{
FeatureChecker = featureChecker;
}
public async Task<IViewComponentResult> InvokeAsync()
{
if (!await FeatureChecker.IsEnabledAsync(CmsKitFeatures.GlobalResourceEnable))
{
return Content(string.Empty);
}
return View("~/Pages/CmsKit/Shared/Components/GlobalResources/Script/Default.cshtml");
}
}

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

@ -1,3 +1 @@
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.GlobalResources.Style.GlobalStyleModel
<link rel="stylesheet" href="@("/cms-kit/global-resources/style?v=" + Model.LastModificationTimeTimestamp)"/>
<link rel="stylesheet" href="~/cms-kit/global-resources/style" />

6
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/GlobalStyleModel.cs

@ -1,6 +0,0 @@
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.GlobalResources.Style;
public class GlobalStyleModel
{
public long LastModificationTimeTimestamp { get; set; }
}

28
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/GlobalResources/Style/GlobalStyleViewComponent.cs

@ -1,33 +1,27 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.CmsKit.Public.GlobalResources;
using Volo.Abp.Features;
using Volo.CmsKit.Features;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.GlobalResources.Style;
public class GlobalStyleViewComponent : AbpViewComponent
{
protected IGlobalResourcePublicAppService GlobalResourcePublicAppService { get; }
protected IFeatureChecker FeatureChecker { get; }
public GlobalStyleViewComponent(IGlobalResourcePublicAppService globalResourcePublicAppService)
public GlobalStyleViewComponent(IFeatureChecker featureChecker)
{
GlobalResourcePublicAppService = globalResourcePublicAppService;
FeatureChecker = featureChecker;
}
[BindProperty(SupportsGet = true)]
public DateTime? LastModificationTime { get; set; }
public async Task<IViewComponentResult> InvokeAsync()
{
var lastModificationTime = (await GlobalResourcePublicAppService.GetGlobalStyleAsync())?.LastModificationTime;
var lastModificationTimeTimestamp = (long)(lastModificationTime.HasValue ? lastModificationTime.Value.Subtract(DateTime.UnixEpoch).TotalSeconds : 0);
if (!await FeatureChecker.IsEnabledAsync(CmsKitFeatures.GlobalResourceEnable))
{
return Content(string.Empty);
}
return View("~/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml",
new GlobalStyleModel()
{
LastModificationTimeTimestamp = lastModificationTimeTimestamp
});
return View("~/Pages/CmsKit/Shared/Components/GlobalResources/Style/Default.cshtml");
}
}
Loading…
Cancel
Save