PCRB webassembly
This commit is contained in:
140
MesaFabApproval.Client/Pages/Components/PCRBAttachmentForm.razor
Normal file
140
MesaFabApproval.Client/Pages/Components/PCRBAttachmentForm.razor
Normal file
@ -0,0 +1,140 @@
|
||||
@inject MesaFabApprovalAuthStateProvider authStateProvider
|
||||
@inject NavigationManager navigationManager
|
||||
@inject IPCRBService pcrbService
|
||||
@inject ISnackbar snackbar
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudPaper Class="m-2 p-2">
|
||||
<MudForm @bind-Errors="@errors">
|
||||
<MudTextField T="string"
|
||||
Label="File Name"
|
||||
Disabled
|
||||
Immediate
|
||||
@bind-Value="@fileName"
|
||||
@bind-Text="@fileName"
|
||||
AutoGrow />
|
||||
<MudFileUpload T="IBrowserFile"
|
||||
FilesChanged="AddFile"
|
||||
Required
|
||||
Disabled="@(!string.IsNullOrWhiteSpace(fileName))"
|
||||
RequiredError="You must select a file">
|
||||
<ActivatorContent>
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Tertiary"
|
||||
style="margin: auto;"
|
||||
StartIcon="@Icons.Material.Filled.AttachFile">
|
||||
@if (addFileInProcess) {
|
||||
<MudProgressCircular Class="m-1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudText>Processing</MudText>
|
||||
} else {
|
||||
<MudText>Add File</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</ActivatorContent>
|
||||
</MudFileUpload>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Tertiary"
|
||||
Class="m1-auto"
|
||||
OnClick=Submit>
|
||||
@if (processing) {
|
||||
<MudProgressCircular Class="m-1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudText>Processing</MudText>
|
||||
}
|
||||
else {
|
||||
<MudText>Submit</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 int planNumber { get; set; } = 0;
|
||||
|
||||
[Parameter]
|
||||
public int step { get; set; } = 0;
|
||||
|
||||
private string[] errors = { };
|
||||
|
||||
private string fileName = "";
|
||||
|
||||
private IBrowserFile? file = null;
|
||||
|
||||
private bool addFileInProcess = false;
|
||||
private bool processing = false;
|
||||
|
||||
protected override async Task OnParametersSetAsync() {
|
||||
if (planNumber <= 0) {
|
||||
snackbar.Add($"{planNumber} is not a valid PCRB plan#", Severity.Error);
|
||||
MudDialog.Close(DialogResult.Cancel());
|
||||
}
|
||||
|
||||
if (step <= 0) {
|
||||
snackbar.Add($"{step} is not a valid PCRB stage#", Severity.Error);
|
||||
MudDialog.Close(DialogResult.Cancel());
|
||||
}
|
||||
|
||||
if (authStateProvider.CurrentUser is null) {
|
||||
await authStateProvider.Logout();
|
||||
navigationManager.NavigateTo("login");
|
||||
}
|
||||
}
|
||||
|
||||
private void AddFile(IBrowserFile newFile) {
|
||||
addFileInProcess = true;
|
||||
file = newFile;
|
||||
fileName = newFile.Name;
|
||||
addFileInProcess = false;
|
||||
}
|
||||
|
||||
private async Task Submit() {
|
||||
processing = true;
|
||||
try {
|
||||
if (authStateProvider.CurrentUser is null) {
|
||||
await authStateProvider.Logout();
|
||||
navigationManager.NavigateTo("login");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
throw new Exception("file name missing");
|
||||
|
||||
if (file is null)
|
||||
throw new Exception("file is missing");
|
||||
|
||||
PCRBAttachment attachment = new() {
|
||||
Step = step,
|
||||
UploadDateTime = DateTime.Now,
|
||||
UploadedByID = authStateProvider.CurrentUser.UserID,
|
||||
PlanNumber = planNumber,
|
||||
File = file,
|
||||
FileName = fileName
|
||||
};
|
||||
|
||||
await pcrbService.UploadAttachment(attachment);
|
||||
|
||||
processing = false;
|
||||
|
||||
MudDialog.Close(DialogResult.Ok(attachment));
|
||||
} catch (Exception ex) {
|
||||
snackbar.Add($"Unable to save document, because {ex.Message}", Severity.Error);
|
||||
processing = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Cancel() {
|
||||
MudDialog.Close(DialogResult.Cancel());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user