feature/apply-filter (#18)
Co-authored-by: Maxime Adler <madler@sqli.com> Reviewed-on: #18
This commit was merged in pull request #18.
This commit is contained in:
@@ -12,19 +12,4 @@ public class GameBase : ComponentBase
|
||||
{
|
||||
NavigationManager.NavigateTo($"/Games/Detail/{GameDto.Id}");
|
||||
}
|
||||
|
||||
protected string GetFormatedStorageSpace()
|
||||
{
|
||||
if (GameDto.StorageSpace == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return GameDto.StorageSpace switch
|
||||
{
|
||||
>= 1000000 => $"{GameDto.StorageSpace / 1000000:f1} To",
|
||||
>= 1000 => $"{GameDto.StorageSpace / 1000:f1} Go",
|
||||
_ => $"{GameDto.StorageSpace:f1} Mo"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public partial class GameCreationForm
|
||||
[Parameter] public CategoriesDto? Categories { get; set; }
|
||||
[Parameter] public EventCallback OnSubmit { get; set; }
|
||||
|
||||
private GameDto GameDto = new();
|
||||
private GameDetailDto GameDto = new();
|
||||
private EditContext? EditContext;
|
||||
private readonly SelectTheme Theme = SelectTheme.Creation;
|
||||
private readonly SliderParams SliderParams = new() { Gap = 1, Min = 1, Max = 5 };
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
}
|
||||
</div>
|
||||
|
||||
<span class="storage">@GetFormatedStorageSpace()</span>
|
||||
<span class="storage">@GameHelper.GetFormatedStorageSpace(GameDto.StorageSpace)</span>
|
||||
|
||||
<div class="interest">
|
||||
<span class="value" style="@($"color: var({GameHelper.GetInterestColor(GameDto.Interest, 5)})")">
|
||||
|
||||
@@ -4,7 +4,7 @@ using GameIdeas.Shared.Dto;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Pages.Games.Components;
|
||||
|
||||
public class GameValidation : AbstractValidator<GameDto>
|
||||
public class GameValidation : AbstractValidator<GameDetailDto>
|
||||
{
|
||||
public GameValidation()
|
||||
{
|
||||
|
||||
@@ -22,5 +22,11 @@
|
||||
<SelectSearch TItem="PublisherDto" Placeholder="@ResourcesKey.Publishers" GetLabel="@(p => p.Name)"
|
||||
@bind-Values=GameFilter.Publishers @bind-Values:after=HandleValueChanged Theme="Theme" Items="Categories?.Publishers" />
|
||||
|
||||
<SelectSearch TItem="int" Placeholder="@ResourcesKey.ReleaseDate" GetLabel="@(p => p.ToString())"
|
||||
@bind-Values=GameFilter.ReleaseYears @bind-Values:after=HandleValueChanged Theme="Theme" Items="Categories?.ReleaseYears" />
|
||||
|
||||
<SelectSearch TItem="int" Placeholder="@ResourcesKey.StorageSize" GetLabel="@GetStorageSpaceLabel"
|
||||
@bind-Values=GameFilter.StorageSpaceIds @bind-Values:after=HandleValueChanged Theme="Theme" Items="@(Categories?.StorageSpaces?.Select(stor => stor.Id).ToList())" />
|
||||
|
||||
<span class="title">@ResourcesKey.LastAdd</span>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using GameIdeas.BlazorApp.Helpers;
|
||||
using GameIdeas.BlazorApp.Pages.Games.Header;
|
||||
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||
using GameIdeas.Resources;
|
||||
using GameIdeas.Shared.Dto;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
@@ -6,9 +9,9 @@ namespace GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||
|
||||
public partial class AdvancedGameFilter
|
||||
{
|
||||
[Parameter] public GameFilterDto GameFilter { get; set; } = new();
|
||||
[Parameter] public GameFilterParams GameFilter { get; set; } = new();
|
||||
[Parameter] public CategoriesDto? Categories { get; set; }
|
||||
[Parameter] public EventCallback<GameFilterDto> GameFilterChanged { get; set; }
|
||||
[Parameter] public EventCallback<GameFilterParams> GameFilterChanged { get; set; }
|
||||
|
||||
private readonly SelectTheme Theme = SelectTheme.AdvancedFilter;
|
||||
|
||||
@@ -16,4 +19,31 @@ public partial class AdvancedGameFilter
|
||||
{
|
||||
await GameFilterChanged.InvokeAsync(GameFilter);
|
||||
}
|
||||
|
||||
private string GetStorageSpaceLabel(int storageSpaceId)
|
||||
{
|
||||
var storageSpace = Categories?.StorageSpaces?.FirstOrDefault(c => c.Id == storageSpaceId)
|
||||
?? throw new ArgumentNullException(ResourcesKey.ErrorStorageSpaceLabel);
|
||||
|
||||
if (storageSpace.MinSize == null && storageSpace.MaxSize != null)
|
||||
{
|
||||
return string.Format(ResourcesKey.MinStorageSpaceFormat,
|
||||
GameHelper.GetFormatedStorageSpace(storageSpace.MaxSize));
|
||||
}
|
||||
|
||||
if (storageSpace.MinSize != null && storageSpace.MaxSize == null)
|
||||
{
|
||||
return string.Format(ResourcesKey.MaxStorageSpaceFormat,
|
||||
GameHelper.GetFormatedStorageSpace(storageSpace.MinSize));
|
||||
}
|
||||
|
||||
if (storageSpace.MinSize != null && storageSpace.MaxSize != null)
|
||||
{
|
||||
return string.Format(ResourcesKey.MinMaxStorageSpaceFormat,
|
||||
GameHelper.GetFormatedStorageSpace(storageSpace.MinSize),
|
||||
GameHelper.GetFormatedStorageSpace(storageSpace.MaxSize));
|
||||
}
|
||||
|
||||
throw new ArgumentNullException(ResourcesKey.ErrorStorageSpaceLabel);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@
|
||||
@using GameIdeas.Shared.Dto
|
||||
|
||||
<div class="form-filter">
|
||||
<Select TItem="SortPropertyDto" ValuesChanged=HandleSortPropertyClicked
|
||||
THeader="SortTypeDto" HeaderValuesChanged=HandleSortTypeClicked
|
||||
<Select TItem="SortPropertyDto" Values="[Value.SortProperty]" ValuesChanged=HandleSortPropertyClicked
|
||||
THeader="SortTypeDto" HeaderValues="[Value.SortType]" HeaderValuesChanged=HandleSortTypeClicked
|
||||
Params=SelectParams Theme="SelectTheme.Sort" >
|
||||
<div class="square-button">
|
||||
<svg class="sort-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
<div class="search-container">
|
||||
<SearchInput @bind-Text="@Value.Title"
|
||||
@bind-Text:after="HandleValueChanged"
|
||||
Placeholder="@ResourcesKey.Research" />
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,30 +1,33 @@
|
||||
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||
using GameIdeas.BlazorApp.Shared.Components.SliderRange;
|
||||
using GameIdeas.BlazorApp.Shared.Models;
|
||||
using GameIdeas.Resources;
|
||||
using GameIdeas.Shared.Dto;
|
||||
using GameIdeas.Shared.Enum;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||
|
||||
public partial class GameFilter
|
||||
{
|
||||
[Parameter] public GameFilterDto Value { get; set; } = new();
|
||||
[Parameter] public EventCallback<GameFilterDto> ValueChanged { get; set; }
|
||||
[Parameter] public GameFilterParams Value { get; set; } = new();
|
||||
[Parameter] public EventCallback<GameFilterParams> ValueChanged { get; set; }
|
||||
[Parameter] public DisplayType DisplayType { get; set; }
|
||||
[Parameter] public EventCallback<DisplayType> DisplayTypeChanged { get; set; }
|
||||
[Parameter] public CategoriesDto? Categories { get; set; }
|
||||
|
||||
|
||||
private readonly List<SortTypeDto> SortTypes = [
|
||||
new() { SortType = SortType.Ascending, Label = "Ascendant" },
|
||||
new() { SortType = SortType.Descending, Label = "Descendant" }
|
||||
public static readonly List<SortTypeDto> SortTypes = [
|
||||
new() { SortType = SortType.Ascending, Label = ResourcesKey.Ascending },
|
||||
new() { SortType = SortType.Descending, Label = ResourcesKey.Descending }
|
||||
];
|
||||
|
||||
private readonly List<SortPropertyDto> GameProperties = [
|
||||
new() { SortProperty = game => game.Title!, Label = "Titre" },
|
||||
new() { SortProperty = game => game.ReleaseDate!, Label = "Date de parution" }
|
||||
public static readonly List<SortPropertyDto> GameProperties = [
|
||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.Title), Label = ResourcesKey.Title },
|
||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.ReleaseDate), Label = ResourcesKey.ReleaseDate },
|
||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.CreationDate), Label = ResourcesKey.CreateDate },
|
||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.ModificationDate), Label = ResourcesKey.UpdateDate },
|
||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.StorageSpace), Label = ResourcesKey.StorageSize },
|
||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.Interest), Label = ResourcesKey.Interest }
|
||||
];
|
||||
|
||||
private SelectParams<SortPropertyDto, SortTypeDto> SelectParams = new();
|
||||
@@ -36,10 +39,8 @@ public partial class GameFilter
|
||||
{
|
||||
Headers = SortTypes,
|
||||
GetHeaderLabel = header => header.Label,
|
||||
DefaultHeaders = SortTypes.Where(h => h.SortType == SortType.Ascending).ToList(),
|
||||
Items = GameProperties,
|
||||
GetItemLabel = item => item.Label,
|
||||
DefaultItems = GameProperties.Where(p => p.Label == "Titre").ToList()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using GameIdeas.Shared.Dto;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||
|
||||
public class GameFilterParams
|
||||
{
|
||||
public SortTypeDto? SortType { get; set; }
|
||||
public SortPropertyDto? SortProperty { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public List<PlatformDto>? Platforms { get; set; }
|
||||
public List<PropertyDto>? Properties { get; set; }
|
||||
public List<TagDto>? Tags { get; set; }
|
||||
public List<PublisherDto>? Publishers { get; set; }
|
||||
public List<DeveloperDto>? Developers { get; set; }
|
||||
public int MinInterest { get; set; } = 1;
|
||||
public int MaxInterest { get; set; } = 5;
|
||||
public List<int>? ReleaseYears { get; set; }
|
||||
public List<int>? StorageSpaceIds { get; set; }
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
<GameHeader AddTypeChanged="HandleAddClicked">
|
||||
<GameFilter Categories="Categories"
|
||||
@bind-DisplayType=DisplayType
|
||||
@bind-Value=GameFilter />
|
||||
Value=GameFilter ValueChanged="HandleFilterChanged" />
|
||||
</GameHeader>
|
||||
|
||||
<div class="container">
|
||||
@@ -36,9 +36,9 @@
|
||||
|
||||
</div>
|
||||
|
||||
<AdvancedGameFilter @bind-GameFilter=GameFilter Categories="Categories" />
|
||||
<AdvancedGameFilter GameFilter=GameFilter GameFilterChanged="HandleFilterChanged" Categories="Categories" />
|
||||
</div>
|
||||
|
||||
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
|
||||
<GameCreationForm Categories="Categories" OnSubmit="HandleFetchDatas" />
|
||||
<GameCreationForm Categories="Categories" OnSubmit="() => HandleFetchDatas()" />
|
||||
</Popup>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||
using GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
using GameIdeas.BlazorApp.Shared.Components.Popup;
|
||||
using GameIdeas.BlazorApp.Shared.Models;
|
||||
using GameIdeas.Shared.Dto;
|
||||
using GameIdeas.Shared.Enum;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Pages.Games;
|
||||
@@ -11,17 +13,26 @@ public partial class Game
|
||||
[Inject] private IGameGateway GameGateway { get; set; } = default!;
|
||||
|
||||
private DisplayType DisplayType = DisplayType.List;
|
||||
private GameFilterDto GameFilter = new();
|
||||
private GameFilterParams GameFilter = new();
|
||||
private Popup? ManualAddPopup;
|
||||
private bool IsLoading = false;
|
||||
private CategoriesDto? Categories;
|
||||
private IEnumerable<GameDto> GamesDto = [];
|
||||
private int CurrentPage;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
CurrentPage = 1;
|
||||
GameFilter.SortType = Filter.GameFilter.SortTypes
|
||||
.First(st => st.SortType == SortType.Ascending);
|
||||
|
||||
GameFilter.SortProperty= Filter.GameFilter.GameProperties
|
||||
.First(gp => gp.PropertyName == nameof(GameIdeas.Shared.Model.Game.Title));
|
||||
|
||||
await HandleFetchDatas();
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
private void HandleAddClicked(AddType addType)
|
||||
{
|
||||
switch (addType)
|
||||
@@ -39,14 +50,16 @@ public partial class Game
|
||||
{
|
||||
ManualAddPopup?.Close();
|
||||
}
|
||||
private async Task HandleFetchDatas()
|
||||
private async Task HandleFetchDatas(bool loadCategories = true, bool displayLoader = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
IsLoading = displayLoader;
|
||||
|
||||
Categories = await GameGateway.FetchCategories();
|
||||
GamesDto = await GameGateway.FetchGames(new PaggingDto() { CurrentPage = 1, NumberPerPage = 50 });
|
||||
if (loadCategories)
|
||||
Categories = await GameGateway.FetchCategories();
|
||||
|
||||
GamesDto = await GameGateway.FetchGames(GameFilter, CurrentPage);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -57,4 +70,9 @@ public partial class Game
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
private async Task HandleFilterChanged(GameFilterParams args)
|
||||
{
|
||||
GameFilter = args;
|
||||
await HandleFetchDatas(loadCategories: false, displayLoader: false);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using GameIdeas.BlazorApp.Services;
|
||||
using GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||
using GameIdeas.BlazorApp.Services;
|
||||
using GameIdeas.BlazorApp.Shared.Constants;
|
||||
using GameIdeas.BlazorApp.Shared.Exceptions;
|
||||
using GameIdeas.Resources;
|
||||
@@ -8,7 +9,7 @@ namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
|
||||
public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
||||
{
|
||||
public async Task<int> CreateGame(GameDto game)
|
||||
public async Task<int> CreateGame(GameDetailDto game)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -34,11 +35,26 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<GameDto>> FetchGames(PaggingDto pagging)
|
||||
public async Task<IEnumerable<GameDto>> FetchGames(GameFilterParams filterParams, int currentPage)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await httpClientService.FetchDataAsync<IEnumerable<GameDto>>(Endpoints.Game.Fetch(pagging));
|
||||
GameFilterDto filter = new()
|
||||
{
|
||||
CurrentPage = currentPage,
|
||||
Title = filterParams.Title,
|
||||
MaxInterest = filterParams.MaxInterest,
|
||||
MinInterest = filterParams.MinInterest,
|
||||
StorageSpaces = filterParams.StorageSpaceIds,
|
||||
DeveloperIds = filterParams.Developers?.Select(d => d.Id ?? 0).ToList(),
|
||||
PublisherIds = filterParams.Publishers?.Select(d => d.Id ?? 0).ToList(),
|
||||
PlatformIds = filterParams.Platforms?.Select(d => d.Id ?? 0).ToList(),
|
||||
PropertyIds = filterParams.Properties?.Select(d => d.Id ?? 0).ToList(),
|
||||
ReleaseYears = filterParams.ReleaseYears,
|
||||
TagIds = filterParams.Tags?.Select(d => d.Id ?? 0).ToList(),
|
||||
};
|
||||
|
||||
var result = await httpClientService.FetchDataAsync<IEnumerable<GameDto>>(Endpoints.Game.Fetch(filter));
|
||||
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchGames);
|
||||
}
|
||||
catch (Exception)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using GameIdeas.Shared.Dto;
|
||||
using GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||
using GameIdeas.Shared.Dto;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||
|
||||
public interface IGameGateway
|
||||
{
|
||||
Task<CategoriesDto> FetchCategories();
|
||||
Task<int> CreateGame(GameDto game);
|
||||
Task<IEnumerable<GameDto>> FetchGames(PaggingDto pagging);
|
||||
Task<int> CreateGame(GameDetailDto game);
|
||||
Task<IEnumerable<GameDto>> FetchGames(GameFilterParams filter, int currentPage);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,7 @@ public partial class GameHeader : ComponentBase
|
||||
SelectParams = new()
|
||||
{
|
||||
Items = AddTypes.ToList(),
|
||||
GetItemLabel = item => item.Value,
|
||||
DefaultItems = []
|
||||
GetItemLabel = item => item.Value
|
||||
};
|
||||
|
||||
base.OnInitialized();
|
||||
|
||||
Reference in New Issue
Block a user