SHA256
GuestLog - GuestDocument pages initial implementation
This commit is contained in:
@@ -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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user