From fdcd6a16686f4032daae79e47b52830f99d07a18 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Mar 2022 09:45:26 +0800 Subject: [PATCH 1/7] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=B6=88=E9=99=A4=E8=AD=A6=E5=91=8A=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Shared/Samples/Geolocations.razor | 2 +- src/BootstrapBlazor.Shared/Samples/Geolocations.razor.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Samples/Geolocations.razor b/src/BootstrapBlazor.Shared/Samples/Geolocations.razor index 7df1e587b..d58ff1391 100644 --- a/src/BootstrapBlazor.Shared/Samples/Geolocations.razor +++ b/src/BootstrapBlazor.Shared/Samples/Geolocations.razor @@ -7,7 +7,7 @@

@Localizer["IntroText3"]

- @if (WatchID == null) + @if (WatchID == 0) { diff --git a/src/BootstrapBlazor.Shared/Samples/Geolocations.razor.cs b/src/BootstrapBlazor.Shared/Samples/Geolocations.razor.cs index 9ea80aef9..58d3270a0 100644 --- a/src/BootstrapBlazor.Shared/Samples/Geolocations.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/Geolocations.razor.cs @@ -105,9 +105,9 @@ public partial class Geolocations : IAsyncDisposable /// /// /// - public ValueTask DisposeAsync() + public async ValueTask DisposeAsync() { - DisposeAsync(true); + await DisposeAsync(true); GC.SuppressFinalize(this); } } -- Gitee From 29fd3dd26ef60e3ec9f987e236032221da1361a7 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Mar 2022 18:38:15 +0800 Subject: [PATCH 2/7] =?UTF-8?q?doc:=20=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Samples/GlobalException.razor.cs | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Samples/GlobalException.razor.cs b/src/BootstrapBlazor.Shared/Samples/GlobalException.razor.cs index 0d51af81f..f72a3bf03 100644 --- a/src/BootstrapBlazor.Shared/Samples/GlobalException.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/GlobalException.razor.cs @@ -41,27 +41,27 @@ public partial class GlobalException /// private static IEnumerable GetAttributes() => new[] { - // TODO: 移动到数据库中 - new AttributeItem() { - Name = nameof(ErrorLogger.ChildContent), - Description = "子组件模板", - Type = nameof(RenderTemplate), - ValueList = " — ", - DefaultValue = " — " - }, - new AttributeItem() { - Name = nameof(ErrorLogger.ErrorContent), - Description = "异常显示模板", - Type = nameof(RenderTemplate), - ValueList = " — ", - DefaultValue = " — " - }, - new AttributeItem() { - Name = nameof(ErrorLogger.ShowToast), - Description = "是否显示错误消息弹窗", - Type = "bool", - ValueList = "true|false", - DefaultValue = "true" - } - }; + // TODO: 移动到数据库中 + new AttributeItem() { + Name = nameof(ErrorLogger.ChildContent), + Description = "子组件模板", + Type = nameof(RenderTemplate), + ValueList = " — ", + DefaultValue = " — " + }, + new AttributeItem() { + Name = nameof(ErrorLogger.ErrorContent), + Description = "异常显示模板", + Type = nameof(RenderTemplate), + ValueList = " — ", + DefaultValue = " — " + }, + new AttributeItem() { + Name = nameof(ErrorLogger.ShowToast), + Description = "是否显示错误消息弹窗", + Type = "bool", + ValueList = "true|false", + DefaultValue = "true" + } + }; } -- Gitee From 2c7c87c24472e5668fd2967eaf3859ce21cc2111 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Mar 2022 20:20:38 +0800 Subject: [PATCH 3/7] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Shared/Locales/en.json | 2 +- src/BootstrapBlazor.Shared/Locales/zh.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Locales/en.json b/src/BootstrapBlazor.Shared/Locales/en.json index 053b77616..32c248be4 100644 --- a/src/BootstrapBlazor.Shared/Locales/en.json +++ b/src/BootstrapBlazor.Shared/Locales/en.json @@ -424,7 +424,7 @@ }, "BootstrapBlazor.Shared.Samples.GlobalException": { "Title": "Global exception", - "Introduce": "Added component ErrorLogger Through this component, global logs and exceptions can be output uniformly; currently, the Blazor framework does not provide a MVC like Global exception The overall solution, for the time being, you need to use try/catch in the code block for exception capture", + "Introduce": "Added component ErrorLogger Through this component, global logs and exceptions can be output uniformly; currently, the Blazor framework does not provide a MVC like Global exception The overall solution", "H1": "Instructions", "Step1": "1. Add AddLogging to the Startup file to enable the net core system log function", "Step1Introduce": "Use AddFileLogger need to reference Longbow.Logging component package", diff --git a/src/BootstrapBlazor.Shared/Locales/zh.json b/src/BootstrapBlazor.Shared/Locales/zh.json index e802ca43d..20a8a9ba5 100644 --- a/src/BootstrapBlazor.Shared/Locales/zh.json +++ b/src/BootstrapBlazor.Shared/Locales/zh.json @@ -425,7 +425,7 @@ }, "BootstrapBlazor.Shared.Samples.GlobalException": { "Title": "全局异常", - "Introduce": "

增加组件 ErrorLogger 通过本组件可以对全局的日志、异常进行统一输出;目前由于 Blazor 框架并未提供一个类似 MVC全局异常 整体解决方案

  • NET5.0 框架下暂时还需要在代码块中使用 try/catch 进行异常捕获
  • NET6.0 框架下 无需任何额外代码 即可进行全局异常捕获与处理
", + "Introduce": "

增加组件 ErrorLogger 通过本组件可以对全局的日志、异常进行统一输出;目前由于 Blazor 框架并未提供一个类似 MVC全局异常 整体解决方案;通过使用 ErrorLogger 组件 无需任何额外代码 即可进行全局异常捕获与处理

", "H1": "使用方法", "Step1": "1. Startup 文件中增加 AddLogging 开启 net core 系统日志功能", "Step1Introduce": "使用 AddFileLogger 需要引用 Longbow.Logging 组件包 [传送门]", -- Gitee From 6c0791ac64b55c966c51cf6201e132d3c70eba27 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Mar 2022 20:50:39 +0800 Subject: [PATCH 4/7] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Editor/Editor.razor.cs | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/BootstrapBlazor/Components/Editor/Editor.razor.cs b/src/BootstrapBlazor/Components/Editor/Editor.razor.cs index dccceaf2e..bc32c6334 100644 --- a/src/BootstrapBlazor/Components/Editor/Editor.razor.cs +++ b/src/BootstrapBlazor/Components/Editor/Editor.razor.cs @@ -114,16 +114,16 @@ public partial class Editor : IDisposable PlaceHolder ??= Localizer[nameof(PlaceHolder)]; ToolbarItems ??= new List - { - new List { "style", new List() { "style" } }, - new List { "font", new List() { "bold", "underline", "clear" } }, - new List { "fontname", new List() { "fontname"} }, - new List { "color", new List() { "color"} }, - new List { "para", new List() { "ul", "ol", "paragraph"} }, - new List { "table", new List() { "table"} }, - new List { "insert", new List() { "link", "picture", "video" } }, - new List { "view", new List() { "fullscreen", "codeview", "help"} } - }; + { + new List { "style", new List() { "style" } }, + new List { "font", new List() { "bold", "underline", "clear" } }, + new List { "fontname", new List() { "fontname"} }, + new List { "color", new List() { "color"} }, + new List { "para", new List() { "ul", "ol", "paragraph"} }, + new List { "table", new List() { "table"} }, + new List { "insert", new List() { "link", "picture", "video" } }, + new List { "view", new List() { "fullscreen", "codeview", "help"} } + }; CustomerToolbarButtons ??= Enumerable.Empty(); } @@ -187,10 +187,10 @@ public partial class Editor : IDisposable list.AddRange(ToolbarItems); var itemList = new List - { - "custom", - CustomerToolbarButtons.Select(p => p.ButtonName).ToList() - }; + { + "custom", + CustomerToolbarButtons.Select(p => p.ButtonName).ToList() + }; list.Add(itemList); return Task.FromResult(list); @@ -230,8 +230,11 @@ public partial class Editor : IDisposable { if (disposing) { - Interope?.Dispose(); - Interope = null; + if (Interope != null) + { + Interope.Dispose(); + Interope = null; + } } } -- Gitee From 0d486c20178234fd27c6394fb1de2f098af5d8cd Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Mar 2022 20:51:04 +0800 Subject: [PATCH 5/7] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/EditorTest.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/UnitTest/Components/EditorTest.cs diff --git a/test/UnitTest/Components/EditorTest.cs b/test/UnitTest/Components/EditorTest.cs new file mode 100644 index 000000000..2b4fb17b2 --- /dev/null +++ b/test/UnitTest/Components/EditorTest.cs @@ -0,0 +1,11 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using BootstrapBlazor.Shared; + +namespace UnitTest.Components; + +public class EditorTest : BootstrapBlazorTestBase +{ +} -- Gitee From 59355e76795be20d957a525c736952253bd5e280 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Mar 2022 20:51:19 +0800 Subject: [PATCH 6/7] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/EditorTest.cs | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/UnitTest/Components/EditorTest.cs b/test/UnitTest/Components/EditorTest.cs index 2b4fb17b2..cce36b3f6 100644 --- a/test/UnitTest/Components/EditorTest.cs +++ b/test/UnitTest/Components/EditorTest.cs @@ -8,4 +8,31 @@ namespace UnitTest.Components; public class EditorTest : BootstrapBlazorTestBase { + [Fact] + public async Task Editor_Ok() + { + var value = new Foo(); + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.Value, value.Name); + pb.Add(a => a.ValueChanged, v => value.Name = v); + pb.Add(a => a.IsEditor, false); + pb.Add(a => a.Height, 200); + }); + + await cut.InvokeAsync(() => cut.Instance.Update("Test")); + Assert.Equal("Test", value.Name); + + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.OnValueChanged, v => + { + value.Name = v; + return Task.CompletedTask; + }); + }); + + await cut.InvokeAsync(() => cut.Instance.Update("Test1")); + Assert.Equal("Test1", value.Name); + } } -- Gitee From 9edba3fea52481f48e482a5c3b001f0e9dae76d7 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Thu, 17 Mar 2022 20:51:43 +0800 Subject: [PATCH 7/7] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20Button=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/EditorTest.cs | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/UnitTest/Components/EditorTest.cs b/test/UnitTest/Components/EditorTest.cs index cce36b3f6..030d86250 100644 --- a/test/UnitTest/Components/EditorTest.cs +++ b/test/UnitTest/Components/EditorTest.cs @@ -35,4 +35,44 @@ public class EditorTest : BootstrapBlazorTestBase await cut.InvokeAsync(() => cut.Instance.Update("Test1")); Assert.Equal("Test1", value.Name); } + + [Fact] + public async Task CustomerToolbarButtons_Ok() + { + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.Value, "Test"); + pb.Add(a => a.CustomerToolbarButtons, new EditorToolbarButton[] + { + new EditorToolbarButton() + { + ButtonName = "Test1", + IconClass = "Class1", + Tooltip = "Tooltip1" + } + }); + }); + + IEnumerable? buttons = null; + await cut.InvokeAsync(async () => buttons = await cut.Instance.GetToolBar()); + Assert.NotNull(buttons); + + IEnumerable? btns = null; + await cut.InvokeAsync(async () => btns = await cut.Instance.GetPluginAttrs()); + Assert.Single(buttons); + Assert.Equal("Class1", btns!.First().IconClass); + Assert.Equal("Tooltip1", btns!.First().Tooltip); + + var name = ""; + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.OnClickButton, v => + { + return Task.FromResult("Test"); + }); + pb.Add(a => a.Value, null); + }); + await cut.InvokeAsync(async () => name = await cut.Instance.ClickPluginItem("Test1")); + Assert.Equal("Test", name); + } } -- Gitee