PersonRolesEditActorComponent added

This commit is contained in:
2024-10-08 02:14:16 +02:00
Unverified
parent bf90df6370
commit 35e657d8d1
20 changed files with 296 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
public class Media
{
public string Base { get; set; }
public string GetAllMedia { get; set; }
public string GetMedia { get; set; }
public string GetMediaGenres { get; set; }
public string PostMediaGenre { get; set; }

View File

@@ -8,6 +8,7 @@ namespace WatchIt.Website.Services.WebAPI.Media;
public interface IMediaWebAPIService
{
Task GetAllMedia(MediaQueryParameters? query = null, Action<IEnumerable<MediaResponse>>? successAction = null);
Task GetMedia(long mediaId, Action<MediaResponse>? successAction = null, Action? notFoundAction = null);
Task GetMediaGenres(long mediaId, Action<IEnumerable<GenreResponse>>? successAction = null, Action? notFoundAction = null);

View File

@@ -35,6 +35,18 @@ public class MediaWebAPIService : BaseWebAPIService, IMediaWebAPIService
#region Main
public async Task GetAllMedia(MediaQueryParameters? query = null, Action<IEnumerable<MediaResponse>>? successAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.GetAllMedia);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
request.Query = query;
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.ExecuteAction();
}
public async Task GetMedia(long mediaId, Action<MediaResponse>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.GetMedia, mediaId);

View File

@@ -9,8 +9,8 @@
<link rel="icon" type="image/png" href="favicon.png"/>
<!-- CSS -->
<link rel="stylesheet" href="css/general.css?version=0.2.0.3"/>
<link rel="stylesheet" href="css/main_button.css?version=0.2.0.0"/>
<link rel="stylesheet" href="css/general.css?version=0.3.0.1"/>
<link rel="stylesheet" href="css/main_button.css?version=0.3.0.0"/>
<link rel="stylesheet" href="WatchIt.Website.styles.css?version=0.2.0.12"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

View File

@@ -45,7 +45,7 @@
</InputSelect>
</div>
</div>
<div class="row">
<div class="row mt-2">
<div class="col align-self-center">
@if (!string.IsNullOrWhiteSpace(_error))
{

View File

@@ -0,0 +1,117 @@
@using Blazorise.Extensions
@using WatchIt.Common.Model.Roles
<div class="rounded-3 panel panel-regular p-3 @(Class)">
@if (_loaded)
{
<div class="vstack gap-3">
<div class="container-grid">
<div class="row gx-2">
<div class="col align-self-center">
<h3 class="m-0"><strong>Actor roles</strong></h3>
</div>
@if (!_editingMode)
{
<div class="col-auto">
<button type="button" class="btn btn-secondary" disabled="@(!Id.HasValue)" @onclick="@(() => ActivateEdit())">Add</button>
</div>
}
else
{
<div class="col-auto">
<button type="button" class="btn btn-secondary" @onclick="@(CancelEdit)">Cancel</button>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(SaveEdit)">
@if (!_saving)
{
<span>Save</span>
}
else
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span>Saving...</span>
}
</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)
{
<tr>
<td class="align-middle">
@(Media[_roles[roleId].Data.MediaId].Title)@(Media[_roles[roleId].Data.MediaId].ReleaseDate.HasValue ? $" ({Media[_roles[roleId].Data.MediaId].ReleaseDate!.Value.Year})" : string.Empty)
</td>
<td class="align-middle">
@(Media[_roles[roleId].Data.MediaId].Type == MediaType.Movie ? $"Movie" : "TV Series")
</td>
<td class="align-middle">
@(_roleTypes[_roles[roleId].Data.TypeId])
</td>
<td class="align-middle">
@(_roles[roleId].Data.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="@(!Id.HasValue || _roles[roleId].Deleting)" @onclick="@(() => ActivateEdit(roleId))"><i class="fas fa-edit"></i></button>
<button class="btn btn-outline-danger btn-sm" type="button" disabled="@(!Id.HasValue || _roles[roleId].Deleting)" @onclick="@(() => Delete(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
{
}
</div>
}
else
{
<LoadingComponent Color="white"/>
}
</div>

View File

@@ -0,0 +1,100 @@
using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Model.Roles;
using WatchIt.Website.Services.WebAPI.Media;
using WatchIt.Website.Services.WebAPI.Persons;
using WatchIt.Website.Services.WebAPI.Roles;
namespace WatchIt.Website.Components.PersonEditPage;
public partial class PersonRolesEditActorComponent : ComponentBase
{
#region SERVICES
[Inject] private IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!;
[Inject] private IMediaWebAPIService MediaWebAPIService { get; set; } = default!;
[Inject] private IRolesWebAPIService RolesWebAPIService { get; set; } = default!;
#endregion
#region PARAMETERS
[Parameter] public required long? Id { get; set; }
[Parameter] public required Dictionary<long, MediaResponse> Media { get; set; }
[Parameter] public string Class { get; set; } = string.Empty;
#endregion
#region FIELDS
private bool _loaded;
private Dictionary<Guid, (ActorRoleResponse Data, bool Deleting)> _roles = [];
private Dictionary<short, string> _roleTypes = [];
private Guid? _editedId;
private IActorRolePersonRequest _editedModel = new ActorRoleRequest();
private bool _editingMode;
private bool _saving;
#endregion
#region PUBLIC METHODS
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
List<Task> endTasks = new List<Task>();
// STEP 0
if (Id.HasValue)
{
endTasks.AddRange(
[
PersonsWebAPIService.GetPersonAllActorRoles(Id.Value, successAction: data => _roles = data.ToDictionary(x => x.Id, x => (x, false))),
RolesWebAPIService.GetAllActorRoleTypes(successAction: data => _roleTypes = data.ToDictionary(x => x.Id, x => x.Name)),
]);
}
// END
await Task.WhenAll(endTasks);
_loaded = true;
StateHasChanged();
}
}
private void CancelEdit()
{
_editingMode = false;
}
private void SaveEdit()
{
}
private void ActivateEdit(Guid? id = null)
{
_editedId = id;
_editedModel = id.HasValue ? new ActorRoleRequest(_roles[id.Value].Data) : new ActorRoleRequest();
_editingMode = true;
}
private async Task Delete(Guid id)
{
_roles[id] = (_roles[id].Data, true);
await RolesWebAPIService.DeleteActorRole(id, () => _roles.Remove(id));
}
#endregion
}

View File

@@ -59,6 +59,12 @@
Class="h-100"/>
</div>
</div>
<div class="row mt-3">
<div class="col">
<PersonRolesEditActorComponent Id="@(Id)"
Media="@(_media)"/>
</div>
</div>
</div>
}
else

View File

@@ -1,7 +1,9 @@
using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Model.Persons;
using WatchIt.Website.Layout;
using WatchIt.Website.Services.Utility.Authentication;
using WatchIt.Website.Services.WebAPI.Media;
using WatchIt.Website.Services.WebAPI.Persons;
namespace WatchIt.Website.Pages;
@@ -13,6 +15,7 @@ public partial class PersonEditPage : ComponentBase
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
[Inject] private IAuthenticationService AuthenticationService { get; set; } = default!;
[Inject] private IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!;
[Inject] private IMediaWebAPIService MediaWebAPIService { get; set; } = default!;
#endregion
@@ -36,6 +39,7 @@ public partial class PersonEditPage : ComponentBase
private User? _user;
private PersonResponse? _person;
private Dictionary<long, MediaResponse> _media = [];
#endregion
@@ -53,7 +57,7 @@ public partial class PersonEditPage : ComponentBase
// STEP 0
step1Tasks.AddRange(
[
Task.Run(async () => _user = await AuthenticationService.GetUserAsync())
Task.Run(async () => _user = await AuthenticationService.GetUserAsync()),
]);
// STEP 1
@@ -62,7 +66,8 @@ public partial class PersonEditPage : ComponentBase
{
endTasks.AddRange(
[
PersonsWebAPIService.GetPerson(Id.Value, data => _person = data, () => NavigationManager.NavigateTo("/person/new", true))
PersonsWebAPIService.GetPerson(Id.Value, data => _person = data, () => NavigationManager.NavigateTo("/person/new", true)),
MediaWebAPIService.GetAllMedia(successAction: data => _media = data.ToDictionary(x => x.Id, x => x)),
]);
}

View File

@@ -14,6 +14,7 @@ using WatchIt.Website.Services.WebAPI.Media;
using WatchIt.Website.Services.WebAPI.Movies;
using WatchIt.Website.Services.WebAPI.Persons;
using WatchIt.Website.Services.WebAPI.Photos;
using WatchIt.Website.Services.WebAPI.Roles;
using WatchIt.Website.Services.WebAPI.Series;
namespace WatchIt.Website;
@@ -79,6 +80,7 @@ public static class Program
builder.Services.AddSingleton<ISeriesWebAPIService, SeriesWebAPIService>();
builder.Services.AddSingleton<IPhotosWebAPIService, PhotosWebAPIService>();
builder.Services.AddSingleton<IPersonsWebAPIService, PersonsWebAPIService>();
builder.Services.AddSingleton<IRolesWebAPIService, RolesWebAPIService>();
return builder;
}

View File

@@ -25,6 +25,7 @@
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Movies\WatchIt.Website.Services.WebAPI.Movies.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Persons\WatchIt.Website.Services.WebAPI.Persons.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Photos\WatchIt.Website.Services.WebAPI.Photos.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Roles\WatchIt.Website.Services.WebAPI.Roles.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Series\WatchIt.Website.Services.WebAPI.Series.csproj" />
</ItemGroup>
@@ -46,6 +47,7 @@
<ItemGroup>
<PackageReference Include="Blazorise.Bootstrap5" Version="1.6.1" />
<PackageReference Include="Blazorise.Components" Version="1.6.1" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.6.1" />
</ItemGroup>

View File

@@ -37,6 +37,7 @@
},
"Media": {
"Base": "/media",
"GetAllMedia": "",
"GetMedia": "/{0}",
"GetMediaGenres": "/{0}/genres",
"PostMediaGenre": "/{0}/genres/{1}",

View File

@@ -42,7 +42,14 @@ body, html {
-webkit-text-fill-color: transparent;
}
.table-transparent {
--bs-table-bg: transparent !important;
}
.table td.table-cell-fit, .table th.table-cell-fit {
white-space: nowrap;
width: 1%;
}