Skip to content

Commit

Permalink
Merge pull request #511 from ipax77/dev
Browse files Browse the repository at this point in the history
Tourney link and stats query parameters
  • Loading branch information
ipax77 authored Aug 4, 2024
2 parents 1b60e08 + 29f7e6c commit 0fcdbd4
Show file tree
Hide file tree
Showing 10 changed files with 2,495 additions and 8 deletions.
2,370 changes: 2,370 additions & 0 deletions src/MysqlMigrations/Migrations/20240804071113_EventLink.Designer.cs

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions src/MysqlMigrations/Migrations/20240804071113_EventLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace MysqlMigrations.Migrations
{
/// <inheritdoc />
public partial class EventLink : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "ExternalLink",
table: "Events",
type: "varchar(200)",
maxLength: 200,
nullable: false,
defaultValue: "")
.Annotation("MySql:CharSet", "utf8mb4");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ExternalLink",
table: "Events");
}
}
}
5 changes: 5 additions & 0 deletions src/MysqlMigrations/Migrations/ReplayContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasPrecision(0)
.HasColumnType("datetime(0)");

b.Property<string>("ExternalLink")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)");

b.Property<int>("GameMode")
.HasColumnType("int");

Expand Down
2 changes: 1 addition & 1 deletion src/SC2ArcadeCrawler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void Main(string[] args)

var crawlerService = scope.ServiceProvider.GetRequiredService<CrawlerService>();

crawlerService.GetLobbyHistory(DateTime.Today.AddDays(-2), default).Wait();
crawlerService.GetLobbyHistory(DateTime.Today.AddDays(-1), default).Wait();
// crawlerService.GetLobbyHistory(new DateTime(2021, 2, 1), default).Wait();

Console.WriteLine("done.");
Expand Down
2 changes: 2 additions & 0 deletions src/dsstats.db8/Replay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public Event()
public DateTime EventStart { get; set; }
public string? WinnerTeam { get; set; }
public GameMode GameMode { get; set; }
[MaxLength(200)]
public string ExternalLink { get; set; } = string.Empty;
public virtual ICollection<ReplayEvent> ReplayEvents { get; set; }
}

Expand Down
3 changes: 2 additions & 1 deletion src/dsstats.db8services/Tourneys/TourneysService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public async Task<List<TourneyDto>> GetTourneys()
EventGuid = s.EventGuid,
EventStart = s.EventStart,
GameMode = s.GameMode,
WinnerTeam = s.WinnerTeam
WinnerTeam = s.WinnerTeam,
ExternalLink = s.ExternalLink,
}).ToListAsync();
}

Expand Down
11 changes: 7 additions & 4 deletions src/dsstats.razorlib/Tourneys/TourneyStatsComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@inject ITourneysService tourneysService

<CascadingValue Value="statsRequest">
<TourneyStatsRequestComponent OnFieldChanged="LoadStats"></TourneyStatsRequestComponent>
<TourneyStatsRequestComponent OnFieldChanged="e => LoadStats(e)"></TourneyStatsRequestComponent>
</CascadingValue>

@if (statsResponse == null)
Expand Down Expand Up @@ -102,15 +102,18 @@ else

protected override async Task OnInitializedAsync()
{
await LoadStats(statsRequest);
await LoadStats(statsRequest, true);
await base.OnInitializedAsync();
}


private async Task LoadStats(TourneysStatsRequest request)
private async Task LoadStats(TourneysStatsRequest request, bool isInit = false)
{
statsResponse = await tourneysService.GetTourneyStats(request, default);
await OnRequestChanged.InvokeAsync(request);
if (!isInit)
{
await OnRequestChanged.InvokeAsync(request);
}
await InvokeAsync(() => StateHasChanged());
}

Expand Down
1 change: 1 addition & 0 deletions src/dsstats.shared/Tourneys/TourneyDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public record TourneyDto
public DateTime EventStart { get; set; }
public GameMode GameMode { get; set; }
public string? WinnerTeam { get; set; }
public string ExternalLink { get; set; } = string.Empty;
}
52 changes: 50 additions & 2 deletions src/dsstats.web/dsstats.web.Client/Pages/Tourneys/StatsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,67 @@
@using dsstats.razorlib.Tourneys
@using dsstats.shared
@layout TourneysLayout
@inject NavigationManager NavigationManager

<PageTitle>dsstats -tourneys stats </PageTitle>

<TourneyStatsComponent statsRequest="StatsRequest" OnRequestChanged="RequestChanged" />

@code {
[SupplyParameterFromQuery]
public string? Tourney { get; set; }
[SupplyParameterFromQuery]
public bool? GroupOnly { get; set; }

TourneysStatsRequest StatsRequest = new()
{

};

private void RequestChanged(TourneysStatsRequest statsRequest)
protected override void OnInitialized()
{
SetRequest();
base.OnInitialized();
}

private void SetRequest()
{
if (!string.IsNullOrEmpty(Tourney))
{
StatsRequest.Tournament = Tourney;
}
if (GroupOnly is not null)
{
StatsRequest.Round = GroupOnly.Value ? "Group" : "Ro";
}
}

private void RequestChanged(TourneysStatsRequest request)
{

Dictionary<string, object?> queryDic = new();

if (!string.IsNullOrEmpty(request.Tournament))
{
queryDic.Add("Tourney", request.Tournament);
}
else
{
queryDic.Add("Tourney", null);
}

if (!string.IsNullOrEmpty(request.Round))
{
queryDic.Add("GroupOnly", request.Round.Equals("Group"));
}
else
{
queryDic.Add("GroupOnly", null);
}

NavigationManager.NavigateTo(
NavigationManager.GetUriWithQueryParameters(
new Dictionary<string, object?>(queryDic)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@using dsstats.shared.Interfaces
@layout TourneysLayout
@inject ITourneysService tourneysService
@inject NavigationManager NavigationManager

<PageTitle>dsstats - tourneys</PageTitle>

Expand All @@ -15,6 +16,8 @@
<th>Name</th>
<th>Winner</th>
<th>Mode</th>
<th>Stats</th>
<th>External Link</th>
</tr>
</thead>
<tbody>
Expand All @@ -24,6 +27,20 @@
<td>@tournament.Name</td>
<td>@tournament.WinnerTeam</td>
<td>@tournament.GameMode</td>
<td>
<button type="button" class="btn btn-sm btn-outline-light"
@onclick="e => NavigateToStats(tournament)">
Stats
</button>
</td>
@if (string.IsNullOrEmpty(tournament.ExternalLink))
{
<td></td>
}
else
{
<td><a href="@tournament.ExternalLink">Challonge</a></td>
}
</tr>
}
</tbody>
Expand All @@ -33,6 +50,15 @@
@code {
List<TourneyDto> tourneys = new();

private void NavigateToStats(TourneyDto tourney)
{
NavigationManager.NavigateTo(NavigationManager.GetUriWithQueryParameters("tourneys/stats",
new Dictionary<string, object?>()
{
{"Tourney", tourney.Name }
}
), false);
}

protected override async Task OnInitializedAsync()
{
Expand Down

0 comments on commit 0fcdbd4

Please sign in to comment.