mirror of https://github.com/abpframework/abp.git
9 changed files with 157 additions and 0 deletions
@ -0,0 +1,10 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Progression |
|||
{ |
|||
public interface IUiPageProgressService |
|||
{ |
|||
Task Go(int? percentage, Action<UiPageProgressOptions> options = null); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Progression |
|||
{ |
|||
public class NullUiPageProgressService : IUiPageProgressService, ITransientDependency |
|||
{ |
|||
public Task Go(int? percentage, Action<UiPageProgressOptions> options = null) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Progression |
|||
{ |
|||
public class UiPageProgressEventArgs : EventArgs |
|||
{ |
|||
public UiPageProgressEventArgs(int? percentage, UiPageProgressOptions options) |
|||
{ |
|||
Percentage = percentage; |
|||
Options = options; |
|||
} |
|||
|
|||
public int? Percentage { get; } |
|||
|
|||
public UiPageProgressOptions Options { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
namespace Volo.Abp.AspNetCore.Components.Progression |
|||
{ |
|||
/// <summary>
|
|||
/// Options to override page progress appearance.
|
|||
/// </summary>
|
|||
public class UiPageProgressOptions |
|||
{ |
|||
/// <summary>
|
|||
/// Type or color, of the page progress.
|
|||
/// </summary>
|
|||
public UiPageProgressType Type { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace Volo.Abp.AspNetCore.Components.Progression |
|||
{ |
|||
public enum UiPageProgressType |
|||
{ |
|||
Default, |
|||
Info, |
|||
Success, |
|||
Warning, |
|||
Error, |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.AspNetCore.Components.Progression; |
|||
using Volo.Abp.AspNetCore.Components.WebAssembly; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI |
|||
{ |
|||
[Dependency(ReplaceServices = true)] |
|||
public class BlazoriseUiPageProgressService : IUiPageProgressService, IScopedDependency |
|||
{ |
|||
/// <summary>
|
|||
/// An event raised after the notification is received.
|
|||
/// </summary>
|
|||
public event EventHandler<UiPageProgressEventArgs> ProgressChanged; |
|||
|
|||
public Task Go(int? percentage, Action<UiPageProgressOptions> options = null) |
|||
{ |
|||
var uiPageProgressOptions = CreateDefaultOptions(); |
|||
options?.Invoke(uiPageProgressOptions); |
|||
|
|||
ProgressChanged?.Invoke(this, new UiPageProgressEventArgs(percentage, uiPageProgressOptions)); |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
protected virtual UiPageProgressOptions CreateDefaultOptions() |
|||
{ |
|||
return new UiPageProgressOptions(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
<PageProgress @ref="@PageProgressRef" Visible="@Visible" Color="@Color" /> |
|||
@ -0,0 +1,58 @@ |
|||
using System; |
|||
using Blazorise; |
|||
using Microsoft.AspNetCore.Components; |
|||
using Volo.Abp.AspNetCore.Components.Progression; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components |
|||
{ |
|||
public partial class UiPageProgress : ComponentBase, IDisposable |
|||
{ |
|||
protected PageProgress PageProgressRef { get; set; } |
|||
|
|||
protected int? Percentage { get; set; } |
|||
|
|||
protected bool Visible { get; set; } |
|||
|
|||
protected Color Color { get; set; } |
|||
|
|||
[Inject] protected BlazoriseUiPageProgressService UiPageProgressService { get; set; } |
|||
|
|||
protected override void OnInitialized() |
|||
{ |
|||
base.OnInitialized(); |
|||
|
|||
UiPageProgressService.ProgressChanged += OnProgressChanged; |
|||
} |
|||
|
|||
private async void OnProgressChanged(object sender, UiPageProgressEventArgs e) |
|||
{ |
|||
Percentage = e.Percentage; |
|||
Visible = e.Percentage == null || (e.Percentage >= 0 && e.Percentage <= 100); |
|||
Color = GetColor(e.Options.Type); |
|||
|
|||
await PageProgressRef.SetValueAsync(e.Percentage); |
|||
|
|||
await InvokeAsync(StateHasChanged); |
|||
} |
|||
|
|||
public virtual void Dispose() |
|||
{ |
|||
if (UiPageProgressService != null) |
|||
{ |
|||
UiPageProgressService.ProgressChanged -= OnProgressChanged; |
|||
} |
|||
} |
|||
|
|||
protected virtual Color GetColor(UiPageProgressType pageProgressType) |
|||
{ |
|||
return pageProgressType switch |
|||
{ |
|||
UiPageProgressType.Info => Color.Info, |
|||
UiPageProgressType.Success => Color.Success, |
|||
UiPageProgressType.Warning => Color.Warning, |
|||
UiPageProgressType.Error => Color.Danger, |
|||
_ => Color.None, |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue