Merge pull request #124 from mateuszskoczek/features/media_page_roles_rating

role rating in mediapage added
This commit is contained in:
2024-10-20 02:59:51 +02:00
committed by GitHub
Unverified
10 changed files with 172 additions and 25 deletions

View File

@@ -13,7 +13,7 @@
<link rel="stylesheet" href="css/panel.css?version=0.3.0.3"/>
<link rel="stylesheet" href="css/main_button.css?version=0.3.0.0"/>
<link rel="stylesheet" href="css/gaps.css?version=0.3.0.1"/>
<link rel="stylesheet" href="WatchIt.Website.styles.css?version=0.2.0.13"/>
<link rel="stylesheet" href="WatchIt.Website.styles.css?version=0.3.0.16"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- BOOTSTRAP -->

View File

@@ -8,7 +8,11 @@
<RoleListComponent Id="@(Id)"
TRole="WatchIt.Common.Model.Roles.ActorRoleResponse"
TQuery="WatchIt.Common.Model.Roles.ActorRoleMediaQueryParameters"
GetRolesAction="MediaWebAPIService.GetMediaAllActorRoles"
AdditionalTextSource="@(data => data.Name)"/>
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)"/>
</div>
</div>

View File

@@ -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
}

View File

@@ -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)"/>
</div>
}
else

View File

@@ -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<CreatorRoleResponse, CreatorRoleMediaQueryParameters> _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)
{

View File

@@ -4,7 +4,9 @@
<div class="container-grid">
<div class="row">
<div class="col-auto">
<PictureComponent Picture="@(_picture)" Placeholder="/assets/person_poster.png" AlternativeText="poster" Height="100"/>
<a class="text-reset text-decoration-none" href="/person/@(Role.PersonId)">
<PictureComponent Picture="@(_picture)" Placeholder="/assets/person_poster.png" AlternativeText="poster" Height="110"/>
</a>
</div>
<div class="col">
<div class="d-flex align-items-start flex-column h-100">
@@ -16,10 +18,48 @@
}
else
{
<strong>@(_person.Name)</strong>@(Role is ActorRoleResponse actor ? $" as {actor.Name}" : string.Empty)
<a class="text-reset text-decoration-none" href="/person/@(Role.PersonId)">
<strong>@(_person.Name)</strong>@(Role is ActorRoleResponse actor ? $" as {actor.Name}" : string.Empty)
</a>
}
</span>
</div>
<div class="d-inline-flex gap-3">
<div class="vstack">
<span id="ratingNameText">Global rating:</span>
<div class="hstack gap-2">
<span id="ratingStar">★</span>
<div class="d-inline-flex flex-column justify-content-center">
@if (_globalRating is not null)
{
<span id="ratingValue">@(_globalRating.Count > 0 ? _globalRating.Average : "--")/10</span>
if (_globalRating.Count > 0)
{
<span id="ratingCount">@(_globalRating.Count)</span>
}
}
else
{
<div class="spinner-border spinner-border-sm text-light"></div>
}
</div>
</div>
</div>
<div class="vr"></div>
<div class="vstack">
<span id="ratingNameText">Your rating:</span>
<div class="d-inline-flex align-items-center h-100">
@if (_authenticated)
{
<Rating Color="Color.Light" MaxValue="10" @bind-SelectedValue="@(_yourRating)" @onclick="@(RatingChanged)"/>
}
else
{
<span id="ratingLoginInfoText">You must be logged in to rate the role</span>
}
</div>
</div>
</div>
</div>
</div>
</div>

View File

@@ -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<TRole> : 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<TRole> : ComponentBase where TRole : IRoleRes
#region PARAMETERS
[Parameter] public required TRole Role { get; set; }
[Parameter] public required Func<Guid, Action<RatingResponse>, Task> GetGlobalRatingAction { get; set; }
[Parameter] public required Func<Guid, Action<short>, Action, Task> GetUserRatingAction { get; set; }
[Parameter] public required Func<Guid, RatingRequest, Task> PutRatingAction { get; set; }
[Parameter] public required Func<Guid, Task> DeleteRatingAction { get; set; }
#endregion
@@ -26,8 +33,12 @@ public partial class RoleComponent<TRole> : 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<TRole> : 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
}

View File

@@ -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;
}

View File

@@ -8,14 +8,19 @@
<div class="vstack">
@for (int i = 0; i < _roles.Count; i++)
{
if (i > 0)
{
<hr/>
}
<a class="text-reset text-decoration-none" href="/person/@(_roles[i].PersonId)">
int iCopy = i;
if (i > 0)
{
<hr/>
}
<RoleComponent TRole="TRole"
Role="@(_roles[i])"/>
</a>
Role="@(_roles[i])"
GetGlobalRatingAction="@(GetGlobalRatingAction)"
GetUserRatingAction="@(GetUserRatingAction)"
PutRatingAction="@(PutRatingAction)"
DeleteRatingAction="@(DeleteRatingAction)"/>
}
}
@if (!_allItemsLoaded)
{
@@ -36,5 +41,5 @@
}
else
{
<LoadingComponent/>
<LoadingComponent Color="LoadingComponent.LoadingComponentColors.Light"/>
}

View File

@@ -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<TRole, TQuery> : ComponentBase where TRole : IRoleResponse, IQueryOrderable<TRole> where TQuery : QueryParameters<TRole>
{
#region SERVICES
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
#endregion
#region PROPERTIES
[Parameter] public required long Id { get; set; }
[Parameter] public required Func<long, TQuery, Action<IEnumerable<TRole>>, Task> GetRolesAction { get; set; }
[Parameter] public TQuery Query { get; set; } = Activator.CreateInstance<TQuery>();
[Parameter] public Func<TRole, string>? AdditionalTextSource { get; set; }
[Parameter] public required Func<long, TQuery, Action<IEnumerable<TRole>>, Task> GetRolesAction { get; set; }
[Parameter] public required Func<Guid, Action<RatingResponse>, Task> GetGlobalRatingAction { get; set; }
[Parameter] public required Func<Guid, Action<short>, Action, Task> GetUserRatingAction { get; set; }
[Parameter] public required Func<Guid, RatingRequest, Task> PutRatingAction { get; set; }
[Parameter] public required Func<Guid, Task> DeleteRatingAction { get; set; }
#endregion