Options are now sent with the message.

Cleaned and optimized the code.
pull/5712/head
Mladen Macanovic 5 years ago
parent 38c3579d29
commit 63c87a106e

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

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

@ -5,27 +5,27 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly
{
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;
}
public Task SuccessAsync(string message, string title = null)
public Task SuccessAsync(string message, string title = null, UiMessageOptions options = null)
{
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;
}
public Task ErrorAsync(string message, string title = null)
public Task ErrorAsync(string message, string title = null, UiMessageOptions options = null)
{
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);
}

@ -1,19 +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; }
}
}

@ -14,27 +14,27 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly
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);
}
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);
}
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);
}
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);
}
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);
}

@ -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,31 +20,31 @@ namespace Volo.Abp.BlazoriseUI
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>();
await uiMessageNotifierService.NotifyConfirmationReceivedAsync(message, title, callback);
await uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Confirmation, message, title, options, callback);
return await callback.Task;
}

@ -21,6 +21,7 @@ namespace Volo.Abp.BlazoriseUI.Components
MessageType = e.MessageType;
Message = e.Message;
Title = e.Title;
Options = e.Options;
Callback = e.Callback;
ModalRef.Show();
@ -73,7 +74,7 @@ namespace Volo.Abp.BlazoriseUI.Components
protected virtual bool ShowMessageIcon
=> Options?.ShowMessageIcon ?? true;
protected virtual object MessageIcon => MessageType switch
protected virtual object MessageIcon => Options?.MessageIcon ?? MessageType switch
{
UiMessageType.Info => IconName.Info,
UiMessageType.Success => IconName.Check,
@ -85,6 +86,7 @@ namespace Volo.Abp.BlazoriseUI.Components
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))",

@ -10,16 +10,9 @@ namespace Volo.Abp.BlazoriseUI
{
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));
return Task.CompletedTask;
}
public Task NotifyConfirmationReceivedAsync(string message, string title, TaskCompletionSource<bool> callback)
{
MessageReceived?.Invoke(this, new UiMessageEventArgs(UiMessageType.Confirmation, message, title, callback));
MessageReceived?.Invoke(this, new UiMessageEventArgs(messageType, message, title, options, callback));
return Task.CompletedTask;
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Blazorise;
using Microsoft.AspNetCore.Components;
using Volo.Abp.AspNetCore.Components.WebAssembly;
@ -23,7 +24,11 @@ namespace MyCompanyName.MyProjectName.Blazor.Pages
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()

Loading…
Cancel
Save