From 9dcf9a789eacc3fc87738456053077b9fcf50843 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Mon, 5 Oct 2020 13:05:29 +0200 Subject: [PATCH 1/7] First UiMessageAlert test --- framework/Volo.Abp.sln | 28 ++++----- .../WebAssembly/IUiMessageNotifierService.cs | 25 ++++++++ .../WebAssembly/NullUiMessageService.cs | 33 +++++++++++ .../Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs | 4 +- .../BlazoriseUiMessageService.cs | 49 ++++++++++++++++ .../Components/UiMessageAlert.razor | 17 ++++++ .../Components/UiMessageAlert.razor.cs | 58 +++++++++++++++++++ .../UiMessageNotifierService.cs | 20 +++++++ .../Volo.Abp.BlazoriseUI.csproj | 2 +- .../src/Volo.Abp.BlazoriseUI/_Imports.razor | 2 + .../MyCompanyName.MyProjectName.Blazor.csproj | 1 + .../Pages/Index.razor | 20 ++++++- .../_Imports.razor | 2 + 13 files changed, 242 insertions(+), 19 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs create mode 100644 framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs create mode 100644 framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor create mode 100644 framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs create mode 100644 framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs create mode 100644 framework/src/Volo.Abp.BlazoriseUI/_Imports.razor diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 503b42c7e1..53666c57c1 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -319,33 +319,33 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Aliyun EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Aliyun.Tests", "test\Volo.Abp.BlobStoring.Aliyun.Tests\Volo.Abp.BlobStoring.Aliyun.Tests.csproj", "{8E49687A-E69F-49F2-8DB0-428D0883A937}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BlobStoring.Aws", "src\Volo.Abp.BlobStoring.Aws\Volo.Abp.BlobStoring.Aws.csproj", "{50968CDE-1029-4051-B2E5-B69D0ECF2A18}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Aws", "src\Volo.Abp.BlobStoring.Aws\Volo.Abp.BlobStoring.Aws.csproj", "{50968CDE-1029-4051-B2E5-B69D0ECF2A18}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BlobStoring.Aws.Tests", "test\Volo.Abp.BlobStoring.Aws.Tests\Volo.Abp.BlobStoring.Aws.Tests.csproj", "{2CD3B26A-CA81-4279-8D5D-6A594517BB3F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlobStoring.Aws.Tests", "test\Volo.Abp.BlobStoring.Aws.Tests\Volo.Abp.BlobStoring.Aws.Tests.csproj", "{2CD3B26A-CA81-4279-8D5D-6A594517BB3F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Kafka", "src\Volo.Abp.Kafka\Volo.Abp.Kafka.csproj", "{2A864049-9CD5-4493-8CDB-C408474D43D4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Kafka", "src\Volo.Abp.Kafka\Volo.Abp.Kafka.csproj", "{2A864049-9CD5-4493-8CDB-C408474D43D4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.EventBus.Kafka", "src\Volo.Abp.EventBus.Kafka\Volo.Abp.EventBus.Kafka.csproj", "{C1D891B0-AE83-42CB-987D-425A2787DE78}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.EventBus.Kafka", "src\Volo.Abp.EventBus.Kafka\Volo.Abp.EventBus.Kafka.csproj", "{C1D891B0-AE83-42CB-987D-425A2787DE78}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.GlobalFeatures", "src\Volo.Abp.GlobalFeatures\Volo.Abp.GlobalFeatures.csproj", "{04F44063-C952-403A-815F-EFB778BDA125}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.GlobalFeatures", "src\Volo.Abp.GlobalFeatures\Volo.Abp.GlobalFeatures.csproj", "{04F44063-C952-403A-815F-EFB778BDA125}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.GlobalFeatures.Tests", "test\Volo.Abp.GlobalFeatures.Tests\Volo.Abp.GlobalFeatures.Tests.csproj", "{231F1581-AA21-44C3-BF27-51EB3AD5355C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.GlobalFeatures.Tests", "test\Volo.Abp.GlobalFeatures.Tests\Volo.Abp.GlobalFeatures.Tests.csproj", "{231F1581-AA21-44C3-BF27-51EB3AD5355C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Http.Client.IdentityModel.WebAssembly", "src\Volo.Abp.Http.Client.IdentityModel.WebAssembly\Volo.Abp.Http.Client.IdentityModel.WebAssembly.csproj", "{3D35A1E0-A9A1-404F-9B55-5F1A7EB6D5B8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Http.Client.IdentityModel.WebAssembly", "src\Volo.Abp.Http.Client.IdentityModel.WebAssembly\Volo.Abp.Http.Client.IdentityModel.WebAssembly.csproj", "{3D35A1E0-A9A1-404F-9B55-5F1A7EB6D5B8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.Client.Common", "src\Volo.Abp.AspNetCore.Mvc.Client.Common\Volo.Abp.AspNetCore.Mvc.Client.Common.csproj", "{8A22D962-016E-474A-8BB7-F831F0ABF3AC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AspNetCore.Mvc.Client.Common", "src\Volo.Abp.AspNetCore.Mvc.Client.Common\Volo.Abp.AspNetCore.Mvc.Client.Common.csproj", "{8A22D962-016E-474A-8BB7-F831F0ABF3AC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Components.WebAssembly", "src\Volo.Abp.AspNetCore.Components.WebAssembly\Volo.Abp.AspNetCore.Components.WebAssembly.csproj", "{E1A62D10-F2FB-4040-BD60-11A3934058DF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AspNetCore.Components.WebAssembly", "src\Volo.Abp.AspNetCore.Components.WebAssembly\Volo.Abp.AspNetCore.Components.WebAssembly.csproj", "{E1A62D10-F2FB-4040-BD60-11A3934058DF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BlazoriseUI", "src\Volo.Abp.BlazoriseUI\Volo.Abp.BlazoriseUI.csproj", "{4EBDDB1B-D6C5-4FAE-B5A7-2171B18CDFA5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.BlazoriseUI", "src\Volo.Abp.BlazoriseUI\Volo.Abp.BlazoriseUI.csproj", "{4EBDDB1B-D6C5-4FAE-B5A7-2171B18CDFA5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme", "src\Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme\Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.csproj", "{ABC27C10-C0FF-44CB-B4FF-A09C0B79F695}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme", "src\Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme\Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.csproj", "{ABC27C10-C0FF-44CB-B4FF-A09C0B79F695}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Components.WebAssembly.Theming", "src\Volo.Abp.AspNetCore.Components.WebAssembly.Theming\Volo.Abp.AspNetCore.Components.WebAssembly.Theming.csproj", "{29CA7471-4E3E-4E75-8B33-001DDF682F01}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AspNetCore.Components.WebAssembly.Theming", "src\Volo.Abp.AspNetCore.Components.WebAssembly.Theming\Volo.Abp.AspNetCore.Components.WebAssembly.Theming.csproj", "{29CA7471-4E3E-4E75-8B33-001DDF682F01}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Autofac.WebAssembly", "src\Volo.Abp.Autofac.WebAssembly\Volo.Abp.Autofac.WebAssembly.csproj", "{37F89B0B-1C6B-426F-A5EE-676D1956D9E9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Autofac.WebAssembly", "src\Volo.Abp.Autofac.WebAssembly\Volo.Abp.Autofac.WebAssembly.csproj", "{37F89B0B-1C6B-426F-A5EE-676D1956D9E9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Authentication.OpenIdConnect", "src\Volo.Abp.AspNetCore.Authentication.OpenIdConnect\Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj", "{DEFE3DB2-EA4F-4F90-87FC-B25D64427BC5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AspNetCore.Authentication.OpenIdConnect", "src\Volo.Abp.AspNetCore.Authentication.OpenIdConnect\Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj", "{DEFE3DB2-EA4F-4F90-87FC-B25D64427BC5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs new file mode 100644 index 0000000000..c3f6b917a7 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs @@ -0,0 +1,25 @@ +using System; +using System.Threading.Tasks; + +namespace Volo.Abp.AspNetCore.Components.WebAssembly +{ + public interface IUiMessageNotifierService + { + event EventHandler MessageReceived; + + Task NotifyMessageReceived(string message, string title = null); + } + + public class UiMessageEventArgs : EventArgs + { + public UiMessageEventArgs(string message, string title) + { + Message = message; + Title = title; + } + + public string Message { get; } + + public string Title { get; } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs new file mode 100644 index 0000000000..59830b0480 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs @@ -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) + { + return Task.CompletedTask; + } + + public Task SuccessAsync(string message, string title = null) + { + return Task.CompletedTask; + } + + public Task WarnAsync(string message, string title = null) + { + return Task.CompletedTask; + } + + public Task ErrorAsync(string message, string title = null) + { + return Task.CompletedTask; + } + + public Task ConfirmAsync(string message, string title = null) + { + return Task.FromResult(true); + } + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index 7289ebe954..8723209c53 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -225,7 +225,7 @@ namespace Volo.Abp.BlazoriseUI { if (reference == null) { - reference = (TRef) ScopedServices.GetRequiredService(serviceType); + reference = (TRef)ScopedServices.GetRequiredService(serviceType); } return reference; @@ -266,7 +266,7 @@ namespace Volo.Abp.BlazoriseUI var input = await CreateGetListInputAsync(); var result = await AppService.GetListAsync(input); Entities = MapToListViewModel(result.Items); - TotalCount = (int?) result.TotalCount; + TotalCount = (int?)result.TotalCount; } private IReadOnlyList MapToListViewModel(IReadOnlyList dtos) diff --git a/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs b/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs new file mode 100644 index 0000000000..66bc231ce7 --- /dev/null +++ b/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs @@ -0,0 +1,49 @@ +using System.Threading.Tasks; +using Blazorise; +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 IUiMessageNotifierService uiMessageNotifierService; + + public ILogger Logger { get; set; } + + public BlazoriseUiMessageService(IUiMessageNotifierService uiMessageNotifierService) + { + this.uiMessageNotifierService = uiMessageNotifierService; + + Logger = NullLogger.Instance; + } + + public Task InfoAsync(string message, string title = null) + { + return uiMessageNotifierService.NotifyMessageReceived(message, title); + } + + public Task SuccessAsync(string message, string title = null) + { + return uiMessageNotifierService.NotifyMessageReceived(message, title); + } + + public Task WarnAsync(string message, string title = null) + { + return uiMessageNotifierService.NotifyMessageReceived(message, title); + } + + public Task ErrorAsync(string message, string title = null) + { + return uiMessageNotifierService.NotifyMessageReceived(message, title); + } + + public Task ConfirmAsync(string message, string title = null) + { + return Task.FromResult(true); + } + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor new file mode 100644 index 0000000000..e041053883 --- /dev/null +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor @@ -0,0 +1,17 @@ + + + + + + @Title + + + + @Message + + + + + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs new file mode 100644 index 0000000000..b5ee799bdd --- /dev/null +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +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 += UiMessageNotifierService_MessageReceived; + + base.OnInitialized(); + } + + private void UiMessageNotifierService_MessageReceived(object sender, UiMessageEventArgs e) + { + Message = e.Message; + Title = e.Title; + + ModalRef.Show(); + } + + public void Dispose() + { + if (UiMessageNotifierService != null) + { + UiMessageNotifierService.MessageReceived -= UiMessageNotifierService_MessageReceived; + } + } + + protected Task OnCancelClicked() + { + ModalRef.Hide(); + + return Task.CompletedTask; + } + + protected Task OnOKClicked() + { + ModalRef.Hide(); + + return Task.CompletedTask; + } + + protected Modal ModalRef { get; set; } + + [Inject] IUiMessageNotifierService UiMessageNotifierService { get; set; } + + [Parameter] public string Title { get; set; } + + [Parameter] public string Message { get; set; } + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs b/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs new file mode 100644 index 0000000000..cdd86a75f3 --- /dev/null +++ b/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs @@ -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 : IUiMessageNotifierService, IScopedDependency + { + public event EventHandler MessageReceived; + + public Task NotifyMessageReceived(string message, string title = null) + { + MessageReceived?.Invoke(this, new UiMessageEventArgs(message, title)); + + return Task.CompletedTask; + } + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj b/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj index 12628b1440..091ee37717 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj +++ b/framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj @@ -1,4 +1,4 @@ - + diff --git a/framework/src/Volo.Abp.BlazoriseUI/_Imports.razor b/framework/src/Volo.Abp.BlazoriseUI/_Imports.razor new file mode 100644 index 0000000000..37be71828c --- /dev/null +++ b/framework/src/Volo.Abp.BlazoriseUI/_Imports.razor @@ -0,0 +1,2 @@ +@using Microsoft.AspNetCore.Components.Web +@using Blazorise \ No newline at end of file diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj index cba18ad1bd..ab574cea1d 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj @@ -15,6 +15,7 @@ + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor index 114be0b5e1..3f5e2f52fc 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor @@ -4,6 +4,7 @@ @using System.Security.Claims @using Microsoft.Extensions.Localization @using MyCompanyName.MyProjectName.Localization +@using Volo.Abp.BlazoriseUI.Components @inject ICurrentUser CurrentUser @inject ICurrentTenant CurrentTenant @inject AuthenticationStateProvider AuthenticationStateProvider @@ -14,8 +15,21 @@
Congratulations, MyProjectName is successfully running!
-

Welcome to the Application

+ + + UI Message Tests + + + + + + + +

Welcome to the Application

+

@L["LongWelcomeMessage"]

@if (!CurrentUser.IsAuthenticated) @@ -23,7 +37,7 @@ @L["Login"] - } + }
@@ -161,6 +175,8 @@ @code { + [Inject] IUiMessageService UiMessageService { get; set; } + private IEnumerable _claims; protected override async Task OnInitializedAsync() diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/_Imports.razor b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/_Imports.razor index b1ade9c628..3fcce1e0d0 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/_Imports.razor +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/_Imports.razor @@ -9,3 +9,5 @@ @using MyCompanyName.MyProjectName.Blazor @using Blazorise @using Blazorise.DataGrid +@using Volo.Abp.BlazoriseUI; +@using Volo.Abp.BlazoriseUI.Components; \ No newline at end of file From 8330e0bd21b6d4a94feacdc9a7137ba13139ad8a Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Tue, 6 Oct 2020 11:22:45 +0200 Subject: [PATCH 2/7] WIP: Confirmation message implementation and started the adding options and styles --- .../WebAssembly/IUiMessageNotifierService.cs | 28 +++++- .../WebAssembly/UiMessageOptions.cs | 19 ++++ .../BlazoriseUiMessageService.cs | 17 ++-- .../Components/UiMessageAlert.razor | 37 ++++++- .../Components/UiMessageAlert.razor.cs | 97 +++++++++++++++++-- .../UiMessageNotifierService.cs | 11 ++- .../Pages/Index.razor | 37 +++---- .../Pages/Index.razor.cs | 62 ++++++++++++ 8 files changed, 264 insertions(+), 44 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageOptions.cs create mode 100644 templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs index c3f6b917a7..309b73337b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs @@ -7,19 +7,43 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly { event EventHandler MessageReceived; - Task NotifyMessageReceived(string message, string title = null); + Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title = null); + + Task NotifyConfirmationReceivedAsync(string message, string title, TaskCompletionSource callback); } public class UiMessageEventArgs : EventArgs { - public UiMessageEventArgs(string message, string title) + public UiMessageEventArgs(UiMessageType messageType, string message, string title) + { + MessageType = messageType; + Message = message; + Title = title; + } + + public UiMessageEventArgs(UiMessageType messageType, string message, string title, TaskCompletionSource callback) { + MessageType = messageType; Message = message; Title = title; + Callback = callback; } + public UiMessageType MessageType { get; set; } + public string Message { get; } public string Title { get; } + + public TaskCompletionSource Callback { get; } + } + + public enum UiMessageType + { + Info, + Success, + Warning, + Error, + Confirmation, } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageOptions.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageOptions.cs new file mode 100644 index 0000000000..7909911c7e --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageOptions.cs @@ -0,0 +1,19 @@ +namespace Volo.Abp.AspNetCore.Components.WebAssembly +{ + public class UiMessageOptions + { + public bool ShowMessageIcon { get; set; } = true; + + public string OkButtonText { get; set; } + + public object OkButtonIcon { get; set; } + + public string ConfirmButtonText { get; set; } + + public object ConfirmButtonIcon { get; set; } + + public string CancelButtonText { get; set; } + + public object CancelButtonIcon { get; set; } + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs b/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs index 66bc231ce7..e7795f928d 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using Blazorise; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.AspNetCore.Components.WebAssembly; @@ -23,27 +22,31 @@ namespace Volo.Abp.BlazoriseUI public Task InfoAsync(string message, string title = null) { - return uiMessageNotifierService.NotifyMessageReceived(message, title); + return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Info, message, title); } public Task SuccessAsync(string message, string title = null) { - return uiMessageNotifierService.NotifyMessageReceived(message, title); + return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Success, message, title); } public Task WarnAsync(string message, string title = null) { - return uiMessageNotifierService.NotifyMessageReceived(message, title); + return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Warning, message, title); } public Task ErrorAsync(string message, string title = null) { - return uiMessageNotifierService.NotifyMessageReceived(message, title); + return uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Error, message, title); } - public Task ConfirmAsync(string message, string title = null) + public async Task ConfirmAsync(string message, string title = null) { - return Task.FromResult(true); + var callback = new TaskCompletionSource(); + + await uiMessageNotifierService.NotifyConfirmationReceivedAsync(message, title, callback); + + return await callback.Task; } } } diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor index e041053883..0bba328a51 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor @@ -1,17 +1,48 @@  - + @Title + @if ( ShowMessageIcon ) + { + + + + } @Message - - + @if ( IsConfirmation ) + { + + + } + else + { + + } \ No newline at end of file diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs index b5ee799bdd..dadab8135b 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Blazorise; @@ -10,17 +9,21 @@ namespace Volo.Abp.BlazoriseUI.Components { public partial class UiMessageAlert : ComponentBase, IDisposable { + private object messageIcon; + protected override void OnInitialized() { - UiMessageNotifierService.MessageReceived += UiMessageNotifierService_MessageReceived; + UiMessageNotifierService.MessageReceived += OnMessageReceived; base.OnInitialized(); } - private void UiMessageNotifierService_MessageReceived(object sender, UiMessageEventArgs e) + private void OnMessageReceived(object sender, UiMessageEventArgs e) { + MessageType = e.MessageType; Message = e.Message; Title = e.Title; + Callback = e.Callback; ModalRef.Show(); } @@ -29,30 +32,106 @@ namespace Volo.Abp.BlazoriseUI.Components { if (UiMessageNotifierService != null) { - UiMessageNotifierService.MessageReceived -= UiMessageNotifierService_MessageReceived; + UiMessageNotifierService.MessageReceived -= OnMessageReceived; } } - protected Task OnCancelClicked() + protected Task OnOkClicked() { ModalRef.Hide(); - return Task.CompletedTask; + return Okayed.InvokeAsync(null); + } + + protected Task OnConfirmClicked() + { + ModalRef.Hide(); + + if (IsConfirmation && Callback != null) + { + Callback.SetResult(true); + } + + return Confirmed.InvokeAsync(null); } - protected Task OnOKClicked() + protected Task OnCancelClicked() { ModalRef.Hide(); - return Task.CompletedTask; + if (IsConfirmation && Callback != null) + { + Callback.SetResult(false); + } + + return Canceled.InvokeAsync(null); } protected Modal ModalRef { get; set; } - [Inject] IUiMessageNotifierService UiMessageNotifierService { get; set; } + protected virtual bool IsConfirmation + => MessageType == UiMessageType.Confirmation; + + protected virtual bool ShowMessageIcon + => Options?.ShowMessageIcon ?? true; + + protected virtual object MessageIcon => MessageType switch + { + UiMessageType.Info => IconName.Info, + UiMessageType.Success => IconName.Check, + UiMessageType.Warning => IconName.Exclamation, + UiMessageType.Error => IconName.Stop, + UiMessageType.Confirmation => IconName.QuestionCircle, + _ => null, + }; + + protected virtual string MessageIconColor => MessageType switch + { + UiMessageType.Info => "#0000ff", + UiMessageType.Success => "#00ff00", + UiMessageType.Warning => "#ffae00", + UiMessageType.Error => "#e8301c", + UiMessageType.Confirmation => "#de692f", + _ => 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 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 IUiMessageNotifierService UiMessageNotifierService { get; set; } } } diff --git a/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs b/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs index cdd86a75f3..3b97045a93 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs @@ -10,9 +10,16 @@ namespace Volo.Abp.BlazoriseUI { public event EventHandler MessageReceived; - public Task NotifyMessageReceived(string message, string title = null) + public Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title = null) { - MessageReceived?.Invoke(this, new UiMessageEventArgs(message, title)); + MessageReceived?.Invoke(this, new UiMessageEventArgs(messageType, message, title)); + + return Task.CompletedTask; + } + + public Task NotifyConfirmationReceivedAsync(string message, string title, TaskCompletionSource callback) + { + MessageReceived?.Invoke(this, new UiMessageEventArgs(UiMessageType.Confirmation, message, title, callback)); return Task.CompletedTask; } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor index 3f5e2f52fc..5a0d3dd08b 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor @@ -1,7 +1,6 @@ @page "/" @using Volo.Abp.Users @using Volo.Abp.MultiTenancy -@using System.Security.Claims @using Microsoft.Extensions.Localization @using MyCompanyName.MyProjectName.Localization @using Volo.Abp.BlazoriseUI.Components @@ -20,19 +19,31 @@ UI Message Tests - + + + +

Welcome to the Application

- +

@L["LongWelcomeMessage"]

- @if (!CurrentUser.IsAuthenticated) + @if ( !CurrentUser.IsAuthenticated ) { @L["Login"] @@ -171,20 +182,4 @@ abpframework

- - -@code -{ - [Inject] IUiMessageService UiMessageService { get; set; } - - private IEnumerable _claims; - - protected override async Task OnInitializedAsync() - { - var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); - if (authState.User.Identity.IsAuthenticated) - { - _claims = authState.User.Claims; - } - } -} + \ No newline at end of file diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs new file mode 100644 index 0000000000..8c5440e747 --- /dev/null +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using Volo.Abp.AspNetCore.Components.WebAssembly; + +namespace MyCompanyName.MyProjectName.Blazor.Pages +{ + public partial class Index + { + private IEnumerable _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" ); + } + + 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; } + } +} From 38c3579d29dcd638ae2914286b46bf0c9fd325f6 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Tue, 6 Oct 2020 11:41:29 +0200 Subject: [PATCH 3/7] Fixed message icon styles --- .../Components/UiMessageAlert.razor.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs index dadab8135b..4d543174e0 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs @@ -9,8 +9,6 @@ namespace Volo.Abp.BlazoriseUI.Components { public partial class UiMessageAlert : ComponentBase, IDisposable { - private object messageIcon; - protected override void OnInitialized() { UiMessageNotifierService.MessageReceived += OnMessageReceived; @@ -80,18 +78,18 @@ namespace Volo.Abp.BlazoriseUI.Components UiMessageType.Info => IconName.Info, UiMessageType.Success => IconName.Check, UiMessageType.Warning => IconName.Exclamation, - UiMessageType.Error => IconName.Stop, + UiMessageType.Error => IconName.Times, UiMessageType.Confirmation => IconName.QuestionCircle, _ => null, }; protected virtual string MessageIconColor => MessageType switch { - UiMessageType.Info => "#0000ff", - UiMessageType.Success => "#00ff00", - UiMessageType.Warning => "#ffae00", - UiMessageType.Error => "#e8301c", - UiMessageType.Confirmation => "#de692f", + 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, }; From 63c87a106e9f40dde8c4df29da05af18e5123370 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 7 Oct 2020 10:07:03 +0200 Subject: [PATCH 4/7] Options are now sent with the message. Cleaned and optimized the code. --- .../WebAssembly/IUiMessageNotifierService.cs | 21 +++++--------- .../WebAssembly/IUiMessageService.cs | 18 ++++++------ .../WebAssembly/NullUiMessageService.cs | 10 +++---- .../WebAssembly/UiMessageOptions.cs | 29 +++++++++++++++++++ .../WebAssembly/UiMessageService.cs | 14 ++++----- .../Components/WebAssembly/UiMessageType.cs | 14 +++++++++ .../BlazoriseUiMessageService.cs | 20 ++++++------- .../Components/UiMessageAlert.razor.cs | 4 ++- .../UiMessageNotifierService.cs | 11 ++----- .../Pages/Index.razor.cs | 7 ++++- 10 files changed, 92 insertions(+), 56 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageType.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs index 309b73337b..456eb1bed7 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs +++ b/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 MessageReceived; - Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title = null); - - Task NotifyConfirmationReceivedAsync(string message, string title, TaskCompletionSource callback); + Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource 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 callback) + public UiMessageEventArgs(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource 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 Callback { get; } - } + public UiMessageOptions Options { get; } - public enum UiMessageType - { - Info, - Success, - Warning, - Error, - Confirmation, + public TaskCompletionSource Callback { get; } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageService.cs index 2c834ddc87..ff86c1c867 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageService.cs +++ b/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 { - 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 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 ConfirmAsync(string message, string title = null, UiMessageOptions options = null); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs index 59830b0480..0c7df5780d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs +++ b/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 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 ConfirmAsync(string message, string title = null) + public Task ConfirmAsync(string message, string title = null, UiMessageOptions options = null) { return Task.FromResult(true); } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageOptions.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageOptions.cs index 7909911c7e..85b26bc4b6 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageOptions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageOptions.cs @@ -1,19 +1,48 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly { + /// + /// Options to override message dialog appearance. + /// public class UiMessageOptions { + /// + /// If true, the message dialog will show the large icon for the current message type. + /// public bool ShowMessageIcon { get; set; } = true; + /// + /// Overrides the build-in message icon. + /// + public object MessageIcon { get; set; } + + /// + /// Custom text for the Ok button. + /// public string OkButtonText { get; set; } + /// + /// Custom icon for the Ok button. + /// public object OkButtonIcon { get; set; } + /// + /// Custom text for the Confirmation button. + /// public string ConfirmButtonText { get; set; } + /// + /// Custom icon for the Confirmation button. + /// public object ConfirmButtonIcon { get; set; } + /// + /// Custom text for the Cancel button. + /// public string CancelButtonText { get; set; } + /// + /// Custom icon for the Cancel button. + /// public object CancelButtonIcon { get; set; } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageService.cs index 16fe041de4..dfdc09f55d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageService.cs +++ b/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; } - 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 ConfirmAsync(string message, string title = null) + + public async Task ConfirmAsync(string message, string title = null, UiMessageOptions options = null) { return await JsRuntime.InvokeAsync("confirm", message); } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageType.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageType.cs new file mode 100644 index 0000000000..5e3a77a3c5 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageType.cs @@ -0,0 +1,14 @@ +namespace Volo.Abp.AspNetCore.Components.WebAssembly +{ + /// + /// Defines the possible ui message types with predefined actions. + /// + public enum UiMessageType + { + Info, + Success, + Warning, + Error, + Confirmation, + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs b/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs index e7795f928d..2c3481f313 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs @@ -20,31 +20,31 @@ namespace Volo.Abp.BlazoriseUI Logger = NullLogger.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 ConfirmAsync(string message, string title = null) + public async Task ConfirmAsync(string message, string title = null, UiMessageOptions options = null) { var callback = new TaskCompletionSource(); - await uiMessageNotifierService.NotifyConfirmationReceivedAsync(message, title, callback); + await uiMessageNotifierService.NotifyMessageReceivedAsync(UiMessageType.Confirmation, message, title, options, callback); return await callback.Task; } diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs index 4d543174e0..a3cd3f8f1e 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs @@ -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))", diff --git a/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs b/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs index 3b97045a93..c8ae0ecb0d 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs @@ -10,16 +10,9 @@ namespace Volo.Abp.BlazoriseUI { public event EventHandler MessageReceived; - public Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title = null) + public Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource callback) { - MessageReceived?.Invoke(this, new UiMessageEventArgs(messageType, message, title)); - - return Task.CompletedTask; - } - - public Task NotifyConfirmationReceivedAsync(string message, string title, TaskCompletionSource callback) - { - MessageReceived?.Invoke(this, new UiMessageEventArgs(UiMessageType.Confirmation, message, title, callback)); + MessageReceived?.Invoke(this, new UiMessageEventArgs(messageType, message, title, options, callback)); return Task.CompletedTask; } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs index 8c5440e747..730da74983 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs +++ b/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.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() From 989fd3f53db28be3971f677e186c515bba4c1ccc Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 7 Oct 2020 10:22:31 +0200 Subject: [PATCH 5/7] Moved objects to their own file --- ...{IUiMessageNotifierService.cs => UiMessageEventArgs.cs} | 7 ------- .../src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs | 4 ++-- .../Components/UiMessageAlert.razor.cs | 2 +- .../src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs | 4 ++-- 4 files changed, 5 insertions(+), 12 deletions(-) rename framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/{IUiMessageNotifierService.cs => UiMessageEventArgs.cs} (77%) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageEventArgs.cs similarity index 77% rename from framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs rename to framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageEventArgs.cs index 456eb1bed7..4431d3c819 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/IUiMessageNotifierService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageEventArgs.cs @@ -3,13 +3,6 @@ using System.Threading.Tasks; namespace Volo.Abp.AspNetCore.Components.WebAssembly { - public interface IUiMessageNotifierService - { - event EventHandler MessageReceived; - - Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource callback = null); - } - public class UiMessageEventArgs : EventArgs { public UiMessageEventArgs(UiMessageType messageType, string message, string title, UiMessageOptions options) diff --git a/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs b/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs index 2c3481f313..70643069be 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUiMessageService.cs @@ -9,11 +9,11 @@ namespace Volo.Abp.BlazoriseUI [Dependency(ReplaceServices = true)] public class BlazoriseUiMessageService : IUiMessageService, IScopedDependency { - private readonly IUiMessageNotifierService uiMessageNotifierService; + private readonly UiMessageNotifierService uiMessageNotifierService; public ILogger Logger { get; set; } - public BlazoriseUiMessageService(IUiMessageNotifierService uiMessageNotifierService) + public BlazoriseUiMessageService(UiMessageNotifierService uiMessageNotifierService) { this.uiMessageNotifierService = uiMessageNotifierService; diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs index a3cd3f8f1e..7dada11bd3 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor.cs @@ -132,6 +132,6 @@ namespace Volo.Abp.BlazoriseUI.Components [Parameter] public EventCallback Canceled { get; set; } - [Inject] protected IUiMessageNotifierService UiMessageNotifierService { get; set; } + [Inject] protected UiMessageNotifierService UiMessageNotifierService { get; set; } } } diff --git a/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs b/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs index c8ae0ecb0d..af49f993b5 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/UiMessageNotifierService.cs @@ -6,11 +6,11 @@ using Volo.Abp.DependencyInjection; namespace Volo.Abp.BlazoriseUI { [Dependency(ReplaceServices = true)] - public class UiMessageNotifierService : IUiMessageNotifierService, IScopedDependency + public class UiMessageNotifierService : IScopedDependency { public event EventHandler MessageReceived; - public Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource callback) + public Task NotifyMessageReceivedAsync(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource callback = null) { MessageReceived?.Invoke(this, new UiMessageEventArgs(messageType, message, title, options, callback)); From 5884e4d85354009d0379ca5108db179070fb0ec4 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 7 Oct 2020 10:25:23 +0200 Subject: [PATCH 6/7] Removed project reference to Volo.Abp.BlazoriseUI --- .../MyCompanyName.MyProjectName.Blazor.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj index ab574cea1d..cba18ad1bd 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyCompanyName.MyProjectName.Blazor.csproj @@ -15,7 +15,6 @@ - From 0a125d77e10b6305ef5dd2aeca20228d778a2930 Mon Sep 17 00:00:00 2001 From: Mladen Macanovic Date: Wed, 7 Oct 2020 12:55:50 +0200 Subject: [PATCH 7/7] Move use of UiMessageAlert to BasicTheme MainLayout --- .../Themes/Basic/MainLayout.razor | 6 ++++-- .../Themes/Basic/_Imports.razor | 2 ++ .../Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor | 2 +- .../MyCompanyName.MyProjectName.Blazor/Pages/Index.razor | 3 --- .../MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs | 1 - 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/MainLayout.razor b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/MainLayout.razor index 8e64b32022..6954057142 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/MainLayout.razor +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/MainLayout.razor @@ -11,12 +11,14 @@
@Body + +
diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/_Imports.razor b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/_Imports.razor index f1ebc76453..7d695e9344 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/_Imports.razor +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/_Imports.razor @@ -8,3 +8,5 @@ @using Volo.Abp.AspNetCore.Components.WebAssembly @using Blazorise @using Blazorise.DataGrid +@using Volo.Abp.BlazoriseUI; +@using Volo.Abp.BlazoriseUI.Components; \ No newline at end of file diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor index 0bba328a51..6caf37c0b9 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/UiMessageAlert.razor @@ -9,7 +9,7 @@ @if ( ShowMessageIcon ) { - + } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor index 5a0d3dd08b..0f0d1935df 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor @@ -3,7 +3,6 @@ @using Volo.Abp.MultiTenancy @using Microsoft.Extensions.Localization @using MyCompanyName.MyProjectName.Localization -@using Volo.Abp.BlazoriseUI.Components @inject ICurrentUser CurrentUser @inject ICurrentTenant CurrentTenant @inject AuthenticationStateProvider AuthenticationStateProvider @@ -37,8 +36,6 @@ - -

Welcome to the Application

@L["LongWelcomeMessage"]

diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs index 730da74983..7ac6682659 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Pages/Index.razor.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Blazorise;