109 lines
3.2 KiB
Plaintext
109 lines
3.2 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" Error="@OnError" Change="@OnChange" 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)" Disabled="@fileNotSelected" 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;
|
|
bool fileNotSelected = true;
|
|
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;
|
|
|
|
upload.ClearFiles();
|
|
}
|
|
|
|
state = hasError ? UploadState.Idle : UploadState.Completed;
|
|
}
|
|
|
|
void OnError(UploadErrorEventArgs args)
|
|
{
|
|
hasError = true;
|
|
errorMessage = args.Message;
|
|
|
|
upload.ClearFiles();
|
|
|
|
state = UploadState.Idle;
|
|
}
|
|
|
|
void OnChange(UploadChangeEventArgs args)
|
|
{
|
|
fileNotSelected = args.Files.Count() <= 0;
|
|
}
|
|
}
|