diff --git a/LANCommander/Components/Table/IPickableColumn.cs b/LANCommander/Components/Table/IPickableColumn.cs new file mode 100644 index 0000000..584a9e6 --- /dev/null +++ b/LANCommander/Components/Table/IPickableColumn.cs @@ -0,0 +1,11 @@ +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 new file mode 100644 index 0000000..9e8fdfa --- /dev/null +++ b/LANCommander/Components/Table/PickableColumn.razor @@ -0,0 +1,13 @@ +@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 new file mode 100644 index 0000000..0fb4150 --- /dev/null +++ b/LANCommander/Components/Table/PickablePropertyColumn.razor @@ -0,0 +1,14 @@ +@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/TableCustomizer.razor b/LANCommander/Components/TableCustomizer.razor new file mode 100644 index 0000000..90a7c7c --- /dev/null +++ b/LANCommander/Components/TableCustomizer.razor @@ -0,0 +1,85 @@ +@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 19b7ce0..41677c9 100644 --- a/LANCommander/Pages/Games/Index.razor +++ b/LANCommander/Pages/Games/Index.razor @@ -7,7 +7,6 @@ @attribute [Authorize] @inject GameService GameService @inject NavigationManager NavigationManager -@inject ProtectedLocalStorage BrowserStorage @@ -22,154 +21,74 @@ - - - @Field.Icon.GetDisplayName() - @Field.Title.GetDisplayName() - @Field.SortTitle.GetDisplayName() - @Field.ReleasedOn.GetDisplayName() - @Field.CreatedOn.GetDisplayName() - @Field.CreatedBy.GetDisplayName() - @Field.UpdatedOn.GetDisplayName() - @Field.UpdatedBy.GetDisplayName() - @Field.Singleplayer.GetDisplayName() - @Field.Multiplayer.GetDisplayName() - @Field.TotalKeys.GetDisplayName() - @Field.KeysAllocated.GetDisplayName() - @Field.Developers.GetDisplayName() - @Field.Publishers.GetDisplayName() - @Field.Genres.GetDisplayName() - @Field.MultiplayerModes.GetDisplayName() - @Field.ArchiveSize.GetDisplayName() - - + - @if (FieldVisible(Field.Icon)) - { - - - - } + + + - @if (FieldVisible(Field.Title)) - { - - } - - @if (FieldVisible(Field.SortTitle)) - { - - } - - @if (FieldVisible(Field.ReleasedOn)) - { - - } - - @if (FieldVisible(Field.CreatedOn)) - { - - } + - @if (FieldVisible(Field.CreatedBy)) - { - - @context.CreatedBy?.UserName - - } + + + + + + + + @context.CreatedBy?.UserName + + + + + + @context.UpdatedBy?.UserName + + + + + + + + + - @if (FieldVisible(Field.UpdatedOn)) - { - - } + + @context.Keys?.Count + - @if (FieldVisible(Field.UpdatedBy)) - { - - @context.UpdatedBy?.UserName - - } + + @context.Keys?.Count(k => k.ClaimedOn.HasValue) + - @if (FieldVisible(Field.Singleplayer)) - { - - - - } + + @foreach (var dev in context.Developers) + { + @dev.Name + } + - @if (FieldVisible(Field.Multiplayer)) - { - - - - } + + @foreach (var pub in context.Publishers) + { + @pub.Name + } + - @if (FieldVisible(Field.TotalKeys)) - { - - @context.Keys?.Count - - } + + @foreach (var genre in context.Genres) + { + @genre.Name + } + - @if (FieldVisible(Field.KeysAllocated)) - { - - @context.Keys?.Count(k => k.ClaimedOn.HasValue) - - } - - @if (FieldVisible(Field.Developers)) - { - - @foreach (var dev in context.Developers) - { - @dev.Name - } - - } - - @if (FieldVisible(Field.Publishers)) - { - - @foreach (var pub in context.Publishers) - { - @pub.Name - } - - } - - @if (FieldVisible(Field.Genres)) - { - - @foreach (var genre in context.Genres) - { - @genre.Name - } - - } - - @if (FieldVisible(Field.MultiplayerModes)) - { - - @foreach (var mode in context.MultiplayerModes.Select(mm => mm.Type).Distinct()) - { - @mode.GetDisplayName() - } - - } - - @if (FieldVisible(Field.ArchiveSize)) - { - long? compressedSize = context.Archives?.OrderByDescending(a => a.CreatedOn).FirstOrDefault()?.CompressedSize; - - - @if (compressedSize.HasValue) - { - @ByteSizeLib.ByteSize.FromBytes((double)compressedSize) - } - - } + + @foreach (var mode in context.MultiplayerModes.Select(mm => mm.Type).Distinct()) + { + @mode.GetDisplayName() + } + @@ -195,7 +114,7 @@
-@code { + @code { IEnumerable Games { get; set; } = new List(); bool Loading = true; @@ -203,50 +122,10 @@ string Search = ""; - ITable Table; + Table Table; + TableCustomizer TableCustomizer; - Dictionary FieldVisibility = new Dictionary() - { - { Field.Icon, true }, - { Field.Title, true }, - { Field.SortTitle, true }, - { Field.ReleasedOn, true }, - { Field.CreatedOn, true }, - { Field.CreatedBy, true }, - { Field.UpdatedOn, true }, - { Field.UpdatedBy, true } - }; - - enum Field - { - Icon, - Title, - [Display(Name = "Sort Title")] - SortTitle, - [Display(Name = "Released On")] - ReleasedOn, - [Display(Name = "Created On")] - CreatedOn, - [Display(Name = "Created By")] - CreatedBy, - [Display(Name = "Updated On")] - UpdatedOn, - [Display(Name = "Updated By")] - UpdatedBy, - Singleplayer, - Multiplayer, - [Display(Name = "Total Keys")] - TotalKeys, - [Display(Name = "Keys Allocated")] - KeysAllocated, - Developers, - Publishers, - Genres, - [Display(Name = "Multiplayer Modes")] - MultiplayerModes, - [Display(Name = "Archive Size")] - ArchiveSize, - } + Dictionary ColumnVisibility = new Dictionary(); protected override async Task OnAfterRenderAsync(bool firstRender) { @@ -256,11 +135,6 @@ Loading = false; - var storedFieldVisibility = await BrowserStorage.GetAsync>("Views.Games.FieldPicker"); - - if (storedFieldVisibility.Success && storedFieldVisibility.Value != null) - FieldVisibility = storedFieldVisibility.Value; - StateHasChanged(); } } @@ -270,16 +144,6 @@ Games = await GameService.Get(g => g.Title.ToLower().Contains(Search.ToLower().Trim()) || g.SortTitle.ToLower().Contains(Search.ToLower().Trim())).OrderBy(g => String.IsNullOrWhiteSpace(g.SortTitle) ? g.Title : g.SortTitle).ToListAsync(); } - private bool FieldVisible(Field field) - { - return FieldVisibility.ContainsKey(field) && FieldVisibility[field] == true; - } - - private void ChangeFieldVisibility(Field field, bool state) - { - FieldVisibility[field] = state; - } - private string GetIcon(Game game) { return $"/api/Games/{game.Id}/Icon.png"; @@ -321,7 +185,5 @@ private async Task CloseFieldPicker() { FieldPickerVisible = false; - - await BrowserStorage.SetAsync("Views.Games.FieldPicker", FieldVisibility); } } diff --git a/LANCommander/_Imports.razor b/LANCommander/_Imports.razor index a1c070a..99bc753 100644 --- a/LANCommander/_Imports.razor +++ b/LANCommander/_Imports.razor @@ -10,6 +10,7 @@ @using BlazorMonaco @using BlazorMonaco.Editor @using LANCommander.Components +@using LANCommander.Components.Table @using LANCommander.Shared @using LANCommander.Services -@using LANCommander.Data.Models \ No newline at end of file +@using LANCommander.Data.Models