Merge pull request 'Add report logos and configurable folder scan depth' (#2) from feat/report-logos-and-scan-depth into main
Reviewed-on: #2
This commit is contained in:
@@ -14,11 +14,8 @@
|
||||
@if (!Session.HasProfile) { <NoProfilePrompt /> return; }
|
||||
|
||||
<div class="card">
|
||||
<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>
|
||||
<SitePicker Profile="Session.CurrentProfile!" @bind-SelectedSites="_sites" />
|
||||
<div class="form-row mt-8">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Mode</label>
|
||||
<select class="form-select" @bind="_mode" style="width:120px">
|
||||
@@ -47,7 +44,7 @@
|
||||
</button>
|
||||
@if (_running) { <button class="btn btn-secondary" @onclick="Cancel">Cancel</button> }
|
||||
</div>
|
||||
<ProgressPanel IsRunning="_running" StatusMessage="_status" Current="_current" Total="_total" />
|
||||
<ProgressPanel IsRunning="_running" StatusMessage="@_status" Current="_current" Total="_total" />
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(_error)) { <div class="alert alert-error">@_error</div> }
|
||||
@@ -58,6 +55,7 @@
|
||||
<div class="flex-row">
|
||||
<div class="card-title">Duplicate Groups <span class="count-badge">@_results.Count</span></div>
|
||||
<div class="spacer"></div>
|
||||
<MergeModeSelect Value="_mergeMode" ValueChanged="v => _mergeMode = v" Visible="_bySite.Count > 1" />
|
||||
<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>
|
||||
@@ -81,28 +79,43 @@
|
||||
}
|
||||
|
||||
@code {
|
||||
private string _siteUrl = string.Empty, _library = string.Empty, _mode = "Files";
|
||||
private List<SiteInfo> _sites = new();
|
||||
private string _library = string.Empty, _mode = "Files";
|
||||
private bool _matchSize = true, _matchCreated, _matchModified, _matchFolderCount, _matchFileCount;
|
||||
private bool _running; private string _status = string.Empty, _error = string.Empty;
|
||||
private int _current, _total;
|
||||
private List<DuplicateGroup> _results = new();
|
||||
private List<(string Label, IReadOnlyList<DuplicateGroup> Results)> _bySite = new();
|
||||
private ReportMergeMode _mergeMode = ReportMergeMode.SingleMerged;
|
||||
private CancellationTokenSource? _cts;
|
||||
|
||||
private async Task RunScan()
|
||||
{
|
||||
_error = string.Empty; _results.Clear(); _running = true;
|
||||
_error = string.Empty; _results = new(); _bySite = new(); _running = true;
|
||||
_cts = new CancellationTokenSource();
|
||||
var siteUrl = string.IsNullOrWhiteSpace(_siteUrl) ? Session.CurrentProfile!.TenantUrl : _siteUrl.Trim();
|
||||
if (_sites.Count == 0) { _error = "Please select at least one site."; _running = false; return; }
|
||||
var progress = new Progress<OperationProgress>(p => { _status = p.Message; _current = p.Current; _total = p.Total; InvokeAsync(StateHasChanged); });
|
||||
try
|
||||
{
|
||||
var opts = new DuplicateScanOptions(_mode, _matchSize, _matchCreated, _matchModified, _matchFolderCount, _matchFileCount, Library: _library.TrimOrNull());
|
||||
_results = (await Elevation.RunAsync(async c =>
|
||||
var bySite = new List<(string, IReadOnlyList<DuplicateGroup>)>();
|
||||
var flat = new List<DuplicateGroup>();
|
||||
int i = 0;
|
||||
foreach (var site in _sites)
|
||||
{
|
||||
var ctx = await SessionMgr.GetOrCreateContextAsync(siteUrl, Session.CurrentProfile!, c);
|
||||
return await DupSvc.ScanDuplicatesAsync(ctx, opts, progress, c);
|
||||
}, _cts.Token)).ToList();
|
||||
_status = $"Found {_results.Count} duplicate groups.";
|
||||
_cts.Token.ThrowIfCancellationRequested();
|
||||
_status = $"Scanning {site.Title} ({++i}/{_sites.Count})…";
|
||||
await InvokeAsync(StateHasChanged);
|
||||
var groups = await Elevation.RunAsync(async c =>
|
||||
{
|
||||
var ctx = await SessionMgr.GetOrCreateContextAsync(site.Url, Session.CurrentProfile!, c);
|
||||
return await DupSvc.ScanDuplicatesAsync(ctx, opts, progress, c);
|
||||
}, _cts.Token);
|
||||
bySite.Add((site.Title, groups));
|
||||
flat.AddRange(groups);
|
||||
}
|
||||
_bySite = bySite; _results = flat;
|
||||
_status = $"Found {_results.Count} duplicate groups across {_sites.Count} site(s).";
|
||||
}
|
||||
catch (OperationCanceledException) { _status = "Cancelled."; }
|
||||
catch (Exception ex) { _error = ex.Message; }
|
||||
@@ -110,6 +123,16 @@
|
||||
}
|
||||
|
||||
private void Cancel() => _cts?.Cancel();
|
||||
private async Task ExportCsv() { await WebExport.DownloadCsvAsync(CsvExport.BuildCsv(_results), $"duplicates_{DateTime.Now:yyyyMMdd_HHmmss}.csv"); }
|
||||
private async Task ExportHtml() { await WebExport.DownloadHtmlAsync(HtmlExport.BuildHtml(_results), $"duplicates_{DateTime.Now:yyyyMMdd_HHmmss}.html"); }
|
||||
private async Task ExportCsv()
|
||||
{
|
||||
var ts = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
||||
var output = ReportMergeHelper.Build(_bySite, _mergeMode, "duplicates", ts, ReportFormat.Csv, rs => CsvExport.BuildCsv(rs));
|
||||
await WebExport.DownloadBytesAsync(output.Bytes, output.FileName, output.Mime);
|
||||
}
|
||||
private async Task ExportHtml()
|
||||
{
|
||||
var ts = DateTime.Now.ToString("yyyyMMdd_HHmmss");
|
||||
var output = ReportMergeHelper.Build(_bySite, _mergeMode, "duplicates", ts, ReportFormat.Html, rs => HtmlExport.BuildHtml(rs, Session.CurrentBranding));
|
||||
await WebExport.DownloadBytesAsync(output.Bytes, output.FileName, output.Mime);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user