Skip to content

Commit

Permalink
feat(Table): add IsVisibleWhenAdd/Edit parameter (#2938)
Browse files Browse the repository at this point in the history
* feat(Table): support hiding column in dialog add and edit #2932

新建/编辑时隐藏某些列, 适应不同场景

todo : 渲染 Excel 单元格方法需不需要处理?

* undo launchUrl

* feat: 增加 IsVisibleWhenAdd/IsVisibleWhenEdit 参数

* feat: 重构显示编辑项逻辑

* refactor: 更新扩展方法

* refactor: 删除枚举

* doc: 更新菜单与示例

* doc: 更新文档

* doc: 精简代码

* test: 更新单元测试

* test: 移除异步设置逻辑

* test: 更新单元测试

* refactor: 更新样式

* fix: 修复编辑类型丢失问题

* fix: 修复行内编辑丢失编辑状态问题

* doc: 更新编辑示例

* fix: 修复新建行是无保存按钮问题

* test: 更新单元测试

* test: 更新单元测试

* refactor: 重构代码

* feat: 增加黑名单功能

* test: 更新单元测试

---------

Co-authored-by: Argo-AscioTech <argo@live.ca>
  • Loading branch information
densen2014 and ArgoZhang authored Feb 25, 2024
1 parent e707027 commit bd47781
Show file tree
Hide file tree
Showing 25 changed files with 315 additions and 133 deletions.
54 changes: 35 additions & 19 deletions src/BootstrapBlazor.Server/Components/Samples/Table/Tables.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ private void OnClick()
Items = Foo.GenerateFoo(FooLocalizer);
}

private IEnumerable<AttributeItem> GetTableColumnAttributes() => new AttributeItem[]
{
private AttributeItem[] GetTableColumnAttributes() =>
[
new()
{
Name = "TextWrap",
Expand Down Expand Up @@ -113,22 +113,6 @@ private void OnClick()
DefaultValue = " — "
},
new()
{
Name = nameof(IEditorItem.IsReadonlyWhenAdd),
Description = Localizer["IsReadonlyWhenAddAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new()
{
Name = nameof(IEditorItem.IsReadonlyWhenEdit),
Description = Localizer["IsReadonlyWhenEditAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new()
{
Name = nameof(IEditorItem.Lookup),
Description = Localizer["LookupAttr"],
Expand Down Expand Up @@ -169,6 +153,22 @@ private void OnClick()
DefaultValue = "false"
},
new()
{
Name = nameof(IEditorItem.IsReadonlyWhenAdd),
Description = Localizer["IsReadonlyWhenAddAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new()
{
Name = nameof(IEditorItem.IsReadonlyWhenEdit),
Description = Localizer["IsReadonlyWhenEditAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new()
{
Name = "SearchTemplate",
Description = Localizer["SearchTemplateColumnAttr"],
Expand Down Expand Up @@ -257,6 +257,22 @@ private void OnClick()
DefaultValue = "true"
},
new()
{
Name = "IsVisibleWhenAdd",
Description = Localizer["IsVisibleWhenAddAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "true"
},
new()
{
Name = "IsVisibleWhenEdit",
Description = Localizer["IsVisibleWhenEditAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "true"
},
new()
{
Name = "Width",
Description = Localizer["WidthAttr"],
Expand Down Expand Up @@ -344,7 +360,7 @@ private void OnClick()
ValueList = "true/false",
DefaultValue = "false"
}
};
];

private AttributeItem[] GetAttributes() =>
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
<h3>@Localizer["TablesEditTitle"]</h3>
<h4>@((MarkupString)Localizer["TablesEditDescription"].Value)</h4>

<DemoBlock Title="@Localizer["TablesEditItemsTitle"]"
Introduction="@Localizer["TablesEditItemsIntro"]"
Name="EditItems">
<DemoBlock Title="@Localizer["TablesEditItemsTitle"]" Introduction="@Localizer["TablesEditItemsIntro"]" Name="EditItems">
<section ignore>@((MarkupString)Localizer["TablesEditItemsDescription"].Value)</section>
<Table TItem="Foo" @bind-Items="EditItems"
IsStriped="true" IsBordered="true" IsMultipleSelect="true"
Expand All @@ -26,9 +24,21 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditTemplateTitle"]"
Introduction="@Localizer["TablesEditTemplateIntro"]"
Name="EditTemplate">
<DemoBlock Title="@Localizer["TablesVisibleTitle"]" Introduction="@Localizer["TablesVisibleIntro"]" Name="Visible">
<Table TItem="Foo" Items="@Items.Take(3)" IsMultipleSelect="true"
ShowToolbar="true" ShowExtendButtons="true">
<TableColumns>
<TableColumn @bind-Field="@context.DateTime" Width="180" />
<TableColumn @bind-Field="@context.Name" />
<TableColumn @bind-Field="@context.Address" Rows="3" Visible="false" IsVisibleWhenAdd="true" IsVisibleWhenEdit="true" />
<TableColumn @bind-Field="@context.Count" IsVisibleWhenAdd="false" />
<TableColumn @bind-Field="@context.Complete" IsVisibleWhenEdit="false" />
<TableColumn @bind-Field="@context.Education" />
</TableColumns>
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditTemplateTitle"]" Introduction="@Localizer["TablesEditTemplateIntro"]" Name="EditTemplate">
<section ignore>@((MarkupString)Localizer["TablesEditTemplateDescription"].Value)</section>
<Table TItem="Foo" EditDialogShowMaximizeButton="true"
IsPagination="true" PageItemsSource="@PageItemsSource" DataService="@CustomerDataService"
Expand All @@ -51,9 +61,7 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditOnAddAsyncTitle"]"
Introduction="@Localizer["TablesEditOnAddAsyncIntro"]"
Name="OnAddAsync">
<DemoBlock Title="@Localizer["TablesEditOnAddAsyncTitle"]" Introduction="@Localizer["TablesEditOnAddAsyncIntro"]" Name="OnAddAsync">
<section ignore>
<p>@((MarkupString)Localizer["TablesEditOnAddAsyncDescription"].Value)</p>
<p>@((MarkupString)Localizer["TablesEditOnAddAsyncTips1"].Value)</p>
Expand All @@ -80,9 +88,7 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesColumnEditTemplateTitle"]"
Introduction="@Localizer["TablesColumnEditTemplateIntro"]"
Name="ColumnEditTemplate">
<DemoBlock Title="@Localizer["TablesColumnEditTemplateTitle"]" Introduction="@Localizer["TablesColumnEditTemplateIntro"]" Name="ColumnEditTemplate">
<section ignore>
<div>@((MarkupString)Localizer["TablesColumnEditTemplateDescription1"].Value)</div>
<div>@((MarkupString)Localizer["TablesColumnEditTemplateTips"].Value)</div>
Expand All @@ -109,9 +115,7 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditModeTitle"]"
Introduction="@Localizer["TablesEditModeIntro"]"
Name="EditMode">
<DemoBlock Title="@Localizer["TablesEditModeTitle"]" Introduction="@Localizer["TablesEditModeIntro"]" Name="EditMode">
<section ignore>
<p>@((MarkupString)Localizer["TablesEditModeDescription"].Value)</p>
<p>@((MarkupString)Localizer["TablesEditModeTips1"].Value)</p>
Expand All @@ -127,18 +131,17 @@
<TableColumns>
<TableColumn @bind-Field="@context.DateTime" Width="180" />
<TableColumn @bind-Field="@context.Name" />
<TableColumn @bind-Field="@context.Address" />
<TableColumn @bind-Field="@context.Address" Rows="3" />
<TableColumn @bind-Field="@context.Education" />
<TableColumn @bind-Field="@context.Count" />
<TableColumn @bind-Field="@context.Complete" />
<TableColumn @bind-Field="@context.Count" IsVisibleWhenAdd="false" />
<TableColumn @bind-Field="@context.Complete" IsVisibleWhenEdit="false" />
</TableColumns>
</Table>

<section ignore>
<p>@((MarkupString)Localizer["TablesEditModeInCell"].Value)</p>
<RadioList @bind-Value="InsertMode" />
</section>

<Table TItem="Foo"
IsPagination="true" PageItemsSource="@PageItemsSource"
IsStriped="true" IsBordered="true" IsMultipleSelect="true"
Expand All @@ -148,17 +151,15 @@
<TableColumns>
<TableColumn @bind-Field="@context.DateTime" Width="180" />
<TableColumn @bind-Field="@context.Name" />
<TableColumn @bind-Field="@context.Address" />
<TableColumn @bind-Field="@context.Address" Rows="3" />
<TableColumn @bind-Field="@context.Education" />
<TableColumn @bind-Field="@context.Count" />
<TableColumn @bind-Field="@context.Complete" />
<TableColumn @bind-Field="@context.Count" IsVisibleWhenAdd="false" />
<TableColumn @bind-Field="@context.Complete" IsVisibleWhenEdit="false" />
</TableColumns>
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditInjectDataServiceTitle"]"
Introduction="@Localizer["TablesEditInjectDataServiceIntro"]"
Name="InjectDataService">
<DemoBlock Title="@Localizer["TablesEditInjectDataServiceTitle"]" Introduction="@Localizer["TablesEditInjectDataServiceIntro"]" Name="InjectDataService">
<section ignore>
@((MarkupString)Localizer["TablesEditInjectDataServiceDescription"].Value)
<ul class="ul-demo mb-3">
Expand All @@ -182,9 +183,7 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditDataServiceTitle"]"
Introduction="@Localizer["TablesEditDataServiceIntro"]"
Name="DataService">
<DemoBlock Title="@Localizer["TablesEditDataServiceTitle"]" Introduction="@Localizer["TablesEditDataServiceIntro"]" Name="DataService">
<section ignore>
<b>@Localizer["TablesEditDataServiceDescription"]</b>
<div class="mt-1">@((MarkupString)Localizer["TablesEditDataServiceTips1"].Value)</div>
Expand All @@ -201,9 +200,7 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditFooterTemplateTitle"]"
Introduction="@Localizer["TablesEditFooterTemplateIntro"]"
Name="EditFooterTemplate">
<DemoBlock Title="@Localizer["TablesEditFooterTemplateTitle"]" Introduction="@Localizer["TablesEditFooterTemplateIntro"]" Name="EditFooterTemplate">
<section ignore>
<p>@((MarkupString)Localizer["TablesEditFooterTemplateDescription"].Value)</p>
<Pre class="mb-3">&lt;EditFooterTemplate Context="model"&gt;
Expand Down
6 changes: 5 additions & 1 deletion src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4823,6 +4823,8 @@
"TextEllipsisAttr": "Whether to omit text when exceeded",
"TemplateAttr": "Template",
"VisibleAttr": "Whether to display this column",
"IsVisibleWhenAddAttr": "Whether to display this column in new item dialog",
"IsVisibleWhenEditAttr": "Whether to display this column in edit item dialog",
"WidthAttr": "Column width (px)",
"FixedAttr": "Whether to fix this column",
"GroupNameAttr": "Current Property Grouping",
Expand Down Expand Up @@ -4998,7 +5000,9 @@
"TablesEditInjectDataServiceTips1": "Startup file injects data service",
"TablesEditInjectDataServiceTips2": "Implementation principle and usage introduction",
"TablesEditInjectDataServiceTips3": "custom data service",
"TablesEditInjectDataServiceTips4": "After enabling the use of the injected data service, you can set the component individually by setting the <code>DataServices</code> parameter, if the instance provided by the internal use of the injected service is not set"
"TablesEditInjectDataServiceTips4": "After enabling the use of the injected data service, you can set the component individually by setting the <code>DataServices</code> parameter, if the instance provided by the internal use of the injected service is not set",
"TablesVisibleNormalTitle": "Editor Visible/Hidden",
"TablesVisibleNormalIntro": "If the <code>IsVisibleWhenAdd</code> or <code>IsVisibleWhenEdit</code> property is set to <code>false</code>, hide this column when creating or updating. In this example, the <b>New</b> pop-up window does not display <b>Count</b> <b>Edit</b> Pop up window does not display <b>Complete</b> edit the item"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesVirtualization": {
"TablesVirtualizationTitle": "Table virtual scroll row",
Expand Down
6 changes: 5 additions & 1 deletion src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -4823,6 +4823,8 @@
"TextEllipsisAttr": "是否文本超出时省略",
"TemplateAttr": "模板",
"VisibleAttr": "是否显示此列",
"IsVisibleWhenAddAttr": "新建时此列是否显示",
"IsVisibleWhenEditAttr": "编辑时此列是否显示",
"WidthAttr": "列宽度(像素px)",
"FixedAttr": "是否固定本列",
"GroupNameAttr": "当前属性分组",
Expand Down Expand Up @@ -4998,7 +5000,9 @@
"TablesEditInjectDataServiceTips2": "实现原理与用法介绍",
"TablesEditInjectDataServiceTips3": "自定义数据服务",
"TablesEditInjectDataServiceTips4": "开启使用注入数据服务后,可通过设置 <code>DataServices</code> 参数对组件进行单独设置,如未设置内部使用注入服务提供的实例",
"TablesEditShowSearchPlaceHolderString": "不可为空,50字以内"
"TablesEditShowSearchPlaceHolderString": "不可为空,50字以内",
"TablesVisibleTitle": "Table 编辑时显示/隐藏",
"TablesVisibleIntro": "<div><code>Visible</code> 默认值为 <code>true</code> 如果有列设置了 <code>IsVisibleWhenAdd</code> 或者 <code>IsVisibleWhenEdit</code> 属性为 <code>false</code> 时, 新建或者更新时隐藏此列。本例中 <b>新建</b> 弹窗不显示 <b>数量</b> <b>编辑</b> 弹窗不显示 <b>是否</b> 编辑项。</div><div>可以通过在数据模型中使用 <code>[AutoGenerateClass(Visible = false)]</code> 全部禁止显示,再通过 <code>IsVisibleWhenAdd</code> 或者 <code>IsVisibleWhenEdit</code> 单独设置编辑状态下的可见性,本例中,<b>地址</b> 列默认不可见,<b>新建、编辑</b> 弹窗内均可以编辑</div>"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesVirtualization": {
"TablesVirtualizationTitle": "Table 虚拟滚动行",
Expand Down
9 changes: 7 additions & 2 deletions src/BootstrapBlazor/Attributes/AutoGenerateBaseAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BootstrapBlazor.Components;

/// <summary>
///
/// AutoGenerateColumn 标签基类,用于 <see cref="Table{TItem}"/> 标识自动生成列
/// </summary>
public abstract class AutoGenerateBaseAttribute : Attribute
{
Expand All @@ -15,10 +15,15 @@ public abstract class AutoGenerateBaseAttribute : Attribute
public bool Editable { get; set; } = true;

/// <summary>
/// 获得/设置 当前列编辑时是否只读 默认为 false
/// 获得/设置 当前编辑项是否只读 默认为 false
/// </summary>
public bool Readonly { get; set; }

/// <summary>
/// 获得/设置 当前编辑项是否显示 默认为 true
/// </summary>
public bool Visible { get; set; } = true;

/// <summary>
/// 获得/设置 是否允许排序 默认为 false
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BootstrapBlazor.Components;

/// <summary>
///
/// AutoGenerateColumn 标签类,用于 <see cref="Table{TItem}"/> 标识自动生成列
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class AutoGenerateClassAttribute : AutoGenerateBaseAttribute
Expand Down
19 changes: 12 additions & 7 deletions src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,25 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
public bool SkipValidate { get; set; }

/// <summary>
/// 获得/设置 新建时此列只读 默认为 false
/// <inheritdoc/>
/// </summary>
public bool IsReadonlyWhenAdd { get; set; }

/// <summary>
/// 获得/设置 编辑时此列只读 默认为 false
/// <inheritdoc/>
/// </summary>
public bool IsReadonlyWhenEdit { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
public bool IsVisibleWhenAdd { get; set; } = true;

/// <summary>
/// <inheritdoc/>
/// </summary>
public bool IsVisibleWhenEdit { get; set; } = true;

/// <summary>
/// 获得/设置 是否显示标签 Tooltip 多用于标签文字过长导致裁减时使用 默认 false
/// </summary>
Expand Down Expand Up @@ -80,11 +90,6 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
/// </summary>
public bool Fixed { get; set; }

/// <summary>
/// 获得/设置 列是否显示 默认为 true 可见的
/// </summary>
public bool Visible { get; set; } = true;

/// <summary>
/// 获得/设置 列 td 自定义样式 默认为 null 未设置
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/EditorForm/EditorForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<CascadingValue Value="@_editorItems" IsFixed="true">
@FieldItems?.Invoke(Model)
</CascadingValue>
@if (FirstRender)
@if (_firstRender)
{
<div class="ef-loading">
<Spinner Color="Color.Primary" />
Expand Down
Loading

0 comments on commit bd47781

Please sign in to comment.