This refactor splits the import and export functionality out of the ImportContext and adds an ExportContext. This also introduced separate importer and exporter implementations. Additionally, adding archive, save, scripts, and server files to the final export archive has been implemented at the exporter implementation for each instead of handling it in the context. This should be a good pattern if other files need to be added down the road.
167 lines
No EOL
5.3 KiB
Text
167 lines
No EOL
5.3 KiB
Text
@using LANCommander.SDK.Enums
|
|
@using LANCommander.Server.ImportExport
|
|
@using LANCommander.Server.ImportExport.Factories
|
|
@using LANCommander.Server.ImportExport.Models
|
|
@using LANCommander.Server.ImportExport.Services
|
|
@inherits FeedbackComponent<ExportDialogOptions>
|
|
@inject ArchiveService ArchiveService
|
|
@inject ExportService ExportService
|
|
@inject ExportContextFactory ExportContextFactory
|
|
@inject IMessageService MessageService
|
|
@inject NavigationManager NavigationManager
|
|
@inject ILogger<ExportDialog> Logger
|
|
|
|
<Spin Spinning="_loading">
|
|
<Collapse>
|
|
@foreach (var group in ExportItems.GroupBy(i => i.Flag))
|
|
{
|
|
<Panel ShowArrow="false" Key="@group.Key.ToString()">
|
|
<HeaderTemplate>
|
|
<Flex Direction="FlexDirection.Horizontal" Gap="FlexGap.Small">
|
|
<Checkbox @bind-Checked="SelectedFlags[group.Key]" />
|
|
<Flex Direction="FlexDirection.Horizontal" Justify="FlexJustify.SpaceBetween">
|
|
<Text>@group.Key (@(group.Count()))</Text>
|
|
|
|
@{
|
|
var size = group.Sum(i => i.Size);
|
|
|
|
if (size > 0)
|
|
{
|
|
<ByteSize Value="size" />
|
|
}
|
|
}
|
|
</Flex>
|
|
</Flex>
|
|
</HeaderTemplate>
|
|
<ChildContent>
|
|
<AntList DataSource="group">
|
|
<ChildContent Context="item">
|
|
<ListItem>
|
|
<Flex Direction="FlexDirection.Horizontal" Justify="FlexJustify.SpaceBetween">
|
|
<Text>@item.Name</Text>
|
|
|
|
@if (item.Size > 0)
|
|
{
|
|
<ByteSize Value="item.Size"/>
|
|
}
|
|
</Flex>
|
|
</ListItem>
|
|
</ChildContent>
|
|
</AntList>
|
|
</ChildContent>
|
|
</Panel>
|
|
}
|
|
</Collapse>
|
|
</Spin>
|
|
|
|
<Flex Justify="FlexJustify.End" Gap="FlexGap.Small" Style="margin-top: 16px;">
|
|
<Button OnClick="Export" Type="@ButtonType.Primary" Disabled="_loading">Export</Button>
|
|
<Button OnClick="Cancel">Cancel</Button>
|
|
</Flex>
|
|
|
|
@code {
|
|
ExportContext ExportContext;
|
|
|
|
IEnumerable<ExportItemInfo> ExportItems = new List<ExportItemInfo>();
|
|
|
|
Dictionary<ExportRecordFlags, bool> SelectedFlags = Enum.GetValues<ExportRecordFlags>()
|
|
.ToDictionary(
|
|
f => f,
|
|
_ => true);
|
|
|
|
bool _loading = true;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_loading = true;
|
|
|
|
ExportContext = ExportContextFactory.Create();
|
|
|
|
ExportContext.OnRecordError += RecordError;
|
|
ExportContext.OnRecordAdded += RecordAdded;
|
|
ExportContext.OnRecordProcessed += RecordProcessed;
|
|
|
|
if (Options != null && Options.RecordId != Guid.Empty)
|
|
ExportItems = await ExportContext.InitializeExportAsync(Options.RecordId, Options.RecordType);
|
|
|
|
_loading = false;
|
|
}
|
|
|
|
private void RecordProcessed(object? sender, object e)
|
|
{
|
|
|
|
}
|
|
|
|
private void RecordAdded(object? sender, object e)
|
|
{
|
|
|
|
}
|
|
|
|
private void RecordError(object? sender, object e)
|
|
{
|
|
|
|
}
|
|
|
|
async Task Export()
|
|
{
|
|
var flags = SelectedFlags
|
|
.Where(f => f.Value)
|
|
.Aggregate(ExportRecordFlags.None, (cur, f) => cur | f.Key);
|
|
|
|
await ExportContext.PrepareExportQueueAsync(flags);
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
var contextId = ExportService.EnqueueContext(ExportContext);
|
|
|
|
NavigationManager.NavigateTo($"/api/Export/{contextId}", true);
|
|
}
|
|
|
|
async Task Cancel()
|
|
{
|
|
await CloseFeedbackAsync();
|
|
}
|
|
|
|
public override async Task OnFeedbackCancelAsync(ModalClosingEventArgs args)
|
|
{
|
|
//ExportContext.Dispose();
|
|
|
|
await base.OnFeedbackCancelAsync(args);
|
|
}
|
|
|
|
public override async Task OnFeedbackOkAsync(ModalClosingEventArgs args)
|
|
{
|
|
//ExportContext.Dispose();
|
|
|
|
await base.OnFeedbackOkAsync(args);
|
|
}
|
|
|
|
public async Task OnUploadCompleted(string data)
|
|
{
|
|
if (Guid.TryParse(data, out var objectKey))
|
|
{
|
|
try
|
|
{
|
|
var archivePath = await ArchiveService.GetArchiveFileLocationAsync(objectKey.ToString());
|
|
|
|
ExportItems = await ExportContext.InitializeExportAsync(Options.RecordId, Options.RecordType);
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("An unknown error occurred while trying to gather export details");
|
|
Logger.LogError(ex, "An unknown error occurred while trying to gather export details");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
MessageService.Error("Export file failed to generate!");
|
|
Logger.LogError("Export file failed to generate!");
|
|
|
|
await CloseFeedbackAsync();
|
|
}
|
|
}
|
|
} |