Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,18 @@

<div class="row form-inline g-3">
<div class="col-12 col-sm-6">
<BootstrapInput @bind-Value="Model.Name" />
<BootstrapInput @bind-Value="Model.Name"></BootstrapInput>
</div>
<div class="col-12 col-sm-6">
<MultiSelect @bind-Value="@Model.Hobby" Items="Hobbies" />
<MultiSelect @bind-Value="@Model.Hobby" Items="Hobbies"></MultiSelect>
</div>
<div class="col-12">
<Textarea @bind-Value="Model.Address" rows="3"/>
<Textarea @bind-Value="Model.Address" rows="3"></Textarea>
</div>
<div class="col-12 col-sm-6">
<Select @bind-Value="Model.Education" />
<Select @bind-Value="Model.Education"></Select>
</div>
<div class="col-12 col-sm-6">
<Display Value="@EducationDesc" ShowLabel="true" DisplayText="@Localizer["TablesEditTemplateDisplayLabel"]" />
<Display Value="@EducationDesc" ShowLabel="true" DisplayText="@Localizer["TablesEditTemplateDisplayLabel"]"></Display>
</div>
</div>

@code {
[Parameter]
[NotNull]
public Foo? Model { get; set; }

private IEnumerable<SelectedItem>? Hobbies { get; set; }

private string? EducationDesc => Model.Education == EnumEducation.Primary ? Localizer["TablesEditTemplateDisplayDetail1"] : Localizer["TablesEditTemplateDisplayDetail2"];

/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnInitialized()
{
Hobbies = Foo.GenerateHobbies(LocalizerFoo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone

namespace BootstrapBlazor.Server.Components.Components;

/// <summary>
/// DemoTableEditTemplate component
/// </summary>
public partial class DemoTableEditTemplate
{
/// <summary>
/// Gets or sets the Foo instance.
/// </summary>
[Parameter]
[NotNull]
public Foo? Model { get; set; }

private IEnumerable<SelectedItem>? Hobbies { get; set; }

private string? EducationDesc => Model.Education switch
{
EnumEducation.Primary => Localizer["TablesEditTemplateDisplayDetail1"],
EnumEducation.Middle => Localizer["TablesEditTemplateDisplayDetail2"],
_ => ""
};

/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnInitialized()
{
Hobbies = Foo.GenerateHobbies(LocalizerFoo);
}
}
10 changes: 3 additions & 7 deletions src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ public partial class EditorForm<TModel> : IShowLabel
/// <returns></returns>
private string? GetCssString(IEditorItem item)
{
int cols = 0;
int cols = Math.Max(0, Math.Min(12, item.Cols));
double mdCols = 6;
if (item is AutoGenerateColumnAttribute a && a.Cols > 0 && a.Cols < 13)
{
cols = a.Cols;
}
if (ItemsPerRow.HasValue)
{
mdCols = Math.Min(12, Math.Ceiling(12d / ItemsPerRow.Value));
mdCols = Math.Max(0, Math.Min(12, Math.Ceiling(12d / ItemsPerRow.Value)));
}
return CssBuilder.Default("col-12")
.AddClass($"col-sm-{cols}", cols > 0) // 指定 Cols
.AddClass($"col-sm-6 col-md-{mdCols}", mdCols < 12 && cols == 0 && item.Items == null && item.Rows == 0) // 指定 ItemsPerRow
.AddClass($"col-sm-6 col-md-{mdCols}", mdCols > 0 && cols == 0 && item.Rows == 0 && !Utility.IsCheckboxList(item.PropertyType, item.ComponentType)) // 指定 ItemsPerRow
.Build();
}

Expand Down
6 changes: 6 additions & 0 deletions src/BootstrapBlazor/Components/EditorForm/EditorItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public class EditorItem<TModel, TValue> : ComponentBase, IEditorItem
[Parameter]
public int Rows { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
[Parameter]
public int Cols { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/BootstrapBlazor/Components/EditorForm/IEditorItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public interface IEditorItem : ILookup
/// </summary>
int Rows { get; set; }

/// <summary>
/// Gets or sets the field expand columns. Default is 0.
/// </summary>
int Cols { get; set; }

/// <summary>
/// Gets or sets the edit template.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/BootstrapBlazor/Components/Table/InternalTableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ class InternalTableColumn(string fieldName, Type fieldType, string? fieldText =
/// </summary>
public int Rows { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
public int Cols { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions src/BootstrapBlazor/Components/Table/TableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,19 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
public string? Step { get; set; }

/// <summary>
/// 获得/设置 Textarea 行数 默认为 0
/// <inheritdoc/>
/// </summary>
[Parameter]
public int Rows { get; set; }

/// <summary>
/// 获得/设置 是否为默认排序规则 默认为 SortOrder.Unset
/// <inheritdoc/>
/// </summary>
[Parameter]
public int Cols { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
[Parameter]
public SortOrder DefaultSortOrder { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static void CopyValue(this ITableColumn dest, IEditorItem source)
if (source.LookupService != null) dest.LookupService = source.LookupService;
if (source.Readonly.HasValue) dest.Readonly = source.Readonly;
if (source.Rows > 0) dest.Rows = source.Rows;
if (source.Cols > 0) dest.Cols = source.Cols;
if (source.SkipValidate) dest.SkipValidate = source.SkipValidate;
if (!string.IsNullOrEmpty(source.Text)) dest.Text = source.Text;
if (source.ValidateRules != null) dest.ValidateRules = source.ValidateRules;
Expand Down
6 changes: 3 additions & 3 deletions src/BootstrapBlazor/Utils/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,12 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co
return ret;
}

private static List<SelectedItem> Clone(this IEnumerable<SelectedItem> source) => source.Select(d => new SelectedItem(d.Value, d.Text)
private static List<SelectedItem> Clone(this IEnumerable<SelectedItem> source) => [.. source.Select(d => new SelectedItem(d.Value, d.Text)
{
Active = d.Active,
IsDisabled = d.IsDisabled,
GroupName = d.GroupName
}).ToList();
})];

private static object? GenerateValue(object model, string fieldName) => GetPropertyValue<object, object?>(model, fieldName);

Expand Down Expand Up @@ -671,7 +671,7 @@ private static Type GenerateComponentType(IEditorItem item)
/// <param name="fieldType"></param>
/// <param name="componentType">组件类型</param>
/// <returns></returns>
private static bool IsCheckboxList(Type fieldType, Type? componentType = null)
public static bool IsCheckboxList(Type fieldType, Type? componentType = null)
{
var ret = false;
if (componentType != null)
Expand Down
2 changes: 2 additions & 0 deletions test/UnitTest/Attributes/AutoGenerateClassTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void AutoGenerateColumn_Ok()
ComponentType = typeof(Select<string>),
Step = "1",
Rows = 1,
Cols = 6,
LookupStringComparison = StringComparison.Ordinal,
LookupServiceKey = "test-lookup",
LookupServiceData = true,
Expand Down Expand Up @@ -93,6 +94,7 @@ public void AutoGenerateColumn_Ok()
Assert.Equal(typeof(Select<string>), attr.ComponentType);
Assert.Equal("1", attr.Step);
Assert.Equal(1, attr.Rows);
Assert.Equal(6, attr.Cols);
Assert.Equal(StringComparison.Ordinal, attr.LookupStringComparison);
Assert.Equal("Test", attr.GroupName);
Assert.Equal(1, attr.GroupOrder);
Expand Down
1 change: 1 addition & 0 deletions test/UnitTest/Components/EditorFormTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public void EditorItem_Ok()
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.Field), f.Address);
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.FieldExpression), Utility.GenerateValueExpression(foo, nameof(Foo.Address), typeof(string)));
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.Rows), 3);
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.Cols), 0);
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.ValidateRules), new List<IValidator>
{
new FormItemValidator(new RequiredAttribute())
Expand Down
1 change: 1 addition & 0 deletions test/UnitTest/Components/InternalTableColumnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void InternalTableColumn_Ok()
SetValue("Readonly", true);
SetValue("Step", "1");
SetValue("Rows", 1);
SetValue("Cols", 6);
SetValue("ComponentType", typeof(string));
SetValue("Order", 1);
SetValue("Lookup", new SelectedItem[] { new("test", "Test") });
Expand Down
2 changes: 2 additions & 0 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5019,6 +5019,7 @@ public void TableColumn_Property()
builder.AddAttribute(31, "IsVisibleWhenAdd", false);
builder.AddAttribute(32, "IsVisibleWhenEdit", false);
builder.AddAttribute(33, "LookupService", new FooLookupService());
builder.AddAttribute(34, "Cols", 6);
builder.CloseComponent();
});
});
Expand All @@ -5040,6 +5041,7 @@ public void TableColumn_Property()
Assert.NotNull(column.Instance.Step);
Assert.NotNull(column.Instance.Template);
Assert.Equal(1, column.Instance.Rows);
Assert.Equal(6, column.Instance.Cols);
Assert.NotNull(column.Instance.EditTemplate);
Assert.NotNull(column.Instance.SearchTemplate);
Assert.NotNull(column.Instance.FilterTemplate);
Expand Down
2 changes: 2 additions & 0 deletions test/UnitTest/Extensions/ITableColumnExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void CopyValue_Ok()
IsReadonlyWhenEdit = true,
Readonly = true,
Rows = 3,
Cols = 6,
SkipValidate = true,
Text = "Test",
ValidateRules = [new RequiredValidator()],
Expand Down Expand Up @@ -130,6 +131,7 @@ public void CopyValue_Ok()
Assert.False(col.IsVisibleWhenEdit);
Assert.True(col.Readonly);
Assert.Equal(3, col.Rows);
Assert.Equal(6, col.Cols);
Assert.True(col.SkipValidate);
Assert.Equal("Test", col.Text);
Assert.NotNull(col.ValidateRules);
Expand Down
1 change: 0 additions & 1 deletion test/UnitTest/Services/ThrottleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ await dispatcher.ThrottleAsync(async () =>
{
count++;
});
Assert.Equal(expected, count);
}

[Fact]
Expand Down