Skip to content

Commit

Permalink
Merge pull request #164 from SSchulze1989/develop
Browse files Browse the repository at this point in the history
v 0.13.0
  • Loading branch information
SSchulze1989 authored Dec 27, 2024
2 parents af5ee1b + e1dba5f commit 11a5b19
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,14 @@
<MudText Style="@($"color: {GetPenaltyColor(penalty)}")">
@switch (penalty)
{
case { Type: PenaltyType.Points, Points: >= 0 }:
@:@(-penalty.Points) pt@(penalty.Points != 1 ? "s" : "")
break;
case { Type: PenaltyType.Points, Points: < 0 }:
@:+@(-penalty.Points) pt@(penalty.Points != 1 ? "s" : "")
case { Type: PenaltyType.Points }:
@:@(penalty.Points < 0 ? "+" : "")@(-penalty.Points) pt@(penalty.Points != 1 ? "s" : "")
break;
case { Type: PenaltyType.Position }:
@:+ @penalty.Positions position@(penalty.Positions != 1 ? "s" : "")
@:@(penalty.Positions >= 0 ? "+" : "")@penalty.Positions position@(penalty.Positions != 1 ? "s" : "")
break;
case { Type: PenaltyType.Time }:
@:+ @penalty.Time
@:@(penalty.Time >= TimeSpan.Zero ? "+" : "")@penalty.Time
break;
case { Type: PenaltyType.Disqualification }:
<MudStack Row="true" AlignItems="AlignItems.Center">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
@namespace iRLeagueManager.Web.Components
@using iRLeagueApiCore.Common.Enums
@using iRLeagueApiCore.Common.Models.Reviews
@inherits EditDialogBase<VoteCategoryViewModel, VoteCategoryModel>

<MudDialog>
<DialogContent>
<EditForm Model="Vm" OnValidSubmit=Submit>
<StatusResultValidator @ref=ResultValidator />
<MudGrid Spacing="2">
<MudItem xs="8">
<MudTextField @bind-Value="Vm.Text"
Label="Name"
For="() => Vm.Text"
Variant="Variant.Outlined" />
</MudItem>
<MudItem xs="4">
<MudTextField @bind-Value="Vm.DefaultPenalty"
Label="@GetPointLabel(Vm.DefaultPenalty)"
For="() => Vm.DefaultPenalty"
InputMode="InputMode.numeric"
InputType="InputType.Number"
Variant="Variant.Outlined" />
</MudItem>
</MudGrid>
<MudStack Spacing="2">
<MudTextField @bind-Value="Vm.Text"
Label="Name"
For="() => Vm.Text"
Variant="Variant.Outlined" />
<MudSelect Label="Type" @bind-Value="Vm.Type" Variant="Variant.Outlined">
@foreach (var penaltyType in Enum.GetValues<PenaltyType>())
{
<MudSelectItem Value="@penaltyType" />
}
</MudSelect>
@switch (Vm.DefaultPenalty.Type)
{
case PenaltyType.Points:
<MudNumericField Label="Points" @bind-Value="Vm.Points" Variant="Variant.Outlined" />
break;
case PenaltyType.Position:
<MudNumericField Label="Positions" @bind-Value="Vm.Positions" Variant="Variant.Outlined" />
break;
case PenaltyType.Time:
<MudNumericField Label="Time" @bind-Value="Vm.TimeSeconds" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentText="seconds" />
break;
}
</MudStack>
<FormValidationMessage TValue=string Message=@ResultValidator?.ErrorMessage />
</EditForm>
</DialogContent>
Expand Down
56 changes: 54 additions & 2 deletions src/iRLeagueManager.Web/Pages/Settings/ReviewSettings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,47 @@
HelperText="@(categoriesExpanded ? "Collapse" : "Expand")"
InitiallyExpanded="false"
Class="me-4 pe-4">
<MudTable Items="Bind(Reviews, x => x.VoteCategories)"
<MudTable Items="Reviews.VoteCategories"
Breakpoint="Breakpoint.None"
Hover="true"
OnRowClick="@((TableRowClickEventArgs<VoteCategoryViewModel> e) => OnVoteCategoryClick(e.Item))">
<HeaderContent>
<MudTh Class="ps-4">Text</MudTh>
<MudTh>Penalty/Bonus</MudTh>
<MudTh></MudTh>
<MudTh></MudTh>
</HeaderContent>
<RowTemplate Context=category>
<MudTd Class="ps-4">
@category.Text
</MudTd>
<MudTd>
@(category.DefaultPenalty > 0 ? "+" : "")@category.DefaultPenalty
@switch(category.Type)
{
case PenaltyType.Points:
@:@(category.Points >= 0 ? "+" : "")@(category.Points) pt@(category.Points != 1 ? "s" : "")
break;
case PenaltyType.Position:
@:@(category.Positions >= 0 ? "+" : "")@category.Positions position@(category.Positions != 1 ? "s" : "")
break;
case PenaltyType.Time:
@:@(category.Time >= TimeSpan.Zero ? "+" : "")@category.Time
break;
case PenaltyType.Disqualification:
<MudStack Row="true" AlignItems="AlignItems.Center">
<MudText>DSQ</MudText>
<MudIcon Icon="@Icons.Material.Filled.Flag" Style="color: black;" Size="Size.Small" />
</MudStack>
break;
}
</MudTd>
<MudTd>
<MudIconButton Icon="@Icons.Material.Filled.ArrowUpward"
Size="Size.Small" Disabled="category.Index <= 0"
OnClick="@(() => MoveCategoryUp(category))" />
<MudIconButton Icon="@Icons.Material.Filled.ArrowDownward"
Size="Size.Small" Disabled="category.Index >= Reviews.VoteCategories.Count - 1"
OnClick="@(() => MoveCategoryDown(category))" />
</MudTd>
<MudTd>
<MudIconButton Icon="@Icons.Material.Outlined.Delete" Color="Color.Error" OnClick="@(() => OnDeleteVoteCategoryClick(category))" Size="Size.Small" />
Expand Down Expand Up @@ -187,4 +213,30 @@
}
base.Dispose(disposing);
}

private async Task MoveCategoryUp(VoteCategoryViewModel category)
{
var index = Reviews.VoteCategories.IndexOf(category);
if (index <= 0 || Reviews.VoteCategories.Count <= index)
{
return;
}
var tmp = Reviews.VoteCategories[index];
Reviews.VoteCategories[index] = Reviews.VoteCategories[index - 1];
Reviews.VoteCategories[index - 1] = tmp;
await Reviews.UpdateVoteCategoryOrder(Reviews.VoteCategories, CancellationToken);
}

private async Task MoveCategoryDown(VoteCategoryViewModel category)
{
var index = Reviews.VoteCategories.IndexOf(category);
if (index < 0 || Reviews.VoteCategories.Count <= index + 1)
{
return;
}
var tmp = Reviews.VoteCategories[index];
Reviews.VoteCategories[index] = Reviews.VoteCategories[index + 1];
Reviews.VoteCategories[index + 1] = tmp;
await Reviews.UpdateVoteCategoryOrder(Reviews.VoteCategories, CancellationToken);
}
}
62 changes: 51 additions & 11 deletions src/iRLeagueManager.Web/ViewModels/ReviewSettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using iRLeagueApiCore.Common.Models.Reviews;
using iRLeagueManager.Web.Data;
using iRLeagueManager.Web.Extensions;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace iRLeagueManager.Web.ViewModels;

Expand All @@ -10,11 +9,11 @@ public sealed class ReviewSettingsViewModel : LeagueViewModelBase<ReviewSettings
public ReviewSettingsViewModel(ILoggerFactory loggerFactory, LeagueApiService apiService) :
base(loggerFactory, apiService)
{
voteCategories = new();
voteCategories = [];
}

private ObservableCollection<VoteCategoryViewModel> voteCategories;
public ObservableCollection<VoteCategoryViewModel> VoteCategories
private IList<VoteCategoryViewModel> voteCategories;
public IList<VoteCategoryViewModel> VoteCategories
{
get => voteCategories;
set
Expand All @@ -41,20 +40,20 @@ private void OnVoteCategoryChanged(object? sender, EventArgs e)

public async Task<StatusResult> LoadAsync(CancellationToken cancellationToken = default)
{
if (ApiService.CurrentLeague is null)
if (CurrentLeague is null)
{
return LeagueNullResult();
}

try
{
Loading = true;
var request = ApiService.CurrentLeague.VoteCategories()
var request = CurrentLeague.VoteCategories()
.Get(cancellationToken);
var result = await request;
if (result.Success && result.Content is not null)
{
VoteCategories = new(result.Content.Select(x => new VoteCategoryViewModel(LoggerFactory, ApiService, x)));
VoteCategories = result.Content.Select(x => new VoteCategoryViewModel(LoggerFactory, ApiService, x)).ToList();
}
return result.ToStatusResult();
}
Expand All @@ -64,17 +63,58 @@ public async Task<StatusResult> LoadAsync(CancellationToken cancellationToken =
}
}

public async Task<StatusResult> UpdateVoteCategoryOrder(IList<VoteCategoryViewModel> voteCategories, CancellationToken cancellationToken = default)
{
if (CurrentLeague == null)
{
return LeagueNullResult();
}

try
{
Loading = true;
bool hasIndexUpdated = false;
foreach (var (voteCategory, index) in voteCategories.WithIndex())
{
if (voteCategory.Index != index)
{
voteCategory.Index = index;
var request = CurrentLeague
.VoteCategories()
.WithId(voteCategory.CatId)
.Put(voteCategory.GetModel(), cancellationToken);
var result = await request;
if (result.Success == false)
{
return result.ToStatusResult();
}
hasIndexUpdated = true;
}
}

if (hasIndexUpdated)
{
return await LoadAsync(cancellationToken);
}
return StatusResult.SuccessResult();
}
finally
{
Loading = false;
}
}

public async Task<StatusResult> AddVoteCategory(VoteCategoryModel voteCategory, CancellationToken cancellationToken = default)
{
if (ApiService.CurrentLeague is null)
if (CurrentLeague is null)
{
return LeagueNullResult();
}

try
{
Loading = true;
var request = ApiService.CurrentLeague.VoteCategories()
var request = CurrentLeague.VoteCategories()
.Post(voteCategory, cancellationToken);
var result = await request;
if (result.Success == false)
Expand All @@ -91,15 +131,15 @@ public async Task<StatusResult> AddVoteCategory(VoteCategoryModel voteCategory,

public async Task<StatusResult> DeleteVoteCategory(VoteCategoryModel voteCategory, CancellationToken cancellationToken = default)
{
if (ApiService.CurrentLeague is null)
if (CurrentLeague is null)
{
return LeagueNullResult();
}

try
{
Loading = true;
var request = ApiService.CurrentLeague.VoteCategories()
var request = CurrentLeague.VoteCategories()
.WithId(voteCategory.Id)
.Delete(cancellationToken);
var result = await request;
Expand Down
11 changes: 9 additions & 2 deletions src/iRLeagueManager.Web/ViewModels/VoteCategoryViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using iRLeagueApiCore.Common.Models.Reviews;
using iRLeagueApiCore.Common.Enums;
using iRLeagueApiCore.Common.Models;
using iRLeagueApiCore.Common.Models.Reviews;
using iRLeagueManager.Web.Data;
using iRLeagueManager.Web.Extensions;

Expand All @@ -18,7 +20,12 @@ public VoteCategoryViewModel(ILoggerFactory loggerFactory, LeagueApiService apiS

public long CatId => model.Id;
public string Text { get => model.Text; set => SetP(model.Text, value => model.Text = value, value); }
public int DefaultPenalty { get => -model.DefaultPenalty; set => SetP(model.DefaultPenalty, value => model.DefaultPenalty = value, -value); }
public PenaltyModel DefaultPenalty { get => model.DefaultPenalty; set => SetP(model.DefaultPenalty, value => model.DefaultPenalty = value, value); }
public PenaltyType Type { get => DefaultPenalty.Type; set => SetP(DefaultPenalty.Type, value => DefaultPenalty.Type = value, value); }
public int Points { get => -DefaultPenalty.Points; set => SetP(DefaultPenalty.Points, value => DefaultPenalty.Points = value, -value); }
public int Positions { get => DefaultPenalty.Positions; set => SetP(DefaultPenalty.Positions, value => DefaultPenalty.Positions = value, value); }
public TimeSpan Time { get => DefaultPenalty.Time; set => SetP(DefaultPenalty.Time, value => DefaultPenalty.Time = value, value); }
public int TimeSeconds { get => (int)DefaultPenalty.Time.TotalSeconds; set => SetP(TimeSeconds, value => DefaultPenalty.Time = TimeSpan.FromSeconds(value), value); }
public int Index { get => model.Index; set => SetP(model.Index, value => model.Index = value, value); }

public async Task<StatusResult> SaveChangesAsync(CancellationToken cancellationToken = default)
Expand Down
4 changes: 2 additions & 2 deletions src/iRLeagueManager.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
}
},
"AllowedHosts": "*",
//"APIServer": "http://localhost:5000",
"APIServer": "https://irleaguemanager.net/api/",
"APIServer": "http://localhost:5000",
//"APIServer": "https://irleaguemanager.net/api/",
"DefaultUser": "testuser",
"DefaultPassword": "TestPass123!"
}
6 changes: 3 additions & 3 deletions src/iRLeagueManager.Web/iRLeagueManager.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Version>0.12.6</Version>
<Version>0.13.0</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-iRLeagueManager.Web-2B05F9DC-55A3-49D1-BD64-31507000EDF3</UserSecretsId>
Expand Down Expand Up @@ -33,8 +33,8 @@
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
<PackageReference Include="CoreCLR-NCalc" Version="3.0.145" />
<PackageReference Include="HtmlSanitizer" Version="8.0.843" />
<PackageReference Include="iRLeagueApiCore.Client" Version="0.12.2" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.12.2" />
<PackageReference Include="iRLeagueApiCore.Client" Version="0.13.0" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.13.0" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.3" />
Expand Down

0 comments on commit 11a5b19

Please sign in to comment.