SHA256
GuestLog - Improvements to GuestDocument creation
- Added DocumentNumber validations. - Added new page to see GuestDocument details.
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
@attribute [Route($"{GuestConsts.Page_GuestDocs_Detail}")]
|
||||
|
||||
@using Somnia.GuestLog.Models.DTOs;
|
||||
@using Somnia.GuestLog.Services;
|
||||
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@inject NavigationManager Navigation
|
||||
@inject IGuestDocumentService guestDocService
|
||||
|
||||
|
||||
@inject FluentValidation.IValidator<GuestDocIdDTO> docIdValidator;
|
||||
|
||||
|
||||
<PageTitle>Somnia - Guest Docs - Details</PageTitle>
|
||||
|
||||
<MudStack Row="true" Class="my-4">
|
||||
<MudText Typo="Typo.h4" GutterBottom="true">Guest Document - "@docId"</MudText>
|
||||
<MudSpacer />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Add"
|
||||
OnClick="() => BtnEdit()">
|
||||
@LanguageLocale.general_btnEdit
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Default" Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.ArrowBack" OnClick="() => BtnReturn()">
|
||||
@LanguageLocale.general_btnReturn
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
|
||||
@if (documentModel is not null)
|
||||
{
|
||||
<GuestDocForm @ref="_form" Model="documentModel" ReadOnly="true" />
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public string? docId { get; set; }
|
||||
|
||||
GuestDocForm _form = null!;
|
||||
|
||||
GuestDocumentDTO? documentModel = null;
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (docId is null)
|
||||
{
|
||||
Snackbar.Add("No GuestDocument provided!!", Severity.Error);
|
||||
Navigation.NotFound();
|
||||
return;
|
||||
}
|
||||
|
||||
GuestDocIdDTO? docIdModel = GuestDocIdDTO.DecodeFromString(docId);
|
||||
if (docIdModel is null)
|
||||
{
|
||||
Snackbar.Add($"Provided GuestDocId can't be decoded: '{docId}'", Severity.Error);
|
||||
Navigation.NotFound();
|
||||
return;
|
||||
}
|
||||
|
||||
//Get model from db.
|
||||
documentModel = await guestDocService.GetDtoByIdAsync(docIdModel.DocumentType, docIdModel.DocumentNum);
|
||||
if (documentModel is null)
|
||||
{
|
||||
Snackbar.Add($"GuestDocument not found with ID: '{docId}'", Severity.Error);
|
||||
Navigation.NotFound();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnEdit()
|
||||
{
|
||||
Snackbar.Add("Not implemented yet!", Severity.Info);
|
||||
}
|
||||
|
||||
private void BtnReturn()
|
||||
{
|
||||
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_List);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
@attribute [Route($"{GuestConsts.Page_GuestDocs_New}")]
|
||||
|
||||
@using Microsoft.EntityFrameworkCore;
|
||||
@using Somnia.GuestLog.Models.DTOs;
|
||||
@using Somnia.GuestLog.Infrastructure;
|
||||
@using Somnia.GuestLog.Services;
|
||||
@using Somnia.GuestLog.Validators;
|
||||
|
||||
@inject IDbContextFactory<GuestLogContext> contextFactory
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@inject NavigationManager Navigation
|
||||
@inject IGuestDocumentService guestDocService
|
||||
@inject IDataListService dataListService;
|
||||
|
||||
@inject FluentValidation.IValidator<GuestDocIdDTO> docIdValidator;
|
||||
|
||||
|
||||
<PageTitle>Somnia - Guest Docs - New</PageTitle>
|
||||
@@ -26,16 +27,98 @@
|
||||
@LanguageLocale.general_btnReturn
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
<GuestDocForm @ref="_form" />
|
||||
|
||||
@if (currentPageMode == ePageMode.selectDocId || currentPageMode == ePageMode.alreadyExistDoc)
|
||||
{
|
||||
<MudPaper Class="pa-4" Elevation="3" Height="100%" Style="">
|
||||
<MudForm @ref="_docIdForm" Model="@currentDocId"
|
||||
Validation="@((docIdValidator as GuestDocIdDTOValidator)!.ValidateValue)">
|
||||
<MudStack Breakpoint="Breakpoint.Sm">
|
||||
<MudSelect @bind-Value="currentDocId.DocumentType" For="@(() => currentDocId.DocumentType)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_DocumentType" Immediate="true" Required>
|
||||
|
||||
@foreach (string docType in dataListService.GetDataListByName(GuestConsts.DataList_DocumentTypes))
|
||||
{
|
||||
<MudSelectItem Value="docType">
|
||||
@dataListService.GetLocalizedValue(GuestConsts.DataList_DocumentTypes, docType)
|
||||
</MudSelectItem>
|
||||
}
|
||||
|
||||
</MudSelect>
|
||||
<MudTextField @bind-Value="currentDocId.DocumentNum" For="@(() => currentDocId.DocumentNum)"
|
||||
Label="@LanguageLocale.dto_GuestDocument_DocumentNum" Required
|
||||
OnBlur="@(() => currentDocId.DocumentNum = currentDocId.DocumentNum.ToUpper())" />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.Search" OnClick="() => BtnCheckDocId()" Disabled="@loadingDocId">
|
||||
@LanguageLocale.general_btnSearch
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
</MudForm>
|
||||
|
||||
@if (currentPageMode == ePageMode.alreadyExistDoc)
|
||||
{
|
||||
<MudStack>
|
||||
<MudDivider Class="my-4" />
|
||||
<MudText Typo="Typo.body1" Style="text-align: center;">@LanguageLocale.page_GuestDocNew_msgAlreadyExists
|
||||
</MudText>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.Search" OnClick="() => BtnGoToDocument()">
|
||||
@LanguageLocale.page_GuestDocNew_btnGoExistingDoc
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
}
|
||||
</MudPaper>
|
||||
}
|
||||
|
||||
@if (currentPageMode == ePageMode.createNew)
|
||||
{
|
||||
<GuestDocForm @ref="_form" Model="newDocumentModel" />
|
||||
}
|
||||
|
||||
|
||||
@code {
|
||||
|
||||
GuestDocForm _form = null!;
|
||||
MudForm _docIdForm = null!;
|
||||
|
||||
ePageMode currentPageMode = ePageMode.selectDocId;
|
||||
GuestDocIdDTO currentDocId = new() { DocumentNum = "", DocumentType = "" };
|
||||
GuestDocumentDTO newDocumentModel = new();
|
||||
|
||||
bool loadingDocId = false;
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
/// <summary>
|
||||
/// Check if given Document already exists or can be created.
|
||||
/// </summary>
|
||||
private async Task BtnCheckDocId()
|
||||
{
|
||||
await _docIdForm.ValidateAsync();
|
||||
if (!_docIdForm.IsValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
loadingDocId = true;
|
||||
GuestDocumentDTO? dto = await guestDocService.GetDtoByIdAsync(currentDocId.DocumentType, currentDocId.DocumentNum);
|
||||
loadingDocId = false;
|
||||
|
||||
if (dto is null)
|
||||
{
|
||||
//Document don't exist -> Create it.
|
||||
currentPageMode = ePageMode.createNew;
|
||||
|
||||
//Update model with current DocId
|
||||
newDocumentModel.DocumentType = currentDocId.DocumentType;
|
||||
newDocumentModel.DocumentNum = currentDocId.DocumentNum;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//GuestDoc already exists!
|
||||
currentPageMode = ePageMode.alreadyExistDoc;
|
||||
}
|
||||
|
||||
private void BtnReturn()
|
||||
{
|
||||
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_List);
|
||||
@@ -69,6 +152,27 @@
|
||||
Navigation.NavigateTo(GuestConsts.Page_GuestDocs_List);
|
||||
}
|
||||
|
||||
private void BtnGoToDocument()
|
||||
{
|
||||
if (currentPageMode != ePageMode.alreadyExistDoc)
|
||||
{
|
||||
Snackbar.Add("Invalid operation!", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
string docId = GuestDocIdDTO.EncodeAsString(currentDocId);
|
||||
string uri = GuestConsts.Page_GuestDocs_Detail.Replace("{docId}", docId);
|
||||
Navigation.NavigateTo(uri);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Models
|
||||
|
||||
enum ePageMode
|
||||
{
|
||||
selectDocId, alreadyExistDoc, createNew
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user