Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Enable handling for standing sort options #115

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@using System.ComponentModel
@using iRLeagueApiCore.Common.Enums
@inherits MvvmComponentBase
@inject SortOptionsViewModel sortOptions
@inject SortOptionsViewModel Vm

<EditForm Model=sortOptions>
<EditForm Model=Vm>
<div class="input-group-list mb-3">
@{ var optionsAvailable = Enum.GetValues<SortValue>().Except(sortOptions.Options.Select(x => x.SortValue)); }
@foreach((var option, var index) in @Bind(sortOptions, x => x.Options).Select((x, i) => (x, i)))
@{ var optionsAvailable = AvailableSortValues.Except(Vm.Options.Select(x => x.SortValue)); }
@foreach((var option, var index) in @Bind(Vm, x => x.Options).Select((x, i) => (x, i)))
{
<InputGroup Label=@(index == 0 ? "Sort by" : "..then by")>
<InputSelect class="form-select" @bind-Value=option.SortValue>
Expand All @@ -20,15 +20,16 @@
<option [email protected]><span class="oi oi-arrow-down">Asc.</span></option>
<option [email protected]><span class="oi oi-arrow-up">Desc.</span></option>
</InputSelect>
<button class="btn btn-outline-danger" type="button" @onclick=@(() => sortOptions.RemoveOption(option))>
<button class="btn btn-outline-danger" type="button" @onclick=@(() => Vm.RemoveOption(option))>
<span class="oi oi-x"/>
</button>
</InputGroup>
}
<InputGroup Label=@(sortOptions.Options.Count() == 0 ? "Sort by" : "..then by")>
<InputGroup Label=@(Vm.Options.Count() == 0 ? "Sort by" : "..then by")>
<InputSelect @bind-Value=NewValue
@ref=NewValueInput
class="form-select">
class="form-select"
placeholder="Select...">
<option value="">Select...</option>
@foreach(var enumValue in optionsAvailable)
{
Expand Down Expand Up @@ -56,6 +57,27 @@
[Parameter]
public IList<SortOptions> Model { get; set; } = default!;

[Parameter]
public IEnumerable<SortValue> AvailableSortValues { get; set; } = new[]
{
SortValue.Pos,
SortValue.PosChg,
SortValue.StartPos,
SortValue.RacePts,
SortValue.PenPts,
SortValue.BonusPts,
SortValue.TotalPts,
SortValue.TotalPtsNoBonus,
SortValue.TotalPtsNoPenalty,
SortValue.Intvl,
SortValue.ComplLaps,
SortValue.LeadLaps,
SortValue.Incs,
SortValue.FastLap,
SortValue.QualLap,
SortValue.FinalPos,
};

private SortDirection NewSortDirection { get; set; }

private SortValue? NewValue
Expand Down Expand Up @@ -84,14 +106,14 @@
{
return;
}
sortOptions.SetModel(Model);
Vm.SetModel(Model);
}

private async Task SetNewValue(SortValue? value, SortDirection direction)
{
if (value.HasValue)
{
sortOptions.AddOption(value.Value, direction);
Vm.AddOption(value.Value, direction);
}
if (NewValueInput.Element is not null)
{
Expand All @@ -101,7 +123,7 @@

private async Task Submit()
{
var result = ModalResult.Ok(sortOptions.GetModel());
var result = ModalResult.Ok(Vm.GetModel());
await ModalInstance.CloseAsync(result);
}

Expand Down Expand Up @@ -130,6 +152,15 @@
SortValue.FastLap => "Fastest Lap",
SortValue.QualLap => "Qualy Lap",
SortValue.FinalPos => "Final Position",
SortValue.LastRaceOrder => "Last race finish position",
SortValue.Wins => "Wins",
SortValue.Top3 => "Podiums",
SortValue.Top5 => "Top 5",
SortValue.Top10 => "Top 10",
SortValue.Races => "Races started",
SortValue.RacesCounted => "Races counted",
SortValue.RacesScored => "Races eligible for points",
SortValue.RacesInPoints => "Races with points",
_ => string.Empty,
};
}
Expand Down
52 changes: 52 additions & 0 deletions src/iRLeagueManager.Web/Pages/Settings/ChampionShipSettings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@
</div>
<label class="form-control" data-bs-toggle="tooltip" title="Treat events with multiple race sessions as single events (if they have a combined result). This will affect the statistics for race-nr, wins, fastest laps etc.">Treat as single event</label>
</div>
<InputGroup Label="Sort Final">
<button class="form-control" type="button" @onclick=@(() => EditSortOptionsClick(ChampSeason.StandingConfig)) data-bs-toggle="tooltip" title="Sort for final order displayed on results page and to define final positions">
@{
var sortOptions = ChampSeason.StandingConfig.SortOptions;
}
@if (sortOptions.Any())
{
<div class="d-flex justify-content-start overflow-scroll">
@foreach ((var option, var priority) in sortOptions.Select((x, i) => (x, i + 1)))
{
<div class="d-inline-block me-3 mb-2">
<span>
@(
priority
)[email protected]()
</span>
</div>
}
</div>
}
else
{
<div class="text-muted">Default</div>
}
</button>
</InputGroup>
<InputGroup Label="Count Weeks">
<InputNumber class="form-control"
@bind-Value=ChampSeason.StandingConfig.WeeksCounted
Expand Down Expand Up @@ -306,6 +332,32 @@ else
ChampSeason.DefaultResultConfig = null;
}

private async Task EditSortOptionsClick(StandingConfigurationViewModel standingConfig)
{
var parameters = new ModalParameters<EditSortOptionsModal>()
.Add(x => x.Model, standingConfig.SortOptions.ToList())
.Add(x => x.AvailableSortValues, new[]
{
SortValue.TotalPts,
SortValue.PenPts,
SortValue.Incs,
SortValue.Wins,
SortValue.Top3,
SortValue.Top5,
SortValue.Top10,
SortValue.LastRaceOrder,
SortValue.Races,
SortValue.RacesCounted,
SortValue.RacesScored,
SortValue.RacesInPoints,
});
var result = await ModalService.Show<EditSortOptionsModal>("Edit Standing Sorting", parameters).Result;
if (result.Confirmed && result.Data is IList<SortOptions> model)
{
standingConfig.SortOptions = model.ToList();
}
}

private ResultConfigModel CreateResultConfig() => new ResultConfigModel()
{
ChampSeasonId = ChampSeason.ChampSeasonId,
Expand Down
38 changes: 36 additions & 2 deletions src/iRLeagueManager.Web/ViewModels/SortOptionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public SortDirection SortDirection
}
}

private (SortValue sortValue, SortDirection direction) GetSortValue(SortOptions value)
private static (SortValue sortValue, SortDirection direction) GetSortValue(SortOptions value)
{
return value switch
{
Expand Down Expand Up @@ -73,11 +73,29 @@ public SortDirection SortDirection
SortOptions.TotalPtsWoBonusDesc => (SortValue.TotalPtsNoBonus, SortDirection.Descending),
SortOptions.TotalPtsWoPenaltyAsc => (SortValue.TotalPtsNoPenalty, SortDirection.Ascending),
SortOptions.TotalPtsWoPenaltyDesc => (SortValue.TotalPtsNoPenalty, SortDirection.Descending),
SortOptions.LastRaceOrderAsc => (SortValue.LastRaceOrder, SortDirection.Ascending),
SortOptions.LastRaceOrderDesc => (SortValue.LastRaceOrder, SortDirection.Descending),
SortOptions.WinsAsc => (SortValue.Wins, SortDirection.Ascending),
SortOptions.WinsDesc => (SortValue.Wins, SortDirection.Descending),
SortOptions.Top3Asc => (SortValue.Top3, SortDirection.Ascending),
SortOptions.Top3Desc => (SortValue.Top3, SortDirection.Descending),
SortOptions.Top5Asc => (SortValue.Top5, SortDirection.Ascending),
SortOptions.Top5Desc => (SortValue.Top5, SortDirection.Descending),
SortOptions.Top10Asc => (SortValue.Top10, SortDirection.Ascending),
SortOptions.Top10Desc => (SortValue.Top10, SortDirection.Descending),
SortOptions.RacesAsc => (SortValue.Races, SortDirection.Ascending),
SortOptions.RacesDesc => (SortValue.Races, SortDirection.Descending),
SortOptions.RacesCountedAsc => (SortValue.RacesCounted, SortDirection.Ascending),
SortOptions.RacesCountedDesc => (SortValue.RacesCounted, SortDirection.Descending),
SortOptions.RacesScoredAsc => (SortValue.RacesScored, SortDirection.Ascending),
SortOptions.RacesScoredDesc => (SortValue.RacesScored, SortDirection.Descending),
SortOptions.RacesInPointsAsc => (SortValue.RacesInPoints, SortDirection.Ascending),
SortOptions.RacesInPointsDesc => (SortValue.RacesInPoints, SortDirection.Descending),
_ => (SortValue.TotalPts, SortDirection.Descending),
};
}

private SortOptions GetSortOptions(SortValue sortValue, SortDirection direction)
private static SortOptions GetSortOptions(SortValue sortValue, SortDirection direction)
{
return (sortValue, direction) switch
{
Expand Down Expand Up @@ -113,6 +131,22 @@ private SortOptions GetSortOptions(SortValue sortValue, SortDirection direction)
(SortValue.TotalPtsNoBonus, SortDirection.Descending) => SortOptions.TotalPtsWoBonusDesc,
(SortValue.TotalPtsNoPenalty, SortDirection.Ascending) => SortOptions.TotalPtsWoPenaltyAsc,
(SortValue.TotalPtsNoPenalty, SortDirection.Descending) => SortOptions.TotalPtsWoPenaltyDesc,
(SortValue.Wins, SortDirection.Ascending) => SortOptions.WinsAsc,
(SortValue.Wins, SortDirection.Descending) => SortOptions.WinsDesc,
(SortValue.Top3, SortDirection.Ascending) => SortOptions.Top3Asc,
(SortValue.Top3, SortDirection.Descending) => SortOptions.Top3Desc,
(SortValue.Top5, SortDirection.Ascending) => SortOptions.Top5Asc,
(SortValue.Top5, SortDirection.Descending) => SortOptions.Top5Desc,
(SortValue.Top10, SortDirection.Ascending) => SortOptions.Top10Asc,
(SortValue.Top10, SortDirection.Descending) => SortOptions.Top10Desc,
(SortValue.Races, SortDirection.Ascending) => SortOptions.RacesAsc,
(SortValue.Races, SortDirection.Descending) => SortOptions.RacesDesc,
(SortValue.RacesCounted, SortDirection.Ascending) => SortOptions.RacesCountedAsc,
(SortValue.RacesCounted, SortDirection.Descending) => SortOptions.RacesCountedDesc,
(SortValue.RacesScored, SortDirection.Ascending) => SortOptions.RacesScoredAsc,
(SortValue.RacesScored, SortDirection.Descending) => SortOptions.RacesScoredDesc,
(SortValue.RacesInPoints, SortDirection.Ascending) => SortOptions.RacesInPointsAsc,
(SortValue.RacesInPoints, SortDirection.Descending) => SortOptions.RacesInPointsDesc,
_ => SortOptions.TotalPtsDesc,
};
}
Expand Down
17 changes: 14 additions & 3 deletions src/iRLeagueManager.Web/ViewModels/SortOptionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public override void SetModel(IList<SortOptions> model)

public void AddOption(SortValue value, SortDirection direction)
{
var option = new SortOptionViewModel(new());
option.SortValue = value;
option.SortDirection = direction;
var option = new SortOptionViewModel(new())
{
SortValue = value,
SortDirection = direction
};
Options.Add(option);
}

Expand Down Expand Up @@ -62,6 +64,15 @@ public enum SortValue
FastLap,
QualLap,
FinalPos,
LastRaceOrder,
Wins,
Top3,
Top5,
Top10,
Races,
RacesCounted,
RacesScored,
RacesInPoints,
}

public enum SortDirection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public StandingConfigurationViewModel(ILoggerFactory loggerFactory, LeagueApiSer
public bool UseCombinedResult { get => model.UseCombinedResult; set => SetP(model.UseCombinedResult, value => model.UseCombinedResult = value, value); }

public int? WeeksCounted { get => model.WeeksCounted <= 0 ? null : model.WeeksCounted; set => SetP(model.WeeksCounted, value => model.WeeksCounted = value, value > 0 ? value.Value : 0); }

public ICollection<SortOptions> SortOptions { get => model.SortOptions; set => SetP(model.SortOptions, value => model.SortOptions = value, value); }
}
4 changes: 2 additions & 2 deletions src/iRLeagueManager.Web/iRLeagueManager.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
<PackageReference Include="Blazored.Modal" Version="7.1.0" />
<PackageReference Include="HtmlSanitizer" Version="8.0.645" />
<PackageReference Include="iRLeagueApiCore.Client" Version="0.9.0" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.9.1" />
<PackageReference Include="iRLeagueApiCore.Client" Version="0.9.4" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.9.3-dev.3" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="Blazored.Toast" Version="4.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.3" />
Expand Down