Browse Source

Merge pull request #19410 from abpframework/web-app-enhancements

pull/19414/head
maliming 3 years ago
committed by GitHub
parent
commit
c7ff84a59e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 27
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Bundling/AbpScripts.razor
  2. 29
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Bundling/AbpStyles.razor

27
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Bundling/AbpScripts.razor

@ -1,5 +1,7 @@
@using Volo.Abp @using Volo.Abp
@implements IDisposable
@inject IComponentBundleManager BundleManager @inject IComponentBundleManager BundleManager
@inject PersistentComponentState PersistentComponentState
@if (ScriptFiles != null) @if (ScriptFiles != null)
{ {
@ -18,16 +20,37 @@
private List<string>? ScriptFiles { get; set; } private List<string>? ScriptFiles { get; set; }
private PersistingComponentStateSubscription persistingSubscription;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
if (BundleName == null) if (BundleName == null)
{ {
throw new AbpException("The BundleName parameter of the AbpScripts component can not be null!"); throw new AbpException("The BundleName parameter of the AbpScripts component can not be null!");
} }
ScriptFiles = (await BundleManager.GetScriptBundleFilesAsync(BundleName!)).ToList();
persistingSubscription = PersistentComponentState.RegisterOnPersisting(PersistScriptFiles);
if (PersistentComponentState.TryTakeFromJson<List<string>>(nameof(ScriptFiles), out var restoredStyleFiles))
{
ScriptFiles = restoredStyleFiles;
}
else
{
ScriptFiles = (await BundleManager.GetScriptBundleFilesAsync(BundleName!)).ToList();
}
if (OperatingSystem.IsBrowser() && WebAssemblyScriptFiles != null) if (OperatingSystem.IsBrowser() && WebAssemblyScriptFiles != null)
{ {
ScriptFiles.AddRange(WebAssemblyScriptFiles); ScriptFiles?.AddRange(WebAssemblyScriptFiles);
} }
} }
private Task PersistScriptFiles()
{
PersistentComponentState.PersistAsJson(nameof(ScriptFiles), ScriptFiles);
return Task.CompletedTask;
}
public void Dispose() => persistingSubscription.Dispose();
} }

29
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Bundling/AbpStyles.razor

@ -1,11 +1,13 @@
@using Volo.Abp @using Volo.Abp
@implements IDisposable
@inject IComponentBundleManager BundleManager @inject IComponentBundleManager BundleManager
@inject PersistentComponentState PersistentComponentState
@if (StyleFiles != null) @if (StyleFiles != null)
{ {
foreach (var file in StyleFiles) foreach (var file in StyleFiles)
{ {
<link rel="stylesheet" href="@file"/> <link rel="stylesheet" href="@file" />
} }
} }
@ -18,16 +20,37 @@
private List<string>? StyleFiles { get; set; } private List<string>? StyleFiles { get; set; }
private PersistingComponentStateSubscription persistingSubscription;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
if (BundleName == null) if (BundleName == null)
{ {
throw new AbpException("The BundleName parameter of the AbpStyles component can not be null!"); throw new AbpException("The BundleName parameter of the AbpStyles component can not be null!");
} }
StyleFiles = (await BundleManager.GetStyleBundleFilesAsync(BundleName!)).ToList();
persistingSubscription = PersistentComponentState.RegisterOnPersisting(PersistStyleFiles);
if (PersistentComponentState.TryTakeFromJson<List<string>>(nameof(StyleFiles), out var restoredStyleFiles))
{
StyleFiles = restoredStyleFiles;
}
else
{
StyleFiles = (await BundleManager.GetStyleBundleFilesAsync(BundleName!)).ToList();
}
if (OperatingSystem.IsBrowser() && WebAssemblyStyleFiles != null) if (OperatingSystem.IsBrowser() && WebAssemblyStyleFiles != null)
{ {
StyleFiles.AddRange(WebAssemblyStyleFiles); StyleFiles?.AddRange(WebAssemblyStyleFiles);
} }
} }
private Task PersistStyleFiles()
{
PersistentComponentState.PersistAsJson(nameof(StyleFiles), StyleFiles);
return Task.CompletedTask;
}
public void Dispose() => persistingSubscription.Dispose();
} }

Loading…
Cancel
Save