diff --git a/LANCommander/Components/Table/IPickableColumn.cs b/LANCommander/Components/Table/IPickableColumn.cs deleted file mode 100644 index 584a9e6..0000000 --- a/LANCommander/Components/Table/IPickableColumn.cs +++ /dev/null @@ -1,11 +0,0 @@ -using AntDesign; -using Microsoft.AspNetCore.Components; - -namespace LANCommander.Components.Table -{ - public interface IPickableColumn : IColumn - { - public bool Visible { get; set; } - public EventCallback VisibleChanged { get; set; } - } -} diff --git a/LANCommander/Components/Table/PickableColumn.razor b/LANCommander/Components/Table/PickableColumn.razor deleted file mode 100644 index 9e8fdfa..0000000 --- a/LANCommander/Components/Table/PickableColumn.razor +++ /dev/null @@ -1,13 +0,0 @@ -@typeparam TData -@inherits Column -@implements IPickableColumn - -@if (Visible) -{ - base.BuildRenderTree(__builder); -} - -@code { - [Parameter] public bool Visible { get; set; } = true; - [Parameter] public EventCallback VisibleChanged { get; set; } -} \ No newline at end of file diff --git a/LANCommander/Components/Table/PickablePropertyColumn.razor b/LANCommander/Components/Table/PickablePropertyColumn.razor deleted file mode 100644 index 0fb4150..0000000 --- a/LANCommander/Components/Table/PickablePropertyColumn.razor +++ /dev/null @@ -1,14 +0,0 @@ -@typeparam TItem -@typeparam TProp -@inherits PropertyColumn -@implements IPickableColumn - -@if (Visible) -{ - base.BuildRenderTree(__builder); -} - -@code { - [Parameter] public bool Visible { get; set; } = true; - [Parameter] public EventCallback VisibleChanged { get; set; } -} \ No newline at end of file diff --git a/LANCommander/Components/TableColumnPicker.razor b/LANCommander/Components/TableColumnPicker.razor new file mode 100644 index 0000000..4b71e04 --- /dev/null +++ b/LANCommander/Components/TableColumnPicker.razor @@ -0,0 +1,72 @@ +@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; +@inject ProtectedLocalStorage BrowserStorage + + + + @foreach (var column in ColumnVisibility.Keys) + { + + @column + + } + + + +@code { + [Parameter] public string Key { get; set; } + [Parameter] public bool Visible { get; set; } + [Parameter] public EventCallback VisibleChanged { get; set; } + + Dictionary ColumnVisibility = new Dictionary(); + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + try + { + var storedColumnVisibility = await BrowserStorage.GetAsync>($"Views.{Key}.ColumnPicker"); + + if (storedColumnVisibility.Success && storedColumnVisibility.Value != null) + ColumnVisibility = storedColumnVisibility.Value; + + StateHasChanged(); + } + catch + { + ColumnVisibility = new Dictionary(); + await BrowserStorage.SetAsync($"Views.{Key}.FieldPicker", ColumnVisibility); + } + } + } + + public bool IsColumnHidden(string columnName, bool isDefault = true) + { + if (!ColumnVisibility.ContainsKey(columnName)) + ColumnVisibility[columnName] = isDefault; + + return !ColumnVisibility[columnName]; + } + + protected override void OnParametersSet() + { + base.OnParametersSet(); + + if (ColumnVisibility == null) + ColumnVisibility = new Dictionary(); + } + + async Task ChangeColumnVisibility(string column, bool state) + { + ColumnVisibility[column] = state; + + await InvokeAsync(StateHasChanged); + } + + async Task Close() + { + Visible = false; + + await VisibleChanged.InvokeAsync(); + } +} \ No newline at end of file diff --git a/LANCommander/Components/TableCustomizer.razor b/LANCommander/Components/TableCustomizer.razor deleted file mode 100644 index 90a7c7c..0000000 --- a/LANCommander/Components/TableCustomizer.razor +++ /dev/null @@ -1,85 +0,0 @@ -@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; -@typeparam TItem -@inject ProtectedLocalStorage BrowserStorage - -@if (Table != null) -{ - - - @foreach (IPickableColumn column in Table.ColumnContext.HeaderColumns.Where(c => !String.IsNullOrWhiteSpace(c.Title) && typeof(IPickableColumn).IsAssignableFrom(c.GetType()))) - { - - @column.Title - - } - - -} - -@code { - [Parameter] public Table Table { get; set; } - [Parameter] public string Key { get; set; } - [Parameter] public bool Visible { get; set; } - [Parameter] public EventCallback VisibleChanged { get; set; } - - Dictionary ColumnVisibility { get; set; } - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - { - try - { - var storedColumnVisibility = await BrowserStorage.GetAsync>($"Views.{Key}.FieldPicker"); - - if (storedColumnVisibility.Success && storedColumnVisibility.Value != null) - ColumnVisibility = storedColumnVisibility.Value; - - StateHasChanged(); - } - catch - { - ColumnVisibility = new Dictionary(); - await BrowserStorage.SetAsync($"Views.{Key}.FieldPicker", ColumnVisibility); - } - } - } - - protected override void OnParametersSet() - { - base.OnParametersSet(); - - if (ColumnVisibility == null) - ColumnVisibility = new Dictionary(); - - if (Table != null) - { - foreach (ColumnBase column in Table.ColumnContext.HeaderColumns) - { - ColumnVisibility[column.ColIndex] = !column.Hidden; - } - } - } - - async Task ChangeColumnVisibility(IPickableColumn column, bool state) - { - //ColumnVisibility[1] = state; - - //await BrowserStorage.SetAsync($"Views.{Key}.FieldPicker", ColumnVisibility); - - var pickableColumn = Table.ColumnContext.Columns[column.ColIndex] as IPickableColumn; - - pickableColumn.Visible = state; - - await pickableColumn.VisibleChanged.InvokeAsync(); - - await InvokeAsync(StateHasChanged); - } - - async Task Close() - { - Visible = false; - - await VisibleChanged.InvokeAsync(); - } -} \ No newline at end of file diff --git a/LANCommander/Pages/Games/Index.razor b/LANCommander/Pages/Games/Index.razor index 41677c9..1bf4c92 100644 --- a/LANCommander/Pages/Games/Index.razor +++ b/LANCommander/Pages/Games/Index.razor @@ -21,79 +21,79 @@ - + - - +
+ - +
+ + +
- - +
@@ -67,6 +76,8 @@ string Search = ""; IEnumerable SelectedServers; + TableColumnPicker Picker; + bool ColumnPickerVisible = false; protected override void OnAfterRender(bool firstRender) { @@ -140,4 +151,14 @@ ServerProcessService.StopServer(server); } } + + private async Task OpenColumnPicker() + { + ColumnPickerVisible = true; + } + + private async Task CloseColumnPicker() + { + ColumnPickerVisible = false; + } } diff --git a/LANCommander/_Imports.razor b/LANCommander/_Imports.razor index 99bc753..6420f79 100644 --- a/LANCommander/_Imports.razor +++ b/LANCommander/_Imports.razor @@ -10,7 +10,6 @@ @using BlazorMonaco @using BlazorMonaco.Editor @using LANCommander.Components -@using LANCommander.Components.Table @using LANCommander.Shared @using LANCommander.Services @using LANCommander.Data.Models