SHA256
GuestLog - GuestDocument pages initial implementation
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
@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 />
|
||||
|
||||
<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" />
|
||||
|
||||
<MudSelect @bind-Value="Model.Nationality" For="@(() => Model.Nationality)" Label="Nationality">
|
||||
@foreach (var countryPair in GuestConsts.CountryList)
|
||||
{
|
||||
<MudSelectItem Value="countryPair.Key">@countryPair.Value</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<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" />
|
||||
|
||||
<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>
|
||||
|
||||
<MudDivider DividerType="DividerType.Middle" Class="mt-6" />
|
||||
<MudText Typo="Typo.subtitle1" Align="Align.Center">Contact Details</MudText>
|
||||
<MudDivider DividerType="DividerType.Middle" Class="mb-4" />
|
||||
|
||||
<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" />
|
||||
|
||||
<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>
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public GuestDocumentDTO Model { get; set; } = new();
|
||||
|
||||
|
||||
private MudForm _form = null!;
|
||||
private readonly GuestDocumentDTOValidator guestDocValidator = new();
|
||||
|
||||
private bool isSuportNumberRequired { get => Model?.Nationality == "ESP"; }
|
||||
|
||||
public async Task<bool> ValidateForm()
|
||||
{
|
||||
await _form.ValidateAsync();
|
||||
return _form.IsValid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
<MudNavLink Href="weather" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.List">Weather</MudNavLink>
|
||||
|
||||
<MudNavLink Href="@GuestConsts.Page_GuestDocs_List" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.DocumentScanner">Guests</MudNavLink>
|
||||
</MudNavMenu>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
@attribute [Route($"{GuestConsts.Page_GuestDocs_List}")]
|
||||
|
||||
@using Microsoft.EntityFrameworkCore;
|
||||
@using Somnia.GuestLog.Models.Entities;
|
||||
@using Somnia.GuestLog.Infrastructure;
|
||||
|
||||
@inject IDbContextFactory<GuestLogContext> contextFactory
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>Somnia - Guest Docs</PageTitle>
|
||||
|
||||
<MudStack Row="true" Class="my-4">
|
||||
<MudText Typo="Typo.h4" GutterBottom="true">Guest Documents</MudText>
|
||||
<MudSpacer />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Add"
|
||||
OnClick="() => BtnNewGuest()">
|
||||
New Guest
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
|
||||
<MudSelect T="string" MultiSelection="true" FullWidth="true" Dense="true" Clearable="true" Margin="@Margin.Dense"
|
||||
Class="filter-input category-filter" Label="Module" Placeholder="Select Modules"
|
||||
SelectedValuesChanged="@FilterModuleValuesChanged">
|
||||
@foreach (var module in _moduleList)
|
||||
{
|
||||
<MudSelectItem T="string" Value="@module">@module</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<MudDataGrid @ref="_dataGrid" T="GuestDocument" Items="@guestDocList" Loading="@_dataLoading" ReadOnly="true"
|
||||
Hideable="true" ColumnsPanelReordering="true">
|
||||
<ToolBarContent>
|
||||
<MudText Typo="Typo.subtitle1">Documents 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()">
|
||||
Reload Data
|
||||
</MudButton>
|
||||
<MudButton StartIcon="@Icons.Material.Outlined.ViewColumn" Variant="Variant.Outlined" Size="Size.Small"
|
||||
OnClick="(args) => BtnConfigureColumnsClick(args)">
|
||||
Configure Columns
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
</ToolBarContent>
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.DocumentType" Hideable="false" />
|
||||
<PropertyColumn Property="x => x.DocumentNum" Hideable="false" />
|
||||
<PropertyColumn Property="x => x.Name" />
|
||||
<PropertyColumn Property="x => x.Surname" />
|
||||
<PropertyColumn Property="x => x.Nationality" />
|
||||
<PropertyColumn Property="x => x.UpdateTime" />
|
||||
|
||||
<TemplateColumn CellClass="d-flex justify-between" Title="Options" StickyRight Hideable="false"
|
||||
ShowColumnOptions="false">
|
||||
<CellTemplate>
|
||||
<MudIconButton Size="@Size.Small" Icon="@Icons.Material.Outlined.Info"
|
||||
OnClick="() => BtnViewDetails(context.Item)" />
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</Columns>
|
||||
</MudDataGrid>
|
||||
|
||||
|
||||
@code {
|
||||
private IEnumerable<GuestDocument> guestDocList = [];
|
||||
|
||||
private bool _dataLoading = true;
|
||||
private HashSet<string> _moduleList = [];
|
||||
private HashSet<string> _selectedModuleList = [];
|
||||
|
||||
private MudDataGrid<GuestDocument>? _dataGrid;
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadDataAsync(showMsg: false);
|
||||
|
||||
@* _moduleList = guestDocList.Select(e => e.Module).ToHashSet(); *@
|
||||
}
|
||||
|
||||
#region Data Loading
|
||||
|
||||
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();
|
||||
|
||||
if (showMsg)
|
||||
{
|
||||
Snackbar.Add("Data loaded from DB", Severity.Info, o => o.VisibleStateDuration = 1000);
|
||||
}
|
||||
_dataLoading = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private async Task FilterModuleValuesChanged(IReadOnlyCollection<string> newValues)
|
||||
{
|
||||
_selectedModuleList = [.. newValues];
|
||||
|
||||
await LoadDataAsync();
|
||||
}
|
||||
|
||||
private async Task BtnConfigureColumnsClick(MouseEventArgs args)
|
||||
{
|
||||
if (_dataGrid is null)
|
||||
{
|
||||
Snackbar.Add("No ref to grid");
|
||||
return;
|
||||
}
|
||||
_dataGrid.ShowColumnsPanel(args);
|
||||
}
|
||||
|
||||
private Task BtnViewDetails(GuestDocument item)
|
||||
{
|
||||
Snackbar.Add($"Show details of {item.DocumentNum}", Severity.Info);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void BtnNewGuest()
|
||||
{
|
||||
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_New);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
@attribute [Route($"{GuestConsts.Page_GuestDocs_New}")]
|
||||
|
||||
@using Microsoft.EntityFrameworkCore;
|
||||
@using Somnia.GuestLog.Models.DTOs;
|
||||
@using Somnia.GuestLog.Infrastructure;
|
||||
@using Somnia.GuestLog.Services;
|
||||
|
||||
@inject IDbContextFactory<GuestLogContext> contextFactory
|
||||
@inject ISnackbar Snackbar
|
||||
@inject NavigationManager Navigation
|
||||
@inject IGuestDocumentService guestDocService
|
||||
|
||||
|
||||
<PageTitle>Somnia - Guest Docs - New</PageTitle>
|
||||
|
||||
<MudStack Row="true" Class="my-4">
|
||||
<MudText Typo="Typo.h4" GutterBottom="true">New Guest Document</MudText>
|
||||
<MudSpacer />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Add"
|
||||
OnClick="() => BtnSaveNewGuest()">
|
||||
Create
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Default" Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.ArrowBack" OnClick="() => BtnReturn()">
|
||||
Return
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
<GuestDocForm @ref="_form" />
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
GuestDocForm _form = null!;
|
||||
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void BtnReturn()
|
||||
{
|
||||
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_List);
|
||||
}
|
||||
|
||||
private async Task BtnSaveNewGuest()
|
||||
{
|
||||
bool isFormValid = await _form.ValidateForm();
|
||||
if (!isFormValid)
|
||||
{
|
||||
Snackbar.Add("Invalid Form!", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
GuestDocumentDTO model = _form.Model;
|
||||
|
||||
Snackbar.Add($"Document '{model.DocumentNum}' creating...", Severity.Info);
|
||||
|
||||
bool isCreated = await guestDocService.CreateDocumentAsync(model);
|
||||
if (!isCreated)
|
||||
{
|
||||
Snackbar.Add($"Error creating Document '{model.DocumentNum}'", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_List);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
@using Somnia.GuestLog.Components.Controls
|
||||
Reference in New Issue
Block a user