Add file upload popup dialog
This commit is contained in:
@ -46,8 +46,8 @@
|
||||
</Helper>
|
||||
</RadzenFormField>
|
||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
||||
<RadzenButton ButtonType="ButtonType.Submit" Disabled="@inProgress" Text="Создать"></RadzenButton>
|
||||
<RadzenButton Click="@DoClose" ButtonStyle="ButtonStyle.Light" Disabled="@inProgress" Text="Отмена"></RadzenButton>
|
||||
<RadzenButton ButtonType="ButtonType.Submit" Disabled="@inProgress" Text="Создать" />
|
||||
<RadzenButton Click="@DoClose" ButtonStyle="ButtonStyle.Light" Disabled="@inProgress" Text="Отмена" />
|
||||
</RadzenStack>
|
||||
</RadzenStack>
|
||||
</RadzenTemplateForm>
|
||||
|
||||
80
Hcs.WebApp/Components/Dialogs/StartParsing.razor
Normal file
80
Hcs.WebApp/Components/Dialogs/StartParsing.razor
Normal file
@ -0,0 +1,80 @@
|
||||
@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-to-parse" Progress="@OnProgress" Complete="@OnCompleteAsync" ChooseText="Перетащите сюда или нажмите, чтобы выбрать файл" 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;
|
||||
|
||||
void Upload()
|
||||
{
|
||||
state = UploadState.InProgress;
|
||||
hasError = false;
|
||||
|
||||
upload.Upload();
|
||||
}
|
||||
|
||||
void Close()
|
||||
{
|
||||
DialogService.Close(true);
|
||||
}
|
||||
|
||||
void OnProgress(UploadProgressArgs args)
|
||||
{
|
||||
progress = args.Progress;
|
||||
}
|
||||
|
||||
async Task OnCompleteAsync(UploadCompleteEventArgs args)
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
hasError = true;
|
||||
errorMessage = e.Message;
|
||||
}
|
||||
|
||||
state = hasError ? UploadState.Idle : UploadState.Completed;
|
||||
}
|
||||
}
|
||||
@ -46,8 +46,6 @@
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
|
||||
if (firstRender)
|
||||
{
|
||||
ChangeState(PageState.Loading);
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
</RadzenColumn>
|
||||
<RadzenColumn Size="12" SizeMD="6">
|
||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
||||
<RadzenButton Icon="sync" Text="@syncButtonText" Disabled="@(state != SyncedPageState.Idle)" Click="@SyncDataAsync" ButtonStyle="ButtonStyle.Primary" />
|
||||
<RadzenButton Icon="upload_file" Text="@parseButtonText" Disabled="@(state != SyncedPageState.Idle)" Click="@ParseDataAsync" ButtonStyle="ButtonStyle.Primary" />
|
||||
</RadzenStack>
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
@attribute [Authorize]
|
||||
|
||||
@inject RegistryService RegistryService
|
||||
@inject DialogService DialogService
|
||||
|
||||
<PageTitle>Общие справочники подсистемы НСИ</PageTitle>
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
@attribute [Authorize]
|
||||
|
||||
@inject RegistryService RegistryService
|
||||
@inject DialogService DialogService
|
||||
|
||||
<PageTitle>Частные справочники подсистемы НСИ</PageTitle>
|
||||
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
using Hcs.WebApp.BackgroundServices;
|
||||
using Hcs.WebApp.Components.Dialogs;
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
using Hcs.WebApp.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Radzen;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Hcs.WebApp.Components.Shared
|
||||
@ -12,6 +14,7 @@ namespace Hcs.WebApp.Components.Shared
|
||||
protected SyncedPageState state;
|
||||
protected IEnumerable<TData> data;
|
||||
protected string syncButtonText = "...";
|
||||
protected string parseButtonText = "...";
|
||||
|
||||
protected abstract Campaign.CampaignType CampaignType { get; }
|
||||
|
||||
@ -24,6 +27,9 @@ namespace Hcs.WebApp.Components.Shared
|
||||
[Inject]
|
||||
private CampaignManagementState CampaignManagementState { get; set; }
|
||||
|
||||
[Inject]
|
||||
protected DialogService DialogService { get; set; }
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
@ -78,31 +84,63 @@ namespace Hcs.WebApp.Components.Shared
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task ParseDataAsync()
|
||||
{
|
||||
if (state == SyncedPageState.SyncWaiting) return;
|
||||
|
||||
ChangeState(SyncedPageState.SyncWaiting);
|
||||
|
||||
if (await HeadquartersService.HasActiveCampaignAsync(CampaignType))
|
||||
{
|
||||
ChangeState(SyncedPageState.Idle);
|
||||
}
|
||||
else
|
||||
{
|
||||
await DialogService.OpenAsync<StartParsing>(
|
||||
"Отправка файла",
|
||||
null,
|
||||
new DialogOptions()
|
||||
{
|
||||
Width = "600px",
|
||||
CloseDialogOnEsc = false,
|
||||
CloseDialogOnOverlayClick = false,
|
||||
ShowClose = false
|
||||
});
|
||||
|
||||
//// TODO: Use user id
|
||||
//var campaign = await HeadquartersService.InitiateCampaignAsync(CampaignType, "");
|
||||
//CampaignManagementState.EnqueueCampaign(campaign);
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeState(SyncedPageState state)
|
||||
{
|
||||
if (this.state == state) return;
|
||||
|
||||
this.state = state;
|
||||
|
||||
SetSyncButtonText();
|
||||
SetButtonsText();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void SetSyncButtonText()
|
||||
private void SetButtonsText()
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case SyncedPageState.Init:
|
||||
syncButtonText = "...";
|
||||
parseButtonText = "...";
|
||||
break;
|
||||
|
||||
case SyncedPageState.Loading:
|
||||
case SyncedPageState.Idle:
|
||||
syncButtonText = "Синхронизировать";
|
||||
parseButtonText = "Спарсить";
|
||||
break;
|
||||
|
||||
case SyncedPageState.SyncWaiting:
|
||||
syncButtonText = "Идет синхронизация...";
|
||||
parseButtonText = "Идет парсинг...";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user