Add file upload popup dialog
This commit is contained in:
@ -46,8 +46,8 @@
|
|||||||
</Helper>
|
</Helper>
|
||||||
</RadzenFormField>
|
</RadzenFormField>
|
||||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
||||||
<RadzenButton ButtonType="ButtonType.Submit" Disabled="@inProgress" Text="Создать"></RadzenButton>
|
<RadzenButton ButtonType="ButtonType.Submit" Disabled="@inProgress" Text="Создать" />
|
||||||
<RadzenButton Click="@DoClose" ButtonStyle="ButtonStyle.Light" Disabled="@inProgress" Text="Отмена"></RadzenButton>
|
<RadzenButton Click="@DoClose" ButtonStyle="ButtonStyle.Light" Disabled="@inProgress" Text="Отмена" />
|
||||||
</RadzenStack>
|
</RadzenStack>
|
||||||
</RadzenStack>
|
</RadzenStack>
|
||||||
</RadzenTemplateForm>
|
</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)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
await base.OnAfterRenderAsync(firstRender);
|
|
||||||
|
|
||||||
if (firstRender)
|
if (firstRender)
|
||||||
{
|
{
|
||||||
ChangeState(PageState.Loading);
|
ChangeState(PageState.Loading);
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
<RadzenColumn Size="12" SizeMD="6">
|
<RadzenColumn Size="12" SizeMD="6">
|
||||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
<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>
|
</RadzenStack>
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
|
|
||||||
@inject RegistryService RegistryService
|
@inject RegistryService RegistryService
|
||||||
@inject DialogService DialogService
|
|
||||||
|
|
||||||
<PageTitle>Общие справочники подсистемы НСИ</PageTitle>
|
<PageTitle>Общие справочники подсистемы НСИ</PageTitle>
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
|
|
||||||
@inject RegistryService RegistryService
|
@inject RegistryService RegistryService
|
||||||
@inject DialogService DialogService
|
|
||||||
|
|
||||||
<PageTitle>Частные справочники подсистемы НСИ</PageTitle>
|
<PageTitle>Частные справочники подсистемы НСИ</PageTitle>
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
using Hcs.WebApp.BackgroundServices;
|
using Hcs.WebApp.BackgroundServices;
|
||||||
|
using Hcs.WebApp.Components.Dialogs;
|
||||||
using Hcs.WebApp.Data.Hcs;
|
using Hcs.WebApp.Data.Hcs;
|
||||||
using Hcs.WebApp.Services;
|
using Hcs.WebApp.Services;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Authorization;
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
|
using Radzen;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
|
||||||
namespace Hcs.WebApp.Components.Shared
|
namespace Hcs.WebApp.Components.Shared
|
||||||
@ -12,6 +14,7 @@ namespace Hcs.WebApp.Components.Shared
|
|||||||
protected SyncedPageState state;
|
protected SyncedPageState state;
|
||||||
protected IEnumerable<TData> data;
|
protected IEnumerable<TData> data;
|
||||||
protected string syncButtonText = "...";
|
protected string syncButtonText = "...";
|
||||||
|
protected string parseButtonText = "...";
|
||||||
|
|
||||||
protected abstract Campaign.CampaignType CampaignType { get; }
|
protected abstract Campaign.CampaignType CampaignType { get; }
|
||||||
|
|
||||||
@ -24,6 +27,9 @@ namespace Hcs.WebApp.Components.Shared
|
|||||||
[Inject]
|
[Inject]
|
||||||
private CampaignManagementState CampaignManagementState { get; set; }
|
private CampaignManagementState CampaignManagementState { get; set; }
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
protected DialogService DialogService { get; set; }
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
if (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)
|
private void ChangeState(SyncedPageState state)
|
||||||
{
|
{
|
||||||
if (this.state == state) return;
|
if (this.state == state) return;
|
||||||
|
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
|
||||||
SetSyncButtonText();
|
SetButtonsText();
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetSyncButtonText()
|
private void SetButtonsText()
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case SyncedPageState.Init:
|
case SyncedPageState.Init:
|
||||||
syncButtonText = "...";
|
syncButtonText = "...";
|
||||||
|
parseButtonText = "...";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SyncedPageState.Loading:
|
case SyncedPageState.Loading:
|
||||||
case SyncedPageState.Idle:
|
case SyncedPageState.Idle:
|
||||||
syncButtonText = "Синхронизировать";
|
syncButtonText = "Синхронизировать";
|
||||||
|
parseButtonText = "Спарсить";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SyncedPageState.SyncWaiting:
|
case SyncedPageState.SyncWaiting:
|
||||||
syncButtonText = "Идет синхронизация...";
|
syncButtonText = "Идет синхронизация...";
|
||||||
|
parseButtonText = "Идет парсинг...";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user