!2346 fix(#I4RV9J): the Edit/Delete button on toolbar can modify readonly row set by ShowEdit/DeleteCallback method

* feat: 增加提示信息初始化
* feat: 增加删除按钮提示无法删除数据
* doc: 更新资源文件增加无法删除提示信息
* feat: 增加选中项无法删除逻辑
* feat: 增加选中项无法编辑提示参数
* doc: 增加资源文件
This commit is contained in:
Argo 2022-01-22 09:49:07 +00:00
parent a08252fc49
commit ce5a055aec
5 changed files with 78 additions and 35 deletions

View File

@ -189,6 +189,13 @@ public partial class Table<TItem>
[NotNull]
public string? EditButtonToastNotSelectContent { get; set; }
/// <summary>
/// 编辑按钮 Toast 选择项设置不可编辑时提示 Content 文字
/// </summary>
[Parameter]
[NotNull]
public string? EditButtonToastReadonlyContent { get; set; }
/// <summary>
/// 编辑按钮 Toast 多项选择时提示 Content 文字
/// </summary>
@ -245,6 +252,13 @@ public partial class Table<TItem>
[NotNull]
public string? DeleteButtonToastTitle { get; set; }
/// <summary>
/// 删除按钮选项中有无法删除项时 Toast 提示文字
/// </summary>
[Parameter]
[NotNull]
public string? DeleteButtonToastCanNotDeleteContent { get; set; }
/// <summary>
/// 删除按钮 Toast 提示 Content 文字
/// </summary>
@ -296,6 +310,7 @@ public partial class Table<TItem>
EditButtonToastNotSelectContent ??= Localizer[nameof(EditButtonToastNotSelectContent)];
EditButtonToastMoreSelectContent ??= Localizer[nameof(EditButtonToastMoreSelectContent)];
EditButtonToastNoSaveMethodContent ??= Localizer[nameof(EditButtonToastNoSaveMethodContent)];
EditButtonToastReadonlyContent ??= Localizer[nameof(EditButtonToastReadonlyContent)];
SaveButtonToastTitle ??= Localizer[nameof(SaveButtonToastTitle)];
SaveButtonToastContent ??= Localizer[nameof(SaveButtonToastContent)];
SaveButtonToastResultContent ??= Localizer[nameof(SaveButtonToastResultContent)];
@ -304,6 +319,7 @@ public partial class Table<TItem>
DeleteButtonToastTitle ??= Localizer[nameof(DeleteButtonToastTitle)];
DeleteButtonToastContent ??= Localizer[nameof(DeleteButtonToastContent)];
DeleteButtonToastResultContent ??= Localizer[nameof(DeleteButtonToastResultContent)];
DeleteButtonToastCanNotDeleteContent ??= Localizer[nameof(DeleteButtonToastCanNotDeleteContent)];
DataServiceInvalidOperationText ??= Localizer[nameof(DataServiceInvalidOperationText), typeof(TItem).FullName!];
NotSetOnTreeExpandErrorMessage = Localizer[nameof(NotSetOnTreeExpandErrorMessage)];
UnsetText ??= Localizer[nameof(UnsetText)];

View File

@ -325,49 +325,58 @@ public partial class Table<TItem>
{
if (SelectedRows.Count == 1)
{
await ToggleLoading(true);
await InternalOnEditAsync();
EditModalTitleString = EditModalTitle;
// 显示编辑框
if (EditMode == EditMode.Popup)
// 检查是否选中了不可编辑行(行内无编辑按钮)
if (ShowEditButtonCallback != null && !ShowEditButtonCallback(SelectedRows[0]))
{
await ShowEditDialog(ItemChangedType.Update);
// 提示不可编辑
await ShowToastAsync(ToastCategory.Information, EditButtonToastReadonlyContent);
}
else if (EditMode == EditMode.EditForm)
else
{
ShowEditForm = true;
ShowAddForm = false;
await UpdateAsync();
await ToggleLoading(true);
await InternalOnEditAsync();
EditModalTitleString = EditModalTitle;
}
else if (EditMode == EditMode.InCell)
{
AddInCell = false;
EditInCell = true;
await UpdateAsync();
// 显示编辑框
if (EditMode == EditMode.Popup)
{
await ShowEditDialog(ItemChangedType.Update);
}
else if (EditMode == EditMode.EditForm)
{
ShowEditForm = true;
ShowAddForm = false;
await UpdateAsync();
}
else if (EditMode == EditMode.InCell)
{
AddInCell = false;
EditInCell = true;
await UpdateAsync();
}
await ToggleLoading(false);
}
await ToggleLoading(false);
}
else
{
var option = new ToastOption
{
Category = ToastCategory.Information,
Title = EditButtonToastTitle,
Content = SelectedRows.Count == 0 ? EditButtonToastNotSelectContent : EditButtonToastMoreSelectContent
};
await Toast.Show(option);
var content = SelectedRows.Count == 0 ? EditButtonToastNotSelectContent : EditButtonToastMoreSelectContent;
await ShowToastAsync(ToastCategory.Information, content);
}
}
else
{
await ShowToastAsync(ToastCategory.Error, EditButtonToastNoSaveMethodContent);
}
async Task ShowToastAsync(ToastCategory category, string content)
{
var option = new ToastOption
{
Category = ToastCategory.Error,
Category = category,
Title = EditButtonToastTitle,
Content = EditButtonToastNoSaveMethodContent
Content = content
};
await Toast.Show(option);
}
@ -554,20 +563,32 @@ public partial class Table<TItem>
{
var ret = false;
if (SelectedRows.Count == 0)
{
await ShowToastAsync(DeleteButtonToastContent);
}
else
{
if (ShowDeleteButtonCallback != null && SelectedRows.Any(i => !ShowDeleteButtonCallback(i)))
{
await ShowToastAsync(DeleteButtonToastCanNotDeleteContent);
}
else
{
ret = true;
}
}
return ret;
async Task ShowToastAsync(string content)
{
var option = new ToastOption
{
Category = ToastCategory.Information,
Title = DeleteButtonToastTitle
};
option.Content = string.Format(DeleteButtonToastContent, Math.Ceiling(option.Delay / 1000.0));
option.Content = string.Format(content, Math.Ceiling(option.Delay / 1000.0));
await Toast.Show(option);
}
else
{
ret = true;
}
return ret;
}
/// <summary>
@ -732,11 +753,11 @@ public partial class Table<TItem>
/// 是否显示行内编辑按钮
/// </summary>
/// <returns></returns>
protected bool GetShowEditButton(TItem item) => ShowEditButtonCallback == null ? ShowToolbar && ShowDefaultButtons && ShowEditButton : ShowEditButtonCallback(item);
protected bool GetShowEditButton(TItem item) => ShowToolbar && ShowDefaultButtons && (ShowEditButtonCallback == null ? ShowEditButton : ShowEditButtonCallback(item));
/// <summary>
/// 是否显示行内删除按钮
/// </summary>
/// <returns></returns>
protected bool GetShowDeleteButton(TItem item) => ShowDeleteButtonCallback == null ? ShowToolbar && ShowDefaultButtons && ShowDeleteButton : ShowDeleteButtonCallback(item);
protected bool GetShowDeleteButton(TItem item) => ShowToolbar && ShowDefaultButtons && (ShowDeleteButtonCallback == null ? ShowDeleteButton : ShowDeleteButtonCallback(item));
}

View File

@ -230,6 +230,7 @@
"AddButtonToastContent": "Add data failed. Please provider OnAddAsync method",
"EditButtonToastTitle": "Add Data",
"EditButtonToastNotSelectContent": "Save data failed. Please provider OnSaveAsync method",
"EditButtonToastReadonlyContent": "The selected data cannot be edited",
"EditButtonToastMoreSelectContent": "Only one row can be EDIT",
"EditButtonToastNoSaveMethodContent": "Can not EDIT data. Please provider OnSaveAsync method",
"SaveButtonToastTitle": "Save Data",
@ -240,6 +241,7 @@
"DeleteButtonToastTitle": "Delete Data",
"DeleteButtonToastContent": "Please select DELETE rows, auto close after {0}s",
"DeleteButtonToastResultContent": "Delete data {0}, auto close after {1}s",
"DeleteButtonToastCanNotDeleteContent": "There is undeletable data in the selected data, auto close after {0}s",
"DataServiceInvalidOperationText": "Cannot provide a value for property 'DataService' on type 'BootstrapBlazor.Components.Table`1[[{0}]]'. There is no registered service of type 'BootstrapBlazor.Components.IDataService`1[{0}]'.",
"NotSetOnTreeExpandErrorMessage": "not set OnTreeExpand parameter",
"UnsetText": "Asc",

View File

@ -230,6 +230,7 @@
"AddButtonToastContent": "Falha ao Adicionar. Atribua o método OnAddAsync",
"EditButtonToastTitle": "Adicionar Registro",
"EditButtonToastNotSelectContent": "Falha ao Salvar. Atribua o método OnSaveAsync",
"EditButtonToastReadonlyContent": "Os dados seleccionados não podem ser editados",
"EditButtonToastMoreSelectContent": "Somente uma linha pode ser alterada",
"EditButtonToastNoSaveMethodContent": "Falha ao Editar. Atribua o método OnSaveAsync",
"SaveButtonToastTitle": "Salvar Registro",
@ -240,6 +241,7 @@
"DeleteButtonToastTitle": "Apagar Registro",
"DeleteButtonToastContent": "Selecione o registro a excluir, fechando em {0}s",
"DeleteButtonToastResultContent": "Registro excluido {0}, fechando em {1}s",
"DeleteButtonToastCanNotDeleteContent": "Não foi possível editar o X, fechando em {0}s",
"DataServiceInvalidOperationText": "Não foi possível fornecer um valor para 'DataService' do tipo 'BootstrapBlazor.Components.Table`1[[{0}]]'. Não existe serviço registrado do tipo 'BootstrapBlazor.Components.IDataService`1[{0}]'.",
"NotSetOnTreeExpandErrorMessage": "parâmetro OnTreeExpand não atribuído",
"UnsetText": "Asc",

View File

@ -230,6 +230,7 @@
"AddButtonToastContent": "未提供新建数据方法,无法新建数据",
"EditButtonToastTitle": "编辑数据",
"EditButtonToastNotSelectContent": "请选择要编辑的数据",
"EditButtonToastReadonlyContent": "选项不可编辑",
"EditButtonToastMoreSelectContent": "只能选择一项要编辑的数据",
"EditButtonToastNoSaveMethodContent": "未提供保存数据方法,无法编辑数据",
"SaveButtonToastTitle": "保存数据",
@ -240,6 +241,7 @@
"DeleteButtonToastTitle": "删除数据",
"DeleteButtonToastContent": "请选择要删除的数据, {0} 秒后自动关闭",
"DeleteButtonToastResultContent": "删除数据{0}, {1} 秒后自动关闭",
"DeleteButtonToastCanNotDeleteContent": "选中数据中有不可删除数据, {0} 秒后自动关闭",
"DataServiceInvalidOperationText": "未注册 'BootstrapBlazor.Components.IDataService`1[{0}]' 服务",
"NotSetOnTreeExpandErrorMessage": "未设置 OnTreeExpand 回调委托方法",
"UnsetText": "点击升序",