Skip to content

Commit

Permalink
Client changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hesketh committed Feb 22, 2024
1 parent b122b97 commit 5383882
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 27 deletions.
2 changes: 1 addition & 1 deletion API.Client/Clients/PersonClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Hesketh.MecatolArchives.API.Client.Clients;

public sealed class PersonClient : EntityClient<Person, Person, Post.Person>
public sealed class PersonClient : EntityClient<Person, Put.Person, Post.Person>
{
public PersonClient(HttpClient client, IAuthHeaderProvider authHeaderProvider) : base(client, authHeaderProvider,
"people")
Expand Down
1 change: 1 addition & 0 deletions API.Data/Faction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public sealed class Faction : IEntity
{
public string Name { get; set; } = null!;
public bool HideFromStatistics { get; set; } = false;
public string? Link { get; set; } = null;
public Guid Identifier { get; set; }
}
3 changes: 2 additions & 1 deletion API.Data/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public sealed class Person : IEntity
public string Name { get; set; } = null!;
public Colour? DefaultColour { get; set; } = null;
public Guid Identifier { get; set; }

public bool HideFromStatistics { get; set; } = false;

public string Initials
{
get
Expand Down
2 changes: 2 additions & 0 deletions API.Data/Post/Faction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
public sealed class Faction
{
public string Name { get; set; } = null!;
public bool HideFromStatistics { get; set; } = false;
public string? Link { get; set; } = null;
}
1 change: 1 addition & 0 deletions API.Data/Post/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public sealed class Person
{
public string Name { get; set; } = null!;
public Guid? DefaultColourId { get; set; } = null;
public bool HideFromStatistics { get; set; } = false;
}
4 changes: 3 additions & 1 deletion API.Data/Post/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ public Player(Data.Player model)
Points = model.Points;
Winner = model.Winner;
Eliminated = model.Eliminated;

DraftOrder = model.DraftOrder;

PersonIdentifier = model.Person.Identifier;
FactionIdentifier = model.Faction.Identifier;
ColourIdentifier = model.Colour.Identifier;
}

public uint DraftOrder { get; set; }
public uint Points { get; set; }
public bool Winner { get; set; }
public bool Eliminated { get; set; }
Expand Down
12 changes: 11 additions & 1 deletion API.Data/Put/Person.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
namespace Hesketh.MecatolArchives.API.Data.Put;

public sealed class Person
public sealed class Person : IEntity
{
public Person() {}

public Person(Data.Person person)
{
Identifier = person.Identifier;
Name = person.Name;
DefaultColourId = person.DefaultColour?.Identifier;
}

public Guid Identifier { get; set; }
public string Name { get; set; } = null!;
public bool HideFromStatistics { get; set; } = false;
public Guid? DefaultColourId { get; set; } = null;
}
13 changes: 10 additions & 3 deletions Website/Components/Dialogs/EditPlayDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<MudTh>Player</MudTh>
<MudTh>Colour</MudTh>
<MudTh>Faction</MudTh>
<MudTh>Draft</MudTh>
<MudTh>Eliminated</MudTh>
<MudTh>Points</MudTh>
<MudTh>Winner</MudTh>
Expand Down Expand Up @@ -109,6 +110,9 @@
}
</MudSelect>
</MudTd>
<MudTh>
<MudNumericField T="uint" @bind-Value="playerContext.DraftOrder" Label="Draft"/>
</MudTh>
<MudTd>
<MudCheckBox T="bool" @bind-Value="playerContext.Eliminated" Label="Eliminated" />
</MudTd>
Expand Down Expand Up @@ -166,7 +170,8 @@
Faction = player.Faction,
Person = player.Person,
Points = player.Points,
Winner = player.Winner
Winner = player.Winner,
DraftOrder = player.DraftOrder
});
}

Expand Down Expand Up @@ -215,7 +220,8 @@
FactionIdentifier = x.Faction!.Identifier,
PersonIdentifier = x.Person!.Identifier,
Points = x.Points,
Winner = x.Winner
Winner = x.Winner,
DraftOrder = x.DraftOrder
}).ToList(),
PointGoal = _play.PointGoal,
RulesVersion = _play.RulesVersion,
Expand Down Expand Up @@ -329,7 +335,8 @@
public uint Points { get; set; }
public bool Winner { get; set; }
public bool Eliminated { get; set; }

public uint DraftOrder { get; set; }

public Person? Person { get; set; }
public Faction? Faction { get; set; }
public Colour? Colour { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions Website/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
<MudDrawerHeader>
<MudText Typo="Typo.h6">MECATOL ARCHIVES</MudText>
</MudDrawerHeader>
<CascadingValue Value="@Authenticated">
<NavMenu/>
</CascadingValue>
</MudDrawer>
<MudMainContent>
<CascadingValue Value="@Authenticated">
Expand Down
21 changes: 14 additions & 7 deletions Website/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
<MudNavLink Href="games/history" Icon="@Icons.Material.Filled.History">Games</MudNavLink>
<MudNavLink Href="stats/people" Icon="@Icons.Material.Filled.Leaderboard">Players</MudNavLink>
<MudNavLink Href="stats/factions" Icon="@Icons.Material.Filled.Leaderboard">Factions</MudNavLink>
<MudNavGroup Title="Data" Icon="@Icons.Material.Filled.DataObject">
<MudNavLink Href="data/colours" Icon="@Icons.Material.Filled.List">Colours</MudNavLink>
<MudNavLink Href="data/expansions" Icon="@Icons.Material.Filled.List">Expansions</MudNavLink>
<MudNavLink Href="data/factions" Icon="@Icons.Material.Filled.List">Factions</MudNavLink>
<MudNavLink Href="data/variants" Icon="@Icons.Material.Filled.List">Variants</MudNavLink>
<MudNavLink Href="data/people" Icon="@Icons.Material.Filled.List">People</MudNavLink>
</MudNavGroup>
@if (Authenticated)
{
<MudNavGroup Title="Data" Icon="@Icons.Material.Filled.DataObject">
<MudNavLink Href="data/colours" Icon="@Icons.Material.Filled.List">Colours</MudNavLink>
<MudNavLink Href="data/expansions" Icon="@Icons.Material.Filled.List">Expansions</MudNavLink>
<MudNavLink Href="data/factions" Icon="@Icons.Material.Filled.List">Factions</MudNavLink>
<MudNavLink Href="data/variants" Icon="@Icons.Material.Filled.List">Variants</MudNavLink>
<MudNavLink Href="data/people" Icon="@Icons.Material.Filled.List">People</MudNavLink>
</MudNavGroup>
}
</MudNavMenu>

@code {
[CascadingParameter] public bool Authenticated { get; set; } = false;
}
7 changes: 6 additions & 1 deletion Website/Components/Pages/Data/FactionsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<col style="width: 50px;"/>
}
<col style="width: auto"/>
<col style="width: auto"/>
<col style="width: auto"/>
@if (!_dataGrid.ReadOnly)
{
<col style="width: 100px"/>
Expand Down Expand Up @@ -47,6 +49,8 @@
<MudTextField T="string" @bind-Value="@context.Item.Name"></MudTextField>
</EditTemplate>
</TemplateColumn>
<PropertyColumn Property="x => x.HideFromStatistics"/>
<PropertyColumn Property="x => x.Link" Required="false"/>
<TemplateColumn Hidden="@(_dataGrid.ReadOnly)" CellClass="d-flex justify-end" Sortable="false">
<CellTemplate>
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Filled.Delete" OnClick="@(() => Delete(context.Item))"/>
Expand Down Expand Up @@ -95,7 +99,8 @@
{
var result = await FactionClient.CreateAsync(new API.Data.Post.Faction
{
Name = faction.Name
Name = faction.Name,
HideFromStatistics = faction.HideFromStatistics
});
faction.Identifier = result.Identifier;
_factions.Add(faction);
Expand Down
55 changes: 43 additions & 12 deletions Website/Components/Pages/Data/PeoplePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
@using Hesketh.MecatolArchives.API.Client.Clients
@using Hesketh.MecatolArchives.API.Data
@using Hesketh.MecatolArchives.API.Client.Auth
@using Hesketh.MecatolArchives.Website.Helpers
@inject PersonClient PersonClient;
@inject IDialogService DialogService
@inject ColourClient ColourClient

<PageTitle>People</PageTitle>

Expand All @@ -14,26 +16,43 @@
EditTrigger="DataGridEditTrigger.Manual"
@ref="_dataGrid">
<ColGroup>
<col style="width: auto" />
<col style="width: auto"/>
@if (!_dataGrid.ReadOnly)
{
<col style="width: 100px" />
<col style="width: 100px"/>
}
</ColGroup>
<ToolBarContent>
<MudText Typo="Typo.h6">PEOPLE</MudText>
<MudSpacer />
<MudSpacer/>
@if (!_dataGrid.ReadOnly)
{
<MudIconButton Icon="@Icons.Material.Filled.Add" OnClick="CreateNew" />
<MudIconButton Icon="@Icons.Material.Filled.Add" OnClick="CreateNew"/>
}
</ToolBarContent>
<Columns>
<PropertyColumn Property="x => x.Name" />
<PropertyColumn Property="x => x.Name"/>
<PropertyColumn Property="x => x.HideFromStatistics"/>
<TemplateColumn Sortable="false">
<CellTemplate>
@if (context.Item.DefaultColour != null)
{
<MudText Style="@ColourStyleHelper.GetUnderlineStyle(context.Item.DefaultColour.Hex)">@context.Item.DefaultColour.Name</MudText>
}
</CellTemplate>
<EditTemplate>
<MudSelect T="Colour" Label="Colour" @bind-Value="@context.Item.DefaultColour" ToStringFunc="ToStringFunc">
@foreach (var colour in Colours)
{
<MudSelectItem T="Colour" Style="@ColourStyleHelper.GetUnderlineStyle(colour.Hex)" Value="@colour">@colour.Name</MudSelectItem>
}
</MudSelect>
</EditTemplate>
</TemplateColumn>
<TemplateColumn Hidden="@(_dataGrid.ReadOnly)" CellClass="d-flex justify-end" Sortable="false">
<CellTemplate>
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Filled.Delete" OnClick="@(() => Delete(context.Item))" />
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Filled.Edit" OnClick="@context.Actions.StartEditingItemAsync" />
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Filled.Delete" OnClick="@(() => Delete(context.Item))"/>
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Filled.Edit" OnClick="@context.Actions.StartEditingItemAsync"/>
</CellTemplate>
</TemplateColumn>
</Columns>
Expand All @@ -44,12 +63,18 @@
private MudDataGrid<Person> _dataGrid = null!;
private List<Person> _people = new();
[CascadingParameter] public bool Authenticated { get; set; } = false;

private ICollection<Colour> Colours { get; set; } = new List<Colour>();

protected override async Task OnParametersSetAsync()
{
_people = new List<Person>(await PersonClient.GetAsync());
}

protected override async Task OnInitializedAsync()
{
Colours = new List<Colour>(await ColourClient.GetAsync());
}

private async void Delete(Person person)
{
var delete = await DialogService.ShowMessageBox("Delete", $"Are you sure you wish to delete {person.Name}?", "Yes", "No");
Expand All @@ -72,18 +97,24 @@
{
if (person.Identifier != Guid.Empty)
{
await PersonClient.UpdateAsync(person);
await PersonClient.UpdateAsync(new API.Data.Put.Person(person));
}
else
{
var result = await PersonClient.CreateAsync(new API.Data.Post.Person
{
Name = person.Name
});
{
Name = person.Name,
HideFromStatistics = person.HideFromStatistics
});
person.Identifier = result.Identifier;
_people.Add(person);
}

StateHasChanged();
}

private string ToStringFunc(Colour? arg)
{
return arg?.Name ?? string.Empty;
}
}
7 changes: 7 additions & 0 deletions Website/Components/Pages/Stats/FactionPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<MudText Style="display: inline-block; text-align: center;"
Typo="Typo.h4">@_title</MudText>
</div>
@if (_link != null)
{
<MudSpacer/>
<MudIconButton Icon="@Icons.Material.Filled.Info" Href="@_link"/>
}
</MudCardHeader>
<MudCardContent>
<StatisticTable Statistics="@(new[] { _statistics.Overall })" />
Expand Down Expand Up @@ -49,6 +54,7 @@
private Statistics _statistics = new();
private ICollection<Play> _playHistory = new List<Play>();
private string _title = "Faction";
private string? _link = null;

protected override async Task OnParametersSetAsync()
{
Expand All @@ -57,6 +63,7 @@

var faction = await FactionClient.GetAsync(FactionIdentifier);
_title = faction.Name;
_link = faction.Link;

StateHasChanged();
}
Expand Down

0 comments on commit 5383882

Please sign in to comment.