2025-04-11 02:31:29 -05:00
|
|
|
@using LANCommander.SDK.Enums
|
2025-07-27 17:51:50 -05:00
|
|
|
@using LANCommander.Server.ImportExport
|
|
|
|
|
@using LANCommander.Server.ImportExport.Factories
|
|
|
|
|
@using LANCommander.Server.ImportExport.Models
|
|
|
|
|
@using LANCommander.Server.ImportExport.Services
|
2025-04-11 02:31:29 -05:00
|
|
|
@inherits FeedbackComponent<ExportDialogOptions>
|
2025-11-17 22:09:03 -06:00
|
|
|
@inject ArchiveService ArchiveService
|
2025-07-27 17:51:50 -05:00
|
|
|
@inject ExportService ExportService
|
|
|
|
|
@inject ExportContextFactory ExportContextFactory
|
2025-04-11 02:31:29 -05:00
|
|
|
@inject IMessageService MessageService
|
2025-07-25 17:57:33 -05:00
|
|
|
@inject NavigationManager NavigationManager
|
2025-04-11 02:31:29 -05:00
|
|
|
@inject ILogger<ExportDialog> Logger
|
|
|
|
|
|
2025-07-25 17:57:33 -05:00
|
|
|
<Spin Spinning="_loading">
|
2025-08-01 02:27:06 -05:00
|
|
|
<Tree TItem="string"
|
|
|
|
|
Checkable
|
|
|
|
|
Multiple
|
|
|
|
|
CheckOnClickNode="false"
|
|
|
|
|
@bind-CheckedKeys="_selectedKeys">
|
|
|
|
|
@foreach (var group in ExportItems.GroupBy(i => i.Type))
|
2025-07-25 17:57:33 -05:00
|
|
|
{
|
2025-08-01 19:15:32 -05:00
|
|
|
var size = group.Sum(i => i.Size);
|
|
|
|
|
|
|
|
|
|
<TreeNode Title="@($"{group.Key.GetDisplayName()} ({group.Count()})")">
|
|
|
|
|
<TitleTemplate>
|
|
|
|
|
<GridRow>
|
|
|
|
|
<GridCol Flex=@("auto")>
|
|
|
|
|
@group.Key.GetDisplayName() (@group.Count())
|
|
|
|
|
</GridCol>
|
|
|
|
|
|
|
|
|
|
@if (size > 0)
|
|
|
|
|
{
|
|
|
|
|
<GridCol Flex=@("none")>
|
|
|
|
|
<ByteSize Value="@size" />
|
|
|
|
|
</GridCol>
|
|
|
|
|
}
|
|
|
|
|
</GridRow>
|
|
|
|
|
</TitleTemplate>
|
|
|
|
|
<ChildContent>
|
|
|
|
|
@foreach (var item in group)
|
|
|
|
|
{
|
|
|
|
|
<TreeNode Key="@item.Id.ToString()">
|
|
|
|
|
<TitleTemplate>
|
|
|
|
|
<GridRow>
|
|
|
|
|
<GridCol Flex=@("auto")>
|
|
|
|
|
@item.Name
|
2025-08-01 02:27:06 -05:00
|
|
|
</GridCol>
|
2025-08-01 19:15:32 -05:00
|
|
|
|
|
|
|
|
@if (item.Size > 0)
|
|
|
|
|
{
|
|
|
|
|
<GridCol Flex=@("none")>
|
|
|
|
|
<ByteSize Value="@item.Size"/>
|
|
|
|
|
</GridCol>
|
|
|
|
|
}
|
|
|
|
|
</GridRow>
|
|
|
|
|
</TitleTemplate>
|
|
|
|
|
</TreeNode>
|
|
|
|
|
}
|
|
|
|
|
</ChildContent>
|
2025-08-01 02:27:06 -05:00
|
|
|
</TreeNode>
|
2025-07-25 17:57:33 -05:00
|
|
|
}
|
2025-08-01 02:27:06 -05:00
|
|
|
</Tree>
|
2025-07-25 17:57:33 -05:00
|
|
|
</Spin>
|
2025-07-19 17:39:55 -05:00
|
|
|
|
|
|
|
|
<Flex Justify="FlexJustify.End" Gap="FlexGap.Small" Style="margin-top: 16px;">
|
2025-07-25 17:57:33 -05:00
|
|
|
<Button OnClick="Export" Type="@ButtonType.Primary" Disabled="_loading">Export</Button>
|
2025-07-19 17:39:55 -05:00
|
|
|
<Button OnClick="Cancel">Cancel</Button>
|
|
|
|
|
</Flex>
|
2025-04-11 02:31:29 -05:00
|
|
|
|
|
|
|
|
@code {
|
2025-07-27 17:51:50 -05:00
|
|
|
ExportContext ExportContext;
|
2025-04-11 02:31:29 -05:00
|
|
|
|
2025-07-19 17:39:55 -05:00
|
|
|
IEnumerable<ExportItemInfo> ExportItems = new List<ExportItemInfo>();
|
2025-04-11 02:31:29 -05:00
|
|
|
|
2025-08-01 02:27:06 -05:00
|
|
|
string[] _selectedKeys;
|
2025-07-25 17:57:33 -05:00
|
|
|
bool _loading = true;
|
|
|
|
|
|
2025-04-11 02:31:29 -05:00
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2025-07-25 17:57:33 -05:00
|
|
|
_loading = true;
|
|
|
|
|
|
2025-07-27 17:51:50 -05:00
|
|
|
ExportContext = ExportContextFactory.Create();
|
2025-04-11 02:31:29 -05:00
|
|
|
|
2025-07-27 17:51:50 -05:00
|
|
|
ExportContext.OnRecordError += RecordError;
|
|
|
|
|
ExportContext.OnRecordAdded += RecordAdded;
|
|
|
|
|
ExportContext.OnRecordProcessed += RecordProcessed;
|
2025-07-19 17:39:55 -05:00
|
|
|
|
|
|
|
|
if (Options != null && Options.RecordId != Guid.Empty)
|
2025-07-27 17:51:50 -05:00
|
|
|
ExportItems = await ExportContext.InitializeExportAsync(Options.RecordId, Options.RecordType);
|
2025-07-25 17:57:33 -05:00
|
|
|
|
2025-08-01 19:15:32 -05:00
|
|
|
_selectedKeys = ExportItems.Select(i => i.Id.ToString()).ToArray();
|
|
|
|
|
|
2025-07-25 17:57:33 -05:00
|
|
|
_loading = false;
|
2025-04-11 02:31:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RecordProcessed(object? sender, object e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RecordAdded(object? sender, object e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RecordError(object? sender, object e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task Export()
|
|
|
|
|
{
|
2025-08-01 02:27:06 -05:00
|
|
|
var selectedGuids = _selectedKeys
|
|
|
|
|
.Select(k => Guid.TryParse(k, out var id) ? (Guid?)id : null)
|
|
|
|
|
.Where(id => id.HasValue)
|
|
|
|
|
.Select(g => g!.Value);
|
2025-04-12 02:37:14 -05:00
|
|
|
|
2025-08-01 02:27:06 -05:00
|
|
|
await ExportContext.PrepareExportQueueAsync(selectedGuids);
|
2025-04-12 02:37:14 -05:00
|
|
|
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
2025-07-25 17:57:33 -05:00
|
|
|
|
2025-07-27 17:51:50 -05:00
|
|
|
var contextId = ExportService.EnqueueContext(ExportContext);
|
2025-07-25 17:57:33 -05:00
|
|
|
|
|
|
|
|
NavigationManager.NavigateTo($"/api/Export/{contextId}", true);
|
2025-04-11 02:31:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task Cancel()
|
|
|
|
|
{
|
|
|
|
|
await CloseFeedbackAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async Task OnFeedbackCancelAsync(ModalClosingEventArgs args)
|
|
|
|
|
{
|
2025-07-27 17:51:50 -05:00
|
|
|
//ExportContext.Dispose();
|
2025-04-11 02:31:29 -05:00
|
|
|
|
|
|
|
|
await base.OnFeedbackCancelAsync(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async Task OnFeedbackOkAsync(ModalClosingEventArgs args)
|
|
|
|
|
{
|
2025-07-27 17:51:50 -05:00
|
|
|
//ExportContext.Dispose();
|
2025-04-11 02:31:29 -05:00
|
|
|
|
|
|
|
|
await base.OnFeedbackOkAsync(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task OnUploadCompleted(string data)
|
|
|
|
|
{
|
|
|
|
|
if (Guid.TryParse(data, out var objectKey))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2025-11-17 22:09:03 -06:00
|
|
|
var archivePath = await ArchiveService.GetArchiveFileLocationAsync(objectKey.ToString());
|
2025-04-12 02:37:14 -05:00
|
|
|
|
2025-07-27 17:51:50 -05:00
|
|
|
ExportItems = await ExportContext.InitializeExportAsync(Options.RecordId, Options.RecordType);
|
2025-04-11 02:31:29 -05:00
|
|
|
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2025-04-12 02:37:14 -05:00
|
|
|
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");
|
2025-04-11 02:31:29 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
|
2025-04-12 02:37:14 -05:00
|
|
|
MessageService.Error("Export file failed to generate!");
|
|
|
|
|
Logger.LogError("Export file failed to generate!");
|
2025-04-11 02:31:29 -05:00
|
|
|
|
|
|
|
|
await CloseFeedbackAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|