changes in model, actor roles adding in person edit page finished

This commit is contained in:
2024-10-08 19:56:14 +02:00
Unverified
parent 35e657d8d1
commit 4064f49240
38 changed files with 352 additions and 163 deletions

View File

@@ -1,5 +1,6 @@
@using Blazorise.Extensions
@using WatchIt.Common.Model.Roles
@using Blazorise.Components
@@ -106,7 +107,44 @@
}
else
{
<EditForm Model="@(_editedModel)">
<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="MediaResponse"
TValue="long"
Data="@(Media.Values)"
TextField="@(item => item.ReleaseDate.HasValue ? $"{item.Title} ({item.ReleaseDate.Value.Year})" : item.Title)"
ValueField="@(item => item.Id)"
@bind-SelectedValue="@(_editedModel.MediaId)"
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>
}

View File

@@ -38,7 +38,7 @@ public partial class PersonRolesEditActorComponent : ComponentBase
private Guid? _editedId;
private IActorRolePersonRequest _editedModel = new ActorRoleRequest();
private IActorRolePersonRequest? _editedModel;
private bool _editingMode;
private bool _saving;
@@ -67,6 +67,7 @@ public partial class PersonRolesEditActorComponent : ComponentBase
// END
await Task.WhenAll(endTasks);
_roles = _roles.OrderBy(x => Media.First(y => y.Key == x.Value.Data.MediaId).Value.ReleaseDate).ToDictionary(x => x.Key, x => x.Value);
_loaded = true;
StateHasChanged();
@@ -78,15 +79,49 @@ public partial class PersonRolesEditActorComponent : ComponentBase
_editingMode = false;
}
private void SaveEdit()
private async Task SaveEdit()
{
void SuccessPost(ActorRoleResponse data)
{
_roles[data.Id] = (data, false);
_roles = _roles.OrderBy(x => Media.First(y => y.Key == x.Value.Data.MediaId).Value.ReleaseDate).ToDictionary(x => x.Key, x => x.Value);
_saving = false;
_editingMode = false;
}
void SuccessPut()
{
ActorRoleResponse temp = _roles[_editedId!.Value].Data;
temp.MediaId = _editedModel.MediaId;
temp.TypeId = _editedModel.TypeId;
temp.Name = _editedModel.Name;
_roles[_editedId!.Value] = (temp, false);
_roles = _roles.OrderBy(x => Media.First(y => y.Key == x.Value.Data.MediaId).Value.ReleaseDate).ToDictionary(x => x.Key, x => x.Value);
_saving = false;
_editingMode = false;
}
_saving = true;
if (_editedId.HasValue)
{
await RolesWebAPIService.PutActorRole(_editedId.Value, _editedModel as ActorRoleUniversalRequest, SuccessPut);
}
else
{
await PersonsWebAPIService.PostPersonActorRole(Id!.Value, _editedModel as ActorRolePersonRequest, SuccessPost);
}
}
private void ActivateEdit(Guid? id = null)
{
_editedId = id;
_editedModel = id.HasValue ? new ActorRoleRequest(_roles[id.Value].Data) : new ActorRoleRequest();
_editedModel = id.HasValue ? new ActorRoleUniversalRequest(_roles[id.Value].Data) : new ActorRolePersonRequest()
{
TypeId = _roleTypes.Keys.First()
};
_editingMode = true;
}

View File

@@ -51,7 +51,7 @@
else
{
<div class="d-flex align-items-center justify-content-center h-100 content-width">
<LoadingComponent/>
<LoadingComponent Color="white"/>
</div>
}
</div>