From 4d749e2f0c8787f2fdca665f9dd3b948436a836e Mon Sep 17 00:00:00 2001 From: Mateusz Skoczek Date: Sun, 20 Oct 2024 02:58:16 +0200 Subject: [PATCH] role rating in mediapage added --- WatchIt.Website/WatchIt.Website/App.razor | 2 +- .../Panels/ActorRolesPanelComponent.razor | 8 +++- .../Panels/ActorRolesPanelComponent.razor.cs | 23 ++++++++++ .../Panels/CreatorRolesPanelComponent.razor | 6 ++- .../CreatorRolesPanelComponent.razor.cs | 9 ++++ .../Subcomponents/RoleComponent.razor | 44 ++++++++++++++++++- .../Subcomponents/RoleComponent.razor.cs | 44 ++++++++++++++----- .../Subcomponents/RoleComponent.razor.css | 26 +++++++++++ .../Subcomponents/RoleListComponent.razor | 19 +++++--- .../Subcomponents/RoleListComponent.razor.cs | 16 ++++++- 10 files changed, 172 insertions(+), 25 deletions(-) create mode 100644 WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.css diff --git a/WatchIt.Website/WatchIt.Website/App.razor b/WatchIt.Website/WatchIt.Website/App.razor index 9d4f9db..92e4b6b 100644 --- a/WatchIt.Website/WatchIt.Website/App.razor +++ b/WatchIt.Website/WatchIt.Website/App.razor @@ -13,7 +13,7 @@ - + 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 987e85b..3c37b7f 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/ActorRolesPanelComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/ActorRolesPanelComponent.razor @@ -8,7 +8,11 @@ + AdditionalTextSource="@(data => data.Name)" + GetRolesAction="@(MediaWebAPIService.GetMediaAllActorRoles)" + GetGlobalRatingAction="@((id, action) => RolesWebAPIService.GetActorRoleRating(id, action))" + GetUserRatingAction="@(_user is not null ? (id, actionSuccess, actionNotFound) => RolesWebAPIService.GetActorRoleRatingByUser(id, _user.Id, actionSuccess, actionNotFound) : null)" + PutRatingAction="(id, request) => RolesWebAPIService.PutActorRoleRating(id, request)" + DeleteRatingAction="(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 2387e7c..6d07919 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,5 +1,7 @@ using Microsoft.AspNetCore.Components; +using WatchIt.Website.Services.Utility.Authentication; using WatchIt.Website.Services.WebAPI.Media; +using WatchIt.Website.Services.WebAPI.Roles; namespace WatchIt.Website.Components.Pages.MediaPage.Panels; @@ -8,6 +10,8 @@ public partial class ActorRolesPanelComponent : ComponentBase #region SERVICES [Inject] private IMediaWebAPIService MediaWebAPIService { get; set; } = default!; + [Inject] private IRolesWebAPIService RolesWebAPIService { get; set; } = default!; + [Inject] private IAuthenticationService AuthenticationService { get; set; } = default!; #endregion @@ -19,4 +23,23 @@ public partial class ActorRolesPanelComponent : ComponentBase [Parameter] public required long Id { get; set; } #endregion + + + + #region FIELDS + + private User? _user; + + #endregion + + + + #region PRIVATE METHODS + + protected override async Task OnParametersSetAsync() + { + _user = await AuthenticationService.GetUserAsync(); + } + + #endregion } \ No newline at end of file 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 ca9d341..c47c208 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/CreatorRolesPanelComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Panels/CreatorRolesPanelComponent.razor @@ -20,8 +20,12 @@ Id="@(Id)" TRole="CreatorRoleResponse" TQuery="CreatorRoleMediaQueryParameters" + Query="@(_query)" GetRolesAction="MediaWebAPIService.GetMediaAllCreatorRoles" - Query="@(_query)"/> + GetGlobalRatingAction="@((id, action) => RolesWebAPIService.GetCreatorRoleRating(id, action))" + GetUserRatingAction="@(_user is not null ? (id, actionSuccess, actionNotFound) => RolesWebAPIService.GetCreatorRoleRatingByUser(id, _user.Id, actionSuccess, actionNotFound) : null)" + PutRatingAction="(id, request) => RolesWebAPIService.PutActorRoleRating(id, request)" + DeleteRatingAction="(id) => RolesWebAPIService.DeleteActorRoleRating(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 bea6541..181c061 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,6 +1,7 @@ using Microsoft.AspNetCore.Components; using WatchIt.Common.Model.Roles; using WatchIt.Website.Components.Pages.MediaPage.Subcomponents; +using WatchIt.Website.Services.Utility.Authentication; using WatchIt.Website.Services.WebAPI.Media; using WatchIt.Website.Services.WebAPI.Roles; @@ -12,6 +13,7 @@ public partial class CreatorRolesPanelComponent : ComponentBase [Inject] private IMediaWebAPIService MediaWebAPIService { get; set; } = default!; [Inject] private IRolesWebAPIService RolesWebAPIService { get; set; } = default!; + [Inject] private IAuthenticationService AuthenticationService { get; set; } = default!; #endregion @@ -27,6 +29,8 @@ public partial class CreatorRolesPanelComponent : ComponentBase #region FIELDS + + private User? _user; private RoleListComponent _roleListComponent; @@ -40,6 +44,11 @@ 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 index 5a7a10b..aef354b 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor @@ -4,7 +4,9 @@
- + + +
@@ -16,10 +18,48 @@ } else { - @(_person.Name)@(Role is ActorRoleResponse actor ? $" as {actor.Name}" : string.Empty) + + @(_person.Name)@(Role is ActorRoleResponse actor ? $" as {actor.Name}" : string.Empty) + }
+
+
+ Global rating: +
+ +
+ @if (_globalRating is not null) + { + @(_globalRating.Count > 0 ? _globalRating.Average : "--")/10 + if (_globalRating.Count > 0) + { + @(_globalRating.Count) + } + } + else + { +
+ } +
+
+
+
+
+ Your rating: +
+ @if (_authenticated) + { + + } + else + { + You must be logged in to rate the role + } +
+
+
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 index 2f60032..fc7f7d0 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.cs @@ -1,7 +1,9 @@ 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; @@ -11,6 +13,7 @@ public partial class RoleComponent : ComponentBase where TRole : IRoleRes #region SERVICES [Inject] private IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!; + [Inject] private IAuthenticationService AuthenticationService { get; set; } = default!; #endregion @@ -19,6 +22,10 @@ public partial class RoleComponent : ComponentBase where TRole : IRoleRes #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 @@ -26,8 +33,12 @@ public partial class RoleComponent : ComponentBase where TRole : IRoleRes #region FIELDS + private bool _authenticated; private PersonResponse? _person; - private Picture? _picture; + private Picture? _picture; + private RatingResponse? _globalRating; + + private int _yourRating; #endregion @@ -44,22 +55,33 @@ public partial class RoleComponent : ComponentBase where TRole : IRoleRes // STEP 0 endTasks.AddRange( [ - PersonsWebAPIService.GetPersonPhoto(Role.PersonId, data => - { - _picture = data; - StateHasChanged(); - }), - PersonsWebAPIService.GetPerson(Role.PersonId, data => - { - _person = data; - StateHasChanged(); - }) + Task.Run(async () => _authenticated = await AuthenticationService.GetAuthenticationStatusAsync()), + PersonsWebAPIService.GetPersonPhoto(Role.PersonId, data => _picture = data), + PersonsWebAPIService.GetPerson(Role.PersonId, data => _person = data), + GetGlobalRatingAction(Role.Id, data => _globalRating = data), + GetUserRatingAction(Role.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 new file mode 100644 index 0000000..9179236 --- /dev/null +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleComponent.razor.css @@ -0,0 +1,26 @@ +/* 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 index d5fce9b..f16167c 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor @@ -8,14 +8,19 @@
@for (int i = 0; i < _roles.Count; i++) { - if (i > 0) { -
- } - + int iCopy = i; + if (i > 0) + { +
+ } -
+ Role="@(_roles[i])" + GetGlobalRatingAction="@(GetGlobalRatingAction)" + GetUserRatingAction="@(GetUserRatingAction)" + PutRatingAction="@(PutRatingAction)" + DeleteRatingAction="@(DeleteRatingAction)"/> + } } @if (!_allItemsLoaded) { @@ -36,5 +41,5 @@ } 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/Pages/MediaPage/Subcomponents/RoleListComponent.razor.cs index a671fb4..9709e74 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/MediaPage/Subcomponents/RoleListComponent.razor.cs @@ -1,5 +1,6 @@ using System.ComponentModel; using Microsoft.AspNetCore.Components; +using WatchIt.Common.Model.Rating; using WatchIt.Common.Model.Roles; using WatchIt.Common.Query; @@ -7,12 +8,25 @@ namespace WatchIt.Website.Components.Pages.MediaPage.Subcomponents; public partial class RoleListComponent : ComponentBase where TRole : IRoleResponse, IQueryOrderable where TQuery : QueryParameters { + #region SERVICES + + [Inject] private NavigationManager NavigationManager { get; set; } = default!; + + #endregion + + + #region PROPERTIES [Parameter] public required long Id { get; set; } - [Parameter] public required Func>, Task> GetRolesAction { 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; } #endregion