123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- @using WarcViewerBlazorWinForm.Backend.IO.Archiving
- @using WarcViewerBlazorWinForm.Backend.Warc
- @using WarcViewerBlazorWinForm.Backend.IO
- @inject ViewerMainForm MainForm
- @inject WarcIndexManager IndexManager
- @inject IEventBus EventBus
- <ConditionBlock If="_selectedFile==null">
- <Button Color="Color.Primary" Icon="fa-solid fa-font-awesome" Text="Open..." @onclick="OpenFile"></Button>
- </ConditionBlock>
- <ConditionBlock If="_selectedFile != null">
- <Row>
- <Card>
- <HeaderTemplate>
- <div class="w-100">
- File: @_selectedFile
- <Button Color="Color.Danger" Icon="fa-solid fa-close" Text="Close" @onclick="CloseFile"></Button>
- <ConditionBlock If="_isDirectlyRead == false">
- <Button Color="Color.Primary" Icon="fa-solid fa-check" Text="Load Selected" @onclick="LoadSelectArchiveEntry"></Button>
- </ConditionBlock>
- </div>
- </HeaderTemplate>
- <BodyTemplate>
- <ConditionBlock If="_isDirectlyRead == null">
- Opening file...
- </ConditionBlock>
- <ConditionBlock If="_isDirectlyRead == true">
- TODO: read WARC directly
- </ConditionBlock>
- <ConditionBlock If="_isDirectlyRead == false">
- <div style="height:100%">
- <Table TItem="ArchiveEntryRow" TableSize="TableSize.Compact" OnQueryAsync="@DoQueryResult" @bind-SelectedRows="_selectedRows"
- ScrollMode="ScrollMode.Virtual" ShowLineNo LineNoText="#"
- IsBordered IsStriped IsFixedHeader ShowSkeleton IsMultipleSelect="true">
- <TableColumns>
- <TableColumn @bind-Field="@context.Name" Text="Name" Filterable></TableColumn>
- </TableColumns>
- </Table>
- </div>
- </ConditionBlock>
- </BodyTemplate>
- </Card>
- </Row>
- </ConditionBlock>
- @code {
- private string? _selectedFile;
- private bool? _isDirectlyRead;
- private ArchiveEntryRow[]? _rows;
- private List<ArchiveEntryRow> _selectedRows=new ();
- private async void OpenFile()
- {
- var open = MainForm.OpenFileWarc();
- if (open == null) return;
- _selectedFile = open;
- StateHasChanged();
- using var r = new FileReader();
- await r.LoadFileAsync(_selectedFile);
- StateHasChanged();
- if (r.IsDirectRead==true)
- {
- //TODO: read WARC directly
- }
- _isDirectlyRead = r.IsDirectRead;
- if (_isDirectlyRead == false && r.PackagedEntryNames.HasValue) _rows = r.PackagedEntryNames.Value.ToArray().Select((p, i) => new ArchiveEntryRow(i, p)).ToArray();
- StateHasChanged();
- }
- private void CloseFile() => _selectedFile = null;
- private Task<QueryData<ArchiveEntryRow>> DoQueryResult(QueryPageOptions options)
- {
- if (_rows == null)
- {
- return Task.FromResult(new QueryData<ArchiveEntryRow>
- {
- Items = Array.Empty<ArchiveEntryRow>(),
- TotalCount = 0,
- IsFiltered = false
- });
- }
- var filterFunc = options.Filters.GetFilterFunc<ArchiveEntryRow>();
- var data = _rows.Where(filterFunc).Skip(options.StartIndex).Take(options.PageItems);
- var ret = new QueryData<ArchiveEntryRow>
- {
- Items = data,
- TotalCount = _rows.Count(filterFunc),
- IsFiltered = options.Filters.Any()
- };
- return Task.FromResult(ret);
- }
- public void LoadSelectArchiveEntry()
- {
- if (_selectedFile == null) return; // WTF?
- var file = _selectedFile;
- _selectedFile = null;
- StateHasChanged();
- foreach (var row in _selectedRows)
- {
- var fd = new FileDescriptor(file!,_isDirectlyRead==true,row.Name);
- EventBus.Publish(new WarcIndexerLoadRequestEvent(fd));
- }
- }
- private class ArchiveEntryRow
- {
- public string Name { get; set; }
- public ArchiveEntryRow()
- {
- }
- public ArchiveEntryRow(int index, string name)
- {
- Name = name;
- }
- }
- }
|