Initial commit
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
@page "/search"
|
||||
@attribute [Authorize]
|
||||
@inject IUserSessionService Session
|
||||
@inject ISessionManager SessionMgr
|
||||
@inject ISearchService SearchSvc
|
||||
@inject SearchCsvExportService CsvExport
|
||||
@inject SearchHtmlExportService HtmlExport
|
||||
@inject WebExportService WebExport
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<h1 class="page-title">File Search</h1>
|
||||
|
||||
@if (!Session.HasProfile) { <NoProfilePrompt /> return; }
|
||||
|
||||
<div class="card">
|
||||
<div class="card-title">Search Options</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Site URL</label>
|
||||
<input class="form-input" @bind="_siteUrl" placeholder="@Session.CurrentProfile!.TenantUrl" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">File Extensions (comma-separated)</label>
|
||||
<input class="form-input" @bind="_extensions" placeholder="docx, xlsx, pdf" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Regex filter (filename)</label>
|
||||
<input class="form-input" @bind="_regex" placeholder="Optional regex pattern" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Max results</label>
|
||||
<input class="form-input" type="number" @bind="_maxResults" min="1" max="50000" style="width:120px" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Created by</label>
|
||||
<input class="form-input" @bind="_createdBy" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Modified by</label>
|
||||
<input class="form-input" @bind="_modifiedBy" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Library (optional)</label>
|
||||
<input class="form-input" @bind="_library" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-row mt-8">
|
||||
<button class="btn btn-primary" @onclick="RunSearch" disabled="@_running">
|
||||
@(_running ? "Searching…" : "Search")
|
||||
</button>
|
||||
@if (_running) { <button class="btn btn-secondary" @onclick="Cancel">Cancel</button> }
|
||||
</div>
|
||||
<ProgressPanel IsRunning="_running" StatusMessage="_status" Current="_current" Total="_total" />
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_error)) { <div class="alert alert-error">@_error</div> }
|
||||
|
||||
@if (_results.Count > 0)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="flex-row">
|
||||
<div class="card-title">Results <span class="count-badge">@_results.Count</span></div>
|
||||
<div class="spacer"></div>
|
||||
<button class="btn btn-secondary btn-sm" @onclick="ExportCsv">Export CSV</button>
|
||||
<button class="btn btn-secondary btn-sm" @onclick="ExportHtml">Export HTML</button>
|
||||
</div>
|
||||
<div class="data-table-wrap">
|
||||
<table class="data-table">
|
||||
<thead><tr><th>Name</th><th>Ext</th><th>Path</th><th>Created</th><th>Modified</th><th class="num">Size (KB)</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var r in _results.Take(500))
|
||||
{
|
||||
<tr>
|
||||
<td>@System.IO.Path.GetFileName(r.Path)</td>
|
||||
<td>@r.FileExtension</td>
|
||||
<td title="@r.Path" style="max-width:300px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">@r.Path</td>
|
||||
<td>@(r.Created?.ToString("yyyy-MM-dd") ?? "")</td>
|
||||
<td>@(r.LastModified?.ToString("yyyy-MM-dd") ?? "")</td>
|
||||
<td class="num">@((r.SizeBytes / 1024.0).ToString("F1"))</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@if (_results.Count > 500) { <div class="text-muted mt-8">Showing first 500 of @_results.Count. Export for full results.</div> }
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private string _siteUrl = string.Empty, _extensions = string.Empty, _regex = string.Empty;
|
||||
private string _createdBy = string.Empty, _modifiedBy = string.Empty, _library = string.Empty;
|
||||
private int _maxResults = 5000;
|
||||
private bool _running; private string _status = string.Empty, _error = string.Empty;
|
||||
private int _current, _total;
|
||||
private List<SearchResult> _results = new();
|
||||
private CancellationTokenSource? _cts;
|
||||
|
||||
private async Task RunSearch()
|
||||
{
|
||||
_error = string.Empty; _results.Clear(); _running = true;
|
||||
_cts = new CancellationTokenSource();
|
||||
var siteUrl = string.IsNullOrWhiteSpace(_siteUrl) ? Session.CurrentProfile!.TenantUrl : _siteUrl.Trim();
|
||||
var progress = new Progress<OperationProgress>(p => { _status = p.Message; _current = p.Current; _total = p.Total; InvokeAsync(StateHasChanged); });
|
||||
try
|
||||
{
|
||||
var ctx = await SessionMgr.GetOrCreateContextAsync(siteUrl, Session.CurrentProfile!, _cts.Token);
|
||||
var exts = _extensions.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
var opts = new SearchOptions(exts, _regex, null, null, null, null, _createdBy.TrimOrNull(), _modifiedBy.TrimOrNull(), _library.TrimOrNull(), _maxResults, siteUrl);
|
||||
_results = (await SearchSvc.SearchFilesAsync(ctx, opts, progress, _cts.Token)).ToList();
|
||||
_status = $"Found {_results.Count} files.";
|
||||
}
|
||||
catch (OperationCanceledException) { _status = "Cancelled."; }
|
||||
catch (Exception ex) { _error = ex.Message; }
|
||||
finally { _running = false; await InvokeAsync(StateHasChanged); }
|
||||
}
|
||||
|
||||
private void Cancel() => _cts?.Cancel();
|
||||
private async Task ExportCsv() { await WebExport.DownloadCsvAsync(CsvExport.BuildCsv(_results), $"search_{DateTime.Now:yyyyMMdd_HHmmss}.csv"); }
|
||||
private async Task ExportHtml() { await WebExport.DownloadHtmlAsync(HtmlExport.BuildHtml(_results), $"search_{DateTime.Now:yyyyMMdd_HHmmss}.html"); }
|
||||
}
|
||||
Reference in New Issue
Block a user