Files
hcs/Hcs.WebApp/Components/Dialogs/StartParsing.razor

91 lines
2.8 KiB
Plaintext

@using Hcs.WebApp.Services
@inject DialogService DialogService
@inject FileToParseService FileToParseService
<style>
#uploadWithDragAndDrop {
left: 0;
--rz-upload-button-bar-background-color: transparent;
--rz-upload-button-bar-padding: 0;
}
#uploadWithDragAndDrop .rz-fileupload-buttonbar .rz-fileupload-choose {
width: 100%;
text-align: center;
font-size: 16px;
padding: 75px 0;
}
</style>
<RadzenStack JustifyContent="JustifyContent.Center" Style="height: 100%;">
<RadzenAlert Visible="@hasError" AlertStyle="AlertStyle.Danger" Variant="Variant.Flat" Shade="Shade.Lighter" AllowClose="false">
@errorMessage
</RadzenAlert>
<RadzenUpload id="uploadWithDragAndDrop" @ref="upload" Url="upload/parsing" Progress="@OnProgress" Complete="@OnCompleteAsync" ChooseText="Перетащите сюда или нажмите, чтобы выбрать файл" Accept=".xlsx" Auto="false" Multiple="false" Style="width: 100%;" />
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
<RadzenButton Click="@Upload" Visible="@(state == UploadState.Idle)" Text="Отправить" />
<RadzenButton Click="@Close" Visible="@(state == UploadState.Idle)" ButtonStyle="ButtonStyle.Light" Text="Отмена" />
</RadzenStack>
<RadzenProgressBar Value="@progress" Visible="@(state != UploadState.Idle)" />
<RadzenButton Click="@Close" Visible="@(state == UploadState.Completed)" Text="Закрыть" />
</RadzenStack>
@code {
enum UploadState
{
Idle,
InProgress,
Completed
}
RadzenUpload upload;
UploadState state;
int progress;
bool hasError;
string errorMessage;
int? fileToParseId;
[Parameter]
public required string UploaderId { get; set; }
void Upload()
{
state = UploadState.InProgress;
hasError = false;
upload.Upload();
}
void Close()
{
DialogService.Close(fileToParseId);
}
void OnProgress(UploadProgressArgs args)
{
progress = args.Progress;
}
async Task OnCompleteAsync(UploadCompleteEventArgs args)
{
try
{
var root = args.JsonResponse.RootElement;
var fileToParse = await FileToParseService.AddFileToParseAsync(
root.GetProperty("Path").GetString(),
root.GetProperty("FileName").GetString(),
UploaderId,
DateTime.Now);
fileToParseId = fileToParse.Id;
}
catch (Exception e)
{
hasError = true;
errorMessage = e.Message;
}
state = hasError ? UploadState.Idle : UploadState.Completed;
}
}