From 1f4d51b81730556cc41567400d6f9f2304723590 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Sat, 14 Oct 2023 01:26:52 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20IStepProvider?= =?UTF-8?q?=20=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tstrapBlazorServiceCollectionExtensions.cs | 1 + .../Services/DefaultStepProvider.cs | 16 ++++++++++++ src/BootstrapBlazor/Services/IStepProvider.cs | 25 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/BootstrapBlazor/Services/DefaultStepProvider.cs create mode 100644 src/BootstrapBlazor/Services/IStepProvider.cs diff --git a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs index e4bfbaa02ac..d752583aa30 100644 --- a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs +++ b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs @@ -36,6 +36,7 @@ public static IServiceCollection AddBootstrapBlazor(this IServiceCollection serv services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(typeof(IDispatchService<>), typeof(DefaultDispatchService<>)); + services.TryAddSingleton(); services.TryAddTransient(); services.TryAddTransient(); diff --git a/src/BootstrapBlazor/Services/DefaultStepProvider.cs b/src/BootstrapBlazor/Services/DefaultStepProvider.cs new file mode 100644 index 00000000000..535d1ca3cba --- /dev/null +++ b/src/BootstrapBlazor/Services/DefaultStepProvider.cs @@ -0,0 +1,16 @@ +// 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 System.Collections.Concurrent; + +namespace BootstrapBlazor.Components; + +internal class DefaultStepProvider : IStepProvider +{ + private readonly ConcurrentDictionary _cache = new(); + + public string? GetStep(Type type) => _cache.TryGetValue(type, out var step) ? step : null; + + public void SetStep(Type type, string? value) => _cache.AddOrUpdate(type, t => value, (t, v) => value); +} diff --git a/src/BootstrapBlazor/Services/IStepProvider.cs b/src/BootstrapBlazor/Services/IStepProvider.cs new file mode 100644 index 00000000000..4e8280fb61b --- /dev/null +++ b/src/BootstrapBlazor/Services/IStepProvider.cs @@ -0,0 +1,25 @@ +// 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/ + +namespace BootstrapBlazor.Components; + +/// +/// IStepProvider 接口 +/// +public interface IStepProvider +{ + /// + /// 通过数据类型获得当前步长 + /// + /// + /// + string? GetStep(Type type); + + /// + /// 设置指定数据类型步长数值 + /// + /// + /// + void SetStep(Type type, string? value); +} From de4287dc68de3b05f6d760be29c392c404a36ae2 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Sat, 14 Oct 2023 12:22:06 +0800 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20StepSettings?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InputNumber/BootstrapInputNumber.razor.cs | 7 ++ .../BootstrapBlazorOptionsExtensions.cs | 31 ++++++++ .../Options/BootstrapBlazorOptions.cs | 5 ++ src/BootstrapBlazor/Options/StepSettings.cs | 76 +++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 src/BootstrapBlazor/Extensions/BootstrapBlazorOptionsExtensions.cs create mode 100644 src/BootstrapBlazor/Options/StepSettings.cs diff --git a/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs b/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs index 63051f65504..597010a993f 100644 --- a/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs +++ b/src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs @@ -2,6 +2,7 @@ // 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.Extensions; using Microsoft.Extensions.Localization; using System.Globalization; @@ -90,6 +91,10 @@ public partial class BootstrapInputNumber [NotNull] private IIconTheme? IconTheme { get; set; } + [Inject] + [NotNull] + private IOptions? StepOption { get; set; } + /// /// /// @@ -155,6 +160,8 @@ private void SetStep() StepString = Step; break; } + + StepString ??= StepOption.Value.GetStep(); } /// diff --git a/src/BootstrapBlazor/Extensions/BootstrapBlazorOptionsExtensions.cs b/src/BootstrapBlazor/Extensions/BootstrapBlazorOptionsExtensions.cs new file mode 100644 index 00000000000..96be7275442 --- /dev/null +++ b/src/BootstrapBlazor/Extensions/BootstrapBlazorOptionsExtensions.cs @@ -0,0 +1,31 @@ +// 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/ + +namespace BootstrapBlazor.Extensions; + +/// +/// BootstrapBlazorOptions 配置类扩展方法 +/// +public static class BootstrapBlazorOptionsExtensions +{ + /// + /// 获取步长泛型方法 + /// + /// + /// + /// + public static string? GetStep(this BootstrapBlazorOptions options) => options.GetStep(typeof(TType)); + + /// + /// 获取步长方法 + /// + /// 配置实体类实例 + /// 数据类型 + /// + public static string? GetStep(this BootstrapBlazorOptions options, Type type) + { + var t = Nullable.GetUnderlyingType(type) ?? type; + return options.StepSettings.GetStep(t); + } +} diff --git a/src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs b/src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs index 16d6c139d78..a3046226f70 100644 --- a/src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs +++ b/src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs @@ -69,6 +69,11 @@ public class BootstrapBlazorOptions /// public TableSettings TableSettings { get; set; } = new(); + /// + /// 获得/设置 Step 配置实例 + /// + public StepSettings StepSettings { get; set; } = new(); + /// /// 获得/设置 是否禁用表单内回车自动提交功能 默认 null 未设置 /// diff --git a/src/BootstrapBlazor/Options/StepSettings.cs b/src/BootstrapBlazor/Options/StepSettings.cs new file mode 100644 index 00000000000..5e15a91645e --- /dev/null +++ b/src/BootstrapBlazor/Options/StepSettings.cs @@ -0,0 +1,76 @@ +// 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/ + +namespace BootstrapBlazor.Components; + +/// +/// StepSettings 配置类 +/// +public class StepSettings +{ + /// + /// 获得/设置 int 数据类型步长 默认 null 未设置 + /// + public int? Int { get; set; } + + /// + /// 获得/设置 long 数据类型步长 默认 null 未设置 + /// + public int? Long { get; set; } + + /// + /// 获得/设置 short 数据类型步长 默认 null 未设置 + /// + public int? Short { get; set; } + + /// + /// 获得/设置 float 数据类型步长 默认 null 未设置 + /// + public float? Float { get; set; } + + /// + /// 获得/设置 double 数据类型步长 默认 null 未设置 + /// + public double? Double { get; set; } + + /// + /// 获得/设置 decimal 数据类型步长 默认 null 未设置 + /// + public decimal? Decimal { get; set; } + + /// + /// 获得步长字符串 + /// + /// + /// + public string? GetStep(Type type) + { + string? ret = null; + if (type == typeof(int)) + { + ret = Int?.ToString(); + } + if (type == typeof(long)) + { + ret = Long?.ToString(); + } + if (type == typeof(short)) + { + ret = Short?.ToString(); + } + if (type == typeof(float)) + { + ret = Float?.ToString(); + } + if (type == typeof(double)) + { + ret = Double?.ToString(); + } + if (type == typeof(decimal)) + { + ret = Decimal?.ToString(); + } + return ret; + } +} From 1068e9d57a8dd00f699ba7eee30fa8abec6b95a0 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Sat, 14 Oct 2023 12:22:26 +0800 Subject: [PATCH 3/6] =?UTF-8?q?revert:=20=E5=88=A0=E9=99=A4=20IStepProvide?= =?UTF-8?q?r=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tstrapBlazorServiceCollectionExtensions.cs | 1 - .../Services/DefaultStepProvider.cs | 16 ------------ src/BootstrapBlazor/Services/IStepProvider.cs | 25 ------------------- 3 files changed, 42 deletions(-) delete mode 100644 src/BootstrapBlazor/Services/DefaultStepProvider.cs delete mode 100644 src/BootstrapBlazor/Services/IStepProvider.cs diff --git a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs index d752583aa30..e4bfbaa02ac 100644 --- a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs +++ b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs @@ -36,7 +36,6 @@ public static IServiceCollection AddBootstrapBlazor(this IServiceCollection serv services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(typeof(IDispatchService<>), typeof(DefaultDispatchService<>)); - services.TryAddSingleton(); services.TryAddTransient(); services.TryAddTransient(); diff --git a/src/BootstrapBlazor/Services/DefaultStepProvider.cs b/src/BootstrapBlazor/Services/DefaultStepProvider.cs deleted file mode 100644 index 535d1ca3cba..00000000000 --- a/src/BootstrapBlazor/Services/DefaultStepProvider.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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 System.Collections.Concurrent; - -namespace BootstrapBlazor.Components; - -internal class DefaultStepProvider : IStepProvider -{ - private readonly ConcurrentDictionary _cache = new(); - - public string? GetStep(Type type) => _cache.TryGetValue(type, out var step) ? step : null; - - public void SetStep(Type type, string? value) => _cache.AddOrUpdate(type, t => value, (t, v) => value); -} diff --git a/src/BootstrapBlazor/Services/IStepProvider.cs b/src/BootstrapBlazor/Services/IStepProvider.cs deleted file mode 100644 index 4e8280fb61b..00000000000 --- a/src/BootstrapBlazor/Services/IStepProvider.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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/ - -namespace BootstrapBlazor.Components; - -/// -/// IStepProvider 接口 -/// -public interface IStepProvider -{ - /// - /// 通过数据类型获得当前步长 - /// - /// - /// - string? GetStep(Type type); - - /// - /// 设置指定数据类型步长数值 - /// - /// - /// - void SetStep(Type type, string? value); -} From f067bf7fee6587f9bdbf66c9b12a84271fd5c115 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Sat, 14 Oct 2023 12:24:10 +0800 Subject: [PATCH 4/6] =?UTF-8?q?chore:=20=E5=A2=9E=E5=8A=A0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/appsettings.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor.Server/appsettings.json b/src/BootstrapBlazor.Server/appsettings.json index 11a74c75313..9d1a22194c2 100644 --- a/src/BootstrapBlazor.Server/appsettings.json +++ b/src/BootstrapBlazor.Server/appsettings.json @@ -30,7 +30,15 @@ "TableSettings": { "CheckboxColumnWidth": 36 }, - "IgnoreLocalizerMissing": true + "IgnoreLocalizerMissing": true, + "StepSettings": { + "Short": 1, + "Int": 1, + "Long": 1, + "Float": "0.1", + "Double": "0.01", + "Decimal": "0.01" + } }, "Cache-Control": { "Files": [ ".png", ".gif", ".jpg", ".jpeg", ".svg" ], From dc085b3c1e5e11958519017c2635a34059cc401c Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Sat, 14 Oct 2023 12:24:42 +0800 Subject: [PATCH 5/6] chore: bump version 7.11.1-beta07 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index a424b1e94ed..7c195ff428f 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 7.11.1-beta06 + 7.11.1-beta07 From 95e48a9623d0c20daf936a2f9f439c792ec7f913 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Sat, 14 Oct 2023 12:36:52 +0800 Subject: [PATCH 6/6] =?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 --- .../Options/BootstrapBlazorOptionsTest.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/UnitTest/Options/BootstrapBlazorOptionsTest.cs b/test/UnitTest/Options/BootstrapBlazorOptionsTest.cs index c2e25177bd6..4d16821166f 100644 --- a/test/UnitTest/Options/BootstrapBlazorOptionsTest.cs +++ b/test/UnitTest/Options/BootstrapBlazorOptionsTest.cs @@ -2,6 +2,8 @@ // 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.Extensions; + namespace UnitTest.Options; public class BootstrapBlazorOptionsTest @@ -39,4 +41,35 @@ public void Options_IgnoreLocalizerMissing_Null() options.IgnoreLocalizerMissing = true; Assert.True(options.IgnoreLocalizerMissing.Value); } + + [Fact] + public void Options_StepSettings() + { + var options = new BootstrapBlazorOptions(); + Assert.NotNull(options.StepSettings); + + options.StepSettings = new(); + + Assert.Null(options.GetStep()); + Assert.Null(options.GetStep()); + Assert.Null(options.GetStep()); + Assert.Null(options.GetStep()); + Assert.Null(options.GetStep()); + Assert.Null(options.GetStep()); + + options.StepSettings.Short = 1; + options.StepSettings.Int = 2; + options.StepSettings.Long = 3; + options.StepSettings.Float = 0.1f; + options.StepSettings.Double = 0.01d; + options.StepSettings.Decimal = 0.001M; + + Assert.Equal("1", options.GetStep()); + Assert.Equal("2", options.GetStep()); + Assert.Equal("3", options.GetStep(typeof(long?))); + + Assert.Equal("0.1", options.GetStep()); + Assert.Equal("0.01", options.GetStep()); + Assert.Equal("0.001", options.GetStep()); + } }