feat(app): server sync table, conflict resolution, sync options and Library sync glyphs

SyncHost runs the sync agent of the signed-in session and gives transfer jobs
their connection; the Server screen lists every sequence of this PC and of the
server with its state and actions (upload, download originals, open with
proxies, keep mine / take server / save both, pause, resume), filter chips,
search, Upload all local and the comparison footer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 22:53:24 +00:00
1 parent c02d1867d0
commit 25653c052b
16 files changed
+1072 -10

No files matched your search

+147
View File
@@ -0,0 +1,147 @@
using Titano.App.Infrastructure;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Data.Sync;
using Titano.Ui.Controls;
namespace Titano.App.Server;
/// <summary>Filter chips of the sync table (Server.html).</summary>
public enum SyncFilter
{
All,
LocalOnly,
Remote,
Conflicts,
}
/// <summary>What a row of the sync table offers.</summary>
public enum SyncAction
{
Upload,
OpenWithProxies,
DownloadOriginals,
SyncSettings,
KeepMine,
TakeServer,
SaveBoth,
Pause,
Resume,
}
/// <summary>What the signed-in account may do (server permission bits).</summary>
/// <param name="CanUpload">Send originals and settings.</param>
/// <param name="CanFetchOriginals">Download originals (editors and render nodes).</param>
public readonly record struct SyncRights(bool CanUpload, bool CanFetchOriginals)
{
public static SyncRights Of(long permissions) => new(
(permissions & (long)Permissions.Upload) != 0 && (permissions & (long)Permissions.Edit) != 0,
(permissions & (long)(Permissions.Edit | Permissions.RenderNode)) != 0);
}
/// <summary>The words, glyphs and actions of the sync table (BRIEF §12.7): plain functions of a <see cref="SyncEntry"/>.</summary>
public static class SyncText
{
/// <summary>"originals · proxies", "proxies" (cached server proxies) or "—".</summary>
public static string Local(SyncEntry entry)
{
if (entry.HasLocalOriginals)
return (entry.Local!.Status & SequenceStatus.ProxiesBuilt) != 0 ? Join(Loc.L("Server.Sync.Originals"), Loc.L("Server.Sync.Proxies")) : Loc.L("Server.Sync.Originals");
return entry.Link is { ProxiesCached: > 0 } ? Loc.L("Server.Sync.Proxies") : Loc.L("Server.Sync.None");
}
/// <summary>"originals · proxies · 3 exports", "46 % received" while uploading, or "—".</summary>
public static string Server(SyncEntry entry)
{
if (entry.Transfer is { Kind: JobKind.UploadCommit, State: JobState.Running, ProgressTotal: > 0 } upload)
return Loc.L("Server.Sync.Received", Formatting.Percent((double)upload.ProgressDone / upload.ProgressTotal));
if (entry.Link is not { } link) return Loc.L("Server.Sync.None");
var parts = new List<string>(3) { Loc.L("Server.Sync.Originals") };
if (link.ServerHasProxies) parts.Add(Loc.L("Server.Sync.Proxies"));
if (link.RenderCount > 0) parts.Add(Loc.Plural("Server.Sync.Exports", link.RenderCount));
return Join([.. parts]);
}
/// <summary>The State column: glyph kind, word and tooltip (never colour alone).</summary>
public static (StatusKind Kind, string Text, string ToolTip) State(SyncEntry entry)
{
if (entry.Transfer is { } job)
{
var upload = job.Kind == JobKind.UploadCommit;
return job.State switch
{
JobState.Paused => (StatusKind.Paused, Loc.L("Server.Sync.State.Paused"), Loc.L("Tooltips.Server.Sync.State.Paused")),
JobState.Queued => (StatusKind.Queued, Loc.L("Server.Sync.State.Waiting"), Loc.L("Tooltips.Server.Sync.State.Waiting")),
_ => (StatusKind.Running, Loc.L(upload ? "Server.Sync.State.Uploading" : "Server.Sync.State.Downloading"),
Loc.L(upload ? "Tooltips.Server.Sync.State.Uploading" : "Tooltips.Server.Sync.State.Downloading")),
};
}
return entry.Status switch
{
SyncStatus.InSync => (StatusKind.Done, Loc.L("Server.Sync.State.InSync"), Loc.L("Tooltips.Server.Sync.State.InSync")),
SyncStatus.LocalOnly => (StatusKind.Offline, Loc.L("Server.Sync.State.LocalOnly"), Loc.L("Tooltips.Server.Sync.State.LocalOnly")),
SyncStatus.RemoteOnly => (StatusKind.Remote, Loc.L("Server.Sync.State.RemoteOnly"), Loc.L("Tooltips.Server.Sync.State.RemoteOnly")),
SyncStatus.ProxiesOnly => (StatusKind.Remote, Loc.L("Server.Sync.State.ProxiesOnly"), Loc.L("Tooltips.Server.Sync.State.ProxiesOnly")),
SyncStatus.LocalAhead => (StatusKind.Synced, Loc.L("Server.Sync.State.LocalAhead"), Loc.L("Tooltips.Server.Sync.State.LocalAhead")),
SyncStatus.ServerAhead => (StatusKind.Remote, Loc.L("Server.Sync.State.ServerAhead"), Loc.L("Tooltips.Server.Sync.State.ServerAhead")),
_ => (StatusKind.Warning, Loc.L("Server.Sync.State.Conflict"), Conflict(entry)),
};
}
/// <summary>"exposure.deflickerWindow.manual: 41 here, 33 on the server" for each setting that differs (at most three).</summary>
public static string Conflict(SyncEntry entry)
{
var differences = entry.Link?.ConflictSettingsJson is { } theirs ? SyncRules.Differences(entry.Local?.SettingsJson, theirs) : [];
if (differences.Count == 0) return Loc.L("Tooltips.Server.Sync.State.Conflict");
return string.Join("\n", differences.Select(d => Loc.L("Server.Conflict.Difference", d.Path, d.Mine ?? Loc.L("Server.Sync.None"), d.Theirs ?? Loc.L("Server.Sync.None"))));
}
/// <summary>The row's buttons, in the order the mockup shows them.</summary>
public static IReadOnlyList<SyncAction> Actions(SyncEntry entry, SyncRights rights)
{
if (entry.Transfer is { } job) return job.State == JobState.Paused ? [SyncAction.Resume] : [SyncAction.Pause];
var actions = new List<SyncAction>(3);
switch (entry.Status)
{
case SyncStatus.LocalOnly when rights.CanUpload:
actions.Add(SyncAction.Upload);
break;
case SyncStatus.RemoteOnly or SyncStatus.ProxiesOnly:
actions.Add(SyncAction.OpenWithProxies);
if (rights.CanFetchOriginals) actions.Add(SyncAction.DownloadOriginals);
break;
case SyncStatus.LocalAhead when entry.Link is { MissingRemote: > 0 }:
if (rights.CanUpload) actions.Add(SyncAction.Upload);
break;
case SyncStatus.ServerAhead when entry.Link is { MissingLocal: > 0 }:
if (rights.CanFetchOriginals) actions.Add(SyncAction.DownloadOriginals);
break;
case SyncStatus.LocalAhead or SyncStatus.ServerAhead:
actions.Add(SyncAction.SyncSettings);
break;
case SyncStatus.Conflict:
actions.AddRange([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth]);
break;
}
return actions;
}
/// <summary>The bytes an upload or download of the row moves (for the tooltips).</summary>
public static long Size(SyncEntry entry, SyncAction action) => action switch
{
SyncAction.Upload => entry.Local?.TotalBytes ?? 0,
SyncAction.DownloadOriginals => entry.Link?.TotalBytes ?? 0,
_ => 0,
};
public static bool Matches(SyncEntry entry, SyncFilter filter, string search) =>
(filter switch
{
SyncFilter.LocalOnly => entry.Status == SyncStatus.LocalOnly,
SyncFilter.Remote => entry.Status is SyncStatus.RemoteOnly or SyncStatus.ProxiesOnly,
SyncFilter.Conflicts => entry.Status == SyncStatus.Conflict,
_ => true,
}) && (search.Length == 0 || entry.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase));
private static string Join(params string[] parts) => string.Join(" · ", parts);
}