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
|
||||
|
||||
<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">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -15,17 +16,18 @@ public partial class GameFilter
|
||||
[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() { PropertyName = nameof(GameIdeas.Shared.Model.Game.Title), Label = "Titre" },
|
||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.ReleaseDate), Label = "Date de parution" },
|
||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.StorageSpace), Label = "Espace de stockage" },
|
||||
new() { PropertyName = nameof(GameIdeas.Shared.Model.Game.Interest), Label = "Inter<65>t" }
|
||||
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();
|
||||
@@ -37,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.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.Models;
|
||||
using GameIdeas.Shared.Dto;
|
||||
using GameIdeas.Shared.Enum;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Pages.Games;
|
||||
@@ -21,6 +22,12 @@ public partial class Game
|
||||
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(true);
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
public class SelectParams<TItem, THeader>
|
||||
{
|
||||
public List<TItem> Items { get; set; } = [];
|
||||
public List<TItem> DefaultItems { get; set; } = [];
|
||||
public Func<TItem, string> GetItemLabel { get; set; } = _ => string.Empty;
|
||||
public List<THeader> Headers { get; set; } = [];
|
||||
public List<THeader> DefaultHeaders { get; set; } = [];
|
||||
public Func<THeader, string> GetHeaderLabel { get; set; } = _ => string.Empty;
|
||||
public Func<string, TItem>? AddItem { get; set; }
|
||||
|
||||
|
||||
@@ -37,16 +37,6 @@ public partial class Select<TItem, THeader>
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
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()
|
||||
|
||||
@@ -22,6 +22,8 @@ public class Translations (TranslationService translationService)
|
||||
public string StorageSizeMo => translationService.Translate(nameof(StorageSizeMo));
|
||||
public string LastModification => translationService.Translate(nameof(LastModification));
|
||||
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 Interest => translationService.Translate(nameof(Interest));
|
||||
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 Unknown => translationService.Translate(nameof(Unknown));
|
||||
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
|
||||
@@ -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 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 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 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.");
|
||||
@@ -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 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 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",
|
||||
"LastModification": "Dernière modifications",
|
||||
"ReleaseDate": "Date de parution",
|
||||
"CreateDate": "Date de création",
|
||||
"UpdateDate": "Date de modification",
|
||||
"Title": "Titre",
|
||||
"Interest": "Intérêt",
|
||||
"Properties": "Propriétés",
|
||||
@@ -35,6 +37,7 @@
|
||||
"InvalidTitle": "Le titre est incorrect",
|
||||
"InvalidInterest": "L'interêt est incorrect",
|
||||
"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)
|
||||
.ToListAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(filter.Title))
|
||||
{
|
||||
games = ApplySearchGameFilter(games, filter).ToList();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (filter.Title != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (filter.SortType != null && filter.SortPropertyName != null)
|
||||
{
|
||||
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)
|
||||
{
|
||||
query = query.OrderBy(lambda.Compile()).AsQueryable();
|
||||
query = Queryable.OrderBy(query, lambda);
|
||||
}
|
||||
else
|
||||
{
|
||||
query = query.OrderByDescending(lambda.Compile()).AsQueryable();
|
||||
query = Queryable.OrderByDescending(query, lambda);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
.Select(k => k.Trim())
|
||||
.ToArray();
|
||||
.ToArray() ?? [];
|
||||
|
||||
query = query
|
||||
.Where(game => keywords.All(
|
||||
@@ -92,7 +99,6 @@ public class GameReadService(GameIdeasContext context, IMapper mapper) : IGameRe
|
||||
))
|
||||
.ThenBy(game => game.Title.Length);
|
||||
|
||||
return;
|
||||
}
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user