Skip to content

Commit

Permalink
Merge pull request #153 from SSchulze1989/feature/change-teams-on-pre…
Browse files Browse the repository at this point in the history
…vious-result

Feature/change teams on previous result
  • Loading branch information
SSchulze1989 authored Jul 12, 2024
2 parents def7551 + f2f1dfe commit 3560c40
Show file tree
Hide file tree
Showing 18 changed files with 557 additions and 129 deletions.
2 changes: 1 addition & 1 deletion src/iRLeagueManager.Web/Components/EventSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
return null;
}
index ??= EventList.EventList.IndexOf(@event);
return $"{(index + 1).Value.ToString("00")}. {@event.Date.GetValueOrDefault().ToString("dd.MM.yy")}: {@event.TrackName}" + (@event.ConfigName != "-" ? $" - {@event.ConfigName}" : "");
return $"{(index + 1).Value.ToString("00")}. {@event.Date.GetValueOrDefault().ToShortDateFormatted()}: {@event.TrackName}" + (@event.ConfigName != "-" ? $" - {@event.ConfigName}" : "");
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
@using iRLeagueApiCore.Common.Models.Tracks
@using iRLeagueManager.Web.ViewModels
@inherits EditDialogBase<EventViewModel, EventModel>
@inject JsonSerializerOptions jsonOptions
@inject TrackListService trackListService

<EditForm Model=Vm OnValidSubmit=Submit>
<EditForm Model=Vm>
<StatusResultValidator @ref=ResultValidator TrimPrefix="Event." />
<MudDialog>
<DialogContent>
Expand Down Expand Up @@ -106,7 +105,7 @@
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel" Color="Color.Secondary">Cancel</MudButton>
<ProgressButton ButtonType="ButtonType.Submit" Color="Color.Primary" Loading="Loading">Save</ProgressButton>
<ProgressButton OnClick="Submit" Color="Color.Primary" Loading="Loading">Save</ProgressButton>
</DialogActions>
</MudDialog>
</EditForm>
Expand Down
30 changes: 29 additions & 1 deletion src/iRLeagueManager.Web/Components/Results/DisplayResult.razor
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<MudMenu Icon="@Icons.Material.Filled.MoreVert" Dense="true" Size="Size.Small">
<MudMenuItem OnClick="() => AddBonusPentalyClick(Row)">Add Bonus/Penalty</MudMenuItem>
<MudMenuItem OnClick="() => ShowBonusesPenaltiesClick(Row)">Show Bonuses/Penalties</MudMenuItem>
<MudMenuItem OnClick="() => ChangeTeamClick(Row)">Change Team</MudMenuItem>
</MudMenu>
</td>
}
Expand All @@ -127,6 +128,8 @@
@code {
[CascadingParameter]
private EventListViewModel EventList { get; set; } = default!;
[CascadingParameter]
private ResultsPageViewModel? ResultsPageVm { get; set; }
[Parameter, EditorRequired]
public SessionResultViewModel Result { get; set; } = default!;
[Parameter]
Expand All @@ -143,7 +146,7 @@
protected override void OnParametersSet()
{
base.OnParametersSet();
BlazorParameterNullException.ThrowIfNull(this, EventList);
BlazorParameterNullException.ThrowIfNull(this, EventList, cascading: true);
BlazorParameterNullException.ThrowIfNull(this, Result);
isTeamResult = Result.ResultRows.Any(x => x.MemberId == null);
showDisqualification = Result.ResultRows.Any(x => x.Status == RaceStatus.Disqualified);
Expand Down Expand Up @@ -220,4 +223,29 @@
};
await DialogService.Show<ShowPenaltiesDialog>("Bonuses/Penalties", parameters, options).Result;
}

private async Task ChangeTeamClick(ResultRowModel? row)
{
if (row is null)
{
return;
}

var parameters = new DialogParameters<ChangeTeamsDialog>()
{
{ x => x.Member, new() { FirstName = row.Firstname, LastName = row.Lastname, MemberId = row.MemberId.GetValueOrDefault() }},
};

await DialogService.Show<ChangeTeamsDialog>("Change Team", parameters).Result;
await Refresh();
}

private async Task Refresh()
{
if (ResultsPageVm?.SelectedEvent is null)
{
return;
}
await ResultsPageVm.LoadFromEventAsync(ResultsPageVm.SelectedEvent.EventId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@inherits EditDialogBase<ReviewCommentViewModel, ReviewCommentModel>
@inject LeagueApiService ApiService

<EditForm Model=Vm OnValidSubmit=Submit>
<EditForm Model=Vm>
<MudDialog>
<DialogContent>
<MudStack Spacing="2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@using iRLeagueManager.Web.ViewModels
@inherits EditDialogBase<ReviewViewModel, ReviewModel>

<EditForm Model=Vm OnValidSubmit=Submit>
<EditForm Model=Vm>
<StatusResultValidator @ref=ResultValidator />
<MudDialog>
<DialogContent>
Expand Down Expand Up @@ -53,7 +53,7 @@
</DialogContent>
<DialogActions>
<MudButton Color="Color.Secondary" OnClick="Cancel">Cancel</MudButton>
<ProgressButton Color="Color.Primary" ButtonType="ButtonType.Submit" Loading="Loading">Save</ProgressButton>
<ProgressButton Color="Color.Primary" OnClick="Submit" Loading="Loading">Save</ProgressButton>
</DialogActions>
</MudDialog>
</EditForm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@inherits EditDialogBase<ReviewViewModel, ReviewModel>
@inject LeagueApiService ApiService

<EditForm Model=Vm OnValidSubmit=Submit>
<EditForm Model=Vm>
<MudDialog>
<DialogContent>
<MudStack Spacing="2">
Expand Down Expand Up @@ -84,7 +84,7 @@
</DialogContent>
<DialogActions>
<MudButton Color="Color.Secondary" OnClick="Cancel">Cancel</MudButton>
<ProgressButton Color="Color.Primary" ButtonType="ButtonType.Submit" Loading="Vm.Loading">Save</ProgressButton>
<ProgressButton Color="Color.Primary" OnClick="Submit" Loading="Vm.Loading">Save</ProgressButton>
</DialogActions>
</MudDialog>
</EditForm>
Expand Down
80 changes: 80 additions & 0 deletions src/iRLeagueManager.Web/Components/Teams/ChangeTeamsDialog.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@namespace iRLeagueManager.Web.Components
@inherits UtilityComponentBase

<MudDialog>
<DialogContent>
<MudStack>
<MudProgressLinear Indeterminate="Loading" Color="Color.Primary" Class="@(Loading ? "" : "invisible")"/>
@* Driver Info *@
<MudText Typo="Typo.h5">
@Member.FirstName @Member.LastName
</MudText>

@* Select new Team *@
<MudAutocomplete Label="New Team"
@bind-Value="newTeam"
SearchFunc="SearchTeam"
Placeholder="@currentTeam?.Name"
ToStringFunc="@(team => team?.Name)"
Clearable="true">
</MudAutocomplete>

@* Select Season *@
<MudSelect Label="Season" @bind-Value="Season">
@foreach (var season in ApiService.Shared.SeasonList)
{
<MudSelectItem Value="season">
@season.SeasonName
</MudSelectItem>
}
</MudSelect>
<MudSwitch Label="Apply to whole season"
@bind-Value="selectWholeSeason"
Color="Color.Primary" />

@* Result/Team table *@
<MudTable Items="memberTeamResults" Bordered="true" Dense="true">
<HeaderContent>
<MudTh></MudTh>
<MudTh>Race</MudTh>
<MudTh>Team</MudTh>
<MudTh></MudTh>
</HeaderContent>
<RowTemplate Context="Row">
<MudTd>
<MudCheckBox Value="@(Row.Selected || selectWholeSeason)"
ValueChanged="@((bool value) => Row.Selected = value)"
Disabled="selectWholeSeason" />
</MudTd>
<MudTd>
<MudStack Spacing="0">
<span>@Row.RaceNr. - @Row.Date.ToShortDateFormatted()</span>
<span>@Row.TrackName</span>
</MudStack>
</MudTd>
<MudTd Style="@($"{(Row.Team != null ? $"color: {Row.Team.TeamColor}" : "")}")">@Row.Team?.Name</MudTd>
<MudTd Style="width: 4em">
@switch (Row.State)
{
case ChangeTeamState.ToChange:
<MudIcon Icon="@Icons.Material.Outlined.Pending"/>
break;
case ChangeTeamState.Changing:
<MudProgressCircular Color="Color.Default" Indeterminate="true" Size="Size.Small" />
break;
case ChangeTeamState.Changed:
<MudIcon Icon="@Icons.Material.Outlined.CheckCircle" Color="Color.Success" />
break;
default:
break;
}
</MudTd>
</RowTemplate>
</MudTable>
</MudStack>
</DialogContent>
<DialogActions>
<MudButton Color="Color.Secondary" OnClick="@(() => ModalInstance.Close())">Close</MudButton>
<MudButton Color="Color.Primary" OnClick="Submit" Disabled="!CanSubmit">Apply</MudButton>
</DialogActions>
</MudDialog>
Loading

0 comments on commit 3560c40

Please sign in to comment.