Browse Source

Options are now sent with the message.

Cleaned and optimized the code.
pull/5712/head
Mladen Macanovic 6 years ago
parent
commit
63c87a106e
  1. 21
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs
  2. 18
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageService.cs
  3. 10
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs
  4. 29
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageOptions.cs
  5. 14
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageService.cs
  6. 14
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageType.cs
  7. 20
      framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs
  8. 4
      framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs
  9. 11
      framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs
  10. 7
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs

21
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs

@ -7,25 +7,25 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly
{ {
event EventHandler<UiMessageEventArgs> MessageReceived; event EventHandler<UiMessageEventArgs> MessageReceived;
Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title = null); Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource<bool> callback = null);
Task NotifyConfirmationReceivedAsync(string message, string title, TaskCompletionSource<bool> callback);
} }
public class UiMessageEventArgs : EventArgs public class UiMessageEventArgs : EventArgs
{ {
public UiMessageEventArgs(UiMessageType messageType, string message, string title) public UiMessageEventArgs(UiMessageType messageType, string message, string title, UiMessageOptions options)
{ {
MessageType = messageType; MessageType = messageType;
Message = message; Message = message;
Title = title; Title = title;
Options = options;
} }
public UiMessageEventArgs(UiMessageType messageType, string message, string title, TaskCompletionSource<bool> callback) public UiMessageEventArgs(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource<bool> callback)
{ {
MessageType = messageType; MessageType = messageType;
Message = message; Message = message;
Title = title; Title = title;
Options = options;
Callback = callback; Callback = callback;
} }
@ -35,15 +35,8 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly
public string Title { get; } public string Title { get; }
public TaskCompletionSource<bool> Callback { get; } public UiMessageOptions Options { get; }
}
public enum UiMessageType public TaskCompletionSource<bool> Callback { get; }
{
Info,
Success,
Warning,
Error,
Confirmation,
} }
} }

18
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageService.cs

@ -4,14 +4,14 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly
{ {
public interface IUiMessageService public interface IUiMessageService
{ {
Task InfoAsync(string message, string title = null); Task InfoAsync(string message, string title = null, UiMessageOptions options = null);
Task SuccessAsync(string message, string title = null); Task SuccessAsync(string message, string title = null, UiMessageOptions options = null);
Task WarnAsync(string message, string title = null); Task WarnAsync(string message, string title = null, UiMessageOptions options = null);
Task ErrorAsync(string message, string title = null); Task ErrorAsync(string message, string title = null, UiMessageOptions options = null);
Task<bool> ConfirmAsync(string message, string title = null); Task<bool> ConfirmAsync(string message, string title = null, UiMessageOptions options = null);
} }
} }

10
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs

@ -5,27 +5,27 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly
{ {
public class NullUiMessageService : IUiMessageService, ITransientDependency public class NullUiMessageService : IUiMessageService, ITransientDependency
{ {
public Task InfoAsync(string message, string title = null) public Task InfoAsync(string message, string title = null, UiMessageOptions options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task SuccessAsync(string message, string title = null) public Task SuccessAsync(string message, string title = null, UiMessageOptions options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task WarnAsync(string message, string title = null) public Task WarnAsync(string message, string title = null, UiMessageOptions options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task ErrorAsync(string message, string title = null) public Task ErrorAsync(string message, string title = null, UiMessageOptions options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task<bool> ConfirmAsync(string message, string title = null) public Task<bool> ConfirmAsync(string message, string title = null, UiMessageOptions options = null)
{ {
return Task.FromResult(true); return Task.FromResult(true);
} }

29
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageOptions.cs

@ -1,19 +1,48 @@
namespace Volo.Abp.AspNetCore.Components.WebAssembly namespace Volo.Abp.AspNetCore.Components.WebAssembly
{ {
/// <summary>
/// Options to override message dialog appearance.
/// </summary>
public class UiMessageOptions 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; 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; } public string OkButtonText { get; set; }
/// <summary>
/// Custom icon for the Ok button.
/// </summary>
public object OkButtonIcon { get; set; } public object OkButtonIcon { get; set; }
/// <summary>
/// Custom text for the Confirmation button.
/// </summary>
public string ConfirmButtonText { get; set; } public string ConfirmButtonText { get; set; }
/// <summary>
/// Custom icon for the Confirmation button.
/// </summary>
public object ConfirmButtonIcon { get; set; } public object ConfirmButtonIcon { get; set; }
/// <summary>
/// Custom text for the Cancel button.
/// </summary>
public string CancelButtonText { get; set; } public string CancelButtonText { get; set; }
/// <summary>
/// Custom icon for the Cancel button.
/// </summary>
public object CancelButtonIcon { get; set; } public object CancelButtonIcon { get; set; }
} }
} }

14
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageService.cs

@ -14,27 +14,27 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly
JsRuntime = jsRuntime; JsRuntime = jsRuntime;
} }
public async Task InfoAsync(string message, string title = null) public async Task InfoAsync(string message, string title = null, UiMessageOptions options = null)
{ {
await JsRuntime.InvokeVoidAsync("alert", message); await JsRuntime.InvokeVoidAsync("alert", message);
} }
public async Task SuccessAsync(string message, string title = null) public async Task SuccessAsync(string message, string title = null, UiMessageOptions options = null)
{ {
await JsRuntime.InvokeVoidAsync("alert", message); await JsRuntime.InvokeVoidAsync("alert", message);
} }
public async Task WarnAsync(string message, string title = null) public async Task WarnAsync(string message, string title = null, UiMessageOptions options = null)
{ {
await JsRuntime.InvokeVoidAsync("alert", message); await JsRuntime.InvokeVoidAsync("alert", message);
} }
public async Task ErrorAsync(string message, string title = null) public async Task ErrorAsync(string message, string title = null, UiMessageOptions options = null)
{ {
await JsRuntime.InvokeVoidAsync("alert", message); await JsRuntime.InvokeVoidAsync("alert", message);
} }
public async Task<bool> ConfirmAsync(string message, string title = null) public async Task<bool> ConfirmAsync(string message, string title = null, UiMessageOptions options = null)
{ {
return await JsRuntime.InvokeAsync<bool>("confirm", message); return await JsRuntime.InvokeAsync<bool>("confirm", message);
} }

14
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageType.cs

@ -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,
}
}

20
framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs

@ -20,31 +20,31 @@ namespace Volo.Abp.BlazoriseUI
Logger = NullLogger<BlazoriseUiMessageService>.Instance; Logger = NullLogger<BlazoriseUiMessageService>.Instance;
} }
public Task InfoAsync(string message, string title = null) public Task InfoAsync(string message, string title = null, UiMessageOptions options = null)
{ {
return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Info, message, title); return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Info, message, title, options);
} }
public Task SuccessAsync(string message, string title = null) public Task SuccessAsync(string message, string title = null, UiMessageOptions options = null)
{ {
return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Success, message, title); return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Success, message, title, options);
} }
public Task WarnAsync(string message, string title = null) public Task WarnAsync(string message, string title = null, UiMessageOptions options = null)
{ {
return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Warning, message, title); return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Warning, message, title, options);
} }
public Task ErrorAsync(string message, string title = null) public Task ErrorAsync(string message, string title = null, UiMessageOptions options = null)
{ {
return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Error, message, title); return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Error, message, title, options);
} }
public async Task<bool> ConfirmAsync(string message, string title = null) public async Task<bool> ConfirmAsync(string message, string title = null, UiMessageOptions options = null)
{ {
var callback = new TaskCompletionSource<bool>(); var callback = new TaskCompletionSource<bool>();
await uiMessageNotifierService.NotifyConfirmationReceivedAsync(message, title, callback); await uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Confirmation, message, title, options, callback);
return await callback.Task; return await callback.Task;
} }

4
framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs

@ -21,6 +21,7 @@ namespace Volo.Abp.BlazoriseUI.Components
MessageType = e.MessageType; MessageType = e.MessageType;
Message = e.Message; Message = e.Message;
Title = e.Title; Title = e.Title;
Options = e.Options;
Callback = e.Callback; Callback = e.Callback;
ModalRef.Show(); ModalRef.Show();
@ -73,7 +74,7 @@ namespace Volo.Abp.BlazoriseUI.Components
protected virtual bool ShowMessageIcon protected virtual bool ShowMessageIcon
=> Options?.ShowMessageIcon ?? true; => Options?.ShowMessageIcon ?? true;
protected virtual object MessageIcon => MessageType switch protected virtual object MessageIcon => Options?.MessageIcon ?? MessageType switch
{ {
UiMessageType.Info => IconName.Info, UiMessageType.Info => IconName.Info,
UiMessageType.Success => IconName.Check, UiMessageType.Success => IconName.Check,
@ -85,6 +86,7 @@ namespace Volo.Abp.BlazoriseUI.Components
protected virtual string MessageIconColor => MessageType switch 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.Info => "var(--b-theme-info, var(--info, #17a2b8))",
UiMessageType.Success => "var(--b-theme-success, var(--success, #28a745))", UiMessageType.Success => "var(--b-theme-success, var(--success, #28a745))",
UiMessageType.Warning => "var(--b-theme-warning, var(--warning, #ffc107))", UiMessageType.Warning => "var(--b-theme-warning, var(--warning, #ffc107))",

11
framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs

@ -10,16 +10,9 @@ namespace Volo.Abp.BlazoriseUI
{ {
public event EventHandler<UiMessageEventArgs> MessageReceived; public event EventHandler<UiMessageEventArgs> MessageReceived;
public Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title = null) public Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource<bool> callback)
{ {
MessageReceived?.Invoke(this, new UiMessageEventArgs(messageType, message, title)); MessageReceived?.Invoke(this, new UiMessageEventArgs(messageType, message, title, options, callback));
return Task.CompletedTask;
}
public Task NotifyConfirmationReceivedAsync(string message, string title, TaskCompletionSource<bool> callback)
{
MessageReceived?.Invoke(this, new UiMessageEventArgs(UiMessageType.Confirmation, message, title, callback));
return Task.CompletedTask; return Task.CompletedTask;
} }

7
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Blazorise;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Volo.Abp.AspNetCore.Components.WebAssembly; using Volo.Abp.AspNetCore.Components.WebAssembly;
@ -23,7 +24,11 @@ namespace MyCompanyName.MyProjectName.Blazor.Pages
Task OnInfoTestClicked() Task OnInfoTestClicked()
{ {
return UiMessageService.InfoAsync( "This is the Info message", "Info" ); return UiMessageService.InfoAsync( "This is the Info message", "Info", new UiMessageOptions
{
OkButtonIcon = IconName.InfoCircle,
OkButtonText = "Hello info"
} );
} }
Task OnSuccessTestClicked() Task OnSuccessTestClicked()

Loading…
Cancel
Save