4 Commits

Author SHA1 Message Date
77f3558f44 Fix merge
All checks were successful
Game Ideas build for PR / build_test (pull_request) Successful in 51s
2025-05-06 22:09:55 +02:00
ad43502507 Adjust header size
All checks were successful
Game Ideas build for PR / build_test (pull_request) Successful in 55s
2025-05-06 22:07:53 +02:00
58588012ae Update style
All checks were successful
Game Ideas build for PR / build_test (pull_request) Successful in 57s
2025-05-06 21:50:58 +02:00
7c0adb1c58 Add read more description 2025-05-06 01:15:52 +02:00
81 changed files with 488 additions and 1048 deletions

View File

@@ -20,20 +20,6 @@ public static class GameHelper
game.CreationDate = DateTime.Now;
}
public static void UpdateTrackingDto(GameDetailDto game, AuthenticationState authState)
{
if (authState == null)
{
throw new ArgumentNullException(nameof(authState), "Authentication state missing");
}
var userId = authState.User.FindFirstValue(ClaimTypes.Sid)
?? throw new ArgumentNullException(nameof(authState), "user state missing");
game.ModificationUserId = userId;
game.ModificationDate = DateTime.Now;
}
public static string GetInterestColor(int interest, int maxInterest)
{
int firstTier = (int)Math.Floor(0.33 * maxInterest);

View File

@@ -4,3 +4,9 @@
<div class="page">
@Body
</div>
<div class="background">
<span class="orb red"></span>
<span class="orb blue"></span>
<span class="orb green"></span>
</div>

View File

@@ -3,3 +3,46 @@
flex-direction: column;
height: 100%;
}
.orb {
position: absolute;
border-radius: 100%;
z-index: var(--index-orb);
}
.green {
width: 80vh;
height: 80vh;
top: -20vh;
background: #315941;
filter: blur(30vh);
}
.blue {
width: 80vw;
height: 80vw;
left: 10vw;
top: 50vh;
background: #3A4156;
filter: blur(30vh);
}
.red {
width: 100vh;
height: 100vh;
left: 60vw;
top: -40vh;
background: #593533;
filter: blur(30vh);
}
.background {
height: 100vh;
width: 100vw;
background: var(--background);
position: fixed;
overflow: hidden;
top: 0;
left: 0;
z-index: var(--index-background);
}

View File

@@ -1,22 +1,14 @@
@page "/Detail/{GameId:int}"
@using GameIdeas.BlazorApp.Helpers
@using GameIdeas.BlazorApp.Pages.Games.Components
@using GameIdeas.BlazorApp.Shared.Components
@using GameIdeas.BlazorApp.Shared.Components.ButtonAdd
@using GameIdeas.BlazorApp.Shared.Components.Header
@using GameIdeas.BlazorApp.Shared.Components.Interest
@using GameIdeas.BlazorApp.Shared.Components.Popup
@using GameIdeas.BlazorApp.Shared.Components.ReadMore
@using GameIdeas.BlazorApp.Shared.Constants
@using GameIdeas.Shared.Constants
@inherits GameBaseComponent
@layout MainLayout
<HeaderGameIdeas>
<div class="button">
<ButtonAdd AddTypeChanged="HandleAddClicked" />
</div>
</HeaderGameIdeas>
<div class="detail-container">
@@ -106,7 +98,3 @@
<div class="section">
</div>
</div>
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
<GameCreationForm Categories="Categories" OnSubmit="HandleSubmitNewGame" />
</Popup>

View File

@@ -1,47 +1,19 @@
using GameIdeas.BlazorApp.Shared.Components;
using GameIdeas.BlazorApp.Shared.Exceptions;
using GameIdeas.Resources;
using GameIdeas.BlazorApp.Pages.Games.Gateways;
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components;
using System.Linq.Expressions;
namespace GameIdeas.BlazorApp.Pages.Detail;
public partial class GameDetail : GameBaseComponent
public partial class GameDetail
{
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
[Inject] private IGameGateway GameGateway { get; set; } = default!;
[Parameter] public int GameId { get; set; }
private GameDetailDto Game = new();
protected override async Task OnInitializedAsync()
{
await FetchGameDetail();
Game = await GameGateway.GetGameById(GameId);
await base.OnInitializedAsync();
}
private void HandleSubmitNewGame()
{
NavigationManager.NavigateTo("/Games");
}
private async Task FetchGameDetail()
{
try
{
IsLoading = true;
StateHasChanged();
Game = await GameGateway.GetGameById(GameId);
}
catch (Exception)
{
throw new FetchGameDetailException(ResourcesKey.ErrorFetchDetail);
}
finally
{
IsLoading = false;
StateHasChanged();
}
}
}

View File

@@ -90,12 +90,6 @@
background: var(--input-selected);
}
.button {
display: flex;
width: 100%;
justify-content: end;
}
@media screen and (max-width: 1000px) {
.section {
padding: 20px;

View File

@@ -1,8 +0,0 @@
namespace GameIdeas.BlazorApp.Pages.Games.Components;
public enum DetailOptions
{
Detail,
Edit,
Delete
}

View File

@@ -1,7 +1,4 @@
using GameIdeas.BlazorApp.Shared.Components.Select;
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.Resources;
using GameIdeas.Shared.Dto;
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components;
namespace GameIdeas.BlazorApp.Pages.Games.Components;
@@ -9,51 +6,10 @@ namespace GameIdeas.BlazorApp.Pages.Games.Components;
public class GameBase : ComponentBase
{
[Parameter] public GameDto GameDto { get; set; } = new();
[Parameter] public EventCallback<GameDto> OnDelete { get; set; } = new();
[Parameter] public EventCallback<GameDto> OnEdit { get; set; } = new();
[Inject] public NavigationManager NavigationManager { get; set; } = default!;
protected SelectParams<DetailOptions, object> SelectParams = default!;
protected Select<DetailOptions, object>? SelectOption;
protected override void OnInitialized()
protected void HandleDetailClicked()
{
SelectParams = new()
{
Items = [DetailOptions.Detail, DetailOptions.Edit, DetailOptions.Delete],
GetItemLabel = GetDetailOptionsLabel
};
}
protected async Task HandlerSelectValuesChanged(IEnumerable<DetailOptions> detailOptions)
{
var option = detailOptions.First();
switch (option)
{
case DetailOptions.Detail:
NavigationManager.NavigateTo($"/Detail/{GameDto.Id}");
break;
case DetailOptions.Edit:
await OnEdit.InvokeAsync(GameDto);
break;
case DetailOptions.Delete:
await OnDelete.InvokeAsync(GameDto);
break;
default:
break;
}
SelectOption?.Close();
}
private string GetDetailOptionsLabel(DetailOptions options)
{
return options switch
{
DetailOptions.Detail => ResourcesKey.Detail,
DetailOptions.Edit => ResourcesKey.Edit,
DetailOptions.Delete => ResourcesKey.Delete,
_ => ResourcesKey.Unknown
};
NavigationManager.NavigateTo($"/Games/Detail/{GameDto.Id}");
}
}

View File

@@ -24,13 +24,13 @@
<div class="input-game">
<div class="label">@ResourcesKey.Developer :</div>
<SelectSearch TItem="DeveloperDto" Theme="Theme" GetLabel="@(i => i.Name)" QuickAdd=true
Items="Categories?.Developers" ValuesChanged="HandleDeveloperChanged" Values="@(GameDto.Developer != null ? [GameDto.Developer] : [])"
Items="Categories?.Developers" ValuesChanged="HandleDeveloperChanged"
AddItem="@(str => new DeveloperDto() { Name = str })" SelectType="SelectType.Single" />
</div>
<div class="input-game">
<div class="label">@ResourcesKey.Publisher :</div>
<SelectSearch TItem="PublisherDto" Theme="Theme" GetLabel="@(i => i.Name)" QuickAdd=true
Items="Categories?.Publishers" ValuesChanged="HandlePublisherChanged" Values="@(GameDto.Publisher != null ? [GameDto.Publisher] : [])"
Items="Categories?.Publishers" ValuesChanged="HandlePublisherChanged"
AddItem="@(str => new PublisherDto() { Name = str })" SelectType="SelectType.Single" />
</div>
</div>

View File

@@ -3,13 +3,12 @@ using GameIdeas.BlazorApp.Pages.Games.Gateways;
using GameIdeas.BlazorApp.Shared.Components.Popup;
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.BlazorApp.Shared.Components.Slider;
using GameIdeas.BlazorApp.Shared.Exceptions;
using GameIdeas.Resources;
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.JSInterop;
using System.Security.Claims;
namespace GameIdeas.BlazorApp.Pages.Games.Components;
@@ -21,7 +20,6 @@ public partial class GameCreationForm
[CascadingParameter] private Popup? Popup { get; set; }
[Parameter] public CategoriesDto? Categories { get; set; }
[Parameter] public EventCallback OnSubmit { get; set; }
[Parameter] public EventCallback OnRender { get; set; }
private GameDetailDto GameDto = new();
private EditContext? EditContext;
@@ -29,19 +27,15 @@ public partial class GameCreationForm
private readonly SliderParams SliderParams = new() { Gap = 1, Min = 1, Max = 5 };
private bool IsLoading = false;
protected override void OnInitialized()
protected override async Task OnInitializedAsync()
{
EditContext = new(GameDto);
base.OnInitialized();
await base.OnInitializedAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await Js.InvokeVoidAsync("resizeGameForm");
if (firstRender)
{
await OnRender.InvokeAsync();
}
}
private void HandleOnCancel()
@@ -59,24 +53,16 @@ public partial class GameCreationForm
try
{
IsLoading = true;
StateHasChanged();
int gameId;
var authState = await AuthenticationState.GetAuthenticationStateAsync();
GameHelper.WriteTrackingDto(GameDto, authState);
if (GameDto.Id != null)
{
gameId = await GameGateway.UpdateGame(GameDto);
}
else
{
gameId = await GameGateway.CreateGame(GameDto);
}
var gameId = await GameGateway.CreateGame(GameDto);
if (gameId == 0)
if (gameId != 0)
{
throw new GameCreationException(ResourcesKey.ErrorCreateGame);
Popup?.Close();
await OnSubmit.InvokeAsync();
}
}
catch (Exception)
@@ -88,40 +74,13 @@ public partial class GameCreationForm
IsLoading = false;
StateHasChanged();
}
Popup?.Close();
await OnSubmit.InvokeAsync();
}
private void HandlePublisherChanged(List<PublisherDto> pubs)
{
GameDto.Publisher = pubs.FirstOrDefault();
}
private void HandleDeveloperChanged(List<DeveloperDto> devs)
{
GameDto.Developer = devs.FirstOrDefault();
}
public async Task SetGameToUpdateAsync(int gameId)
{
try
{
IsLoading = true;
StateHasChanged();
GameDto = await GameGateway.GetGameById(gameId);
}
catch (Exception)
{
throw new FetchGameDetailException(ResourcesKey.ErrorFetchDetail);
}
finally
{
IsLoading = false;
EditContext = new(GameDto);
StateHasChanged();
}
}
}

View File

@@ -34,7 +34,6 @@
grid-column: 2;
box-sizing: border-box;
color: var(--white);
padding: 0 8px;
}
::deep input[type="date"]::-webkit-calendar-picker-indicator {
@@ -119,20 +118,3 @@
.buttons button:hover {
background: var(--violet-selected);
}
@media screen and (max-width: 400px) {
.input-game {
grid-template-columns: auto 1fr;
}
#label-description {
width: auto !important;
}
}
@media screen and (max-width: 700px) {
.game-form {
flex-direction: column;
gap: 8px;
}
}

View File

@@ -1,12 +1,10 @@
@using GameIdeas.BlazorApp.Helpers
@using GameIdeas.BlazorApp.Shared.Components.Interest
@using GameIdeas.BlazorApp.Shared.Components.Select
@using GameIdeas.BlazorApp.Shared.Components.Select.Models
@using GameIdeas.BlazorApp.Shared.Constants
@inherits GameBase
<div class="row">
<img class="icon" src="icon.png" />
<img class="icon" src="~/icon.png" />
<a class="title" href="@($"/Detail/{GameDto.Id}")">@GameDto.Title</a>
@@ -35,8 +33,5 @@
<Interest Value="GameDto.Interest" />
<Select @ref="SelectOption" TItem="DetailOptions" THeader="object" Type="SelectType.Single" Theme="SelectTheme.RowOption"
Params="SelectParams" ValuesChanged="HandlerSelectValuesChanged">
@Icons.Triangle
</Select>
<button class="detail">@Icons.Triangle</button>
</div>

View File

@@ -8,6 +8,7 @@
box-shadow: var(--drop-shadow);
border-radius: var(--big-radius);
align-items: center;
overflow: hidden;
}
.row > * {
@@ -39,7 +40,6 @@
}
.release-date, .storage {
display: block;
color: rgb(184, 184, 184);
}
@@ -68,37 +68,21 @@
text-decoration: underline;
}
::deep .button {
width: fit-content;
transform: rotate(-90deg);
transition: transform 0.2s ease-in-out;
justify-self: center;
.detail {
transform: scale(0.6, 1) rotate(-90deg);
background: none;
border: none;
outline: none;
cursor: pointer;
}
::deep .button svg {
::deep .detail svg {
fill: var(--white);
height: 20px;
width: 20px;
transform: scale(1, 0.6);
}
::deep .button:hover, ::deep .button.selected {
transform: translate(-4px, 2px);
}
@media screen and (max-width: 700px) {
.release-date, .tags, .storage {
display: none;
}
.row {
grid-template-columns: auto 3fr 3fr 30px 30px;
}
}
@media screen and (min-width: 700px) and (max-width: 1000px) {
@media screen and (max-width: 1000px) {
.row {
grid-template-columns: auto 3fr 2fr 3fr 30px 30px;
grid-template-columns: 48px 3fr 2fr 3fr 30px 30px;
}
.tags, .storage {

View File

@@ -97,3 +97,15 @@
display: none;
}
}
@keyframes loading {
0% {
background: rgb(255, 255, 255, 0.05);
}
50% {
background: rgb(255, 255, 255, 0.2);
}
100% {
background: rgb(255, 255, 255, 0.05);
}
}

View File

@@ -4,8 +4,6 @@
@using GameIdeas.BlazorApp.Shared.Constants
@using GameIdeas.Shared.Dto
<NavigationLock OnBeforeInternalNavigation="HandleLocationChanged" />
<div class="advanced-filter-container" style="@(ExpandedFilter ? "display: flex" : "")">
<span class="title">@ResourcesKey.Filters</span>
@@ -29,15 +27,15 @@
<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" OrderBy="@(item => item.ToString())"
<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>
<button type="button" class="open-filter" @onclick=HandleExpandFilterAsync>
<button type="button" class="open-filter" @onclick=HandleExpandFilter>
@Icons.Filter
</button>
<BackdropFilter @ref="BackdropFilter" OnClick="HandleBackdropFilterClickedAsync" CloseOnClick="true"
<BackdropFilter @ref="BackdropFilter" OnClick="HandleBackdropFilterClicked" CloseOnClick="true"
AllowBodyScroll="false" Color="BackdropFilterColor.Overlay" />

View File

@@ -4,7 +4,6 @@ using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.Resources;
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Routing;
namespace GameIdeas.BlazorApp.Pages.Games.Filter;
@@ -49,24 +48,13 @@ public partial class AdvancedGameFilter
throw new ArgumentNullException(ResourcesKey.ErrorStorageSpaceLabel);
}
private void HandleExpandFilterAsync(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
private void HandleExpandFilter(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
{
ExpandedFilter = true;
BackdropFilter?.Show();
}
private void HandleBackdropFilterClickedAsync()
private void HandleBackdropFilterClicked()
{
ExpandedFilter = false;
}
private void HandleLocationChanged(LocationChangingContext locationContext)
{
if (ExpandedFilter)
{
ExpandedFilter = false;
BackdropFilter?.Hide();
locationContext.PreventNavigation();
}
}
}

View File

@@ -1,13 +1,12 @@
@page "/Games"
@page "/"
@using GameIdeas.BlazorApp.Pages.Games.Components
@using GameIdeas.BlazorApp.Pages.Games.Filter
@using GameIdeas.BlazorApp.Shared.Components
@using GameIdeas.BlazorApp.Shared.Components.ButtonAdd
@using GameIdeas.BlazorApp.Shared.Components.Header
@using GameIdeas.BlazorApp.Shared.Components.Popup
@using GameIdeas.BlazorApp.Shared.Components.Popup.Components
@using GameIdeas.Resources
@inherits GameBaseComponent
@layout MainLayout
<PageTitle>@ResourcesKey.GamesIdeas</PageTitle>
@@ -23,22 +22,12 @@
<div class="content">
@if (!IsLoading)
{
@if (GamesDto.NumberOfGames != 0)
@foreach (var game in GamesDto)
{
<div class="games-number">@string.Format(ResourcesKey.GamesNumberFormat, GamesDto.NumberOfGames)</div>
@foreach (var game in GamesDto.Games)
{
<GameRow GameDto="game" OnDelete="HandleDeleteGame" OnEdit="HandleEditGame" />
<GameRow GameDto="game" />
}
}
else
{
<div class="no-games">@ResourcesKey.NoGames</div>
}
}
else
{
@for (int i = 0; i < 20; i++)
{
@@ -52,9 +41,5 @@
</div>
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
<GameCreationForm @ref="CreationForm" Categories="Categories" OnSubmit="HandleOnSubmitGame" OnRender="HandleRenderCreationForm" />
</Popup>
<Popup @ref=DeletePopup Closable=false>
<ConfirmDelete OnCancel="HandleCancelPopupClicked" OnConfirm="HandleRemoveGame" />
<GameCreationForm Categories="Categories" OnSubmit="() => HandleFetchDatas()" />
</Popup>

View File

@@ -1,23 +1,24 @@
using GameIdeas.BlazorApp.Pages.Games.Components;
using GameIdeas.BlazorApp.Pages.Games.Filter;
using GameIdeas.BlazorApp.Shared.Components;
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;
public partial class Games : GameBaseComponent
public partial class Games
{
[Inject] private IGameGateway GameGateway { get; set; } = default!;
private DisplayType DisplayType = DisplayType.List;
private GameFilterParams GameFilter = new();
private GameListDto GamesDto = new();
private Popup? ManualAddPopup;
private bool IsLoading = false;
private CategoriesDto? Categories;
private IEnumerable<GameDto> GamesDto = [];
private int CurrentPage;
private Popup? DeletePopup;
private GameDto? GameToDelete;
private int? GameIdToUpdate;
private GameCreationForm? CreationForm;
protected override async Task OnInitializedAsync()
{
@@ -25,19 +26,38 @@ public partial class Games : GameBaseComponent
GameFilter.SortType = Filter.GameFilter.SortTypes
.First(st => st.SortType == SortType.Ascending);
GameFilter.SortProperty = Filter.GameFilter.GameProperties
GameFilter.SortProperty= Filter.GameFilter.GameProperties
.First(gp => gp.PropertyName == nameof(GameIdeas.Shared.Model.Game.Title));
await HandleFetchDatas();
await base.OnInitializedAsync();
}
private async Task HandleFetchDatas(bool displayLoader = true)
private void HandleAddClicked(AddType addType)
{
switch (addType)
{
case AddType.Manual:
ManualAddPopup?.Open();
break;
case AddType.Auto:
break;
default:
break;
}
}
private void HandleBackdropManualAddClicked()
{
ManualAddPopup?.Close();
}
private async Task HandleFetchDatas(bool loadCategories = true, bool displayLoader = true)
{
try
{
IsLoading = displayLoader;
StateHasChanged();
if (loadCategories)
Categories = await GameGateway.FetchCategories();
GamesDto = await GameGateway.FetchGames(GameFilter, CurrentPage);
}
@@ -48,75 +68,11 @@ public partial class Games : GameBaseComponent
finally
{
IsLoading = false;
StateHasChanged();
}
}
private async Task HandleFilterChanged(GameFilterParams args)
{
GameFilter = args;
await HandleFetchDatas(false);
}
private void HandleDeleteGame(GameDto args)
{
DeletePopup?.Open();
GameToDelete = args;
}
private void HandleCancelPopupClicked()
{
DeletePopup?.Close();
GameToDelete = null;
}
private void HandleEditGame(GameDto args)
{
if (args.Id == null)
{
return;
}
GameIdToUpdate = args.Id;
ManualAddPopup?.Open();
}
private async Task HandleRemoveGame()
{
DeletePopup?.Close();
if (GameToDelete?.Id == null)
{
return;
}
try
{
IsLoading = true;
StateHasChanged();
await GameGateway.DeleteGame(GameToDelete?.Id ?? 0);
await HandleFetchDatas(false);
}
catch (Exception)
{
throw;
}
GameToDelete = null;
}
private async Task HandleRenderCreationForm()
{
if (GameIdToUpdate != null && CreationForm != null)
{
await CreationForm.SetGameToUpdateAsync(GameIdToUpdate ?? 0);
}
GameIdToUpdate = null;
}
private async Task HandleOnSubmitGame()
{
await HandleFetchDatas(false);
await HandleFetchCategories();
await HandleFetchDatas(loadCategories: false, displayLoader: false);
}
}

View File

@@ -35,7 +35,7 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
}
}
public async Task<GameListDto> FetchGames(GameFilterParams filterParams, int currentPage)
public async Task<IEnumerable<GameDto>> FetchGames(GameFilterParams filterParams, int currentPage)
{
try
{
@@ -52,11 +52,9 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
PropertyIds = filterParams.Properties?.Select(d => d.Id ?? 0).ToList(),
ReleaseYears = filterParams.ReleaseYears,
TagIds = filterParams.Tags?.Select(d => d.Id ?? 0).ToList(),
SortPropertyName = filterParams.SortProperty?.PropertyName,
SortType = filterParams.SortType?.SortType
};
var result = await httpClientService.FetchDataAsync<GameListDto>(Endpoints.Game.Fetch(filter));
var result = await httpClientService.FetchDataAsync<IEnumerable<GameDto>>(Endpoints.Game.Fetch(filter));
return result ?? throw new InvalidOperationException(ResourcesKey.ErrorFetchGames);
}
catch (Exception)
@@ -78,28 +76,4 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchGames);
}
}
public async Task<bool> DeleteGame(int gameIdToDelete)
{
try
{
return await httpClientService.DeleteAsync<bool>(Endpoints.Game.Delete(gameIdToDelete));
}
catch (Exception)
{
throw new GameDeletionException(ResourcesKey.ErrorDeleteGame);
}
}
public async Task<int> UpdateGame(GameDetailDto gameDto)
{
try
{
return await httpClientService.PutAsync<int>(Endpoints.Game.Update, gameDto);
}
catch (Exception)
{
throw new GameUpdateException(ResourcesKey.ErrorUpdateGame);
}
}
}

View File

@@ -7,8 +7,6 @@ public interface IGameGateway
{
Task<CategoriesDto> FetchCategories();
Task<int> CreateGame(GameDetailDto game);
Task<GameListDto> FetchGames(GameFilterParams filter, int currentPage);
Task<IEnumerable<GameDto>> FetchGames(GameFilterParams filter, int currentPage);
Task<GameDetailDto> GetGameById(int gameId);
Task<bool> DeleteGame(int gameIdToDelete);
Task<int> UpdateGame(GameDetailDto gameDto);
}

View File

@@ -1,10 +0,0 @@
@page "/"
@inject NavigationManager navigationManager
@code {
protected override void OnInitialized()
{
navigationManager.NavigateTo("/Games");
}
}

View File

@@ -10,9 +10,9 @@ public partial class Login
[Parameter] public IAuthGateway AuthGateway { get; set; } = default!;
private EditContext? EditContext;
private readonly UserDto UserDto = new();
private UserDto UserDto = new();
private bool IsLoading = false;
private readonly LoginValidator Validator = new();
private LoginValidator Validator = new();
protected override void OnInitialized()
{
EditContext = new EditContext(UserDto);
@@ -28,8 +28,6 @@ public partial class Login
try
{
IsLoading = true;
StateHasChanged();
await AuthGateway.Login(UserDto);
}
catch (Exception)

View File

@@ -50,6 +50,6 @@
border-radius: 50%;
border: 3px solid rgba(0, 0, 0, 0.2);
border-top-color: var(--white);
animation: spin 1s linear infinite;
animation: loading 1s linear infinite;
justify-self: center;
}

View File

@@ -14,7 +14,7 @@ public partial class UserMenu
{
ContentVisile = false;
await AuthGateway.Logout();
NavigationManager.NavigateTo("/Games");
NavigationManager.NavigateTo("/");
}
private void HandleAccountClicked()

View File

@@ -1,4 +1,5 @@
using FluentValidation;
using GameIdeas.BlazorApp.Shared.Components.Select;
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components;

View File

@@ -89,16 +89,3 @@
.submit ::deep svg {
fill: var(--green);
}
@media screen and (max-width: 700px) {
.row {
height: 104px;
display: grid;
grid-template-rows: 48px 48px;
grid-template-columns: 48px 1fr 100px;
}
.role {
grid-column: 2;
}
}

View File

@@ -54,3 +54,16 @@
fill: var(--yellow);
}
@keyframes loading {
0% {
background: rgb(255, 255, 255, 0.05);
}
50% {
background: rgb(255, 255, 255, 0.2);
}
100% {
background: rgb(255, 255, 255, 0.05);
}
}

View File

@@ -28,21 +28,12 @@
<div class="content">
@if (!IsLoading)
{
@if (UserList.UsersCount != 0)
{
<div class="user-number">@string.Format(ResourcesKey.UsersNumberFormat, UserList.UsersCount)</div>
@foreach (var user in UserList.Users ?? [])
{
<UserRow User="user" Roles="Roles.ToList()" OnRemove="HandleOpenConfirmationPopup" OnSubmit="HandleUpdateUser" Validator="@(new UserUpdateValidator())" CanDelete=@(user.Id != currentUserId) />
}
}
else
{
<div class="no-users">@ResourcesKey.NoUsers</div>
}
}
else
{
@for (int i = 0; i < 20; i++)
{

View File

@@ -17,10 +17,10 @@ public partial class Users
private Popup? Popup;
private bool IsLoading = false;
private readonly UserFilterParams FilterParams = new();
private UserFilterParams FilterParams = new();
private UserListDto UserList = new();
private IEnumerable<RoleDto> Roles = [];
private readonly int CurrentPage = 1;
private int CurrentPage = 1;
private UserDto UserAdd = new();
private UserDto? UserDelete;
private string? currentUserId;
@@ -36,17 +36,18 @@ public partial class Users
}
await FetchUsers();
await FetchRoles();
await FetchData();
await base.OnInitializedAsync();
}
private async Task FetchUsers(bool displayLoading = true)
private async Task FetchData(bool fetchRoles = true)
{
try
{
IsLoading = displayLoading;
StateHasChanged();
IsLoading = true;
if (fetchRoles)
Roles = await UserGateway.GetRoles();
UserList = await UserGateway.GetUsers(FilterParams, CurrentPage);
}
@@ -57,27 +58,6 @@ public partial class Users
finally
{
IsLoading = false;
StateHasChanged();
}
}
private async Task FetchRoles()
{
try
{
IsLoading = true;
StateHasChanged();
Roles = await UserGateway.GetRoles();
}
catch (Exception)
{
throw;
}
finally
{
IsLoading = false;
StateHasChanged();
}
}
@@ -86,10 +66,9 @@ public partial class Users
try
{
IsLoading = true;
StateHasChanged();
await UserGateway.CreateUser(user);
await FetchUsers();
await FetchData(false);
}
catch (Exception)
{
@@ -98,9 +77,9 @@ public partial class Users
finally
{
IsLoading = false;
StateHasChanged();
UserAdd = new();
}
UserAdd = new();
}
private async Task HandleUpdateUser(UserDto user)
@@ -108,10 +87,9 @@ public partial class Users
try
{
IsLoading = true;
StateHasChanged();
await UserGateway.UpdateUser(user);
await FetchUsers();
await FetchData(false);
}
catch (Exception)
{
@@ -120,7 +98,6 @@ public partial class Users
finally
{
IsLoading = false;
StateHasChanged();
}
}
@@ -136,10 +113,9 @@ public partial class Users
try
{
IsLoading = true;
StateHasChanged();
await UserGateway.DeleteUser(UserDelete.Id);
await FetchUsers();
await FetchData(false);
}
catch (Exception)
{
@@ -148,7 +124,6 @@ public partial class Users
finally
{
IsLoading = false;
StateHasChanged();
}
UserDelete = null;
@@ -159,7 +134,7 @@ public partial class Users
}
private async Task HandleFilterChanged()
{
await FetchUsers(false);
await FetchData(false);
}
private void HandleCancelPopupClicked()
{

View File

@@ -1,3 +1,4 @@
using System.Net.Http.Json;
using Blazored.LocalStorage;
using GameIdeas.BlazorApp;
using GameIdeas.BlazorApp.Pages.Games.Gateways;
@@ -9,7 +10,6 @@ using GameIdeas.Shared.Constants;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using System.Net.Http.Json;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
var services = builder.Services;

View File

@@ -1,11 +1,11 @@
using Blazored.LocalStorage;
using GameIdeas.Resources;
using GameIdeas.Resources;
using System.Net.Http.Headers;
using System.Text.Json.Serialization;
using System.Text.Json;
using System.Text;
using Blazored.LocalStorage;
using GameIdeas.Shared.Constants;
using Microsoft.AspNetCore.Components.Authorization;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace GameIdeas.BlazorApp.Services;

View File

@@ -1,9 +1,9 @@
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Claims;
using System.IdentityModel.Tokens.Jwt;
using GameIdeas.Shared.Constants;
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components.Authorization;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
namespace GameIdeas.BlazorApp.Services;

View File

@@ -35,7 +35,7 @@
}
else
{
await Js.InvokeVoidAsync("setBodyOverflow", "visible");
await Js.InvokeVoidAsync("setBodyOverflow", "auto");
}
}
catch (Exception)

View File

@@ -1,5 +1,5 @@
using GameIdeas.BlazorApp.Shared.Components.Select;
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.BlazorApp.Shared.Components.Select;
using GameIdeas.BlazorApp.Shared.Models;
using GameIdeas.Resources;
using Microsoft.AspNetCore.Components;

View File

@@ -19,3 +19,13 @@
height: 60px;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

View File

@@ -1,60 +0,0 @@
using GameIdeas.BlazorApp.Pages.Games.Gateways;
using GameIdeas.BlazorApp.Shared.Models;
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components;
namespace GameIdeas.BlazorApp.Shared.Components;
public class GameBaseComponent : ComponentBase
{
[Inject] protected IGameGateway GameGateway { get; set; } = default!;
protected Popup.Popup? ManualAddPopup;
protected CategoriesDto? Categories;
protected bool IsLoading = false;
protected override async Task OnInitializedAsync()
{
await HandleFetchCategories();
await base.OnInitializedAsync();
}
protected async Task HandleFetchCategories()
{
try
{
IsLoading = true;
StateHasChanged();
Categories = await GameGateway.FetchCategories();
}
catch (Exception)
{
throw;
}
finally
{
IsLoading = false;
StateHasChanged();
}
}
protected void HandleAddClicked(AddType addType)
{
switch (addType)
{
case AddType.Manual:
ManualAddPopup?.Open();
break;
case AddType.Auto:
break;
default:
break;
}
}
protected void HandleBackdropManualAddClicked()
{
ManualAddPopup?.Close();
}
}

View File

@@ -1,3 +1,7 @@
using GameIdeas.BlazorApp.Shared.Components.Select;
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.BlazorApp.Shared.Models;
using GameIdeas.Resources;
using Microsoft.AspNetCore.Components;
namespace GameIdeas.BlazorApp.Shared.Components.Header;

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace GameIdeas.BlazorApp.Shared.Components.ReadMore;

View File

@@ -7,7 +7,6 @@
placeholder="@Placeholder"
disabled="@IsDisable"
style="@(IsDisable ? "pointer-events: none" : "")"
onClick="this.select();"
@bind=@Text
@bind:event="oninput"
@bind:after="HandleTextChanged"

View File

@@ -34,7 +34,6 @@
min-width: 18px;
height: 18px;
width: 18px;
z-index: 800;
}
.clear-icon:hover {

View File

@@ -52,20 +52,3 @@
.single .selected {
display: none;
}
/***** Navigation Theme *****/
.row-option {
padding: 4px 8px;
}
.row-option:hover {
background: var(--violet-selected);
}
.row-option .selected {
display: none;
}
.row-option:last-child {
color: var(--red);
}

View File

@@ -14,7 +14,6 @@ public static class SelectHelper
SelectTheme.AdvancedFilter => "advanced-filter",
SelectTheme.Creation => "creation",
SelectTheme.Single => "single",
SelectTheme.RowOption => "row-option",
_ => string.Empty
};
}

View File

@@ -4,10 +4,8 @@ public class SelectParams<TItem, THeader>
{
public List<TItem> Items { get; set; } = [];
public Func<TItem, string> GetItemLabel { get; set; } = _ => string.Empty;
public Func<TItem, string>? GetItemOrder { get; set; }
public List<THeader> Headers { get; set; } = [];
public Func<THeader, string> GetHeaderLabel { get; set; } = _ => string.Empty;
public Func<THeader, string>? GetHeaderOrder { get; set; }
public Func<string, TItem>? AddItem { get; set; }
}

View File

@@ -7,6 +7,5 @@ public enum SelectTheme
Filter,
AdvancedFilter,
Creation,
Single,
RowOption
Single
}

View File

@@ -6,7 +6,7 @@
@typeparam THeader
<div class="select-container">
<div class="button @(IsContentOpen ? "selected" : "")" @onclick=HandleButtonClicked>
<div class="button" @onclick=HandleButtonClicked>
@ChildContent
</div>
@@ -27,9 +27,9 @@
@if (Params.Headers != null)
{
@foreach (var header in GetHeaders())
@foreach (var header in Params.Headers.Union(HeaderValues ?? []))
{
<SelectRow IsSelected=@(HeaderValues?.Contains(header))
<SelectRow IsSelected=HeaderValues?.Contains(header)
Label="@Params.GetHeaderLabel(header)" Theme=Theme
OnClick="_ => HandleHeaderClicked(header)" />
}
@@ -42,9 +42,9 @@
@if (Params.Items != null)
{
@foreach (var item in GetItems())
@foreach (var item in Params.Items.Union(Values ?? []))
{
<SelectRow IsSelected=@(Values?.Contains(item))
<SelectRow IsSelected=Values?.Contains(item)
Label="@Params.GetItemLabel(item)" Theme=Theme
OnClick="_ => HandleValueClicked(item)" />
}

View File

@@ -1,6 +1,9 @@
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.Resources;
using GameIdeas.Shared.Constants;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using System.Text.RegularExpressions;
namespace GameIdeas.BlazorApp.Shared.Components.Select;
@@ -89,24 +92,11 @@ public partial class Select<TItem, THeader>
if (Params.AddItem != null)
{
Values ??= [];
if (Type != SelectType.Multiple)
{
Values = [];
}
Values.Add(Params.AddItem(AddLabel));
AddLabel = string.Empty;
await ValuesChanged.InvokeAsync(Values);
}
}
private List<THeader> GetHeaders() => [.. (HeaderValues ?? [])
.UnionBy(Params.Headers, Params.GetHeaderLabel)
.OrderBy(Params.GetHeaderOrder ?? Params.GetHeaderLabel)];
private List<TItem> GetItems() => [.. (Values ?? [])
.UnionBy(Params.Items, Params.GetItemLabel)
.OrderBy(Params.GetItemOrder ?? Params.GetItemLabel)];
}

View File

@@ -22,6 +22,8 @@
overflow: hidden;
display: flex;
flex-direction: column;
animation-name: fade-in;
animation-duration: 0.2s;
}
.line {
@@ -102,13 +104,3 @@
.single {
border: none;
}
/***** Row Option Theme *****/
.dropdown.row-option {
width: auto;
right: 10px;
}
.row-option .content {
background: var(--violet);
}

View File

@@ -5,12 +5,12 @@
@typeparam TItem
<Select @ref=Select TItem="TItem" THeader="string" Theme="Theme" Type="SelectType" DisableClicked=true
<Select @ref=Select TItem="TItem" THeader="string" Theme="Theme" Type="SelectType"
Params="SelectParams" Values=Values ValuesChanged="HandleValuesChanged" QuickAdd=QuickAdd>
<div class="@SelectHelper.GetClassFromTheme(Theme)">
<SearchInput @ref=SearchInput Icon="SearchInputIcon.Dropdown" Placeholder="@Placeholder"
TextChanged="HandleTextChanged" ClearClicked="HandleClearClicked" IsDisable=false
TextChanged="HandleClearClicked" ClearClicked="HandleClearClicked" IsDisable=QuickAdd
FocusIn="HandleFocusIn" SearchClicked="HandleFocusIn" />
</div>

View File

@@ -1,7 +1,6 @@
using GameIdeas.BlazorApp.Pages.Games;
using GameIdeas.BlazorApp.Shared.Components.Search;
using GameIdeas.BlazorApp.Shared.Components.Select;
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.BlazorApp.Shared.Components.Select;
using Microsoft.AspNetCore.Components;
namespace GameIdeas.BlazorApp.Shared.Components.SelectSearch;
@@ -11,7 +10,6 @@ public partial class SelectSearch<TItem>
[Parameter] public SelectTheme Theme { get; set; }
[Parameter] public List<TItem> Items { get; set; } = [];
[Parameter] public Func<TItem, string> GetLabel { get; set; } = _ => string.Empty;
[Parameter] public Func<TItem, string>? OrderBy { get; set; }
[Parameter] public List<TItem> Values { get; set; } = [];
[Parameter] public EventCallback<List<TItem>> ValuesChanged { get; set; }
[Parameter] public string Placeholder { get; set; } = string.Empty;
@@ -29,62 +27,26 @@ public partial class SelectSearch<TItem>
{
Items = Items,
GetItemLabel = GetLabel,
GetItemOrder = OrderBy,
AddItem = AddItem
};
base.OnParametersSet();
}
protected override void OnAfterRender(bool firstRender)
{
if (firstRender && Values != null)
{
SearchInput?.SetText(string.Join(", ", Values.Select(GetLabel)));
}
}
private async Task HandleValuesChanged(IEnumerable<TItem> values)
{
Values = [.. values];
Values = values.ToList();
SearchInput?.SetText(string.Join(", ", Values.Select(GetLabel)));
await ValuesChanged.InvokeAsync([.. Values]);
await ValuesChanged.InvokeAsync(Values.ToList());
}
private async Task HandleClearClicked()
{
Values = [];
Select?.Close();
SearchInput?.SetText(string.Empty);
await ValuesChanged.InvokeAsync([]);
await ValuesChanged.InvokeAsync(Values.ToList());
}
private void HandleFocusIn()
{
Select?.Open();
}
private void HandleTextChanged(string args)
{
if (!string.IsNullOrEmpty(args))
{
var keywords = args
.Split([' '], StringSplitOptions.RemoveEmptyEntries)
.Select(k => k.Trim())
.ToArray() ?? [];
SelectParams.Items = [.. Items
.Where(game => keywords.All(
kw => SelectParams.GetItemLabel(game).Contains(kw, StringComparison.OrdinalIgnoreCase)
))
.OrderBy(game => keywords.Min(kw =>
SelectParams.GetItemLabel(game).IndexOf(kw, StringComparison.OrdinalIgnoreCase)
))
.ThenBy(game => SelectParams.GetItemLabel(game).Length)];
}
else
{
SelectParams.Items = Items;
SearchInput?.SetText(string.Join(", ", Values?.Select(GetLabel) ?? []));
}
}
}

View File

@@ -2,7 +2,7 @@
public class SliderParams
{
public int Min { get; set; }
public int Min{ get; set; }
public int Max { get; set; }
public int Gap { get; set; } = 0;
}

View File

@@ -2,7 +2,7 @@
public class SliderRangeParams
{
public int Min { get; set; }
public int Min{ get; set; }
public int Max { get; set; }
public int Gap { get; set; } = 0;
}

View File

@@ -10,8 +10,6 @@ public static class Endpoints
public const string Create = "api/Game/Create";
public static string Fetch(GameFilterDto filter) => $"api/Game?{UrlHelper.BuildUrlParams(filter)}";
public static string FetchById(int gameId) => $"api/Game/{gameId}";
public static string Delete(int gameId) => $"api/Game/Delete/{gameId}";
public const string Update = "api/Game/Update";
}
public static class Category

View File

@@ -1,3 +0,0 @@
namespace GameIdeas.BlazorApp.Shared.Exceptions;
public class FetchGameDetailException(string message) : Exception(message);

View File

@@ -1,3 +0,0 @@
namespace GameIdeas.BlazorApp.Shared.Exceptions;
public class GameDeletionException(string message) : Exception(message);

View File

@@ -1,3 +0,0 @@
namespace GameIdeas.BlazorApp.Shared.Exceptions;
public class GameUpdateException(string message) : Exception(message);

View File

@@ -82,20 +82,64 @@ html, body, #app {
}
.loading-progress {
display: flex;
width: 100vw;
height: 100vh;
justify-content: center;
align-items: center;
animation: loading-background 4s linear infinite;
position: relative;
display: block;
width: 8rem;
height: 8rem;
margin: 20vh auto 1rem auto;
}
.loading-progress > #loading-icon {
max-width: 200px;
max-height: 200px;
animation: loading-icon 4s ease-in-out infinite;
.loading-progress circle {
fill: none;
stroke: #e0e0e0;
stroke-width: 0.6rem;
transform-origin: 50% 50%;
transform: rotate(-90deg);
}
.loading-progress circle:last-child {
stroke: #1b6ec2;
stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text {
color: #000;
position: absolute;
text-align: center;
font-weight: bold;
inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}
.loading-progress-text:after {
content: var(--blazor-load-percentage-text, "Loading");
}
code {
color: #c02d76;
}
.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
color: var(--bs-secondary-color);
text-align: end;
}
.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
text-align: start;
}
:focus-visible {
outline: none;
}
.expand-col-2 {
grid-column: 1 / 3;
}
.expand-row-2 {
grid-row: 1 / 3;
}
.body-sm {
color: #ccc
}
@@ -103,10 +147,9 @@ html, body, #app {
.body-lg {
font-weight: 400;
font-size: 14px;
display: block;
}
.header-1, .header-2 {
.header-1, .header-2, span, a {
display: block;
color: var(--white);
margin: 0;
@@ -114,59 +157,14 @@ html, body, #app {
text-decoration: none;
}
:focus-visible {
outline: none;
}
@keyframes loading-background {
0% {
background: rgb(0, 0, 0, 0.2);
}
50% {
background: rgb(0, 0, 0, 0.3);
}
100% {
background: rgb(0, 0, 0, 0.2);
}
}
@keyframes loading-icon {
0% {
transform: scale(1);
}
50% {
transform: scale(0.95);
}
100% {
transform: scale(1);
}
@keyframes fade-in {
0% {opacity: 0}
100% {opacity: 1}
}
@keyframes loading {
0% {
background: rgb(255, 255, 255, 0.05);
}
50% {
background: rgb(255, 255, 255, 0.2);
}
100% {
background: rgb(255, 255, 255, 0.05);
}
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
to {
transform: rotate(360deg);
}
}

View File

@@ -1,42 +0,0 @@
.orb {
position: absolute;
border-radius: 100%;
z-index: var(--index-orb);
}
.green {
width: 80vh;
height: 80vh;
top: -20vh;
background: #315941;
filter: blur(30vh);
}
.blue {
width: 80vw;
height: 80vw;
left: 10vw;
top: 50vh;
background: #3A4156;
filter: blur(30vh);
}
.red {
width: 100vh;
height: 100vh;
left: 60vw;
top: -40vh;
background: #593533;
filter: blur(30vh);
}
#background {
height: 100vh;
width: 100vw;
background: var(--background);
position: fixed;
overflow: hidden;
top: 0;
left: 0;
z-index: var(--index-background);
}

View File

@@ -7,22 +7,17 @@
<title>Game Ideas</title>
<base href="/" />
<link rel="stylesheet" href="css/app.css" />
<link rel="stylesheet" href="css/background.css" />
<link rel="icon" type="image/png" href="icon.png" />
<link href="GameIdeas.BlazorApp.styles.css" rel="stylesheet" />
</head>
<body>
<div id="app">
<div class="loading-progress">
<img src="icon.png" alt="" id="loading-icon">
</div>
</div>
<div id="background">
<span class="orb red"></span>
<span class="orb blue"></span>
<span class="orb green"></span>
<svg class="loading-progress">
<circle r="40%" cx="50%" cy="50%" />
<circle r="40%" cx="50%" cy="50%" />
</svg>
<div class="loading-progress-text"></div>
</div>
<div id="blazor-error-ui">
@@ -30,7 +25,6 @@
<a href="." class="reload">Reload</a>
<span class="dismiss">🗙</span>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="Shared/Components/BackdropFilter/BackdropFilter.razor.js"></script>
<script src="Pages/Games/Components/GameCreationForm.razor.js"></script>

View File

@@ -39,13 +39,10 @@ public class Translations (TranslationService translationService)
public string ErrorFetchCategories => translationService.Translate(nameof(ErrorFetchCategories));
public string PlaceholderAdd => translationService.Translate(nameof(PlaceholderAdd));
public string ErrorCreateGame => translationService.Translate(nameof(ErrorCreateGame));
public string ErrorDeleteGame => translationService.Translate(nameof(ErrorDeleteGame));
public string ErrorUpdateGame => translationService.Translate(nameof(ErrorUpdateGame));
public string InvalidTitle => translationService.Translate(nameof(InvalidTitle));
public string InvalidInterest => translationService.Translate(nameof(InvalidInterest));
public string Unknown => translationService.Translate(nameof(Unknown));
public string ErrorFetchGames => translationService.Translate(nameof(ErrorFetchGames));
public string ErrorFetchDetail => translationService.Translate(nameof(ErrorFetchDetail));
public string Ascending => translationService.Translate(nameof(Ascending));
public string Descending => translationService.Translate(nameof(Descending));
public string ErrorStorageSpaceLabel => translationService.Translate(nameof(ErrorStorageSpaceLabel));
@@ -71,13 +68,6 @@ public class Translations (TranslationService translationService)
public string About => translationService.Translate(nameof(About));
public string ReadMore => translationService.Translate(nameof(ReadMore));
public string ReadLess => translationService.Translate(nameof(ReadLess));
public string Detail => translationService.Translate(nameof(Detail));
public string Edit => translationService.Translate(nameof(Edit));
public string Delete => translationService.Translate(nameof(Delete));
public string NoGames => translationService.Translate(nameof(NoGames));
public string NoUsers => translationService.Translate(nameof(NoUsers));
public string GamesNumberFormat => translationService.Translate(nameof(GamesNumberFormat));
public string UsersNumberFormat => translationService.Translate(nameof(UsersNumberFormat));
}
public static class ResourcesKey
@@ -125,13 +115,10 @@ public static class ResourcesKey
public static string ErrorFetchCategories => _instance?.ErrorFetchCategories ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchCategories is not initialized.");
public static string PlaceholderAdd => _instance?.PlaceholderAdd ?? throw new InvalidOperationException("ResourcesKey.PlaceholderAdd is not initialized.");
public static string ErrorCreateGame => _instance?.ErrorCreateGame ?? throw new InvalidOperationException("ResourcesKey.ErrorCreateGame is not initialized.");
public static string ErrorDeleteGame => _instance?.ErrorDeleteGame ?? throw new InvalidOperationException("ResourcesKey.ErrorDeleteGame is not initialized.");
public static string ErrorUpdateGame => _instance?.ErrorUpdateGame ?? throw new InvalidOperationException("ResourcesKey.ErrorUpdateGame is not initialized.");
public static string InvalidTitle => _instance?.InvalidTitle ?? throw new InvalidOperationException("ResourcesKey.InvalidTitle 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 ErrorFetchGames => _instance?.ErrorFetchGames ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchGames is not initialized.");
public static string ErrorFetchDetail => _instance?.ErrorFetchDetail ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchDetail 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.");
public static string ErrorStorageSpaceLabel => _instance?.ErrorStorageSpaceLabel ?? throw new InvalidOperationException("ResourcesKey.ErrorStorageSpaceLabel is not initialized.");
@@ -157,11 +144,4 @@ public static class ResourcesKey
public static string About => _instance?.About ?? throw new InvalidOperationException("ResourcesKey.About is not initialized.");
public static string ReadMore => _instance?.ReadMore ?? throw new InvalidOperationException("ResourcesKey.ReadMore is not initialized.");
public static string ReadLess => _instance?.ReadLess ?? throw new InvalidOperationException("ResourcesKey.ReadLess is not initialized.");
public static string Detail => _instance?.Detail ?? throw new InvalidOperationException("ResourcesKey.Detail is not initialized.");
public static string Edit => _instance?.Edit ?? throw new InvalidOperationException("ResourcesKey.Edit is not initialized.");
public static string Delete => _instance?.Delete ?? throw new InvalidOperationException("ResourcesKey.Delete is not initialized.");
public static string NoGames => _instance?.NoGames ?? throw new InvalidOperationException("ResourcesKey.NoGames is not initialized.");
public static string NoUsers => _instance?.NoUsers ?? throw new InvalidOperationException("ResourcesKey.NoUsers is not initialized.");
public static string GamesNumberFormat => _instance?.GamesNumberFormat ?? throw new InvalidOperationException("ResourcesKey.GamesNumberFormat is not initialized.");
public static string UsersNumberFormat => _instance?.UsersNumberFormat ?? throw new InvalidOperationException("ResourcesKey.UsersNumberFormat is not initialized.");
}

View File

@@ -5,7 +5,7 @@ namespace GameIdeas.Resources;
public class TranslationService
{
private readonly Dictionary<string, Dictionary<string, string>?> _translations = [];
private readonly Dictionary<string, Dictionary<string, string>?> _translations = new();
public void Initialize(Dictionary<string, string> translations)
{

View File

@@ -22,7 +22,7 @@ public class GlobalConstants
public const int API_PORT = 8000;
public const string SUB_DOMAIN_NAME = "api-";
public const double DELAY_INPUT_MS = 450;
public const double DELAY_INPUT_MS = 500;
public const int MAX_DESCRIPTION_LENGTH = 350;
}

View File

@@ -1,7 +0,0 @@
namespace GameIdeas.Shared.Dto;
public class GameListDto
{
public IEnumerable<GameDto> Games { get; set; } = [];
public int NumberOfGames { get; set; }
}

View File

@@ -1,4 +1,6 @@
namespace GameIdeas.Shared.Dto;
using GameIdeas.Shared.Enum;
namespace GameIdeas.Shared.Dto;
public class UserDto
{

View File

@@ -31,3 +31,4 @@ public partial class Game
public virtual ICollection<GameProperty> GameProperties { get; set; }
public virtual ICollection<GameTag> GameTags { get; set; }
}

View File

@@ -25,16 +25,14 @@ public class GameIdeasContext : IdentityDbContext<User>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Developer>(entity =>
{
modelBuilder.Entity<Developer>(entity => {
entity.ToTable("Developer");
entity.HasIndex(e => e.Name)
.IsUnique();
});
modelBuilder.Entity<Platform>(entity =>
{
modelBuilder.Entity<Platform>(entity => {
entity.ToTable("Platform");
entity.HasIndex(e => e.Label)

View File

@@ -17,7 +17,7 @@ public class GameController(
private readonly ILogger<GameController> logger = loggerFactory.CreateLogger<GameController>();
[HttpGet]
public async Task<ActionResult<GameListDto>> SearchGames([FromQuery] GameFilterDto filter)
public async Task<ActionResult<IEnumerable<GameDto>>> SearchGames([FromQuery] GameFilterDto filter)
{
try
{

View File

@@ -5,7 +5,7 @@ namespace GameIdeas.WebAPI.Controllers;
[ApiController]
[Route("api/[controller]")]
public class TranslationsController(ILogger<TranslationsController> Logger) : ControllerBase
public class TranslationsController (ILogger<TranslationsController> Logger) : ControllerBase
{
[HttpGet]
public async Task<IActionResult> GetTranslations()
@@ -26,7 +26,7 @@ public class TranslationsController(ILogger<TranslationsController> Logger) : Co
dictionary.Add(culture, content);
}
}
catch (Exception ex)
catch(Exception ex)
{
Logger.LogError(ex, "Internal translations error");
}

View File

@@ -1,3 +1,3 @@
namespace GameIdeas.WebAPI.Exceptions;
public class UserInvalidException(string message) : Exception(message);
public class UserInvalidException (string message) : Exception(message);

View File

@@ -35,13 +35,10 @@
"ErrorFetchCategories": "Erreur lors de la récupération des catégories",
"PlaceholderAdd": "Ajouter un nouveau",
"ErrorCreateGame": "Erreur lors de la création d'un jeu",
"ErrorDeleteGame": "Erreur lors de la suppression d'un jeu",
"ErrorUpdateGame": "Erreur lors de la modification d'un jeu",
"InvalidTitle": "Le titre est incorrect",
"InvalidInterest": "L'interêt est incorrect",
"Unknown": "Inconnu",
"ErrorFetchGames": "Erreur lors de la récupération des jeux",
"ErrorFetchDetail": "Erreur lors de la récupération des détails d'un jeu",
"Ascending": "Ascendant",
"Descending": "Descendant",
"ErrorStorageSpaceLabel": "Erreur lors de la génération des label de l'espace de stockage",
@@ -66,12 +63,5 @@
"Informations": "Informations",
"About": "À propos",
"ReadMore": "Afficher",
"ReadLess": "Réduire",
"Detail": "Détail",
"Edit": "Modifier",
"Delete": "Supprimer",
"NoGames": "Pas de jeux disponible",
"NoUsers": "Pas d'utilisateurs disponible",
"GamesNumberFormat": "Nombre de jeux : {0}",
"UsersNumberFormat": "Nombre d'utilisateurs : {0}"
"ReadLess": "Réduire"
}

View File

@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@@ -54,7 +54,7 @@ namespace GameIdeas.WebAPI.Migrations
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@$"DELETE FROM ""AspNetUserRoles"" WHERE ""UserId"" = '{GlobalConstants.ADMINISTRATOR_USER_ID}' AND ""RoleId"" = '{GlobalConstants.ADMINISTRATOR_ID}'");
migrationBuilder.Sql(@$"DELETE FROM ""AspNetUserRoles"" WHERE ""UserId"" = '{GlobalConstants.ADMINISTRATOR_USER_ID.ToString()}' AND ""RoleId"" = '{GlobalConstants.ADMINISTRATOR_ID.ToString()}'");
migrationBuilder.DeleteData("AspNetUsers", "Id", GlobalConstants.ADMINISTRATOR_USER_ID.ToString());
migrationBuilder.DeleteData("AspNetRoles", "Id", GlobalConstants.ADMINISTRATOR_ID.ToString());
migrationBuilder.DeleteData("AspNetRoles", "Id", GlobalConstants.MEMBER_ID.ToString());

View File

@@ -12,7 +12,7 @@ namespace GameIdeas.WebAPI.Services.Games;
public class GameReadService(GameIdeasContext context, IMapper mapper, ICategoryService categoryService) : IGameReadService
{
public async Task<GameListDto> GetGames(GameFilterDto filter)
public async Task<IEnumerable<GameDto>> GetGames(GameFilterDto filter)
{
var query = context.Games
.Include(g => g.GamePlatforms).ThenInclude(gp => gp.Platform)
@@ -26,19 +26,13 @@ public class GameReadService(GameIdeasContext context, IMapper mapper, ICategory
ApplyOrder(ref query, filter);
var games = await query.ToListAsync();
var games = await query.Skip((filter.CurrentPage - 1) * GlobalConstants.NUMBER_PER_PAGE)
.Take(GlobalConstants.NUMBER_PER_PAGE)
.ToListAsync();
ApplyStaticFilter(ref games, filter);
games = [.. games
.Skip((filter.CurrentPage - 1) * GlobalConstants.NUMBER_PER_PAGE)
.Take(GlobalConstants.NUMBER_PER_PAGE)];
return new()
{
Games = mapper.Map<IEnumerable<GameDto>>(games),
NumberOfGames = games.Count
};
return mapper.Map<IEnumerable<GameDto>>(games);
}
public async Task<GameDetailDto> GetGameById(int gameId)
@@ -136,14 +130,15 @@ public class GameReadService(GameIdeasContext context, IMapper mapper, ICategory
.Select(k => k.Trim())
.ToArray() ?? [];
games = [.. games
games = games
.Where(game => keywords.All(
kw => game.Title.Contains(kw, StringComparison.OrdinalIgnoreCase)
))
.OrderBy(game => keywords.Min(kw =>
game.Title.IndexOf(kw, StringComparison.OrdinalIgnoreCase)
))
.ThenBy(game => game.Title.Length)];
.ThenBy(game => game.Title.Length)
.ToList();
return;
}
@@ -152,9 +147,10 @@ public class GameReadService(GameIdeasContext context, IMapper mapper, ICategory
{
var storageSpaces = categoryService.GetStorageSpaces().Where(stor => filter.StorageSpaces.Contains(stor.Id));
games = [.. games
games = games
.Where(game => storageSpaces.Any(stor =>
(stor.MinSize ?? int.MinValue) <= game.StorageSpace && (stor.MaxSize ?? int.MaxValue) > game.StorageSpace))];
(stor.MinSize ?? int.MinValue) <= game.StorageSpace && (stor.MaxSize ?? int.MaxValue) > game.StorageSpace))
.ToList();
}
}
}

View File

@@ -4,7 +4,6 @@ using GameIdeas.Shared.Exceptions;
using GameIdeas.Shared.Model;
using GameIdeas.WebAPI.Context;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
namespace GameIdeas.WebAPI.Services.Games;
@@ -14,7 +13,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
{
var gameToCreate = mapper.Map<Game>(gameDto);
await HandleDeveloperPublisherCreation(gameToCreate);
HandleDeveloperPublisherCreation(gameToCreate);
await context.Games.AddAsync(gameToCreate);
await context.SaveChangesAsync();
@@ -36,7 +35,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
var gameToUpdate = mapper.Map<Game>(gameDto);
await HandleDeveloperPublisherCreation(gameToUpdate);
HandleDeveloperPublisherCreation(gameToUpdate);
await HandlePlatformsCreation(gameDto.Platforms, gameToUpdate.Id);
await HandlePropertiesCreation(gameDto.Properties, gameToUpdate.Id);
await HandleTagsCreation(gameDto.Tags, gameToUpdate.Id);
@@ -49,27 +48,12 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
public async Task<bool> DeleteGame(int gameId)
{
await HandlePlatformsCreation([], gameId);
await HandlePropertiesCreation([], gameId);
await HandleTagsCreation([], gameId);
var gameToRemove = await context.Games
.FirstOrDefaultAsync(g => g.Id == gameId)
?? throw new NotFoundException($"[{typeof(Game).FullName}] with ID {gameId} has not been found in context");
context.Games.Remove(gameToRemove);
await context.SaveChangesAsync();
context.Publishers.RemoveRange(
context.Publishers.Include(p => p.Games)
.Where(p => p.Games.Count == 0));
context.Developers.RemoveRange(
context.Developers.Include(d => d.Games)
.Where(d => d.Games.Count == 0));
await context.SaveChangesAsync();
return true;
return await context.SaveChangesAsync() != 0;
}
private async Task HandlePlatformsCreation(IEnumerable<PlatformDto>? categoriesToCreate, int gameId)
@@ -78,9 +62,6 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
{
var gps = mapper.Map<ICollection<GamePlatform>>(categoriesToCreate);
context.GamePlatforms.RemoveRange(
context.GamePlatforms.Where(gp => gp.GameId == gameId));
foreach (var gp in gps)
{
gp.GameId = gameId;
@@ -88,14 +69,6 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
context.Platforms.AttachRange(gps.Select(gp => gp.Platform));
await context.GamePlatforms.AddRangeAsync(gps);
await context.SaveChangesAsync();
context.Platforms.RemoveRange(
context.Platforms.Include(p => p.GamePlatforms)
.Where(p => p.GamePlatforms.Count == 0));
await context.SaveChangesAsync();
}
}
@@ -105,9 +78,6 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
{
var gps = mapper.Map<ICollection<GameProperty>>(categoriesToCreate);
context.GameProperties.RemoveRange(
context.GameProperties.Where(gp => gp.GameId == gameId));
foreach (var gp in gps)
{
gp.GameId = gameId;
@@ -115,14 +85,6 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
context.Properties.AttachRange(gps.Select(gp => gp.Property));
await context.GameProperties.AddRangeAsync(gps);
await context.SaveChangesAsync();
context.Properties.RemoveRange(
context.Properties.Include(p => p.GameProperties)
.Where(p => p.GameProperties.Count == 0));
await context.SaveChangesAsync();
}
}
@@ -132,9 +94,6 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
{
var gts = mapper.Map<ICollection<GameTag>>(categoriesToCreate);
context.GameTags.RemoveRange(
context.GameTags.Where(gt => gt.GameId == gameId));
foreach (var gt in gts)
{
gt.GameId = gameId;
@@ -142,30 +101,11 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
context.Tags.AttachRange(gts.Select(gt => gt.Tag));
await context.GameTags.AddRangeAsync(gts);
await context.SaveChangesAsync();
context.Tags.RemoveRange(
context.Tags.Include(t => t.GameTags)
.Where(t => t.GameTags.Count == 0));
await context.SaveChangesAsync();
}
}
private async Task HandleDeveloperPublisherCreation(Game? game)
private void HandleDeveloperPublisherCreation(Game? game)
{
context.Publishers.RemoveRange(
context.Publishers.Include(p => p.Games)
.Where(p => p.Games.Count == 0));
context.Developers.RemoveRange(
context.Developers.Include(d => d.Games)
.Where(d => d.Games.Count == 0));
await context.SaveChangesAsync();
if (game?.Publisher != null)
{
context.Publishers.Attach(game.Publisher);

View File

@@ -4,6 +4,6 @@ namespace GameIdeas.WebAPI.Services.Games;
public interface IGameReadService
{
Task<GameListDto> GetGames(GameFilterDto filter);
Task<IEnumerable<GameDto>> GetGames(GameFilterDto filter);
Task<GameDetailDto> GetGameById(int gameId);
}

View File

@@ -33,9 +33,8 @@ public class UserReadService(
.OrderBy(u => u.UserName)
.ToListAsync();
ApplyStaticFilter(ref users, filter);
var count = users.Count;
ApplyStaticFilter(ref users, filter);
var usersDto = mapper.Map<IEnumerable<UserDto>>(users);
usersDto = await ApplyRoles(usersDto, filter);
@@ -92,14 +91,15 @@ public class UserReadService(
.Select(k => k.Trim())
.ToArray() ?? [];
users = [.. users
users = users
.Where(user => keywords.All(
kw => user.UserName?.Contains(kw, StringComparison.OrdinalIgnoreCase) ?? true
))
.OrderBy(user => keywords.Min(kw =>
user.UserName?.IndexOf(kw, StringComparison.OrdinalIgnoreCase)
))
.ThenBy(user => user.UserName?.Length)];
.ThenBy(user => user.UserName?.Length)
.ToList();
}
}

View File

@@ -1,4 +1,5 @@
using GameIdeas.Resources;
using AutoMapper;
using GameIdeas.Resources;
using GameIdeas.Shared.Dto;
using GameIdeas.Shared.Model;
using GameIdeas.WebAPI.Exceptions;