GuestLog - GuestDocument detail view and creation improvements.

This commit is contained in:
2026-06-21 22:35:20 +02:00
parent 76b2695c02
commit 9f44ff6e3d
7 changed files with 205 additions and 83 deletions
@@ -0,0 +1,26 @@
@using Somnia.GuestLog.Models.DTOs
<MudDialog>
<TitleContent>
GuestDocument Details
</TitleContent>
<DialogContent>
<GuestDocForm Model="@DocumentDTO" ReadOnly=true />
</DialogContent>
<DialogActions>
<MudButton Color="Color.Primary" Variant="Variant.Filled" EndIcon="@Icons.Material.Filled.Close"
OnClick="Submit">
Close
</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public GuestDocumentDTO DocumentDTO { get; set; } = new();
private void Submit() => MudDialog.Close(DialogResult.Ok(true));
}
@@ -1,87 +1,139 @@
@using Somnia.GuestLog.Models.DTOs;
@using Somnia.GuestLog.Validators;
<MudPaper Class="pa-4">
<MudForm @ref="@_form" Model="@Model" Validation="@(guestDocValidator.ValidateValue)" ValidationDelay="0">
<MudSelect @bind-Value="Model.DocumentType" For="@(() => Model.DocumentType)" Label="DocumentType" Required>
@foreach (string docType in GuestConsts.DocumentTypeList)
{
<MudSelectItem Value="docType">@docType</MudSelectItem>
}
</MudSelect>
<MudTextField @bind-Value="Model.DocumentNum" For="@(() => Model.DocumentNum)" Label="Document Num"
Immediate="true" Required />
<MudForm @ref="@_form" Model="@Model" Validation="@(guestDocValidator.ValidateValue)" ValidationDelay="0"
ReadOnly="@ReadOnly">
<MudGrid>
<MudItem xs="12" md="6">
<MudPaper Class="pa-4" Elevation="3" Height="100%">
<MudText Typo="Typo.subtitle1" Align="Align.Center">Document Details</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudStack Row>
<MudSelect @bind-Value="Model.DocumentType" For="@(() => Model.DocumentType)" Label="DocumentType"
Required>
@foreach (string docType in GuestConsts.DocumentTypeList)
{
<MudSelectItem Value="docType">@docType</MudSelectItem>
}
</MudSelect>
<MudTextField @bind-Value="Model.DocumentNum" For="@(() => Model.DocumentNum)" Label="Document Num"
Immediate="true" Required />
</MudStack>
<MudDatePicker @bind-Date="Model.IssueDate" For="@(() => Model.IssueDate)" Label="Issue Date" Clearable
OpenTo="OpenTo.Year" Editable />
<MudStack Row>
<MudDatePicker @bind-Date="Model.IssueDate" For="@(() => Model.IssueDate)" Label="Issue Date"
Clearable OpenTo="OpenTo.Year" Editable />
<MudTextField @bind-Value="Model.SupportNum" For="@(() => Model.SupportNum)" Label="Support Num"
Immediate="true" Required="@isSuportNumberRequired" />
<MudTextField @bind-Value="Model.SupportNum" For="@(() => Model.SupportNum)" Label="Support Num"
Immediate="true" Required="@isSuportNumberRequired" />
</MudStack>
<MudSelect @bind-Value="Model.Nationality" For="@(() => Model.Nationality)" Label="Nationality">
@foreach (var countryPair in GuestConsts.CountryList)
{
<MudSelectItem Value="countryPair.Key">@countryPair.Value</MudSelectItem>
}
</MudSelect>
<MudSelect @bind-Value="Model.Nationality" For="@(() => Model.Nationality)" Label="Nationality">
@foreach (var countryPair in GuestConsts.CountryList)
{
<MudSelectItem Value="countryPair.Key">@countryPair.Value</MudSelectItem>
}
</MudSelect>
</MudPaper>
</MudItem>
<MudItem xs="12" md="6">
<MudPaper Class="pa-4" Elevation="3" Height="100%">
<MudText Typo="Typo.subtitle1" Align="Align.Center">Customer Details</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudDivider DividerType="DividerType.Middle" Class="mt-6" />
<MudText Typo="Typo.subtitle1" Align="Align.Center">Customer Details</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudTextField @bind-Value="Model.Name" For="@(() => Model.Name)" Immediate="true" Label="Name" />
<MudTextField @bind-Value="Model.Surname" For="@(() => Model.Surname)" Immediate="true"
Label="Surname" />
<MudTextField @bind-Value="Model.Surname2" For="@(() => Model.Surname2)" Immediate="true"
Label="Surname2" />
<MudTextField @bind-Value="Model.Name" For="@(() => Model.Name)" Immediate="true" Label="Name" />
<MudTextField @bind-Value="Model.Surname" For="@(() => Model.Surname)" Immediate="true" Label="Surname" />
<MudTextField @bind-Value="Model.Surname2" For="@(() => Model.Surname2)" Immediate="true" Label="Surname2" />
<MudStack Row>
<MudDatePicker @bind-Date="Model.BirthDate" For="@(() => Model.BirthDate)" Label="BirthDate"
Clearable OpenTo="OpenTo.Year" Editable />
<MudDatePicker @bind-Date="Model.BirthDate" For="@(() => Model.BirthDate)" Label="BirthDate" Clearable
OpenTo="OpenTo.Year" Editable />
<MudSelect @bind-Value="Model.Gender" For="@(() => Model.Gender)" Label="Gender">
@foreach (var genderPair in GuestConsts.GenderList)
{
<MudSelectItem Value="genderPair.Key">@genderPair.Value</MudSelectItem>
}
</MudSelect>
</MudStack>
</MudPaper>
</MudItem>
<MudSelect @bind-Value="Model.Gender" For="@(() => Model.Gender)" Label="Gender">
@foreach (var genderPair in GuestConsts.GenderList)
{
<MudSelectItem Value="genderPair.Key">@genderPair.Value</MudSelectItem>
}
</MudSelect>
<MudItem xs="12" md="6">
<MudPaper Class="pa-4" Elevation="3" Height="100%">
<MudText Typo="Typo.subtitle1" Align="Align.Center">Contact Details</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudDivider DividerType="DividerType.Middle" Class="mt-6" />
<MudText Typo="Typo.subtitle1" Align="Align.Center">Contact Details</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudStack Row>
<MudTextField @bind-Value="Model.PhoneNumber" For="@(() => Model.PhoneNumber)" Immediate="true"
Label="Phone Number" />
<MudTextField @bind-Value="Model.EmailAddress" For="@(() => Model.EmailAddress)" Immediate="true"
Label="Email" />
</MudStack>
</MudPaper>
</MudItem>
<MudTextField @bind-Value="Model.PhoneNumber" For="@(() => Model.PhoneNumber)" Immediate="true"
Label="Phone Number" />
<MudTextField @bind-Value="Model.EmailAddress" For="@(() => Model.EmailAddress)" Immediate="true"
Label="Email" />
<MudItem xs="12" md="6">
<MudPaper Class="pa-4" Elevation="3" Height="100%">
<MudText Typo="Typo.subtitle1" Align="Align.Center">Address</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudDivider DividerType="DividerType.Middle" Class="mt-6" />
<MudText Typo="Typo.subtitle1" Align="Align.Center">Address Details</MudText>
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
<MudTextField @bind-Value="Model.Address" For="@(() => Model.Address)" Immediate="true" Label="Address" />
<MudTextField @bind-Value="Model.AddressCity" For="@(() => Model.AddressCity)" Immediate="true" Label="City" />
<MudTextField @bind-Value="Model.AddressProvince" For="@(() => Model.AddressProvince)" Immediate="true"
Label="Province" />
<MudTextField @bind-Value="Model.AddressState" For="@(() => Model.AddressState)" Immediate="true"
Label="State" />
<MudSelect @bind-Value="Model.AddressCountry" For="@(() => Model.AddressCountry)" Label="Country">
@foreach (var countryPair in GuestConsts.CountryList)
{
<MudSelectItem Value="countryPair.Key">@countryPair.Value</MudSelectItem>
}
</MudSelect>
<MudTextField @bind-Value="Model.ZipCode" For="@(() => Model.ZipCode)" Immediate="true" Label="ZipCode" />
</MudForm>
</MudPaper>
<MudTextField @bind-Value="Model.Address" For="@(() => Model.Address)" Immediate="true" Label="Address" />
<MudStack Row>
<MudTextField @bind-Value="Model.AddressCity" For="@(() => Model.AddressCity)" Immediate="true"
Label="City" />
<MudTextField @bind-Value="Model.AddressProvince" For="@(() => Model.AddressProvince)" Immediate="true"
Label="Province" />
<MudTextField @bind-Value="Model.AddressState" For="@(() => Model.AddressState)" Immediate="true"
Label="State" />
</MudStack>
<MudStack Row>
<MudSelect @bind-Value="Model.AddressCountry" For="@(() => Model.AddressCountry)" Label="Country">
@foreach (var countryPair in GuestConsts.CountryList)
{
<MudSelectItem Value="countryPair.Key">@countryPair.Value</MudSelectItem>
}
</MudSelect>
<MudTextField @bind-Value="Model.ZipCode" For="@(() => Model.ZipCode)" Immediate="true"
Label="ZipCode" />
</MudStack>
</MudPaper>
</MudItem>
</MudGrid>
<MudText Class="mt-4">@CreateTimeString</MudText>
</MudForm>
@code {
[Parameter]
public GuestDocumentDTO Model { get; set; } = new();
[Parameter]
public bool ReadOnly { get; set; } = false;
private MudForm _form = null!;
private readonly GuestDocumentDTOValidator guestDocValidator = new();
private bool isSuportNumberRequired { get => Model?.Nationality == "ESP"; }
private string CreateTimeString
{
get
{
List<string> textList = [];
if (Model.CreateTime != null)
{
textList.Add($"Created at: {Model.CreateTime.Value.ToString()}");
}
if (Model.UpdateTime != null)
{
textList.Add($"Last Update Time: {Model.UpdateTime.Value.ToString()}");
}
return string.Join("; ", textList);
}
}
public async Task<bool> ValidateForm()
{
@@ -0,0 +1,29 @@
<MudDialog>
<TitleContent>
<MudText Typo="Typo.subtitle1" Align="Align.Center">In progress...</MudText>
</TitleContent>
<DialogContent>
<div class="d-flex flex-grow-1 flex-wrap justify-center align-center ma-8">
<MudProgressCircular Indeterminate="true" Color="Color.Primary" Size="Size.Large"/>
</div>
</DialogContent>
</MudDialog>
@code {
[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = null!;
protected override async Task OnParametersSetAsync()
{
var updatedOptions = MudDialog.Options with
{
BackdropClick = false,
CloseButton = false,
CloseOnEscapeKey = false,
CloseOnNavigation = true,
FullWidth = true,
};
await MudDialog.SetOptionsAsync(updatedOptions);
}
}
@@ -1,12 +1,13 @@
@attribute [Route($"{GuestConsts.Page_GuestDocs_List}")]
@using Microsoft.EntityFrameworkCore;
@using Somnia.GuestLog.Models.Entities;
@using Somnia.GuestLog.Infrastructure;
@using Somnia.GuestLog.Models.DTOs;
@using Somnia.GuestLog.Services;
@inject IDbContextFactory<GuestLogContext> contextFactory
@inject IGuestDocumentService GuestDocService
@inject NavigationManager Navigation
@inject ISnackbar Snackbar
@inject IDialogService DialogService
<PageTitle>Somnia - Guest Docs</PageTitle>
@@ -28,10 +29,10 @@
}
</MudSelect>
<MudDataGrid @ref="_dataGrid" T="GuestDocument" Items="@guestDocList" Loading="@_dataLoading" ReadOnly="true"
<MudDataGrid @ref="_dataGrid" T="GuestDocumentDTO" Items="@guestDocList" Loading="@_dataLoading" ReadOnly="true"
Hideable="true" ColumnsPanelReordering="true">
<ToolBarContent>
<MudText Typo="Typo.subtitle1">Documents List</MudText>
<MudText Typo="Typo.subtitle1">Document List</MudText>
<MudStack Class="ml-auto" Row="true" AlignItems="AlignItems.End">
<MudButton StartIcon="@Icons.Material.Outlined.Refresh" Variant="Variant.Outlined" Size="Size.Small"
OnClick="() => LoadDataAsync()">
@@ -63,13 +64,13 @@
@code {
private IEnumerable<GuestDocument> guestDocList = [];
private IEnumerable<GuestDocumentDTO> guestDocList = [];
private bool _dataLoading = true;
private HashSet<string> _moduleList = [];
private HashSet<string> _selectedModuleList = [];
private MudDataGrid<GuestDocument>? _dataGrid;
private MudDataGrid<GuestDocumentDTO>? _dataGrid;
protected override async Task OnInitializedAsync()
@@ -84,18 +85,8 @@
private async Task LoadDataAsync(bool showMsg = true)
{
_dataLoading = true;
using var dbContext = await contextFactory.CreateDbContextAsync();
IQueryable<GuestDocument> query = dbContext.GuestDocuments.AsQueryable();
@* if (_selectedModuleList.Count > 0)
{
query = query.Where(c => _selectedModuleList.Contains(c.Module));
} *@
guestDocList = await query
.OrderByDescending(e => e.UpdateTime)
.ToListAsync();
guestDocList = await GuestDocService.GetDtoListAsync();
if (showMsg)
{
@@ -125,10 +116,18 @@
_dataGrid.ShowColumnsPanel(args);
}
private Task BtnViewDetails(GuestDocument item)
private async Task BtnViewDetails(GuestDocumentDTO item)
{
Snackbar.Add($"Show details of {item.DocumentNum}", Severity.Info);
return Task.CompletedTask;
var parameters =
new DialogParameters<GuestDocDetailsDialog> { { x => x.DocumentDTO, item } };
var options = new DialogOptions()
{
FullScreen = true,
CloseButton = true,
CloseOnEscapeKey = true,
};
await DialogService.ShowAsync<GuestDocDetailsDialog>("GuestDoc Details", parameters, options);
}
private void BtnNewGuest()
@@ -7,6 +7,7 @@
@inject IDbContextFactory<GuestLogContext> contextFactory
@inject ISnackbar Snackbar
@inject IDialogService DialogService
@inject NavigationManager Navigation
@inject IGuestDocumentService guestDocService
@@ -53,13 +54,18 @@
Snackbar.Add($"Document '{model.DocumentNum}' creating...", Severity.Info);
//Show Loading dialog...
var loadingDialog = await DialogService.ShowAsync<LoadingDialog>();
bool isCreated = await guestDocService.CreateDocumentAsync(model);
if (!isCreated)
{
Snackbar.Add($"Error creating Document '{model.DocumentNum}'", Severity.Error);
loadingDialog.Close();
return;
}
Snackbar.Add($"Document '{model.DocumentNum}' Created!", Severity.Success);
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_List);
}
@@ -27,4 +27,8 @@ public class GuestDocumentDTO
public string? AddressState { get; set; }
public string? AddressCountry { get; set; }
public string? ZipCode { get; set; }
public DateTime? CreateTime { get; set; }
public DateTime? UpdateTime { get; set; }
}
@@ -85,7 +85,11 @@ public class GuestDocumentService(
public async Task<IEnumerable<GuestDocumentDTO>> GetDtoListAsync()
{
using var dbContext = contextFactory.CreateDbContext();
return await dbContext.GuestDocuments.Select(x => GetDtoFromDb(x)).ToListAsync();
var dbList = await dbContext.GuestDocuments
.OrderByDescending(e => e.UpdateTime)
.ToListAsync();
return dbList.Select(x => GetDtoFromDb(x));
}
@@ -111,6 +115,8 @@ public class GuestDocumentService(
AddressState = dbItem.AddressDetails?.AddressState ?? "",
AddressCountry = dbItem.AddressDetails?.AddressCountry! ?? "",
ZipCode = dbItem.AddressDetails?.ZipCode ?? "",
CreateTime = dbItem.CreateTime,
UpdateTime = dbItem.UpdateTime,
};
}