PersonEditFormComponent added
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace WatchIt.Common.Model.Persons;
|
||||
@@ -10,6 +11,29 @@ public class PersonRequest : Person
|
||||
public short? GenderId { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public PersonRequest()
|
||||
{
|
||||
Name = string.Empty;
|
||||
}
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public PersonRequest(PersonResponse person)
|
||||
{
|
||||
Name = person.Name;
|
||||
FullName = person.FullName;
|
||||
Description = person.Description;
|
||||
BirthDate = person.BirthDate;
|
||||
DeathDate = person.DeathDate;
|
||||
GenderId = person.Gender?.Id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
using FluentValidation;
|
||||
using WatchIt.Common.Model.Persons;
|
||||
using WatchIt.Database;
|
||||
|
||||
namespace WatchIt.WebAPI.Validators.Persons;
|
||||
|
||||
public class PersonRequestValidator : AbstractValidator<PersonRequest>
|
||||
{
|
||||
|
||||
public PersonRequestValidator(DatabaseContext database)
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty().MaximumLength(100);
|
||||
RuleFor(x => x.FullName).MaximumLength(200);
|
||||
RuleFor(x => x.Description).MaximumLength(1000);
|
||||
When(x => x.GenderId.HasValue, () =>
|
||||
{
|
||||
RuleFor(x => x.GenderId!.Value).MustBeIn(database.Genders.Select(g => g.Id));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
@using WatchIt.Common.Model.Genders
|
||||
<div class="rounded-3 panel panel-regular p-3 @(Class)">
|
||||
@if (_loaded)
|
||||
{
|
||||
<EditForm Model="_person">
|
||||
<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="_person!.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="_person!.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="_person!.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="_person!.BirthDate"/>
|
||||
<span class="input-group-text">-</span>
|
||||
<InputDate TValue="DateOnly?" class="form-control" @bind-Value="_person!.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="_person!.GenderId">
|
||||
<option value="@(default(short?))">No choice</option>
|
||||
@foreach (GenderResponse gender in _genders)
|
||||
{
|
||||
<option value="@(gender.Id)">@(gender.Name)</option>
|
||||
}
|
||||
</InputSelect>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
}
|
||||
else
|
||||
{
|
||||
<LoadingComponent Color="white"/>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,69 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using WatchIt.Common.Model.Genders;
|
||||
using WatchIt.Common.Model.Persons;
|
||||
using WatchIt.Website.Services.WebAPI.Persons;
|
||||
|
||||
namespace WatchIt.Website.Components.PersonEditPage;
|
||||
|
||||
public partial class PersonEditFormComponent : ComponentBase
|
||||
{
|
||||
#region SERVICES
|
||||
|
||||
[Inject] private IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PARAMETERS
|
||||
|
||||
[Parameter] public long? Id { get; set; }
|
||||
[Parameter] public string Class { get; set; } = string.Empty;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region FIELDS
|
||||
|
||||
private bool _loaded;
|
||||
|
||||
private IEnumerable<GenderResponse> _genders = [];
|
||||
|
||||
private PersonRequest _person = new PersonRequest();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
List<Task> endTasks = new List<Task>();
|
||||
|
||||
// STEP 0
|
||||
endTasks.AddRange(
|
||||
[
|
||||
// TODO: Add gender fetch
|
||||
]);
|
||||
if (Id.HasValue)
|
||||
{
|
||||
endTasks.AddRange(
|
||||
[
|
||||
PersonsWebAPIService.GetPerson(Id.Value, data => _person = new PersonRequest(data))
|
||||
]);
|
||||
}
|
||||
|
||||
// END
|
||||
await Task.WhenAll(endTasks);
|
||||
|
||||
_loaded = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
<div class="container-grid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="rounded-3 panel panel-regular p-3">
|
||||
<div class="rounded-3 panel panel-regular p-2 px-3">
|
||||
<h3 class="m-0 p-0">@(Id is not null ? "Edit" : "Create new") person @(_person is not null ? $" \"{_person.Name}\"" : string.Empty)</h3>
|
||||
</div>
|
||||
</div>
|
||||
@@ -25,7 +25,8 @@
|
||||
Class="h-100"/>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="rounded-3 panel panel-regular p-2 h-100"></div>
|
||||
<PersonEditFormComponent Id="@(Id)"
|
||||
Class="h-100"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
@using WatchIt.Website
|
||||
@using WatchIt.Website.Layout
|
||||
@using WatchIt.Website.Components
|
||||
@using WatchIt.Website.Components.PersonEditPage
|
||||
@using WatchIt.Common.Model.Accounts
|
||||
@using WatchIt.Common.Model.Media
|
||||
@using WatchIt.Website.Services.Utility.Tokens
|
||||
|
||||
Reference in New Issue
Block a user