Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Table): add IsVisibleWhenAdd/Edit parameter #2938

Merged
merged 23 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
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["TablesVisibleNormalTitle"]" Introduction="@Localizer["TablesVisibleNormalIntro"]" 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" />
<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 Down Expand Up @@ -156,9 +160,7 @@
</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 +184,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 +201,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字以内",
"TablesVisibleNormalTitle": "Table 编辑时显示/隐藏",
"TablesVisibleNormalIntro": "如果有列设置了 <code>IsVisibleWhenAdd</code> 或者 <code>IsVisibleWhenEdit</code> 属性为 <code>false</code> 时, 新建或者更新时隐藏此列。本例中 <b>新建</b> 弹窗不显示 <b>数量</b> <b>编辑</b> 弹窗不显示 <b>是否</b> 编辑项"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesVirtualization": {
"TablesVirtualizationTitle": "Table 虚拟滚动行",
Expand Down
24 changes: 17 additions & 7 deletions src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,30 @@ 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 Visible { get; set; } = true;

/// <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 +95,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
20 changes: 8 additions & 12 deletions src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ public partial class EditorForm<TModel> : IShowLabel
/// </summary>
private readonly List<IEditorItem> _formItems = [];

private IEnumerable<IEditorItem> UnsetGroupItems => _formItems.Where(i => string.IsNullOrEmpty(i.GroupName));
private IEnumerable<IEditorItem> UnsetGroupItems => _formItems.Where(i => string.IsNullOrEmpty(i.GroupName) && i.IsVisible(ItemChangedType, IsSearch.Value));

private IEnumerable<KeyValuePair<string, IOrderedEnumerable<IEditorItem>>> GroupItems => _formItems
.Where(i => !string.IsNullOrEmpty(i.GroupName))
.Where(i => !string.IsNullOrEmpty(i.GroupName) && i.IsVisible(ItemChangedType, IsSearch.Value))
.GroupBy(i => i.GroupOrder).OrderBy(i => i.Key)
.Select(i => new KeyValuePair<string, IOrderedEnumerable<IEditorItem>>(i.First().GroupName!, i.OrderBy(x => x.Order)));

Expand Down Expand Up @@ -230,10 +230,7 @@ protected override void OnParametersSet()
ShowLabel ??= ValidateForm?.ShowLabel;
}

/// <summary>
///
/// </summary>
private bool FirstRender { get; set; } = true;
private bool _firstRender = true;

/// <summary>
/// OnAfterRenderAsync 方法
Expand All @@ -246,11 +243,10 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

if (firstRender)
{
FirstRender = false;
_firstRender = false;

if (Items != null)
{
// 通过级联参数渲染组件
_formItems.AddRange(Items);
}
else
Expand All @@ -267,8 +263,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
var item = items.FirstOrDefault(i => i.GetFieldName() == el.GetFieldName());
if (item != null)
{
// 过滤掉不编辑的列
if (!el.Editable)
// 过滤掉不编辑与不可见的列
if (!el.Editable || !el.IsVisible(ItemChangedType, IsSearch.Value))
{
items.Remove(item);
}
Expand All @@ -280,11 +276,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
}
}
}
_formItems.AddRange(items.Where(i => i.Editable));
_formItems.AddRange(items);
}
else
{
_formItems.AddRange(_editorItems.Where(i => i.Editable));
_formItems.AddRange(_editorItems.Where(i => i.Editable && i.IsVisible(ItemChangedType, IsSearch.Value)));
}
}
StateHasChanged();
Expand Down
27 changes: 23 additions & 4 deletions src/BootstrapBlazor/Components/EditorForm/EditorItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,41 @@ public class EditorItem<TValue> : ComponentBase, IEditorItem
public bool Editable { get; set; } = true;

/// <summary>
/// 获得/设置 当前列编辑时是否为只读模式 默认为 false
/// <inheritdoc/>>
/// </summary>
/// <remarks>此属性覆盖 <see cref="IsReadonlyWhenAdd"/> 与 <see cref="IsReadonlyWhenEdit"/> 即新建与编辑时均只读</remarks>
[Parameter]
public bool Readonly { get; set; }

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

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

/// <summary>
/// <inheritdoc/>>
/// </summary>
[Parameter]
public bool Visible { get; set; } = true;

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

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

/// <summary>
/// 获得/设置 是否不进行验证 默认为 false
/// </summary>
Expand Down
Loading