From fd38d899c982db4b3443dbca79ba4acf79b7643c Mon Sep 17 00:00:00 2001 From: Mateusz Skoczek Date: Thu, 24 Oct 2024 23:15:09 +0200 Subject: [PATCH] PersonMetadataPanel created, RoleListComponent rebuilded and separated from MediaPage --- WatchIt.Website/WatchIt.Website/App.razor | 2 +- .../Subcomponents/ListItemComponent.razor | 52 ++++++--- .../Subcomponents/ListItemComponent.razor.cs | 96 +++++++++++++++-- .../Subcomponents/ListItemComponent.razor.css | 17 +-- .../Subcomponents/RoleListComponent.razor | 58 ++++++++++ .../Subcomponents/RoleListComponent.razor.cs | 56 ++++++---- .../DatabasePage/DatabasePageComponent.razor | 19 ++-- .../DatabasePageComponent.razor.cs | 6 ++ .../Panels/ActorRolesPanelComponent.razor | 26 +++-- .../Panels/ActorRolesPanelComponent.razor.cs | 2 + .../Panels/CreatorRolesPanelComponent.razor | 23 ++-- .../CreatorRolesPanelComponent.razor.cs | 17 ++- .../Subcomponents/RoleComponent.razor | 52 --------- .../Subcomponents/RoleComponent.razor.cs | 100 ------------------ .../Subcomponents/RoleComponent.razor.css | 26 ----- .../Subcomponents/RoleListComponent.razor | 45 -------- .../Subcomponents/RoleListComponent.razor.css | 0 .../Panels/PersonMetadataPanel.razor | 16 +++ .../Panels/PersonMetadataPanel.razor.cs | 13 +++ .../Panels/SearchResultPanelComponent.razor | 22 ++-- .../SearchResultPanelComponent.razor.cs | 7 ++ .../WatchIt.Website/Pages/DatabasePage.razor | 18 +++- .../WatchIt.Website/Pages/MediaPage.razor | 4 +- .../WatchIt.Website/Pages/PersonPage.razor | 27 ++++- .../WatchIt.Website/Pages/SearchPage.razor | 18 +++- .../WatchIt.Website/WatchIt.Website.csproj | 1 + .../WatchIt.Website/wwwroot/css/general.css | 13 +++ 27 files changed, 403 insertions(+), 333 deletions(-) create mode 100644 WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/RoleListComponent.razor rename WatchIt.Website/WatchIt.Website/Components/{Pages/MediaPage => Common}/Subcomponents/RoleListComponent.razor.cs (50%) delete mode 100644 WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor delete mode 100644 WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.cs delete mode 100644 WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.css delete mode 100644 WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor delete mode 100644 WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor.css create mode 100644 WatchIt.Website/WatchIt.Website/Components/Pages/PersonPage/Panels/PersonMetadataPanel.razor create mode 100644 WatchIt.Website/WatchIt.Website/Components/Pages/PersonPage/Panels/PersonMetadataPanel.razor.cs diff --git a/WatchIt.Website/WatchIt.Website/App.razor b/WatchIt.Website/WatchIt.Website/App.razor index c54fec3..e5cba46 100644 --- a/WatchIt.Website/WatchIt.Website/App.razor +++ b/WatchIt.Website/WatchIt.Website/App.razor @@ -9,7 +9,7 @@ - + diff --git a/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor b/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor index 7f48f38..42b9837 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor @@ -1,24 +1,50 @@
- + + +
- - @(Name)@(string.IsNullOrWhiteSpace(AdditionalNameInfo) ? string.Empty : AdditionalNameInfo) - + + @(Name)@(string.IsNullOrWhiteSpace(AdditionalInfo) ? string.Empty : AdditionalInfo) +
-
- -
- @(Rating.Count > 0 ? Rating.Average : "--")/10 - @if (Rating.Count > 0) - { - @(Rating.Count) - } -
+
+ +
+ Global rating: + +
+
+ @if (GetUserRatingMethod is not null && PutRatingMethod is not null && DeleteRatingMethod is not null) + { +
+
+ Your rating: +
+ @if (_user is null) + { + You must be logged in to rate + } + else if (!_userRatingLoaded) + { +
+ + Loading... +
+ } + else + { + + } +
+
+ }
diff --git a/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor.cs b/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor.cs index f96cf4b..818f3ee 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor.cs @@ -1,29 +1,52 @@ using Microsoft.AspNetCore.Components; using WatchIt.Common.Model; using WatchIt.Common.Model.Rating; +using WatchIt.Website.Services.Utility.Authentication; namespace WatchIt.Website.Components.Common.Subcomponents; public partial class ListItemComponent : ComponentBase { + #region SERVICES + + [Inject] private IAuthenticationService AuthenticationService { get; set; } = default!; + + #endregion + + + #region PARAMETERS - [Parameter] public required long Id { get; set; } [Parameter] public required string Name { get; set; } - [Parameter] public string? AdditionalNameInfo { get; set; } - [Parameter] public required RatingResponse Rating { get; set; } - [Parameter] public required Func, Task> PictureDownloadingTask { get; set; } - [Parameter] public int PictureHeight { get; set; } = 150; + [Parameter] public string? AdditionalInfo { get; set; } + + [Parameter] public int NameSize { get; set; } = 25; + + [Parameter] public required string PosterPlaceholder { get; set; } + [Parameter] public int PosterHeight { get; set; } = 150; + [Parameter] public required Func, Task> PosterDownloadingTask { get; set; } + + [Parameter] public RatingResponse? GlobalRating { get; set; } + [Parameter] public required Func, Task> GetGlobalRatingMethod { get; set; } + [Parameter] public Func, Action, Task>? GetUserRatingMethod { get; set; } + [Parameter] public Func? PutRatingMethod { get; set; } + [Parameter] public Func? DeleteRatingMethod { get; set; } + [Parameter] public Action? OnRatingChanged { get; set; } + + [Parameter] public required string ItemUrl { get; set; } #endregion #region FIELDS - - private bool _loaded; - private Picture? _picture; + private User? _user; + + private Picture? _poster; + + private int _userRating; + private bool _userRatingLoaded; #endregion @@ -35,20 +58,71 @@ public partial class ListItemComponent : ComponentBase { if (firstRender) { - List endTasks = new List(); + List step1Tasks = new List(1); + List endTasks = new List(3); // STEP 0 + if (GetUserRatingMethod is not null) + { + step1Tasks.AddRange( + [ + Task.Run(async () => _user = await AuthenticationService.GetUserAsync()), + ]); + } endTasks.AddRange( [ - PictureDownloadingTask(Id, picture => _picture = picture), + PosterDownloadingTask(data => _poster = data), ]); + if (GlobalRating is null) + { + endTasks.AddRange( + [ + GetGlobalRatingMethod(data => GlobalRating = data), + ]); + } + + // STEP 1 + await Task.WhenAll(step1Tasks); + StateHasChanged(); + if (GetUserRatingMethod is not null && _user is not null) + { + endTasks.AddRange( + [ + GetUserRatingMethod(_user.Id, + data => + { + _userRating = data; + _userRatingLoaded = true; + }, + () => + { + _userRating = 0; + _userRatingLoaded = true; + } + ) + ]); + } await Task.WhenAll(endTasks); - _loaded = true; StateHasChanged(); } } + + private async Task RatingChanged() + { + if (_userRating == 0) + { + await DeleteRatingMethod!(); + } + else + { + await PutRatingMethod!(new RatingRequest((short)_userRating)); + } + + await GetGlobalRatingMethod(data => GlobalRating = data); + OnRatingChanged?.Invoke(); + } #endregion } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor.css b/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor.css index 91b920c..7c26de1 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor.css +++ b/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/ListItemComponent.razor.css @@ -1,17 +1,10 @@ /* IDS */ -#nameText { - font-size: 25px; +#ratingNameText { + font-size: 14px; + font-weight: bold; } -#ratingStar { - font-size: 30px; -} - -#ratingValue { - font-size: 20px; -} - -#ratingCount { - font-size: 10px; +#ratingLoginInfoText { + font-size: 13px; } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/RoleListComponent.razor b/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/RoleListComponent.razor new file mode 100644 index 0000000..01b8398 --- /dev/null +++ b/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/RoleListComponent.razor @@ -0,0 +1,58 @@ +@typeparam TRole where TRole : WatchIt.Common.Model.Roles.IRoleResponse, WatchIt.Common.Query.IQueryOrderable +@typeparam TQuery where TQuery : WatchIt.Common.Query.QueryParameters +@typeparam TRoleParent + + + +@if (_loaded) +{ + if (_roles.Count > 0) + { +
+ @for (int i = 0; i < _roles.Count; i++) + { + { + int iCopy = i; + KeyValuePair roleParentPair = _roles.ElementAt(i); + TRole role = roleParentPair.Key; + TRoleParent parent = roleParentPair.Value; + string url = string.Format(ParentUrlTemplate, ParentItemIdSource(role)); + if (i > 0) + { +
+ } + + } + } + @if (!_allItemsLoaded) + { +
+ +
+ } +
+ } + else + { + No roles found + } +} +else +{ + +} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor.cs b/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/RoleListComponent.razor.cs similarity index 50% rename from WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor.cs rename to WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/RoleListComponent.razor.cs index da39771..a44624f 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Components/Common/Subcomponents/RoleListComponent.razor.cs @@ -1,33 +1,35 @@ -using System.ComponentModel; using Microsoft.AspNetCore.Components; +using WatchIt.Common.Model; using WatchIt.Common.Model.Rating; -using WatchIt.Common.Model.Roles; -using WatchIt.Common.Query; -namespace WatchIt.Website.Components.Pages.MediaPage.Subcomponents; +namespace WatchIt.Website.Components.Common.Subcomponents; -public partial class RoleListComponent : ComponentBase where TRole : IRoleResponse, IQueryOrderable where TQuery : QueryParameters +public partial class RoleListComponent : ComponentBase where TRole : WatchIt.Common.Model.Roles.IRoleResponse, WatchIt.Common.Query.IQueryOrderable + where TQuery : WatchIt.Common.Query.QueryParameters { - #region SERVICES - - [Inject] private NavigationManager NavigationManager { get; set; } = default!; - - #endregion - - - #region PARAMETERS [Parameter] public required long Id { get; set; } [Parameter] public TQuery Query { get; set; } = Activator.CreateInstance(); - [Parameter] public Func? AdditionalTextSource { get; set; } - [Parameter] public required Func>, Task> GetRolesAction { get; set; } - [Parameter] public required Func, Task> GetGlobalRatingAction { get; set; } - [Parameter] public required Func, Action, Task> GetUserRatingAction { get; set; } - [Parameter] public required Func PutRatingAction { get; set; } - [Parameter] public required Func DeleteRatingAction { get; set; } - + + [Parameter] public required Func NameSource { get; set; } + [Parameter] public Func? AdditionalInfoSource { get; set; } + + [Parameter] public required Func, Task> GetRoleParentMethod { get; set; } + [Parameter] public required Func ParentItemIdSource { get; set; } + [Parameter] public required string ParentUrlTemplate { get; set; } + + [Parameter] public required string PosterPlaceholder { get; set; } + [Parameter] public required Func, Task> PosterDownloadingTask { get; set; } + + [Parameter] public required Func, Task> GetGlobalRatingMethod { get; set; } + [Parameter] public required Func, Action, Task> GetUserRatingMethod { get; set; } + [Parameter] public required Func PutRatingMethod { get; set; } + [Parameter] public required Func DeleteRatingMethod { get; set; } + + [Parameter] public Action? OnRatingChanged { get; set; } + #endregion @@ -39,7 +41,7 @@ public partial class RoleListComponent : ComponentBase where TRol private bool _loaded; private bool _allItemsLoaded; - private List _roles = new List(); + private Dictionary _roles = new Dictionary(); private bool _rolesFetching; #endregion @@ -72,6 +74,7 @@ public partial class RoleListComponent : ComponentBase where TRol // INIT Query.First = _pageSize; + Query.OrderBy = "rating.average"; // STEP 0 endTasks.AddRange( @@ -90,9 +93,15 @@ public partial class RoleListComponent : ComponentBase where TRol private async Task GetRoles(bool firstFetch = false) { _rolesFetching = true; - await GetRolesAction(Id, Query, data => + await GetRolesAction(Id, Query, async data => { - _roles.AddRange(data); + List newRolesArray = data.ToList(); + Dictionary newRoles = new Dictionary(); + await Parallel.ForEachAsync(data, new ParallelOptions { MaxDegreeOfParallelism = 4 }, async (item, _) => await GetRoleParentMethod(ParentItemIdSource(item), parent => newRoles[item] = parent)); + foreach (KeyValuePair kvp in newRoles.OrderBy(x => newRolesArray.IndexOf(x.Key))) + { + _roles[kvp.Key] = kvp.Value; + } if (data.Count() < _pageSize) { _allItemsLoaded = true; @@ -106,6 +115,7 @@ public partial class RoleListComponent : ComponentBase where TRol } Query.After += data.Count(); _rolesFetching = false; + StateHasChanged(); }); } diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/DatabasePage/DatabasePageComponent.razor b/WatchIt.Website/WatchIt.Website/Components/Pages/DatabasePage/DatabasePageComponent.razor index 2df7f44..0a3738a 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/DatabasePage/DatabasePageComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/DatabasePage/DatabasePageComponent.razor @@ -52,12 +52,19 @@ { foreach (TItem item in _items) { -
- + long id = IdSource(item); + string url = string.Format(UrlIdTemplate, id); +
+
} if (!_allItemsLoaded) diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/DatabasePage/DatabasePageComponent.razor.cs b/WatchIt.Website/WatchIt.Website/Components/Pages/DatabasePage/DatabasePageComponent.razor.cs index 2bb0928..6d07ab9 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/DatabasePage/DatabasePageComponent.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/DatabasePage/DatabasePageComponent.razor.cs @@ -28,6 +28,12 @@ public partial class DatabasePageComponent : ComponentBase where [Parameter] public required Func>, Task> ItemDownloadingTask { get; set; } [Parameter] public required Dictionary SortingOptions { get; set; } [Parameter] public required RenderFragment ChildContent { get; set; } + [Parameter] public required Func, Task> GetGlobalRatingMethod { get; set; } + [Parameter] public Func, Action, Task>? GetUserRatingMethod { get; set; } + [Parameter] public Func? PutRatingMethod { get; set; } + [Parameter] public Func? DeleteRatingMethod { get; set; } + [Parameter] public required string PosterPlaceholder { get; set; } + #endregion diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/ActorRolesPanelComponent.razor b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/ActorRolesPanelComponent.razor index 8b32774..9f1a1df 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/ActorRolesPanelComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/ActorRolesPanelComponent.razor @@ -1,18 +1,26 @@ -@using WatchIt.Website.Components.Pages.MediaPage.Subcomponents +@using WatchIt.Common.Model.Persons +@using WatchIt.Common.Model.Roles
Actors - + NameSource="@((_, parent) => parent.Name)" + AdditionalInfoSource="@((item, _) => $" as {item.Name}")" + GetRoleParentMethod="@((id, action) => PersonsWebAPIService.GetPerson(id, action))" + ParentItemIdSource="@(item => item.PersonId)" + ParentUrlTemplate="/person/{0}" + PosterPlaceholder="/assets/person_poster.png" + PosterDownloadingTask="@((id, action) => PersonsWebAPIService.GetPersonPhoto(id, action))" + GetGlobalRatingMethod="@((id, action) => RolesWebAPIService.GetActorRoleRating(id, action))" + GetUserRatingMethod="@((id, userId, actionSuccess, actionNotFound) => RolesWebAPIService.GetActorRoleRatingByUser(id, userId, actionSuccess, actionNotFound))" + PutRatingMethod="@((id, request) => RolesWebAPIService.PutActorRoleRating(id, request))" + DeleteRatingMethod="@(id => RolesWebAPIService.DeleteActorRoleRating(id))"/>
\ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/ActorRolesPanelComponent.razor.cs b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/ActorRolesPanelComponent.razor.cs index 5cd65b7..023869c 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/ActorRolesPanelComponent.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/ActorRolesPanelComponent.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using WatchIt.Website.Services.Utility.Authentication; using WatchIt.Website.Services.WebAPI.Media; +using WatchIt.Website.Services.WebAPI.Persons; using WatchIt.Website.Services.WebAPI.Roles; namespace WatchIt.Website.Components.Pages.MediaPage.Panels; @@ -10,6 +11,7 @@ public partial class ActorRolesPanelComponent : ComponentBase #region SERVICES [Inject] private IMediaWebAPIService MediaWebAPIService { get; set; } = default!; + [Inject] private IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!; [Inject] private IRolesWebAPIService RolesWebAPIService { get; set; } = default!; #endregion diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/CreatorRolesPanelComponent.razor b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/CreatorRolesPanelComponent.razor index 29a7c51..3361227 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/CreatorRolesPanelComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/CreatorRolesPanelComponent.razor @@ -1,5 +1,5 @@ +@using WatchIt.Common.Model.Persons @using WatchIt.Common.Model.Roles -@using WatchIt.Website.Components.Pages.MediaPage.Subcomponents @@ -16,16 +16,23 @@ }
- + GetRolesAction="@(MediaWebAPIService.GetMediaAllCreatorRoles)" + NameSource="@((_, parent) => parent.Name)" + GetRoleParentMethod="@((id, action) => PersonsWebAPIService.GetPerson(id, action))" + ParentItemIdSource="@(item => item.PersonId)" + ParentUrlTemplate="/person/{0}" + PosterPlaceholder="/assets/person_poster.png" + PosterDownloadingTask="@((id, action) => PersonsWebAPIService.GetPersonPhoto(id, action))" + GetGlobalRatingMethod="@((id, action) => RolesWebAPIService.GetCreatorRoleRating(id, action))" + GetUserRatingMethod="@((id, userId, actionSuccess, actionNotFound) => RolesWebAPIService.GetCreatorRoleRatingByUser(id, userId, actionSuccess, actionNotFound))" + PutRatingMethod="@((id, request) => RolesWebAPIService.PutCreatorRoleRating(id, request))" + DeleteRatingMethod="@((id) => RolesWebAPIService.DeleteCreatorRoleRating(id))"/>
} else diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/CreatorRolesPanelComponent.razor.cs b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/CreatorRolesPanelComponent.razor.cs index 181c061..8c84b65 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/CreatorRolesPanelComponent.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/CreatorRolesPanelComponent.razor.cs @@ -1,8 +1,10 @@ using Microsoft.AspNetCore.Components; +using WatchIt.Common.Model.Persons; using WatchIt.Common.Model.Roles; -using WatchIt.Website.Components.Pages.MediaPage.Subcomponents; +using WatchIt.Website.Components.Common.Subcomponents; using WatchIt.Website.Services.Utility.Authentication; using WatchIt.Website.Services.WebAPI.Media; +using WatchIt.Website.Services.WebAPI.Persons; using WatchIt.Website.Services.WebAPI.Roles; namespace WatchIt.Website.Components.Pages.MediaPage.Panels; @@ -10,10 +12,10 @@ namespace WatchIt.Website.Components.Pages.MediaPage.Panels; public partial class CreatorRolesPanelComponent : ComponentBase { #region SERVICES - + + [Inject] private IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!; [Inject] private IMediaWebAPIService MediaWebAPIService { get; set; } = default!; [Inject] private IRolesWebAPIService RolesWebAPIService { get; set; } = default!; - [Inject] private IAuthenticationService AuthenticationService { get; set; } = default!; #endregion @@ -29,10 +31,8 @@ public partial class CreatorRolesPanelComponent : ComponentBase #region FIELDS - - private User? _user; - private RoleListComponent _roleListComponent; + private RoleListComponent _roleListComponent; private bool _loaded; @@ -44,11 +44,6 @@ public partial class CreatorRolesPanelComponent : ComponentBase #region PRIVATE METHODS - - protected override async Task OnParametersSetAsync() - { - _user = await AuthenticationService.GetUserAsync(); - } protected override async Task OnAfterRenderAsync(bool firstRender) { diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor deleted file mode 100644 index fbef83b..0000000 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor +++ /dev/null @@ -1,52 +0,0 @@ -@using WatchIt.Common.Model.Roles -@typeparam TRole where TRole : WatchIt.Common.Model.Roles.IRoleResponse - -
-
-
- - - -
-
-
-
- - @if (_person is null) - { - Loading... - } - else - { - - @(_person.Name)@(Role is ActorRoleResponse actor ? $" as {actor.Name}" : string.Empty) - - } - -
-
-
- Global rating: - -
-
-
- Your rating: -
- @if (_user is not null) - { - - } - else - { - You must be logged in to rate the role - } -
-
-
-
-
-
-
\ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.cs b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.cs deleted file mode 100644 index fe7d00d..0000000 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.cs +++ /dev/null @@ -1,100 +0,0 @@ -using Microsoft.AspNetCore.Components; -using WatchIt.Common.Model; -using WatchIt.Common.Model.Persons; -using WatchIt.Common.Model.Rating; -using WatchIt.Common.Model.Roles; -using WatchIt.Website.Services.Utility.Authentication; -using WatchIt.Website.Services.WebAPI.Persons; - -namespace WatchIt.Website.Components.Pages.MediaPage.Subcomponents; - -public partial class RoleComponent : ComponentBase where TRole : IRoleResponse -{ - #region SERVICES - - [Inject] private IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!; - [Inject] private IAuthenticationService AuthenticationService { get; set; } = default!; - - #endregion - - - - #region PARAMETERS - - [Parameter] public required TRole Role { get; set; } - [Parameter] public required Func, Task> GetGlobalRatingAction { get; set; } - [Parameter] public required Func, Action, Task> GetUserRatingAction { get; set; } - [Parameter] public required Func PutRatingAction { get; set; } - [Parameter] public required Func DeleteRatingAction { get; set; } - - #endregion - - - - #region FIELDS - - private User? _user; - private PersonResponse? _person; - private Picture? _picture; - private RatingResponse? _globalRating; - - private int _yourRating; - - #endregion - - - - #region PRIVATE METHODS - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - { - List step1Tasks = new List(); - List endTasks = new List(); - - // STEP 0 - step1Tasks.AddRange( - [ - Task.Run(async () => _user = await AuthenticationService.GetUserAsync()), - ]); - endTasks.AddRange( - [ - PersonsWebAPIService.GetPersonPhoto(Role.PersonId, data => _picture = data), - PersonsWebAPIService.GetPerson(Role.PersonId, data => _person = data), - GetGlobalRatingAction(Role.Id, data => _globalRating = data) - ]); - - // STEP 1 - await Task.WhenAll(step1Tasks); - if (_user is not null) - { - endTasks.AddRange( - [ - GetUserRatingAction(Role.Id, _user.Id, data => _yourRating = data, () => _yourRating = 0) - ]); - } - - // END - await Task.WhenAll(endTasks); - - StateHasChanged(); - } - } - - private async Task RatingChanged() - { - if (_yourRating == 0) - { - await DeleteRatingAction(Role.Id); - } - else - { - await PutRatingAction(Role.Id, new RatingRequest((short)_yourRating)); - } - - await GetGlobalRatingAction(Role.Id, data => _globalRating = data); - } - - #endregion -} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.css b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.css deleted file mode 100644 index 9179236..0000000 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.css +++ /dev/null @@ -1,26 +0,0 @@ -/* IDS */ - -#nameText { - font-size: 20px; -} - -#ratingNameText { - font-size: 14px; - font-weight: bold; -} - -#ratingLoginInfoText { - font-size: 13px; -} - -#ratingStar { - font-size: 30px; -} - -#ratingValue { - font-size: 20px; -} - -#ratingCount { - font-size: 10px; -} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor deleted file mode 100644 index f16167c..0000000 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor +++ /dev/null @@ -1,45 +0,0 @@ -@typeparam TRole where TRole : WatchIt.Common.Model.Roles.IRoleResponse, WatchIt.Common.Query.IQueryOrderable -@typeparam TQuery where TQuery : WatchIt.Common.Query.QueryParameters - -@if (_loaded) -{ - if (_roles.Count > 0) - { -
- @for (int i = 0; i < _roles.Count; i++) - { - { - int iCopy = i; - if (i > 0) - { -
- } - - } - } - @if (!_allItemsLoaded) - { -
- -
- } -
- } - else - { - No roles found - } -} -else -{ - -} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor.css b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor.css deleted file mode 100644 index e69de29..0000000 diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/PersonPage/Panels/PersonMetadataPanel.razor b/WatchIt.Website/WatchIt.Website/Components/Pages/PersonPage/Panels/PersonMetadataPanel.razor new file mode 100644 index 0000000..331fec5 --- /dev/null +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/PersonPage/Panels/PersonMetadataPanel.razor @@ -0,0 +1,16 @@ +
+ +
\ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/PersonPage/Panels/PersonMetadataPanel.razor.cs b/WatchIt.Website/WatchIt.Website/Components/Pages/PersonPage/Panels/PersonMetadataPanel.razor.cs new file mode 100644 index 0000000..03abb8b --- /dev/null +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/PersonPage/Panels/PersonMetadataPanel.razor.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Components; +using WatchIt.Common.Model.Persons; + +namespace WatchIt.Website.Components.Pages.PersonPage.Panels; + +public partial class PersonMetadataPanel : ComponentBase +{ + #region PARAMETERS + + [Parameter] public required PersonResponse Item { get; set; } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/SearchPage/Panels/SearchResultPanelComponent.razor b/WatchIt.Website/WatchIt.Website/Components/Pages/SearchPage/Panels/SearchResultPanelComponent.razor index e899426..c0a7d47 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/SearchPage/Panels/SearchResultPanelComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/SearchPage/Panels/SearchResultPanelComponent.razor @@ -28,13 +28,21 @@ }
- - - + @{ + int iCopy = i; + long id = IdSource(_items[iCopy]); + string url = string.Format(UrlIdTemplate, id); + } +
} diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/SearchPage/Panels/SearchResultPanelComponent.razor.cs b/WatchIt.Website/WatchIt.Website/Components/Pages/SearchPage/Panels/SearchResultPanelComponent.razor.cs index 428f4fe..e3f2f68 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/SearchPage/Panels/SearchResultPanelComponent.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/SearchPage/Panels/SearchResultPanelComponent.razor.cs @@ -11,11 +11,18 @@ public partial class SearchResultPanelComponent : ComponentBase w [Parameter] public required string Title { get; set; } [Parameter] public required TQuery Query { get; set; } + [Parameter] public required Func IdSource { get; set; } [Parameter] public required Func NameSource { get; set; } [Parameter] public Func AdditionalNameInfoSource { get; set; } = _ => null; [Parameter] public required Func RatingSource { get; set; } + [Parameter] public required Func, Task> GetGlobalRatingMethod { get; set; } + [Parameter] public Func, Action, Task>? GetUserRatingMethod { get; set; } + [Parameter] public Func? PutRatingMethod { get; set; } + [Parameter] public Func? DeleteRatingMethod { get; set; } [Parameter] public required string UrlIdTemplate { get; set; } + [Parameter] public required string PosterPlaceholder { get; set; } + [Parameter] public required Func>, Task> ItemDownloadingTask { get; set; } [Parameter] public required Func, Task> PictureDownloadingTask { get; set; } diff --git a/WatchIt.Website/WatchIt.Website/Pages/DatabasePage.razor b/WatchIt.Website/WatchIt.Website/Pages/DatabasePage.razor index 0d46cb7..5740ae8 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/DatabasePage.razor +++ b/WatchIt.Website/WatchIt.Website/Pages/DatabasePage.razor @@ -46,7 +46,12 @@ { "rating.average", "Average rating" }, { "title", "Title" }, { "release_date", "Release date" }, - })"> + })" + PosterPlaceholder="/assets/media_poster.png" + GetGlobalRatingMethod="@((id, action) => MediaWebAPIService.GetMediaRating(id, action))" + GetUserRatingMethod="@((id, userId, successAction, notfoundAction) => MediaWebAPIService.GetMediaRatingByUser(id, userId, successAction, notfoundAction))" + PutRatingMethod="@((id, request) => MediaWebAPIService.PutMediaRating(id, request))" + DeleteRatingMethod="@(id => MediaWebAPIService.DeleteMediaRating(id))"> break; @@ -67,7 +72,12 @@ { "rating.average", "Average rating" }, { "title", "Title" }, { "release_date", "Release date" }, - })"> + })" + PosterPlaceholder="/assets/media_poster.png" + GetGlobalRatingMethod="@((id, action) => MediaWebAPIService.GetMediaRating(id, action))" + GetUserRatingMethod="@((id, userId, successAction, notfoundAction) => MediaWebAPIService.GetMediaRatingByUser(id, userId, successAction, notfoundAction))" + PutRatingMethod="@((id, request) => MediaWebAPIService.PutMediaRating(id, request))" + DeleteRatingMethod="@(id => MediaWebAPIService.DeleteMediaRating(id))"> break; @@ -88,7 +98,9 @@ { "name", "Name" }, { "birth_date", "Birth date" }, { "death_date", "Death date" }, - })"> + })" + PosterPlaceholder="/assets/person_poster.png" + GetGlobalRatingMethod="@((id, action) => PersonsWebAPIService.GetPersonGlobalRating(id, action))"> break; diff --git a/WatchIt.Website/WatchIt.Website/Pages/MediaPage.razor b/WatchIt.Website/WatchIt.Website/Pages/MediaPage.razor index ec8b3dc..a295da4 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/MediaPage.razor +++ b/WatchIt.Website/WatchIt.Website/Pages/MediaPage.razor @@ -45,7 +45,7 @@ else
-
+