MediaRolesEditComponents added
This commit is contained in:
@@ -8,7 +8,7 @@ public class CreatorRoleMediaRequest : CreatorRoleRequest, ICreatorRoleMediaRequ
|
|||||||
#region PROPERTIES
|
#region PROPERTIES
|
||||||
|
|
||||||
[JsonPropertyName("person_id")]
|
[JsonPropertyName("person_id")]
|
||||||
public required long PersonId { get; set; }
|
public long PersonId { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
@using Blazorise.Extensions
|
||||||
|
@using WatchIt.Common.Model.Roles
|
||||||
|
@using Blazorise.Components
|
||||||
|
@using WatchIt.Common.Model.Persons
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<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">
|
||||||
|
<h4 class="m-0"><strong>Actor roles</strong></h4>
|
||||||
|
</div>
|
||||||
|
@if (!_editingMode)
|
||||||
|
{
|
||||||
|
<div class="col-auto">
|
||||||
|
<button type="button" class="btn btn-secondary" disabled="@(!Id.HasValue)" @onclick="@(() => ActivateEdit())">Add</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(_error))
|
||||||
|
{
|
||||||
|
<div class="col-auto align-self-center">
|
||||||
|
<span class="text-danger">@(_error)</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<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">
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td class="align-middle">
|
||||||
|
@(Persons[_roles[roleId].Data.PersonId].Name)
|
||||||
|
</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
|
||||||
|
{
|
||||||
|
<EditForm Model="@(_editedModel)">
|
||||||
|
<AntiforgeryToken/>
|
||||||
|
<div class="container-grid">
|
||||||
|
<div class="row form-group mb-1">
|
||||||
|
<label for="actorFormPerson" class="col-1 col-form-label">Person:</label>
|
||||||
|
<div class="col">
|
||||||
|
<Autocomplete ElementId="actorFormPerson"
|
||||||
|
TItem="PersonResponse"
|
||||||
|
TValue="long"
|
||||||
|
Data="@(Persons.Values)"
|
||||||
|
TextField="@(item => item.Name)"
|
||||||
|
ValueField="@(item => item.Id)"
|
||||||
|
@bind-SelectedValue="@(_editedModel.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="@(_editedModel.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="@(_editedModel.Name)"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</EditForm>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<LoadingComponent Color="white"/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using WatchIt.Common.Model.Media;
|
||||||
|
using WatchIt.Common.Model.Persons;
|
||||||
|
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.MediaEditPage;
|
||||||
|
|
||||||
|
public partial class MediaRolesEditActorComponent : 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, PersonResponse> Persons { get; set; }
|
||||||
|
[Parameter] public string Class { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region FIELDS
|
||||||
|
|
||||||
|
private bool _loaded;
|
||||||
|
private string? _error;
|
||||||
|
|
||||||
|
private Dictionary<Guid, (ActorRoleResponse Data, bool Deleting)> _roles = [];
|
||||||
|
private Dictionary<short, string> _roleTypes = [];
|
||||||
|
|
||||||
|
|
||||||
|
private Guid? _editedId;
|
||||||
|
private IActorRoleMediaRequest? _editedModel;
|
||||||
|
|
||||||
|
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(
|
||||||
|
[
|
||||||
|
MediaWebAPIService.GetMediaAllActorRoles(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()
|
||||||
|
{
|
||||||
|
_error = null;
|
||||||
|
_editingMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveEdit()
|
||||||
|
{
|
||||||
|
void SuccessPost(ActorRoleResponse data)
|
||||||
|
{
|
||||||
|
_roles[data.Id] = (data, false);
|
||||||
|
|
||||||
|
_saving = false;
|
||||||
|
_editingMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SuccessPut()
|
||||||
|
{
|
||||||
|
ActorRoleResponse temp = _roles[_editedId!.Value].Data;
|
||||||
|
temp.PersonId = _editedModel.PersonId;
|
||||||
|
temp.TypeId = _editedModel.TypeId;
|
||||||
|
temp.Name = _editedModel.Name;
|
||||||
|
|
||||||
|
_roles[_editedId!.Value] = (temp, false);
|
||||||
|
|
||||||
|
_saving = false;
|
||||||
|
_editingMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BadRequest(IDictionary<string, string[]> errors)
|
||||||
|
{
|
||||||
|
_error = errors.SelectMany(x => x.Value).FirstOrDefault() ?? "Unknown error";
|
||||||
|
_saving = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unauthorized()
|
||||||
|
{
|
||||||
|
_error = "You do not have permission to do this";
|
||||||
|
_saving = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_error = null;
|
||||||
|
_saving = true;
|
||||||
|
if (_editedId.HasValue)
|
||||||
|
{
|
||||||
|
await RolesWebAPIService.PutActorRole(_editedId.Value, _editedModel as ActorRoleUniversalRequest, SuccessPut, BadRequest, Unauthorized);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await MediaWebAPIService.PostMediaActorRole(Id!.Value, _editedModel as ActorRoleMediaRequest, SuccessPost, BadRequest, Unauthorized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ActivateEdit(Guid? id = null)
|
||||||
|
{
|
||||||
|
_editedId = id;
|
||||||
|
_editedModel = id.HasValue ? new ActorRoleUniversalRequest(_roles[id.Value].Data) : new ActorRoleMediaRequest()
|
||||||
|
{
|
||||||
|
TypeId = _roleTypes.Keys.First()
|
||||||
|
};
|
||||||
|
_editingMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Delete(Guid id)
|
||||||
|
{
|
||||||
|
_roles[id] = (_roles[id].Data, true);
|
||||||
|
await RolesWebAPIService.DeleteActorRole(id, () => _roles.Remove(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
@using Blazorise.Extensions
|
||||||
|
@using Blazorise.Components
|
||||||
|
@using WatchIt.Common.Model.Persons
|
||||||
|
|
||||||
|
|
||||||
|
<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">
|
||||||
|
<h4 class="m-0"><strong>Creator roles</strong></h4>
|
||||||
|
</div>
|
||||||
|
@if (!_editingMode)
|
||||||
|
{
|
||||||
|
<div class="col-auto">
|
||||||
|
<button type="button" class="btn btn-secondary" disabled="@(!Id.HasValue)" @onclick="@(() => ActivateEdit())">Add</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(_error))
|
||||||
|
{
|
||||||
|
<div class="col-auto align-self-center">
|
||||||
|
<span class="text-danger">@(_error)</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<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">
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td class="align-middle">
|
||||||
|
@(Persons[_roles[roleId].Data.PersonId].Name)
|
||||||
|
</td>
|
||||||
|
<td class="align-middle">
|
||||||
|
@(_roleTypes[_roles[roleId].Data.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="@(!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
|
||||||
|
{
|
||||||
|
<EditForm Model="@(_editedModel)">
|
||||||
|
<AntiforgeryToken/>
|
||||||
|
<div class="container-grid">
|
||||||
|
<div class="row form-group mb-1">
|
||||||
|
<label for="creatorFormPerson" class="col-1 col-form-label">Media:</label>
|
||||||
|
<div class="col">
|
||||||
|
<Autocomplete ElementId="creatorFormPerson"
|
||||||
|
TItem="PersonResponse"
|
||||||
|
TValue="long"
|
||||||
|
Data="@(Persons.Values)"
|
||||||
|
TextField="@(item => item.Name)"
|
||||||
|
ValueField="@(item => item.Id)"
|
||||||
|
@bind-SelectedValue="@(_editedModel.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="creatorFormType" class="col-1 col-form-label">Type:</label>
|
||||||
|
<div class="col">
|
||||||
|
<InputSelect id="creatorFormType" class="form-control" TValue="short" @bind-Value="@(_editedModel.TypeId)">
|
||||||
|
@foreach (KeyValuePair<short, string> type in _roleTypes)
|
||||||
|
{
|
||||||
|
<option value="@(type.Key)">@(type.Value)</option>
|
||||||
|
}
|
||||||
|
</InputSelect>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</EditForm>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<LoadingComponent Color="white"/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using WatchIt.Common.Model.Media;
|
||||||
|
using WatchIt.Common.Model.Persons;
|
||||||
|
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.MediaEditPage;
|
||||||
|
|
||||||
|
public partial class MediaRolesEditCreatorComponent : 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, PersonResponse> Persons { get; set; }
|
||||||
|
[Parameter] public string Class { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region FIELDS
|
||||||
|
|
||||||
|
private bool _loaded;
|
||||||
|
private string? _error;
|
||||||
|
|
||||||
|
private Dictionary<Guid, (CreatorRoleResponse Data, bool Deleting)> _roles = [];
|
||||||
|
private Dictionary<short, string> _roleTypes = [];
|
||||||
|
|
||||||
|
|
||||||
|
private Guid? _editedId;
|
||||||
|
private ICreatorRoleMediaRequest? _editedModel;
|
||||||
|
|
||||||
|
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(
|
||||||
|
[
|
||||||
|
MediaWebAPIService.GetMediaAllCreatorRoles(Id.Value, successAction: data => _roles = data.ToDictionary(x => x.Id, x => (x, false))),
|
||||||
|
RolesWebAPIService.GetAllCreatorRoleTypes(successAction: data => _roleTypes = data.ToDictionary(x => x.Id, x => x.Name)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// END
|
||||||
|
await Task.WhenAll(endTasks);
|
||||||
|
|
||||||
|
_loaded = true;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CancelEdit()
|
||||||
|
{
|
||||||
|
_error = null;
|
||||||
|
_editingMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveEdit()
|
||||||
|
{
|
||||||
|
void SuccessPost(CreatorRoleResponse data)
|
||||||
|
{
|
||||||
|
_roles[data.Id] = (data, false);
|
||||||
|
|
||||||
|
_saving = false;
|
||||||
|
_editingMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SuccessPut()
|
||||||
|
{
|
||||||
|
CreatorRoleResponse temp = _roles[_editedId!.Value].Data;
|
||||||
|
temp.PersonId = _editedModel.PersonId;
|
||||||
|
temp.TypeId = _editedModel.TypeId;
|
||||||
|
|
||||||
|
_roles[_editedId!.Value] = (temp, false);
|
||||||
|
|
||||||
|
_saving = false;
|
||||||
|
_editingMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BadRequest(IDictionary<string, string[]> errors)
|
||||||
|
{
|
||||||
|
_error = errors.SelectMany(x => x.Value).FirstOrDefault() ?? "Unknown error";
|
||||||
|
_saving = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unauthorized()
|
||||||
|
{
|
||||||
|
_error = "You do not have permission to do this";
|
||||||
|
_saving = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_error = null;
|
||||||
|
_saving = true;
|
||||||
|
if (_editedId.HasValue)
|
||||||
|
{
|
||||||
|
await RolesWebAPIService.PutCreatorRole(_editedId.Value, _editedModel as CreatorRoleUniversalRequest, SuccessPut, BadRequest, Unauthorized);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await MediaWebAPIService.PostMediaCreatorRole(Id!.Value, _editedModel as CreatorRoleMediaRequest, SuccessPost, BadRequest, Unauthorized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ActivateEdit(Guid? id = null)
|
||||||
|
{
|
||||||
|
_editedId = id;
|
||||||
|
_editedModel = id.HasValue ? new CreatorRoleUniversalRequest(_roles[id.Value].Data) : new CreatorRoleMediaRequest()
|
||||||
|
{
|
||||||
|
TypeId = _roleTypes.Keys.First()
|
||||||
|
};
|
||||||
|
_editingMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Delete(Guid id)
|
||||||
|
{
|
||||||
|
_roles[id] = (_roles[id].Data, true);
|
||||||
|
await RolesWebAPIService.DeleteCreatorRole(id, () => _roles.Remove(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
<div class="container-grid">
|
<div class="container-grid">
|
||||||
<div class="row gx-2">
|
<div class="row gx-2">
|
||||||
<div class="col align-self-center">
|
<div class="col align-self-center">
|
||||||
<h3 class="m-0"><strong>Actor roles</strong></h3>
|
<h4 class="m-0"><strong>Actor roles</strong></h4>
|
||||||
</div>
|
</div>
|
||||||
@if (!_editingMode)
|
@if (!_editingMode)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<div class="container-grid">
|
<div class="container-grid">
|
||||||
<div class="row gx-2">
|
<div class="row gx-2">
|
||||||
<div class="col align-self-center">
|
<div class="col align-self-center">
|
||||||
<h3 class="m-0"><strong>Creator roles</strong></h3>
|
<h4 class="m-0"><strong>Creator roles</strong></h4>
|
||||||
</div>
|
</div>
|
||||||
@if (!_editingMode)
|
@if (!_editingMode)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -199,6 +199,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col">
|
||||||
|
<MediaRolesEditActorComponent Id="@(Id)"
|
||||||
|
Persons="@(_persons)"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col">
|
||||||
|
<MediaRolesEditCreatorComponent Id="@(Id)"
|
||||||
|
Persons="@(_persons)"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="rounded-3 panel panel-regular p-4">
|
<div class="rounded-3 panel panel-regular p-4">
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ using Microsoft.AspNetCore.Components;
|
|||||||
using Microsoft.AspNetCore.Components.Forms;
|
using Microsoft.AspNetCore.Components.Forms;
|
||||||
using WatchIt.Common.Model.Media;
|
using WatchIt.Common.Model.Media;
|
||||||
using WatchIt.Common.Model.Movies;
|
using WatchIt.Common.Model.Movies;
|
||||||
|
using WatchIt.Common.Model.Persons;
|
||||||
using WatchIt.Common.Model.Photos;
|
using WatchIt.Common.Model.Photos;
|
||||||
using WatchIt.Common.Model.Series;
|
using WatchIt.Common.Model.Series;
|
||||||
using WatchIt.Website.Layout;
|
using WatchIt.Website.Layout;
|
||||||
using WatchIt.Website.Services.Utility.Authentication;
|
using WatchIt.Website.Services.Utility.Authentication;
|
||||||
using WatchIt.Website.Services.WebAPI.Media;
|
using WatchIt.Website.Services.WebAPI.Media;
|
||||||
using WatchIt.Website.Services.WebAPI.Movies;
|
using WatchIt.Website.Services.WebAPI.Movies;
|
||||||
|
using WatchIt.Website.Services.WebAPI.Persons;
|
||||||
using WatchIt.Website.Services.WebAPI.Photos;
|
using WatchIt.Website.Services.WebAPI.Photos;
|
||||||
using WatchIt.Website.Services.WebAPI.Series;
|
using WatchIt.Website.Services.WebAPI.Series;
|
||||||
|
|
||||||
@@ -24,6 +26,7 @@ public partial class MediaEditPage : ComponentBase
|
|||||||
[Inject] public IMoviesWebAPIService MoviesWebAPIService { get; set; } = default!;
|
[Inject] public IMoviesWebAPIService MoviesWebAPIService { get; set; } = default!;
|
||||||
[Inject] public ISeriesWebAPIService SeriesWebAPIService { get; set; } = default!;
|
[Inject] public ISeriesWebAPIService SeriesWebAPIService { get; set; } = default!;
|
||||||
[Inject] public IPhotosWebAPIService PhotosWebAPIService { get; set; } = default!;
|
[Inject] public IPhotosWebAPIService PhotosWebAPIService { get; set; } = default!;
|
||||||
|
[Inject] public IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -48,6 +51,8 @@ public partial class MediaEditPage : ComponentBase
|
|||||||
private User? _user;
|
private User? _user;
|
||||||
|
|
||||||
private MediaResponse? _media;
|
private MediaResponse? _media;
|
||||||
|
private Dictionary<long, PersonResponse> _persons;
|
||||||
|
|
||||||
private MovieRequest? _movieRequest;
|
private MovieRequest? _movieRequest;
|
||||||
private SeriesRequest? _seriesRequest;
|
private SeriesRequest? _seriesRequest;
|
||||||
private Media? _mediaRequest => _movieRequest is not null ? _movieRequest : _seriesRequest;
|
private Media? _mediaRequest => _movieRequest is not null ? _movieRequest : _seriesRequest;
|
||||||
@@ -107,6 +112,10 @@ public partial class MediaEditPage : ComponentBase
|
|||||||
[
|
[
|
||||||
InitializeMedia()
|
InitializeMedia()
|
||||||
]);
|
]);
|
||||||
|
endTasks.AddRange(
|
||||||
|
[
|
||||||
|
PersonsWebAPIService.GetAllPersons(successAction: data => _persons = data.ToDictionary(x => x.Id, x => x))
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 2
|
// STEP 2
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
@using WatchIt.Website.Layout
|
@using WatchIt.Website.Layout
|
||||||
@using WatchIt.Website.Components
|
@using WatchIt.Website.Components
|
||||||
@using WatchIt.Website.Components.PersonEditPage
|
@using WatchIt.Website.Components.PersonEditPage
|
||||||
|
@using WatchIt.Website.Components.MediaEditPage
|
||||||
@using WatchIt.Common.Model.Accounts
|
@using WatchIt.Common.Model.Accounts
|
||||||
@using WatchIt.Common.Model.Media
|
@using WatchIt.Common.Model.Media
|
||||||
@using WatchIt.Website.Services.Utility.Tokens
|
@using WatchIt.Website.Services.Utility.Tokens
|
||||||
|
|||||||
Reference in New Issue
Block a user