mirror of https://github.com/abpframework/abp.git
committed by
GitHub
19 changed files with 522 additions and 53 deletions
@ -0,0 +1,33 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
public class NullUiMessageService : IUiMessageService, ITransientDependency |
|||
{ |
|||
public Task InfoAsync(string message, string title = null, UiMessageOptions options = null) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task SuccessAsync(string message, string title = null, UiMessageOptions options = null) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task WarnAsync(string message, string title = null, UiMessageOptions options = null) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task ErrorAsync(string message, string title = null, UiMessageOptions options = null) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task<bool> ConfirmAsync(string message, string title = null, UiMessageOptions options = null) |
|||
{ |
|||
return Task.FromResult(true); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
public class UiMessageEventArgs : EventArgs |
|||
{ |
|||
public UiMessageEventArgs(UiMessageType messageType, string message, string title, UiMessageOptions options) |
|||
{ |
|||
MessageType = messageType; |
|||
Message = message; |
|||
Title = title; |
|||
Options = options; |
|||
} |
|||
|
|||
public UiMessageEventArgs(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource<bool> callback) |
|||
{ |
|||
MessageType = messageType; |
|||
Message = message; |
|||
Title = title; |
|||
Options = options; |
|||
Callback = callback; |
|||
} |
|||
|
|||
public UiMessageType MessageType { get; set; } |
|||
|
|||
public string Message { get; } |
|||
|
|||
public string Title { get; } |
|||
|
|||
public UiMessageOptions Options { get; } |
|||
|
|||
public TaskCompletionSource<bool> Callback { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
/// <summary>
|
|||
/// Options to override message dialog appearance.
|
|||
/// </summary>
|
|||
public class UiMessageOptions |
|||
{ |
|||
/// <summary>
|
|||
/// If true, the message dialog will show the large icon for the current message type.
|
|||
/// </summary>
|
|||
public bool ShowMessageIcon { get; set; } = true; |
|||
|
|||
/// <summary>
|
|||
/// Overrides the build-in message icon.
|
|||
/// </summary>
|
|||
public object MessageIcon { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Custom text for the Ok button.
|
|||
/// </summary>
|
|||
public string OkButtonText { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Custom icon for the Ok button.
|
|||
/// </summary>
|
|||
public object OkButtonIcon { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Custom text for the Confirmation button.
|
|||
/// </summary>
|
|||
public string ConfirmButtonText { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Custom icon for the Confirmation button.
|
|||
/// </summary>
|
|||
public object ConfirmButtonIcon { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Custom text for the Cancel button.
|
|||
/// </summary>
|
|||
public string CancelButtonText { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Custom icon for the Cancel button.
|
|||
/// </summary>
|
|||
public object CancelButtonIcon { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly |
|||
{ |
|||
/// <summary>
|
|||
/// Defines the possible ui message types with predefined actions.
|
|||
/// </summary>
|
|||
public enum UiMessageType |
|||
{ |
|||
Info, |
|||
Success, |
|||
Warning, |
|||
Error, |
|||
Confirmation, |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Logging.Abstractions; |
|||
using Volo.Abp.AspNetCore.Components.WebAssembly; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI |
|||
{ |
|||
[Dependency(ReplaceServices = true)] |
|||
public class BlazoriseUiMessageService : IUiMessageService, IScopedDependency |
|||
{ |
|||
private readonly UiMessageNotifierService uiMessageNotifierService; |
|||
|
|||
public ILogger<BlazoriseUiMessageService> Logger { get; set; } |
|||
|
|||
public BlazoriseUiMessageService(UiMessageNotifierService uiMessageNotifierService) |
|||
{ |
|||
this.uiMessageNotifierService = uiMessageNotifierService; |
|||
|
|||
Logger = NullLogger<BlazoriseUiMessageService>.Instance; |
|||
} |
|||
|
|||
public Task InfoAsync(string message, string title = null, UiMessageOptions options = null) |
|||
{ |
|||
return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Info, message, title, options); |
|||
} |
|||
|
|||
public Task SuccessAsync(string message, string title = null, UiMessageOptions options = null) |
|||
{ |
|||
return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Success, message, title, options); |
|||
} |
|||
|
|||
public Task WarnAsync(string message, string title = null, UiMessageOptions options = null) |
|||
{ |
|||
return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Warning, message, title, options); |
|||
} |
|||
|
|||
public Task ErrorAsync(string message, string title = null, UiMessageOptions options = null) |
|||
{ |
|||
return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Error, message, title, options); |
|||
} |
|||
|
|||
public async Task<bool> ConfirmAsync(string message, string title = null, UiMessageOptions options = null) |
|||
{ |
|||
var callback = new TaskCompletionSource<bool>(); |
|||
|
|||
await uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Confirmation, message, title, options, callback); |
|||
|
|||
return await callback.Task; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<Modal @ref="@ModalRef"> |
|||
<ModalBackdrop /> |
|||
<ModalContent Centered="true"> |
|||
<ModalHeader> |
|||
<ModalTitle> |
|||
@Title |
|||
</ModalTitle> |
|||
</ModalHeader> |
|||
<ModalBody> |
|||
@if ( ShowMessageIcon ) |
|||
{ |
|||
<DisplayHeading Size="DisplayHeadingSize.Is2" Style="text-align:center;"> |
|||
<Icon Name="@MessageIcon" Style="@MessageIconStyle" /> |
|||
</DisplayHeading> |
|||
} |
|||
@Message |
|||
</ModalBody> |
|||
<ModalFooter> |
|||
@if ( IsConfirmation ) |
|||
{ |
|||
<Button Color="Color.Danger" Padding="Padding.Is2.OnX" Margin="Margin.IsAuto.FromRight" Clicked="@OnCancelClicked"> |
|||
@if ( Options?.CancelButtonIcon != null ) |
|||
{ |
|||
<Icon Name="@Options.CancelButtonIcon" Margin="Margin.Is2.FromRight" /> |
|||
} |
|||
@CancelButtonText |
|||
</Button> |
|||
<Button Color="Color.Primary" Padding="Padding.Is2.OnX" Clicked="@OnConfirmClicked"> |
|||
@if ( Options?.ConfirmButtonIcon != null ) |
|||
{ |
|||
<Icon Name="@Options.ConfirmButtonIcon" Margin="Margin.Is2.FromRight" /> |
|||
} |
|||
@ConfirmButtonText |
|||
</Button> |
|||
} |
|||
else |
|||
{ |
|||
<Button Color="Color.Primary" Padding="Padding.Is2.OnX" Clicked="@OnOkClicked"> |
|||
@if ( Options?.OkButtonIcon != null ) |
|||
{ |
|||
<Icon Name="@Options.OkButtonIcon" Margin="Margin.Is2.FromRight" /> |
|||
} |
|||
@OkButtonText |
|||
</Button> |
|||
} |
|||
</ModalFooter> |
|||
</ModalContent> |
|||
</Modal> |
|||
@ -0,0 +1,137 @@ |
|||
using System; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Blazorise; |
|||
using Microsoft.AspNetCore.Components; |
|||
using Volo.Abp.AspNetCore.Components.WebAssembly; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components |
|||
{ |
|||
public partial class UiMessageAlert : ComponentBase, IDisposable |
|||
{ |
|||
protected override void OnInitialized() |
|||
{ |
|||
UiMessageNotifierService.MessageReceived += OnMessageReceived; |
|||
|
|||
base.OnInitialized(); |
|||
} |
|||
|
|||
private void OnMessageReceived(object sender, UiMessageEventArgs e) |
|||
{ |
|||
MessageType = e.MessageType; |
|||
Message = e.Message; |
|||
Title = e.Title; |
|||
Options = e.Options; |
|||
Callback = e.Callback; |
|||
|
|||
ModalRef.Show(); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
if (UiMessageNotifierService != null) |
|||
{ |
|||
UiMessageNotifierService.MessageReceived -= OnMessageReceived; |
|||
} |
|||
} |
|||
|
|||
protected Task OnOkClicked() |
|||
{ |
|||
ModalRef.Hide(); |
|||
|
|||
return Okayed.InvokeAsync(null); |
|||
} |
|||
|
|||
protected Task OnConfirmClicked() |
|||
{ |
|||
ModalRef.Hide(); |
|||
|
|||
if (IsConfirmation && Callback != null) |
|||
{ |
|||
Callback.SetResult(true); |
|||
} |
|||
|
|||
return Confirmed.InvokeAsync(null); |
|||
} |
|||
|
|||
protected Task OnCancelClicked() |
|||
{ |
|||
ModalRef.Hide(); |
|||
|
|||
if (IsConfirmation && Callback != null) |
|||
{ |
|||
Callback.SetResult(false); |
|||
} |
|||
|
|||
return Canceled.InvokeAsync(null); |
|||
} |
|||
|
|||
protected Modal ModalRef { get; set; } |
|||
|
|||
protected virtual bool IsConfirmation |
|||
=> MessageType == UiMessageType.Confirmation; |
|||
|
|||
protected virtual bool ShowMessageIcon |
|||
=> Options?.ShowMessageIcon ?? true; |
|||
|
|||
protected virtual object MessageIcon => Options?.MessageIcon ?? MessageType switch |
|||
{ |
|||
UiMessageType.Info => IconName.Info, |
|||
UiMessageType.Success => IconName.Check, |
|||
UiMessageType.Warning => IconName.Exclamation, |
|||
UiMessageType.Error => IconName.Times, |
|||
UiMessageType.Confirmation => IconName.QuestionCircle, |
|||
_ => null, |
|||
}; |
|||
|
|||
protected virtual string MessageIconColor => MessageType switch |
|||
{ |
|||
// gets the color in the order of importance: Blazorise > Bootstrap > fallback color
|
|||
UiMessageType.Info => "var(--b-theme-info, var(--info, #17a2b8))", |
|||
UiMessageType.Success => "var(--b-theme-success, var(--success, #28a745))", |
|||
UiMessageType.Warning => "var(--b-theme-warning, var(--warning, #ffc107))", |
|||
UiMessageType.Error => "var(--b-theme-danger, var(--danger, #dc3545))", |
|||
UiMessageType.Confirmation => "var(--b-theme-secondary, var(--secondary, #6c757d))", |
|||
_ => null, |
|||
}; |
|||
|
|||
protected virtual string MessageIconStyle |
|||
{ |
|||
get |
|||
{ |
|||
var sb = new StringBuilder(); |
|||
|
|||
sb.Append($"color:{MessageIconColor}"); |
|||
|
|||
return sb.ToString(); |
|||
} |
|||
} |
|||
|
|||
protected virtual string OkButtonText |
|||
=> Options?.OkButtonText ?? "OK"; |
|||
|
|||
protected virtual string ConfirmButtonText |
|||
=> Options?.ConfirmButtonText ?? "Confirm"; |
|||
|
|||
protected virtual string CancelButtonText |
|||
=> Options?.CancelButtonText ?? "Cancel"; |
|||
|
|||
[Parameter] public UiMessageType MessageType { get; set; } |
|||
|
|||
[Parameter] public string Title { get; set; } |
|||
|
|||
[Parameter] public string Message { get; set; } |
|||
|
|||
[Parameter] public TaskCompletionSource<bool> Callback { get; set; } |
|||
|
|||
[Parameter] public UiMessageOptions Options { get; set; } |
|||
|
|||
[Parameter] public EventCallback Okayed { get; set; } // TODO: ?
|
|||
|
|||
[Parameter] public EventCallback Confirmed { get; set; } |
|||
|
|||
[Parameter] public EventCallback Canceled { get; set; } |
|||
|
|||
[Inject] protected UiMessageNotifierService UiMessageNotifierService { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.AspNetCore.Components.WebAssembly; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI |
|||
{ |
|||
[Dependency(ReplaceServices = true)] |
|||
public class UiMessageNotifierService : IScopedDependency |
|||
{ |
|||
public event EventHandler<UiMessageEventArgs> MessageReceived; |
|||
|
|||
public Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource<bool> callback = null) |
|||
{ |
|||
MessageReceived?.Invoke(this, new UiMessageEventArgs(messageType, message, title, options, callback)); |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
@using Microsoft.AspNetCore.Components.Web |
|||
@using Blazorise |
|||
@ -0,0 +1,66 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using Blazorise; |
|||
using Microsoft.AspNetCore.Components; |
|||
using Volo.Abp.AspNetCore.Components.WebAssembly; |
|||
|
|||
namespace MyCompanyName.MyProjectName.Blazor.Pages |
|||
{ |
|||
public partial class Index |
|||
{ |
|||
private IEnumerable<Claim> _claims; |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); |
|||
if ( authState.User.Identity.IsAuthenticated ) |
|||
{ |
|||
_claims = authState.User.Claims; |
|||
} |
|||
} |
|||
|
|||
Task OnInfoTestClicked() |
|||
{ |
|||
return UiMessageService.InfoAsync( "This is the Info message", "Info", new UiMessageOptions |
|||
{ |
|||
OkButtonIcon = IconName.InfoCircle, |
|||
OkButtonText = "Hello info" |
|||
} ); |
|||
} |
|||
|
|||
Task OnSuccessTestClicked() |
|||
{ |
|||
return UiMessageService.SuccessAsync( "This is the Success message", "Success" ); |
|||
} |
|||
|
|||
Task OnWarningTestClicked() |
|||
{ |
|||
return UiMessageService.WarnAsync( "This is the Warning message", "Warning" ); |
|||
} |
|||
|
|||
Task OnErrorTestClicked() |
|||
{ |
|||
return UiMessageService.ErrorAsync( "This is the Error message", "Error" ); |
|||
} |
|||
|
|||
Task OnConfirmTestClicked() |
|||
{ |
|||
return UiMessageService.ConfirmAsync( "This is the Confirm message", "Confirm" ) |
|||
.ContinueWith( result => |
|||
{ |
|||
if ( result.Result ) |
|||
{ |
|||
Console.WriteLine( "Confirmed" ); |
|||
} |
|||
else |
|||
{ |
|||
Console.WriteLine( "Cancelled" ); |
|||
} |
|||
} ); |
|||
} |
|||
|
|||
[Inject] IUiMessageService UiMessageService { get; set; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue