Skip to content

Commit

Permalink
Merge pull request #99 from SSchulze1989/develop
Browse files Browse the repository at this point in the history
v 0.8.1
  • Loading branch information
SSchulze1989 authored Aug 17, 2023
2 parents 22e5795 + 92f804a commit f39a9db
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 40 deletions.
18 changes: 6 additions & 12 deletions src/iRLeagueManager.Web/Components/Results/DisplayResult.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@
}
<ResultTableHeader Text="Fastest Lap" Sort="@(x => x.FastestLapTime)" />
<ResultTableHeader Text="Avg. Lap" Sort="@(x => x.AvgLapTime)" />
@if (isTeamResult == false)
{
<ResultTableHeader Text="Interval" Sort="@(x => x.Interval)" />
<ResultTableHeader Text="Laps Lead" Sort="@(x => x.LeadLaps)" Direction="SortDirection.Descending" />
<ResultTableHeader Text="Laps Compl." Sort="@(x => x.CompletedLaps)" Direction="SortDirection.Descending" />
}
<ResultTableHeader Text="Interval" Sort="@(x => x.Interval)" />
<ResultTableHeader Text="Laps Lead" Sort="@(x => x.LeadLaps)" Direction="SortDirection.Descending" />
<ResultTableHeader Text="Laps Compl." Sort="@(x => x.CompletedLaps)" Direction="SortDirection.Descending" />
<ResultTableHeader Text="Race Pts." Sort="@(x => x.RacePoints)" Direction="SortDirection.Descending" />
@if (displayBonusPoints)
{
Expand Down Expand Up @@ -83,12 +80,9 @@
}
<td class="@(IsFastestLap(resultRows, Row, x => x.FastestLapTime) ? "fw-bold" : "")">@Row.FastestLapTime.LapTimeString() @(Row.FastLapNr != 0 ? $"({Row.FastLapNr})" : "")</td>
<td class="@(IsFastestLap(resultRows, Row, x => x.AvgLapTime) ? "fw-bold" : "")">@Row.AvgLapTime.LapTimeString()</td>
@if (isTeamResult == false)
{
<td>+@(Row.Interval.Laps == 0 ? Row.Interval.Time.LapTimeString() : $"{Row.Interval.Laps} Laps")</td>
<td>@Row.LeadLaps</td>
<td>@Row.CompletedLaps</td>
}
<td>+@(Row.Interval.Laps == 0 ? Row.Interval.Time.LapTimeString() : $"{Row.Interval.Laps} Laps")</td>
<td>@Row.LeadLaps</td>
<td>@Row.CompletedLaps</td>
<td>@Row.RacePoints</td>
@if (displayBonusPoints)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@
return;
}
await Vm.LoadAvailableResultConfigs(Cts.Token);
await Vm.LoadLeagueMembers(Cts.Token);
await Vm.LoadLeagueMembersAndTeams(Cts.Token);
}

private async Task PointsFilterClick()
{
var parameters = new ModalParameters<EditResultFilterModal>()
.Add(x => x.Model, Vm.GetModel().FiltersForPoints)
.Add(x => x.LeagueMembers, Vm.LeagueMembers);
.Add(x => x.LeagueMembers, Vm.LeagueMembers)
.Add(x => x.Teams, Vm.Teams);
var options = new ModalOptions()
{
DisableBackgroundCancel = true,
Expand All @@ -173,7 +174,8 @@
{
var parameters = new ModalParameters<EditResultFilterModal>()
.Add(x => x.Model, Vm.GetModel().FiltersForResult)
.Add(x => x.LeagueMembers, Vm.LeagueMembers);
.Add(x => x.LeagueMembers, Vm.LeagueMembers)
.Add(x => x.Teams, Vm.Teams);
var options = new ModalOptions()
{
DisableBackgroundCancel = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,41 @@
</BlazoredTypeahead>
</InputGroup>
break;
case FilterType.Team:
<InputGroup Label="Teams">
<BlazoredTypeahead @bind-Values=filter.FilterValues
class="form-control p-0"
style="border-top-right-radius:0; border-top-left-radius:0;"
EnableDropDown=true
SearchMethod=SearchTeams
ConvertMethod="@(item => item.TeamId.ToString())"
MinimumLength=1
MaximumSuggestions=100
DeleteItemsOnBackspace=false
placeholder="Search driver by name...">

<SelectedTemplate Context=teamId>
@{
var team = Teams.FirstOrDefault(x => x.TeamId.ToString() == teamId);
}
@if (team is null)
{
@teamId
}
else
{
@team.Name
}
</SelectedTemplate>
<ResultTemplate Context=team>
@team.Name@(team.IRacingTeamId != null ? $" ({@team.IRacingTeamId})" : "")
</ResultTemplate>
<NotFoundTemplate Context=name>
<span>Team <b>@name</b> Not found!</span>
</NotFoundTemplate>
</BlazoredTypeahead>
</InputGroup>
break;
case FilterType.ColumnProperty:
<InputGroup Label="Type">
<InputSelect class="form-select" id="input-type-select" aria-label="input-type-select" @bind-Value=filter.Comparator>
Expand Down Expand Up @@ -111,6 +146,7 @@
}
else if (propertyType == typeof(double) || propertyType == typeof(double?) || propertyType == typeof(int) || propertyType == typeof(int?))
{

<input type="number" class="form-control" value=@filter.Value @onchange=@((ChangeEventArgs args) => filter.Value = args.Value?.ToString() ?? string.Empty) />
}
else
Expand All @@ -137,6 +173,8 @@

[Parameter]
public IEnumerable<MemberModel> LeagueMembers { get; set; } = default!;
[Parameter]
public IEnumerable<TeamModel> Teams { get; set; } = default!;

[Parameter]
public bool AllowForEach { get; set; } = false;
Expand All @@ -156,6 +194,7 @@
nameof(ResultRowModel.NewSafetyRating),
nameof(ResultRowModel.Incidents),
"Member",
"Team",
};

public static MatchedValueAction[] DefaultActions { get; } = new[]
Expand All @@ -170,6 +209,25 @@
[Parameter]
public IEnumerable<MatchedValueAction> Actions { get; set; } = DefaultActions;

protected override void OnParametersSet()
{
base.OnParametersSet();
BlazorParameterNullException.ThrowIfNull(this, ModalInstance);
BlazorParameterNullException.ThrowIfNull(this, Model);
BlazorParameterNullException.ThrowIfNull(this, LeagueMembers);
BlazorParameterNullException.ThrowIfNull(this, Teams);
}

protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (firstRender == false)
{
return;
}
vm.SetModel(Model);
}

private async Task<IEnumerable<MemberModel>> SearchMembers(string searchString)
{
if (string.IsNullOrEmpty(searchString))
Expand All @@ -178,12 +236,26 @@
}

var terms = searchString.ToLower().Split(',', ' ', ';')
.Where(x => string.IsNullOrWhiteSpace(x) == false)
.Where(x => string.IsNullOrWhiteSpace(x) == false)
.ToArray();
return await Task.FromResult(LeagueMembers
.Where(x => MatchMemberSearchTerms(x, terms)));
}

private async Task<IEnumerable<TeamModel>> SearchTeams(string searchstring)
{
if (string.IsNullOrWhiteSpace(searchstring))
{
return await Task.FromResult(Teams);
}

var terms = searchstring.ToLower().Split(',', ' ', ';')
.Where(x => string.IsNullOrWhiteSpace(x) == false)
.ToArray();
return await Task.FromResult(Teams.
Where(x => MatchTeamSearchTerms(x, terms)));
}

private bool MatchMemberSearchTerms(MemberModel member, params string[] terms)
{
var searchName = member.FirstName + member.LastName;
Expand All @@ -194,20 +266,14 @@
);
}

protected override void OnParametersSet()
{
BlazorParameterNullException.ThrowIfNull(this, ModalInstance);
BlazorParameterNullException.ThrowIfNull(this, Model);
BlazorParameterNullException.ThrowIfNull(this, LeagueMembers);
}

protected override void OnAfterRender(bool firstRender)
private bool MatchTeamSearchTerms(TeamModel team, params string[] terms)
{
if (firstRender == false)
{
return;
}
vm.SetModel(Model);
var searchName = team.Name;
var iracingId = team.IRacingTeamId.GetValueOrDefault().ToString();
return terms
.Any(x => searchName.Contains(x, StringComparison.OrdinalIgnoreCase) ||
iracingId.Contains(x)
);
}

private async Task Submit()
Expand Down
22 changes: 17 additions & 5 deletions src/iRLeagueManager.Web/ViewModels/ResultConfigViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public ResultConfigViewModel(ILoggerFactory loggerFactory, LeagueApiService apiS
filtersForResult ??= new();
availableResultConfigs ??= new();
leagueMembers ??= new();
teams ??= new();
}

public long LeagueId => model.LeagueId;
Expand Down Expand Up @@ -76,6 +77,9 @@ public bool CalculateCombinedResult
private ObservableCollection<MemberModel> leagueMembers;
public ObservableCollection<MemberModel> LeagueMembers { get => leagueMembers; set => Set(ref leagueMembers, value); }

private ObservableCollection<TeamModel> teams;
public ObservableCollection<TeamModel> Teams { get => teams; set => Set(ref teams, value); }

public override void SetModel(ResultConfigModel model)
{
base.SetModel(model);
Expand Down Expand Up @@ -134,7 +138,7 @@ public async Task<StatusResult> LoadAvailableResultConfigs(CancellationToken can
return result.ToStatusResult();
}

public async Task<StatusResult> LoadLeagueMembers(CancellationToken cancellationToken = default)
public async Task<StatusResult> LoadLeagueMembersAndTeams(CancellationToken cancellationToken = default)
{
if (CurrentLeague is null)
{
Expand All @@ -144,13 +148,21 @@ public async Task<StatusResult> LoadLeagueMembers(CancellationToken cancellation
try
{
Loading = true;
var result = await CurrentLeague.Members()
var membersResult = await CurrentLeague.Members()
.Get(cancellationToken);
if (result.Success && result.Content is not null)
if (membersResult.Success == false || membersResult.Content is null)
{
LeagueMembers = new(result.Content);
return membersResult.ToStatusResult();
}
return result.ToStatusResult();
LeagueMembers = new(membersResult.Content);
var teamsResult = await CurrentLeague.Teams()
.Get(cancellationToken);
if (teamsResult.Success == false || teamsResult.Content is null)
{
return teamsResult.ToStatusResult();
}
Teams = new(teamsResult.Content);
return StatusResult.SuccessResult();
}
finally
{
Expand Down
19 changes: 18 additions & 1 deletion src/iRLeagueManager.Web/ViewModels/ResultFilterViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using iRLeagueApiCore.Common.Enums;
using iRLeagueApiCore.Common.Models;
using iRLeagueManager.Web.Data;
using System.Globalization;

namespace iRLeagueManager.Web.ViewModels;

Expand Down Expand Up @@ -33,7 +34,10 @@ public string ColumnPropertyName
public ComparatorType Comparator { get => model.Comparator; set => SetP(model.Comparator, value => model.Comparator = value, value); }
public FilterType FilterType { get => model.FilterType; private set => SetP(model.FilterType, value => model.FilterType = value, value); }
public IList<string> FilterValues { get => (IList<string>)model.FilterValues; set => SetP(model.FilterValues, value => model.FilterValues = value, value); }
public string Value { get => model.FilterValues.FirstOrDefault() ?? string.Empty; set => SetP(model.FilterValues.FirstOrDefault() ?? string.Empty, value => model.FilterValues = new[] { value }.ToList(), value); }
public string Value
{
get => ConvertFromValue(model.FilterValues.FirstOrDefault() ?? string.Empty, ColumnPropertyName);
set => SetP(model.FilterValues.FirstOrDefault() ?? string.Empty, value => model.FilterValues = new[] { ConvertToValue(value, ColumnPropertyName) }.ToList(), value); }
public MatchedValueAction Action { get => model.Action; set => SetP(model.Action, value => model.Action = value, value); }

public override void SetModel(ResultFilterModel model)
Expand All @@ -47,7 +51,20 @@ private void UpdateFilterType()
FilterType = ColumnPropertyName switch
{
"Member" => FilterType.Member,
"Team" => FilterType.Team,
_ => FilterType.ColumnProperty,
};
}

private static string ConvertFromValue(string filterValue, string? columnProperty) => columnProperty switch
{
nameof(ResultRowModel.CompletedPct) => ((double)Convert.ChangeType(filterValue, typeof(double), CultureInfo.InvariantCulture) * 100).ToString(),
_ => filterValue
};

private static string ConvertToValue(string value, string? columnProperty) => columnProperty switch
{
nameof(ResultRowModel.CompletedPct) => ((double)Convert.ChangeType(value, typeof(double), CultureInfo.InvariantCulture) / 100).ToString(),
_ => value
};
}
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.8.0</Version>
<Version>0.8.1</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-iRLeagueManager.Web-2B05F9DC-55A3-49D1-BD64-31507000EDF3</UserSecretsId>
Expand Down 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.8.0" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.8.0" />
<PackageReference Include="iRLeagueApiCore.Client" Version="0.8.1" />
<PackageReference Include="iRLeagueApiCore.Common" Version="0.8.1" />
<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

0 comments on commit f39a9db

Please sign in to comment.