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

- 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:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-10-27 21:58:39 +01:00
1 parent 9aa818ed47
commit 7e4a3b481d
416 files changed
+15304 -1572

No files matched your search

+52 -6
View File
@@ -18,6 +18,8 @@ using Chronos.Core.Naming;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Jobs;
using Chronos.Data.Repositories;
using Chronos.Ui.Controls;
using Chronos.Ui.Mvvm;
using Chronos.Ui.Theming;
@@ -56,6 +58,9 @@ public sealed class SettingsViewModel : SectionViewModel
/// <summary>Drops a read of the open archive's settings that may have missed an edit being written meanwhile.</summary>
private readonly ArchiveReadGate _archiveReads = new();
/// <summary>The archive whose templates changed and which of them, offered by a toast (as long as a toast stays up).</summary>
private readonly ReorganizeOffer _reorganize = new(new Toast { Title = string.Empty }.Lifetime);
private bool _isDetectingFormats;
private IReadOnlyList<BackupOption> _backups = [];
private BackupOption? _selectedBackup;
@@ -104,13 +109,13 @@ public sealed class SettingsViewModel : SectionViewModel
{
_s.FolderTemplate = v;
Save();
_ = UpdateArchiveAsync(a => a with { Templates = a.Templates with { Folder = v } });
_ = OfferReorganizeAsync(UpdateArchiveAsync(a => a with { Templates = a.Templates with { Folder = v } }), ReorganizeParts.Folders);
}, () => Loc.L("Tooltips.Settings.FolderTemplate"));
FileTemplate = new EditableField(_s.FileTemplate, v => NamingPreview.Validate(v, isFolder: false), v =>
{
_s.FileTemplate = v;
Save();
_ = UpdateArchiveAsync(a => a with { Templates = a.Templates with { File = v } });
_ = OfferReorganizeAsync(UpdateArchiveAsync(a => a with { Templates = a.Templates with { File = v } }), ReorganizeParts.Files);
}, () => Loc.L("Tooltips.Settings.FileTemplate"));
FolderTemplate.PropertyChanged += (_, e) =>
{
@@ -1015,18 +1020,19 @@ public sealed class SettingsViewModel : SectionViewModel
/// that fails (offline, read-only, busy) the user hears why and the rows show the archive's values again. An edit made
/// while the archive at a folder just chosen is opening waits for it, then goes to that archive (or stays this PC's
/// default when there is none), instead of being lost. <paramref name="retarget"/> is the folder change the edit was
/// made after, the latest one by default.
/// made after, the latest one by default. Returns the archive as the edit left it; null when no archive took it.
/// </summary>
private async Task UpdateArchiveAsync(Func<ArchiveSettings, ArchiveSettings> edit, Task<Archive?>? retarget = null)
private async Task<Archive?> UpdateArchiveAsync(Func<ArchiveSettings, ArchiveSettings> edit, Task<Archive?>? retarget = null)
{
retarget ??= _retarget;
var waited = !retarget.IsCompleted;
if (await ArchiveAtFolderAsync(retarget) is not { } archive || Shell.Services.Archives is not { } archives) return;
if (await ArchiveAtFolderAsync(retarget) is not { } archive || Shell.Services.Archives is not { } archives) return null;
bool reload;
Archive? saved = null;
_archiveReads.BeginWrite();
try
{
var updated = await Task.Run(() => archives.UpdateSettingsAsync(archive.Id, edit));
var updated = saved = await Task.Run(() => archives.UpdateSettingsAsync(archive.Id, edit));
// The archive folder may have changed meanwhile: the rows then belong to another archive.
if (_archive?.Id == updated.Id) _archive = updated;
// The open showed the archive's values over the edit: unless another folder was chosen since, the rows (and
@@ -1047,6 +1053,46 @@ public sealed class SettingsViewModel : SectionViewModel
}
// Only once the write ended: a read begun while it is written waits for that end.
if (reload) await LoadArchiveAsync();
return saved;
}
/// <summary>
/// A template names only what is filed from now on: once the archive took a new one (<paramref name="update"/>), a toast
/// offers Reorganize, which applies the templates changed since to every sequence already in the archive, after a dry
/// run (owner review 2, R7). A template changed while the toast is still up joins it instead of raising another.
/// </summary>
private async Task OfferReorganizeAsync(Task<Archive?> update, ReorganizeParts part)
{
if (await update is not { } archive || Shell.Services.Database is not { } db) return;
try
{
// An empty archive has nothing to reorganize.
if (await db.Sequences.CountAsync(new SequenceQuery { ArchiveId = archive.Id }) == 0) return;
}
catch (DatabaseException ex)
{
Log.Warning("settings", "The sequences of the archive were not counted", ex);
return;
}
var raised = DateTime.UtcNow;
if (!_reorganize.Add(archive, part, raised)) return;
var toast = new Toast
{
Title = Loc.L("Settings.Archive.TemplatesSaved"),
Message = Loc.L("Settings.Archive.ExistingKept"),
ActionText = Loc.L("Settings.Archive.Reorganize"),
ActionToolTip = Loc.L("Tooltips.Settings.Reorganize"),
ActionCommand = new RelayCommand(() =>
{
// Every template of this archive changed since; what this toast offered when another toast of it took them.
var (target, parts) = _reorganize.Take(archive.Id) ?? (archive, part);
Shell.Navigate(SectionKey.Archive);
_ = Shell.Archive.OpenReorganizeAllAsync(target, parts);
}),
};
// Gone from the screen early (dismissed, pushed out), the next change of this archive raises a toast of its own.
toast.Closed += (_, _) => _reorganize.Closed(archive.Id, raised);
Shell.ShowToast(toast);
}
/// <summary>