Files
SharepointToolbox-Web/Components/Pages/Search.razor
T
kawa 5df7b72800 Add report logos and configurable folder scan depth
Report branding (top-left MSP logo, top-right client logo):
- Add MspLogo to AppSettings; client logo already on TenantProfile
- IUserSessionService.CurrentBranding composes MSP + active profile logo
- New reusable LogoUpload component (InputFile -> base64 LogoData, 512KB cap)
- MSP logo upload in Settings; optional client logo in profile create/edit
- Wire ReportBranding into all 6 HTML export pages
- Fix EditProfile dropping ClientLogo on edit

Storage metrics: expose folder scan depth (0-20) in scan options UI,
passed to existing StorageScanOptions.FolderDepth recursion.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-02 14:56:49 +02:00

129 lines
6.0 KiB
Plaintext

@page "/search"
@attribute [Authorize]
@inject IUserSessionService Session
@inject ISessionManager SessionMgr
@inject IElevationCoordinator Elevation
@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 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 Elevation.RunAsync(async c =>
{
var ctx = await SessionMgr.GetOrCreateContextAsync(siteUrl, Session.CurrentProfile!, c);
return await SearchSvc.SearchFilesAsync(ctx, opts, progress, c);
}, _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, Session.CurrentBranding), $"search_{DateTime.Now:yyyyMMdd_HHmmss}.html"); }
}