From bb16617f3ff5ce1c5bfa2dfe7e6ea11d25226f7c Mon Sep 17 00:00:00 2001 From: Mikhail Shabanov Date: Fri, 19 Aug 2022 16:44:00 +0200 Subject: [PATCH] feat: added nations selector to tanks tree --- .../Pages/PlayerInfoTanksTree.razor | 200 +++++++++--------- .../Pages/PlayerInfoTanksTree.razor.css | 13 ++ .../Pages/PlayerInfoTanksTreeBase.cs | 65 ++++-- 3 files changed, 170 insertions(+), 108 deletions(-) create mode 100644 WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTree.razor.css diff --git a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTree.razor b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTree.razor index 793734a..316f797 100644 --- a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTree.razor +++ b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTree.razor @@ -1,108 +1,116 @@ @using WotBlitzStatisticsPro.Blazor.Helpers @using System.Linq @inherits PlayerInfoTanksTreeBase; -
- - - @for (int i = 0; i < 10; i++) +
+
+ @foreach (var nationForFilter in NationsFilter) { - - + } - - - - @foreach (var pathConnection in Connections) - { - - } - - @if (TreeItems != null) - { - @for (int tier = 1; tier < 11; tier++) +
+
+ + + @for (int i = 0; i < 10; i++) { - @foreach (var tank in TreeItems.Where(t => t.Tier == tier).OrderBy(t => t.Row).ToList()) + + + } + + + + @foreach (var pathConnection in Connections) + { + + } + + @if (TreeItems != null) + { + @for (int tier = 1; tier < 11; tier++) { - - - - - t.Tier == tier).OrderBy(t => t.Row).ToList()) + { + + - + height="@CardHeigth"> + + + + - - - - - @tank.Tier.RomanNumber() - - - - - - @tank.Name - + + + + + @tank.Tier.RomanNumber() + + + + + + @tank.Name + - - @if (tank.IsResearched && tank.MarkOfMastery.HasValue && tank.WinRate.HasValue && tank.AvgDamage.HasValue && tank.Battles.HasValue && tank.LastBattleTime.HasValue) - { - - - - - - - @(tank.WinRate.Value.ToString("N0"))% - - - - - - @tank.AvgDamage.Value.ToString("N0") - - - - - @tank.Battles.Value.ToString("N0") - - - - - @tank.LastBattleTime.Value.ToString("d") - - - } - - @if (!tank.IsResearched) - { - - - - - @((tank.PriceCredit / 1000).ToString("N0")) K - - - } - - + + @if (tank.IsResearched && tank.MarkOfMastery.HasValue && tank.WinRate.HasValue && tank.AvgDamage.HasValue && tank.Battles.HasValue && tank.LastBattleTime.HasValue) + { + + + + + + + @(tank.WinRate.Value.ToString("N0"))% + + + + + + @tank.AvgDamage.Value.ToString("N0") + + + + + @tank.Battles.Value.ToString("N0") + + + + + @tank.LastBattleTime.Value.ToString("d") + + + } + + @if (!tank.IsResearched) + { + + + + + @((tank.PriceCredit / 1000).ToString("N0")) K + + + } + + + } } } - } - -
+ +
+
\ No newline at end of file diff --git a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTree.razor.css b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTree.razor.css new file mode 100644 index 0000000..f48a517 --- /dev/null +++ b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTree.razor.css @@ -0,0 +1,13 @@ + +.nation-filter-flag { + width: 70px; + height: 46px; + border-radius: 4px; + margin-right: 10px; +} + +.filter-selected { + border-width: 1px; + border-color: #f5aa3b; + border-style: solid; +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTreeBase.cs b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTreeBase.cs index 3a78c08..bf3be93 100644 --- a/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTreeBase.cs +++ b/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoTanksTreeBase.cs @@ -1,11 +1,13 @@ using MediatR; using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; using Microsoft.Extensions.Localization; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using WotBlitzStatisticsPro.Blazor.GraphQl; +using WotBlitzStatisticsPro.Blazor.Helpers; using WotBlitzStatisticsPro.Blazor.Model; using WotBlitzStatisticsPro.Blazor.Services; @@ -43,10 +45,12 @@ namespace WotBlitzStatisticsPro.Blazor.Pages public List TreeItems { get; set; } = new(); - public string SelectedNation { get; set; } = "germany"; + public string SelectedNation { get; set; } public List Connections { get; set; } = new List(); + public List> NationsFilter { get; set; } = new(); + public string FrameStyle { get @@ -57,19 +61,10 @@ namespace WotBlitzStatisticsPro.Blazor.Pages protected async override Task OnInitializedAsync() { + FillNationsFilter(); var screenHeight = await MediaQueriesService.WindowHeight(); - // TODO: Move it to the Nation selector handler - try - { - VehiclesLibrary = await GraphQlBackendService.GetVehiclesByNation(SelectedNation); - BuildTree(); - } - catch (System.Exception e) - { - Notifications.ReportError("Can not get data from backend", e.Message); - } - + await LoadTree(); } public int GetTextWidth(string text, string fontFace, int fontSize) @@ -242,5 +237,51 @@ namespace WotBlitzStatisticsPro.Blazor.Pages return maxRowsCount; } + + private void FillNationsFilter() + { + // ToDo: Should get values from Dictionary here instead of hard code + NationsFilter.Add(new FilterItem(Constants.CountryUsa, Constants.CountryUsa.NationAsset())); + NationsFilter.Add(new FilterItem(Constants.CountryFrance, Constants.CountryFrance.NationAsset())); + NationsFilter.Add(new FilterItem(Constants.CountryUssr, Constants.CountryUssr.NationAsset())); + NationsFilter.Add(new FilterItem(Constants.CountryChina, Constants.CountryChina.NationAsset())); + NationsFilter.Add(new FilterItem(Constants.CountryUk, Constants.CountryUk.NationAsset())); + NationsFilter.Add(new FilterItem(Constants.CountryJapan, Constants.CountryJapan.NationAsset())); + NationsFilter.Add(new FilterItem(Constants.CountryGermany, Constants.CountryGermany.NationAsset())); + NationsFilter.Add(new FilterItem(Constants.CountryOther, Constants.CountryOther.NationAsset())); + NationsFilter.Add(new FilterItem(Constants.CountryEuropean, Constants.CountryEuropean.NationAsset())); + + SelectedNation = NationsFilter[0].ItemId; + } + + public string NationFilterStyle(string nation) + { + string basic = "nation-filter-flag"; + if (SelectedNation == nation) + { + return $"{basic} filter-selected"; + } + return basic; + } + + public async Task ApplyNationFilter(MouseEventArgs e, string nationToApply) + { + SelectedNation = nationToApply; + await LoadTree(); + } + + private async Task LoadTree() + { + try + { + VehiclesLibrary = await GraphQlBackendService.GetVehiclesByNation(SelectedNation); + BuildTree(); + } + catch (System.Exception e) + { + Notifications.ReportError("Can not get data from backend", e.Message); + } + + } } }