Skip to content

Commit

Permalink
Merge pull request #42 from SSchulze1989/develop
Browse files Browse the repository at this point in the history
v0.5.0
  • Loading branch information
SSchulze1989 authored Mar 7, 2023
2 parents e7ddabc + a0885ec commit 381cc9b
Show file tree
Hide file tree
Showing 31 changed files with 1,108 additions and 309 deletions.
10 changes: 5 additions & 5 deletions src/iRLeagueManager.Web/Components/ConfirmModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
@switch (ButtonTypes)
{
case ButtonTypes.Ok:
<div class="col-sm-6 d-flex justify-content-center">
<div class="col d-flex justify-content-center">
<button class="btn btn-primary" @onclick=OkClick>Ok</button>
</div>
<div class="col-sm-6 d-flex justify-content-center">
<div class="col d-flex justify-content-center">
<button class="btn btn-secondary" @onclick=CancelClick>Cancel</button>
</div>
break;
case ButtonTypes.OkCancel:
<div class="col-sm-6 d-flex justify-content-center">
<div class="col d-flex justify-content-center">
<button class="btn btn-primary" @onclick=CancelClick>Cancel</button>
</div>
break;
case ButtonTypes.YesNo:
<div class="col-sm-6 d-flex justify-content-center">
<div class="col d-flex justify-content-center">
<button class="btn btn-outline-primary" @onclick=OkClick>Yes</button>
</div>
<div class="col-sm-6 d-flex justify-content-center">
<div class="col d-flex justify-content-center">
<button class="btn btn-secondary" @onclick=CancelClick>No</button>
</div>
break;
Expand Down
22 changes: 16 additions & 6 deletions src/iRLeagueManager.Web/Components/EditEventModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@inject TrackListService trackListService

<EditForm Model=Event OnValidSubmit=Submit>
<StatusResultValidator @ref=ResultValidator/>
<StatusResultValidator @ref=ResultValidator TrimPrefix="Event."/>
<div class="input-group-list mb-2">
<InputGroup Label="Name">
<InputText class="form-control" placeholder="Event Name" aria-label="EventName" id="name" @bind-Value="Event.Name"/>
Expand Down Expand Up @@ -97,27 +97,27 @@
</div>
<div class="input-group-list mb-2">
<InputGroup Label="Result Configs">
<BlazoredTypeahead @bind-Values=Event.ResultConfigs
<BlazoredTypeahead @bind-Values=Event.ResultConfigs
SearchMethod=SearchResultConfigs
MinimumLength=0
MaximumSuggestions=10
EnableDropDown=true
DeleteItemsOnBackspace=false
class="form-control py-0 px-0 ps-1 border"
style="border-color: #ced4da !important"
class="form-control py-0 px-0 ps-1"
placeholder="Enter config name...">
<SelectedTemplate Context=config >
@config?.Name
@GetReferencedResultConfigName(config)
</SelectedTemplate>
<ResultTemplate Context=config>
@config.Name
@GetReferencedResultConfigName(config)
</ResultTemplate>
<NotFoundTemplate Context=name>
@name not found!
</NotFoundTemplate>
</BlazoredTypeahead>
</InputGroup>
</div>
<FormValidationMessage For="() => Event.ResultConfigs" />
<FormValidationMessage TValue=string Message=@ResultValidator?.ErrorMessage />
<CancelSubmitButtons ModelState=Event SubmitText="Save" OnCancel=Cancel/>
</EditForm>
Expand Down Expand Up @@ -196,9 +196,19 @@
private async Task<IEnumerable<ResultConfigInfoModel>> SearchResultConfigs(string name)
{
return await Task.FromResult(ResultConfigs
.Where(x => Event.ResultConfigs.Any(y => y.ResultConfigId == x.ResultConfigId) == false)
.Where(x => x.Name.Contains(name, StringComparison.OrdinalIgnoreCase) || x.DisplayName.Contains(name, StringComparison.OrdinalIgnoreCase)));
}

private string GetReferencedResultConfigName(ResultConfigInfoModel config)
{
if (string.IsNullOrEmpty(config.ChampionshipName))
{
return config.Name;
}
return $"{config.ChampionshipName} - {config.Name}";
}

private async Task Submit()
{
//var status = await Event.SaveChangesAsync(cts.Token);
Expand Down
2 changes: 1 addition & 1 deletion src/iRLeagueManager.Web/Components/EditModalBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace iRLeagueManager.Web.Components;

public class EditModalBase<TViewModel, TModel> : MvvmComponentBase where TViewModel : LeagueViewModelBase<TViewModel, TModel>
public class EditModalBase<TViewModel, TModel> : MvvmComponentBase where TViewModel : LeagueViewModelBase<TViewModel, TModel> where TModel : class
{
[Inject]
protected TViewModel Vm { get; set; } = default!;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@using iRLeagueManager.Web.ViewModels

<div @attributes=AdditionalAttributes>
<div class="mb-1">
<h5>@ChampSeason.ChampionshipName</h5>
</div>
<div class="d-flex mb-2 gap-3">
<h6>ResultConfigs</h6>
<div class="d-flex">
@foreach(var config in ChampSeason.ResultConfigs)
{
<div class="badge bg-secondary p-2">
@config.Name
</div>
}
</div>
</div>
<div class="d-flex gap-3">
<h6>Standing Config</h6>
<div>
@ChampSeason.StandingConfig?.Name
</div>
</div>
</div>


@code {
[Parameter(CaptureUnmatchedValues=true)]
public IDictionary<string, object>? AdditionalAttributes { get; set; }

[Parameter, EditorRequired]
public ChampSeasonViewModel ChampSeason { get; set; } = default!;

protected override void OnParametersSet()
{
_ = ChampSeason ?? throw BlazorParameterNullException.New(this, ChampSeason);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@using iRLeagueManager.Web.ViewModels

<div @attributes=AdditionalAttributes>
@{
var name = ChampSeason?.ChampionshipName ?? Championship.Name;
var displayName = ChampSeason?.ChampionshipDisplayName ?? Championship.DisplayName;
}
<div class="d-flex">
<h5>@name</h5>
@if (string.IsNullOrEmpty(displayName) == false && displayName != name)
{
<i>&nbsp;&nbsp;&nbsp;=> "@displayName"</i>
}
</div>
@if (ChampSeason is not null)
{
<div class="row">
<div class="col-5">
<h6>Result Configurations</h6>
<ul>
@foreach(var config in ChampSeason.ResultConfigs)
{
<li>@config.Name</li>
}
</ul>
</div>
<div class="col-5">
<h6>Standings</h6>
<ul>
<li>Count @ChampSeason.StandingConfig?.WeeksCounted weeks</li>
</ul>
</div>
</div>
}
</div>


@code {
[Parameter(CaptureUnmatchedValues=true)]
public IDictionary<string, object>? AdditionalAttributes { get; set; }

[Parameter, EditorRequired]
public ChampionshipViewModel Championship { get; set; } = default!;

[Parameter, EditorRequired]
public ChampSeasonViewModel? ChampSeason { get; set; }

protected override void OnParametersSet()
{
_ = Championship ?? throw BlazorParameterNullException.New(this, Championship);
}
}
126 changes: 126 additions & 0 deletions src/iRLeagueManager.Web/Components/Settings/EditChampSeasonModal.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
@using iRLeagueApiCore.Common.Models;
@inherits EditModalBase<ChampSeasonViewModel, ChampSeasonModel>

<EditForm Model="Vm" OnValidSubmit=Submit>
<StatusResultValidator @ref=ResultValidator />
<div class="accordion mb-3">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseChampionship" aria-expanded="true" aria-controls="collapseChampionship">
Championship
</button>
</h2>
<div class="accordion-collapse collapse show input-group-list input-group-list-flush" id="collapseChampionship">
<InputGroup Label="Name">
<InputText class="form-control" @bind-Value=Vm.ChampionshipName placeholder="Enter championship name ..." data-bs-toggle="tooltip" title="Name to identify the championship" />
</InputGroup>
<InputGroup Label="Display Name">
<InputText class="form-control" @bind-Value=Vm.ChampionshipDisplayName placeholder="@Vm.ChampionshipName" data-bs-toggle="tooltip" title="Name of the championship to be shown displayed on results and standings" />
</InputGroup>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseResults" aria-expanded="true" aria-controls="collapseResults">
Race Results
</button>
</h2>
<div class="accordion-collapse collapse show list-group list-group-flush" id="collapseResults">
@foreach(var resultConfig in Vm.ResultConfigViewModels)
{
<div class="list-group-item list-group-item-action d-flex justify-content-between" type="button" @onclick=@(() => OnResultConfigClick(resultConfig))>
<ResultConfigPreview ResultConfig="resultConfig" class="overflow-auto"/>
<div class="d-flex align-self-start">
<button class="btn btn-toggle" type="button" data-bs-toggle="collapse" data-bs-target="#config_@(resultConfig.ResultConfigId)_details"
aria-expanded="false" @onclick:stopPropagation>
<span class="oi oi-chevron-bottom btn-toggle-off" />
<span class="oi oi-chevron-top btn-toggle-on" />
</button>
<button class="btn btn-outline-danger" type="button" @onclick=@(() =>OnDeleteResultConfigClick(resultConfig)) @onclick:stopPropagation>
<span class="oi oi-trash" />
</button>
</div>
</div>
}
<div class="list-group-item">
<button class="btn btn-outline-secondary" type="button" @onclick=OnAddResultConfigClick>
Add Result Configuration
</button>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseStandings" aria-expanded="true" aria-controls="collapseStandings">
Standings
</button>
</h2>
<div class="accordion-collapse collapse show input-group-list input-group-list-flush" id="collapseStandings">
@if (Vm.StandingConfig is not null)
{
<div class="input-group">
<div class="input-group-text">
<InputCheckbox class="form-check-input mt-0" @bind-Value=Vm.StandingConfig.UseCombinedResult />
</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="Count Weeks">
<InputNumber class="form-control" @bind-Value=Vm.StandingConfig.WeeksCounted data-bs-toggle="tooltip" title="Number of races counted per season. (used for Dropweeks)" />
</InputGroup>
}
</div>
</div>
</div>
<FormValidationMessage TValue=string Message=@ResultValidator?.ErrorMessage />
<CancelSubmitButtons ModelState=Vm SubmitText="Save" OnCancel=Cancel />
</EditForm>

@code {
private IEnumerable<ResultConfigViewModel> ResultConfigs { get; set; } = Array.Empty<ResultConfigViewModel>();

protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender == false) return;

await Vm.LoadResultConfigs(Cts.Token);
await InvokeAsync(StateHasChanged);
}

private async Task OnResultConfigClick(ResultConfigViewModel config)
{
var parameters = new ModalParameters<EditResultConfigModal>()
.Add(x => x.Model, config.CopyModel())
.Add(x => x.OnSubmit, (configVm, cancellationToken) => configVm.SaveChangesAsync(cancellationToken));
var result = await ModalService.Show<EditResultConfigModal>("Edit result config", parameters).Result;
if (result.Confirmed && result.Data is ResultConfigModel model)
{
config.SetModel(model);
}
}

private async Task OnAddResultConfigClick()
{
var parameters = new ModalParameters<EditResultConfigModal>()
.Add(x => x.Model, CreateResultConfig())
.Add(x => x.OnSubmit, (x, c) => Vm.AddResultConfig(x.GetModel(), c));
await ModalService.Show<EditResultConfigModal>("Add result config", parameters).Result;
}

private async Task OnDeleteResultConfigClick(ResultConfigViewModel config)
{
var parameters = new ModalParameters<ConfirmModal>()
.Add(x => x.Text, $"Really delete result config \"{config.Name}\"?")
.Add(x => x.ButtonTypes, ButtonTypes.YesNo);
var result = await ModalService.Show<ConfirmModal>("Delete Result Config", parameters).Result;
if (result.Confirmed)
{
await Vm.DeleteResultConfig(config.GetModel());
}
}

private ResultConfigModel CreateResultConfig()
{
return new ResultConfigModel();
}
}
Loading

0 comments on commit 381cc9b

Please sign in to comment.