Refactoring, database structure changed

This commit is contained in:
2025-03-03 00:56:32 +01:00
Unverified
parent d3805ef3db
commit c603c41c0b
913 changed files with 21764 additions and 32775 deletions

View File

@@ -0,0 +1,20 @@
@inherits Component
<div class="panel">
<div class="vstack">
<div class="d-flex justify-content-center">
<div class="text-danger icon-size">⚠&#xFE0E;</div>
</div>
<div class="d-flex justify-content-center">
<h3 class="text-danger">An error occured while loading a page</h3>
</div>
@if (!string.IsNullOrWhiteSpace(ErrorMessage))
{
<div class="d-flex justify-content-center">
<p>@ErrorMessage</p>
</div>
}
</div>
</div>

View File

@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Components;
namespace WatchIt.Website.Components.Panels.Common;
public partial class ErrorPanel : Component
{
#region PARAMETERS
[Parameter] public string? ErrorMessage { get; set; }
#endregion
}

View File

@@ -0,0 +1,5 @@
/* CLASSES */
.icon-size {
font-size: 80px;
}

View File

@@ -0,0 +1,49 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
@typeparam TItem
<div class="panel">
<div class="vstack gap-3">
<span class="panel-text-title">@(Title)</span>
@if (_loaded)
{
<div class="container-grid">
<div class="row">
@if (_items.Count() > 0)
{
for (int i = 0; i < Count; i++)
{
<div class="col">
@if (_items.Count() > i)
{
<a class="text-reset text-decoration-none" href="@(string.Format(ItemUrlFormatString, IdSource(_items.ElementAt(i))))">
@{ int iCopy = i; }
<HorizontalListItem Place="@(HidePlace ? null : i + 1)"
Name="@(NameSource(_items.ElementAt(iCopy)))"
PosterPlaceholder="@(PosterPlaceholder)"
GetPosterAction="@(() => GetPictureAction(_items.ElementAt(iCopy)))"/>
</a>
}
</div>
}
}
else if (!string.IsNullOrWhiteSpace(EmptyListMessage))
{
<div class="col">
<div class="d-flex justify-content-center">
@(EmptyListMessage)
</div>
</div>
}
</div>
</div>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>
</div>

View File

@@ -0,0 +1,50 @@
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Generics.Image;
namespace WatchIt.Website.Components.Panels.Common;
public partial class HorizontalListPanel<TItem> : Component
{
#region PARAMETERS
[Parameter] public int Count { get; set; } = 5;
[Parameter] public required string Title {get; set; }
[Parameter] public required Func<Task<IApiResponse<IEnumerable<TItem>>>> GetItemsAction { get; set; }
[Parameter] public required string ItemUrlFormatString { get; set; }
[Parameter] public required Func<TItem, long> IdSource { get; set; }
[Parameter] public required Func<TItem, string> NameSource { get; set; }
[Parameter] public required string PosterPlaceholder { get; set; }
[Parameter] public required Func<TItem, Task<ImageResponse?>> GetPictureAction { get; set; }
[Parameter] public bool HidePlace { get; set; }
[Parameter] public string? EmptyListMessage { get; set; }
#endregion
#region FIELDS
private bool _loaded;
private IEnumerable<TItem> _items = default!;
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
IApiResponse<IEnumerable<TItem>> response = await GetItemsAction();
if (response.IsSuccessful)
{
_items = response.Content;
}
_loaded = true;
StateHasChanged();
}
#endregion
}

View File

@@ -0,0 +1,72 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel @(Class)">
@if (_loaded)
{
<div class="vstack gap-3">
<Image Content="@(_imageSelected)" Placeholder="@(ImagePlaceholder)" AlternativeText="loaded_image" Circle="@(Circle)" Width="@(ContentWidth)"/>
<Blazorise.FileEdit Width="@(Blazorise.Width.Px(ContentWidth - 100))" Changed="@(LoadImageFromFile)" Filter="image/jpeg, image/png, image/webp" Disabled="@(Disabled)"/>
@if (_imageChanged || _imageSaved is not null)
{
<div class="content-width">
@if (_imageChanged)
{
<div class="container-grid">
<div class="row gx-1">
<div class="col">
<button type="button" class="btn btn-secondary btn-block btn-stretch-x" @onclick="@(SaveImage)" disabled=@(Disabled || _imageSaving || _imageDeleting) autocomplete="off">
@if (!_imageSaving)
{
<span>Save</span>
}
else
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span>Saving...</span>
}
</button>
</div>
<div class="col">
<button type="button" class="btn btn-danger btn-block btn-stretch-x" @onclick="@(CancelImage)" disabled=@(Disabled || _imageSaving || _imageDeleting) autocomplete="off">Drop changes</button>
</div>
</div>
</div>
}
else if (_imageSaved is not null)
{
<button type="button" class="btn btn-danger btn-block btn-stretch-x" @onclick="@(DeleteImage)" disabled=@(Disabled || _imageSaving || _imageDeleting) autocomplete="off">
@if (!_imageSaving)
{
<span>Delete</span>
}
else
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span>Deleting...</span>
}
</button>
}
</div>
}
</div>
}
else
{
<div class="d-flex align-items-center justify-content-center h-100 content-width">
<Loading Color="@(Loading.Colors.Light)"/>
</div>
}
</div>
<style>
/* CLASSES */
.content-width {
width: @(ContentWidth)px;
}
</style>

View File

@@ -0,0 +1,138 @@
using System.Reflection.Metadata;
using Blazorise;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using WatchIt.DTO.Models.Generics.Image;
namespace WatchIt.Website.Components.Panels.Common;
public partial class ImageEditorPanel : Component
{
#region PARAMETERS
[Parameter] public int ContentWidth { get; set; } = 300;
[Parameter] public required string ImagePlaceholder { get; set; }
[Parameter] public bool Circle { get; set; }
[Parameter] public bool Disabled { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
[Parameter]
public required ImageBase? Image
{
get => _imageSaved;
set
{
_imageSet = true;
_imageSaved = value;
_imageSelected = ImageToRequest(value);
}
}
[Parameter] public required Func<Task<ImageResponse?>> ImageGetMethod { get; set; }
[Parameter] public required Func<ImageRequest, Task<ImageResponse?>> ImagePutMethod { get; set; }
[Parameter] public required Func<Task<bool>> ImageDeleteMethod { get; set; }
[Parameter] public Action<ImageResponse?>? OnImageChanged { get; set; }
#endregion
#region FIELDS
private bool _loaded;
private ImageBase? _imageSaved;
private bool _imageSet;
private ImageRequest? _imageSelected;
private bool _imageChanged;
private bool _imageSaving;
private bool _imageDeleting;
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
if (!_imageSet)
{
_imageSaved = await ImageGetMethod();
_imageSelected = ImageToRequest(_imageSaved);
}
_loaded = true;
StateHasChanged();
}
private async Task LoadImageFromFile(FileChangedEventArgs args)
{
IFileEntry file = args.Files.First();
Stream stream = file.OpenReadStream(5242880);
byte[] array;
using (MemoryStream ms = new MemoryStream())
{
await stream.CopyToAsync(ms);
array = ms.ToArray();
}
_imageSelected = new ImageRequest
{
Image = array,
MimeType = file.Type,
};
_imageChanged = true;
}
private async Task SaveImage()
{
_imageSaving = true;
if (_imageSelected is not null)
{
ImageResponse? response = await ImagePutMethod(_imageSelected);
if (response is not null)
{
_imageSaved = response;
_imageSelected = ImageToRequest(_imageSaved);
_imageChanged = false;
OnImageChanged?.Invoke(response);
}
}
_imageSaving = false;
}
private void CancelImage()
{
_imageSelected = ImageToRequest(_imageSaved);
_imageChanged = false;
}
private async Task DeleteImage()
{
_imageDeleting = true;
if (_imageSaved is not null)
{
bool response = await ImageDeleteMethod();
if (response)
{
_imageSaved = null;
_imageSelected = null;
_imageChanged = false;
OnImageChanged?.Invoke(null);
}
}
_imageDeleting = false;
}
public static ImageRequest? ImageToRequest(ImageBase? image) => image is null ? null : new ImageRequest
{
Image = image.Image,
MimeType = image.MimeType,
};
#endregion
}

View File

@@ -0,0 +1,27 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="container-grid mt-header">
<div class="row">
<div class="col-auto">
<Image Content="@(Poster)" Placeholder="@(PosterPlaceholder)" AlternativeText="poster" Height="350"/>
</div>
<div class="col">
<div class="d-flex flex-column justify-content-end h-100">
<h1 class="fw-bold title-shadow">@(Name)</h1>
<div class="d-flex flex-column gap-3">
@if (!string.IsNullOrWhiteSpace(Subname))
{
<span class="fst-italic description-shadow">@(Subname)</span>
}
@if (!string.IsNullOrWhiteSpace(Description))
{
<span class="description-shadow">@(Description)</span>
}
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Components;
using WatchIt.DTO.Models.Generics.Image;
namespace WatchIt.Website.Components.Panels.Common;
public partial class ItemPageHeaderPanel : Component
{
#region PARAMETERS
[Parameter] public required string Name { get; set; }
[Parameter] public string? Subname { get; set; }
[Parameter] public string? Description { get; set; }
[Parameter] public ImageResponse? Poster { get; set; }
[Parameter] public required string PosterPlaceholder { get; set; }
#endregion
}

View File

@@ -0,0 +1,9 @@
/* CLASSES */
.title-shadow {
text-shadow: 2px 2px 2px #000;
}
.description-shadow {
text-shadow: 1px 1px 1px #000;
}

View File

@@ -0,0 +1,124 @@
@using System.Net
@using WatchIt.Website.Components.Subcomponents.Common
@using Blazorise
@using Blazorise.Snackbar
@using Refit
@using WatchIt.DTO.Models.Controllers.Roles
@using WatchIt.DTO.Models.Generics.Rating
@inherits Component
@typeparam TRole where TRole : WatchIt.DTO.Models.Controllers.Roles.Role.Response.RoleResponse
@typeparam TRoleParent
<div class="panel @(Class)">
@if (_loaded)
{
<div class="vstack gap-3">
<span class="panel-text-title">@(Title)</span>
@if (RoleParents is null)
{
<span class="text-center">An error occured. @(ParentName) could not be obtained.</span>
}
else if (_roles is null)
{
<span class="text-center">An error occured. Roles could not be obtained.</span>
}
else if (!_roles.Any())
{
<span class="text-center">No items found.</span>
}
else if (_roleTypes is null)
{
<span class="text-center">An error occured. Role types could not be obtained.</span>
}
else
{
<div class="d-flex justify-content-center">
<RadioGroup TValue="short" Color="Color.Default" Buttons Size="Size.Small" @bind-CheckedValue="@(_checkedType)">
@foreach (IRoleTypeResponse roleType in _roleTypes)
{
<Radio Value="@(roleType.Id)">@roleType.Name</Radio>
}
</RadioGroup>
</div>
<div class="vstack">
@{
IEnumerable<TRole> roles = _roles.Where(x => x.TypeId == _checkedType);
}
@for (int i = 0; i < roles.Count(); i++)
{
TRole role = roles.ElementAt(i);
TRoleParent parent = ParentFunc(role, RoleParents);
if (i > 0)
{
<hr/>
}
<VerticalListItem @key="@(role)"
Name="@(NameFunc(role, parent))"
AdditionalInfo="@(AdditionalInfoFunc is not null ? AdditionalInfoFunc(role, parent) : null)"
PicturePlaceholder="@(PicturePlaceholder)"
PictureFunc="@(() => PictureFunc(role, parent))"
GetGlobalRatingMethod="@(async () =>
{
IApiResponse<RatingOverallResponse> response = await RolesClient.GetRoleRating(role.Id);
if (!response.IsSuccessful)
{
await Base.SnackbarStack.PushAsync($"An error occured. Rating for role with id {role.Id} could not be obtained.", SnackbarColor.Danger);
}
return response.Content;
})"
GetYourRatingMethod="@(async userId =>
{
IApiResponse<RatingUserResponse> response = await RolesClient.GetRoleUserRating(role.Id, userId);
if (!response.IsSuccessful)
{
if (response.StatusCode != HttpStatusCode.NotFound)
{
await Base.SnackbarStack.PushAsync($"An error occured. User rating for role with id {role.Id} could not be obtained.", SnackbarColor.Danger);
}
return null;
}
else
{
return Convert.ToInt32(response.Content.Rating);
}
})"
PutYourRatingMethod="@(async request =>
{
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await RolesClient.PutRoleRating(token, role.Id, request);
if (!response.IsSuccessful)
{
await Base.SnackbarStack.PushAsync($"An error occured. Role could not be rated.", SnackbarColor.Danger);
}
})"
DeleteYourRatingMethod="@(async () =>
{
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await RolesClient.DeleteRoleRating(token, role.Id);
if (!response.IsSuccessful)
{
await Base.SnackbarStack.PushAsync($"An error occured. Role could not be rated.", SnackbarColor.Danger);
}
})"
ItemUrl="@(UrlFunc(role, parent))"
PictureHeight="110"
NameSize="20"
OnRatingChanged="@(OnRatingChanged)"/>
}
</div>
}
</div>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>

View File

@@ -0,0 +1,107 @@
using Microsoft.AspNetCore.Components;
using WatchIt.Database.Model.Media;
using WatchIt.Database.Model.People;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
using WatchIt.DTO.Models.Controllers.People.Person;
using WatchIt.DTO.Models.Controllers.Roles;
using WatchIt.DTO.Models.Controllers.Roles.Role.Query;
using WatchIt.DTO.Models.Controllers.Roles.Role.Response;
using WatchIt.DTO.Models.Generics.Image;
using WatchIt.DTO.Models.Generics.Rating;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Common;
public partial class RolesPanel<TRole, TRoleParent> : Component where TRole : RoleResponse
{
#region SERVICES
[Inject] protected IRolesClient RolesClient { get; set; } = null!;
[Inject] protected IAuthenticationService AuthenticationService { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required string Title { get; set; }
[Parameter] public IEnumerable<TRoleParent>? RoleParents { get; set; }
[Parameter] public required string ParentName { get; set; }
[Parameter] public required Func<TRole, TRoleParent, string> NameFunc { get; set; }
[Parameter] public required Func<TRole, TRoleParent, string>? AdditionalInfoFunc { get; set; }
[Parameter] public required string PicturePlaceholder { get; set; }
[Parameter] public required Func<TRole, TRoleParent, Task<ImageResponse?>> PictureFunc { get; set; }
[Parameter] public required Func<TRole, TRoleParent, string> UrlFunc { get; set; }
[Parameter] public required Func<TRole, TRoleParent, RatingOverallResponse> GlobalRatingFunc { get; set; }
[Parameter] public required Func<Task<IEnumerable<IRoleTypeResponse>?>> GetRoleTypesMethod { get; set; }
[Parameter] public required Func<Task<IEnumerable<TRole>?>> GetRolesMethod { get; set; }
[Parameter] public required Func<TRole, IEnumerable<TRoleParent>, TRoleParent> ParentFunc { get; set; }
[Parameter] public Action? OnRatingChanged { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
#endregion
#region FIELDS
private bool _loaded;
private IEnumerable<IRoleTypeResponse>? _roleTypes;
private IEnumerable<TRole>? _roles;
private short _checkedType;
private IEnumerable<TRole> _rolesVisible = [];
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
await LoadRoles();
if (_roles is not null && _roles.Any())
{
await LoadRoleTypes();
}
if (_roleTypes is not null && _roleTypes.Any())
{
_checkedType = _roleTypes.First().Id;
//_rolesVisible = _roles.Where(x => x.TypeId == _checkedType);
}
_loaded = true;
StateHasChanged();
}
private async Task LoadRoles()
{
_roles = await GetRolesMethod();
}
private async Task LoadRoleTypes()
{
IEnumerable<IRoleTypeResponse>? roleTypesOriginal = await GetRoleTypesMethod();
IEnumerable<short>? roleTypesId = _roles!.Select(x => x.TypeId).Distinct();
_roleTypes = roleTypesOriginal?.Where(x => roleTypesId.Contains(x.Id));
}
private void CheckedTypeChanged(short value)
{
_checkedType = value;
_rolesVisible = _roles.Where(x => x.TypeId == value);
}
#endregion
}

View File

@@ -0,0 +1,148 @@
@using Blazorise.Extensions
@using WatchIt.DTO.Models.Controllers.Media.Medium.Response
@using WatchIt.DTO.Models.Controllers.Roles.Role.Response
@using WatchIt.Website.Components.Subcomponents.Common
@using Blazorise.Components
@using WatchIt.DTO.Models.Controllers.People.Person
@inherits Component
<div class="panel @(Class)">
@if (_loaded)
{
<div class="vstack gap-3">
<div class="container-grid">
<div class="row gx-2">
<div class="col align-self-center">
<h4 class="m-0"><strong>Actor roles</strong></h4>
</div>
@if (!_editingMode)
{
<div class="col-auto">
<button type="button" class="btn btn-secondary" disabled="@(Disabled)" @onclick="@(() => ActivateEditData())">Add</button>
</div>
}
else
{
<div class="col-auto">
<button type="button" class="btn btn-secondary" @onclick="@(CancelEditData)">Cancel</button>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(SaveData)">
<LoadingButtonContent IsLoading="@(_saving)" Content="Save" LoadingContent="Saving..."/>
</button>
</div>
}
</div>
</div>
@if (!_editingMode)
{
if (_roles.IsNullOrEmpty())
{
<span class="text-center">No items</span>
}
else
{
<table class="table table-sm table-transparent">
<thead>
<tr>
<th scope="col">
Person
</th>
<th scope="col">
Role type
</th>
<th scope="col">
Role name
</th>
<th class="table-cell-fit" scope="col">
Actions
</th>
</tr>
</thead>
<tbody class="table-group-divider">
@foreach (Guid roleId in _roles.Keys)
{
RoleActorResponse role = _roles[roleId].Data;
PersonResponse person = _peopleDict[role.PersonId];
<tr>
<td class="align-middle">
@(person.Name)
</td>
<td class="align-middle">
@(_roleTypes[role.TypeId])
</td>
<td class="align-middle">
@(role.Name)
</td>
<td class="align-middle table-cell-fit">
<div class="hstack gap-1">
<button class="btn btn-outline-secondary btn-sm" type="button" disabled="@(Disabled || _roles[roleId].Deleting)" @onclick="@(() => ActivateEditData(roleId))"><i class="fas fa-edit"></i></button>
<button class="btn btn-outline-danger btn-sm" type="button" disabled="@(Disabled || _roles[roleId].Deleting)" @onclick="@(() => DeleteData(roleId))">
@if (_roles[roleId].Deleting)
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
}
else
{
<i class="fa-solid fa-trash"></i>
}
</button>
</div>
</td>
</tr>
}
</tbody>
</table>
}
}
else
{
<EditForm Model="@(_roleRequest)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group mb-1">
<label for="actorFormPeople" class="col-1 col-form-label">People:</label>
<div class="col">
<Autocomplete ElementId="actorFormPeople"
TItem="PersonResponse"
TValue="long"
Data="@(_peopleDict.Values)"
TextField="@(item => item.Name)"
ValueField="@(item => item.Id)"
@bind-SelectedValue="@(_roleRequest.PersonId)"
Placeholder="Search..."
Filter="AutocompleteFilter.Contains">
<NotFoundContent Context="not_found_context"> Sorry... @not_found_context was not found</NotFoundContent>
</Autocomplete>
</div>
</div>
<div class="row form-group my-1">
<label for="actorFormType" class="col-1 col-form-label">Type:</label>
<div class="col">
<InputSelect id="actorFormType" class="form-control" TValue="short" @bind-Value="@(_roleRequest.TypeId)">
@foreach (KeyValuePair<short, string> type in _roleTypes)
{
<option value="@(type.Key)">@(type.Value)</option>
}
</InputSelect>
</div>
</div>
<div class="row form-group my-1">
<label for="actorFormName" class="col-1 col-form-label">Name:</label>
<div class="col">
<InputText id="actorFormName" class="form-control" @bind-Value="@(_roleRequest.Name)"/>
</div>
</div>
</div>
</EditForm>
}
</div>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>

View File

@@ -0,0 +1,217 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
using WatchIt.DTO.Models.Controllers.People.Person;
using WatchIt.DTO.Models.Controllers.Roles.Role.Query;
using WatchIt.DTO.Models.Controllers.Roles.Role.Request;
using WatchIt.DTO.Models.Controllers.Roles.Role.Response;
using WatchIt.DTO.Models.Controllers.Roles.RoleActorType;
using WatchIt.DTO.Query;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.MediumEditPage;
public partial class ActorRolesEditPanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private IPeopleClient PeopleClient { get; set; } = null!;
[Inject] private IMediaClient MediaClient { get; set; } = null!;
[Inject] private IRolesClient RolesClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required BaseMediumResponse Data { get; set; }
[Parameter] public List<PersonResponse>? People { get; set; }
[Parameter] public bool Disabled { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
#endregion
#region FIELDS
private bool _loaded;
private bool _editingMode;
private Guid? _editedId;
private RoleActorRequest _roleRequest = null!;
private bool _saving;
private Dictionary<long, PersonResponse> _peopleDict = new Dictionary<long, PersonResponse>();
private Dictionary<short, string> _roleTypes = new Dictionary<short, string>();
private Dictionary<Guid, (RoleActorResponse Data, bool Deleting)> _roles = new Dictionary<Guid, (RoleActorResponse Data, bool Deleting)>();
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
ResetRequest();
await Task.WhenAll(
[
LoadRoleTypes(),
LoadMedia()
]);
if (Data is not null)
{
await LoadRoles();
}
_loaded = true;
StateHasChanged();
}
private async Task LoadRoleTypes()
{
IApiResponse<IEnumerable<RoleActorTypeResponse>> response = await RolesClient.GetRoleActorTypes();
if (response.IsSuccessful)
{
_roleTypes = response.Content.ToDictionary(x => x.Id, x => x.Name);
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Actor role types list could not be obtained.", SnackbarColor.Danger);
}
}
private async Task LoadMedia()
{
IEnumerable<PersonResponse>? people = People;
if (people is null)
{
IApiResponse<IEnumerable<PersonResponse>> response = await PeopleClient.GetPeople(includePictures: true);
if (response.IsSuccessful)
{
people = response.Content;
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. People list could not be obtained.", SnackbarColor.Danger);
return;
}
}
_peopleDict = people.ToDictionary(x => x.Id, x => x);
}
private async Task LoadRoles()
{
RoleActorFilterQuery filter = new RoleActorFilterQuery
{
MediumId = Data.Id
};
IApiResponse<IEnumerable<RoleActorResponse>> response = await RolesClient.GetRoleActors(filter);
if (response.IsSuccessful)
{
_roles = response.Content.ToDictionary(x => x.Id, x => (x, false));
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Actor roles could not be obtained.", SnackbarColor.Danger);
}
}
private void CancelEditData()
{
_editingMode = false;
}
private async Task SaveData()
{
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
_saving = true;
IApiResponse<RoleActorResponse> response = await (_editedId.HasValue switch
{
true => RolesClient.PutRoleActor(token, _editedId.Value, _roleRequest),
false => RolesClient.PostRoleActor(token, _roleRequest),
});
switch (response)
{
case { IsSuccessful: true }:
_roles[response.Content.Id] = (response.Content, false);
await Base.SnackbarStack.PushAsync("Role saved successfully.", SnackbarColor.Success);
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("You are not authorized to edit roles data.", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saving = false;
_editingMode = false;
}
private void ActivateEditData(Guid? id = null)
{
_editedId = id;
ResetRequest();
if (id is not null && _roles.TryGetValue(id.Value, out (RoleActorResponse Data, bool Deleting) role))
{
_roleRequest.Name = role.Data.Name;
_roleRequest.PersonId = role.Data.PersonId;
_roleRequest.TypeId = role.Data.TypeId;
}
_editingMode = true;
}
private async Task DeleteData(Guid id)
{
_roles[id] = (_roles[id].Data, true);
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await RolesClient.DeleteRole(token, id);
switch (response)
{
case {IsSuccessful: true}:
_roles.Remove(id);
await Base.SnackbarStack.PushAsync("Role removed successfully.", SnackbarColor.Success);
break;
case {StatusCode: HttpStatusCode.Forbidden} or {StatusCode: HttpStatusCode.Unauthorized}:
await Base.SnackbarStack.PushAsync("You are not authorized to remove roles.", SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
}
private void ResetRequest() => _roleRequest = Data is null ? new RoleActorRequest() : new RoleActorRequest
{
MediumId = Data.Id,
};
#endregion
}

View File

@@ -0,0 +1,137 @@
@using WatchIt.DTO.Models.Controllers.Media.Medium.Response
@using WatchIt.DTO.Models.Controllers.Roles.Role.Response
@using WatchIt.Website.Components.Subcomponents.Common
@using Blazorise.Components
@using WatchIt.DTO.Models.Controllers.People.Person
@using Blazorise.Extensions
@inherits Component
<div class="panel @(Class)">
@if (_loaded)
{
<div class="vstack gap-3">
<div class="container-grid">
<div class="row gx-2">
<div class="col align-self-center">
<h4 class="m-0"><strong>Creator roles</strong></h4>
</div>
@if (!_editingMode)
{
<div class="col-auto">
<button type="button" class="btn btn-secondary" disabled="@(Disabled)" @onclick="@(() => ActivateEditData())">Add</button>
</div>
}
else
{
<div class="col-auto">
<button type="button" class="btn btn-secondary" @onclick="@(CancelEditData)">Cancel</button>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(SaveData)">
<LoadingButtonContent IsLoading="@(_saving)" Content="Save" LoadingContent="Saving..."/>
</button>
</div>
}
</div>
</div>
@if (!_editingMode)
{
if (_roles.IsNullOrEmpty())
{
<span class="text-center">No items</span>
}
else
{
<table class="table table-sm table-transparent">
<thead>
<tr>
<th scope="col">
Person
</th>
<th scope="col">
Role type
</th>
<th class="table-cell-fit" scope="col">
Actions
</th>
</tr>
</thead>
<tbody class="table-group-divider">
@foreach (Guid roleId in _roles.Keys)
{
RoleCreatorResponse role = _roles[roleId].Data;
PersonResponse person = _peopleDict[role.PersonId];
<tr>
<td class="align-middle">
@(person.Name)
</td>
<td class="align-middle">
@(_roleTypes[role.TypeId])
</td>
<td class="align-middle table-cell-fit">
<div class="hstack gap-1">
<button class="btn btn-outline-secondary btn-sm" type="button" disabled="@(Disabled || _roles[roleId].Deleting)" @onclick="@(() => ActivateEditData(roleId))"><i class="fas fa-edit"></i></button>
<button class="btn btn-outline-danger btn-sm" type="button" disabled="@(Disabled || _roles[roleId].Deleting)" @onclick="@(() => DeleteData(roleId))">
@if (_roles[roleId].Deleting)
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
}
else
{
<i class="fa-solid fa-trash"></i>
}
</button>
</div>
</td>
</tr>
}
</tbody>
</table>
}
}
else
{
<EditForm Model="@(_roleRequest)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group mb-1">
<label for="actorFormPeople" class="col-1 col-form-label">People:</label>
<div class="col">
<Autocomplete ElementId="actorFormPeople"
TItem="PersonResponse"
TValue="long"
Data="@(_peopleDict.Values)"
TextField="@(item => item.Name)"
ValueField="@(item => item.Id)"
@bind-SelectedValue="@(_roleRequest.PersonId)"
Placeholder="Search..."
Filter="AutocompleteFilter.Contains">
<NotFoundContent Context="not_found_context"> Sorry... @not_found_context was not found</NotFoundContent>
</Autocomplete>
</div>
</div>
<div class="row form-group my-1">
<label for="actorFormType" class="col-1 col-form-label">Type:</label>
<div class="col">
<InputSelect id="actorFormType" class="form-control" TValue="short" @bind-Value="@(_roleRequest.TypeId)">
@foreach (KeyValuePair<short, string> type in _roleTypes)
{
<option value="@(type.Key)">@(type.Value)</option>
}
</InputSelect>
</div>
</div>
</div>
</EditForm>
}
</div>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>

View File

@@ -0,0 +1,214 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
using WatchIt.DTO.Models.Controllers.People.Person;
using WatchIt.DTO.Models.Controllers.Roles.Role.Query;
using WatchIt.DTO.Models.Controllers.Roles.Role.Request;
using WatchIt.DTO.Models.Controllers.Roles.Role.Response;
using WatchIt.DTO.Models.Controllers.Roles.RoleCreatorType;
using WatchIt.DTO.Query;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.MediumEditPage;
public partial class CreatorRolesEditPanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private IPeopleClient PeopleClient { get; set; } = null!;
[Inject] private IRolesClient RolesClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required BaseMediumResponse Data { get; set; }
[Parameter] public List<PersonResponse>? People { get; set; }
[Parameter] public bool Disabled { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
#endregion
#region FIELDS
private bool _loaded;
private bool _editingMode;
private Guid? _editedId;
private RoleCreatorRequest _roleRequest = null!;
private bool _saving;
private Dictionary<long, PersonResponse> _peopleDict = new Dictionary<long, PersonResponse>();
private Dictionary<short, string> _roleTypes = new Dictionary<short, string>();
private Dictionary<Guid, (RoleCreatorResponse Data, bool Deleting)> _roles = new Dictionary<Guid, (RoleCreatorResponse Data, bool Deleting)>();
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
ResetRequest();
await Task.WhenAll(
[
LoadRoleTypes(),
LoadMedia(),
]);
if (Data is not null)
{
await LoadRoles();
}
_loaded = true;
StateHasChanged();
}
private async Task LoadRoleTypes()
{
IApiResponse<IEnumerable<RoleCreatorTypeResponse>> response = await RolesClient.GetRoleCreatorTypes();
if (response.IsSuccessful)
{
_roleTypes = response.Content.ToDictionary(x => x.Id, x => x.Name);
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Creator role types list could not be obtained.", SnackbarColor.Danger);
}
}
private async Task LoadMedia()
{
IEnumerable<PersonResponse>? people = People;
if (people is null)
{
IApiResponse<IEnumerable<PersonResponse>> response = await PeopleClient.GetPeople(includePictures: true);
if (response.IsSuccessful)
{
people = response.Content;
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. People list could not be obtained.", SnackbarColor.Danger);
return;
}
}
_peopleDict = people.ToDictionary(x => x.Id, x => x);
}
private async Task LoadRoles()
{
RoleCreatorFilterQuery filter = new RoleCreatorFilterQuery
{
MediumId = Data.Id
};
IApiResponse<IEnumerable<RoleCreatorResponse>> response = await RolesClient.GetRoleCreators(filter);
if (response.IsSuccessful)
{
_roles = response.Content.ToDictionary(x => x.Id, x => (x, false));
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Creator roles could not be obtained.", SnackbarColor.Danger);
}
}
private void CancelEditData()
{
_editingMode = false;
}
private async Task SaveData()
{
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
_saving = true;
IApiResponse<RoleCreatorResponse> response = await (_editedId.HasValue switch
{
true => RolesClient.PutRoleCreator(token, _editedId.Value, _roleRequest),
false => RolesClient.PostRoleCreator(token, _roleRequest),
});
switch (response)
{
case { IsSuccessful: true }:
_roles[response.Content.Id] = (response.Content, false);
await Base.SnackbarStack.PushAsync("Role saved successfully.", SnackbarColor.Success);
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("You are not authorized to edit roles data.", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saving = false;
_editingMode = false;
}
private void ActivateEditData(Guid? id = null)
{
_editedId = id;
ResetRequest();
if (id is not null && _roles.TryGetValue(id.Value, out (RoleCreatorResponse Data, bool Deleting) role))
{
_roleRequest.PersonId = role.Data.PersonId;
_roleRequest.TypeId = role.Data.TypeId;
}
_editingMode = true;
}
private async Task DeleteData(Guid id)
{
_roles[id] = (_roles[id].Data, true);
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await RolesClient.DeleteRole(token, id);
switch (response)
{
case {IsSuccessful: true}:
_roles.Remove(id);
await Base.SnackbarStack.PushAsync("Role removed successfully.", SnackbarColor.Success);
break;
case {StatusCode: HttpStatusCode.Forbidden} or {StatusCode: HttpStatusCode.Unauthorized}:
await Base.SnackbarStack.PushAsync("You are not authorized to remove roles.", SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
}
private void ResetRequest() => _roleRequest = Data is null ? new RoleCreatorRequest() : new RoleCreatorRequest
{
MediumId = Data.Id,
};
#endregion
}

View File

@@ -0,0 +1,87 @@
@using WatchIt.DTO.Models.Controllers.Media.Medium.Request
@using WatchIt.DTO.Models.Controllers.Media.Medium.Response
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel @(Class)">
@if (_loaded)
{
<EditForm Model="@(_request)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group mb-1">
<label for="title" class="col-2 col-form-label">Title*</label>
<div class="col-10">
<InputText id="title" class="form-control" @bind-Value="_request!.Title"/>
</div>
</div>
<div class="row form-group my-1">
<label for="og-title" class="col-2 col-form-label">Original title</label>
<div class="col-10">
<InputText id="og-title" class="form-control" @bind-Value="_request!.OriginalTitle"/>
</div>
</div>
<div class="row form-group my-1">
<label for="desc" class="col-2 col-form-label">Description</label>
<div class="col-10">
<InputTextArea id="desc" class="form-control" @bind-Value="_request!.Description"/>
</div>
</div>
<div class="row form-group my-1">
<label for="rel-date" class="col-2 col-form-label">Release date</label>
<div class="col-4">
<InputDate TValue="DateOnly?" id="rel-date" class="form-control" @bind-Value="_request!.ReleaseDate"/>
</div>
<label for="length" class="col-2 col-form-label">Length</label>
<div class="col-4">
<InputNumber TValue="short?" id="length" class="form-control" @bind-Value="_request!.Duration"/>
</div>
</div>
@switch (_request)
{
case MediumMovieRequest movieRequest:
<div class="row form-group mt-1">
<label for="budget" class="col-2 col-form-label">Budget</label>
<div class="col-10">
<InputNumber TValue="decimal?" id="budget" class="form-control" @bind-Value="movieRequest!.Budget"/>
</div>
</div>
break;
case MediumSeriesRequest seriesRequest:
<div class="row form-group mt-1">
<label class="col-2 col-form-label">Has ended</label>
<div class="col-10 col-form-label">
<div class="d-flex gap-3">
<InputRadioGroup TValue="bool" @bind-Value="seriesRequest!.HasEnded">
<div class="d-flex gap-2">
<InputRadio TValue="bool" Value="true"/>
Yes
</div>
<div class="d-flex gap-2">
<InputRadio TValue="bool" Value="false"/>
No
</div>
</InputRadioGroup>
</div>
</div>
</div>
break;
}
<div class="row mt-2">
<div class="col d-flex flex-column align-items-end">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(SaveData)">
<LoadingButtonContent IsLoading="@(_saving)" Content="Save" LoadingContent="Saving..."/>
</button>
</div>
</div>
</div>
</EditForm>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>

View File

@@ -0,0 +1,121 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Media;
using WatchIt.DTO.Models.Controllers.Media.Medium.Request;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.MediumEditPage;
public partial class EditFormPanel : Component
{
#region SERVICES
[Inject] private NavigationManager NavigationManager { get; set; } = null!;
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private IMediaClient MediaClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public BaseMediumResponse? Data { get; set; }
[Parameter] public required NullType TypeIfNull { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
#endregion
#region FIELDS
private bool _loaded;
private bool _saving;
private MediumRequest? _request;
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
LoadData();
_loaded = true;
StateHasChanged();
}
private void LoadData()
{
_request = Data switch
{
null => TypeIfNull switch
{
NullType.Movie => new MediumMovieRequest(),
NullType.Series => new MediumSeriesRequest(),
},
_ => Data.ToRequest()
};
}
private async Task SaveData()
{
_saving = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse<BaseMediumResponse> response = Data switch
{
null => TypeIfNull switch
{
NullType.Movie => await MediaClient.PostMediumMovie(token, _request as MediumMovieRequest ?? throw new InvalidOperationException()),
NullType.Series => await MediaClient.PostMediumSeries(token, _request as MediumSeriesRequest ?? throw new InvalidOperationException()),
},
MediumMovieResponse => await MediaClient.PutMediumMovie(token, Data.Id, _request as MediumMovieRequest ?? throw new InvalidOperationException()),
MediumSeriesResponse => await MediaClient.PutMediumSeries(token, Data.Id, _request as MediumSeriesRequest ?? throw new InvalidOperationException()),
_ => throw new InvalidOperationException()
};
switch (response)
{
case { IsSuccessful: true }:
switch (Data)
{
case null: NavigationManager.NavigateTo($"media/{response.Content.Id}/edit", true); break;
default: await Base.SnackbarStack.PushAsync("Data saved successfully.", SnackbarColor.Success); break;
}
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("You are not authorized to edit media data.", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saving = false;
}
#endregion
}

View File

@@ -0,0 +1,51 @@
@using Blazorise.Extensions
@using WatchIt.DTO.Models.Controllers.Genres.Genre
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel">
<div class="vstack gap-3">
<h4 class="fw-bold">Genres</h4>
<div class="d-flex gap-3">
<InputSelect class="w-100 form-control" TValue="short?" @bind-Value="@(_selectedGenre)" disabled="@(Data is null || _addLoading || _chosenGenres.Values.Any(x => x))">
<option value="@(default(short?))" selected hidden="hidden">Choose genre...</option>
@foreach (GenreResponse genre in _availableGenres)
{
<option value="@(genre.Id)">@(genre.Name)</option>
}
</InputSelect>
<button class="btn btn-secondary" @onclick="AddGenre" disabled="@(Data is null || _selectedGenre is null || _addLoading || _chosenGenres.Values.Any(x => x))">
<LoadingButtonContent Content="Add" LoadingContent="Adding..." IsLoading="@(_addLoading)"/>
</button>
</div>
@if (_chosenGenres.IsNullOrEmpty())
{
<span class="text-center">No items</span>
}
else
{
<table class="table table-sm table-transparent">
<tbody>
@foreach (KeyValuePair<GenreResponse, bool> genre in _chosenGenres)
{
<tr>
<td class="align-middle">
@(genre.Key.Name)
</td>
<td class="align-middle table-cell-fit">
<button class="btn btn-outline-danger btn-sm w-100" type="button" disabled="@(_addLoading || genre.Value)" @onclick="@(() => RemoveGenre(genre.Key))">
<LoadingButtonContent IsLoading="@(genre.Value)">
<i class="fa-solid fa-trash"></i>
</LoadingButtonContent>
</button>
</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>

View File

@@ -0,0 +1,117 @@
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Genres.Genre;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.MediumEditPage;
public partial class GenresEditPanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private IGenresClient GenresClient { get; set; } = null!;
[Inject] private IMediaClient MediaClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required BaseMediumResponse? Data { get; set; }
#endregion
#region FIELDS
private Dictionary<GenreResponse, bool> _chosenGenres = new Dictionary<GenreResponse, bool>();
private List<GenreResponse> _availableGenres = new List<GenreResponse>();
private short? _selectedGenre;
private bool _addLoading;
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await LoadData();
StateHasChanged();
}
private async Task LoadData()
{
if (Data is not null)
{
foreach (GenreResponse genre in Data.Genres)
{
_chosenGenres[genre] = false;
}
}
IApiResponse<IEnumerable<GenreResponse>> response = await GenresClient.GetGenres();
if (response.IsSuccessful)
{
IEnumerable<short> tempSelected = _chosenGenres.Keys.Select(x => x.Id);
_availableGenres.AddRange(response.Content.Where(x => !tempSelected.Contains(x.Id)));
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Genres could not be obtained.", SnackbarColor.Danger);
}
}
private async Task AddGenre()
{
_addLoading = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await MediaClient.PostMediumGenre(token, Data.Id, _selectedGenre!.Value);
if (response.IsSuccessful)
{
GenreResponse selectedGenre = _availableGenres.First(x => x.Id == _selectedGenre);
_availableGenres.Remove(selectedGenre);
_chosenGenres[selectedGenre] = false;
_selectedGenre = null;
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Genre could not be added.", SnackbarColor.Danger);
}
_addLoading = false;
}
private async Task RemoveGenre(GenreResponse genre)
{
_chosenGenres[genre] = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await MediaClient.DeleteMediumGenre(token, Data.Id, genre.Id);
if (response.IsSuccessful)
{
_chosenGenres.Remove(genre);
_availableGenres.Add(genre);
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Genre could not be removed.", SnackbarColor.Danger);
}
}
#endregion
}

View File

@@ -0,0 +1,26 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel" role="button" @onclick="@(Data is not null ? () => NavigationManager.NavigateTo($"/media/{Data.Id}") : null)" style="cursor: @(Data is null ? "default" : "pointer")">
<div class="d-flex gap-3 align-items-center">
<Image Content="@(Data?.Picture)" Height="60" Placeholder="/assets/placeholders/medium.png" AlternativeText="poster"/>
<div class="d-flex-inline flex-column">
<h2 id="primaryText" class="m-0">
@if (Data is null)
{
<span class="fw-bold">New @(TypeIfNull == NullType.Movie ? "movie" : "TV series")</span>
}
else
{
<span class="fw-bold">@(Data.Title)</span>
}
</h2>
@if (Data is not null)
{
<span id="secondaryText" class="text-secondary">Medium settings</span>
}
</div>
</div>
</div>

View File

@@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Components;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
using WatchIt.Website.Clients;
namespace WatchIt.Website.Components.Panels.Pages.MediumEditPage;
public partial class HeaderPanel : Component
{
#region SERVICES
[Inject] public IMediaClient MediaClient { get; set; } = null!;
[Inject] public NavigationManager NavigationManager { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required BaseMediumResponse? Data { get; set; }
[Parameter] public required NullType TypeIfNull { get; set; }
#endregion
}

View File

@@ -0,0 +1,9 @@
/* IDS */
#primaryText {
margin-top: -8px !important;
}
#secondaryText {
color: lightgray !important;
}

View File

@@ -0,0 +1,7 @@
namespace WatchIt.Website.Components.Panels.Pages.MediumEditPage;
public enum NullType
{
Movie,
Series
}

View File

@@ -0,0 +1,160 @@
@using System.Drawing
@using Blazorise.Extensions
@using WatchIt.DTO.Models.Controllers.Photos.Photo
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel">
<div class="container-grid">
<div class="row mb-3">
<div class="col">
<div class="d-flex align-items-center h-100">
<h4 class="m-0"><strong>Photos</strong></h4>
</div>
</div>
<div class="col-auto">
@if (!_photoEditMode)
{
<button type="button" class="btn btn-secondary" disabled="@(!Id.HasValue || !_loaded)" @onclick="() => InitEditPhoto(null)">Add new photo</button>
}
else
{
<div class="d-flex gap-3 align-items-center">
<button type="button" class="btn btn-secondary" disabled="@(_photoEditSaving)" @onclick="SaveEditPhoto">
<LoadingButtonContent IsLoading="@(_photoEditSaving)" LoadingContent="Saving..." Content="Save"/>
</button>
<button type="button" class="btn btn-secondary" disabled="@(_photoEditSaving)" @onclick="CancelEditPhoto">Cancel</button>
</div>
}
</div>
</div>
<div class="row">
<div class="col">
@if (!_photoEditMode)
{
if (_loaded)
{
if (!_photos.IsNullOrEmpty())
{
<div id="scrollPhotos" class="d-flex p-3 gap-3" data-bs-spy="scroll" tabindex="0">
@foreach (PhotoResponse photo in _photos)
{
<div class="container-grid photo-container">
<div class="row">
<div class="col">
<Image Content="@(photo)" AlternativeText="photo" Width="350" Placeholder="/assets/placeholders/photo.png" AspectRatio="Image.ImageComponentAspectRatio.Photo"/>
</div>
</div>
<div class="row mt-2 gx-2">
@if (photo.Background is not null)
{
<div class="col-auto">
<div class="d-flex align-items-center">
<div id="backgroundIndicator" class="border rounded-circle circle-@(photo.Background.IsUniversal ? "blue" : "grey") p-1" data-toggle="tooltip" data-placement="top" title="@(photo.Background.IsUniversal ? "Universal" : "Media-only") background">
<img class="no-vertical-align" src="assets/icons/background.png" alt="background_icon" height="20px" width="20px"/>
</div>
</div>
</div>
}
<div class="col">
<div class="d-flex align-items-center h-100 text-size-upload-date">
Upload: @(photo.UploadDate.ToString("g"))
</div>
</div>
<div class="col-auto">
<button type="button" class="btn btn-secondary btn-sm" @onclick="() => InitEditPhoto(photo.Id)" disabled="@(_photoDeleting.Contains(photo.Id))">
<img src="assets/icons/edit.png" alt="edit_icon" height="20px" width="20px"/>
</button>
</div>
<div class="col-auto">
<button type="button" class="btn btn-danger btn-sm" disabled="@(_photoDeleting.Contains(photo.Id))" @onclick="() => DeletePhoto(photo.Id)">
@if (!_photoDeleting.Contains(photo.Id))
{
<img src="assets/icons/delete.png" alt="delete_icon" height="20px" width="20px"/>
}
else
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
}
</button>
</div>
</div>
</div>
}
</div>
}
else
{
<div class="d-flex justify-content-center">
Photo list is empty
</div>
}
}
else
{
<div class="d-flex justify-content-center">
<Loading Color="Loading.Colors.Light"/>
</div>
}
}
else
{
<div class="container-grid">
<div class="row">
<div class="col-auto">
<div class="container-grid">
<div class="row">
<div class="col">
<Image Content="@(_photoEditRequest)" Placeholder="/assets/placeholders/photo.png" AlternativeText="edit_photo" Width="300" AspectRatio="Image.ImageComponentAspectRatio.Photo"/>
</div>
</div>
@if (_photoEditId is null)
{
<div class="row mt-2">
<div class="col">
<InputFile class="form-control" OnChange="LoadPhoto" autocomplete="off" style="width: 300px;"/>
</div>
</div>
}
</div>
</div>
<div class="col">
<div class="container-grid">
<div class="row form-group">
<div class="col">
<div class="form-check">
<InputCheckbox class="form-check-input" @bind-Value="_photoEditIsBackground"/>
<label class="form-check-label">Use as background</label>
</div>
</div>
<div class="col">
<div class="form-check">
<InputCheckbox class="form-check-input" @bind-Value="_photoEditBackgroundData.IsUniversal" disabled="@(!_photoEditIsBackground)"/>
<label class="form-check-label">Use as universal background</label>
</div>
</div>
</div>
<div class="row form-group my-1">
<label for="first-gradient-color" class="col-4 col-form-label">First gradient color</label>
<div class="col-8">
<input type="color" class="form-control form-control-color w-100" id="first-gradient-color" value="@(ColorTranslator.ToHtml(_photoEditBackgroundData.FirstGradientColor))" disabled="@(!_photoEditIsBackground)" @onchange="EditPhotoFirstGradientColorChanged">
</div>
</div>
<div class="row form-group">
<label for="second-gradient-color" class="col-4 col-form-label">Second gradient color</label>
<div class="col-8">
<input type="color" class="form-control form-control-color w-100" id="second-gradient-color" value="@(ColorTranslator.ToHtml(_photoEditBackgroundData.SecondGradientColor))" disabled="@(!_photoEditIsBackground)" @onchange="EditPhotoSecondGradientColorChanged">
</div>
</div>
</div>
</div>
</div>
</div>
}
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,215 @@
using System.Drawing;
using System.Net;
using Blazorise;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Refit;
using WatchIt.DTO.Models.Controllers.Photos;
using WatchIt.DTO.Models.Controllers.Photos.Photo;
using WatchIt.DTO.Models.Controllers.Photos.PhotoBackground;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
using Color = System.Drawing.Color;
namespace WatchIt.Website.Components.Panels.Pages.MediumEditPage;
public partial class PhotosEditPanel : Component
{
#region SERVICES
[Inject] public NavigationManager NavigationManager { get; set; } = null!;
[Inject] public IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] public IPhotosClient PhotosClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public long? Id { get; set; }
#endregion
#region FIELDS
private bool _loaded;
private IEnumerable<PhotoResponse> _photos = new List<PhotoResponse>();
private List<Guid> _photoDeleting = new List<Guid>();
private bool _photoEditMode;
private Guid? _photoEditId;
private bool _photoEditSaving;
private bool _photoEditIsBackground;
private PhotoRequest? _photoEditRequest;
private PhotoBackgroundRequest? _photoEditBackgroundData = new PhotoBackgroundRequest()
{
FirstGradientColor = Color.FromArgb(0xFF, 0xFF, 0xFF),
SecondGradientColor = Color.FromArgb(0x00, 0x00, 0x00),
IsUniversal = false
};
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
if (Id.HasValue)
{
IApiResponse<IEnumerable<PhotoResponse>> response = await PhotosClient.GetPhotos(new PhotoFilterQuery
{
MediumId = Id.Value,
});
if (response.IsSuccessful)
{
_photos = response.Content;
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Photos cannot be downloaded.", SnackbarColor.Danger);
}
}
_loaded = true;
StateHasChanged();
}
private async Task DeletePhoto(Guid id)
{
_photoDeleting.Add(id);
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await PhotosClient.DeletePhoto(token, id);
if (response.IsSuccessful)
{
NavigationManager.Refresh(true);
}
else
{
_photoDeleting.Remove(id);
await Base.SnackbarStack.PushAsync("An error occured. Photo cannot be removed.", SnackbarColor.Danger);
}
}
private void InitEditPhoto(Guid? id)
{
_photoEditMode = true;
_photoEditId = id;
_photoEditRequest = null;
_photoEditIsBackground = false;
_photoEditBackgroundData = new PhotoBackgroundRequest
{
FirstGradientColor = Color.FromArgb(0xFF, 0xFF, 0xFF),
SecondGradientColor = Color.FromArgb(0x00, 0x00, 0x00),
IsUniversal = false
};
Console.WriteLine(ColorTranslator.ToHtml(_photoEditBackgroundData.FirstGradientColor));
if (id is not null)
{
PhotoResponse response = _photos.First(x => x.Id == id);
_photoEditRequest = response.ToRequest();
if (_photoEditRequest.BackgroundData is not null)
{
_photoEditIsBackground = true;
_photoEditBackgroundData = _photoEditRequest.BackgroundData;
}
}
}
private void CancelEditPhoto()
{
_photoEditMode = false;
_photoEditId = null;
}
private async Task SaveEditPhoto()
{
_photoEditSaving = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response;
_photoEditRequest.BackgroundData = _photoEditIsBackground ? _photoEditBackgroundData : null;
if (_photoEditId is null)
{
response = await PhotosClient.PostPhoto(token, _photoEditRequest);
}
else
{
response = await PhotosClient.PutPhoto(token, _photoEditId.Value, _photoEditRequest);
}
switch (response)
{
case { IsSuccessful: true }:
await Base.SnackbarStack.PushAsync("Photo saved successfully.", SnackbarColor.Success);
NavigationManager.Refresh(true);
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("You are not authorized to edit photos.", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_photoEditMode = false;
_photoEditId = null;
}
private async Task LoadPhoto(InputFileChangeEventArgs args)
{
if (args.File.ContentType.StartsWith("image"))
{
Stream stream = args.File.OpenReadStream(5242880);
byte[] array;
using (MemoryStream ms = new MemoryStream())
{
await stream.CopyToAsync(ms);
array = ms.ToArray();
}
_photoEditRequest = new PhotoRequest
{
MediumId = Id!.Value,
Image = array,
MimeType = args.File.ContentType
};
}
}
private void EditPhotoFirstGradientColorChanged(ChangeEventArgs e)
{
_photoEditBackgroundData.FirstGradientColor = ColorTranslator.FromHtml(e.Value.ToString());
}
private void EditPhotoSecondGradientColorChanged(ChangeEventArgs e)
{
_photoEditBackgroundData.SecondGradientColor = ColorTranslator.FromHtml(e.Value.ToString());
}
#endregion
}

View File

@@ -0,0 +1,45 @@
/* IDS */
#scrollPhotos {
overflow-x: scroll;
border-color: grey;
border-width: 1px;
border-style: solid;
border-radius: 10px;
}
#backgroundIndicator {
height: 30px;
width: 30px;
}
/* CLASSES */
.circle-blue {
background-color: dodgerblue;
border-color: dodgerblue;
}
.circle-grey {
background-color: grey;
border-color: grey;
}
.no-vertical-align {
vertical-align: inherit;
}
.photo-container {
width: 350px;
}
.text-size-upload-date {
font-size: 12px;
}
.photo-default-aspect-ratio {
aspect-ratio: 16/9;
}

View File

@@ -0,0 +1,78 @@
@using Blazorise.Extensions
@using WatchIt.DTO.Models.Controllers.Genres.Genre
@using WatchIt.DTO.Models.Controllers.Media.Medium.Response
@inherits Component
<div class="panel h-100">
<div class="container-grid">
<div class="row">
<div class="col">
<div class="d-flex flex-wrap metadata-pill-container">
<div class="metadata-pill">
<strong>@(Data is MediumMovieResponse ? "Movie" : "TV Series")</strong>
</div>
@if (Data.ReleaseDate is not null)
{
<div class="metadata-pill">
<strong>Release date:</strong> @Data.ReleaseDate.ToString()
</div>
}
@if (Data.Duration is not null)
{
<div class="metadata-pill">
<strong>Length:</strong> @TimeSpan.FromMinutes(Data.Duration.Value).ToString(@"hh\:mm")
</div>
}
@if (Data is MediumMovieResponse movieData)
{
if (movieData.Budget is not null)
{
<div class="metadata-pill">
<strong>Budget:</strong> @(Math.Round(movieData.Budget.Value))$
</div>
}
}
@if (Data is MediumSeriesResponse seriesData)
{
if (seriesData.HasEnded)
{
<div class="metadata-pill">
Ended
</div>
}
}
</div>
</div>
</div>
<div class="row mt-4">
<div class="col">
<h4><strong>Genres:</strong></h4>
</div>
</div>
<div class="row">
<div class="col">
<div class="d-flex flex-wrap gap-3">
@if (Data.Genres.IsNullOrEmpty())
{
<div>
No genres assigned.
</div>
}
else
{
foreach (GenreResponse genre in Data.Genres)
{
<a class="text-decoration-none text-light" href="/genre/@genre.Id">
<div class="metadata-pill">
@genre.Name
</div>
</a>
}
}
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Components;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
namespace WatchIt.Website.Components.Panels.Pages.MediumPage;
public partial class MetadataPanel : Component
{
#region PARAMETERS
[Parameter] public required BaseMediumResponse Data { get; set; }
#endregion
}

View File

@@ -0,0 +1,42 @@
@using WatchIt.Website.Components.Subcomponents.Common
@using Blazorise
@inherits Component
<div class="panel panel-background-gold h-100 text-dark">
<div class="container-grid">
<div class="row">
<div class="col">
<TitledDisplayRating Rating="@(_globalRating)" Title="Global rating:"/>
</div>
</div>
<div class="row">
<div class="col">
<hr class="rating-separator"/>
</div>
</div>
<div class="row">
<div class="col">
<h4 class="text-dark">
<strong>Your rating:</strong>
</h4>
</div>
</div>
<div class="row">
<div class="col">
<Authorization>
<Authorized>
<Rating SelectedValue="@(_userRating)" SelectedValueChanged="@(UserRatingChanged)" Color="Color.Dark" MaxValue="10" TextSize="@(TextSize.Large)"/>
</Authorized>
<NotAuthorized>
<p class="text-dark">You must be logged in to add a rating</p>
</NotAuthorized>
<Loading>
<LoadingInline Content="Loading..."/>
</Loading>
</Authorization>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,106 @@
using System.Net;
using System.Runtime.InteropServices;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
using WatchIt.DTO.Models.Generics.Rating;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.MediumPage;
public partial class RatingPanel : Component
{
#region SERVICES
[Inject] protected IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] protected IMediaClient MediaClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required BaseMediumResponse Data { get; set; }
#endregion
#region FIELDS
private RatingOverallResponse _globalRating;
private int _userRating = 0;
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
_globalRating = Data.Rating;
if (Base.AuthorizedAccount is not null)
{
IApiResponse<RatingUserResponse> response = await MediaClient.GetMediumUserRating(Data.Id, Base.AuthorizedAccount.Id);
if (response.IsSuccessful || response.StatusCode == HttpStatusCode.NotFound)
{
_userRating = Convert.ToInt32(response.Content?.Rating ?? 0);
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. User rating could not be obtained.", SnackbarColor.Danger);
}
}
StateHasChanged();
}
private async Task UserRatingChanged(int value)
{
if (value == _userRating)
{
return;
}
string accessToken = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response;
if (value == 0)
{
response = await MediaClient.DeleteMediumRating(accessToken, Data.Id);
}
else
{
response = await MediaClient.PutMediumRating(accessToken, Data.Id, new RatingRequest { Rating = Convert.ToByte(value) });
}
if (response.IsSuccessful)
{
_userRating = value;
IApiResponse<RatingOverallResponse> globalRatingResponse = await MediaClient.GetMediumRating(Data.Id);
if (globalRatingResponse.IsSuccessful)
{
_globalRating = globalRatingResponse.Content;
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Global rating could not be updated.", SnackbarColor.Danger);
}
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. User rating could not be changed.", SnackbarColor.Danger);
}
}
#endregion
}

View File

@@ -0,0 +1,6 @@
.rating-separator {
border-color: black;
border-width: 1px;
margin: 10px 0;
}

View File

@@ -0,0 +1,154 @@
@using Blazorise.Extensions
@using WatchIt.DTO.Models.Controllers.Media.Medium.Response
@using WatchIt.DTO.Models.Controllers.Roles.Role.Response
@using WatchIt.Website.Components.Subcomponents.Common
@using Blazorise.Components
@inherits Component
<div class="panel @(Class)">
@if (_loaded)
{
<div class="vstack gap-3">
<div class="container-grid">
<div class="row gx-2">
<div class="col align-self-center">
<h4 class="m-0"><strong>Actor roles</strong></h4>
</div>
@if (!_editingMode)
{
<div class="col-auto">
<button type="button" class="btn btn-secondary" disabled="@(Disabled)" @onclick="@(() => ActivateEditData())">Add</button>
</div>
}
else
{
<div class="col-auto">
<button type="button" class="btn btn-secondary" @onclick="@(CancelEditData)">Cancel</button>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(SaveData)">
<LoadingButtonContent IsLoading="@(_saving)" Content="Save" LoadingContent="Saving..."/>
</button>
</div>
}
</div>
</div>
@if (!_editingMode)
{
if (_roles.IsNullOrEmpty())
{
<span class="text-center">No items</span>
}
else
{
<table class="table table-sm table-transparent">
<thead>
<tr>
<th scope="col">
Media name
</th>
<th scope="col">
Media type
</th>
<th scope="col">
Role type
</th>
<th scope="col">
Role name
</th>
<th class="table-cell-fit" scope="col">
Actions
</th>
</tr>
</thead>
<tbody class="table-group-divider">
@foreach (Guid roleId in _roles.Keys)
{
RoleActorResponse role = _roles[roleId].Data;
MediumResponse medium = _mediaDict[role.MediumId];
<tr>
<td class="align-middle">
@(medium.Title)@(medium.ReleaseDate.HasValue ? $" ({medium.ReleaseDate!.Value.Year})" : string.Empty)
</td>
<td class="align-middle">
@(medium.Type == MediumResponseType.Movie ? "Movie" : "TV Series")
</td>
<td class="align-middle">
@(_roleTypes[role.TypeId])
</td>
<td class="align-middle">
@(role.Name)
</td>
<td class="align-middle table-cell-fit">
<div class="hstack gap-1">
<button class="btn btn-outline-secondary btn-sm" type="button" disabled="@(Disabled || _roles[roleId].Deleting)" @onclick="@(() => ActivateEditData(roleId))"><i class="fas fa-edit"></i></button>
<button class="btn btn-outline-danger btn-sm" type="button" disabled="@(Disabled || _roles[roleId].Deleting)" @onclick="@(() => DeleteData(roleId))">
@if (_roles[roleId].Deleting)
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
}
else
{
<i class="fa-solid fa-trash"></i>
}
</button>
</div>
</td>
</tr>
}
</tbody>
</table>
}
}
else
{
<EditForm Model="@(_roleRequest)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group mb-1">
<label for="actorFormMedia" class="col-1 col-form-label">Media:</label>
<div class="col">
<Autocomplete ElementId="actorFormMedia"
TItem="MediumResponse"
TValue="long"
Data="@(_mediaDict.Values)"
TextField="@(item => item.ReleaseDate.HasValue ? $"{item.Title} ({item.ReleaseDate.Value.Year})" : item.Title)"
ValueField="@(item => item.Id)"
@bind-SelectedValue="@(_roleRequest.MediumId)"
Placeholder="Search..."
Filter="AutocompleteFilter.Contains">
<NotFoundContent Context="not_found_context"> Sorry... @not_found_context was not found</NotFoundContent>
</Autocomplete>
</div>
</div>
<div class="row form-group my-1">
<label for="actorFormType" class="col-1 col-form-label">Type:</label>
<div class="col">
<InputSelect id="actorFormType" class="form-control" TValue="short" @bind-Value="@(_roleRequest.TypeId)">
@foreach (KeyValuePair<short, string> type in _roleTypes)
{
<option value="@(type.Key)">@(type.Value)</option>
}
</InputSelect>
</div>
</div>
<div class="row form-group my-1">
<label for="actorFormName" class="col-1 col-form-label">Name:</label>
<div class="col">
<InputText id="actorFormName" class="form-control" @bind-Value="@(_roleRequest.Name)"/>
</div>
</div>
</div>
</EditForm>
}
</div>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>

View File

@@ -0,0 +1,222 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
using WatchIt.DTO.Models.Controllers.People.Person;
using WatchIt.DTO.Models.Controllers.Roles.Role.Query;
using WatchIt.DTO.Models.Controllers.Roles.Role.Request;
using WatchIt.DTO.Models.Controllers.Roles.Role.Response;
using WatchIt.DTO.Models.Controllers.Roles.RoleActorType;
using WatchIt.DTO.Query;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.PersonEditPage;
public partial class ActorRolesEditPanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private IMediaClient MediaClient { get; set; } = null!;
[Inject] private IRolesClient RolesClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required PersonResponse Data { get; set; }
[Parameter] public List<MediumResponse>? Media { get; set; }
[Parameter] public bool Disabled { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
#endregion
#region FIELDS
private bool _loaded;
private bool _editingMode;
private Guid? _editedId;
private RoleActorRequest _roleRequest = null!;
private bool _saving;
private Dictionary<long, MediumResponse> _mediaDict = new Dictionary<long, MediumResponse>();
private Dictionary<short, string> _roleTypes = new Dictionary<short, string>();
private Dictionary<Guid, (RoleActorResponse Data, bool Deleting)> _roles = new Dictionary<Guid, (RoleActorResponse Data, bool Deleting)>();
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
ResetRequest();
await Task.WhenAll(
[
LoadRoleTypes(),
LoadMedia()
]);
if (Data is not null)
{
await LoadRoles();
}
_loaded = true;
StateHasChanged();
}
private async Task LoadRoleTypes()
{
IApiResponse<IEnumerable<RoleActorTypeResponse>> response = await RolesClient.GetRoleActorTypes();
if (response.IsSuccessful)
{
_roleTypes = response.Content.ToDictionary(x => x.Id, x => x.Name);
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Actor role types list could not be obtained.", SnackbarColor.Danger);
}
}
private async Task LoadMedia()
{
IEnumerable<MediumResponse>? media = Media;
if (media is null)
{
IApiResponse<IEnumerable<MediumResponse>> response = await MediaClient.GetMedia(includePictures: true);
if (response.IsSuccessful)
{
media = response.Content;
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Media list could not be obtained.", SnackbarColor.Danger);
return;
}
}
_mediaDict = media.ToDictionary(x => x.Id, x => x);
}
private async Task LoadRoles()
{
RoleActorFilterQuery filter = new RoleActorFilterQuery
{
PersonId = Data.Id
};
OrderQuery order = new OrderQuery
{
OrderBy = "medium.release_date",
};
IApiResponse<IEnumerable<RoleActorResponse>> response = await RolesClient.GetRoleActors(filter, order);
if (response.IsSuccessful)
{
_roles = response.Content.ToDictionary(x => x.Id, x => (x, false));
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Actor roles could not be obtained.", SnackbarColor.Danger);
}
}
private void CancelEditData()
{
_editingMode = false;
}
private async Task SaveData()
{
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
_saving = true;
IApiResponse<RoleActorResponse> response = await (_editedId.HasValue switch
{
true => RolesClient.PutRoleActor(token, _editedId.Value, _roleRequest),
false => RolesClient.PostRoleActor(token, _roleRequest),
});
switch (response)
{
case { IsSuccessful: true }:
_roles[response.Content.Id] = (response.Content, false);
_roles = _roles.OrderBy(x => _mediaDict[x.Value.Data.MediumId].ReleaseDate)
.ToDictionary(x => x.Key, x => x.Value);
await Base.SnackbarStack.PushAsync("Role saved successfully.", SnackbarColor.Success);
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("You are not authorized to edit roles data.", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saving = false;
_editingMode = false;
}
private void ActivateEditData(Guid? id = null)
{
_editedId = id;
ResetRequest();
if (id is not null && _roles.TryGetValue(id.Value, out (RoleActorResponse Data, bool Deleting) role))
{
_roleRequest.Name = role.Data.Name;
_roleRequest.MediumId = role.Data.MediumId;
_roleRequest.TypeId = role.Data.TypeId;
}
_editingMode = true;
}
private async Task DeleteData(Guid id)
{
_roles[id] = (_roles[id].Data, true);
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await RolesClient.DeleteRole(token, id);
switch (response)
{
case {IsSuccessful: true}:
_roles.Remove(id);
await Base.SnackbarStack.PushAsync("Role removed successfully.", SnackbarColor.Success);
break;
case {StatusCode: HttpStatusCode.Forbidden} or {StatusCode: HttpStatusCode.Unauthorized}:
await Base.SnackbarStack.PushAsync("You are not authorized to remove roles.", SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
}
private void ResetRequest() => _roleRequest = Data is null ? new RoleActorRequest() : new RoleActorRequest
{
PersonId = Data.Id,
};
#endregion
}

View File

@@ -0,0 +1,141 @@
@using Blazorise.Extensions
@using WatchIt.DTO.Models.Controllers.Media.Medium.Response
@using WatchIt.DTO.Models.Controllers.Roles.Role.Response
@using WatchIt.Website.Components.Subcomponents.Common
@using Blazorise.Components
@inherits Component
<div class="panel @(Class)">
@if (_loaded)
{
<div class="vstack gap-3">
<div class="container-grid">
<div class="row gx-2">
<div class="col align-self-center">
<h4 class="m-0"><strong>Creator roles</strong></h4>
</div>
@if (!_editingMode)
{
<div class="col-auto">
<button type="button" class="btn btn-secondary" disabled="@(Disabled)" @onclick="@(() => ActivateEditData())">Add</button>
</div>
}
else
{
<div class="col-auto">
<button type="button" class="btn btn-secondary" @onclick="@(CancelEditData)">Cancel</button>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(SaveData)">
<LoadingButtonContent IsLoading="@(_saving)" Content="Save" LoadingContent="Saving..."/>
</button>
</div>
}
</div>
</div>
@if (!_editingMode)
{
if (_roles.IsNullOrEmpty())
{
<span class="text-center">No items</span>
}
else
{
<table class="table table-sm table-transparent">
<thead>
<tr>
<th scope="col">
Media name
</th>
<th scope="col">
Media type
</th>
<th scope="col">
Role type
</th>
<th class="table-cell-fit" scope="col">
Actions
</th>
</tr>
</thead>
<tbody class="table-group-divider">
@foreach (Guid roleId in _roles.Keys)
{
RoleCreatorResponse role = _roles[roleId].Data;
MediumResponse medium = _mediaDict[role.MediumId];
<tr>
<td class="align-middle">
@(medium.Title)@(medium.ReleaseDate.HasValue ? $" ({medium.ReleaseDate!.Value.Year})" : string.Empty)
</td>
<td class="align-middle">
@(medium.Type == MediumResponseType.Movie ? "Movie" : "TV Series")
</td>
<td class="align-middle">
@(_roleTypes[role.TypeId])
</td>
<td class="align-middle table-cell-fit">
<div class="hstack gap-1">
<button class="btn btn-outline-secondary btn-sm" type="button" disabled="@(Disabled || _roles[roleId].Deleting)" @onclick="@(() => ActivateEditData(roleId))"><i class="fas fa-edit"></i></button>
<button class="btn btn-outline-danger btn-sm" type="button" disabled="@(Disabled || _roles[roleId].Deleting)" @onclick="@(() => DeleteData(roleId))">
@if (_roles[roleId].Deleting)
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
}
else
{
<i class="fa-solid fa-trash"></i>
}
</button>
</div>
</td>
</tr>
}
</tbody>
</table>
}
}
else
{
<EditForm Model="@(_roleRequest)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group mb-1">
<label for="actorFormMedia" class="col-1 col-form-label">Media:</label>
<div class="col">
<Autocomplete ElementId="actorFormMedia"
TItem="MediumResponse"
TValue="long"
Data="@(_mediaDict.Values)"
TextField="@(item => item.ReleaseDate.HasValue ? $"{item.Title} ({item.ReleaseDate.Value.Year})" : item.Title)"
ValueField="@(item => item.Id)"
@bind-SelectedValue="@(_roleRequest.MediumId)"
Placeholder="Search..."
Filter="AutocompleteFilter.Contains">
<NotFoundContent Context="not_found_context"> Sorry... @not_found_context was not found</NotFoundContent>
</Autocomplete>
</div>
</div>
<div class="row form-group my-1">
<label for="actorFormType" class="col-1 col-form-label">Type:</label>
<div class="col">
<InputSelect id="actorFormType" class="form-control" TValue="short" @bind-Value="@(_roleRequest.TypeId)">
@foreach (KeyValuePair<short, string> type in _roleTypes)
{
<option value="@(type.Key)">@(type.Value)</option>
}
</InputSelect>
</div>
</div>
</div>
</EditForm>
}
</div>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>

View File

@@ -0,0 +1,221 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
using WatchIt.DTO.Models.Controllers.People.Person;
using WatchIt.DTO.Models.Controllers.Roles.Role.Query;
using WatchIt.DTO.Models.Controllers.Roles.Role.Request;
using WatchIt.DTO.Models.Controllers.Roles.Role.Response;
using WatchIt.DTO.Models.Controllers.Roles.RoleCreatorType;
using WatchIt.DTO.Query;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.PersonEditPage;
public partial class CreatorRolesEditPanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private IPeopleClient PersonsClient { get; set; } = null!;
[Inject] private IMediaClient MediaClient { get; set; } = null!;
[Inject] private IRolesClient RolesClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required PersonResponse Data { get; set; }
[Parameter] public List<MediumResponse>? Media { get; set; }
[Parameter] public bool Disabled { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
#endregion
#region FIELDS
private bool _loaded;
private bool _editingMode;
private Guid? _editedId;
private RoleCreatorRequest _roleRequest = null!;
private bool _saving;
private Dictionary<long, MediumResponse> _mediaDict = new Dictionary<long, MediumResponse>();
private Dictionary<short, string> _roleTypes = new Dictionary<short, string>();
private Dictionary<Guid, (RoleCreatorResponse Data, bool Deleting)> _roles = new Dictionary<Guid, (RoleCreatorResponse Data, bool Deleting)>();
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
ResetRequest();
await Task.WhenAll(
[
LoadRoleTypes(),
LoadMedia(),
]);
if (Data is not null)
{
await LoadRoles();
}
_loaded = true;
StateHasChanged();
}
private async Task LoadRoleTypes()
{
IApiResponse<IEnumerable<RoleCreatorTypeResponse>> response = await RolesClient.GetRoleCreatorTypes();
if (response.IsSuccessful)
{
_roleTypes = response.Content.ToDictionary(x => x.Id, x => x.Name);
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Creator role types list could not be obtained.", SnackbarColor.Danger);
}
}
private async Task LoadMedia()
{
IEnumerable<MediumResponse>? media = Media;
if (media is null)
{
IApiResponse<IEnumerable<MediumResponse>> response = await MediaClient.GetMedia();
if (response.IsSuccessful)
{
media = response.Content;
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Media list could not be obtained.", SnackbarColor.Danger);
return;
}
}
_mediaDict = media.ToDictionary(x => x.Id, x => x);
}
private async Task LoadRoles()
{
RoleCreatorFilterQuery filter = new RoleCreatorFilterQuery
{
PersonId = Data.Id
};
OrderQuery order = new OrderQuery
{
OrderBy = "medium.release_date",
};
IApiResponse<IEnumerable<RoleCreatorResponse>> response = await RolesClient.GetRoleCreators(filter, order);
if (response.IsSuccessful)
{
_roles = response.Content.ToDictionary(x => x.Id, x => (x, false));
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Creator roles could not be obtained.", SnackbarColor.Danger);
}
}
private void CancelEditData()
{
_editingMode = false;
}
private async Task SaveData()
{
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
_saving = true;
IApiResponse<RoleCreatorResponse> response = await (_editedId.HasValue switch
{
true => RolesClient.PutRoleCreator(token, _editedId.Value, _roleRequest),
false => RolesClient.PostRoleCreator(token, _roleRequest),
});
switch (response)
{
case { IsSuccessful: true }:
_roles[response.Content.Id] = (response.Content, false);
_roles = _roles.OrderBy(x => _mediaDict[x.Value.Data.MediumId].ReleaseDate)
.ToDictionary(x => x.Key, x => x.Value);
await Base.SnackbarStack.PushAsync("Role saved successfully.", SnackbarColor.Success);
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("You are not authorized to edit roles data.", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saving = false;
_editingMode = false;
}
private void ActivateEditData(Guid? id = null)
{
_editedId = id;
ResetRequest();
if (id is not null && _roles.TryGetValue(id.Value, out (RoleCreatorResponse Data, bool Deleting) role))
{
_roleRequest.MediumId = role.Data.MediumId;
_roleRequest.TypeId = role.Data.TypeId;
}
_editingMode = true;
}
private async Task DeleteData(Guid id)
{
_roles[id] = (_roles[id].Data, true);
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await RolesClient.DeleteRole(token, id);
switch (response)
{
case {IsSuccessful: true}:
_roles.Remove(id);
await Base.SnackbarStack.PushAsync("Role removed successfully.", SnackbarColor.Success);
break;
case {StatusCode: HttpStatusCode.Forbidden} or {StatusCode: HttpStatusCode.Unauthorized}:
await Base.SnackbarStack.PushAsync("You are not authorized to remove roles.", SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
}
private void ResetRequest() => _roleRequest = Data is null ? new RoleCreatorRequest() : new RoleCreatorRequest
{
PersonId = Data.Id,
};
#endregion
}

View File

@@ -0,0 +1,68 @@
@using WatchIt.DTO.Models.Controllers.Genders.Gender
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel @(Class)">
@if (_loaded)
{
<EditForm Model="@(_request)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group mb-1">
<label for="name" class="col-2 col-form-label">Name*</label>
<div class="col-10">
<InputText id="name" class="form-control" @bind-Value="_request!.Name"/>
</div>
</div>
<div class="row form-group mb-1">
<label for="fullName" class="col-2 col-form-label">Full name</label>
<div class="col-10">
<InputText id="fullName" class="form-control" @bind-Value="_request!.FullName"/>
</div>
</div>
<div class="row form-group my-1">
<label for="desc" class="col-2 col-form-label">Description</label>
<div class="col-10">
<InputTextArea id="desc" class="form-control" @bind-Value="_request!.Description"/>
</div>
</div>
<div class="row form-group mb-1">
<label for="birthDeathDates" class="col-2 col-form-label">Birth and death</label>
<div class="col-10">
<div id="birthDeathDates" class="input-group">
<InputDate TValue="DateOnly?" class="form-control" @bind-Value="_request!.BirthDate"/>
<span class="input-group-text">-</span>
<InputDate TValue="DateOnly?" class="form-control" @bind-Value="_request!.DeathDate"/>
</div>
</div>
</div>
<div class="row form-group my-1">
<label for="desc" class="col-2 col-form-label">Gender</label>
<div class="col-10">
<InputSelect TValue="short?" id="desc" class="form-control" @bind-Value="_request!.GenderId">
<option value="@(default(short?))">No choice</option>
@foreach (GenderResponse gender in _genders)
{
<option value="@(gender.Id)">@(gender.Name)</option>
}
</InputSelect>
</div>
</div>
<div class="row mt-2">
<div class="col d-flex flex-column align-items-end">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(SaveData)">
<LoadingButtonContent IsLoading="@(_saving)" Content="Save" LoadingContent="Saving..."/>
</button>
</div>
</div>
</div>
</EditForm>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>

View File

@@ -0,0 +1,117 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Genders.Gender;
using WatchIt.DTO.Models.Controllers.People;
using WatchIt.DTO.Models.Controllers.People.Person;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.PersonEditPage;
public partial class EditFormPanel : Component
{
#region SERVICES
[Inject] private NavigationManager NavigationManager { get; set; } = null!;
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private IPeopleClient PeopleClient { get; set; } = null!;
[Inject] private IGendersClient GendersClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public PersonResponse? Data { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
#endregion
#region FIELDS
private bool _loaded;
private bool _saving;
private List<GenderResponse> _genders = [];
private PersonRequest _request = new PersonRequest();
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
if (Data is not null)
{
_request = Data.ToRequest();
}
IApiResponse<IEnumerable<GenderResponse>> gendersResponse = await GendersClient.GetGenders();
if (gendersResponse.IsSuccessful)
{
_genders.AddRange(gendersResponse.Content);
}
else
{
await Base.SnackbarStack.PushAsync("An error has occured. List of genders could not be obtained.", SnackbarColor.Danger);
}
_loaded = true;
StateHasChanged();
}
private async Task SaveData()
{
_saving = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse<PersonResponse> response = await (Data switch
{
null => PeopleClient.PostPerson(token, _request),
_ => PeopleClient.PutPerson(token, Data.Id, _request),
});
switch (response)
{
case { IsSuccessful: true }:
switch (Data)
{
case null: NavigationManager.NavigateTo($"people/{response.Content.Id}/edit", true); break;
default: await Base.SnackbarStack.PushAsync("Data saved successfully.", SnackbarColor.Success); break;
}
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("You are not authorized to edit people data.", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saving = false;
}
#endregion
}

View File

@@ -0,0 +1,27 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel" role="button" @onclick="@(Data is not null ? () => NavigationManager.NavigateTo($"/people/{Data.Id}") : null)" style="cursor: @(Data is null ? "default" : "pointer")">
<div class="d-flex gap-3 align-items-center">
<Image Content="@(Data?.Picture)" Height="60" Placeholder="/assets/placeholders/person.png" AlternativeText="poster"/>
<div class="d-flex-inline flex-column">
<h2 id="primaryText" class="m-0">
@if (Data is null)
{
<span class="fw-bold">New person</span>
}
else
{
<span class="fw-bold">@(Data.Name)</span>
}
</h2>
@if (Data is not null)
{
<span id="secondaryText" class="text-secondary">Person settings</span>
}
</div>
</div>
</div>

View File

@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Components;
using WatchIt.DTO.Models.Controllers.People.Person;
using WatchIt.Website.Clients;
namespace WatchIt.Website.Components.Panels.Pages.PersonEditPage;
public partial class HeaderPanel : Component
{
#region SERVICES
[Inject] public IPeopleClient PeopleClient { get; set; } = null!;
[Inject] public NavigationManager NavigationManager { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required PersonResponse? Data { get; set; }
#endregion
}

View File

@@ -0,0 +1,9 @@
/* IDS */
#primaryText {
margin-top: -8px !important;
}
#secondaryText {
color: lightgray !important;
}

View File

@@ -0,0 +1,18 @@
@inherits Component
<div class="panel h-100">
<div class="d-flex flex-wrap metadata-pill-container">
@if (!string.IsNullOrWhiteSpace(Data.Gender?.Name))
{
<div class="metadata-pill"><strong>Gender:</strong> @(Data.Gender?.Name)</div>
}
@if (Data.BirthDate.HasValue)
{
<div class="metadata-pill"><strong>Birth date:</strong> @(Data.BirthDate.Value.ToString())</div>
}
@if (Data.DeathDate.HasValue)
{
<div class="metadata-pill"><strong>Death date:</strong> @(Data.DeathDate.Value.ToString())</div>
}
</div>
</div>

View File

@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Components;
using WatchIt.DTO.Models.Controllers.People.Person;
namespace WatchIt.Website.Components.Panels.Pages.PersonPage;
public partial class MetadataPanel : Component
{
#region PARAMETERS
[Parameter] public required PersonResponse Data { get; set; }
#endregion
}

View File

@@ -0,0 +1,24 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel panel-background-gold h-100 text-dark">
<div class="vstack">
<TitledDisplayRating Rating="@(_globalRating)" Title="Global rating:"/>
<hr/>
<Authorization>
<Authorized>
<TitledDisplayRating Rating="@(_userRating)" Title="Your rating:"/>
</Authorized>
<NotAuthorized>
<div class="vstack">
<h4 class="fw-bold">Your rating:</h4>
<span>Log in to see your rating</span>
</div>
</NotAuthorized>
<Loading>
<LoadingInline/>
</Loading>
</Authorization>
</div>
</div>

View File

@@ -0,0 +1,87 @@
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.People.Person;
using WatchIt.DTO.Models.Generics.Rating;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
namespace WatchIt.Website.Components.Panels.Pages.PersonPage;
public partial class RatingPanel : Component
{
#region SERVICES
[Inject] protected IPeopleClient PeopleClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required PersonResponse Data { get; set; }
#endregion
#region FIELDS
private RatingOverallResponse _globalRating;
private RatingUserOverallResponse? _userRating;
#endregion
#region PUBLIC METHODS
public async Task Update()
{
await Task.WhenAll(
[
GetGlobalRating(),
GetUserRating()
]);
StateHasChanged();
}
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await base.OnFirstRenderAsync();
_globalRating = Data.Rating;
await GetUserRating();
StateHasChanged();
}
private async Task GetUserRating()
{
if (Base.AuthorizationLoaded && Base.AuthorizedAccount is not null)
{
IApiResponse<RatingUserOverallResponse> response = await PeopleClient.GetPersonUserRating(Data.Id, Base.AuthorizedAccount.Id);
if (response.IsSuccessful)
{
_userRating = response.Content;
}
}
}
private async Task GetGlobalRating()
{
IApiResponse<RatingOverallResponse> response = await PeopleClient.GetPersonRating(Data.Id);
if (response.IsSuccessful)
{
_globalRating = response.Content;
}
}
#endregion
}

View File

@@ -0,0 +1,95 @@
@using Blazorise.Extensions
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
@typeparam TItem
@typeparam TQuery where TQuery : WatchIt.DTO.Query.IFilterQuery
<div class="panel">
<div class="container-grid">
<div class="row mb-4">
<div class="col">
<h4 class="m-0"><strong>@(Title)</strong></h4>
</div>
</div>
@if (_loaded)
{
if (!_items.IsNullOrEmpty())
{
for (int i = 0; i < _items.Count; i++)
{
if (i > 0)
{
<div class="row">
<div class="col">
<hr/>
</div>
</div>
}
<div class="row">
<div class="col">
@{
int iCopy = i;
TItem item = _items[iCopy];
string url = string.Format(UrlIdTemplate, IdFunc(item));
}
<VerticalListItem Name="@(NameFunc(item))"
AdditionalInfo="@(AdditionalNameInfoFunc(item))"
PicturePlaceholder="@(PicturePlaceholder)"
PictureFunc="@(() => PictureFunc(item))"
GlobalRating="@(GlobalRatingFunc(item))"
SecondaryRatingTitle="@(SecondaryRatingTitle)"
GetGlobalRatingMethod="@(() => GetGlobalRatingMethod(item))"
GetSecondaryRatingMethod="@(() => GetSecondaryRatingMethod(item))"
GetYourRatingMethod="@(GetYourRatingMethod is not null ? async userId => (int?)(await GetYourRatingMethod(item, userId))?.Rating : null)"
PutYourRatingMethod="@(PutYourRatingMethod is not null ? request => PutYourRatingMethod(item, request) : null)"
DeleteYourRatingMethod="@(DeleteYourRatingMethod is not null ? () => DeleteYourRatingMethod(item) : null)"
ItemUrl="@(url)"/>
</div>
</div>
}
if (!_allItemsLoaded)
{
<div class="row mt-3">
<div class="col">
<div class="d-flex justify-content-center">
<button class="btn btn-secondary" @onclick="DownloadItems">
@if (!_itemsLoading)
{
<span>Load more</span>
}
else
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span>Loading...</span>
}
</button>
</div>
</div>
</div>
}
}
else
{
<div class="row">
<div class="col">
<div class="d-flex justify-content-center">
No items found
</div>
</div>
</div>
}
}
else
{
<div class="row">
<div class="col">
<Loading Color="@(Loading.Colors.Light)"/>
</div>
</div>
}
</div>
</div>

View File

@@ -0,0 +1,89 @@
using Microsoft.AspNetCore.Components;
using WatchIt.DTO.Models.Generics.Image;
using WatchIt.DTO.Models.Generics.Rating;
using WatchIt.DTO.Query;
namespace WatchIt.Website.Components.Panels.Pages.SearchPage;
public partial class StandardSearchResultPanel<TItem, TQuery> : Component where TQuery : IFilterQuery
{
#region PARAMETERS
[Parameter] public required string Title { get; set; }
[Parameter] public required TQuery Query { get; set; }
[Parameter] public required Func<TQuery, OrderQuery, PagingQuery, Task<IEnumerable<TItem>>> GetItemsMethod { get; set; }
[Parameter] public required Func<TItem, long> IdFunc { get; set; }
[Parameter] public required Func<TItem, string> NameFunc { get; set; }
[Parameter] public Func<TItem, string?> AdditionalNameInfoFunc { get; set; } = _ => null;
[Parameter] public required Func<TItem, Task<ImageResponse?>> PictureFunc { get; set; }
[Parameter] public required Func<TItem, RatingOverallResponse> GlobalRatingFunc { get; set; }
[Parameter] public required string UrlIdTemplate { get; set; }
[Parameter] public required string PicturePlaceholder { get; set; }
[Parameter] public string? SecondaryRatingTitle { get; set; }
[Parameter] public required Func<TItem, Task<RatingOverallResponse?>> GetGlobalRatingMethod { get; set; }
[Parameter] public Func<TItem, Task<IRatingResponse?>>? GetSecondaryRatingMethod { get; set; }
[Parameter] public Func<TItem, long, Task<IRatingUserResponse?>>? GetYourRatingMethod { get; set; }
[Parameter] public Func<TItem, RatingRequest, Task>? PutYourRatingMethod { get; set; }
[Parameter] public Func<TItem, Task>? DeleteYourRatingMethod { get; set; }
#endregion
#region FIELDS
private static readonly OrderQuery _orderQuery = new OrderQuery
{
OrderBy = "rating.average"
};
private readonly PagingQuery _pagingQuery = new PagingQuery
{
First = 5
};
private readonly List<TItem> _items = [];
private bool _loaded;
private bool _allItemsLoaded;
private bool _itemsLoading;
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await DownloadItems();
_pagingQuery.After = 5;
_loaded = true;
StateHasChanged();
}
private async Task DownloadItems()
{
_itemsLoading = true;
IEnumerable<TItem> items = await GetItemsMethod(Query, _orderQuery, _pagingQuery);
_items.AddRange(items);
if (items.Count() < 5)
{
_allItemsLoaded = true;
}
else
{
_pagingQuery.After ??= 0;
_pagingQuery.After += 5;
}
_itemsLoading = false;
}
#endregion
}

View File

@@ -0,0 +1,80 @@
@using Blazorise.Extensions
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel">
<div class="container-grid">
<div class="row mb-4">
<div class="col">
<h4 class="m-0"><strong>Users</strong></h4>
</div>
</div>
@if (_loaded)
{
if (!_items.IsNullOrEmpty())
{
for (int i = 0; i < _items.Count; i++)
{
if (i > 0)
{
<div class="row">
<div class="col">
<hr/>
</div>
</div>
}
<div class="row">
<div class="col">
@{
int iCopy = i;
}
<VerticalListUserItem Item="@(_items[iCopy])"
ProfilePictureIncluded="@(true)"/>
</div>
</div>
}
if (!_allItemsLoaded)
{
<div class="row mt-3">
<div class="col">
<div class="d-flex justify-content-center">
<button class="btn btn-secondary" @onclick="DownloadItems">
@if (!_itemsLoading)
{
<span>Load more</span>
}
else
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span>Loading...</span>
}
</button>
</div>
</div>
</div>
}
}
else
{
<div class="row">
<div class="col">
<div class="d-flex justify-content-center">
No items found
</div>
</div>
</div>
}
}
else
{
<div class="row">
<div class="col">
<Loading Color="@(Loading.Colors.Light)"/>
</div>
</div>
}
</div>
</div>

View File

@@ -0,0 +1,83 @@
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Accounts.Account;
using WatchIt.DTO.Query;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
namespace WatchIt.Website.Components.Panels.Pages.SearchPage;
public partial class UserSearchResultPanel : Component
{
#region SERVICES
[Inject] private IAccountsClient AccountsClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required string Query { get; set; }
#endregion
#region FIELDS
private readonly AccountFilterQuery _filterQuery = new AccountFilterQuery();
private readonly PagingQuery _pagingQuery = new PagingQuery
{
First = 5
};
private List<AccountResponse> _items = [];
private bool _loaded;
private bool _allItemsLoaded;
private bool _itemsLoading;
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await DownloadItems();
_pagingQuery.After = 5;
_loaded = true;
StateHasChanged();
}
private async Task DownloadItems()
{
_itemsLoading = true;
IApiResponse<IEnumerable<AccountResponse>> response = await AccountsClient.GetAccounts(_filterQuery, pagingQuery: _pagingQuery, includeProfilePictures: true);
if (!response.IsSuccessful)
{
await Base.SnackbarStack.PushAsync("An error has occured. Users could not be loaded", SnackbarColor.Danger);
}
IEnumerable<AccountResponse> items = response.Content ?? [];
_items.AddRange(items);
if (items.Count() < 5)
{
_allItemsLoaded = true;
}
else
{
_pagingQuery.After ??= 0;
_pagingQuery.After += 5;
}
_itemsLoading = false;
}
#endregion
}

View File

@@ -0,0 +1,50 @@
@using WatchIt.DTO.Models.Controllers.Genders.Gender
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel @(Class)">
@if (_loaded)
{
<div class="vstack gap-3">
<h4 class="fw-bold">Basic profile info</h4>
<EditForm Model="@(_data)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group my-1">
<label for="desc" class="col-2 col-form-label">Description</label>
<div class="col-10">
<InputTextArea id="desc" class="form-control" @bind-Value="_data!.Description"/>
</div>
</div>
<div class="row form-group my-1">
<label for="desc" class="col-2 col-form-label">Gender</label>
<div class="col-10">
<InputSelect TValue="short?" id="desc" class="form-control" @bind-Value="_data!.GenderId">
<option value="">No choice</option>
@foreach (GenderResponse gender in _genders)
{
<option value="@(gender.Id)">@(gender.Name)</option>
}
</InputSelect>
</div>
</div>
<div class="row mt-2">
<div class="col">
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(Save)">
<LoadingButtonContent IsLoading="@(_saving)" Content="Save" LoadingContent="Saving..."/>
</button>
</div>
</div>
</div>
</div>
</EditForm>
</div>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>

View File

@@ -0,0 +1,105 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Accounts;
using WatchIt.DTO.Models.Controllers.Accounts.Account;
using WatchIt.DTO.Models.Controllers.Accounts.AccountProfileInfo;
using WatchIt.DTO.Models.Controllers.Genders.Gender;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.UserEditPage;
public partial class EditFormPanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private NavigationManager NavigationManager { get; set; } = null!;
[Inject] private IAccountsClient AccountsClient { get; set; } = null!;
[Inject] private IGendersClient GendersClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required AccountResponse Data { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
#endregion
#region FIELDS
private bool _loaded;
private bool _saving;
private IEnumerable<GenderResponse> _genders = [];
private AccountProfileInfoRequest _data = new AccountProfileInfoRequest();
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
_data = Data.ToProfileInfoRequest();
IApiResponse<IEnumerable<GenderResponse>> response = await GendersClient.GetGenders();
if (response.IsSuccessful)
{
_genders = response.Content;
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. List of genders could not be obtained.", SnackbarColor.Danger);
}
_loaded = true;
StateHasChanged();
}
private async Task Save()
{
_saving = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await AccountsClient.PatchAccountProfileInfo(token, _data!);
switch (response)
{
case { IsSuccessful: true}:
await Base.SnackbarStack.PushAsync("Profile info successfully saved.", SnackbarColor.Success);
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("Authentication error", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saving = false;
}
#endregion
}

View File

@@ -0,0 +1,15 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel" role="button" @onclick="@(() => NavigationManager.NavigateTo("/user"))">
<div class="d-flex gap-3 align-items-center">
<AccountPicture Item="@(Data)" Size="60"/>
<div class="d-flex-inline flex-column">
<h2 id="primaryText" class="fw-bold m-0">@(Data.Username)</h2>
<span id="secondaryText" class="text-secondary">User settings</span>
</div>
</div>
</div>

View File

@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Components;
using WatchIt.DTO.Models.Controllers.Accounts.Account;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Subcomponents.Common;
namespace WatchIt.Website.Components.Panels.Pages.UserEditPage;
public partial class HeaderPanel : Component
{
#region SERVICES
[Inject] public NavigationManager NavigationManager { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required AccountResponse Data { get; set; }
#endregion
}

View File

@@ -0,0 +1,9 @@
/* IDS */
#primaryText {
margin-top: -8px !important;
}
#secondaryText {
color: lightgray !important;
}

View File

@@ -0,0 +1,44 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel">
<div class="vstack gap-3">
<h4 class="fw-bold">Change email</h4>
@if (_data is not null)
{
<EditForm Model="@(_data)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group my-1">
<label for="email" class="col-2 col-form-label">New email</label>
<div class="col-10">
<InputText id="email" class="form-control" @bind-Value="_data!.Email"/>
</div>
</div>
<div class="row form-group my-1">
<label for="password" class="col-2 col-form-label">Password</label>
<div class="col-10">
<InputText id="password" type="password" class="form-control" @bind-Value="_data!.Password"/>
</div>
</div>
<div class="row mt-2">
<div class="col">
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(Save)">
<LoadingButtonContent IsLoading="@(_saving)" Content="Save" LoadingContent="Saving..."/>
</button>
</div>
</div>
</div>
</div>
</EditForm>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>
</div>

View File

@@ -0,0 +1,91 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Accounts.Account;
using WatchIt.DTO.Models.Controllers.Accounts.AccountEmail;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.UserEditPage;
public partial class NewEmailPanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = default!;
[Inject] private IAccountsClient AccountsClient { get; set; } = null!;
[Inject] private NavigationManager NavigationManager { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required AccountResponse Data { get; set; }
#endregion
#region FIELDS
private AccountEmailRequest? _data;
private bool _saving;
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
_data = new AccountEmailRequest
{
Email = Data.Email,
};
StateHasChanged();
}
private async Task Save()
{
_saving = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await AccountsClient.PatchAccountEmail(token, _data!);
switch (response)
{
case { IsSuccessful: true}:
Data.Email = _data!.Email;
_data.Password = string.Empty;
await Base.SnackbarStack.PushAsync("Email successfully saved.", SnackbarColor.Success);
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("Incorrect password", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saving = false;
}
#endregion
}

View File

@@ -0,0 +1,50 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel">
<div class="vstack gap-3">
<h4 class="fw-bold">Change password</h4>
@if (_data is not null)
{
<EditForm Model="@(_data)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group my-1">
<label for="oldPassword" class="col-2 col-form-label">Old password</label>
<div class="col-10">
<InputText id="oldPassword" type="password" class="form-control" @bind-Value="_data.OldPassword"/>
</div>
</div>
<div class="row form-group my-1">
<label for="newPassword" class="col-2 col-form-label">New password</label>
<div class="col-10">
<InputText id="newPassword" type="password" class="form-control" @bind-Value="_data.Password"/>
</div>
</div>
<div class="row form-group my-1">
<label for="newPasswordConf" class="col-2 col-form-label">Confirm new password</label>
<div class="col-10">
<InputText id="newPasswordConf" type="password" class="form-control" @bind-Value="_data.PasswordConfirmation"/>
</div>
</div>
<div class="row mt-2">
<div class="col">
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(Save)">
<LoadingButtonContent IsLoading="@(_saving)" Content="Save" LoadingContent="Saving..."/>
</button>
</div>
</div>
</div>
</div>
</EditForm>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>
</div>

View File

@@ -0,0 +1,81 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Accounts.Account;
using WatchIt.DTO.Models.Controllers.Accounts.AccountPassword;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.UserEditPage;
public partial class NewPasswordPanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private IAccountsClient AccountsClient { get; set; } = null!;
[Inject] private NavigationManager NavigationManager { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required AccountResponse Data { get; set; }
#endregion
#region FIELDS
private AccountPasswordRequest? _data = new AccountPasswordRequest();
private bool _saving;
#endregion
#region PRIVATE METHODS
private async Task Save()
{
_saving = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await AccountsClient.PatchAccountPassword(token, _data!);
switch (response)
{
case { IsSuccessful: true}:
_data = new AccountPasswordRequest();
await Base.SnackbarStack.PushAsync("Password successfully saved.", SnackbarColor.Success);
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("Incorrect password", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saving = false;
}
#endregion
}

View File

@@ -0,0 +1,44 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="panel">
<div class="vstack gap-3">
<h4 class="fw-bold">Change username</h4>
@if (_data is not null)
{
<EditForm Model="@(_data)">
<AntiforgeryToken/>
<div class="container-grid">
<div class="row form-group my-1">
<label for="username" class="col-2 col-form-label">New username</label>
<div class="col-10">
<InputText id="username" class="form-control" @bind-Value="_data!.Username"/>
</div>
</div>
<div class="row form-group my-1">
<label for="password" class="col-2 col-form-label">Password</label>
<div class="col-10">
<InputText id="password" type="password" class="form-control" @bind-Value="_data!.Password"/>
</div>
</div>
<div class="row mt-2">
<div class="col">
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(Save)">
<LoadingButtonContent IsLoading="@(_saving)" Content="Save" LoadingContent="Saving..."/>
</button>
</div>
</div>
</div>
</div>
</EditForm>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>
</div>

View File

@@ -0,0 +1,91 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Accounts.Account;
using WatchIt.DTO.Models.Controllers.Accounts.AccountUsername;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.UserEditPage;
public partial class NewUsernamePanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private IAccountsClient AccountsClient { get; set; } = null!;
[Inject] private NavigationManager NavigationManager { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required AccountResponse Data { get; set; }
#endregion
#region FIELDS
private AccountUsernameRequest? _data;
private bool _saving;
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
_data = new AccountUsernameRequest
{
Username = Data.Username,
};
StateHasChanged();
}
private async Task Save()
{
_saving = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await AccountsClient.PatchAccountUsername(token, _data!);
switch (response)
{
case { IsSuccessful: true}:
Data.Username = _data!.Username;
_data.Password = string.Empty;
await Base.SnackbarStack.PushAsync("Username successfully saved.", SnackbarColor.Success);
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("Incorrect password", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saving = false;
}
#endregion
}

View File

@@ -0,0 +1,129 @@
@using System.Drawing
@using WatchIt.DTO.Models.Controllers.Photos.Photo
@using WatchIt.Website.Components.Subcomponents.Common
@using Blazorise.Components
@using WatchIt.DTO.Models.Controllers.Media.Medium.Response
@inherits Component
<div class="panel">
@if (_loaded)
{
<div class="vstack gap-4">
<div class="d-flex align-items-center gap-3">
<h4 class="me-auto m-0 fw-bold">Profile background</h4>
@if (_editMode)
{
<button class="btn btn-danger" @onclick="@(Cancel)">Cancel</button>
}
else
{
<button class="btn btn-secondary" @onclick="@(Edit)">Edit</button>
if (Base.CustomBackground is not null)
{
<button class="btn btn-danger" @onclick="@(Remove)">
<LoadingButtonContent LoadingContent="Removing..." Content="Remove" IsLoading="@(_removeLoading)"/>
</button>
}
}
</div>
@if (_editMode)
{
<div class="vstack gap-3">
<div class="container-grid">
<div class="row gx-2">
<div class="col">
<Autocomplete ElementId="actorFormMedia"
TItem="MediumResponse"
TValue="long?"
Data="@(_mediaList)"
TextField="@(item => item.ReleaseDate.HasValue ? $"{item.Title} ({item.ReleaseDate.Value.Year})" : item.Title)"
ValueField="@(item => item.Id)"
@bind-SelectedValue="@(_selectedMedia)"
Placeholder="Search media..."
Filter="AutocompleteFilter.Contains">
<NotFoundContent Context="not_found_context"> Sorry... @not_found_context was not found</NotFoundContent>
</Autocomplete>
</div>
<div class="col-auto">
<button class="btn btn-secondary" disabled="@(_backgroundsLoading || _selectedMedia is null)" @onclick="@(LoadBackgrounds)">
<LoadingButtonContent LoadingContent="Loading..." Content="Load backgrounds" IsLoading="@(_backgroundsLoading)"/>
</button>
</div>
</div>
</div>
@if (_mediaPhotos is null)
{
<span class="text-center">Select media first</span>
}
else if (!_mediaPhotos.Any())
{
<span class="text-center">No backgrounds for this media</span>
}
else
{
<div id="scrollPhotos" class="d-flex p-3 gap-3" data-bs-spy="scroll" tabindex="0">
@foreach (PhotoResponse photo in _mediaPhotos)
{
<div class="photo-container">
<div class="container-grid">
<div class="row mb-2">
<div class="col">
<Image Content="@(photo)" AlternativeText="photo" Width="350" Placeholder="/assets/photo.png" AspectRatio="Image.ImageComponentAspectRatio.Photo"/>
</div>
</div>
<div class="row gx-2">
<div class="col">
<div class="border rounded-3" style="height: 30px; background: linear-gradient(45deg, @($"{ColorTranslator.ToHtml(photo.Background!.FirstGradientColor)}, {ColorTranslator.ToHtml(photo.Background!.SecondGradientColor)}")"></div>
</div>
<div class="col-auto">
<button type="button" class="btn btn-secondary btn-sm" disabled="@(_saveLoading)" @onclick="@(async () => await Save(photo.Background.Id))">
<LoadingButtonContent LoadingContent="Saving..." Content="Select" IsLoading="@(_saveLoading)"/>
</button>
</div>
</div>
</div>
</div>
}
</div>
}
</div>
}
else
{
if (_selectedPhoto is not null)
{
<div class="container-grid">
<div class="row gx-3 mb-2">
<div class="col">
<Image Class="w-100" Content="@(_selectedPhoto)" AlternativeText="background" Placeholder="/assets/placeholders/photo.png" AspectRatio="Image.ImageComponentAspectRatio.Photo"/>
</div>
<div class="col">
<div class="rounded-3 border h-100" style="height: 30px; background: linear-gradient(45deg, @($"{ColorTranslator.ToHtml(_selectedPhoto.Background!.FirstGradientColor)}, {ColorTranslator.ToHtml(_selectedPhoto.Background!.SecondGradientColor)}"));"></div>
</div>
</div>
<div class="row">
<div class="col">
<div class="d-flex justify-content-center">
<a class="text-decoration-none text-reset" href="/media/@(_selectedPhotoMedia!.Id)">
from <span class="fw-bold">@(_selectedPhotoMedia.Title)</span>@(_selectedPhotoMedia.ReleaseDate.HasValue ? $" ({_selectedPhotoMedia.ReleaseDate.Value.Year})" : string.Empty)
</a>
</div>
</div>
</div>
</div>
}
else
{
<span class="text-center">You don't have selected background. Click "Edit" to choose one.</span>
}
}
</div>
}
else
{
<Loading Color="@(Loading.Colors.Light)"/>
}
</div>

View File

@@ -0,0 +1,179 @@
using System.Net;
using Blazorise.Snackbar;
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Accounts.AccountBackgroundPicture;
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
using WatchIt.DTO.Models.Controllers.Photos.Photo;
using WatchIt.Website.Clients;
using WatchIt.Website.Components.Layout;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.UserEditPage;
public partial class ProfileBackgroundEditorPanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = null!;
[Inject] private IMediaClient MediaClient { get; set; } = null!;
[Inject] private IPhotosClient PhotosClient { get; set; } = null!;
[Inject] private IAccountsClient AccountsClient { get; set; } = null!;
#endregion
#region PARAMETERS
[Parameter] public required long Id { get; set; }
#endregion
#region FIELDS
private bool _loaded;
private bool _editMode;
private long? _selectedMedia;
private IEnumerable<PhotoResponse>? _mediaPhotos;
private bool _backgroundsLoading;
private bool _saveLoading;
private bool _removeLoading;
private IEnumerable<MediumResponse> _mediaList = null!;
private PhotoResponse? _selectedPhoto;
private MediumResponse? _selectedPhotoMedia;
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
await LoadMedia();
_selectedPhoto = Base.CustomBackground;
if (_selectedPhoto is not null)
{
_selectedPhotoMedia = _mediaList.First(x => x.Id == _selectedPhoto.MediumId);
}
_loaded = true;
StateHasChanged();
}
private async Task LoadMedia()
{
IApiResponse<IEnumerable<MediumResponse>> response = await MediaClient.GetMedia();
if (response.IsSuccessful)
{
_mediaList = response.Content;
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. List of media could not be loaded.", SnackbarColor.Danger);
}
}
private async Task Save(Guid id)
{
_saveLoading = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse<PhotoResponse> response = await AccountsClient.PutAccountBackgroundPicture(token, new AccountBackgroundPictureRequest { Id = id });
switch (response)
{
case { IsSuccessful: true}:
Base.CustomBackground = response.Content;
_selectedPhoto = Base.CustomBackground;
_selectedPhotoMedia = _mediaList.First(x => x.Id == _selectedMedia!.Value);
await Base.SnackbarStack.PushAsync("Background picture successfully saved.", SnackbarColor.Success);
break;
case { StatusCode: HttpStatusCode.Forbidden } or { StatusCode: HttpStatusCode.Unauthorized }:
await Base.SnackbarStack.PushAsync("Authentication error", SnackbarColor.Danger);
break;
case { StatusCode: HttpStatusCode.BadRequest }:
string? content = "An unknown error occured.";
if (response.Error is ValidationApiException ex)
{
string? exContent = ex.Content?.Errors.SelectMany(x => x.Value).FirstOrDefault();
if (exContent is not null)
{
content = exContent;
}
}
await Base.SnackbarStack.PushAsync(content, SnackbarColor.Danger);
break;
default:
await Base.SnackbarStack.PushAsync("An unknown error occured.", SnackbarColor.Danger);
break;
}
_saveLoading = false;
Cancel();
}
private void Cancel()
{
_editMode = false;
_selectedMedia = null;
_saveLoading = false;
_backgroundsLoading = false;
_mediaPhotos = null;
}
private void Edit()
{
_editMode = true;
}
private async Task Remove()
{
_removeLoading = true;
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
IApiResponse response = await AccountsClient.DeleteAccountBackgroundPicture(token);
if (response.IsSuccessful)
{
Base.CustomBackground = null;
_selectedPhoto = null;
_selectedPhotoMedia = null;
await Base.SnackbarStack.PushAsync("Background picture successfully removed.", SnackbarColor.Success);
}
else
{
await Base.SnackbarStack.PushAsync("An error occured. Background picture could not be removed.", SnackbarColor.Danger);
}
_removeLoading = false;
}
private async Task LoadBackgrounds()
{
_backgroundsLoading = true;
IApiResponse<IEnumerable<PhotoResponse>> response = await PhotosClient.GetPhotos(new PhotoFilterQuery()
{
IsBackground = true,
MediumId = _selectedMedia!.Value
});
if (!response.IsSuccessful)
{
await Base.SnackbarStack.PushAsync("An error occured. Background photos could not be obtained.", SnackbarColor.Danger);
}
_mediaPhotos = response.Content;
_backgroundsLoading = false;
}
#endregion
}

View File

@@ -0,0 +1,23 @@
/* IDS */
#scrollPhotos {
overflow-x: scroll;
border-color: grey;
border-width: 1px;
border-style: solid;
border-radius: 10px;
}
#backgroundIndicator {
height: 30px;
width: 30px;
}
/* CLASSES */
.photo-container {
width: 350px;
}

View File

@@ -0,0 +1,36 @@
@using WatchIt.DTO.Models.Controllers.Accounts.Account
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div class="vstack gap-default">
<div class="panel panel-section-header">
<h3 class="fw-bold m-0">@(Title)</h3>
</div>
@if (!_loaded)
{
<div class="panel">
<Loading Color="Loading.Colors.Light"/>
</div>
}
else if (!_items.Any())
{
<div class="panel">
<div class="d-flex justify-content-center">
No items
</div>
</div>
}
else
{
foreach (AccountResponse item in _items)
{
<div class="panel">
<VerticalListUserItem Item="item"
PictureSize="50"/>
</div>
}
}
</div>

View File

@@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Components;
using WatchIt.DTO.Models.Controllers.Accounts.Account;
namespace WatchIt.Website.Components.Panels.Pages.UserPage;
public partial class FollowListPanel : Component
{
#region PARAMETERS
[Parameter] public required string Title { get; set; }
[Parameter] public required Func<Task<IEnumerable<AccountResponse>>> GetItemsMethod { get; set; }
#endregion
#region FIELDS
private bool _loaded;
private IEnumerable<AccountResponse> _items = [];
#endregion
#region PRIVATE METHODS
protected override async Task OnFirstRenderAsync()
{
_items = await GetItemsMethod();
_loaded = true;
StateHasChanged();
}
#endregion
}

View File

@@ -0,0 +1,56 @@
@using WatchIt.Website.Components.Subcomponents.Common
@inherits Component
<div id="base" class="vstack">
<AccountPicture Class="shadow position-absolute z-1 start-50 translate-middle" Item="@(Data)" Size="240"/>
<div class="panel z-0">
<div class="vstack gap-3">
<div id="space" class="container-grid"></div>
<div class="d-flex justify-content-center">
<h3 class="fw-bold m-0">@(Data.Username)</h3>
</div>
@if (!string.IsNullOrWhiteSpace(Data.Description))
{
<span class="text-center w-100 mb-2">
@(Data.Description)
</span>
}
<div class="d-flex flex-wrap justify-content-center metadata-pill-container">
<div class="metadata-pill"><strong>Email:</strong> @(Data.Email)</div>
@if (!string.IsNullOrWhiteSpace(Data.Gender?.Name))
{
<div class="metadata-pill"><strong>Gender:</strong> @(Data.Gender?.Name)</div>
}
<div class="metadata-pill"><strong>Joined:</strong> @(Data.JoinDate.LocalDateTime.ToShortDateString())</div>
<div class="metadata-pill"><strong>Last active:</strong> @(Data.ActiveDate.LocalDateTime.ToShortDateString())</div>
@if (Data.IsAdmin)
{
<div class="metadata-pill"><strong>Admin</strong></div>
}
@if (LoggedUserData is not null && Data.Id != LoggedUserData.Id)
{
<div role="button" class="metadata-pill @(!_followLoading ? "metadata-pill-hoverable" : string.Empty)" @onclick="@(Follow)">
@if (_followLoading)
{
<div class="spinner-border spinner-border-sm"></div>
}
else
{
if (Followers.Any(x => x.Id == LoggedUserData.Id))
{
<span><i class="fa fa-eye-slash" aria-hidden="true"></i> Unfollow</span>
}
else
{
<span><i class="fa fa-eye" aria-hidden="true"></i> Follow</span>
}
}
</div>
}
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,71 @@
using Microsoft.AspNetCore.Components;
using Refit;
using WatchIt.DTO.Models.Controllers.Accounts.Account;
using WatchIt.Website.Clients;
using WatchIt.Website.Services.Authentication;
namespace WatchIt.Website.Components.Panels.Pages.UserPage;
public partial class HeaderPanel : Component
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = default!;
[Inject] private IAccountsClient AccountsClient { get; set; } = default!;
#endregion
#region PARAMETERS
[Parameter] public required AccountResponse Data { get; set; }
[Parameter] public required List<AccountResponse> Followers { get; set; }
[Parameter] public AccountResponse? LoggedUserData { get; set; }
[Parameter] public Action<bool>? FollowingChanged { get; set; }
#endregion
#region FIELDS
private bool _followLoading;
#endregion
#region PRIVATE METHODS
private async Task Follow()
{
string token = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
_followLoading = true;
IApiResponse response;
if (Followers.Any(x => x.Id == LoggedUserData!.Id))
{
response = await AccountsClient.DeleteAccountFollow(token, Data.Id);
if (response.IsSuccessful)
{
Followers.RemoveAll(x => x.Id == LoggedUserData!.Id);
FollowingChanged?.Invoke(false);
}
}
else
{
response = await AccountsClient.PostAccountFollow(token, Data.Id);
if (response.IsSuccessful)
{
Followers.Add(LoggedUserData);
FollowingChanged?.Invoke(true);
}
}
if (response.IsSuccessful)
{
_followLoading = false;
}
}
#endregion
}

View File

@@ -0,0 +1,9 @@
/* IDS */
#base {
margin-top: 120px;
}
#space {
height: 100px;
}