PCRB webassembly
This commit is contained in:
151
MesaFabApproval.Client/Pages/Components/PCR3DocumentForm.razor
Normal file
151
MesaFabApproval.Client/Pages/Components/PCR3DocumentForm.razor
Normal file
@ -0,0 +1,151 @@
|
||||
@inject MesaFabApprovalAuthStateProvider authStateProvider
|
||||
@inject NavigationManager navigationManager
|
||||
@inject IPCRBService pcrbService
|
||||
@inject IUserService userService
|
||||
@inject IECNService ecnService
|
||||
@inject ISnackbar snackbar
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudPaper Class="m-2 p-2">
|
||||
<MudForm @bind-Errors="@errors">
|
||||
<MudTextField T="string"
|
||||
Label="Document Type"
|
||||
@bind-Value="@document.DocType"
|
||||
@bind-Text="@document.DocType"
|
||||
Disabled
|
||||
AutoGrow />
|
||||
<MudTextField Label="Document Numbers - Rev. & Title"
|
||||
@bind-Value="@document.DocNumbers"
|
||||
@bind-Text="@document.DocNumbers"
|
||||
Immediate
|
||||
AutoGrow
|
||||
AutoFocus />
|
||||
@if (DocNumberIsNA()) {
|
||||
<MudTextField Label="Comments"
|
||||
@bind-Value="@document.Comment"
|
||||
@bind-Text="@document.Comment"
|
||||
Required
|
||||
RequiredError="You must provide a comment"
|
||||
Immediate
|
||||
AutoGrow />
|
||||
} else {
|
||||
<MudTextField @bind-Value="@document.ECNNumber"
|
||||
Required
|
||||
RequiredError="You must provide a valid ECN#"
|
||||
Clearable
|
||||
Variant="Variant.Outlined"
|
||||
InputType="@InputType.Number"
|
||||
Validation="@(new Func<int, Task<string>>(ECNNoIsValid))"
|
||||
Label="ECN#"
|
||||
Immediate
|
||||
AutoGrow />
|
||||
}
|
||||
<MudCheckBox Label="Complete"
|
||||
Color="Color.Tertiary"
|
||||
@bind-Value=complete
|
||||
LabelPosition="LabelPosition.Start" />
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
@if ((DocNumberIsNA() && !string.IsNullOrWhiteSpace(document.Comment)) ||
|
||||
(!DocNumberIsNA() && ecnNoIsValid)) {
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Tertiary"
|
||||
Class="m1-auto"
|
||||
OnClick=Save>
|
||||
@if (saveInProcess) {
|
||||
<MudProgressCircular Class="m-1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudText>Processing</MudText>
|
||||
} else {
|
||||
<MudText>Save</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
}
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Class="grey text-black m1-auto"
|
||||
OnClick=Cancel>
|
||||
Cancel
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
MudDialogInstance MudDialog { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public required PCR3Document document { get; set; }
|
||||
|
||||
private string[] errors = { };
|
||||
|
||||
private bool complete = false;
|
||||
|
||||
private bool saveInProcess = false;
|
||||
|
||||
private bool ecnNoIsValid = true;
|
||||
|
||||
protected override async Task OnParametersSetAsync() {
|
||||
complete = document.CompletedByID > 0;
|
||||
}
|
||||
|
||||
private async Task Save() {
|
||||
saveInProcess = true;
|
||||
try {
|
||||
if (authStateProvider.CurrentUser is null) {
|
||||
await authStateProvider.Logout();
|
||||
navigationManager.NavigateTo("login");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!complete) {
|
||||
document.CompletedByID = 0;
|
||||
document.CompletedBy = null;
|
||||
document.CompletedDate = DateTimeUtilities.MAX_DT;
|
||||
}
|
||||
|
||||
if (complete && document.CompletedByID <= 0) {
|
||||
document.CompletedByID = authStateProvider.CurrentUser.UserID;
|
||||
document.CompletedBy = authStateProvider.CurrentUser;
|
||||
document.CompletedDate = DateTime.Now;
|
||||
}
|
||||
|
||||
if (!DocNumberIsNA() && !ecnNoIsValid)
|
||||
throw new Exception($"{document.ECNNumber} is not a valid ECN#");
|
||||
if (DocNumberIsNA() && string.IsNullOrWhiteSpace(document.Comment))
|
||||
throw new Exception("you must provide a comment");
|
||||
|
||||
await pcrbService.UpdatePCR3Document(document);
|
||||
|
||||
await pcrbService.GetPCR3DocumentsForPlanNumber(document.PlanNumber, true);
|
||||
|
||||
saveInProcess = false;
|
||||
|
||||
MudDialog.Close(DialogResult.Ok(document));
|
||||
} catch (Exception ex) {
|
||||
saveInProcess = false;
|
||||
snackbar.Add($"Unable to save document, because {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void Cancel() {
|
||||
MudDialog.Close(DialogResult.Cancel());
|
||||
}
|
||||
|
||||
private bool DocNumberIsNA() {
|
||||
if (document.DocNumbers.ToLower().Equals("na") ||
|
||||
document.DocNumbers.ToLower().Equals("n/a")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task<string> ECNNoIsValid(int ecnNumber) {
|
||||
string? result = await ecnService.ECNNumberIsValidStr(ecnNumber);
|
||||
if (result is null) ecnNoIsValid = true;
|
||||
else ecnNoIsValid = false;
|
||||
StateHasChanged();
|
||||
return result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user