Apply sort and game filter
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 1m2s
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 1m2s
This commit is contained in:
@@ -7,8 +7,8 @@
|
|||||||
@using GameIdeas.Shared.Dto
|
@using GameIdeas.Shared.Dto
|
||||||
|
|
||||||
<div class="form-filter">
|
<div class="form-filter">
|
||||||
<Select TItem="SortPropertyDto" ValuesChanged=HandleSortPropertyClicked
|
<Select TItem="SortPropertyDto" Values="[Value.SortProperty]" ValuesChanged=HandleSortPropertyClicked
|
||||||
THeader="SortTypeDto" HeaderValuesChanged=HandleSortTypeClicked
|
THeader="SortTypeDto" HeaderValues="[Value.SortType]" HeaderValuesChanged=HandleSortTypeClicked
|
||||||
Params=SelectParams Theme="SelectTheme.Sort" >
|
Params=SelectParams Theme="SelectTheme.Sort" >
|
||||||
<div class="square-button">
|
<div class="square-button">
|
||||||
<svg class="sort-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
<svg class="sort-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||||
using GameIdeas.BlazorApp.Shared.Components.SliderRange;
|
using GameIdeas.BlazorApp.Shared.Components.SliderRange;
|
||||||
using GameIdeas.BlazorApp.Shared.Models;
|
using GameIdeas.BlazorApp.Shared.Models;
|
||||||
|
using GameIdeas.Resources;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using GameIdeas.Shared.Enum;
|
using GameIdeas.Shared.Enum;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
@@ -15,17 +16,18 @@ public partial class GameFilter
|
|||||||
[Parameter] public EventCallback<DisplayType> DisplayTypeChanged { get; set; }
|
[Parameter] public EventCallback<DisplayType> DisplayTypeChanged { get; set; }
|
||||||
[Parameter] public CategoriesDto? Categories { get; set; }
|
[Parameter] public CategoriesDto? Categories { get; set; }
|
||||||
|
|
||||||
|
public static readonly List<SortTypeDto> SortTypes = [
|
||||||
private readonly List<SortTypeDto> SortTypes = [
|
new() { SortType = SortType.Ascending, Label = ResourcesKey.Ascending },
|
||||||
new() { SortType = SortType.Ascending, Label = "Ascendant" },
|
new() { SortType = SortType.Descending, Label = ResourcesKey.Descending }
|
||||||
new() { SortType = SortType.Descending, Label = "Descendant" }
|
|
||||||
];
|
];
|
||||||
|
|
||||||
private readonly List<SortPropertyDto> GameProperties = [
|
public static readonly List<SortPropertyDto> GameProperties = [
|
||||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.Title), Label = "Titre" },
|
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.Title), Label = ResourcesKey.Title },
|
||||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.ReleaseDate), Label = "Date de parution" },
|
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.ReleaseDate), Label = ResourcesKey.ReleaseDate },
|
||||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.StorageSpace), Label = "Espace de stockage" },
|
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.CreationDate), Label = ResourcesKey.CreateDate },
|
||||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.Interest), Label = "Inter<65>t" }
|
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();
|
private SelectParams<SortPropertyDto, SortTypeDto> SelectParams = new();
|
||||||
@@ -37,10 +39,8 @@ public partial class GameFilter
|
|||||||
{
|
{
|
||||||
Headers = SortTypes,
|
Headers = SortTypes,
|
||||||
GetHeaderLabel = header => header.Label,
|
GetHeaderLabel = header => header.Label,
|
||||||
DefaultHeaders = SortTypes.Where(h => h.SortType == SortType.Ascending).ToList(),
|
|
||||||
Items = GameProperties,
|
Items = GameProperties,
|
||||||
GetItemLabel = item => item.Label,
|
GetItemLabel = item => item.Label,
|
||||||
DefaultItems = GameProperties.Where(p => p.PropertyName == nameof(GameDetailDto.Title)).ToList()
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using GameIdeas.BlazorApp.Pages.Games.Gateways;
|
|||||||
using GameIdeas.BlazorApp.Shared.Components.Popup;
|
using GameIdeas.BlazorApp.Shared.Components.Popup;
|
||||||
using GameIdeas.BlazorApp.Shared.Models;
|
using GameIdeas.BlazorApp.Shared.Models;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
|
using GameIdeas.Shared.Enum;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Pages.Games;
|
namespace GameIdeas.BlazorApp.Pages.Games;
|
||||||
@@ -21,6 +22,12 @@ public partial class Game
|
|||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
CurrentPage = 1;
|
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(true);
|
await HandleFetchDatas(true);
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ public partial class GameHeader : ComponentBase
|
|||||||
SelectParams = new()
|
SelectParams = new()
|
||||||
{
|
{
|
||||||
Items = AddTypes.ToList(),
|
Items = AddTypes.ToList(),
|
||||||
GetItemLabel = item => item.Value,
|
GetItemLabel = item => item.Value
|
||||||
DefaultItems = []
|
|
||||||
};
|
};
|
||||||
|
|
||||||
base.OnInitialized();
|
base.OnInitialized();
|
||||||
|
|||||||
@@ -3,10 +3,8 @@
|
|||||||
public class SelectParams<TItem, THeader>
|
public class SelectParams<TItem, THeader>
|
||||||
{
|
{
|
||||||
public List<TItem> Items { get; set; } = [];
|
public List<TItem> Items { get; set; } = [];
|
||||||
public List<TItem> DefaultItems { get; set; } = [];
|
|
||||||
public Func<TItem, string> GetItemLabel { get; set; } = _ => string.Empty;
|
public Func<TItem, string> GetItemLabel { get; set; } = _ => string.Empty;
|
||||||
public List<THeader> Headers { get; set; } = [];
|
public List<THeader> Headers { get; set; } = [];
|
||||||
public List<THeader> DefaultHeaders { get; set; } = [];
|
|
||||||
public Func<THeader, string> GetHeaderLabel { get; set; } = _ => string.Empty;
|
public Func<THeader, string> GetHeaderLabel { get; set; } = _ => string.Empty;
|
||||||
public Func<string, TItem>? AddItem { get; set; }
|
public Func<string, TItem>? AddItem { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -37,16 +37,6 @@ public partial class Select<TItem, THeader>
|
|||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
QuickAddEditContext = new EditContext(AddLabel);
|
QuickAddEditContext = new EditContext(AddLabel);
|
||||||
|
|
||||||
if (Params.DefaultItems.Count != 0)
|
|
||||||
{
|
|
||||||
Values.AddRange(Params.DefaultItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Params.DefaultHeaders.Count != 0)
|
|
||||||
{
|
|
||||||
HeaderValues.AddRange(Params.DefaultHeaders);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleButtonClicked()
|
private void HandleButtonClicked()
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public class Translations (TranslationService translationService)
|
|||||||
public string StorageSizeMo => translationService.Translate(nameof(StorageSizeMo));
|
public string StorageSizeMo => translationService.Translate(nameof(StorageSizeMo));
|
||||||
public string LastModification => translationService.Translate(nameof(LastModification));
|
public string LastModification => translationService.Translate(nameof(LastModification));
|
||||||
public string ReleaseDate => translationService.Translate(nameof(ReleaseDate));
|
public string ReleaseDate => translationService.Translate(nameof(ReleaseDate));
|
||||||
|
public string CreateDate => translationService.Translate(nameof(CreateDate));
|
||||||
|
public string UpdateDate => translationService.Translate(nameof(UpdateDate));
|
||||||
public string Title => translationService.Translate(nameof(Title));
|
public string Title => translationService.Translate(nameof(Title));
|
||||||
public string Interest => translationService.Translate(nameof(Interest));
|
public string Interest => translationService.Translate(nameof(Interest));
|
||||||
public string Properties => translationService.Translate(nameof(Properties));
|
public string Properties => translationService.Translate(nameof(Properties));
|
||||||
@@ -40,6 +42,8 @@ public class Translations (TranslationService translationService)
|
|||||||
public string InvalidInterest => translationService.Translate(nameof(InvalidInterest));
|
public string InvalidInterest => translationService.Translate(nameof(InvalidInterest));
|
||||||
public string Unknown => translationService.Translate(nameof(Unknown));
|
public string Unknown => translationService.Translate(nameof(Unknown));
|
||||||
public string ErrorFetchGames => translationService.Translate(nameof(ErrorFetchGames));
|
public string ErrorFetchGames => translationService.Translate(nameof(ErrorFetchGames));
|
||||||
|
public string Ascending => translationService.Translate(nameof(Ascending));
|
||||||
|
public string Descending => translationService.Translate(nameof(Descending));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ResourcesKey
|
public static class ResourcesKey
|
||||||
@@ -70,6 +74,8 @@ public static class ResourcesKey
|
|||||||
public static string StorageSizeMo => _instance?.StorageSizeMo ?? throw new InvalidOperationException("ResourcesKey.StorageSizeMo is not initialized.");
|
public static string StorageSizeMo => _instance?.StorageSizeMo ?? throw new InvalidOperationException("ResourcesKey.StorageSizeMo is not initialized.");
|
||||||
public static string LastModification => _instance?.LastModification ?? throw new InvalidOperationException("ResourcesKey.LastModification is not initialized.");
|
public static string LastModification => _instance?.LastModification ?? throw new InvalidOperationException("ResourcesKey.LastModification is not initialized.");
|
||||||
public static string ReleaseDate => _instance?.ReleaseDate ?? throw new InvalidOperationException("ResourcesKey.ReleaseDate is not initialized.");
|
public static string ReleaseDate => _instance?.ReleaseDate ?? throw new InvalidOperationException("ResourcesKey.ReleaseDate is not initialized.");
|
||||||
|
public static string CreateDate => _instance?.CreateDate ?? throw new InvalidOperationException("ResourcesKey.CreateDate is not initialized.");
|
||||||
|
public static string UpdateDate => _instance?.UpdateDate ?? throw new InvalidOperationException("ResourcesKey.UpdateDate is not initialized.");
|
||||||
public static string Title => _instance?.Title ?? throw new InvalidOperationException("ResourcesKey.Title is not initialized.");
|
public static string Title => _instance?.Title ?? throw new InvalidOperationException("ResourcesKey.Title is not initialized.");
|
||||||
public static string Interest => _instance?.Interest ?? throw new InvalidOperationException("ResourcesKey.Interest is not initialized.");
|
public static string Interest => _instance?.Interest ?? throw new InvalidOperationException("ResourcesKey.Interest is not initialized.");
|
||||||
public static string Properties => _instance?.Properties ?? throw new InvalidOperationException("ResourcesKey.Properties is not initialized.");
|
public static string Properties => _instance?.Properties ?? throw new InvalidOperationException("ResourcesKey.Properties is not initialized.");
|
||||||
@@ -88,4 +94,6 @@ public static class ResourcesKey
|
|||||||
public static string InvalidInterest => _instance?.InvalidInterest ?? throw new InvalidOperationException("ResourcesKey.InvalidInterest is not initialized.");
|
public static string InvalidInterest => _instance?.InvalidInterest ?? throw new InvalidOperationException("ResourcesKey.InvalidInterest is not initialized.");
|
||||||
public static string Unknown => _instance?.Unknown ?? throw new InvalidOperationException("ResourcesKey.Unknown is not initialized.");
|
public static string Unknown => _instance?.Unknown ?? throw new InvalidOperationException("ResourcesKey.Unknown is not initialized.");
|
||||||
public static string ErrorFetchGames => _instance?.ErrorFetchGames ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchGames is not initialized.");
|
public static string ErrorFetchGames => _instance?.ErrorFetchGames ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchGames is not initialized.");
|
||||||
|
public static string Ascending => _instance?.Ascending ?? throw new InvalidOperationException("ResourcesKey.Ascending is not initialized.");
|
||||||
|
public static string Descending => _instance?.Descending ?? throw new InvalidOperationException("ResourcesKey.Descending is not initialized.");
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
"StorageSizeMo": "Taille d'espace en Mo",
|
"StorageSizeMo": "Taille d'espace en Mo",
|
||||||
"LastModification": "Dernière modifications",
|
"LastModification": "Dernière modifications",
|
||||||
"ReleaseDate": "Date de parution",
|
"ReleaseDate": "Date de parution",
|
||||||
|
"CreateDate": "Date de création",
|
||||||
|
"UpdateDate": "Date de modification",
|
||||||
"Title": "Titre",
|
"Title": "Titre",
|
||||||
"Interest": "Intérêt",
|
"Interest": "Intérêt",
|
||||||
"Properties": "Propriétés",
|
"Properties": "Propriétés",
|
||||||
@@ -35,6 +37,7 @@
|
|||||||
"InvalidTitle": "Le titre est incorrect",
|
"InvalidTitle": "Le titre est incorrect",
|
||||||
"InvalidInterest": "L'interêt est incorrect",
|
"InvalidInterest": "L'interêt est incorrect",
|
||||||
"Unknown": "Inconnu",
|
"Unknown": "Inconnu",
|
||||||
"ErrorFetchGames": "Erreur lors de la récupération des jeux"
|
"ErrorFetchGames": "Erreur lors de la récupération des jeux",
|
||||||
|
"Ascending": "Ascendant",
|
||||||
|
"Descending": "Descendant"
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,11 @@ public class GameReadService(GameIdeasContext context, IMapper mapper) : IGameRe
|
|||||||
.Take(GlobalConstants.NUMBER_PER_PAGE)
|
.Take(GlobalConstants.NUMBER_PER_PAGE)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(filter.Title))
|
||||||
|
{
|
||||||
|
games = ApplySearchGameFilter(games, filter).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
return mapper.Map<IEnumerable<GameDto>>(games);
|
return mapper.Map<IEnumerable<GameDto>>(games);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,11 +56,6 @@ public class GameReadService(GameIdeasContext context, IMapper mapper) : IGameRe
|
|||||||
|
|
||||||
private static void ApplyOrder(ref IQueryable<Game> query, GameFilterDto filter)
|
private static void ApplyOrder(ref IQueryable<Game> query, GameFilterDto filter)
|
||||||
{
|
{
|
||||||
if (filter.Title != null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.SortType != null && filter.SortPropertyName != null)
|
if (filter.SortType != null && filter.SortPropertyName != null)
|
||||||
{
|
{
|
||||||
var param = Expression.Parameter(typeof(Game), "x");
|
var param = Expression.Parameter(typeof(Game), "x");
|
||||||
@@ -65,23 +65,30 @@ public class GameReadService(GameIdeasContext context, IMapper mapper) : IGameRe
|
|||||||
|
|
||||||
if (filter.SortType == Shared.Enum.SortType.Ascending)
|
if (filter.SortType == Shared.Enum.SortType.Ascending)
|
||||||
{
|
{
|
||||||
query = query.OrderBy(lambda.Compile()).AsQueryable();
|
query = Queryable.OrderBy(query, lambda);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
query = query.OrderByDescending(lambda.Compile()).AsQueryable();
|
query = Queryable.OrderByDescending(query, lambda);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ApplyFilter(ref IQueryable<Game> query, GameFilterDto filter)
|
private static void ApplyFilter(ref IQueryable<Game> query, GameFilterDto filter)
|
||||||
{
|
{
|
||||||
if (filter.Title != null)
|
if (filter.PlatformIds != null)
|
||||||
{
|
{
|
||||||
var keywords = filter.Title
|
query = query.Where(game => filter.PlatformIds.All(plat =>
|
||||||
|
game.GamePlatforms.Any(gp => gp.PlatformId == plat)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<Game> ApplySearchGameFilter(IEnumerable<Game> query, GameFilterDto filter)
|
||||||
|
{
|
||||||
|
var keywords = filter.Title?
|
||||||
.Split([' '], StringSplitOptions.RemoveEmptyEntries)
|
.Split([' '], StringSplitOptions.RemoveEmptyEntries)
|
||||||
.Select(k => k.Trim())
|
.Select(k => k.Trim())
|
||||||
.ToArray();
|
.ToArray() ?? [];
|
||||||
|
|
||||||
query = query
|
query = query
|
||||||
.Where(game => keywords.All(
|
.Where(game => keywords.All(
|
||||||
@@ -92,7 +99,6 @@ public class GameReadService(GameIdeasContext context, IMapper mapper) : IGameRe
|
|||||||
))
|
))
|
||||||
.ThenBy(game => game.Title.Length);
|
.ThenBy(game => game.Title.Length);
|
||||||
|
|
||||||
return;
|
return query;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user