feat(app): matches list, compare dialog, settings rows, library and picker surfaces (owner review 6, P6)

Server > Matches shows the pairs the copy engine found (same sequence on the
server and this PC, or twice here), attention first, with the design 8.1
actions; Keep apart and Unlink toast with Undo. The in-window Compare dialog
walks photos, details, projects and the plan, blocks until details are
chosen, and confirms only what replaces or merges (typed count for a merge).
Sync rows of an unanswered pair read "match found" and offer Compare first;
Upload all local skips suspected copies and says why. Settings > Server gains
Link matches, Integrate photos and Integrate projects. Library cards carry the
match status with Compare..., the sequence picker marks twins, and Jobs opens
Integrate and Merge targets. The sample engine and capture scenes render every
state; tests cover the text rules and the screens.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-16 20:29:07 +01:00
1 parent 283d04d9cd
commit 06b826e39d
34 files changed
+3762 -43

No files matched your search

+151 -14
View File
@@ -4,10 +4,12 @@ using System.IO;
using System.Windows.Input;
using System.Windows.Threading;
using Chronos.App.Infrastructure;
using Chronos.App.Server.Copies;
using Chronos.App.Shell;
using Chronos.Core.Diagnostics;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Data.Copies;
using Chronos.Data.Jobs;
using Chronos.Data.Sync;
using Chronos.Ui.Mvvm;
@@ -19,14 +21,29 @@ public sealed class SyncFilterChip(SyncFilter filter, Action<SyncFilter> select)
{
private int _count;
private bool _isSelected;
private bool _attention;
private bool _isVisible = true;
public SyncFilter Filter { get; } = filter;
public string Text => Loc.L("Server.Sync.Filter." + Filter, Formatting.Count(_count));
public string ToolTip => Loc.L("Tooltips.Server.Sync.Filter." + Filter);
public ICommand SelectCommand { get; } = new RelayCommand(() => select(filter));
/// <summary>Conflicts waiting for a choice: the chip is drawn in the warning colour unless it is the selected one.</summary>
public bool NeedsAttention => Filter == SyncFilter.Conflicts && _count > 0;
/// <summary>Conflicts, or matches, waiting for a choice: the chip is drawn in the warning colour unless it is the selected one.</summary>
public bool NeedsAttention => Filter == SyncFilter.Conflicts ? _count > 0 : Filter == SyncFilter.FoundCopies && _attention;
/// <summary>Matches: some pair asks for a choice (set by the sync table from the copy list).</summary>
public bool Attention
{
get => _attention;
set
{
if (Set(ref _attention, value)) OnPropertyChanged(nameof(NeedsAttention));
}
}
/// <summary>The Matches chip shows signed out too while this PC has more than one archive; the others only signed in.</summary>
public bool IsVisible { get => _isVisible; set => Set(ref _isVisible, value); }
public bool IsSelected
{
@@ -86,11 +103,20 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
private int _progressQueued;
private int _reloadQueued;
private bool _attached;
private bool _hasArchives;
/// <summary>The local-only sequences the last Upload all local left out, and why (owner review 6, Q8).</summary>
private readonly Dictionary<Guid, UploadSkip> _skipped = [];
/// <summary>Show was pressed on the Upload all toast: Local only lists the skipped sequences first.</summary>
private bool _skippedFirst;
public SyncTableViewModel(ShellViewModel shell)
{
_shell = shell;
_chips = [.. Enum.GetValues<SyncFilter>().Select(f => new SyncFilterChip(f, Select) { IsSelected = f == SyncFilter.All })];
Copies = new CopyListViewModel(shell) { ShowList = search => ShowFilter(SyncFilter.FoundCopies, search) };
Copies.Changed += OnCopiesChanged;
_uploadAll = new AsyncRelayCommand(UploadAllAsync, () => IsActive && Rights.CanUpload && LocalOnly.Any());
OpenAdminCommand = new RelayCommand(() =>
{
@@ -107,6 +133,22 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
public ObservableCollection<SyncRow> Rows { get; } = [];
public IReadOnlyList<SyncFilterChip> Chips => _chips;
/// <summary>Server › Matches (owner review 6, #73): shown in place of the rows while its chip is selected.</summary>
public CopyListViewModel Copies { get; }
/// <summary>The Matches chip is selected: the copy list, its header and Find matches replace the sync rows.</summary>
public bool IsMatches => _filter == SyncFilter.FoundCopies;
public bool ShowSyncList => !IsMatches && HasRows;
public bool ShowCopyList => IsMatches && Copies.HasRows;
public bool ShowCopyEmpty => IsMatches && Copies.IsEmpty;
/// <summary>The chips show while signed in, and signed out while this PC has more than one archive (local matches).</summary>
public bool ShowChips => IsActive || _hasArchives;
/// <summary>The search box filters the sync rows signed in, and the matches whenever they show.</summary>
public bool ShowSearch => IsActive || IsMatches;
public ICommand UploadAllCommand => _uploadAll;
public ICommand OpenAdminCommand { get; }
@@ -121,7 +163,9 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
get => _search;
set
{
if (Set(ref _search, value ?? string.Empty)) ApplyFilter(rebuild: true);
if (!Set(ref _search, value ?? string.Empty)) return;
Copies.SearchText = _search;
ApplyFilter(rebuild: true);
}
}
@@ -130,7 +174,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
public bool HasRows => Rows.Count > 0;
public SyncEmpty Empty => HasRows ? SyncEmpty.None
public SyncEmpty Empty => HasRows || IsMatches ? SyncEmpty.None
: !IsActive ? SyncEmpty.SignedOut
: _entries.Count == 0 ? SyncEmpty.Nothing
: SyncEmpty.NoMatch;
@@ -149,6 +193,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
!IsActive ? Loc.L("Tooltips.Server.Sync.UploadAll.NotConnected")
: !Rights.CanUpload ? Loc.L("Tooltips.Server.Sync.UploadAll.NoRight")
: !LocalOnly.Any() ? Loc.L("Tooltips.Server.Sync.UploadAll.Nothing")
: SelectUploads(new HashSet<Guid>()).Skipped.Count is > 0 and var skipping ? Loc.Plural("Tooltips.Server.Sync.UploadAllSkipping", skipping)
: Loc.Plural("Tooltips.Server.Sync.UploadAll", LocalOnly.Count(), Formatting.Bytes(LocalOnly.Sum(e => e.Local!.TotalBytes)));
/// <summary>"Last sync 10:15 · manifest diff 0.4 s"; null before the first comparison.</summary>
@@ -187,9 +232,17 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
jobs.JobChanged += OnJobChanged;
jobs.Progress += OnProgress;
}
Copies.Attach();
_ = ReloadAsync();
}
/// <summary>Selects a chip (the Matches toasts' Review and Show, Library › Compare…), with a search text when given.</summary>
internal void ShowFilter(SyncFilter filter, string? search = null)
{
if (search is not null) SearchText = search;
Select(filter);
}
/// <summary>Reads the table again; requests made while a pass runs share the next one, which they wait for.</summary>
public async Task ReloadAsync()
{
@@ -224,20 +277,81 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
jobs.JobChanged -= OnJobChanged;
jobs.Progress -= OnProgress;
}
Copies.Changed -= OnCopiesChanged;
Copies.Dispose();
}
private void Select(SyncFilter filter)
{
_filter = filter;
if (filter != SyncFilter.LocalOnly) _skippedFirst = false;
foreach (var chip in _chips) chip.IsSelected = chip.Filter == filter;
ApplyFilter(rebuild: true);
RaiseLists();
}
private void RaiseLists()
{
OnPropertyChanged(nameof(IsMatches));
OnPropertyChanged(nameof(ShowSyncList));
OnPropertyChanged(nameof(ShowCopyList));
OnPropertyChanged(nameof(ShowCopyEmpty));
OnPropertyChanged(nameof(ShowChips));
OnPropertyChanged(nameof(ShowSearch));
OnPropertyChanged(nameof(Empty));
OnPropertyChanged(nameof(EmptyText));
}
/// <summary>The copy list reloaded: the Matches chip's count and colour, its visibility, and the rows' marks.</summary>
private void OnCopiesChanged()
{
var chip = _chips.Single(c => c.Filter == SyncFilter.FoundCopies);
chip.Count = Copies.Count;
chip.Attention = Copies.AttentionCount > 0;
_ = UpdateArchivesAsync();
ApplyFilter(rebuild: false);
OnPropertyChanged(nameof(UploadAllToolTip));
RaiseLists();
}
/// <summary>Whether this PC has more than one archive (the Matches chip shows signed out then).</summary>
private async Task UpdateArchivesAsync()
{
if (_shell.Services.Database is not { } db) return;
try
{
_hasArchives = (await db.Archives.ListAsync()).Count > 1;
}
catch (Data.DatabaseException)
{
_hasArchives = false;
}
UpdateChipVisibility();
OnPropertyChanged(nameof(ShowChips));
}
private void UpdateChipVisibility()
{
foreach (var chip in _chips) chip.IsVisible = chip.Filter == SyncFilter.FoundCopies ? IsActive || _hasArchives : IsActive;
}
/// <summary>What the Matches list adds to the row of <paramref name="entry"/>: its pair and why Upload all left it out.</summary>
private SyncMark Mark(SyncEntry entry) => entry.Local is { } local
? new SyncMark(Copies.PairOf(local.Id), _skipped.TryGetValue(local.Id, out var why) ? why : null, _shell.Services.Server.Flow.Info?.Name)
: new SyncMark(Copies.PairOf(entry.Id), null, _shell.Services.Server.Flow.Info?.Name);
/// <summary>The rule of Upload all local (design §6.4): what it sends, and what it leaves out and why.</summary>
private (IReadOnlyList<SyncEntry> Upload, IReadOnlyList<(SyncEntry Entry, UploadSkip Why)> Skipped) SelectUploads(IReadOnlySet<Guid> busy) =>
UploadAllRule.Select(LocalOnly, [.. Copies.Pairs.Select(p => p.Copy)],
_shell.Services.Settings.KnownServers.Select(k => k.OriginalsArchiveId).OfType<Guid>().ToHashSet(), busy);
/// <summary>Counts, rows, footer and the Library's sync glyphs after a reload.</summary>
private void Refresh()
{
foreach (var chip in _chips) chip.Count = _entries.Count(e => SyncText.Matches(e, chip.Filter, string.Empty));
foreach (var chip in _chips.Where(c => c.Filter != SyncFilter.FoundCopies)) chip.Count = _entries.Count(e => SyncText.Matches(e, chip.Filter, string.Empty));
UpdateChipVisibility();
ApplyFilter(rebuild: false);
RaiseLists();
UpdateLibrary();
OnPropertyChanged(nameof(IsActive));
OnPropertyChanged(nameof(UploadAllToolTip));
@@ -257,6 +371,8 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
{
var rights = Rights;
var wanted = _entries.Where(e => SyncText.Matches(e, _filter, _search.Trim())).ToList();
// Show on the Upload all toast: the sequences it left out lead Local only.
if (_skippedFirst) wanted = [.. wanted.OrderByDescending(e => e.Local is { } l && _skipped.ContainsKey(l.Id))];
var byId = Rows.ToDictionary(r => r.Id);
if (rebuild)
{
@@ -270,7 +386,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
var entry = wanted[i];
if (i < Rows.Count && Rows[i].Id == entry.Id)
{
Rows[i].Update(entry, rights);
Rows[i].Update(entry, rights, Mark(entry));
continue;
}
var row = Row(entry, rights, byId);
@@ -288,8 +404,8 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
/// <summary>The existing row of an entry, updated, or a new one.</summary>
private SyncRow Row(SyncEntry entry, SyncRights rights, Dictionary<Guid, SyncRow> existing)
{
if (!existing.TryGetValue(entry.Id, out var row)) return new SyncRow(entry, rights, ActAsync);
row.Update(entry, rights);
if (!existing.TryGetValue(entry.Id, out var row)) return new SyncRow(entry, rights, ActAsync, Mark(entry));
row.Update(entry, rights, Mark(entry));
return row;
}
@@ -309,6 +425,9 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
var entry = row.Entry;
switch (action)
{
case SyncAction.Compare:
Copies.Compare(entry.Local?.Id ?? entry.Id);
return;
case SyncAction.Upload:
await service.EnqueueUploadAsync(engine, server, entry.Local!);
break;
@@ -396,16 +515,34 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
private async Task UploadAllAsync()
{
if (Host is not { Service: { } service, Server: { } server } || _shell.Services.Engine is not { } engine) return;
var queued = 0;
foreach (var entry in LocalOnly.ToList())
// Suspected matches, kept-apart sequences, those the server deleted, those an Integrate or Merge holds and those of a
// server's originals archive stay, flagged "skipped" with the reason (owner review 6, Q8).
var busy = new HashSet<Guid>();
if (_shell.Services.Database is { } db)
{
await service.EnqueueUploadAsync(engine, server, entry.Local!);
queued++;
busy.UnionWith(await db.Jobs.ListPendingTargetsAsync(JobKind.Integrate));
busy.UnionWith(await db.Jobs.ListPendingTargetsAsync(JobKind.MergeSequences));
}
_shell.Notify(Loc.Plural("Server.Sync.Queued", queued));
var (upload, skipped) = SelectUploads(busy);
_skipped.Clear();
foreach (var (entry, why) in skipped) _skipped[entry.Local!.Id] = why;
foreach (var entry in upload) await service.EnqueueUploadAsync(engine, server, entry.Local!);
if (skipped.Count == 0) _shell.Notify(Loc.Plural("Server.Sync.Queued", upload.Count));
else
_shell.Notify(Loc.L("Server.Sync.QueuedSkipped", Formatting.Count(upload.Count), Formatting.Count(skipped.Count)), null,
Loc.L("Server.Sync.Show"), Loc.L("Tooltips.Server.Sync.ShowSkipped"), ShowSkipped);
await ReloadAsync();
}
/// <summary>Show on the Upload all toast: Local only, the skipped sequences first.</summary>
private void ShowSkipped()
{
_shell.Navigate(SectionKey.Server);
Select(SyncFilter.LocalOnly);
_skippedFirst = true;
ApplyFilter(rebuild: true);
}
private void OnChanged() => Dispatch(() => _ = ReloadAsync());
private void OnCultureChanged(object? sender, EventArgs e) => Dispatch(() =>
@@ -417,7 +554,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
private void OnJobChanged(Job job)
{
if (job.Kind is not (JobKind.UploadCommit or JobKind.Download)) return;
if (job.Kind is not (JobKind.UploadCommit or JobKind.Download or JobKind.Integrate or JobKind.MergeSequences)) return;
_progress.TryRemove(job.Id, out _);
Dispatch(() =>
{