Added default button removal feature

This commit is contained in:
2025-02-05 17:56:08 +01:00
parent 23c5115c99
commit 43fda30a01
4 changed files with 34 additions and 17 deletions

View File

@@ -21,7 +21,7 @@
<div style="display: flex; flex-direction: column; height: 100%">
<FluentToolbar Class="hopframe-toolbar">
<h3>@_config?.DisplayName</h3>
@if (!DisplaySelection) {
@if (!DisplaySelection && _buttonToggles.ShowRefreshButton) {
<FluentButton
IconStart="@(new Icons.Regular.Size16.ArrowClockwise())"
OnClick="Reload"
@@ -42,8 +42,8 @@
<FluentSpacer />
<FluentSearch @oninput="OnSearch" @onchange="OnSearch" Style="width: 350px" />
@if (_hasCreatePolicy && DisplayActions) {
<FluentButton OnClick="async () => { await CreateOrEdit(null); }">Add Entry</FluentButton>
@if (_hasCreatePolicy && DisplayActions && _buttonToggles.ShowAddEntityButton) {
<FluentButton OnClick="async () => { await CreateOrEdit(null); }">Add Entity</FluentButton>
}
@foreach (var button in _pluginButtons.Where(pb => pb.IsForTable(_config)).Where(pb => pb.Position == PluginButtonPosition.TopRight)) {
@@ -85,13 +85,13 @@
</FluentButton>
}
@if (_hasUpdatePolicy) {
@if (_hasUpdatePolicy && _buttonToggles.ShowEditButton) {
<FluentButton aria-label="Edit entry" OnClick="async () => { await CreateOrEdit(context); }">
<FluentIcon Value="@(new Icons.Regular.Size16.Edit())"/>
</FluentButton>
}
@if (_hasDeletePolicy) {
@if (_hasDeletePolicy && _buttonToggles.ShowDeleteButton) {
<FluentButton aria-label="Delete entry" OnClick="async () => { await DeleteEntry(context); }">
<FluentIcon Value="@(new Icons.Regular.Size16.Delete())" Color="Color.Warning"/>
</FluentButton>
@@ -182,6 +182,7 @@
private readonly CancellationTokenSource _tokenSource = new();
private List<PluginButton> _pluginButtons = new();
private DefaultButtonToggles _buttonToggles = new();
protected override void OnInitialized() {
_config ??= Explorer.GetTable(TableDisplayName);
@@ -197,11 +198,12 @@
return;
}
var eventResult = await PluginOrchestrator.DispatchEvent(new PageInitializedEvent(this) {
var eventResult = await PluginOrchestrator.DispatchEvent(new TableInitializedEvent(this) {
Table = _config!
});
if (eventResult.IsCanceled) return;
_pluginButtons = eventResult.PluginButtons;
_buttonToggles = eventResult.DefaultButtons;
_hasUpdatePolicy = await Handler.IsAuthenticatedAsync(_config?.UpdatePolicy);
_hasDeletePolicy = await Handler.IsAuthenticatedAsync(_config?.DeletePolicy);
@@ -223,6 +225,7 @@
public void Dispose() {
_searchCancel.Dispose();
_tokenSource.Dispose();
}
private CancellationTokenSource _searchCancel = new();

View File

@@ -4,8 +4,9 @@ using Microsoft.FluentUI.AspNetCore.Components;
namespace HopFrame.Web.Plugins.Events;
public class PageInitializedEvent(HopFrameTablePage sender) : HopFrameTablePageEventArgs(sender) {
public class TableInitializedEvent(HopFrameTablePage sender) : HopFrameTablePageEventArgs(sender) {
public List<PluginButton> PluginButtons { get; } = new();
public DefaultButtonToggles DefaultButtons { get; set; } = new();
public void AddPageButton(string title, Func<Task> callback, bool pushRight = false, IconInfo? icon = null) {
PluginButtons.Add(new() {
@@ -91,3 +92,10 @@ public enum PluginButtonPosition {
TopRight = 1,
OnEntry = 2
}
public struct DefaultButtonToggles() {
public bool ShowRefreshButton { get; set; } = true;
public bool ShowAddEntityButton { get; set; } = true;
public bool ShowDeleteButton { get; set; } = true;
public bool ShowEditButton { get; set; } = true;
}

View File

@@ -54,5 +54,4 @@ internal sealed class PluginOrchestrator(IServiceProvider services) : IPluginOrc
return @event;
}
}