From b3e7f9b41bbf5c3964638b2f3e07b147b613ac36 Mon Sep 17 00:00:00 2001 From: Simon Schulze Date: Mon, 13 May 2024 20:51:28 +0200 Subject: [PATCH 1/2] Add Button to fetch results from iracing api --- .../Components/Dialogs/PromptDialog.razor.cs | 3 +- .../Components/Dialogs/TextPromptDialog.razor | 3 +- .../Results/FetchResultsDialog.razor | 64 +++++++++++++++++++ src/iRLeagueManager.Web/Pages/Results.razor | 24 ++++++- 4 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/iRLeagueManager.Web/Components/Results/FetchResultsDialog.razor diff --git a/src/iRLeagueManager.Web/Components/Dialogs/PromptDialog.razor.cs b/src/iRLeagueManager.Web/Components/Dialogs/PromptDialog.razor.cs index 579b5bd8..feb7d858 100644 --- a/src/iRLeagueManager.Web/Components/Dialogs/PromptDialog.razor.cs +++ b/src/iRLeagueManager.Web/Components/Dialogs/PromptDialog.razor.cs @@ -9,7 +9,7 @@ public class PromptDialog : ComponentBase, IDisposable { private bool disposedValue; - [CascadingParameter] MudDialogInstance MudDialog { get; set; } = default!; + [CascadingParameter] protected MudDialogInstance MudDialog { get; set; } = default!; [Parameter] public T Value { get; set; } = default!; [Parameter] public Func>? OnSubmit { get; set; } [Parameter] public Func? OnCancel { get; set; } @@ -18,6 +18,7 @@ public class PromptDialog : ComponentBase, IDisposable [Parameter] public string? Label { get; set; } [Parameter] public string? HelperText { get; set; } [Parameter] public Variant Variant { get; set; } = Variant.Outlined; + [Parameter] public object? Validation { get; set; } private CancellationTokenSource Cts { get; } = new(); protected CancellationToken CancellationToken => Cts.Token; diff --git a/src/iRLeagueManager.Web/Components/Dialogs/TextPromptDialog.razor b/src/iRLeagueManager.Web/Components/Dialogs/TextPromptDialog.razor index eb48d2f0..24b1a921 100644 --- a/src/iRLeagueManager.Web/Components/Dialogs/TextPromptDialog.razor +++ b/src/iRLeagueManager.Web/Components/Dialogs/TextPromptDialog.razor @@ -10,7 +10,8 @@ Variant="Variant" InputType="InputType" Placeholder="@Placeholder" - Clearable="Clearable"/> + Clearable="Clearable" + Validation="Validation"/> diff --git a/src/iRLeagueManager.Web/Components/Results/FetchResultsDialog.razor b/src/iRLeagueManager.Web/Components/Results/FetchResultsDialog.razor new file mode 100644 index 00000000..808c5b21 --- /dev/null +++ b/src/iRLeagueManager.Web/Components/Results/FetchResultsDialog.razor @@ -0,0 +1,64 @@ +@namespace iRLeagueManager.Web.Components +@using iRLeagueApiCore.Common.Models +@inject LeagueApiService apiService +@inherits PromptDialog + + + + + + + + + + +@code { + [Parameter] public EventModel Event { get; set; } = default!; + + private bool hasError = false; + private string errorText = string.Empty; + + protected override async Task Submit() + { + hasError = false; + errorText = string.Empty; + + if (apiService.CurrentLeague is null) + { + MudDialog.Cancel(); + return; + } + + if (int.TryParse(Value, out int subsessionId) == false) + { + hasError = true; + errorText = "Subsession id must be a valid number"; + return; + } + + var request = apiService.CurrentLeague + .Events() + .WithId(Event.Id) + .Results() + .Fetch() + .FromIracingSubSession(subsessionId) + .Post(CancellationToken); + var result = await request; + if (result.Success == false) + { + hasError = true; + errorText = @"Fetching results from iracing api failed. Please check the subsession id and if the league results are available from public. +Please use JSON upload if this does not work"; + } + + MudDialog.Close(Value); + } +} diff --git a/src/iRLeagueManager.Web/Pages/Results.razor b/src/iRLeagueManager.Web/Pages/Results.razor index e94f981b..9e754837 100644 --- a/src/iRLeagueManager.Web/Pages/Results.razor +++ b/src/iRLeagueManager.Web/Pages/Results.razor @@ -108,7 +108,10 @@ @if (SharedState.SeasonFinished == false) { - Upload Result + + Upload Result + Fetch from SubsessionId + } @@ -191,6 +194,25 @@ } } + private async Task FetchResultsClick() + { + var @event = vm.SelectedEvent?.GetModel(); + if (@event is null) + { + return; + } + var parameters = new DialogParameters() + { + { x => x.Event, @event }, + }; + var result = await DialogService.Show("Fetch results from iracing subsession", parameters).Result; + if (result.Canceled == false) + { + await Task.Delay(2000); + await vm.LoadFromEventAsync(@event.Id); + } + } + private async Task TriggerCalculation() { if (vm.Loading) From d549249ab02f492a5f3515ded6285693748be8cf Mon Sep 17 00:00:00 2001 From: Simon Schulze Date: Mon, 13 May 2024 20:52:40 +0200 Subject: [PATCH 2/2] bump version to 0.11.11 --- src/iRLeagueManager.Web/iRLeagueManager.Web.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iRLeagueManager.Web/iRLeagueManager.Web.csproj b/src/iRLeagueManager.Web/iRLeagueManager.Web.csproj index 650a44fc..5e42610b 100644 --- a/src/iRLeagueManager.Web/iRLeagueManager.Web.csproj +++ b/src/iRLeagueManager.Web/iRLeagueManager.Web.csproj @@ -2,7 +2,7 @@ net7.0 - 0.11.10 + 0.11.11 enable enable aspnet-iRLeagueManager.Web-2B05F9DC-55A3-49D1-BD64-31507000EDF3