Implement file upload

This commit is contained in:
2025-11-20 09:55:57 +09:00
parent 7c5c889c53
commit 5b3cb2cabd
9 changed files with 128 additions and 16 deletions

View File

@ -22,7 +22,7 @@
<RadzenAlert Visible="@hasError" AlertStyle="AlertStyle.Danger" Variant="Variant.Flat" Shade="Shade.Lighter" AllowClose="false">
@errorMessage
</RadzenAlert>
<RadzenUpload id="uploadWithDragAndDrop" @ref="upload" Url="upload-to-parse" Progress="@OnProgress" Complete="@OnCompleteAsync" ChooseText="Перетащите сюда или нажмите, чтобы выбрать файл" Auto="false" Multiple="false" Style="width: 100%;" />
<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="Отмена" />
@ -44,6 +44,10 @@
int progress;
bool hasError;
string errorMessage;
int? fileToParseId;
[Parameter]
public required string UploaderId { get; set; }
void Upload()
{
@ -55,7 +59,7 @@
void Close()
{
DialogService.Close(true);
DialogService.Close(fileToParseId);
}
void OnProgress(UploadProgressArgs args)
@ -67,7 +71,13 @@
{
try
{
// TODO
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)
{

View File

@ -1,6 +1,7 @@
using Hcs.WebApp.BackgroundServices;
using Hcs.WebApp.Components.Dialogs;
using Hcs.WebApp.Data.Hcs;
using Hcs.WebApp.Data.Hcs.CampaignArgs;
using Hcs.WebApp.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
@ -74,7 +75,7 @@ namespace Hcs.WebApp.Components.Shared
if (await HeadquartersService.HasActiveCampaignAsync(CampaignType))
{
ChangeState(SyncedPageState.Idle);
ChangeState(SyncedPageState.SyncWaiting);
}
else
{
@ -88,17 +89,19 @@ namespace Hcs.WebApp.Components.Shared
{
if (state == SyncedPageState.SyncWaiting) return;
ChangeState(SyncedPageState.SyncWaiting);
if (await HeadquartersService.HasActiveCampaignAsync(CampaignType))
{
ChangeState(SyncedPageState.Idle);
ChangeState(SyncedPageState.SyncWaiting);
}
else
{
await DialogService.OpenAsync<StartParsing>(
var dialogResult = await DialogService.OpenAsync<StartParsing>(
"Отправка файла",
null,
new Dictionary<string, object>()
{
// TODO: Use user id
{ nameof(StartParsing.UploaderId), "" }
},
new DialogOptions()
{
Width = "600px",
@ -107,9 +110,18 @@ namespace Hcs.WebApp.Components.Shared
ShowClose = false
});
//// TODO: Use user id
//var campaign = await HeadquartersService.InitiateCampaignAsync(CampaignType, "");
//CampaignManagementState.EnqueueCampaign(campaign);
var fileToParseId = -1;
if (dialogResult != null && int.TryParse(dialogResult, out fileToParseId))
{
// TODO: Use user id
var campaign = await HeadquartersService.InitiateCampaignAsync(CampaignType, "", new CampaignParseArgs()
{
FileToParseId = fileToParseId
});
CampaignManagementState.EnqueueCampaign(campaign);
ChangeState(SyncedPageState.SyncWaiting);
}
}
}