This commit is contained in:
2026-06-02 17:13:26 +02:00
14 changed files with 474 additions and 25 deletions
+67 -7
View File
@@ -17,15 +17,43 @@
<div class="card">
<SitePicker Profile="Session.CurrentProfile!" @bind-SelectedSites="_sites" Single="true" />
<div class="form-row mt-8">
<div class="form-group">
<label class="form-label">Library Title</label>
<input class="form-input" @bind="_libraryTitle" placeholder="Shared Documents" />
<LibraryPicker Profile="Session.CurrentProfile!" SiteUrl="@(_sites.FirstOrDefault()?.Url)" @bind-Library="_libraryTitle" Label="Library Title" />
</div>
<div class="form-group">
<label class="form-label">Source</label>
<div class="flex-row">
<button class="btn btn-sm @(_mode == InputMode.Csv ? "btn-primary" : "btn-secondary")"
type="button" @onclick="() => SetMode(InputMode.Csv)">Upload CSV</button>
<button class="btn btn-sm @(_mode == InputMode.Builder ? "btn-primary" : "btn-secondary")"
type="button" @onclick="() => SetMode(InputMode.Builder)">Build visually</button>
</div>
</div>
<div class="form-group">
<label class="form-label">CSV File (Level1, Level2, Level3, Level4)</label>
<InputFile OnChange="LoadFile" accept=".csv" class="form-input" />
</div>
@if (_mode == InputMode.Csv)
{
<div class="form-group">
<label class="form-label">CSV File (Level1, Level2, Level3, Level4)</label>
<InputFile OnChange="LoadFile" accept=".csv" class="form-input" />
</div>
}
else
{
<div class="form-group">
<label class="form-label">Folder Structure</label>
<div class="folder-builder">
@foreach (var root in _tree)
{
<FolderTreeNode Node="root" Depth="1" OnRemove="RemoveRoot" OnChanged="RebuildFromTree" />
}
@if (_tree.Count == 0)
{
<p class="text-muted">No folders yet. Add a top-level folder to start.</p>
}
</div>
<button class="btn btn-secondary btn-sm mt-8" type="button" @onclick="AddRoot">+ Add top-level folder</button>
</div>
}
@if (_rows.Count > 0)
{
@@ -53,14 +81,26 @@
}
@code {
private enum InputMode { Csv, Builder }
private InputMode _mode = InputMode.Csv;
private List<SiteInfo> _sites = new();
private string _libraryTitle = string.Empty;
private List<CsvValidationRow<FolderStructureRow>> _rows = new();
private readonly List<FolderNode> _tree = new();
private bool _running; private string _status = string.Empty, _error = string.Empty;
private int _current, _total;
private BulkOperationSummary<string>? _summary;
private CancellationTokenSource? _cts;
private void SetMode(InputMode mode)
{
_mode = mode;
_rows.Clear();
_summary = null; _error = string.Empty;
if (mode == InputMode.Builder) RebuildFromTree();
}
private async Task LoadFile(InputFileChangeEventArgs e)
{
_rows.Clear();
@@ -68,6 +108,26 @@
_rows = CsvValidation.ParseAndValidateFolders(stream);
}
private void AddRoot()
{
_tree.Add(new FolderNode());
RebuildFromTree();
}
private void RemoveRoot(FolderNode node)
{
_tree.Remove(node);
RebuildFromTree();
}
// Convert the visual tree into validation rows so the count + Create button share the CSV path.
private void RebuildFromTree()
{
_rows = FolderNode.Flatten(_tree)
.Select(r => new CsvValidationRow<FolderStructureRow>(r, new List<string>()))
.ToList();
}
private async Task RunCreate()
{
_error = string.Empty; _summary = null; _running = true;