174 lines
6.4 KiB
Plaintext
174 lines
6.4 KiB
Plaintext
@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
|
|
Required
|
|
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 {
|
|
<MudAutocomplete @bind-Value="@document.ECNNumber"
|
|
T="int"
|
|
SearchFunc="Search"
|
|
Required
|
|
Clearable
|
|
RequiredError="You must provide a valid ECN#"
|
|
Variant="Variant.Outlined"
|
|
Validation="@(new Func<int, Task<string>>(ECNNoIsValid))"
|
|
Label="ECN#"
|
|
Immediate />
|
|
}
|
|
<MudCheckBox Label="Complete"
|
|
Color="Color.Tertiary"
|
|
@bind-Value=complete
|
|
LabelPosition="LabelPosition.Start" />
|
|
</MudForm>
|
|
</MudPaper>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
@if (!string.IsNullOrWhiteSpace(document.DocNumbers) && ((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 IEnumerable<int> allEcnNumbers = new List<int>();
|
|
|
|
private string[] errors = { };
|
|
|
|
private bool complete = false;
|
|
|
|
private bool saveInProcess = false;
|
|
|
|
private bool ecnNoIsValid = true;
|
|
|
|
protected override async Task OnParametersSetAsync() {
|
|
complete = document.CompletedByID > 0;
|
|
|
|
allEcnNumbers = await ecnService.GetAllECNNumbers();
|
|
}
|
|
|
|
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 (string.IsNullOrWhiteSpace(document.DocNumbers)) {
|
|
throw new Exception("Document Numbers cannot be empty");
|
|
}
|
|
|
|
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") ||
|
|
document.DocNumbers.ToLower().Equals("n a") ||
|
|
document.DocNumbers.ToLower().Equals("not applicable")) {
|
|
if (string.IsNullOrWhiteSpace(document.Comment))
|
|
document.Comment = "Not required";
|
|
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;
|
|
}
|
|
|
|
private async Task<IEnumerable<int>> Search(string searchValue, CancellationToken token) {
|
|
if (string.IsNullOrWhiteSpace(searchValue))
|
|
return allEcnNumbers;
|
|
|
|
return allEcnNumbers
|
|
.Where(x => x.ToString().StartsWith(searchValue, StringComparison.InvariantCultureIgnoreCase))
|
|
.Order();
|
|
}
|
|
}
|