feat: owner review 2 phase 4a: Reorganize sequences after import (#12)
CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s
CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s
- Reorganize… on the web panel and the desktop: folder, file and title templates applied to existing sequences, with a dry run and an explicit Apply that runs as a job. - One naming rule (FrameNaming) for import, upload and Reorganize. - Crash-safe plan and file journals, held plans, stale-plan refusal; exports move with their folder. - Writers refuse a folder another program moved or gave to another sequence. - Server: POST /api/v1/archive/reorganize with a bounded plan cache; template rules. - Phase 3 docs and translations merged; strings in all 38 languages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #12.
This commit is contained in:
1 parent
9aa818ed47
commit
7e4a3b481d
416 files changed
+15304
-1572
No files matched your search
@@ -1,6 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.Core.Archiving;
|
||||
@@ -196,160 +195,6 @@ public sealed class RebuildDialogViewModel : ArchiveDialogViewModel
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mass rename (titles) or move (folder layout) of a set (BRIEF §7, §12.5): the template is checked as it is typed,
|
||||
/// the dry run lists every change, and Apply makes exactly those changes (journaled, so a crash resumes it).
|
||||
/// </summary>
|
||||
public sealed class RenameDialogViewModel : ArchiveDialogViewModel
|
||||
{
|
||||
private readonly ArchiveService _archives;
|
||||
private readonly Core.Model.Archive _archive;
|
||||
private readonly IReadOnlyList<Sequence> _set;
|
||||
private readonly Func<int, Task> _applied;
|
||||
private readonly DispatcherTimer _delay = new() { Interval = TimeSpan.FromMilliseconds(400) };
|
||||
private RenamePlan? _plan;
|
||||
private string? _planError;
|
||||
private IReadOnlyList<RenameRow> _rows = [];
|
||||
private CancellationTokenSource? _planning;
|
||||
|
||||
public RenameDialogViewModel(RenameMode mode, ArchiveService archives, Core.Model.Archive archive, IReadOnlyList<Sequence> set, Func<int, Task> applied,
|
||||
Action<ArchiveDialogViewModel> close)
|
||||
: base(close)
|
||||
{
|
||||
Mode = mode;
|
||||
_archives = archives;
|
||||
_archive = archive;
|
||||
_set = set;
|
||||
_applied = applied;
|
||||
var initial = mode == RenameMode.Folders ? archive.FolderTemplate : "{title}";
|
||||
Template = new EditableField(initial, t => MassRename.Validate(mode, t), committed => _ = PlanAsync(),
|
||||
() => Loc.L(mode == RenameMode.Folders ? "Tooltips.Archive.FolderTemplate" : "Tooltips.Archive.TitleTemplate"));
|
||||
Template.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName != nameof(EditableField.Text)) return;
|
||||
_delay.Stop();
|
||||
_delay.Start();
|
||||
};
|
||||
_delay.Tick += (_, _) =>
|
||||
{
|
||||
_delay.Stop();
|
||||
_ = PlanAsync();
|
||||
};
|
||||
ApplyCommand = new AsyncRelayCommand(ApplyAsync, () => ApplyBlocker is null);
|
||||
}
|
||||
|
||||
/// <summary>Why Apply is disabled; null when it can run.</summary>
|
||||
private string? ApplyBlocker =>
|
||||
IsBusy ? Loc.L("Archive.Blocked.Applying")
|
||||
: Template.Error is { } error ? error
|
||||
: _plan is null ? _planError ?? Loc.L("Archive.Blocked.Planning")
|
||||
: _plan.Steps.Count == 0 ? Loc.L("Archive.Blocked.NoChanges")
|
||||
: null;
|
||||
|
||||
public string ApplyToolTip => ApplyBlocker ?? Loc.L("Tooltips.Archive.RenameApply");
|
||||
|
||||
public RenameMode Mode { get; }
|
||||
|
||||
public string Heading => Loc.Plural(Mode == RenameMode.Folders ? "Archive.Rename.MoveHeading" : "Archive.Rename.Heading", _set.Count);
|
||||
|
||||
public EditableField Template { get; }
|
||||
|
||||
public IReadOnlyList<RenameRow> Rows { get => _rows; private set => Set(ref _rows, value); }
|
||||
|
||||
public string SummaryText => _plan is null ? string.Empty : MassRename.Summary(_plan, _set.Count);
|
||||
|
||||
public ICommand ApplyCommand { get; }
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_delay.Stop();
|
||||
_planning?.Cancel();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The dry run of the current template (the engine's plan; nothing changes on disk); it clears the last failure and
|
||||
/// stands in for a dry run still waiting on typing, which would otherwise throw this plan away.
|
||||
/// </summary>
|
||||
public Task PlanAsync()
|
||||
{
|
||||
_delay.Stop();
|
||||
ClearError();
|
||||
return DryRunAsync();
|
||||
}
|
||||
|
||||
private async Task DryRunAsync()
|
||||
{
|
||||
_planning?.Cancel();
|
||||
_plan = null;
|
||||
_planError = null;
|
||||
Rows = [];
|
||||
OnPlanChanged();
|
||||
if (Template.HasErrors) return;
|
||||
var cts = _planning = new CancellationTokenSource();
|
||||
var template = Template.Text;
|
||||
var ids = _set.Select(s => s.Id).ToList();
|
||||
try
|
||||
{
|
||||
var plan = await Task.Run(() => _archives.PlanRenameAsync(_archive.Id, ids, Mode == RenameMode.Folders ? template : null,
|
||||
Mode == RenameMode.Titles ? template : null, cts.Token), cts.Token);
|
||||
if (cts.IsCancellationRequested) return;
|
||||
_plan = plan;
|
||||
Rows = MassRename.Rows(plan, Mode);
|
||||
}
|
||||
catch (OperationCanceledException) when (cts.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
catch (Exception ex) when (ex is ArgumentException or DatabaseException or FormatException)
|
||||
{
|
||||
Log.Warning("archive", "Rename plan failed", ex);
|
||||
_planError = ArchiveFailures.Cause(ex);
|
||||
ShowError(ex);
|
||||
}
|
||||
OnPlanChanged();
|
||||
}
|
||||
|
||||
private void OnPlanChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(SummaryText));
|
||||
OnPropertyChanged(nameof(ApplyToolTip));
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
private async Task ApplyAsync()
|
||||
{
|
||||
if (_plan is not { } plan) return;
|
||||
ClearError();
|
||||
IsBusy = true;
|
||||
// A tick posted before the apply ended must not bring its progress back.
|
||||
var progress = new Progress<int>(n =>
|
||||
{
|
||||
if (IsBusy) BusyText = Loc.L("Archive.Rename.Applying", Formatting.Count(n), Formatting.Count(plan.Steps.Count));
|
||||
});
|
||||
try
|
||||
{
|
||||
await Task.Run(() => _archives.ApplyRenameAsync(plan, progress));
|
||||
Log.Info("archive", $"{Mode} applied to {plan.Steps.Count} sequence(s)");
|
||||
await _applied(plan.Steps.Count);
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or StaleRenamePlanException or DatabaseException)
|
||||
{
|
||||
Log.Warning("archive", "Rename failed", ex);
|
||||
ShowError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
BusyText = null;
|
||||
}
|
||||
// Part of the plan may have been applied, or the archive changed under it: the dry run shows what is left.
|
||||
await DryRunAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Add and remove tags on a set (BRIEF §12.5 Retag): the dry run counts the sequences that change.</summary>
|
||||
public sealed class RetagDialogViewModel : ArchiveDialogViewModel
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user