feat(copies): matches between this PC and the server, Integrate and merge (owner review 6, v1.2.0) #74
No files matched your search
@@ -0,0 +1,250 @@
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Sync;
|
||||
|
||||
namespace Chronos.App.DesignTime;
|
||||
|
||||
/// <summary>One sample pair: the pair, both sides, the photos of each class, the details that differ and the projects.</summary>
|
||||
internal sealed record SampleCopy(FoundCopy Copy, CopyFacts Here, CopyFacts There, IReadOnlyList<ComparedPhoto> Photos,
|
||||
IReadOnlyList<DetailLine> Details, CopyProjectsView Projects, Guid? PreselectedKeep = null);
|
||||
|
||||
/// <summary>
|
||||
/// The matches engine of the screenshots and the App tests (owner review 6, #73, design §8.7): pairs held in memory over the
|
||||
/// sample's own sequences; Compare answers from the pair; the planners build their plans from the choices as the real
|
||||
/// planners would, without touching a file; Enqueue queues a job the capture's engine does not run.
|
||||
/// </summary>
|
||||
internal sealed class SampleCopyEngine : ICopyEngine
|
||||
{
|
||||
private readonly List<SampleCopy> _pairs = [];
|
||||
private Action<CopyFindResult>? _found;
|
||||
|
||||
/// <summary>Written out, so the warnings-as-errors build raises no CS0067 for an event only tests raise.</summary>
|
||||
public event Action<CopyFindResult>? Found
|
||||
{
|
||||
add => _found += value;
|
||||
remove => _found -= value;
|
||||
}
|
||||
|
||||
/// <summary>What Find matches answers (the toast's count).</summary>
|
||||
public CopyFindResult NextFind { get; set; } = CopyFindResult.Empty;
|
||||
|
||||
public IReadOnlyList<SampleCopy> Pairs => _pairs;
|
||||
|
||||
public void Add(SampleCopy pair) => _pairs.Add(pair);
|
||||
|
||||
/// <summary>Raises <see cref="Found"/> as a detection run would (the matches-found toast).</summary>
|
||||
public void RaiseFound(CopyFindResult result) => _found?.Invoke(result);
|
||||
|
||||
public FoundCopy Get(Guid id) => Pair(id).Copy;
|
||||
|
||||
public Task<IReadOnlyList<FoundCopyView>> ListAsync(CancellationToken ct) =>
|
||||
Task.FromResult<IReadOnlyList<FoundCopyView>>([.. _pairs.Where(p => p.Copy.IsListed).Select(p => new FoundCopyView(p.Copy, p.Here, p.There))]);
|
||||
|
||||
public Task<CopyFindResult> FindAsync(ISyncRemote? remote, CancellationToken ct) => Task.FromResult(NextFind);
|
||||
|
||||
public Task<CopyReview> CompareAsync(Guid copyId, ISyncRemote? remote, CancellationToken ct)
|
||||
{
|
||||
var pair = Pair(copyId);
|
||||
var totals = Enum.GetValues<PhotoClass>()
|
||||
.Select(c => new PhotoClassTotal(c, pair.Photos.Count(p => p.Class == c),
|
||||
pair.Photos.Where(p => p.Class == c && p.Here is not null).Sum(p => p.Here!.Size),
|
||||
pair.Photos.Where(p => p.Class == c && p.There is not null).Sum(p => p.There!.Size)))
|
||||
.ToList();
|
||||
var renders = new CopyRendersView(2, 1, 1, 180_000_000, 90_000_000);
|
||||
var can = new CopyCapabilities(Integrate: true, LinkOnly: pair.Copy is { Kind: CopyKind.LocalServer, State: CopyState.Candidate }, DeleteThere: true, []);
|
||||
return Task.FromResult(new CopyReview(pair.Copy, pair.Here, pair.There, new CopyComparisonResult(pair.Photos, totals, pair.Copy.Score),
|
||||
pair.Details, pair.Projects, renders, can));
|
||||
}
|
||||
|
||||
public Task<IntegratePlan> PlanIntegrateAsync(Guid copyId, ISyncRemote remote, IntegrateChoices choices, CancellationToken ct)
|
||||
{
|
||||
var pair = Pair(copyId);
|
||||
var (steps, leftOut) = Steps(pair, choices.Photos, choices.PerPhoto, merge: false);
|
||||
var blocks = new List<CopyBlock>();
|
||||
if (pair.Details.Any(d => !choices.Details.ContainsKey(d.Path))) blocks.Add(CopyBlock.DetailsUnchosen);
|
||||
var projects = choices.Projects == CopyProjects.CopyAcross
|
||||
? pair.Projects.Here.Where(p => !p.IsMain).Select(p => new ProjectStep(CopySide.ThisPc, p.Id, p.Name, p.Name + " (STUDIO-PC)", p.Versions, p.HeadId))
|
||||
.Concat(pair.Projects.There.Where(p => !p.IsMain).Select(p => new ProjectStep(CopySide.Other, p.Id, p.Name, p.Name + " (nas)", p.Versions, p.HeadId)))
|
||||
.ToList()
|
||||
: [];
|
||||
var lasts = steps.Where(s => s.Action is PhotoAction.TrashHere or PhotoAction.TrashThere).Take(1)
|
||||
.Select(s => new LastCopy(s.Key, s.Action == PhotoAction.TrashHere ? CopySide.ThisPc : CopySide.Other, s.FileName, s.Bytes)).ToList();
|
||||
return Task.FromResult(new IntegratePlan(copyId, pair.Copy.Server ?? string.Empty, pair.Copy.LocalId, pair.Copy.RemoteId ?? Guid.Empty, choices,
|
||||
steps, lasts, leftOut, null, null, null, choices.Details.Count, projects,
|
||||
steps.Where(s => s.Action is PhotoAction.Fetch or PhotoAction.FetchVersion).Sum(s => s.Bytes),
|
||||
steps.Where(s => s.Action is PhotoAction.Send or PhotoAction.SendVersion).Sum(s => s.Bytes),
|
||||
1_240_000_000_000, 2_900_000_000_000, blocks, 1, 1, 1, 1, "sample"));
|
||||
}
|
||||
|
||||
public async Task<Job> EnqueueIntegrateAsync(JobEngine engine, IntegratePlan plan, CancellationToken ct)
|
||||
{
|
||||
var job = await engine.EnqueueAsync(JobKind.Integrate, [plan.LocalId], Pair(plan.CopyId).Here.Title);
|
||||
Set(plan.CopyId, c => c with { State = CopyState.Integrating, PreviousState = c.State, JobId = job.Id });
|
||||
return job;
|
||||
}
|
||||
|
||||
public Task<MergePlan> PlanMergeAsync(Guid copyId, Guid? keepId, MergeChoices choices, CancellationToken ct)
|
||||
{
|
||||
var pair = Pair(copyId);
|
||||
var keep = keepId ?? pair.PreselectedKeep;
|
||||
var blocks = new List<CopyBlock>();
|
||||
if (keep is null) blocks.Add(CopyBlock.KeptUnchosen);
|
||||
if (pair.Details.Any(d => !choices.Details.ContainsKey(d.Path))) blocks.Add(CopyBlock.DetailsUnchosen);
|
||||
var keepsHere = keep is null || keep == pair.Copy.LocalId;
|
||||
var (steps, _) = Steps(pair, choices.Photos, choices.PerPhoto, merge: true, keepsHere);
|
||||
var drop = keepsHere ? pair.There : pair.Here;
|
||||
var projects = (keepsHere ? pair.Projects.There : pair.Projects.Here).Where(p => !p.IsMain)
|
||||
.Select(p => new ProjectStep(keepsHere ? CopySide.Other : CopySide.ThisPc, p.Id, p.Name, p.Name + " (2)", p.Versions, p.HeadId)).ToList();
|
||||
return Task.FromResult(new MergePlan(copyId, keep ?? Guid.Empty, keepsHere ? pair.Copy.OtherId ?? Guid.Empty : pair.Copy.LocalId, choices, steps, [],
|
||||
[new RenderStep(Guid.CreateVersion7(), "Alps 2025 4K.mp4", 640_000_000, null)], null, choices.Details.Count, projects,
|
||||
["card:CANON-EOS-R5:2025-07-14"], [], [pair.Copy.Server ?? "nas"], new DeletePlan([], []), drop.Bytes / 20, 1_240_000_000_000, blocks,
|
||||
1, 1, 1, 1, "sample"));
|
||||
}
|
||||
|
||||
public async Task<Job> EnqueueMergeAsync(JobEngine engine, MergePlan plan, CancellationToken ct)
|
||||
{
|
||||
var job = await engine.EnqueueAsync(JobKind.MergeSequences, [plan.KeepId, plan.DropId], Pair(plan.CopyId).Here.Title);
|
||||
Set(plan.CopyId, c => c with { State = CopyState.Integrating, PreviousState = c.State, JobId = job.Id });
|
||||
return job;
|
||||
}
|
||||
|
||||
public Task KeepApartAsync(Guid copyId, CancellationToken ct) => Change(copyId, c => c with { State = CopyState.KeptApart, PreviousState = c.State, AnsweredAt = SampleData.Now });
|
||||
|
||||
public Task AskAgainAsync(Guid copyId, CancellationToken ct) => Change(copyId, c => c with { State = CopyState.Candidate, PreviousState = c.State, AnsweredAt = null });
|
||||
|
||||
public Task LinkAsync(Guid copyId, ISyncRemote remote, CancellationToken ct) => Change(copyId, c => c with { State = CopyState.Linked, PreviousState = c.State });
|
||||
|
||||
public Task UnlinkAsync(Guid copyId, ISyncRemote? remote, CancellationToken ct) => Change(copyId, c => c with { State = CopyState.KeptApart, PreviousState = c.State });
|
||||
|
||||
public Task<FrameDeletePlan> PlanTrashHereAsync(Guid copyId, IReadOnlyCollection<string> photoKeys, CancellationToken ct) =>
|
||||
Task.FromResult(new FrameDeletePlan(new Sequence { Id = Pair(copyId).Copy.LocalId, ArchiveId = Guid.Empty, Folder = string.Empty }, [], 0, []));
|
||||
|
||||
public Task<int> TrashHereAsync(Guid copyId, FrameDeletePlan plan, ISyncRemote? remote, CancellationToken ct) => Task.FromResult(plan.Frames.Count);
|
||||
|
||||
public Task<TrashTherePlan> PlanTrashThereAsync(Guid copyId, ISyncRemote remote, IReadOnlyCollection<string> photoKeys, CancellationToken ct)
|
||||
{
|
||||
var pair = Pair(copyId);
|
||||
var photos = pair.Photos.Where(p => photoKeys.Contains(p.Key) && p.There is not null).ToList();
|
||||
return Task.FromResult(new TrashTherePlan(copyId, pair.Copy.Server ?? string.Empty, pair.Copy.RemoteId ?? Guid.Empty,
|
||||
[.. photos.Select(p => p.There!.FrameId)], [.. photos.Select(p => p.Key)], photos.Count, photos.Sum(p => p.There!.Size), 1, []));
|
||||
}
|
||||
|
||||
public Task<int> TrashThereAsync(TrashTherePlan plan, ISyncRemote remote, CancellationToken ct) => Task.FromResult(plan.Photos);
|
||||
|
||||
public Task KeepHereAsync(Guid copyId, CancellationToken ct) => Change(copyId, c => c with { State = CopyState.KeptApart, PreviousState = c.State });
|
||||
|
||||
public Task<IReadOnlyList<CopyTwin>> TwinsAsync(CancellationToken ct) => Task.FromResult<IReadOnlyList<CopyTwin>>(
|
||||
[.. _pairs.Where(p => p.Copy is { Kind: CopyKind.LocalServer, State: CopyState.Integrated or CopyState.Linked })
|
||||
.Select(p => new CopyTwin(p.Copy.Id, p.Copy.LocalId, p.Here.Where, "Main", p.Copy.Server ?? string.Empty, p.Copy.RemoteId ?? Guid.Empty, "Vertical"))]);
|
||||
|
||||
/// <summary>
|
||||
/// The photo steps of the choices: photos only on one side travel to the other (unless Choose each leaves them out);
|
||||
/// differing ones keep both (Union), or the winner's replaces the loser's, which goes to the trash.
|
||||
/// </summary>
|
||||
private static (List<PhotoStep> Steps, int LeftOut) Steps(SampleCopy pair, CopyPhotoPolicy policy, IReadOnlyDictionary<string, PhotoChoice> perPhoto,
|
||||
bool merge, bool keepsHere = true)
|
||||
{
|
||||
var steps = new List<PhotoStep>();
|
||||
var leftOut = 0;
|
||||
foreach (var photo in pair.Photos)
|
||||
{
|
||||
var here = photo.Here;
|
||||
var there = photo.There;
|
||||
var choice = perPhoto.TryGetValue(photo.Key, out var c) ? c : (PhotoChoice?)null;
|
||||
switch (photo.Class)
|
||||
{
|
||||
case PhotoClass.OnlyHere when here is not null:
|
||||
if (merge && keepsHere) break;
|
||||
if (policy == CopyPhotoPolicy.ChoosePerPhoto && choice != PhotoChoice.Bring && !merge)
|
||||
{
|
||||
leftOut++;
|
||||
break;
|
||||
}
|
||||
steps.Add(new(photo.Key, merge ? PhotoAction.Fetch : PhotoAction.Send, here.FrameId, here.FileName, here.Size, here.Sha256));
|
||||
break;
|
||||
case PhotoClass.OnlyThere when there is not null:
|
||||
if (merge && !keepsHere) break;
|
||||
if (policy == CopyPhotoPolicy.ChoosePerPhoto && choice != PhotoChoice.Bring && !merge)
|
||||
{
|
||||
leftOut++;
|
||||
break;
|
||||
}
|
||||
steps.Add(new(photo.Key, PhotoAction.Fetch, there.FrameId, there.FileName, there.Size, there.Sha256));
|
||||
break;
|
||||
case PhotoClass.Differs when here is not null && there is not null:
|
||||
var wanted = policy switch
|
||||
{
|
||||
CopyPhotoPolicy.Union => PhotoChoice.KeepBoth,
|
||||
CopyPhotoPolicy.ThisPcWins => PhotoChoice.TakeHere,
|
||||
CopyPhotoPolicy.OtherWins => PhotoChoice.TakeThere,
|
||||
_ => choice ?? PhotoChoice.Leave,
|
||||
};
|
||||
if (wanted == PhotoChoice.Leave)
|
||||
{
|
||||
leftOut++;
|
||||
break;
|
||||
}
|
||||
if (wanted is PhotoChoice.KeepBoth or PhotoChoice.TakeHere) steps.Add(new(photo.Key, PhotoAction.SendVersion, here.FrameId, here.FileName, here.Size, here.Sha256));
|
||||
if (wanted is PhotoChoice.KeepBoth or PhotoChoice.TakeThere) steps.Add(new(photo.Key, PhotoAction.FetchVersion, there.FrameId, there.FileName, there.Size, there.Sha256));
|
||||
if (wanted == PhotoChoice.TakeHere) steps.Add(new(photo.Key, PhotoAction.TrashThere, there.FrameId, there.FileName, there.Size, there.Sha256));
|
||||
if (wanted == PhotoChoice.TakeThere) steps.Add(new(photo.Key, PhotoAction.TrashHere, here.FrameId, here.FileName, here.Size, here.Sha256));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (steps, leftOut);
|
||||
}
|
||||
|
||||
private SampleCopy Pair(Guid copyId) => _pairs.Single(p => p.Copy.Id == copyId);
|
||||
|
||||
private void Set(Guid copyId, Func<FoundCopy, FoundCopy> change)
|
||||
{
|
||||
var at = _pairs.FindIndex(p => p.Copy.Id == copyId);
|
||||
_pairs[at] = _pairs[at] with { Copy = change(_pairs[at].Copy) };
|
||||
}
|
||||
|
||||
private Task Change(Guid copyId, Func<FoundCopy, FoundCopy> change)
|
||||
{
|
||||
Set(copyId, change);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The sample pairs (design §8.7): five time-lapses with titles of their own, so the sync scenes' counts stay.</summary>
|
||||
internal static class SampleCopies
|
||||
{
|
||||
/// <summary>The photos of one side: name, size, capture time; every third one unhashed when asked.</summary>
|
||||
internal static IEnumerable<ComparedPhoto> Photos(PhotoClass cls, int count, DateTime start, int from, bool here, bool there, string prefix = "IMG_")
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var at = start.AddSeconds((from + i) * 10);
|
||||
var name = $"{prefix}{from + i + 1:0000}.CR3";
|
||||
var size = 24_000_000L + (from + i) % 7 * 310_000;
|
||||
var sha = $"{cls}{from + i:x8}".PadRight(64, '0');
|
||||
var h = here ? new CopyPhotoInput(Guid.CreateVersion7(), from + i, name, sha, size, at, false) : null;
|
||||
var t = there ? new CopyPhotoInput(Guid.CreateVersion7(), from + i, name, cls == PhotoClass.Differs ? sha.Replace('0', '1') : sha, size + (cls == PhotoClass.Differs ? 4_096 : 0), at, false) : null;
|
||||
yield return new ComparedPhoto(cls, sha, h, t, here ? 1 : 0, there ? 1 : 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
internal static CopyScore Score(IReadOnlyList<ComparedPhoto> photos, int hints)
|
||||
{
|
||||
int Of(PhotoClass c) => photos.Count(p => p.Class == c);
|
||||
var local = photos.Count(p => p.Here is not null);
|
||||
var other = photos.Count(p => p.There is not null);
|
||||
var shared = Of(PhotoClass.Same) + Of(PhotoClass.Differs);
|
||||
var smaller = Math.Max(1, Math.Min(local, other));
|
||||
return new CopyScore(Of(PhotoClass.Same), Of(PhotoClass.SameUnhashed), 0, Of(PhotoClass.OnlyHere), Of(PhotoClass.OnlyThere), Of(PhotoClass.Differs),
|
||||
Of(PhotoClass.DeletedHere), Of(PhotoClass.DeletedThere), Of(PhotoClass.Versions), local, other,
|
||||
Math.Min(1000, shared * 1000 / smaller), shared * 1000 / Math.Max(1, local + other - shared), hints);
|
||||
}
|
||||
|
||||
internal static CopyFacts Facts(Sequence sequence, string where, int photos, bool originals = false, IReadOnlyList<string>? servers = null) =>
|
||||
new(sequence.DisplayTitle, where, sequence.ArchiveId, photos, photos * 24_000_000L, sequence.FirstCapture, sequence.LastCapture,
|
||||
sequence.CameraModel, photos, sequence.Origin, servers ?? [], originals);
|
||||
|
||||
internal static ProjectLine Project(string name, bool main, int versions, int daysAgo) =>
|
||||
new(Guid.CreateVersion7(), name, main, versions, Guid.CreateVersion7(), "sample", SampleData.Now.AddDays(-daysAgo));
|
||||
}
|
||||
@@ -24,6 +24,7 @@ using Chronos.Core.Updates;
|
||||
using Chronos.Core.Video;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Scheduling;
|
||||
using Chronos.Data.Sync;
|
||||
@@ -63,8 +64,11 @@ public sealed class SampleData
|
||||
|
||||
private SampleData(AppServices services) => _services = services;
|
||||
|
||||
/// <summary>What the sample server says it can do (none: an older server, whose sequences open with proxies); tests set it.</summary>
|
||||
public IReadOnlyList<string> Capabilities { get; set; } = [];
|
||||
/// <summary>
|
||||
/// What the sample server says it can do: the photo lookup and uploads into a sequence that matches need (owner review 6,
|
||||
/// #73), but no projects (an older server's sequences open with proxies); tests set it.
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> Capabilities { get; set; } = [ServerCapabilities.PhotoLookup, ServerCapabilities.UploadInto];
|
||||
|
||||
/// <summary>The server-only sequence whose proxies <see cref="CacheProxiesAsync"/> keeps on this PC (Sunrise over Superga).</summary>
|
||||
public Guid ProxiedSequenceId => _sunrise;
|
||||
@@ -278,6 +282,120 @@ public sealed class SampleData
|
||||
await db.Jobs.EnqueueAsync(SampleJobDetails.Apply(Transfer(JobKind.Download, _lakeComo, "Lake Como storm", originals, JobState.Paused, 300, 1_450)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The matches of the screenshots (owner review 6, #73, design §8.7), a phase of its own after the sync captures: five
|
||||
/// time-lapses of their own (a second archive holds the other Alps 2025), so the sync scenes' counts stay. Lighthouse
|
||||
/// 2026-08-13 is a match found on the server (24 photos only here, 2 different, three details differ), Meteor night kept
|
||||
/// apart, Bridge works wk 41 integrated with 3 photos deleted on the server, Alps 2025 twice on this PC (the copy in the
|
||||
/// server's originals archive preselected as the kept one), Garden 2026 deleted on the server. Returns the engine.
|
||||
/// </summary>
|
||||
internal async Task<SampleCopyEngine> FillCopiesAsync()
|
||||
{
|
||||
var db = _db ?? throw new InvalidOperationException("FillAsync first.");
|
||||
var main = (await db.Archives.ListAsync())[0];
|
||||
var root = Path.Combine(_services.Environment.DataDirectory, "archive-nas");
|
||||
Directory.CreateDirectory(root);
|
||||
var originals = new Archive { Id = Guid.CreateVersion7(), Name = "ChronosArchive - Studio NAS", RootPath = root, Created = Now.AddMonths(-3) };
|
||||
await db.Archives.UpsertAsync(originals);
|
||||
var server = _services.Sync.LastServer ?? ServerAddress;
|
||||
const string ServerName = "Studio NAS";
|
||||
var start = new DateTime(2026, 8, 13, 21, 0, 0);
|
||||
|
||||
async Task<Sequence> SequenceAsync(string title, Guid archive, int frames, DateTime first, string camera)
|
||||
{
|
||||
var sequence = new Sequence
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
ArchiveId = archive,
|
||||
Title = title,
|
||||
Folder = $"{first:yyyy}/{first:yyyy-MM-dd} {camera}",
|
||||
CameraMake = "Canon",
|
||||
CameraModel = camera,
|
||||
FirstCapture = first,
|
||||
LastCapture = first.AddSeconds(frames * 10),
|
||||
FrameCount = frames,
|
||||
MedianInterval = 10,
|
||||
TotalBytes = frames * 24_000_000L,
|
||||
Status = SequenceStatus.AnalyzedLight | SequenceStatus.ThumbsBuilt,
|
||||
UpdatedAt = Now,
|
||||
};
|
||||
await db.Sequences.UpsertAsync(sequence);
|
||||
return sequence;
|
||||
}
|
||||
|
||||
var engine = new SampleCopyEngine();
|
||||
FoundCopy Copy(Sequence local, CopyKind kind, CopyState state, IReadOnlyList<ComparedPhoto> photos, Guid? other = null, int gone = 0, int hints = 3) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
Kind = kind,
|
||||
LocalId = local.Id,
|
||||
Server = kind == CopyKind.LocalServer ? server : null,
|
||||
RemoteId = kind == CopyKind.LocalServer ? Guid.CreateVersion7() : null,
|
||||
OtherId = other,
|
||||
Evidence = CopyEvidence.Hashes,
|
||||
State = state,
|
||||
Score = SampleCopies.Score(photos, hints),
|
||||
Fingerprint = "sample",
|
||||
RemoteGoneHits = gone,
|
||||
RemoteGoneAt = gone > 0 ? Now.AddDays(-1) : null,
|
||||
FoundAt = Now.AddDays(-2),
|
||||
UpdatedAt = Now.AddHours(-3),
|
||||
AnsweredAt = state == CopyState.KeptApart ? Now.AddDays(-12) : null,
|
||||
};
|
||||
CopyProjectsView Projects(bool other) => new(
|
||||
[SampleCopies.Project("Main", true, 4, 2), SampleCopies.Project("Vertical", false, 3, 5)],
|
||||
other ? [SampleCopies.Project("Main", true, 2, 9), SampleCopies.Project("Slow pan", false, 1, 9)] : [SampleCopies.Project("Main", true, 2, 9)],
|
||||
MainSame: false, ThereKeepsProjects: true);
|
||||
|
||||
// (1) Lighthouse: the card's photos, the Uploader sent part of them.
|
||||
var lighthouse = await SequenceAsync("Lighthouse 2026-08-13", main.Id, 1_204, start, "Canon EOS R5");
|
||||
List<ComparedPhoto> photos =
|
||||
[
|
||||
.. SampleCopies.Photos(PhotoClass.Same, 1_178, start, 0, here: true, there: true),
|
||||
.. SampleCopies.Photos(PhotoClass.OnlyHere, 24, start, 1_178, here: true, there: false),
|
||||
.. SampleCopies.Photos(PhotoClass.Differs, 2, start, 1_202, here: true, there: true),
|
||||
];
|
||||
engine.Add(new SampleCopy(Copy(lighthouse, CopyKind.LocalServer, CopyState.Candidate, photos),
|
||||
SampleCopies.Facts(lighthouse, main.Name, 1_204), SampleCopies.Facts(lighthouse, ServerName, 1_180), photos,
|
||||
[new DetailLine("title", "Lighthouse 2026-08-13", "Lighthouse"), new DetailLine("rating", "4", "3"),
|
||||
new DetailLine("exposure.deflickerWindow", "41", "33")], Projects(other: true)));
|
||||
|
||||
// (2) Meteor night: kept apart.
|
||||
var meteor = await SequenceAsync("Meteor night", main.Id, 640, new DateTime(2026, 8, 12, 23, 10, 0), "Canon EOS R6");
|
||||
photos = [.. SampleCopies.Photos(PhotoClass.Same, 320, start, 0, true, true), .. SampleCopies.Photos(PhotoClass.OnlyHere, 320, start, 320, true, false)];
|
||||
engine.Add(new SampleCopy(Copy(meteor, CopyKind.LocalServer, CopyState.KeptApart, photos, hints: 1),
|
||||
SampleCopies.Facts(meteor, main.Name, 640), SampleCopies.Facts(meteor, ServerName, 320), photos, [], Projects(other: false)));
|
||||
|
||||
// (3) Bridge works: integrated; the server deleted 3 photos since.
|
||||
var bridge = await SequenceAsync("Bridge works wk 41", main.Id, 2_400, new DateTime(2026, 10, 6, 7, 0, 0), "Canon EOS R5");
|
||||
photos = [.. SampleCopies.Photos(PhotoClass.Same, 2_397, start, 0, true, true), .. SampleCopies.Photos(PhotoClass.DeletedThere, 3, start, 2_397, true, false)];
|
||||
engine.Add(new SampleCopy(Copy(bridge, CopyKind.LocalServer, CopyState.Integrated, photos),
|
||||
SampleCopies.Facts(bridge, main.Name, 2_400), SampleCopies.Facts(bridge, ServerName, 2_397), photos, [], Projects(other: false)));
|
||||
|
||||
// (4) Alps 2025 twice on this PC: the copy downloaded into the server's originals archive is kept.
|
||||
var alps = await SequenceAsync("Alps 2025", main.Id, 940, new DateTime(2025, 7, 14, 5, 30, 0), "Canon EOS R5");
|
||||
var alpsNas = await SequenceAsync("Alps 2025", originals.Id, 902, new DateTime(2025, 7, 14, 5, 30, 0), "Canon EOS R5");
|
||||
photos =
|
||||
[
|
||||
.. SampleCopies.Photos(PhotoClass.Same, 900, start, 0, true, true),
|
||||
.. SampleCopies.Photos(PhotoClass.OnlyHere, 38, start, 900, true, false),
|
||||
.. SampleCopies.Photos(PhotoClass.Versions, 2, start, 938, true, false, "IMG_V"),
|
||||
];
|
||||
engine.Add(new SampleCopy(Copy(alps, CopyKind.LocalLocal, CopyState.Candidate, photos, other: alpsNas.Id),
|
||||
SampleCopies.Facts(alps, main.Name, 940), SampleCopies.Facts(alpsNas, originals.Name, 902, originals: true, servers: [ServerName]), photos,
|
||||
[new DetailLine("rating", "5", "4")], Projects(other: true), PreselectedKeep: alpsNas.Id));
|
||||
|
||||
// (5) Garden 2026: the server deleted its copy.
|
||||
var garden = await SequenceAsync("Garden 2026", main.Id, 480, new DateTime(2026, 5, 2, 6, 0, 0), "Canon EOS R6");
|
||||
photos = [.. SampleCopies.Photos(PhotoClass.Same, 480, start, 0, true, false)];
|
||||
engine.Add(new SampleCopy(Copy(garden, CopyKind.LocalServer, CopyState.Linked, photos, gone: 2),
|
||||
SampleCopies.Facts(garden, main.Name, 480), SampleCopies.Facts(garden, ServerName, 0), photos, [], Projects(other: false)));
|
||||
|
||||
engine.NextFind = new CopyFindResult([engine.Pairs[0].Copy, engine.Pairs[3].Copy], [], []);
|
||||
_services.Sync.Copies = engine;
|
||||
return engine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches the proxies of Sunrise over Superga into the proxy cache through a download job on a one-off engine (the
|
||||
/// capture's engine does not run jobs), so the sync table shows a sequence kept with proxies only.
|
||||
|
||||
@@ -17,6 +17,23 @@ public static class LibraryScenes
|
||||
/// <summary>Sequences selected for the mass actions bar.</summary>
|
||||
public const int MassSelection = 3;
|
||||
|
||||
/// <summary>
|
||||
/// <c>library-copies</c> (owner review 6, #73): the cards of sequences in matches that ask for a choice, with "Also
|
||||
/// elsewhere" or "Deleted there", found by <paramref name="search"/>; the Matches list pushes the statuses after its reload.
|
||||
/// </summary>
|
||||
public static async Task ShowCopiesAsync(ShellViewModel shell, string search)
|
||||
{
|
||||
var library = shell.Library;
|
||||
shell.Navigate(SectionKey.Library);
|
||||
library.Dialog?.CloseCommand.Execute(null);
|
||||
library.ClearSelectionCommand.Execute(null);
|
||||
library.ClearFiltersCommand.Execute(null);
|
||||
library.LayoutIndex = 0;
|
||||
library.SearchText = search;
|
||||
await library.RefreshAsync();
|
||||
await shell.Server.Sync.Copies.ReloadAsync();
|
||||
}
|
||||
|
||||
public static async Task ShowAsync(ShellViewModel shell, string scene)
|
||||
{
|
||||
var library = shell.Library;
|
||||
|
||||
@@ -31,6 +31,7 @@ public sealed class SequenceItem : ObservableObject
|
||||
private int _requestedWidth;
|
||||
private bool _isSelected;
|
||||
private bool _isAnalysing;
|
||||
private CardStatus? _match;
|
||||
|
||||
public SequenceItem(Sequence sequence, ISequenceThumbnails? thumbnails)
|
||||
{
|
||||
@@ -100,7 +101,26 @@ public sealed class SequenceItem : ObservableObject
|
||||
public string TagsText => string.Join(", ", _sequence.Tags);
|
||||
|
||||
/// <summary>Status glyphs of the card and the list (DESIGN §4: glyph + word, never colour alone).</summary>
|
||||
public IReadOnlyList<CardStatus> Statuses => BuildStatuses(_sequence, _isAnalysing);
|
||||
public IReadOnlyList<CardStatus> Statuses => _match is { } match ? [.. BuildStatuses(_sequence, _isAnalysing), match] : BuildStatuses(_sequence, _isAnalysing);
|
||||
|
||||
/// <summary>
|
||||
/// "Also elsewhere" or "Deleted there" (owner review 6, #73): the sequence is in a pair that asks for a choice; set by the
|
||||
/// Matches list after each reload. Null otherwise.
|
||||
/// </summary>
|
||||
public CardStatus? MatchStatus => _match;
|
||||
|
||||
/// <summary>The pair asking for a choice: the card's menu and the list row offer Compare….</summary>
|
||||
public bool HasMatch => _match is not null;
|
||||
|
||||
/// <summary>Takes the Matches list's status of this sequence (null: none).</summary>
|
||||
public void SetMatch(CardStatus? status)
|
||||
{
|
||||
if (Equals(_match, status)) return;
|
||||
_match = status;
|
||||
OnPropertyChanged(nameof(MatchStatus));
|
||||
OnPropertyChanged(nameof(HasMatch));
|
||||
RaiseStatuses();
|
||||
}
|
||||
|
||||
/// <summary>The single most relevant status for the list's State column.</summary>
|
||||
public CardStatus PrimaryStatus => Statuses.FirstOrDefault(s => s.Kind is StatusKind.Error or StatusKind.Warning or StatusKind.Analysing)
|
||||
|
||||
@@ -747,7 +747,7 @@ public sealed class ArchiveViewModel : SectionViewModel
|
||||
if (MaintenanceReports.MaintenanceKinds.Contains(job.Kind)) System.Windows.Application.Current?.Dispatcher.BeginInvoke(() => TrackRecent(job));
|
||||
if (job.State is not (JobState.Done or JobState.Failed)) return;
|
||||
if (job.Kind is not (JobKind.Scan or JobKind.Rebuild or JobKind.Verify or JobKind.Maintenance or JobKind.Import or JobKind.Proxies or JobKind.Thumbs
|
||||
or JobKind.LightAnalyse or JobKind.DeepAnalyse or JobKind.Move or JobKind.Convert)) return;
|
||||
or JobKind.LightAnalyse or JobKind.DeepAnalyse or JobKind.Move or JobKind.Convert or JobKind.Integrate or JobKind.MergeSequences)) return;
|
||||
System.Windows.Application.Current?.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
if (_archive is not { } archive || !job.TargetIds.Any(id => id == archive.Id || _sequenceIds.Contains(id))) return;
|
||||
|
||||
@@ -347,7 +347,7 @@ public sealed class JobsViewModel : SectionViewModel
|
||||
Title = Loc.L("Shell.Job.Done"),
|
||||
Message = JobText.Name(job),
|
||||
ActionText = Loc.L("Jobs.Action.Open"),
|
||||
ActionToolTip = Loc.L("Tooltips.Jobs.Open"),
|
||||
ActionToolTip = Loc.L(job.Kind is JobKind.Integrate or JobKind.MergeSequences ? "Tooltips.Jobs.OpenMatch" : "Tooltips.Jobs.Open"),
|
||||
ActionCommand = new AsyncRelayCommand(() => OpenTargetAsync(job)),
|
||||
RunsFromNotification = true,
|
||||
};
|
||||
@@ -507,6 +507,19 @@ public sealed class JobsViewModel : SectionViewModel
|
||||
{
|
||||
var db = Shell.Services.Database;
|
||||
if (db is null || job.TargetIds.Count == 0) return;
|
||||
// Owner review 6, #73: an Integrate shows its pair in Server › Matches; a merge opens the sequence it kept.
|
||||
if (job.Kind == JobKind.Integrate)
|
||||
{
|
||||
var title = await db.Sequences.GetAsync(job.TargetIds[0]) is { } local ? local.DisplayTitle : null;
|
||||
Shell.Navigate(SectionKey.Server);
|
||||
Shell.Server.Sync.ShowFilter(Chronos.App.Server.SyncFilter.FoundCopies, title);
|
||||
return;
|
||||
}
|
||||
if (job.Kind == JobKind.MergeSequences)
|
||||
{
|
||||
Shell.OpenSequence(job.TargetIds[0]);
|
||||
return;
|
||||
}
|
||||
var targets = job.TargetIds.Distinct().ToList();
|
||||
if (targets.Count > LibraryPager.DefaultPageSize)
|
||||
{
|
||||
|
||||
@@ -12,10 +12,22 @@
|
||||
<ResourceDictionary Source="pack://application:,,,/Chronos;component/Archive/ArchiveDialogs.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<!-- A double-click is read on the card or row itself: it takes the mouse-down to select, so a gesture on the list never sees it. -->
|
||||
<!-- A card of a sequence in a match that asks for a choice offers Compare… in its menu (owner review 6, #73). -->
|
||||
<ContextMenu x:Key="Menu.CardMatch" x:Shared="False">
|
||||
<MenuItem Header="{l:Loc Library.Action.Compare}" ToolTip="{l:Loc Tooltips.Library.Compare}"
|
||||
Command="{Binding PlacementTarget.Tag.CompareItemCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
|
||||
CommandParameter="{Binding}" />
|
||||
</ContextMenu>
|
||||
<Style x:Key="ListBoxItem.LibraryCard" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Card}">
|
||||
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
|
||||
<Setter Property="AutomationProperties.Name" Value="{Binding Title}" />
|
||||
<Setter Property="Tag" Value="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBox}}" />
|
||||
<EventSetter Event="MouseDoubleClick" Handler="OnItemDoubleClick" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding HasMatch}" Value="True">
|
||||
<Setter Property="ContextMenu" Value="{StaticResource Menu.CardMatch}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="ListBoxItem.LibraryRow" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
|
||||
<Setter Property="Height" Value="38" />
|
||||
@@ -296,6 +308,11 @@
|
||||
ItemsPanel="{StaticResource Panel.Row}" VerticalAlignment="Center" Focusable="False" ClipToBounds="True" />
|
||||
<Border Grid.Column="7" HorizontalAlignment="Right" Background="{DynamicResource Brush.Card}" Padding="6,0,0,0" Style="{StaticResource Border.RowActions}">
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<!-- A sequence in a match that asks for a choice: Compare… (owner review 6, #73). -->
|
||||
<Button Style="{StaticResource Button.Row}" Content="{l:Loc Library.Action.Compare}" FontSize="12" Margin="0,0,6,0"
|
||||
Command="{Binding DataContext.CompareItemCommand, RelativeSource={RelativeSource AncestorType=ListBox}}" CommandParameter="{Binding}"
|
||||
ToolTip="{l:Loc Tooltips.Library.Compare}" AutomationProperties.Name="{l:Loc Library.Action.Compare}"
|
||||
Visibility="{Binding HasMatch, Converter={StaticResource BoolToVisibility}}" />
|
||||
<Button Style="{StaticResource Button.RowQuick}" ui:ButtonIcon.Glyph="{StaticResource Icon.Sequence}"
|
||||
Command="{Binding DataContext.OpenItemCommand, RelativeSource={RelativeSource AncestorType=ListBox}}" CommandParameter="{Binding}"
|
||||
ToolTip="{l:Loc Tooltips.Library.Open}" AutomationProperties.Name="{l:Loc Library.Action.Open}" />
|
||||
|
||||
@@ -148,6 +148,10 @@ public sealed class LibraryViewModel : SectionViewModel
|
||||
p => p is SequenceItem { CanRunQuick: true });
|
||||
RenderItemCommand = new AsyncRelayCommand((p, _) => p is SequenceItem item ? _actions.RenderAsync(item.Sequence) : Task.CompletedTask,
|
||||
p => p is SequenceItem { CanRunQuick: true });
|
||||
CompareItemCommand = new RelayCommand(p =>
|
||||
{
|
||||
if (p is SequenceItem item) CompareItem(item);
|
||||
}, p => p is SequenceItem { HasMatch: true });
|
||||
SyncItemCommand = new AsyncRelayCommand((p, _) => p is SequenceItem item ? SyncItemAsync(item) : Task.CompletedTask, p => p is SequenceItem { CanSync: true });
|
||||
|
||||
SaveViewCommand = new RelayCommand(() => OpenViewName(rename: false), () => _viewStore is not null);
|
||||
@@ -196,6 +200,16 @@ public sealed class LibraryViewModel : SectionViewModel
|
||||
public ICommand AnalyseItemCommand { get; }
|
||||
public ICommand RenderItemCommand { get; }
|
||||
public ICommand SyncItemCommand { get; }
|
||||
|
||||
/// <summary>Compare…: Server › Matches, searched for the sequence's title (owner review 6, #73).</summary>
|
||||
public ICommand CompareItemCommand { get; }
|
||||
|
||||
/// <summary>Opens Server › Matches with the pair of <paramref name="item"/> found by its title.</summary>
|
||||
internal void CompareItem(SequenceItem item)
|
||||
{
|
||||
Shell.Navigate(SectionKey.Server);
|
||||
Shell.Server.Sync.ShowFilter(Chronos.App.Server.SyncFilter.FoundCopies, item.Title);
|
||||
}
|
||||
public ICommand SaveViewCommand { get; }
|
||||
public ICommand RenameViewCommand { get; }
|
||||
public ICommand DeleteViewCommand { get; }
|
||||
@@ -1097,7 +1111,9 @@ public sealed class LibraryViewModel : SectionViewModel
|
||||
}
|
||||
// Downloads of proxies only fill the proxy cache, so the Library is read again for originals and exports only.
|
||||
// A conversion makes new sequences, or changes the formats and sizes of the converted ones.
|
||||
// An Integrate fills a sequence with the other side's photos; a merge moves one sequence into another (owner review 6, #73).
|
||||
if (job.Kind is JobKind.Scan or JobKind.Rebuild or JobKind.Import or JobKind.Adopt or JobKind.Move or JobKind.UploadCommit or JobKind.Convert
|
||||
or JobKind.Integrate or JobKind.MergeSequences
|
||||
|| SyncService.TransferKind(job) is SyncTransferKind.DownloadOriginals or SyncTransferKind.GetExports)
|
||||
await RefreshAsync();
|
||||
else if (job.Kind is JobKind.LightAnalyse or JobKind.DeepAnalyse)
|
||||
|
||||
@@ -103,7 +103,14 @@
|
||||
lib:ThumbnailLoading.Width="64" DataContext="{Binding Sequence}">
|
||||
<Image Source="{Binding Thumbnail}" Stretch="UniformToFill" />
|
||||
</Border>
|
||||
<TextBlock Grid.Column="1" Style="{StaticResource Text.Cell}" Text="{Binding Name}" Margin="12,0,0,0" FontWeight="SemiBold" ToolTip="{Binding Name}" />
|
||||
<!-- The same time-lapse has a project at the other home too: a muted Twin chip after the name (owner review 6, #73). -->
|
||||
<DockPanel Grid.Column="1" Margin="12,0,0,0" LastChildFill="True">
|
||||
<Border DockPanel.Dock="Right" CornerRadius="9" BorderBrush="{DynamicResource Brush.Stroke}" BorderThickness="1" Padding="7,0" Margin="8,0,0,0"
|
||||
VerticalAlignment="Center" ToolTip="{Binding TwinToolTip}" Visibility="{Binding HasTwin, Converter={StaticResource BoolToVisibility}}">
|
||||
<TextBlock Text="{l:Loc Editor.Picker.Twin}" FontSize="11" Foreground="{DynamicResource Brush.TextMuted}" />
|
||||
</Border>
|
||||
<TextBlock Style="{StaticResource Text.Cell}" Text="{Binding Name}" FontWeight="SemiBold" ToolTip="{Binding Name}" />
|
||||
</DockPanel>
|
||||
<TextBlock Grid.Column="2" Style="{StaticResource Text.Cell}" Text="{Binding SequenceTitle}" Margin="12,0,0,0" Foreground="{DynamicResource Brush.TextMuted}"
|
||||
ToolTip="{Binding SequenceTitle}" />
|
||||
<ui:StatusGlyph Grid.Column="3" Kind="{Binding StateKind}" Text="{Binding StateText}" ToolTip="{Binding StateToolTip}" Margin="12,0,8,0" VerticalAlignment="Center" />
|
||||
|
||||
@@ -319,12 +319,40 @@ public sealed class SequencePickerViewModel : LocalizedViewModel
|
||||
if (generation != _generation) return;
|
||||
WorkspaceItems.Clear();
|
||||
foreach (var item in items) WorkspaceItems.Add(item);
|
||||
_ = MarkTwinsAsync(items);
|
||||
SelectedProject = WorkspaceItems.FirstOrDefault(i => i.ProjectId == _section.OpenProjectId) ?? WorkspaceItems.FirstOrDefault();
|
||||
OnPropertyChanged(nameof(HasWorkspaceItems));
|
||||
RaiseStates();
|
||||
_workspaceStates = ReadStatesAsync(items, generation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks the projects whose time-lapse (a linked or integrated match) has a workspace project at the other home too
|
||||
/// (owner review 6, #73): a muted Twin chip, "Also at {home}: {project}".
|
||||
/// </summary>
|
||||
private async Task MarkTwinsAsync(IReadOnlyList<WorkspaceProjectItem> items)
|
||||
{
|
||||
if (Shell.Services.Sync.Copies is not { } copies || items.Count == 0) return;
|
||||
try
|
||||
{
|
||||
var twins = await copies.TwinsAsync(CancellationToken.None);
|
||||
foreach (var item in items)
|
||||
{
|
||||
var twin = item.Entry.IsServerHome
|
||||
? twins.FirstOrDefault(t => t.RemoteId == item.SequenceId && t.LocalProject is not null)
|
||||
: twins.FirstOrDefault(t => t.LocalId == item.SequenceId && t.ServerProject is not null);
|
||||
if (twin is null) continue;
|
||||
var server = string.Equals(twin.Server, Shell.Services.Sync.Server, StringComparison.OrdinalIgnoreCase)
|
||||
? Shell.Services.Server.Flow.Info?.Name ?? twin.Server : twin.Server;
|
||||
if (item.Entry.IsServerHome) item.SetTwin(twin.LocalHome, twin.LocalProject);
|
||||
else item.SetTwin(server, twin.ServerProject);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidOperationException or DatabaseException)
|
||||
{
|
||||
Log.Warning("workspace", "The twins of the workspace projects could not be read", ex);
|
||||
}
|
||||
}
|
||||
/// <summary>Each listed project's state, asked of its home one after the other (a home may make a read wait a few seconds).</summary>
|
||||
private async Task ReadStatesAsync(IReadOnlyList<WorkspaceProjectItem> items, int generation)
|
||||
{
|
||||
|
||||
@@ -6,8 +6,14 @@
|
||||
xmlns:infra="clr-namespace:Chronos.App.Infrastructure"
|
||||
xmlns:shell="clr-namespace:Chronos.App.Shell"
|
||||
xmlns:srv="clr-namespace:Chronos.App.Server"
|
||||
xmlns:cp="clr-namespace:Chronos.App.Server.Copies"
|
||||
xmlns:sec="clr-namespace:Chronos.App.Sections">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Chronos;component/Archive/ArchiveDialogs.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/Chronos;component/Server/Copies/CopyDialogs.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<Style x:Key="Text.RowLabel" TargetType="TextBlock" BasedOn="{StaticResource Text.Label}">
|
||||
<Setter Property="MinWidth" Value="60" />
|
||||
<Setter Property="Margin" Value="0,0,10,0" />
|
||||
@@ -41,11 +47,13 @@
|
||||
<Setter Property="AutomationProperties.Name" Value="{Binding Title}" />
|
||||
<Setter Property="AutomationProperties.ItemStatus" Value="{Binding StateText}" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
|
||||
<!-- Server.html: this PC's shared library, the connection panel, the server's jobs while any run or wait paused, then the sync
|
||||
table. The render-node status panel is not built (see the decisions). -->
|
||||
<Grid Margin="20,16,20,12">
|
||||
<Grid>
|
||||
<Grid x:Name="Body" Margin="20,16,20,12" IsEnabled="{Binding IsContentEnabled}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -267,11 +275,12 @@
|
||||
<WrapPanel VerticalAlignment="Center">
|
||||
<TextBlock Text="{l:Loc Server.Sync.Title}" FontWeight="SemiBold" VerticalAlignment="Center" Margin="0,4,10,4" />
|
||||
<ItemsControl ItemsSource="{Binding Chips}" ItemsPanel="{StaticResource Panel.Wrap}" Focusable="False" VerticalAlignment="Center"
|
||||
Visibility="{Binding IsActive, Converter={StaticResource BoolToVisibility}}">
|
||||
Visibility="{Binding ShowChips, Converter={StaticResource BoolToVisibility}}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type srv:SyncFilterChip}">
|
||||
<RadioButton x:Name="Chip" Style="{StaticResource RadioButton.Chip}" GroupName="SyncFilters" Content="{Binding Text}"
|
||||
IsChecked="{Binding IsSelected, Mode=OneWay}" Command="{Binding SelectCommand}" ToolTip="{Binding ToolTip}" Margin="0,1,10,1" />
|
||||
IsChecked="{Binding IsSelected, Mode=OneWay}" Command="{Binding SelectCommand}" ToolTip="{Binding ToolTip}" Margin="0,1,10,1"
|
||||
Visibility="{Binding IsVisible, Converter={StaticResource BoolToVisibility}}" />
|
||||
<DataTemplate.Triggers>
|
||||
<!-- Conflicts waiting are drawn in warning colours, unless the chip is the chosen one (then Accent, DESIGN §4). -->
|
||||
<MultiDataTrigger>
|
||||
@@ -289,9 +298,13 @@
|
||||
</WrapPanel>
|
||||
<TextBox Grid.Column="1" Width="200" Height="30" Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" ui:Field.Glyph="{StaticResource Icon.Search}"
|
||||
ui:Field.Placeholder="{l:Loc Server.Sync.Search}" ToolTip="{l:Loc Tooltips.Server.Sync.Search}" AutomationProperties.Name="{l:Loc Server.Sync.Search}"
|
||||
Margin="10,0,0,0" Visibility="{Binding IsActive, Converter={StaticResource BoolToVisibility}}" />
|
||||
Margin="10,0,0,0" Visibility="{Binding ShowSearch, Converter={StaticResource BoolToVisibility}}" />
|
||||
<Button Grid.Column="2" Content="{l:Loc Server.Sync.UploadAll}" Command="{Binding UploadAllCommand}" ToolTip="{Binding UploadAllToolTip}"
|
||||
ToolTipService.ShowOnDisabled="True" Height="30" Margin="10,0,0,0" />
|
||||
ToolTipService.ShowOnDisabled="True" Height="30" Margin="10,0,0,0"
|
||||
Visibility="{Binding IsMatches, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
|
||||
<!-- Matches: Find matches replaces Upload all local. -->
|
||||
<Button Grid.Column="2" Content="{l:Loc Server.Copies.Action.Find}" Command="{Binding Copies.FindCommand}" ToolTip="{Binding Copies.FindToolTip}"
|
||||
ToolTipService.ShowOnDisabled="True" Height="30" Margin="10,0,0,0" Visibility="{Binding IsMatches, Converter={StaticResource BoolToVisibility}}" />
|
||||
</Grid>
|
||||
|
||||
<!-- Header; the rows repeat its columns (Server.html: 1.6fr 150px 150px 150px 1.4fr with 10 px gaps). The actions column is at least wide enough for a row's three actions (Open with proxies, Download originals and an older server's disabled Open in workspace) on one line. The list always
|
||||
@@ -305,10 +318,17 @@
|
||||
<ColumnDefinition Width="160" />
|
||||
<ColumnDefinition Width="1.4*" MinWidth="400" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Style="{StaticResource Text.Header}" Text="{l:Loc Server.Sync.Column.Sequence}" />
|
||||
<TextBlock Grid.Column="1" Style="{StaticResource Text.Header}" Text="{l:Loc Server.Sync.Column.Local}" Margin="10,0,0,0" />
|
||||
<TextBlock Grid.Column="2" Style="{StaticResource Text.Header}" Text="{l:Loc Server.Sync.Column.Server}" Margin="10,0,0,0" />
|
||||
<TextBlock Visibility="{Binding IsMatches, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" Style="{StaticResource Text.Header}" Text="{l:Loc Server.Sync.Column.Sequence}" />
|
||||
<TextBlock Visibility="{Binding IsMatches, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" Grid.Column="1" Style="{StaticResource Text.Header}" Text="{l:Loc Server.Sync.Column.Local}" Margin="10,0,0,0" />
|
||||
<TextBlock Visibility="{Binding IsMatches, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" Grid.Column="2" Style="{StaticResource Text.Header}" Text="{l:Loc Server.Sync.Column.Server}" Margin="10,0,0,0" />
|
||||
<TextBlock Grid.Column="3" Style="{StaticResource Text.Header}" Text="{l:Loc Server.Sync.Column.State}" Margin="10,0,0,0" />
|
||||
<!-- Matches: Sequence · This side · Other side · State. -->
|
||||
<TextBlock Style="{StaticResource Text.Header}" Text="{l:Loc Server.Copies.Column.Sequence}"
|
||||
Visibility="{Binding IsMatches, Converter={StaticResource BoolToVisibility}}" />
|
||||
<TextBlock Grid.Column="1" Style="{StaticResource Text.Header}" Text="{l:Loc Server.Copies.Column.ThisSide}" Margin="10,0,0,0"
|
||||
Visibility="{Binding IsMatches, Converter={StaticResource BoolToVisibility}}" />
|
||||
<TextBlock Grid.Column="2" Style="{StaticResource Text.Header}" Text="{l:Loc Server.Copies.Column.OtherSide}" Margin="10,0,0,0"
|
||||
Visibility="{Binding IsMatches, Converter={StaticResource BoolToVisibility}}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
@@ -317,7 +337,7 @@
|
||||
<ListBox x:Name="SyncList" Grid.Row="2" ItemsSource="{Binding Rows}" ItemContainerStyle="{StaticResource ListBoxItem.Sync}"
|
||||
VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.ScrollUnit="Pixel"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible" KeyboardNavigation.TabNavigation="Continue"
|
||||
AutomationProperties.Name="{l:Loc Server.Sync.Title}" Visibility="{Binding HasRows, Converter={StaticResource BoolToVisibility}}">
|
||||
AutomationProperties.Name="{l:Loc Server.Sync.Title}" Visibility="{Binding ShowSyncList, Converter={StaticResource BoolToVisibility}}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type srv:SyncRow}">
|
||||
<Border x:Name="RowBorder" Background="Transparent" Padding="14,0">
|
||||
@@ -368,6 +388,52 @@
|
||||
</Grid>
|
||||
</ui:EmptyState>
|
||||
|
||||
<!-- Matches (owner review 6, #73): the pairs of this server and of this PC's archives, with the same row layout. -->
|
||||
<ListBox x:Name="CopyList" Grid.Row="2" ItemsSource="{Binding Copies.Rows}" ItemContainerStyle="{StaticResource ListBoxItem.Sync}"
|
||||
VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.ScrollUnit="Pixel"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible" KeyboardNavigation.TabNavigation="Continue"
|
||||
AutomationProperties.Name="{l:Loc Settings.Server.Copies}" Visibility="{Binding ShowCopyList, Converter={StaticResource BoolToVisibility}}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyRow}">
|
||||
<Border x:Name="RowBorder" Background="Transparent" Padding="14,0">
|
||||
<Grid MinHeight="40">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1.6*" MinWidth="140" />
|
||||
<ColumnDefinition Width="160" />
|
||||
<ColumnDefinition Width="160" />
|
||||
<ColumnDefinition Width="160" />
|
||||
<ColumnDefinition Width="1.4*" MinWidth="400" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Style="{StaticResource Text.Cell}" Text="{Binding Title}" ToolTip="{Binding TitleToolTip}" />
|
||||
<TextBlock Grid.Column="1" Style="{StaticResource Text.Cell}" Text="{Binding HereText}" ToolTip="{Binding HereText}" Margin="10,0,0,0" />
|
||||
<TextBlock Grid.Column="2" Style="{StaticResource Text.Cell}" Text="{Binding ThereText}" ToolTip="{Binding ThereText}" Margin="10,0,0,0" />
|
||||
<ui:StatusGlyph Grid.Column="3" Kind="{Binding StateKind}" Text="{Binding StateText}" ToolTip="{Binding StateToolTip}"
|
||||
FontSize="13" VerticalAlignment="Center" Margin="10,0,0,0"
|
||||
AutomationProperties.LiveSetting="Polite" infra:LiveRegion.Text="{Binding StateAnnouncement}" />
|
||||
<ItemsControl Grid.Column="4" ItemsSource="{Binding Actions}" ItemsPanel="{StaticResource Panel.Wrap}" Focusable="False" VerticalAlignment="Center" Margin="10,4,0,4">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyRowAction}">
|
||||
<Button Style="{StaticResource Button.Row}" Content="{Binding Text}" Command="{Binding Command}" ToolTip="{Binding ToolTip}"
|
||||
ToolTipService.ShowOnDisabled="True" AutomationProperties.Name="{Binding AccessibleName}" FontSize="12" Margin="0,2,6,2" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</Border>
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConflict}" Value="True">
|
||||
<Setter TargetName="RowBorder" Property="Background" Value="{DynamicResource Brush.WarningSubtle}" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<!-- No pair: one sentence and Find matches. -->
|
||||
<ui:EmptyState Grid.Row="2" Message="{Binding Copies.EmptyText}" Visibility="{Binding ShowCopyEmpty, Converter={StaticResource BoolToVisibility}}">
|
||||
<Button Content="{l:Loc Server.Copies.Action.Find}" Command="{Binding Copies.FindCommand}" ToolTip="{Binding Copies.FindToolTip}" ToolTipService.ShowOnDisabled="True" />
|
||||
</ui:EmptyState>
|
||||
|
||||
<!-- Footer: last comparison · server archive · retry state (announced) · admin panel for administrators. -->
|
||||
<Border Grid.Row="3" BorderBrush="{DynamicResource Brush.Stroke}" BorderThickness="0,1,0,0" Padding="14,8">
|
||||
<DockPanel LastChildFill="False" TextElement.FontSize="12">
|
||||
@@ -387,4 +453,12 @@
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<!-- The Compare dialog (and Delete…) over the section; Tab stays inside it (ArchiveView's scrim host). -->
|
||||
<Grid Visibility="{Binding IsDialogOpen, Converter={StaticResource BoolToVisibility}}" KeyboardNavigation.TabNavigation="Cycle"
|
||||
KeyboardNavigation.ControlTabNavigation="Cycle" KeyboardNavigation.DirectionalNavigation="Contained">
|
||||
<Border Background="{DynamicResource Brush.Scrim}" />
|
||||
<ContentPresenter x:Name="DialogHost" Content="{Binding Dialog}" Margin="20" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,12 +1,22 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Chronos.App.Sections;
|
||||
|
||||
public partial class ServerView : UserControl
|
||||
{
|
||||
public ServerView() => InitializeComponent();
|
||||
private IInputElement? _beforeDialog;
|
||||
|
||||
public ServerView()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
}
|
||||
|
||||
/// <summary>The ▾ button opens the list of servers found on the LAN under itself.</summary>
|
||||
private void OnShowKnown(object sender, RoutedEventArgs e)
|
||||
@@ -17,4 +27,34 @@ public partial class ServerView : UserControl
|
||||
menu.Placement = PlacementMode.Bottom;
|
||||
menu.IsOpen = true;
|
||||
}
|
||||
|
||||
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.OldValue is ServerViewModel old) old.PropertyChanged -= OnModelChanged;
|
||||
if (e.NewValue is ServerViewModel model) model.PropertyChanged += OnModelChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A dialog that opens (Compare sequences) takes the keyboard; when it closes, the keyboard goes back to the control that
|
||||
/// opened it, or to the first control of the section when that one can no longer take it.
|
||||
/// </summary>
|
||||
private void OnModelChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName != nameof(ServerViewModel.Dialog) || sender is not ServerViewModel model) return;
|
||||
if (model.Dialog is not null)
|
||||
{
|
||||
if (!IsVisible) return;
|
||||
_beforeDialog ??= Keyboard.FocusedElement is Visual focused && IsAncestorOf(focused) ? Keyboard.FocusedElement : null;
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Input, () => DialogHost.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)));
|
||||
return;
|
||||
}
|
||||
var back = _beforeDialog;
|
||||
_beforeDialog = null;
|
||||
if (!IsVisible) return;
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Input, () =>
|
||||
{
|
||||
if (back is UIElement { IsVisible: true, IsEnabled: true, Focusable: true } element && element.Focus()) return;
|
||||
Body.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Archiving;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Server;
|
||||
using Chronos.App.Settings;
|
||||
@@ -16,7 +17,7 @@ namespace Chronos.App.Sections;
|
||||
/// status (name, version, latency, certificate), account and quota, sign out, the options of this PC (render node,
|
||||
/// proxies kept offline, automatic project sync, uploads paused on metered networks), the server's running and paused jobs
|
||||
/// (<see cref="Jobs"/>) and the sync table (<see cref="Sync"/>).
|
||||
/// The rail badge counts the settings conflicts waiting for a choice.
|
||||
/// The rail badge counts the settings conflicts and the matches waiting for a choice; the Compare dialog shows over the section.
|
||||
/// </summary>
|
||||
public sealed class ServerViewModel : SectionViewModel
|
||||
{
|
||||
@@ -24,6 +25,10 @@ public sealed class ServerViewModel : SectionViewModel
|
||||
private string _address;
|
||||
private string? _errorText;
|
||||
private ServerSession? _session;
|
||||
private ArchiveDialogViewModel? _dialog;
|
||||
|
||||
/// <summary>Dialogs that show once the open one closes, oldest first.</summary>
|
||||
private readonly Queue<ArchiveDialogViewModel> _waiting = new();
|
||||
|
||||
public ServerViewModel(ShellViewModel shell)
|
||||
: base(SectionKey.Server, "Icon.Server")
|
||||
@@ -42,6 +47,9 @@ public sealed class ServerViewModel : SectionViewModel
|
||||
Sync = new SyncTableViewModel(shell);
|
||||
_conflicts = Sync.Chips.Single(c => c.Filter == SyncFilter.Conflicts);
|
||||
_conflicts.PropertyChanged += OnConflictsChanged;
|
||||
Sync.Copies.OpenDialog = OpenDialogWhenFree;
|
||||
Sync.Copies.CloseDialog = CloseDialog;
|
||||
Sync.Copies.Changed += UpdateBadge;
|
||||
Jobs = new ServerJobsViewModel(() => ServerJobsViewModel.AccountOf(Session), () => JobsConnection(Session), SynchronizationContext.Current,
|
||||
(title, message) => Shell.Notify(title, message, isError: true));
|
||||
SharePanel = new SharePanelViewModel(shell);
|
||||
@@ -61,6 +69,44 @@ public sealed class ServerViewModel : SectionViewModel
|
||||
|
||||
public ShellViewModel Shell { get; }
|
||||
|
||||
/// <summary>The section's in-window dialog (Compare sequences, Delete…); null when none is open.</summary>
|
||||
public ArchiveDialogViewModel? Dialog
|
||||
{
|
||||
get => _dialog;
|
||||
private set
|
||||
{
|
||||
if (!Set(ref _dialog, value)) return;
|
||||
OnPropertyChanged(nameof(IsDialogOpen));
|
||||
OnPropertyChanged(nameof(IsContentEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDialogOpen => _dialog is not null;
|
||||
|
||||
/// <summary>The section behind an open dialog takes neither clicks nor keyboard focus.</summary>
|
||||
public bool IsContentEnabled => _dialog is null;
|
||||
|
||||
/// <summary>Shows <paramref name="dialog"/> now when none is open, else once the open one (and those waiting before it) closed.</summary>
|
||||
internal void OpenDialogWhenFree(ArchiveDialogViewModel dialog)
|
||||
{
|
||||
if (_dialog is null) Dialog = dialog;
|
||||
else _waiting.Enqueue(dialog);
|
||||
}
|
||||
|
||||
/// <summary>Closes <paramref name="dialog"/> if it is the open one; the next one waiting shows (one closed meanwhile is skipped).</summary>
|
||||
internal void CloseDialog(ArchiveDialogViewModel dialog)
|
||||
{
|
||||
if (!ReferenceEquals(_dialog, dialog)) return;
|
||||
dialog.Dispose();
|
||||
Dialog = null;
|
||||
while (_waiting.TryDequeue(out var next))
|
||||
{
|
||||
if (next.IsClosed) continue;
|
||||
Dialog = next;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private ServerSession Session => _session ?? Shell.Services.Server;
|
||||
|
||||
public ICommand ConnectCommand { get; }
|
||||
@@ -233,6 +279,8 @@ public sealed class ServerViewModel : SectionViewModel
|
||||
public override void Dispose()
|
||||
{
|
||||
_conflicts.PropertyChanged -= OnConflictsChanged;
|
||||
Sync.Copies.Changed -= UpdateBadge;
|
||||
_dialog?.Dispose();
|
||||
if (_session is not null) _session.PropertyChanged -= OnSessionChanged;
|
||||
Shell.Settings.Encoders.CollectionChanged -= OnEncodersChanged;
|
||||
Sync.Dispose();
|
||||
@@ -249,9 +297,12 @@ public sealed class ServerViewModel : SectionViewModel
|
||||
|
||||
private void OnConflictsChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName is nameof(SyncFilterChip.Count) or "" or null) Badge = _conflicts.Count;
|
||||
if (e.PropertyName is nameof(SyncFilterChip.Count) or "" or null) UpdateBadge();
|
||||
}
|
||||
|
||||
/// <summary>The rail badge: conflicts plus pairs asking for a choice (design §8.1).</summary>
|
||||
private void UpdateBadge() => Badge = _conflicts.Count + Sync.Copies.AttentionCount;
|
||||
|
||||
private void SetSyncOption(bool value, bool current, Action<bool> store, [System.Runtime.CompilerServices.CallerMemberName] string? name = null)
|
||||
{
|
||||
if (value == current) return;
|
||||
|
||||
@@ -681,6 +681,36 @@
|
||||
shell:EditBehavior.Field="{Binding DefaultServer}" ToolTip="{Binding DefaultServer.ToolTip}" ui:Field.Placeholder="{l:Loc Server.AddressPlaceholder}"
|
||||
AutomationProperties.Name="{l:Loc Settings.Server.Default}" FlowDirection="LeftToRight" />
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Server.CopyLinking}">
|
||||
<ComboBox Width="170" HorizontalAlignment="Left" ItemsSource="{Binding CopyRows.LinkingOptions}" SelectedItem="{Binding CopyRows.Linking}" DisplayMemberPath="Label"
|
||||
ToolTip="{l:Loc Tooltips.Settings.CopyLinking}" AutomationProperties.Name="{l:Loc Settings.Server.CopyLinking}">
|
||||
<ComboBox.ItemContainerStyle>
|
||||
<Style TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
|
||||
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
|
||||
</Style>
|
||||
</ComboBox.ItemContainerStyle>
|
||||
</ComboBox>
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Server.CopyPhotos}">
|
||||
<ComboBox Width="170" HorizontalAlignment="Left" ItemsSource="{Binding CopyRows.PhotoOptions}" SelectedItem="{Binding CopyRows.PhotoPolicy}" DisplayMemberPath="Label"
|
||||
ToolTip="{l:Loc Tooltips.Settings.CopyPhotos}" AutomationProperties.Name="{l:Loc Settings.Server.CopyPhotos}">
|
||||
<ComboBox.ItemContainerStyle>
|
||||
<Style TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
|
||||
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
|
||||
</Style>
|
||||
</ComboBox.ItemContainerStyle>
|
||||
</ComboBox>
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Server.CopyProjects}">
|
||||
<ComboBox Width="170" HorizontalAlignment="Left" ItemsSource="{Binding CopyRows.ProjectOptions}" SelectedItem="{Binding CopyRows.ProjectsChoice}" DisplayMemberPath="Label"
|
||||
ToolTip="{l:Loc Tooltips.Settings.CopyProjects}" AutomationProperties.Name="{l:Loc Settings.Server.CopyProjects}">
|
||||
<ComboBox.ItemContainerStyle>
|
||||
<Style TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
|
||||
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
|
||||
</Style>
|
||||
</ComboBox.ItemContainerStyle>
|
||||
</ComboBox>
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Server.RenderNode}">
|
||||
<CheckBox Content="{l:Loc Settings.Server.OfferPc}" IsChecked="{Binding RenderNodeOptIn}" ToolTip="{l:Loc Tooltips.Server.RenderNode}" Margin="0,4,0,0" />
|
||||
</HeaderedContentControl>
|
||||
|
||||
@@ -92,7 +92,7 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
"Settings.Workspace.Sync", "Settings.Workspace.AfterSave", "Settings.Workspace.VersionOnRender", "Settings.Workspace.SaveBeforeRender",
|
||||
"Settings.Workspace.Kept", "Settings.Workspace.CleanAfter", "Settings.Workspace.OpenProject", "Settings.Workspace.Trash", "Settings.Workspace.Homes"]),
|
||||
new(SettingsPage.Server, ["Settings.Server.Share", "Settings.Server.ShareName", "Settings.Server.HttpsPort", "Settings.Server.HttpPort",
|
||||
"Settings.Server.PublicHttpsPort", "Settings.Server.PublicHttpPort", "Settings.Server.Discovery", "Settings.Server.ShareFolder", "Settings.Server.Default", "Settings.Server.RenderNode", "Settings.Server.Certificates", "Settings.Server.Known"]),
|
||||
"Settings.Server.PublicHttpsPort", "Settings.Server.PublicHttpPort", "Settings.Server.Discovery", "Settings.Server.ShareFolder", "Settings.Server.Default", "Settings.Server.CopyLinking", "Settings.Server.CopyPhotos", "Settings.Server.CopyProjects", "Settings.Server.RenderNode", "Settings.Server.Certificates", "Settings.Server.Known"]),
|
||||
new(SettingsPage.Updates, ["Settings.General.CheckOnStart", "Settings.Updates.Latest", "About.Update.Check", "About.Releases"]),
|
||||
new(SettingsPage.Advanced, ["Settings.Advanced.DataFolder", "Settings.Advanced.Logs", "Settings.Advanced.LogLevel", "Settings.Advanced.KeepLogs",
|
||||
"Settings.Advanced.FileSize", "Settings.Advanced.LogsTotal", "Settings.Advanced.Rotation", "Settings.Advanced.Diagnostics",
|
||||
@@ -180,6 +180,7 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
|
||||
// ---- Server › Sharing (owner review 5, #67); saving applies it to the share (AppServices.SaveSettings). ----
|
||||
ShareRows = new ShareSettingsRows(_s, Save, Shell.Services.Environment.ShareDirectory, Shell.Services.Environment.PcName);
|
||||
CopyRows = new CopySettingsRows(_s, Save);
|
||||
|
||||
// ---- Workspace ----
|
||||
WorkspaceRows = new WorkspaceSettingsRows(_s, Save, () => AppEnvironment.Shown(Shell.Services.Workspace.Root), OpenWorkspaceFolder, ChangeWorkspaceFolderAsync,
|
||||
@@ -838,6 +839,9 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
/// <summary>Settings › Server › Sharing: this PC's library shared to the LAN (owner review 5, #67).</summary>
|
||||
public ShareSettingsRows ShareRows { get; }
|
||||
|
||||
/// <summary>Settings › Server › Link matches, Integrate photos, Integrate projects (owner review 6, #73).</summary>
|
||||
public CopySettingsRows CopyRows { get; }
|
||||
|
||||
public ICommand OpenDataFolderCommand { get; }
|
||||
public ICommand OpenLogsCommand { get; }
|
||||
public ICommand ExportDiagnosticsCommand { get; }
|
||||
@@ -1278,7 +1282,7 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
JobKind.Render, JobKind.Import, JobKind.Download, JobKind.UploadCommit, JobKind.Scan, JobKind.Rebuild, JobKind.Verify, JobKind.LightAnalyse,
|
||||
JobKind.DeepAnalyse, JobKind.Thumbs, JobKind.Proxies, JobKind.Maintenance, JobKind.Duplicates, JobKind.Orphans, JobKind.Adopt, JobKind.Move,
|
||||
JobKind.Backup, JobKind.Cleanup, JobKind.EmptyTrash, JobKind.Convert, JobKind.WorkspaceCopy, JobKind.WorkspaceRender, JobKind.WorkspaceSend,
|
||||
JobKind.WorkspaceMove, JobKind.VideoCopy,
|
||||
JobKind.WorkspaceMove, JobKind.VideoCopy, JobKind.Integrate, JobKind.MergeSequences,
|
||||
];
|
||||
|
||||
/// <summary>Stores <paramref name="level"/> for <paramref name="kind"/>, keeping only the levels that differ from the defaults.</summary>
|
||||
@@ -1675,6 +1679,7 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
case SettingsPage.Server:
|
||||
_s.RenderNodeOptIn = defaults.RenderNodeOptIn;
|
||||
ShareRows.Reset();
|
||||
CopyRows.Reset();
|
||||
break;
|
||||
case SettingsPage.Updates:
|
||||
_s.CheckForUpdates = defaults.CheckForUpdates;
|
||||
@@ -1783,6 +1788,7 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
Logs.Refresh();
|
||||
WorkspaceRows.Refresh();
|
||||
ShareRows.Refresh();
|
||||
CopyRows.Refresh();
|
||||
UpdatePreview();
|
||||
LoadCertificates();
|
||||
OnAllPropertiesChanged();
|
||||
@@ -1902,6 +1908,7 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
foreach (var row in MissingExtensions) row.Refresh();
|
||||
Logs.Refresh();
|
||||
WorkspaceRows.Refresh();
|
||||
CopyRows.Refresh();
|
||||
ArchiveRoot.Refresh();
|
||||
FolderTemplate.Refresh();
|
||||
FileTemplate.Refresh();
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>
|
||||
/// A detail that differs (the Details part): its label, this PC's and the other side's value, and the side both take
|
||||
/// (nothing preselected: <see cref="ChoiceIndex"/> -1 until the user picks).
|
||||
/// </summary>
|
||||
public sealed class CopyDetailRow(DetailLine line, bool isMerge, Action changed) : ObservableObject
|
||||
{
|
||||
private int _choiceIndex = -1;
|
||||
|
||||
public DetailLine Line { get; } = line;
|
||||
public string Path => Line.Path;
|
||||
public string Label => SyncText.DetailLabel(Line.Path);
|
||||
public string HereText => Value(Line.Here);
|
||||
public string ThereText => Value(Line.There);
|
||||
public string HereToolTip => Line.Here ?? Loc.L("Server.Sync.None");
|
||||
public string ThereToolTip => Line.There ?? Loc.L("Server.Sync.None");
|
||||
|
||||
public string HereWord => Loc.L(isMerge ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.ThisPc");
|
||||
public string ThereWord => Loc.L(isMerge ? "Server.Copies.Detail.Other" : "Server.Copies.Detail.Server");
|
||||
|
||||
/// <summary>"Deflicker window: This PC/Server": the line's one tab stop.</summary>
|
||||
public string AccessibleName => Loc.L("Server.Copies.ControlFor", Label, HereWord + "/" + ThereWord);
|
||||
|
||||
public string ToolTip => Loc.L("Tooltips.Server.Copies.Detail");
|
||||
|
||||
/// <summary>0 this PC (or the kept one), 1 the other side, -1 not chosen.</summary>
|
||||
public int ChoiceIndex
|
||||
{
|
||||
get => _choiceIndex;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _choiceIndex, value)) return;
|
||||
OnPropertyChanged(nameof(Chosen));
|
||||
changed();
|
||||
}
|
||||
}
|
||||
|
||||
public CopySide? Chosen => _choiceIndex switch
|
||||
{
|
||||
0 => CopySide.ThisPc,
|
||||
1 => CopySide.Other,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
internal void SetQuietly(int index)
|
||||
{
|
||||
_choiceIndex = index;
|
||||
OnPropertyChanged(nameof(ChoiceIndex));
|
||||
OnPropertyChanged(nameof(Chosen));
|
||||
}
|
||||
|
||||
private static string Value(string? value) => string.IsNullOrWhiteSpace(value) ? Loc.L("Server.Sync.None")
|
||||
: value.Length <= 40 ? value : string.Concat(value.AsSpan(0, 39), "…");
|
||||
}
|
||||
@@ -0,0 +1,801 @@
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Archiving;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>The four parts of the Compare dialog, in the order of its SegmentedControl.</summary>
|
||||
public enum CopyDialogPart
|
||||
{
|
||||
Photos,
|
||||
Details,
|
||||
Projects,
|
||||
Plan,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compare sequences / Merge sequences (owner review 6, #73, design §8.2): both sides of a pair, photo by photo (classes and
|
||||
/// the photos of one, with per-photo choices under Choose each), detail by detail (nothing preselected), projects (copied
|
||||
/// across or left), and the plan the engine computes from those choices (debounced 300 ms) with its blocks and their one
|
||||
/// action. Two footer buttons: Cancel and Integrate (Merge); a destructive plan confirms first, then the job is queued
|
||||
/// and the dialog closes. UI thread.
|
||||
/// </summary>
|
||||
public sealed class CopyDialogViewModel : ArchiveDialogViewModel
|
||||
{
|
||||
/// <summary>How long a choice waits before the plan is computed again.</summary>
|
||||
internal static TimeSpan PlanDelay { get; set; } = TimeSpan.FromMilliseconds(300);
|
||||
|
||||
private readonly ShellViewModel _shell;
|
||||
private readonly ICopyEngine _engine;
|
||||
private readonly FoundCopyView _pair;
|
||||
private readonly CopyRights _rights;
|
||||
private readonly bool _integrate;
|
||||
private readonly PhotoClass? _startClass;
|
||||
private readonly Dictionary<string, PhotoChoice> _perPhoto = [];
|
||||
private readonly AsyncRelayCommand _apply;
|
||||
private readonly AsyncRelayCommand _linkOnly;
|
||||
private readonly AsyncRelayCommand _trash;
|
||||
private readonly AsyncRelayCommand _deleteThere;
|
||||
private CancellationTokenSource? _planning;
|
||||
private CopyReview? _review;
|
||||
private IntegratePlan? _plan;
|
||||
private MergePlan? _merge;
|
||||
private CopyDialogPart _part;
|
||||
private SettingsOption<CopyPhotoPolicy> _policy;
|
||||
private int _projectsIndex;
|
||||
private Guid? _keepId;
|
||||
private CopyClassRow? _class;
|
||||
private IReadOnlyList<CopyClassRow> _classes = [];
|
||||
private IReadOnlyList<CopyPhotoRow> _photos = [];
|
||||
private IReadOnlyList<CopyDetailRow> _details = [];
|
||||
private IReadOnlyList<CopyProjectRow> _hereProjects = [];
|
||||
private IReadOnlyList<CopyProjectRow> _thereProjects = [];
|
||||
private IReadOnlyList<CopyKeepOption> _keep = [];
|
||||
private IReadOnlyList<CopyPlanLine> _hereLines = [];
|
||||
private IReadOnlyList<CopyPlanLine> _thereLines = [];
|
||||
private IReadOnlyList<CopyBlockLine> _blocks = [];
|
||||
private bool _isPlanning;
|
||||
private bool _isLoaded;
|
||||
|
||||
public CopyDialogViewModel(ShellViewModel shell, ICopyEngine engine, FoundCopyView pair, CopyRights rights, CopyDialogPart part,
|
||||
PhotoClass? photos, bool integrate, Action<ArchiveDialogViewModel> close)
|
||||
: base(close)
|
||||
{
|
||||
_shell = shell;
|
||||
_engine = engine;
|
||||
_pair = pair;
|
||||
_rights = rights;
|
||||
_part = part;
|
||||
_startClass = photos;
|
||||
_integrate = integrate;
|
||||
Policies = PolicyOptions(IsMerge);
|
||||
var wanted = shell.Services.Settings.CopyPhotos;
|
||||
_policy = Policies.FirstOrDefault(o => o.Value == wanted) ?? Policies[0];
|
||||
_projectsIndex = !IsMerge && shell.Services.Settings.CopyProjects == CopyProjects.Leave ? 1 : 0;
|
||||
_apply = new AsyncRelayCommand(ApplyAsync, () => _isLoaded && !IsBusy && !_isPlanning && (_part != CopyDialogPart.Plan || CanApplyPlan));
|
||||
_linkOnly = new AsyncRelayCommand(LinkOnlyAsync, () => _isLoaded && !IsBusy && ShowLinkOnly);
|
||||
_trash = new AsyncRelayCommand(() => TrashHereAsync([.. _photos.Where(p => p.IsSelected).Select(p => p.Key)]),
|
||||
() => !IsBusy && _photos.Any(p => p.IsSelected));
|
||||
_deleteThere = new AsyncRelayCommand(() => TrashThereAsync([.. _photos.Where(p => p.IsSelected).Select(p => p.Key)]),
|
||||
() => !IsBusy && _photos.Any(p => p.IsSelected));
|
||||
BringAllCommand = new RelayCommand(() => SetAll(bring: true));
|
||||
BringNoneCommand = new RelayCommand(() => SetAll(bring: false));
|
||||
AllBothCommand = new RelayCommand(() => SetAll(bring: true, choice: PhotoChoice.KeepBoth));
|
||||
AllHereCommand = new RelayCommand(() => SetDetails(0));
|
||||
AllThereCommand = new RelayCommand(() => SetDetails(1));
|
||||
}
|
||||
|
||||
public FoundCopy Copy => _pair.Copy;
|
||||
public bool IsMerge => Copy.Kind == CopyKind.LocalLocal;
|
||||
|
||||
public string Heading => Loc.L(IsMerge ? "Server.Copies.Dialog.Merge" : "Server.Copies.Dialog.Compare");
|
||||
|
||||
/// <summary>"This PC · Lighthouse · 1,204 photos · 18.2 GB".</summary>
|
||||
public string HereText => Loc.L("Server.Copies.Where.ThisPc", CopyText.Facts(Here));
|
||||
|
||||
public string ThereText => IsMerge ? Loc.L("Server.Copies.Where.ThisPc", CopyText.Facts(There)) : CopyText.Facts(There);
|
||||
|
||||
private CopyFacts Here => _review?.Here ?? _pair.Here;
|
||||
private CopyFacts There => _review?.There ?? _pair.There;
|
||||
private string ServerName => _rights.ServerName ?? Copy.Server ?? There.Where;
|
||||
|
||||
public bool IsLoaded { get => _isLoaded; private set => Set(ref _isLoaded, value); }
|
||||
|
||||
public CopyReview? Review => _review;
|
||||
|
||||
// ---- Parts ----
|
||||
|
||||
public CopyDialogPart Part
|
||||
{
|
||||
get => _part;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _part, value)) return;
|
||||
OnPropertyChanged(nameof(PartIndex));
|
||||
OnPropertyChanged(nameof(IsPhotos));
|
||||
OnPropertyChanged(nameof(IsDetails));
|
||||
OnPropertyChanged(nameof(IsProjects));
|
||||
OnPropertyChanged(nameof(IsPlan));
|
||||
OnPropertyChanged(nameof(ApplyToolTip));
|
||||
if (value == CopyDialogPart.Plan) SchedulePlan(TimeSpan.Zero);
|
||||
_apply.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public int PartIndex
|
||||
{
|
||||
get => (int)_part;
|
||||
set
|
||||
{
|
||||
if (value is >= 0 and <= 3) Part = (CopyDialogPart)value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPhotos => _part == CopyDialogPart.Photos;
|
||||
public bool IsDetails => _part == CopyDialogPart.Details;
|
||||
public bool IsProjects => _part == CopyDialogPart.Projects;
|
||||
public bool IsPlan => _part == CopyDialogPart.Plan;
|
||||
|
||||
// ---- Photos ----
|
||||
|
||||
public IReadOnlyList<SettingsOption<CopyPhotoPolicy>> Policies { get; }
|
||||
|
||||
public SettingsOption<CopyPhotoPolicy> Policy
|
||||
{
|
||||
get => _policy;
|
||||
set
|
||||
{
|
||||
if (value is null || !Set(ref _policy, value)) return;
|
||||
OnPropertyChanged(nameof(PolicyToolTip));
|
||||
OnPropertyChanged(nameof(IsChoosing));
|
||||
BuildPhotos();
|
||||
Changed();
|
||||
}
|
||||
}
|
||||
|
||||
public string PolicyToolTip => string.Join(Environment.NewLine, Loc.L("Tooltips.Server.Copies.Policy"), _policy.ToolTip);
|
||||
|
||||
/// <summary>Choose each: the photo lists take ticks and version choices.</summary>
|
||||
public bool IsChoosing => _policy.Value == CopyPhotoPolicy.ChoosePerPhoto;
|
||||
|
||||
public IReadOnlyList<CopyClassRow> Classes { get => _classes; private set => Set(ref _classes, value); }
|
||||
|
||||
public CopyClassRow? SelectedClass
|
||||
{
|
||||
get => _class;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _class, value)) return;
|
||||
BuildPhotos();
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<CopyPhotoRow> Photos { get => _photos; private set => Set(ref _photos, value); }
|
||||
|
||||
public bool HasPhotos => _photos.Count > 0;
|
||||
|
||||
/// <summary>"No photos differ.": the selected class holds nothing (or the two sides hold the same photos).</summary>
|
||||
public string? PhotosEmptyText => HasPhotos ? null : Loc.L("Server.Copies.Class.None");
|
||||
|
||||
public bool CanBringAll => _photos.Any(p => p.CanBring);
|
||||
public bool CanKeepAllBoth => _photos.Any(p => p.CanChoose);
|
||||
public bool CanTrashHere => _class?.Class == PhotoClass.DeletedThere && _photos.Count > 0;
|
||||
public bool CanDeleteThere => !IsMerge && _class?.Class == PhotoClass.DeletedHere && _photos.Count > 0 && _review?.Can.DeleteThere == true;
|
||||
|
||||
public ICommand BringAllCommand { get; }
|
||||
public ICommand BringNoneCommand { get; }
|
||||
public ICommand AllBothCommand { get; }
|
||||
public ICommand TrashCommand => _trash;
|
||||
public ICommand DeleteThereCommand => _deleteThere;
|
||||
|
||||
// ---- Details ----
|
||||
|
||||
public IReadOnlyList<CopyDetailRow> Details { get => _details; private set => Set(ref _details, value); }
|
||||
public bool HasDetails => _details.Count > 0;
|
||||
public string? DetailsEmptyText => HasDetails ? null : Loc.L("Server.Copies.Detail.None");
|
||||
public int Unchosen => _details.Count(d => d.Chosen is null);
|
||||
public ICommand AllHereCommand { get; }
|
||||
public ICommand AllThereCommand { get; }
|
||||
public string AllHereText => Loc.L("Server.Copies.Detail.AllThisPc");
|
||||
public string AllThereText => Loc.L("Server.Copies.Detail.AllServer");
|
||||
|
||||
// ---- Projects ----
|
||||
|
||||
/// <summary>0 Copy across, 1 Leave them (a merge always copies: its other home goes to the trash).</summary>
|
||||
public int ProjectsIndex
|
||||
{
|
||||
get => _projectsIndex;
|
||||
set
|
||||
{
|
||||
if (IsMerge || value is < 0 or > 1 || !Set(ref _projectsIndex, value)) return;
|
||||
OnPropertyChanged(nameof(ProjectsToolTip));
|
||||
Changed();
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanChooseProjects => !IsMerge && _review?.Projects.ThereKeepsProjects != false;
|
||||
|
||||
public string ProjectsToolTip => IsMerge ? Loc.L("Tooltips.Server.Copies.Projects.MergeAlways")
|
||||
: Loc.L(_projectsIndex == 0 ? "Tooltips.Server.Copies.Projects.CopyAcross" : "Tooltips.Server.Copies.Projects.Leave");
|
||||
|
||||
public IReadOnlyList<CopyProjectRow> HereProjects { get => _hereProjects; private set => Set(ref _hereProjects, value); }
|
||||
public IReadOnlyList<CopyProjectRow> ThereProjects { get => _thereProjects; private set => Set(ref _thereProjects, value); }
|
||||
|
||||
/// <summary>"nas keeps no projects: they stay." or "No other projects."; null when there are projects to show.</summary>
|
||||
public string? ProjectsNote => _review is not { } review ? null
|
||||
: !review.Projects.ThereKeepsProjects ? Loc.L("Server.Copies.Projects.NoneThere", ServerName)
|
||||
: _hereProjects.Count + _thereProjects.Count == 0 ? Loc.L("Server.Copies.Projects.None")
|
||||
: null;
|
||||
|
||||
// ---- Plan ----
|
||||
|
||||
public IReadOnlyList<CopyKeepOption> KeepOptions { get => _keep; private set => Set(ref _keep, value); }
|
||||
public bool HasKeepOptions => _keep.Count > 0;
|
||||
public IReadOnlyList<CopyPlanLine> HereLines { get => _hereLines; private set => Set(ref _hereLines, value); }
|
||||
public IReadOnlyList<CopyPlanLine> ThereLines { get => _thereLines; private set => Set(ref _thereLines, value); }
|
||||
public IReadOnlyList<CopyBlockLine> Blocks { get => _blocks; private set => Set(ref _blocks, value); }
|
||||
|
||||
/// <summary>"On this PC", or for a merge "Into {kept}".</summary>
|
||||
public string HereHeading => IsMerge ? Loc.L("Server.Copies.Plan.Into", KeptFacts?.Where ?? Loc.L("Server.Copies.Plan.KeptCopy"))
|
||||
: Loc.L("Server.Copies.Plan.OnThisPc");
|
||||
|
||||
public string ThereHeading => IsMerge ? DroppedFacts?.Where ?? There.Where : Loc.L("Server.Copies.Plan.OnServer", ServerName);
|
||||
|
||||
public bool IsPlanning
|
||||
{
|
||||
get => _isPlanning;
|
||||
private set
|
||||
{
|
||||
if (!Set(ref _isPlanning, value)) return;
|
||||
OnPropertyChanged(nameof(PlanningText));
|
||||
_apply.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string? PlanningText => _isPlanning ? Loc.L("Server.Copies.Planning") : null;
|
||||
|
||||
public IntegratePlan? Plan => _plan;
|
||||
public MergePlan? MergePlan => _merge;
|
||||
|
||||
private bool CanApplyPlan => IsMerge ? _merge?.CanApply == true : _plan?.CanApply == true;
|
||||
|
||||
/// <summary>Link only: a pair with a server not linked yet; links the two without moving photos.</summary>
|
||||
public bool ShowLinkOnly => !IsMerge && Copy.State == CopyState.Candidate && _review?.Can.LinkOnly == true;
|
||||
|
||||
public ICommand LinkOnlyCommand => _linkOnly;
|
||||
public string LinkOnlyText => Loc.L("Server.Copies.Action.LinkOnly");
|
||||
public string LinkOnlyToolTip => Loc.L("Tooltips.Server.Copies.LinkOnly");
|
||||
|
||||
// ---- Footer ----
|
||||
|
||||
public ICommand ApplyCommand => _apply;
|
||||
public string ApplyText => Loc.L(IsMerge ? "Server.Copies.Action.Merge" : "Server.Copies.Action.IntegrateNow");
|
||||
|
||||
/// <summary>What Integrate (Merge) does, or the first reason it cannot.</summary>
|
||||
public string ApplyToolTip => _part == CopyDialogPart.Plan && _blocks.Count > 0 ? _blocks[0].Text
|
||||
: Loc.L(IsMerge ? "Tooltips.Server.Copies.Merge" : "Tooltips.Server.Copies.Integrate");
|
||||
|
||||
public string CancelToolTip => Loc.L("Tooltips.Server.Copies.Cancel");
|
||||
|
||||
/// <summary>Reads both sides, then opens on the part asked for (Integrate…: Details while any line is unchosen, else Plan).</summary>
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
IsLoaded = false;
|
||||
BusyText = Loc.L("Server.Copies.Planning");
|
||||
try
|
||||
{
|
||||
_review = await _engine.CompareAsync(Copy.Id, Copy.Kind == CopyKind.LocalServer ? _shell.Services.Sync.Remote : null, CancellationToken.None);
|
||||
if (IsClosed) return;
|
||||
Build(_review);
|
||||
IsLoaded = true;
|
||||
if (_integrate && _part == CopyDialogPart.Plan && Unchosen > 0) _part = CopyDialogPart.Details;
|
||||
OnAllPropertiesChanged();
|
||||
if (_part == CopyDialogPart.Plan) SchedulePlan(TimeSpan.Zero);
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
BusyText = null;
|
||||
_apply.RaiseCanExecuteChanged();
|
||||
_linkOnly.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Computes the plan of the current choices now (tests, captures).</summary>
|
||||
internal async Task PlanNowAsync()
|
||||
{
|
||||
_planning?.Cancel();
|
||||
await PlanAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_planning?.Cancel();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
protected override void OnLanguageChanged()
|
||||
{
|
||||
if (_review is { } review) Build(review);
|
||||
BuildPlanLines();
|
||||
base.OnLanguageChanged();
|
||||
}
|
||||
|
||||
private void Build(CopyReview review)
|
||||
{
|
||||
Classes = [.. review.Photos.Totals.Where(t => t.Count > 0).Select(t => new CopyClassRow(t))];
|
||||
_class = _classes.FirstOrDefault(c => c.Class == _startClass)
|
||||
?? _classes.FirstOrDefault(c => c.Class is not (PhotoClass.Same or PhotoClass.Converted))
|
||||
?? _classes.FirstOrDefault();
|
||||
BuildPhotos();
|
||||
var chosen = _details.ToDictionary(d => d.Path, d => d.ChoiceIndex);
|
||||
Details = [.. review.Details.Select(line => new CopyDetailRow(line, IsMerge, Changed))];
|
||||
foreach (var row in _details) row.SetQuietly(chosen.GetValueOrDefault(row.Path, -1));
|
||||
HereProjects = [.. review.Projects.Here.Select(p => new CopyProjectRow(p))];
|
||||
ThereProjects = [.. review.Projects.There.Select(p => new CopyProjectRow(p))];
|
||||
if (IsMerge)
|
||||
{
|
||||
KeepOptions = [new CopyKeepOption(Copy.LocalId, review.Here, Keep), new CopyKeepOption(Copy.OtherId ?? Guid.Empty, review.There, Keep)];
|
||||
foreach (var option in _keep) option.SetQuietly(option.SequenceId == _keepId);
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildPhotos()
|
||||
{
|
||||
var review = _review;
|
||||
var cls = _class?.Class;
|
||||
var choosing = IsChoosing;
|
||||
var choices = VersionChoices(IsMerge);
|
||||
Func<CopyPhotoRow, Task>? drop = cls == PhotoClass.Versions ? DropAsync : null;
|
||||
Photos = review is null || cls is null ? []
|
||||
: [.. review.Photos.Of(cls.Value).Select(p => new CopyPhotoRow(p, IsMerge,
|
||||
choosing && !IsMerge && cls is PhotoClass.OnlyHere or PhotoClass.OnlyThere,
|
||||
choosing && cls == PhotoClass.Differs, choices, _perPhoto.TryGetValue(p.Key, out var c) ? c : null, () => OnPhotoChanged(p.Key), drop))];
|
||||
foreach (var row in _photos) row.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName != nameof(CopyPhotoRow.IsSelected)) return;
|
||||
_trash.RaiseCanExecuteChanged();
|
||||
_deleteThere.RaiseCanExecuteChanged();
|
||||
};
|
||||
OnPropertyChanged(nameof(HasPhotos));
|
||||
OnPropertyChanged(nameof(PhotosEmptyText));
|
||||
OnPropertyChanged(nameof(CanBringAll));
|
||||
OnPropertyChanged(nameof(CanKeepAllBoth));
|
||||
OnPropertyChanged(nameof(CanTrashHere));
|
||||
OnPropertyChanged(nameof(CanDeleteThere));
|
||||
OnPropertyChanged(nameof(SelectedClass));
|
||||
}
|
||||
|
||||
private void OnPhotoChanged(string key)
|
||||
{
|
||||
if (_photos.FirstOrDefault(p => p.Key == key)?.Chosen is { } chosen) _perPhoto[key] = chosen;
|
||||
else _perPhoto.Remove(key);
|
||||
Changed();
|
||||
}
|
||||
|
||||
private void SetAll(bool bring, PhotoChoice? choice = null)
|
||||
{
|
||||
foreach (var row in _photos)
|
||||
{
|
||||
if (row.CanBring) row.SetQuietly(bring, null);
|
||||
else if (row.CanChoose && choice is { } c) row.SetQuietly(false, row.Choices.FirstOrDefault(o => o.Value == c));
|
||||
else continue;
|
||||
if (row.Chosen is { } chosen) _perPhoto[row.Key] = chosen;
|
||||
else _perPhoto.Remove(row.Key);
|
||||
}
|
||||
Changed();
|
||||
}
|
||||
|
||||
private void SetDetails(int index)
|
||||
{
|
||||
foreach (var row in _details) row.SetQuietly(index);
|
||||
Changed();
|
||||
}
|
||||
|
||||
private void Keep(CopyKeepOption option)
|
||||
{
|
||||
_keepId = option.SequenceId;
|
||||
foreach (var other in _keep.Where(o => !ReferenceEquals(o, option))) other.SetQuietly(false);
|
||||
OnPropertyChanged(nameof(HereHeading));
|
||||
OnPropertyChanged(nameof(ThereHeading));
|
||||
Changed();
|
||||
}
|
||||
|
||||
/// <summary>A choice changed: the plan follows once the user pauses.</summary>
|
||||
private void Changed()
|
||||
{
|
||||
OnPropertyChanged(nameof(Unchosen));
|
||||
if (_plan is not null || _merge is not null || _part == CopyDialogPart.Plan) SchedulePlan(PlanDelay);
|
||||
}
|
||||
|
||||
private void SchedulePlan(TimeSpan delay)
|
||||
{
|
||||
if (!_isLoaded) return;
|
||||
_planning?.Cancel();
|
||||
var run = _planning = new CancellationTokenSource();
|
||||
_ = Delayed();
|
||||
|
||||
async Task Delayed()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (delay > TimeSpan.Zero) await Task.Delay(delay, run.Token);
|
||||
await PlanAsync(run.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// A newer choice planned instead.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IntegrateChoices IntegrateChoices() => new(_policy.Value, IsChoosing ? new Dictionary<string, PhotoChoice>(_perPhoto) : new Dictionary<string, PhotoChoice>(),
|
||||
DetailChoices(), _projectsIndex == 0 ? CopyProjects.CopyAcross : CopyProjects.Leave);
|
||||
|
||||
private MergeChoices MergeChoices() => new(_policy.Value, IsChoosing ? new Dictionary<string, PhotoChoice>(_perPhoto) : new Dictionary<string, PhotoChoice>(),
|
||||
DetailChoices());
|
||||
|
||||
private Dictionary<string, CopySide> DetailChoices() =>
|
||||
_details.Where(d => d.Chosen is not null).ToDictionary(d => d.Path, d => d.Chosen!.Value, StringComparer.Ordinal);
|
||||
|
||||
private async Task PlanAsync(CancellationToken ct)
|
||||
{
|
||||
IsPlanning = true;
|
||||
ClearError();
|
||||
try
|
||||
{
|
||||
if (IsMerge)
|
||||
{
|
||||
var merge = await _engine.PlanMergeAsync(Copy.Id, _keepId, MergeChoices(), ct);
|
||||
ct.ThrowIfCancellationRequested();
|
||||
_merge = merge;
|
||||
if (_keepId is null && !merge.Blocks.Contains(CopyBlock.KeptUnchosen) && merge.KeepId != Guid.Empty)
|
||||
{
|
||||
_keepId = merge.KeepId;
|
||||
foreach (var option in _keep) option.SetQuietly(option.SequenceId == _keepId);
|
||||
}
|
||||
}
|
||||
else if (_shell.Services.Sync.Remote is { } remote && string.Equals(_shell.Services.Sync.Server, Copy.Server, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var plan = await _engine.PlanIntegrateAsync(Copy.Id, remote, IntegrateChoices(), ct);
|
||||
ct.ThrowIfCancellationRequested();
|
||||
_plan = plan;
|
||||
}
|
||||
else
|
||||
{
|
||||
_plan = null;
|
||||
ShowMessage(Loc.L("Tooltips.Server.Copies.SignIn", Copy.Server ?? string.Empty));
|
||||
}
|
||||
BuildPlanLines();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!ct.IsCancellationRequested) IsPlanning = false;
|
||||
}
|
||||
}
|
||||
|
||||
private CopyFacts? KeptFacts => _keepId is { } keep ? keep == Copy.LocalId ? Here : There : null;
|
||||
private CopyFacts? DroppedFacts => _keepId is { } keep ? keep == Copy.LocalId ? There : Here : null;
|
||||
|
||||
/// <summary>The lines of the Plan part, last copies first; the blocks with their one action.</summary>
|
||||
private void BuildPlanLines()
|
||||
{
|
||||
var here = new List<CopyPlanLine>();
|
||||
var there = new List<CopyPlanLine>();
|
||||
var blocks = new List<CopyBlockLine>();
|
||||
if (_plan is { } plan)
|
||||
{
|
||||
Lasts(plan.LastCopies, here, there);
|
||||
Photos(plan.Photos, PhotoAction.Fetch, PhotoAction.FetchVersion, "Server.Copies.Plan.Receives", here);
|
||||
Photos(plan.Photos, PhotoAction.Send, PhotoAction.SendVersion, "Server.Copies.Plan.Receives", there);
|
||||
Trash(plan.Photos, PhotoAction.TrashHere, here);
|
||||
Trash(plan.Photos, PhotoAction.TrashThere, there);
|
||||
var versions = plan.Photos.Count(p => p.Action == PhotoAction.SendVersion);
|
||||
if (versions > 0) there.Add(new(Loc.Plural("Server.Copies.Plan.ServerUsesOurs", versions, ServerName), Loc.L("Tooltips.Server.Copies.Plan.ServerUsesOurs")));
|
||||
if (plan.DetailChanges > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Details", plan.DetailChanges)));
|
||||
var fromHere = plan.Projects.Count(p => p.From == CopySide.ThisPc);
|
||||
var fromThere = plan.Projects.Count - fromHere;
|
||||
if (fromThere > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Projects", fromThere)));
|
||||
if (fromHere > 0) there.Add(new(Loc.Plural("Server.Copies.Plan.Projects", fromHere)));
|
||||
here.Add(new(Loc.L("Server.Copies.Plan.Free", Formatting.Bytes(plan.FreeBytes)), Loc.L("Tooltips.Server.Copies.Plan.Free")));
|
||||
if (plan.QuotaLeftBytes is { } quota) there.Add(new(Loc.L("Server.Copies.Plan.Quota", Formatting.Bytes(quota)), Loc.L("Tooltips.Server.Copies.Plan.Quota")));
|
||||
if (plan.LeftOut > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.LeftOut", plan.LeftOut), Loc.L("Tooltips.Server.Copies.Plan.LeftOut")));
|
||||
foreach (var row in _hereProjects.Concat(_thereProjects))
|
||||
row.SetTarget(plan.Projects.FirstOrDefault(p => p.SourceProjectId == row.Project.Id)?.TargetName);
|
||||
blocks.AddRange(plan.Blocks.Select(Block));
|
||||
}
|
||||
else if (_merge is { } merge)
|
||||
{
|
||||
Lasts(merge.LastCopies, here, there);
|
||||
Photos(merge.Photos, PhotoAction.Fetch, PhotoAction.FetchVersion, "Server.Copies.Plan.Receives", here);
|
||||
if (merge.DetailChanges > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Details", merge.DetailChanges)));
|
||||
if (merge.Renders.Count > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Renders", merge.Renders.Count)));
|
||||
if (merge.Projects.Count > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Projects", merge.Projects.Count)));
|
||||
if (merge.SessionKeys.Count > 0)
|
||||
here.Add(new(Loc.L("Server.Copies.Plan.SessionKeys", Formatting.Count(merge.SessionKeys.Count)),
|
||||
string.Join(Environment.NewLine, [Loc.L("Tooltips.Server.Copies.Plan.SessionKeys"), .. merge.SkippedSessionKeys])));
|
||||
foreach (var link in merge.Links) here.Add(new(Loc.L("Server.Copies.Plan.Relink", link), Loc.L("Tooltips.Server.Copies.Plan.Relink")));
|
||||
here.Add(new(Loc.L("Server.Copies.Plan.Free", Formatting.Bytes(merge.FreeBytes)), Loc.L("Tooltips.Server.Copies.Plan.Free")));
|
||||
if (DroppedFacts is { } dropped)
|
||||
there.Add(new(Loc.Plural("Server.Copies.Plan.DropToTrash", dropped.Photos, Formatting.Bytes(dropped.Bytes)), IsWarning: true));
|
||||
blocks.AddRange(merge.Blocks.Select(Block));
|
||||
}
|
||||
if (here.Count + there.Count == 0 && blocks.Count == 0 && (_plan ?? (object?)_merge) is not null) here.Add(new(Loc.L("Server.Copies.Plan.Nothing")));
|
||||
HereLines = here;
|
||||
ThereLines = there;
|
||||
Blocks = blocks;
|
||||
OnPropertyChanged(nameof(HereHeading));
|
||||
OnPropertyChanged(nameof(ThereHeading));
|
||||
OnPropertyChanged(nameof(ApplyToolTip));
|
||||
_apply.RaiseCanExecuteChanged();
|
||||
|
||||
void Lasts(IReadOnlyList<LastCopy> lasts, List<CopyPlanLine> h, List<CopyPlanLine> t)
|
||||
{
|
||||
var mine = lasts.Count(l => l.Side == CopySide.ThisPc);
|
||||
var theirs = lasts.Count - mine;
|
||||
if (mine > 0) h.Add(new(Loc.Plural("Server.Copies.Plan.LastCopies", mine), Loc.L("Tooltips.Server.Copies.Plan.LastCopies"), true));
|
||||
if (theirs > 0) t.Add(new(Loc.Plural("Server.Copies.Plan.LastCopies", theirs), Loc.L("Tooltips.Server.Copies.Plan.LastCopies"), true));
|
||||
}
|
||||
|
||||
static void Photos(IReadOnlyList<PhotoStep> steps, PhotoAction a, PhotoAction b, string key, List<CopyPlanLine> lines)
|
||||
{
|
||||
var moving = steps.Where(s => s.Action == a || s.Action == b).ToList();
|
||||
if (moving.Count > 0) lines.Add(new(Loc.Plural(key, moving.Count, Formatting.Bytes(moving.Sum(s => s.Bytes)))));
|
||||
var kept = steps.Count(s => s.Action == b);
|
||||
if (kept > 0) lines.Add(new(Loc.Plural("Server.Copies.Plan.Versions", kept)));
|
||||
}
|
||||
|
||||
static void Trash(IReadOnlyList<PhotoStep> steps, PhotoAction a, List<CopyPlanLine> lines)
|
||||
{
|
||||
var n = steps.Count(s => s.Action == a);
|
||||
if (n > 0) lines.Add(new(Loc.Plural("Server.Copies.Plan.Trash", n), IsWarning: true));
|
||||
}
|
||||
}
|
||||
|
||||
private CopyBlockLine Block(CopyBlock block)
|
||||
{
|
||||
var need = _plan is { } plan ? Formatting.Bytes(plan.FetchBytes) : _merge is { } merge ? Formatting.Bytes(merge.CopyBytes) : null;
|
||||
var text = CopyText.Block(block, Here.Title, ServerName, need, Unchosen);
|
||||
Action? choose = block switch
|
||||
{
|
||||
CopyBlock.DetailsUnchosen => () => Part = CopyDialogPart.Details,
|
||||
CopyBlock.KeptUnchosen => () => Part = CopyDialogPart.Plan,
|
||||
_ => null,
|
||||
};
|
||||
return new CopyBlockLine(block, text, choose);
|
||||
}
|
||||
|
||||
/// <summary>Integrate (Merge): from another part, on to the part still waiting for a choice; on the plan, confirm and queue.</summary>
|
||||
private async Task ApplyAsync()
|
||||
{
|
||||
if (_part != CopyDialogPart.Plan)
|
||||
{
|
||||
Part = Unchosen > 0 && _part != CopyDialogPart.Details ? CopyDialogPart.Details : CopyDialogPart.Plan;
|
||||
return;
|
||||
}
|
||||
if (_shell.Services.Engine is not { } jobs) return;
|
||||
try
|
||||
{
|
||||
if (_plan is { CanApply: true } plan)
|
||||
{
|
||||
if (plan.Destructive && !_shell.Services.Dialogs.Confirm(ReplaceRequest(plan))) return;
|
||||
IsBusy = true;
|
||||
await _engine.EnqueueIntegrateAsync(jobs, plan, CancellationToken.None);
|
||||
}
|
||||
else if (_merge is { CanApply: true } merge)
|
||||
{
|
||||
if (!_shell.Services.Dialogs.Confirm(MergeRequest(merge))) return;
|
||||
IsBusy = true;
|
||||
await _engine.EnqueueMergeAsync(jobs, merge, CancellationToken.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
Close();
|
||||
}
|
||||
catch (StaleCopyPlanException ex)
|
||||
{
|
||||
ShowMessage(ex.Message);
|
||||
SchedulePlan(TimeSpan.Zero);
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LinkOnlyAsync()
|
||||
{
|
||||
if (_shell.Services.Sync.Remote is not { } remote) return;
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
await _engine.LinkAsync(Copy.Id, remote, CancellationToken.None);
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Drop…: this version of a Two versions photo goes to the trash of each side that holds it, after a confirmed plan.</summary>
|
||||
private async Task DropAsync(CopyPhotoRow row)
|
||||
{
|
||||
if (row.Photo.Here is not null) await TrashHereAsync([row.Key]);
|
||||
if (row.Photo.There is not null && !IsMerge) await TrashThereAsync([row.Key]);
|
||||
}
|
||||
|
||||
/// <summary>To trash…: the dry run of moving these photos of this PC's copy to its archive trash, the confirmation, then the move.</summary>
|
||||
private async Task TrashHereAsync(IReadOnlyCollection<string> keys)
|
||||
{
|
||||
if (keys.Count == 0) return;
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
var plan = await _engine.PlanTrashHereAsync(Copy.Id, keys, CancellationToken.None);
|
||||
if (plan.Frames.Count == 0)
|
||||
{
|
||||
ShowMessage(Loc.L("Errors.Copies.NotThere"));
|
||||
return;
|
||||
}
|
||||
var request = TrashRequest(plan.Frames.Count, plan.Frames.Select(f => f.FileName), Loc.L("Tooltips.Server.Copies.ToTrash"), []);
|
||||
if (!_shell.Services.Dialogs.Confirm(request)) return;
|
||||
await _engine.TrashHereAsync(Copy.Id, plan, Copy.Kind == CopyKind.LocalServer ? _shell.Services.Sync.Remote : null, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
/// <summary>Delete on server…: the server's dry run, the confirmation, then the move to the server's trash.</summary>
|
||||
private async Task TrashThereAsync(IReadOnlyCollection<string> keys)
|
||||
{
|
||||
if (keys.Count == 0 || _shell.Services.Sync.Remote is not { } remote) return;
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
var plan = await _engine.PlanTrashThereAsync(Copy.Id, remote, keys, CancellationToken.None);
|
||||
if (plan.Photos == 0)
|
||||
{
|
||||
ShowMessage(Loc.L("Errors.Copies.NotThere"));
|
||||
return;
|
||||
}
|
||||
var names = _review?.Photos.Photos.Where(p => plan.Keys.Contains(p.Key)).Select(p => (p.There ?? p.Here)?.FileName ?? p.Key) ?? plan.Keys;
|
||||
var request = TrashRequest(plan.Photos, names, Loc.L("Tooltips.Server.Copies.DeleteOnServer"), plan.LastCopies);
|
||||
if (!_shell.Services.Dialogs.Confirm(request)) return;
|
||||
await _engine.TrashThereAsync(plan, remote, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex) when (Expected(ex))
|
||||
{
|
||||
ShowError(ex);
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
/// <summary>"Replace photos?" (design §8.5): the losing versions per side, the last copies named first.</summary>
|
||||
internal static ConfirmRequest ReplaceRequest(IntegratePlan plan)
|
||||
{
|
||||
var trashed = plan.Photos.Where(p => p.Action is PhotoAction.TrashHere or PhotoAction.TrashThere).ToList();
|
||||
return new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.L("Server.Copies.Confirm.Replace.Title"),
|
||||
Message = Loc.Plural("Server.Copies.Confirm.Replace.Message", trashed.Count),
|
||||
Detail = Lines(plan.LastCopies, trashed.Select(p => p.FileName)),
|
||||
SafeText = Loc.L("Archive.Dialog.Cancel"),
|
||||
SafeToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Safe"),
|
||||
ActionText = Loc.L("Server.Copies.Action.IntegrateNow"),
|
||||
ActionToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Replace.Action"),
|
||||
IsDestructive = true,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>"Merge sequences?" (design §8.5): the dropped sequence's facts, the last copies first, the typed photo count.</summary>
|
||||
internal ConfirmRequest MergeRequest(MergePlan plan)
|
||||
{
|
||||
var keep = plan.KeepId == Copy.LocalId ? Here : There;
|
||||
var drop = plan.KeepId == Copy.LocalId ? There : Here;
|
||||
var only = _review?.Photos.Of(plan.KeepId == Copy.LocalId ? PhotoClass.OnlyThere : PhotoClass.OnlyHere).Count() ?? 0;
|
||||
var facts = new List<string> { Loc.Plural("Server.Copies.Plan.DropToTrash", drop.Photos, Formatting.Bytes(drop.Bytes)) };
|
||||
if (only > 0) facts.Add(Loc.Plural("Server.Copies.Confirm.Merge.OnlyHere", only, drop.Where));
|
||||
if (plan.Renders.Count > 0) facts.Add(Loc.Plural("Server.Copies.Plan.Renders", plan.Renders.Count));
|
||||
if (plan.Projects.Count > 0) facts.Add(Loc.Plural("Server.Copies.Plan.Projects", plan.Projects.Count));
|
||||
return new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.L("Server.Copies.Confirm.Merge.Title"),
|
||||
Message = Loc.L("Server.Copies.Confirm.Merge.Message", drop.Title, drop.Where, keep.Where),
|
||||
Detail = Lines(plan.LastCopies, facts),
|
||||
SafeText = Loc.L("Archive.Dialog.Cancel"),
|
||||
SafeToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Safe"),
|
||||
ActionText = Loc.L("Server.Copies.Action.Merge"),
|
||||
ActionToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Merge.Action"),
|
||||
IsDestructive = true,
|
||||
TypedConfirmation = drop.Photos.ToString(Loc.Culture),
|
||||
TypedPrompt = Loc.L("Server.Copies.Confirm.Merge.TypedPrompt", drop.Title),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>To trash… and Delete on server…: as the Library's delete confirmation, with the last copies named first.</summary>
|
||||
private static ConfirmRequest TrashRequest(int photos, IEnumerable<string> names, string message, IReadOnlyList<LastCopy> lasts) => new()
|
||||
{
|
||||
Heading = Loc.Plural("Server.Copies.Plan.Trash", photos),
|
||||
Message = message,
|
||||
Detail = Lines(lasts, names),
|
||||
DetailToolTip = Loc.L("Tooltips.Archive.DeletePlan"),
|
||||
SafeText = Loc.L("Archive.Delete.Keep"),
|
||||
SafeToolTip = Loc.L("Tooltips.Archive.DeleteKeep"),
|
||||
ActionText = Loc.L("Archive.Delete.Action"),
|
||||
ActionToolTip = message,
|
||||
IsDestructive = true,
|
||||
};
|
||||
|
||||
private static string Lines(IReadOnlyList<LastCopy> lasts, IEnumerable<string> rest)
|
||||
{
|
||||
const int Listed = 10;
|
||||
var all = lasts.Select(l => Loc.L("Server.Copies.Confirm.LastCopy", l.FileName)).Concat(rest).ToList();
|
||||
var lines = all.Take(Listed).ToList();
|
||||
if (all.Count > Listed) lines.Add(Loc.Plural("Archive.Delete.More", all.Count - Listed));
|
||||
return string.Join(Environment.NewLine, lines);
|
||||
}
|
||||
|
||||
/// <summary>The policies of the Photos ComboBox: a merge's two "wins" name the kept and the other sequence.</summary>
|
||||
internal static IReadOnlyList<SettingsOption<CopyPhotoPolicy>> PolicyOptions(bool merge) =>
|
||||
[
|
||||
new(CopyPhotoPolicy.Union, Loc.L("Server.Copies.Policy.Union"), Loc.L("Tooltips.Server.Copies.Policy.Union")),
|
||||
new(CopyPhotoPolicy.ChoosePerPhoto, Loc.L("Server.Copies.Policy.ChoosePerPhoto"), Loc.L("Tooltips.Server.Copies.Policy.ChoosePerPhoto")),
|
||||
new(CopyPhotoPolicy.ThisPcWins, Loc.L(merge ? "Server.Copies.Policy.KeptWins" : "Server.Copies.Policy.ThisPcWins"),
|
||||
Loc.L(merge ? "Tooltips.Server.Copies.Policy.KeptWins" : "Tooltips.Server.Copies.Policy.ThisPcWins")),
|
||||
new(CopyPhotoPolicy.OtherWins, Loc.L(merge ? "Server.Copies.Policy.OtherCopyWins" : "Server.Copies.Policy.OtherWins"),
|
||||
Loc.L(merge ? "Tooltips.Server.Copies.Policy.OtherCopyWins" : "Tooltips.Server.Copies.Policy.OtherWins")),
|
||||
];
|
||||
|
||||
/// <summary>The choices of a Different photo under Choose each.</summary>
|
||||
internal static IReadOnlyList<SettingsOption<PhotoChoice>> VersionChoices(bool merge) =>
|
||||
[
|
||||
new(PhotoChoice.KeepBoth, Loc.L("Server.Copies.Version.Both"), Loc.L("Tooltips.Server.Copies.Version")),
|
||||
new(PhotoChoice.TakeHere, Loc.L(merge ? "Server.Copies.Detail.Kept" : "Server.Copies.Version.Here"), Loc.L("Tooltips.Server.Copies.Version")),
|
||||
new(PhotoChoice.TakeThere, Loc.L(merge ? "Server.Copies.Detail.Other" : "Server.Copies.Version.There"), Loc.L("Tooltips.Server.Copies.Version")),
|
||||
new(PhotoChoice.Leave, Loc.L("Server.Copies.Version.Leave"), Loc.L("Tooltips.Server.Copies.Version")),
|
||||
];
|
||||
|
||||
private static bool Expected(Exception ex) =>
|
||||
ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException or System.IO.IOException or UnauthorizedAccessException;
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Chronos.Ui.Controls;assembly=Chronos.Ui"
|
||||
xmlns:v="clr-namespace:Chronos.Ui.Visuals;assembly=Chronos.Ui"
|
||||
xmlns:l="clr-namespace:Chronos.Ui.Localization;assembly=Chronos.Ui"
|
||||
xmlns:infra="clr-namespace:Chronos.App.Infrastructure"
|
||||
xmlns:cp="clr-namespace:Chronos.App.Server.Copies">
|
||||
<!-- Compare sequences / Merge sequences (owner review 6, #73, design §8.2): Photos · Details · Projects · Plan, two footer buttons. -->
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Chronos;component/Archive/ArchiveDialogs.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<BooleanToVisibilityConverter x:Key="CopyBoolToVisibility" />
|
||||
|
||||
<!-- A choice of a dropdown says what it does in its tooltip. -->
|
||||
<Style x:Key="ComboBoxItem.Option" TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
|
||||
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
|
||||
</Style>
|
||||
|
||||
<!-- Rows of the dialog's lists read as their text; Tab goes to their controls. -->
|
||||
<Style x:Key="ListBoxItem.CopyPhoto" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
|
||||
<Setter Property="AutomationProperties.Name" Value="{Binding Name}" />
|
||||
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
|
||||
</Style>
|
||||
<Style x:Key="ListBoxItem.CopyClass" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
|
||||
<Setter Property="AutomationProperties.Name" Value="{Binding Text}" />
|
||||
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
|
||||
</Style>
|
||||
|
||||
<DataTemplate DataType="{x:Type cp:CopyDialogViewModel}">
|
||||
<Border Style="{StaticResource Border.Dialog}" Width="920" MaxHeight="600">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="{Binding Heading}" Style="{StaticResource Text.Title}" TextTrimming="CharacterEllipsis" ToolTip="{Binding Heading}" />
|
||||
<!-- Both sides: this PC, then the server (or the other archive). -->
|
||||
<Grid Grid.Row="1" Margin="0,10,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding HereText}" ToolTip="{Binding HereText}" TextTrimming="CharacterEllipsis" Typography.NumeralAlignment="Tabular" />
|
||||
<TextBlock Grid.Column="1" Text="▸" Foreground="{DynamicResource Brush.TextFaint}" Margin="10,0" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding ThereText}" ToolTip="{Binding ThereText}" TextTrimming="CharacterEllipsis" Typography.NumeralAlignment="Tabular" />
|
||||
</Grid>
|
||||
<v:SegmentedControl Grid.Row="2" HorizontalAlignment="Left" Margin="0,12,0,10" SelectedIndex="{Binding PartIndex}"
|
||||
IsEnabled="{Binding IsLoaded}" AutomationProperties.Name="{Binding Heading}">
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Part.Photos}" ToolTip="{l:Loc Tooltips.Server.Copies.Compare}" AutomationProperties.Name="{l:Loc Server.Copies.Part.Photos}" />
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Part.Details}" ToolTip="{l:Loc Tooltips.Server.Copies.Detail}" AutomationProperties.Name="{l:Loc Server.Copies.Part.Details}" />
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Part.Projects}" ToolTip="{Binding ProjectsToolTip}" AutomationProperties.Name="{l:Loc Server.Copies.Part.Projects}" />
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Part.Plan}" ToolTip="{Binding ApplyToolTip}" AutomationProperties.Name="{l:Loc Server.Copies.Part.Plan}" />
|
||||
</v:SegmentedControl>
|
||||
|
||||
<Grid Grid.Row="3" MinHeight="240">
|
||||
<!-- Photos: the policy, the class table and the photos of the selected class. -->
|
||||
<Grid Visibility="{Binding IsPhotos, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="300" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,8">
|
||||
<TextBlock Text="{l:Loc Server.Copies.Policy.Label}" Style="{StaticResource Text.DialogLabel}" VerticalAlignment="Center" Margin="0,0,10,0" />
|
||||
<ComboBox Width="170" ItemsSource="{Binding Policies}" SelectedItem="{Binding Policy}" DisplayMemberPath="Label" ToolTip="{Binding PolicyToolTip}"
|
||||
ItemContainerStyle="{StaticResource ComboBoxItem.Option}" AutomationProperties.Name="{l:Loc Server.Copies.Policy.Label}" />
|
||||
</StackPanel>
|
||||
<ListBox Grid.Row="1" ItemsSource="{Binding Classes}" SelectedItem="{Binding SelectedClass}" ItemContainerStyle="{StaticResource ListBoxItem.CopyClass}"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" AutomationProperties.Name="{l:Loc Server.Copies.Part.Photos}" Margin="0,0,14,0">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyClassRow}">
|
||||
<Grid Height="28">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="56" />
|
||||
<ColumnDefinition Width="70" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" FontSize="12" VerticalAlignment="Center" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding CountText}" TextAlignment="Right" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding HereBytesText}" TextAlignment="Right" VerticalAlignment="Center" Foreground="{DynamicResource Brush.TextMuted}"
|
||||
Typography.NumeralAlignment="Tabular" FontSize="12" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<!-- Bring all / Bring none, All: keep both, To trash…, Delete on server…: above the list they act on. -->
|
||||
<WrapPanel Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,8">
|
||||
<Button Style="{StaticResource Button.Link}" Content="{l:Loc Server.Copies.Photo.BringAll}" Command="{Binding BringAllCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.BringAll}" Margin="0,0,14,0" Visibility="{Binding CanBringAll, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<Button Style="{StaticResource Button.Link}" Content="{l:Loc Server.Copies.Photo.BringNone}" Command="{Binding BringNoneCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.BringNone}" Margin="0,0,14,0" Visibility="{Binding CanBringAll, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<Button Style="{StaticResource Button.Link}" Content="{l:Loc Server.Copies.Photo.AllBoth}" Command="{Binding AllBothCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.AllBoth}" Margin="0,0,14,0" Visibility="{Binding CanKeepAllBoth, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<Button Style="{StaticResource Button.Row}" Content="{l:Loc Server.Copies.Action.ToTrash}" Command="{Binding TrashCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.ToTrash}" ToolTipService.ShowOnDisabled="True" Margin="0,0,8,0"
|
||||
Visibility="{Binding CanTrashHere, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<Button Style="{StaticResource Button.Row}" Content="{l:Loc Server.Copies.Action.DeleteOnServer}" Command="{Binding DeleteThereCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.DeleteOnServer}" ToolTipService.ShowOnDisabled="True"
|
||||
Visibility="{Binding CanDeleteThere, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
</WrapPanel>
|
||||
<ListBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Photos}" ItemContainerStyle="{StaticResource ListBoxItem.CopyPhoto}" SelectionMode="Extended"
|
||||
VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.ScrollUnit="Pixel"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" KeyboardNavigation.TabNavigation="Continue"
|
||||
AutomationProperties.Name="{Binding SelectedClass.Text}" Visibility="{Binding HasPhotos, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyPhotoRow}">
|
||||
<Grid MinHeight="28" ToolTip="{Binding ToolTip}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="150" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition Width="110" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox IsChecked="{Binding Bring}" ToolTip="{l:Loc Tooltips.Server.Copies.Bring}" AutomationProperties.Name="{Binding BringAccessibleName}"
|
||||
VerticalAlignment="Center" Margin="0,0,8,0" Visibility="{Binding CanBring, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding TimeText}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" FontSize="12" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding Name}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" FlowDirection="LeftToRight" FontSize="12" />
|
||||
<TextBlock Grid.Column="3" Text="{Binding SizeText}" VerticalAlignment="Center" TextAlignment="Right" Typography.NumeralAlignment="Tabular" FontSize="12" />
|
||||
<TextBlock Grid.Column="4" Text="{Binding SideText}" VerticalAlignment="Center" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0"
|
||||
TextTrimming="CharacterEllipsis" FontSize="12" />
|
||||
<ComboBox Grid.Column="5" Width="120" ItemsSource="{Binding Choices}" SelectedItem="{Binding Choice}" DisplayMemberPath="Label"
|
||||
ItemContainerStyle="{StaticResource ComboBoxItem.Option}" ToolTip="{l:Loc Tooltips.Server.Copies.Version}"
|
||||
AutomationProperties.Name="{Binding ChoiceAccessibleName}" Visibility="{Binding CanChoose, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
<Button Grid.Column="5" Style="{StaticResource Button.Row}" Content="{l:Loc Server.Copies.Action.Drop}" Command="{Binding DropCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Server.Copies.Drop}" AutomationProperties.Name="{Binding DropAccessibleName}" FontSize="12"
|
||||
Visibility="{Binding CanDrop, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding PhotosEmptyText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,8,0,0"
|
||||
Visibility="{Binding PhotosEmptyText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
</Grid>
|
||||
|
||||
<!-- Details: one line per difference, nothing preselected. -->
|
||||
<Grid Visibility="{Binding IsDetails, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,8" Visibility="{Binding HasDetails, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<Button Style="{StaticResource Button.Link}" Content="{Binding AllHereText}" Command="{Binding AllHereCommand}" ToolTip="{l:Loc Tooltips.Server.Copies.Detail.All}" Margin="0,0,14,0" />
|
||||
<Button Style="{StaticResource Button.Link}" Content="{Binding AllThereText}" Command="{Binding AllThereCommand}" ToolTip="{l:Loc Tooltips.Server.Copies.Detail.All}" />
|
||||
</StackPanel>
|
||||
<ItemsControl Grid.Row="1" ItemsSource="{Binding Details}" Focusable="False" Visibility="{Binding HasDetails, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<ItemsControl.Template>
|
||||
<ControlTemplate TargetType="ItemsControl">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" Focusable="False">
|
||||
<ItemsPresenter />
|
||||
</ScrollViewer>
|
||||
</ControlTemplate>
|
||||
</ItemsControl.Template>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyDetailRow}">
|
||||
<Grid Margin="0,0,0,6">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="180" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding Label}" Style="{StaticResource Text.DialogLabel}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" ToolTip="{Binding Label}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding HereText}" ToolTip="{Binding HereToolTip}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" Margin="10,0,0,0" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding ThereText}" ToolTip="{Binding ThereToolTip}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" Margin="10,0,0,0" />
|
||||
<v:SegmentedControl Grid.Column="3" SelectedIndex="{Binding ChoiceIndex}" ToolTip="{Binding ToolTip}" AutomationProperties.Name="{Binding AccessibleName}" Margin="10,0,0,0">
|
||||
<v:SegmentedItem Content="{Binding HereWord}" ToolTip="{Binding HereToolTip}" AutomationProperties.Name="{Binding HereWord}" />
|
||||
<v:SegmentedItem Content="{Binding ThereWord}" ToolTip="{Binding ThereToolTip}" AutomationProperties.Name="{Binding ThereWord}" />
|
||||
</v:SegmentedControl>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<TextBlock Grid.Row="1" Text="{Binding DetailsEmptyText}" Foreground="{DynamicResource Brush.TextMuted}"
|
||||
Visibility="{Binding DetailsEmptyText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
</Grid>
|
||||
|
||||
<!-- Projects: Copy across or Leave them; each side's projects, and where each goes. -->
|
||||
<Grid Visibility="{Binding IsProjects, Converter={StaticResource CopyBoolToVisibility}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<v:SegmentedControl Grid.ColumnSpan="2" HorizontalAlignment="Left" SelectedIndex="{Binding ProjectsIndex}" IsEnabled="{Binding CanChooseProjects}"
|
||||
ToolTip="{Binding ProjectsToolTip}" ToolTipService.ShowOnDisabled="True" AutomationProperties.Name="{l:Loc Server.Copies.Part.Projects}" Margin="0,0,0,10">
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Projects.CopyAcross}" ToolTip="{l:Loc Tooltips.Server.Copies.Projects.CopyAcross}" AutomationProperties.Name="{l:Loc Server.Copies.Projects.CopyAcross}" />
|
||||
<v:SegmentedItem Content="{l:Loc Server.Copies.Projects.Leave}" ToolTip="{l:Loc Tooltips.Server.Copies.Projects.Leave}" AutomationProperties.Name="{l:Loc Server.Copies.Projects.Leave}" />
|
||||
</v:SegmentedControl>
|
||||
<TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding ProjectsNote}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,0,0,8"
|
||||
Visibility="{Binding ProjectsNote, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
<ItemsControl Grid.Row="2" ItemsSource="{Binding HereProjects}" Focusable="False" Margin="0,0,14,0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyProjectRow}">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,6" ToolTip="{Binding ToolTip}">
|
||||
<TextBlock Text="{Binding Name}" FontWeight="SemiBold" />
|
||||
<TextBlock Text="{Binding VersionsText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" />
|
||||
<TextBlock Text="{Binding ChangedText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" />
|
||||
<TextBlock Text="{Binding TargetText}" Foreground="{DynamicResource Brush.Accent}" Margin="10,0,0,0" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ItemsControl Grid.Row="2" Grid.Column="1" ItemsSource="{Binding ThereProjects}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyProjectRow}">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,6" ToolTip="{Binding ToolTip}">
|
||||
<TextBlock Text="{Binding Name}" FontWeight="SemiBold" />
|
||||
<TextBlock Text="{Binding VersionsText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" />
|
||||
<TextBlock Text="{Binding ChangedText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" />
|
||||
<TextBlock Text="{Binding TargetText}" Foreground="{DynamicResource Brush.Accent}" Margin="10,0,0,0" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
|
||||
<!-- Plan: the kept sequence (merge), what each side receives and loses, the blocks with their one action, Link only. -->
|
||||
<ScrollViewer Visibility="{Binding IsPlan, Converter={StaticResource CopyBoolToVisibility}}" VerticalScrollBarVisibility="Auto" Focusable="False">
|
||||
<StackPanel>
|
||||
<StackPanel Visibility="{Binding HasKeepOptions, Converter={StaticResource CopyBoolToVisibility}}" Margin="0,0,0,10">
|
||||
<TextBlock Text="{l:Loc Server.Copies.Plan.KeptCopy}" Style="{StaticResource Text.DialogLabel}" Margin="0,0,0,4" />
|
||||
<ItemsControl ItemsSource="{Binding KeepOptions}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyKeepOption}">
|
||||
<RadioButton GroupName="CopyKeep" Content="{Binding Text}" IsChecked="{Binding IsChecked}" ToolTip="{Binding ToolTip}"
|
||||
AutomationProperties.Name="{Binding AccessibleName}" Margin="0,2" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Margin="0,0,14,0">
|
||||
<TextBlock Text="{Binding HereHeading}" FontWeight="SemiBold" Margin="0,0,0,6" TextTrimming="CharacterEllipsis" ToolTip="{Binding HereHeading}" />
|
||||
<ItemsControl ItemsSource="{Binding HereLines}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyPlanLine}">
|
||||
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" ToolTip="{Binding ShownToolTip}" FontSize="12" Margin="0,0,0,4" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1">
|
||||
<TextBlock Text="{Binding ThereHeading}" FontWeight="SemiBold" Margin="0,0,0,6" TextTrimming="CharacterEllipsis" ToolTip="{Binding ThereHeading}" />
|
||||
<ItemsControl ItemsSource="{Binding ThereLines}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyPlanLine}">
|
||||
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" ToolTip="{Binding ShownToolTip}" FontSize="12" Margin="0,0,0,4" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<ItemsControl ItemsSource="{Binding Blocks}" Focusable="False" Margin="0,10,0,0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type cp:CopyBlockLine}">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,6">
|
||||
<ui:StatusGlyph Kind="Error" Text="{Binding Text}" ToolTip="{Binding Text}" FontSize="12" VerticalAlignment="Center"
|
||||
AutomationProperties.LiveSetting="Assertive" infra:LiveRegion.Text="{Binding Text}" />
|
||||
<Button Style="{StaticResource Button.Link}" Content="{Binding ChooseText}" Command="{Binding ChooseCommand}" ToolTip="{Binding ChooseToolTip}"
|
||||
Margin="10,0,0,0" Visibility="{Binding HasChoose, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Style="{StaticResource Button.Row}" HorizontalAlignment="Left" Content="{Binding LinkOnlyText}" Command="{Binding LinkOnlyCommand}"
|
||||
ToolTip="{Binding LinkOnlyToolTip}" Margin="0,10,0,0" Visibility="{Binding ShowLinkOnly, Converter={StaticResource CopyBoolToVisibility}}" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
<!-- Footer: a failure (or Planning…), then Cancel and Integrate (Merge). -->
|
||||
<DockPanel Grid.Row="4" Margin="0,14,0,0" LastChildFill="True">
|
||||
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Primary}" Content="{Binding ApplyText}" Command="{Binding ApplyCommand}"
|
||||
ToolTip="{Binding ApplyToolTip}" ToolTipService.ShowOnDisabled="True" MinWidth="96" Margin="8,0,0,0" />
|
||||
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{Binding CancelToolTip}"
|
||||
IsDefault="True" IsCancel="True" MinWidth="96" />
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<ui:StatusGlyph Style="{StaticResource Status.DialogError}" />
|
||||
<TextBlock Style="{StaticResource Text.Live}" Text="{Binding PlanningText}" infra:LiveRegion.Text="{Binding PlanningText}"
|
||||
Visibility="{Binding PlanningText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
<TextBlock Style="{StaticResource Text.Live}" Text="{Binding BusyText}" infra:LiveRegion.Text="{Binding BusyText}"
|
||||
Visibility="{Binding BusyText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,426 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Archiving;
|
||||
using Chronos.App.Infrastructure;
|
||||
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.Protocol;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
using Chronos.Ui.Visuals;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>
|
||||
/// Server › Matches (owner review 6, #73, design §8.1): the pairs of this server and of this PC's archives with both sides,
|
||||
/// their state and actions, Find matches, the toasts of detection runs (with Review), Unlink and Keep apart with Undo, the
|
||||
/// Library's "Also elsewhere" status and the Compare dialog. Reloads when the engine or a job of its kinds changes. UI thread.
|
||||
/// </summary>
|
||||
public sealed class CopyListViewModel : ObservableObject, IDisposable
|
||||
{
|
||||
private readonly ShellViewModel _shell;
|
||||
private readonly AsyncRelayCommand _find;
|
||||
private readonly SemaphoreSlim _reloading = new(1, 1);
|
||||
private readonly Dictionary<Guid, int> _deletedThere = [];
|
||||
private IReadOnlyList<FoundCopyView> _pairs = [];
|
||||
private ICopyEngine? _engine;
|
||||
private string _search = string.Empty;
|
||||
private int _reloadQueued;
|
||||
private bool _loaded;
|
||||
private bool _attached;
|
||||
|
||||
public CopyListViewModel(ShellViewModel shell)
|
||||
{
|
||||
_shell = shell;
|
||||
_find = new AsyncRelayCommand(FindAsync, () => Engine is not null && !IsFinding);
|
||||
}
|
||||
|
||||
public ObservableCollection<CopyRow> Rows { get; } = [];
|
||||
|
||||
/// <summary>Every listed pair of this server and of this PC's archives (the chip's count).</summary>
|
||||
public IReadOnlyList<FoundCopyView> Pairs => _pairs;
|
||||
|
||||
/// <summary>"Find matches": looks for pairs on the signed-in server and among this PC's archives now.</summary>
|
||||
public ICommand FindCommand => _find;
|
||||
|
||||
public string FindToolTip => Host.Server is not null
|
||||
? Loc.L("Tooltips.Server.Copies.Find", ServerName ?? Host.Server)
|
||||
: Loc.L("Tooltips.Server.Copies.FindLocal");
|
||||
|
||||
public bool IsFinding { get; private set; }
|
||||
|
||||
public int Count => _pairs.Count;
|
||||
|
||||
/// <summary>Pairs asking for a choice: the chip turns to the warning colours and the rail badge counts them.</summary>
|
||||
public int AttentionCount => _pairs.Count(p => p.Copy.NeedsAttention);
|
||||
|
||||
public bool HasRows => Rows.Count > 0;
|
||||
|
||||
/// <summary>"No matches found.": the empty list's one sentence (its one button is Find matches).</summary>
|
||||
public string? EmptyText => HasRows ? null : Loc.L(_pairs.Count == 0 ? "Server.Copies.Empty" : "Server.Sync.NoMatch");
|
||||
|
||||
public bool IsEmpty => !HasRows;
|
||||
|
||||
/// <summary>Opens a dialog over the Server section (set by <c>ServerViewModel</c>).</summary>
|
||||
internal Action<ArchiveDialogViewModel>? OpenDialog { get; set; }
|
||||
|
||||
/// <summary>Closes a dialog of the Server section.</summary>
|
||||
internal Action<ArchiveDialogViewModel>? CloseDialog { get; set; }
|
||||
|
||||
/// <summary>Shows the Matches chip (set by the sync table).</summary>
|
||||
internal Action<string?>? ShowList { get; set; }
|
||||
|
||||
/// <summary>The search text of the sync table, applied to both titles of a pair.</summary>
|
||||
public string SearchText
|
||||
{
|
||||
get => _search;
|
||||
set
|
||||
{
|
||||
if (Set(ref _search, value ?? string.Empty)) ApplyFilter();
|
||||
}
|
||||
}
|
||||
|
||||
internal ICopyEngine? Engine => Host.Copies;
|
||||
|
||||
private SyncHost Host => _shell.Services.Sync;
|
||||
|
||||
private string? ServerName => _shell.Services.Server.IsConnected ? _shell.Services.Server.Flow.Info?.Name : null;
|
||||
|
||||
/// <summary>The server announces what an Integrate needs (photo lookup and upload into a sequence).</summary>
|
||||
private bool CanIntegrate => _shell.Services.Server.IsConnected && _shell.Services.Server.Flow.Info?.Capabilities is { } capabilities
|
||||
&& capabilities.Contains(ServerCapabilities.PhotoLookup) && capabilities.Contains(ServerCapabilities.UploadInto);
|
||||
|
||||
private CopyRights Rights => new(Host.Server, ServerName, CanIntegrate, Host.CanUpload);
|
||||
|
||||
/// <summary>Raised after each reload (the chip count, the rail badge and the sync rows' marks follow it).</summary>
|
||||
public event Action? Changed;
|
||||
|
||||
public void Attach()
|
||||
{
|
||||
if (_attached) return;
|
||||
_attached = true;
|
||||
Host.CopiesChanged += OnEngineChanged;
|
||||
Host.Changed += OnHostChanged;
|
||||
Loc.CultureChanged += OnCultureChanged;
|
||||
if (_shell.Services.Jobs is { } jobs)
|
||||
{
|
||||
jobs.JobChanged += OnJobChanged;
|
||||
jobs.Progress += OnProgress;
|
||||
}
|
||||
Follow(Engine);
|
||||
_ = ReloadAsync();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_attached) return;
|
||||
_attached = false;
|
||||
Host.CopiesChanged -= OnEngineChanged;
|
||||
Host.Changed -= OnHostChanged;
|
||||
Loc.CultureChanged -= OnCultureChanged;
|
||||
if (_shell.Services.Jobs is { } jobs)
|
||||
{
|
||||
jobs.JobChanged -= OnJobChanged;
|
||||
jobs.Progress -= OnProgress;
|
||||
}
|
||||
Follow(null);
|
||||
}
|
||||
|
||||
/// <summary>The pair the sequence is in (this server's or a local one), the one asking for a choice first; null when none.</summary>
|
||||
public FoundCopy? PairOf(Guid sequenceId) => _pairs
|
||||
.Where(p => p.Copy.LocalId == sequenceId || p.Copy.OtherId == sequenceId || p.Copy.RemoteId == sequenceId)
|
||||
.OrderByDescending(p => p.Copy.NeedsAttention)
|
||||
.Select(p => p.Copy)
|
||||
.FirstOrDefault();
|
||||
|
||||
/// <summary>Reads the pairs again; requests made while a pass runs share the next one.</summary>
|
||||
public async Task ReloadAsync()
|
||||
{
|
||||
Interlocked.Exchange(ref _reloadQueued, 1);
|
||||
await _reloading.WaitAsync();
|
||||
try
|
||||
{
|
||||
while (Interlocked.Exchange(ref _reloadQueued, 0) == 1)
|
||||
{
|
||||
var server = Host.Server;
|
||||
var all = Engine is { } engine ? await engine.ListAsync(CancellationToken.None) : [];
|
||||
_pairs = [.. CopyText.Sorted(all.Where(p => p.Copy.Kind == CopyKind.LocalLocal
|
||||
|| string.Equals(p.Copy.Server, server, StringComparison.OrdinalIgnoreCase)))];
|
||||
AnnounceDeletions();
|
||||
ApplyFilter();
|
||||
UpdateLibrary();
|
||||
RaiseCounts();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
|
||||
{
|
||||
Log.Warning("copies", "The matches could not be read", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_reloading.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Opens the Compare dialog of the pair the sequence is in (Library › Compare…); false when it is in none.</summary>
|
||||
public bool Compare(Guid sequenceId)
|
||||
{
|
||||
if (_pairs.FirstOrDefault(p => p.Copy.Id == PairOf(sequenceId)?.Id) is not { } pair) return false;
|
||||
Open(pair, CopyDialogPart.Photos);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Opens the Compare dialog of <paramref name="pair"/> at <paramref name="part"/> (and a photo class).</summary>
|
||||
internal CopyDialogViewModel? Open(FoundCopyView pair, CopyDialogPart part, PhotoClass? photos = null, bool integrate = false)
|
||||
{
|
||||
if (Engine is not { } engine || OpenDialog is not { } open) return null;
|
||||
var dialog = new CopyDialogViewModel(_shell, engine, pair, Rights, part, photos, integrate, d => CloseDialog?.Invoke(d));
|
||||
open(dialog);
|
||||
_ = dialog.LoadAsync();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private void ApplyFilter()
|
||||
{
|
||||
var rights = Rights;
|
||||
var wanted = _pairs.Where(p => CopyText.Matches(p, _search.Trim())).ToList();
|
||||
var byId = Rows.ToDictionary(r => r.Id);
|
||||
Rows.Clear();
|
||||
foreach (var pair in wanted)
|
||||
{
|
||||
if (byId.TryGetValue(pair.Copy.Id, out var row)) row.Update(pair, rights);
|
||||
else row = new CopyRow(pair, rights, ActAsync);
|
||||
Rows.Add(row);
|
||||
}
|
||||
OnPropertyChanged(nameof(HasRows));
|
||||
OnPropertyChanged(nameof(IsEmpty));
|
||||
OnPropertyChanged(nameof(EmptyText));
|
||||
}
|
||||
|
||||
private void RaiseCounts()
|
||||
{
|
||||
OnPropertyChanged(nameof(Pairs));
|
||||
OnPropertyChanged(nameof(Count));
|
||||
OnPropertyChanged(nameof(AttentionCount));
|
||||
OnPropertyChanged(nameof(FindToolTip));
|
||||
_find.RaiseCanExecuteChanged();
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>The Library's cards and rows of local sequences in pairs that ask for a choice take "Also elsewhere" or "Deleted there".</summary>
|
||||
private void UpdateLibrary()
|
||||
{
|
||||
foreach (var item in _shell.Library.Items)
|
||||
{
|
||||
var pair = _pairs.FirstOrDefault(p => p.Copy.NeedsAttention && (p.Copy.LocalId == item.Id || p.Copy.OtherId == item.Id));
|
||||
item.SetMatch(pair is null ? null : LibraryStatus(pair, item.Id));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The card status of a sequence of <paramref name="pair"/>.</summary>
|
||||
internal static CardStatus LibraryStatus(FoundCopyView pair, Guid sequenceId)
|
||||
{
|
||||
var copy = pair.Copy;
|
||||
if (copy.RemoteGone || copy.Score.DeletedThere > 0)
|
||||
return new CardStatus(StatusKind.Warning, Loc.L("Library.Status.DeletedThere"),
|
||||
Loc.L("Tooltips.Library.Status.DeletedThere", pair.There.Where));
|
||||
var other = copy.Kind == CopyKind.LocalLocal && copy.OtherId == sequenceId ? pair.Here : pair.There;
|
||||
return new CardStatus(StatusKind.Warning, Loc.L("Library.Status.CopyFound"), copy.Kind == CopyKind.LocalServer
|
||||
? Loc.L("Tooltips.Library.Status.CopyFound", other.Where, CopyText.SharedPercent(copy.Score))
|
||||
: Loc.L("Tooltips.Library.Status.CopyFoundLocal", other.Where));
|
||||
}
|
||||
|
||||
/// <summary>An integrated pair with newly deleted photos on the other side: "3 photos deleted on nas" · Review.</summary>
|
||||
private void AnnounceDeletions()
|
||||
{
|
||||
foreach (var pair in _pairs)
|
||||
{
|
||||
var now = pair.Copy.State == CopyState.Integrated ? pair.Copy.Score.DeletedThere : 0;
|
||||
var before = _deletedThere.GetValueOrDefault(pair.Copy.Id);
|
||||
_deletedThere[pair.Copy.Id] = now;
|
||||
if (!_loaded || now <= before) continue;
|
||||
var shown = pair;
|
||||
_shell.Notify(Loc.Plural("Server.Copies.DeletedToast", now - before, pair.There.Where), null, Loc.L("Server.Copies.Action.Review"),
|
||||
Loc.L("Tooltips.Server.Copies.Review"), () => Review(shown));
|
||||
}
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
private void Review(FoundCopyView pair)
|
||||
{
|
||||
_shell.Navigate(SectionKey.Server);
|
||||
ShowList?.Invoke(null);
|
||||
Open(pair, CopyDialogPart.Photos, PhotoClass.DeletedThere);
|
||||
}
|
||||
|
||||
private async Task FindAsync()
|
||||
{
|
||||
if (Engine is not { } engine) return;
|
||||
IsFinding = true;
|
||||
_find.RaiseCanExecuteChanged();
|
||||
try
|
||||
{
|
||||
var found = await engine.FindAsync(Host.Remote, CancellationToken.None);
|
||||
if (found.IsEmpty) _shell.Notify(Loc.L("Server.Copies.Empty"));
|
||||
else Announce(found);
|
||||
}
|
||||
catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
|
||||
{
|
||||
_shell.Notify(ex.Message, isError: true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsFinding = false;
|
||||
_find.RaiseCanExecuteChanged();
|
||||
}
|
||||
await ReloadAsync();
|
||||
}
|
||||
|
||||
/// <summary>"2 matches found" · Review, and "3 sequences linked" · Show (design §8.4).</summary>
|
||||
internal void Announce(CopyFindResult found)
|
||||
{
|
||||
var asking = found.New.Count + found.AskedAgain.Count;
|
||||
if (asking > 0)
|
||||
_shell.Notify(Loc.Plural("Server.Copies.Found", asking), null, Loc.L("Server.Copies.Action.Review"), Loc.L("Tooltips.Server.Copies.ReviewFound"), ShowMatches);
|
||||
if (found.AutoLinked.Count > 0)
|
||||
_shell.Notify(Loc.Plural("Server.Copies.Linked", found.AutoLinked.Count), null, Loc.L("Server.Sync.Show"), Loc.L("Tooltips.Server.Sync.Show"), ShowMatches);
|
||||
}
|
||||
|
||||
private void ShowMatches()
|
||||
{
|
||||
_shell.Navigate(SectionKey.Server);
|
||||
ShowList?.Invoke(null);
|
||||
}
|
||||
|
||||
private async Task ActAsync(CopyRow row, CopyAction action)
|
||||
{
|
||||
if (Engine is not { } engine) return;
|
||||
var pair = row.View;
|
||||
var copy = pair.Copy;
|
||||
try
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case CopyAction.Compare:
|
||||
Open(pair, CopyDialogPart.Photos);
|
||||
return;
|
||||
case CopyAction.Integrate or CopyAction.Merge:
|
||||
Open(pair, CopyDialogPart.Plan, integrate: true);
|
||||
return;
|
||||
case CopyAction.Review:
|
||||
Open(pair, CopyDialogPart.Photos, PhotoClass.DeletedThere);
|
||||
return;
|
||||
case CopyAction.KeepApart:
|
||||
await engine.KeepApartAsync(copy.Id, CancellationToken.None);
|
||||
Toast(Loc.L("Server.Copies.KeptApartToast", row.Title), (Loc.L("Tooltips.Server.Copies.UndoKeepApart"), () => engine.AskAgainAsync(copy.Id, CancellationToken.None)));
|
||||
break;
|
||||
case CopyAction.AskAgain:
|
||||
await engine.AskAgainAsync(copy.Id, CancellationToken.None);
|
||||
break;
|
||||
case CopyAction.Unlink:
|
||||
await engine.UnlinkAsync(copy.Id, Host.Remote, CancellationToken.None);
|
||||
if (copy.Kind == CopyKind.LocalServer && Host.Remote is { } remote)
|
||||
Toast(Loc.L("Server.Copies.Unlinked", row.Title), (Loc.L("Tooltips.Server.Copies.UndoUnlink"), () => engine.LinkAsync(copy.Id, remote, CancellationToken.None)));
|
||||
break;
|
||||
case CopyAction.KeepHere:
|
||||
await engine.KeepHereAsync(copy.Id, CancellationToken.None);
|
||||
break;
|
||||
case CopyAction.UploadAgain:
|
||||
if (Host is { Service: { } service, Server: { } server } && _shell.Services.Engine is { } jobs
|
||||
&& await _shell.Services.Database!.Sequences.GetAsync(copy.LocalId) is { } sequence)
|
||||
await service.EnqueueUploadAsync(jobs, server, sequence);
|
||||
break;
|
||||
case CopyAction.ToTrash when OpenDialog is { } open:
|
||||
var delete = new DeleteDialogViewModel(_shell, [copy.LocalId], d => CloseDialog?.Invoke(d));
|
||||
open(delete);
|
||||
await delete.RunAsync();
|
||||
break;
|
||||
case CopyAction.Pause when copy.JobId is { } paused:
|
||||
await _shell.Services.Jobs!.PauseAsync(paused);
|
||||
break;
|
||||
case CopyAction.Resume when copy.JobId is { } resumed:
|
||||
await _shell.Services.Jobs!.ResumeAsync(resumed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
|
||||
{
|
||||
_shell.Notify(ex.Message, isError: true);
|
||||
}
|
||||
await ReloadAsync();
|
||||
}
|
||||
|
||||
/// <summary>A toast with Undo (Unlink and Keep apart ask no confirmation: design §8.5).</summary>
|
||||
private void Toast(string title, (string ToolTip, Func<Task> Undo) undo) =>
|
||||
_shell.Notify(title, null, Loc.L("Server.Copies.Action.Undo"), undo.ToolTip, async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await undo.Undo();
|
||||
}
|
||||
catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
|
||||
{
|
||||
_shell.Notify(ex.Message, isError: true);
|
||||
}
|
||||
await ReloadAsync();
|
||||
});
|
||||
|
||||
private void Follow(ICopyEngine? engine)
|
||||
{
|
||||
if (ReferenceEquals(_engine, engine)) return;
|
||||
if (_engine is not null) _engine.Found -= OnFound;
|
||||
_engine = engine;
|
||||
if (_engine is not null) _engine.Found += OnFound;
|
||||
}
|
||||
|
||||
private void OnFound(CopyFindResult found) => Dispatch(() =>
|
||||
{
|
||||
if (!found.IsEmpty && !IsFinding) Announce(found);
|
||||
_ = ReloadAsync();
|
||||
});
|
||||
|
||||
private void OnEngineChanged() => Dispatch(() =>
|
||||
{
|
||||
Follow(Engine);
|
||||
_ = ReloadAsync();
|
||||
});
|
||||
|
||||
private void OnHostChanged() => Dispatch(() => _ = ReloadAsync());
|
||||
|
||||
private void OnCultureChanged(object? sender, EventArgs e) => Dispatch(() =>
|
||||
{
|
||||
foreach (var row in Rows) row.Relabel();
|
||||
UpdateLibrary();
|
||||
OnAllPropertiesChanged();
|
||||
});
|
||||
|
||||
private void OnJobChanged(Job job)
|
||||
{
|
||||
if (job.Kind is not (JobKind.Integrate or JobKind.MergeSequences)) return;
|
||||
Dispatch(() =>
|
||||
{
|
||||
foreach (var row in Rows.Where(r => r.Copy.JobId == job.Id)) row.UpdateJob(job.State, job.ProgressDone, job.ProgressTotal);
|
||||
if (job.State is JobState.Done or JobState.Failed or JobState.Cancelled or JobState.Queued) _ = ReloadAsync();
|
||||
});
|
||||
}
|
||||
|
||||
private void OnProgress(JobProgressInfo info)
|
||||
{
|
||||
if (info.Kind is not JobKind.Integrate) return;
|
||||
Dispatch(() =>
|
||||
{
|
||||
foreach (var row in Rows.Where(r => r.Copy.JobId == info.JobId)) row.UpdateJob(JobState.Running, info.Done, info.Total);
|
||||
});
|
||||
}
|
||||
|
||||
private static void Dispatch(Action action)
|
||||
{
|
||||
if (System.Windows.Application.Current?.Dispatcher is not { } dispatcher || dispatcher.CheckAccess()) action();
|
||||
else dispatcher.BeginInvoke(action);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>A line of the Photos part's class table: glyph and class, count, bytes on each side, what it means.</summary>
|
||||
public sealed class CopyClassRow(PhotoClassTotal total) : ObservableObject
|
||||
{
|
||||
public PhotoClass Class { get; } = total.Class;
|
||||
public StatusKind Kind => CopyText.ClassKind(Class);
|
||||
public string Text => CopyText.Class(Class);
|
||||
public string CountText => Formatting.Count(total.Count);
|
||||
public string HereBytesText => total.HereBytes > 0 ? Formatting.Bytes(total.HereBytes) : string.Empty;
|
||||
public string ThereBytesText => total.ThereBytes > 0 ? Formatting.Bytes(total.ThereBytes) : string.Empty;
|
||||
public string ToolTip => CopyText.ClassToolTip(Class);
|
||||
public int Count => total.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A photo of the Photos part's list: capture time, name, size, where it lies, and per policy a Bring tick (Only here,
|
||||
/// Only there under Choose each), a version choice (Different under Choose each) or Drop… (Two versions).
|
||||
/// </summary>
|
||||
public sealed class CopyPhotoRow : ObservableObject
|
||||
{
|
||||
private readonly Action _changed;
|
||||
private bool _bring;
|
||||
private bool _isSelected;
|
||||
private SettingsOption<PhotoChoice>? _choice;
|
||||
|
||||
public CopyPhotoRow(ComparedPhoto photo, bool isMerge, bool canBring, bool canChoose, IReadOnlyList<SettingsOption<PhotoChoice>> choices,
|
||||
PhotoChoice? current, Action changed, Func<CopyPhotoRow, Task>? drop)
|
||||
{
|
||||
Photo = photo;
|
||||
IsMerge = isMerge;
|
||||
CanBring = canBring;
|
||||
CanChoose = canChoose;
|
||||
Choices = choices;
|
||||
_changed = changed;
|
||||
_bring = current == PhotoChoice.Bring;
|
||||
_choice = current is { } c and not PhotoChoice.Bring ? choices.FirstOrDefault(o => o.Value == c) : null;
|
||||
if (drop is not null) DropCommand = new AsyncRelayCommand(() => drop(this));
|
||||
}
|
||||
|
||||
public ComparedPhoto Photo { get; }
|
||||
public bool IsMerge { get; }
|
||||
public string Key => Photo.Key;
|
||||
private CopyPhotoInput? Input => Photo.Here ?? Photo.There;
|
||||
|
||||
public string TimeText => Input?.CapturedAt is { } at ? Formatting.Date(at) + " " + at.ToString("T", Loc.Culture) : string.Empty;
|
||||
public string Name => Input?.FileName ?? Photo.Key;
|
||||
public string SizeText => Formatting.Bytes(Photo.Bytes);
|
||||
|
||||
/// <summary>"This PC", "Server" (Kept, Other for a merge), or both.</summary>
|
||||
public string SideText => (Photo.Here, Photo.There) switch
|
||||
{
|
||||
(not null, not null) => string.Join(Loc.Separator, Side(true), Side(false)),
|
||||
(not null, null) => Side(true),
|
||||
_ => Side(false),
|
||||
};
|
||||
|
||||
public string ToolTip => string.Join(Loc.Separator, Name, SizeText, SideText);
|
||||
|
||||
/// <summary>Only here or Only there under Choose each: a Bring tick.</summary>
|
||||
public bool CanBring { get; }
|
||||
|
||||
/// <summary>Different under Choose each: Keep both, This PC's, Server's, Leave.</summary>
|
||||
public bool CanChoose { get; }
|
||||
|
||||
public IReadOnlyList<SettingsOption<PhotoChoice>> Choices { get; }
|
||||
|
||||
public ICommand? DropCommand { get; }
|
||||
public bool CanDrop => DropCommand is not null;
|
||||
|
||||
public bool Bring
|
||||
{
|
||||
get => _bring;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _bring, value)) return;
|
||||
_changed();
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsOption<PhotoChoice>? Choice
|
||||
{
|
||||
get => _choice;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _choice, value)) return;
|
||||
OnPropertyChanged(nameof(ChoiceAccessibleName));
|
||||
_changed();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The row is selected in the list (To trash… acts on the selection).</summary>
|
||||
public bool IsSelected { get => _isSelected; set => Set(ref _isSelected, value); }
|
||||
|
||||
/// <summary>The user's choice for this photo, or null when none.</summary>
|
||||
public PhotoChoice? Chosen => CanBring ? (_bring ? PhotoChoice.Bring : null) : _choice?.Value;
|
||||
|
||||
public string BringAccessibleName => Loc.L("Server.Copies.ControlFor", Name, Loc.L("Server.Copies.Photo.Bring"));
|
||||
public string ChoiceAccessibleName => Loc.L("Server.Copies.ControlFor", Name, _choice?.Label ?? Loc.L("Server.Copies.Version.Leave"));
|
||||
public string DropAccessibleName => Loc.L("Server.Copies.ControlFor", Name, Loc.L("Server.Copies.Action.Drop"));
|
||||
|
||||
/// <summary>Sets the tick or the choice without raising one change per row (Bring all, All: keep both).</summary>
|
||||
internal void SetQuietly(bool bring, SettingsOption<PhotoChoice>? choice)
|
||||
{
|
||||
_bring = bring;
|
||||
_choice = choice;
|
||||
OnPropertyChanged(nameof(Bring));
|
||||
OnPropertyChanged(nameof(Choice));
|
||||
OnPropertyChanged(nameof(ChoiceAccessibleName));
|
||||
}
|
||||
|
||||
private string Side(bool here) => Loc.L(IsMerge ? (here ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.Other")
|
||||
: here ? "Server.Copies.Detail.ThisPc" : "Server.Copies.Detail.Server");
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>A line of the Plan part ("Receives 24 photos · 412 MB"); a warning line (last copies) leads its column.</summary>
|
||||
public sealed record CopyPlanLine(string Text, string? ToolTip = null, bool IsWarning = false)
|
||||
{
|
||||
public StatusKind Kind => IsWarning ? StatusKind.Warning : StatusKind.Done;
|
||||
public string ShownToolTip => ToolTip ?? Text;
|
||||
}
|
||||
|
||||
/// <summary>Why the plan cannot be applied, with its one action where the dialog itself settles it (Choose).</summary>
|
||||
public sealed class CopyBlockLine(CopyBlock block, string text, Action? choose)
|
||||
{
|
||||
public CopyBlock Block { get; } = block;
|
||||
public string Text { get; } = text;
|
||||
public ICommand? ChooseCommand { get; } = choose is null ? null : new RelayCommand(choose);
|
||||
public bool HasChoose => ChooseCommand is not null;
|
||||
public string ChooseText => Loc.L("Server.Copies.Action.Choose");
|
||||
public string ChooseToolTip => Loc.L("Tooltips.Server.Copies.Choose");
|
||||
}
|
||||
|
||||
/// <summary>A side of a local pair the merge keeps ("Main archive · 1,204 photos · 18.2 GB"): the Kept sequence radios.</summary>
|
||||
public sealed class CopyKeepOption(Guid sequenceId, CopyFacts facts, Action<CopyKeepOption> chosen) : ObservableObject
|
||||
{
|
||||
private bool _isChecked;
|
||||
|
||||
public Guid SequenceId { get; } = sequenceId;
|
||||
public string Text => Loc.L("Server.Copies.Plan.KeptChoice", facts.Where, Loc.Plural("Shell.Status.Photos", facts.Photos), Formatting.Bytes(facts.Bytes));
|
||||
public string ToolTip => Loc.L("Tooltips.Server.Copies.KeptCopy");
|
||||
public string AccessibleName => Loc.L("Server.Copies.ControlFor", facts.Where, Loc.L("Server.Copies.Plan.KeptCopy"));
|
||||
|
||||
public bool IsChecked
|
||||
{
|
||||
get => _isChecked;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _isChecked, value) || !value) return;
|
||||
chosen(this);
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetQuietly(bool value)
|
||||
{
|
||||
_isChecked = value;
|
||||
OnPropertyChanged(nameof(IsChecked));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>A project of one side (the Projects part): name · versions · last change, and the name it gets at the other home.</summary>
|
||||
public sealed class CopyProjectRow(ProjectLine project) : ObservableObject
|
||||
{
|
||||
private string? _target;
|
||||
|
||||
public ProjectLine Project { get; } = project;
|
||||
public string Name => Project.Name;
|
||||
public string VersionsText => Loc.Plural("Server.Copies.Projects.Versions", Project.Versions);
|
||||
public string ChangedText => Formatting.Date(Project.UpdatedAt);
|
||||
|
||||
/// <summary>"→ Vertical (STUDIO-PC)" once the plan named it; null when it stays or Main.</summary>
|
||||
public string? TargetText => _target is null ? null : Loc.L("Server.Copies.Projects.Target", _target);
|
||||
|
||||
public string ToolTip => Project.IsMain ? Loc.L("Tooltips.Server.Copies.Projects.Main")
|
||||
: string.Join(Loc.Separator, Name, VersionsText, ChangedText);
|
||||
|
||||
internal void SetTarget(string? target)
|
||||
{
|
||||
_target = target;
|
||||
OnPropertyChanged(nameof(TargetText));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
using System.Windows.Input;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>A button of a Matches row; kept while the row offers it, so focus and tooltips survive a reload.</summary>
|
||||
public sealed class CopyRowAction : ObservableObject
|
||||
{
|
||||
private readonly AsyncRelayCommand _command;
|
||||
private string _toolTip = string.Empty;
|
||||
private string _sequence = string.Empty;
|
||||
private bool _isEnabled = true;
|
||||
|
||||
public CopyRowAction(CopyAction action, Func<Task> execute)
|
||||
{
|
||||
Action = action;
|
||||
_command = new AsyncRelayCommand(execute, () => _isEnabled);
|
||||
}
|
||||
|
||||
public CopyAction Action { get; }
|
||||
public string Text => CopyText.Label(Action);
|
||||
public ICommand Command => _command;
|
||||
|
||||
public string ToolTip { get => _toolTip; set => Set(ref _toolTip, value); }
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
set
|
||||
{
|
||||
if (Set(ref _isEnabled, value)) _command.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string Sequence
|
||||
{
|
||||
get => _sequence;
|
||||
set
|
||||
{
|
||||
if (Set(ref _sequence, value)) OnPropertyChanged(nameof(AccessibleName));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>"Compare…: Lighthouse 2026-08-13": screen readers name the pair each of the identical buttons acts on.</summary>
|
||||
public string AccessibleName => Loc.L("Server.Sync.ActionFor", Text, _sequence);
|
||||
|
||||
public void Relabel()
|
||||
{
|
||||
OnPropertyChanged(nameof(Text));
|
||||
OnPropertyChanged(nameof(AccessibleName));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>One row of Server › Matches (design §8.1): the sequence, both sides, the state and the actions that apply.</summary>
|
||||
public sealed class CopyRow : ObservableObject
|
||||
{
|
||||
private readonly Func<CopyRow, CopyAction, Task> _act;
|
||||
private FoundCopyView _view;
|
||||
private CopyRights _rights;
|
||||
private (long Done, long Total)? _progress;
|
||||
private Core.Model.JobState? _job;
|
||||
private IReadOnlyList<CopyRowAction> _actions = [];
|
||||
|
||||
public CopyRow(FoundCopyView view, CopyRights rights, Func<CopyRow, CopyAction, Task> act)
|
||||
{
|
||||
_view = view;
|
||||
_act = act;
|
||||
UpdateActions(rights);
|
||||
}
|
||||
|
||||
public FoundCopyView View => _view;
|
||||
public FoundCopy Copy => _view.Copy;
|
||||
public Guid Id => _view.Copy.Id;
|
||||
public string Title => _view.Here.Title;
|
||||
|
||||
/// <summary>Both titles: the other copy may carry another name.</summary>
|
||||
public string TitleToolTip => string.Equals(_view.Here.Title, _view.There.Title, StringComparison.CurrentCulture)
|
||||
? _view.Here.Title
|
||||
: string.Join(Loc.Separator, _view.Here.Title, _view.There.Title);
|
||||
|
||||
public string HereText => CopyText.Where(_view.Here, isServer: false);
|
||||
public string ThereText => CopyText.Where(_view.There, isServer: Copy.Kind == CopyKind.LocalServer);
|
||||
|
||||
public StatusKind StateKind => CopyText.State(Copy, _rights.ServerName, _progress).Kind;
|
||||
public string StateText => CopyText.State(Copy, _rights.ServerName, _progress).Text;
|
||||
public string StateToolTip => string.Join(Loc.Separator, StateText, CopyText.State(Copy, _rights.ServerName, _progress).ToolTip);
|
||||
|
||||
/// <summary>"Lighthouse 2026-08-13: match found": what a screen reader announces when the state changes.</summary>
|
||||
public string StateAnnouncement => Loc.L("Server.Sync.Row.State", Title, StateText);
|
||||
|
||||
/// <summary>The pair asks for a choice: the row is drawn on the warning tint (the State word says it too).</summary>
|
||||
public bool IsConflict => Copy.NeedsAttention;
|
||||
|
||||
public IReadOnlyList<CopyRowAction> Actions
|
||||
{
|
||||
get => _actions;
|
||||
private set => Set(ref _actions, value);
|
||||
}
|
||||
|
||||
public void Update(FoundCopyView view, CopyRights rights)
|
||||
{
|
||||
_view = view;
|
||||
UpdateActions(rights);
|
||||
RaiseTexts();
|
||||
}
|
||||
|
||||
/// <summary>The Integrate job's step ("integrating · 2 of 5") and whether it is paused.</summary>
|
||||
public void UpdateJob(Core.Model.JobState? state, long done, long total)
|
||||
{
|
||||
_progress = (done, total);
|
||||
if (_job != state)
|
||||
{
|
||||
_job = state;
|
||||
UpdateActions(_rights);
|
||||
}
|
||||
RaiseTexts();
|
||||
}
|
||||
|
||||
public void Relabel()
|
||||
{
|
||||
foreach (var action in _actions) action.Relabel();
|
||||
UpdateActions(_rights);
|
||||
RaiseTexts();
|
||||
}
|
||||
|
||||
private void UpdateActions(CopyRights rights)
|
||||
{
|
||||
_rights = rights;
|
||||
var wanted = CopyText.Actions(Copy, _job);
|
||||
if (!wanted.SequenceEqual(_actions.Select(a => a.Action)))
|
||||
{
|
||||
var kept = _actions.ToDictionary(a => a.Action);
|
||||
Actions = [.. wanted.Select(action => kept.GetValueOrDefault(action) ?? new CopyRowAction(action, () => _act(this, action)))];
|
||||
}
|
||||
foreach (var action in _actions)
|
||||
{
|
||||
action.ToolTip = CopyText.ToolTip(Copy, action.Action, rights);
|
||||
action.IsEnabled = CopyText.Blocked(Copy, action.Action, rights) is null;
|
||||
action.Sequence = Title;
|
||||
}
|
||||
}
|
||||
|
||||
private void RaiseTexts()
|
||||
{
|
||||
OnPropertyChanged(nameof(View));
|
||||
OnPropertyChanged(nameof(Copy));
|
||||
OnPropertyChanged(nameof(Title));
|
||||
OnPropertyChanged(nameof(TitleToolTip));
|
||||
OnPropertyChanged(nameof(HereText));
|
||||
OnPropertyChanged(nameof(ThereText));
|
||||
OnPropertyChanged(nameof(StateKind));
|
||||
OnPropertyChanged(nameof(StateText));
|
||||
OnPropertyChanged(nameof(StateToolTip));
|
||||
OnPropertyChanged(nameof(StateAnnouncement));
|
||||
OnPropertyChanged(nameof(IsConflict));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>
|
||||
/// The Matches states that <c>--capture</c> renders (<c>server-copies-<scene>-<theme>.png</c>, design §8.7) and the
|
||||
/// screen smoke tests check, on the sample pairs: the list, the dialog at each part and with each list, the plan with and
|
||||
/// without a block, the merge of a local pair, the toast of Find matches, and the sync rows a pair marks.
|
||||
/// </summary>
|
||||
public static class CopyScenes
|
||||
{
|
||||
/// <summary>Scenes shown in the window (dialogs in-window included); the confirmations are separate windows.</summary>
|
||||
public static readonly IReadOnlyList<string> Views =
|
||||
[
|
||||
"server-copies", "server-copies-toast", "server-copies-photos", "server-copies-choose", "server-copies-versions",
|
||||
"server-copies-review", "server-copies-details", "server-copies-projects", "server-copies-plan", "server-copies-blocked",
|
||||
"server-copies-merge", "server-sync-copyfound", "server-copies-gone",
|
||||
];
|
||||
|
||||
/// <summary>The Lighthouse pair (a match found on the server).</summary>
|
||||
public const string Lighthouse = "Lighthouse 2026-08-13";
|
||||
|
||||
/// <summary>The Alps pair (twice on this PC).</summary>
|
||||
public const string Alps = "Alps 2025";
|
||||
|
||||
/// <summary>Shows <paramref name="view"/>; returns the dialog it opened, if any.</summary>
|
||||
public static async Task<CopyDialogViewModel?> ShowAsync(ShellViewModel shell, string view)
|
||||
{
|
||||
var server = shell.Server;
|
||||
var sync = server.Sync;
|
||||
var list = sync.Copies;
|
||||
shell.Navigate(SectionKey.Server);
|
||||
if (server.Dialog is { } open) server.CloseDialog(open);
|
||||
sync.SearchText = string.Empty;
|
||||
await sync.ReloadAsync();
|
||||
await list.ReloadAsync();
|
||||
switch (view)
|
||||
{
|
||||
case "server-sync-copyfound":
|
||||
sync.ShowFilter(SyncFilter.All);
|
||||
return null;
|
||||
case "server-copies-gone":
|
||||
sync.ShowFilter(SyncFilter.All, "Garden");
|
||||
return null;
|
||||
case "server-copies-toast":
|
||||
sync.ShowFilter(SyncFilter.FoundCopies);
|
||||
if (list.Engine is { } engine) list.Announce(await engine.FindAsync(shell.Services.Sync.Remote, CancellationToken.None));
|
||||
return null;
|
||||
}
|
||||
sync.ShowFilter(SyncFilter.FoundCopies);
|
||||
if (view == "server-copies") return null;
|
||||
var title = view is "server-copies-versions" or "server-copies-merge" ? Alps : view == "server-copies-review" ? "Bridge works wk 41" : Lighthouse;
|
||||
if (list.Pairs.FirstOrDefault(p => p.Here.Title == title) is not { } pair) return null;
|
||||
var (part, photos) = view switch
|
||||
{
|
||||
"server-copies-photos" => (CopyDialogPart.Photos, PhotoClass.OnlyHere),
|
||||
"server-copies-choose" => (CopyDialogPart.Photos, PhotoClass.Differs),
|
||||
"server-copies-versions" => (CopyDialogPart.Photos, PhotoClass.Versions),
|
||||
"server-copies-review" => (CopyDialogPart.Photos, PhotoClass.DeletedThere),
|
||||
"server-copies-details" => (CopyDialogPart.Details, (PhotoClass?)null),
|
||||
"server-copies-projects" => (CopyDialogPart.Projects, null),
|
||||
_ => (CopyDialogPart.Plan, null),
|
||||
};
|
||||
if (list.Open(pair, part, photos) is not { } dialog) return null;
|
||||
await dialog.LoadAsync();
|
||||
switch (view)
|
||||
{
|
||||
case "server-copies-choose":
|
||||
dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ChoosePerPhoto);
|
||||
dialog.SelectedClass = dialog.Classes.FirstOrDefault(c => c.Class == PhotoClass.Differs);
|
||||
break;
|
||||
case "server-copies-details":
|
||||
if (dialog.Details.Count > 0) dialog.Details[0].ChoiceIndex = 0;
|
||||
break;
|
||||
case "server-copies-plan":
|
||||
dialog.AllHereCommand.Execute(null);
|
||||
dialog.Part = CopyDialogPart.Plan;
|
||||
break;
|
||||
}
|
||||
if (dialog.IsPlan) await dialog.PlanNowAsync();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
/// <summary>"Replace photos?": the Lighthouse plan where this PC's version of the different photos wins.</summary>
|
||||
public static async Task<ConfirmRequest?> ReplaceRequestAsync(ShellViewModel shell)
|
||||
{
|
||||
if (await ShowAsync(shell, "server-copies-plan") is not { } dialog) return null;
|
||||
dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ThisPcWins);
|
||||
await dialog.PlanNowAsync();
|
||||
var request = dialog.Plan is { } plan ? CopyDialogViewModel.ReplaceRequest(plan) : null;
|
||||
shell.Server.CloseDialog(dialog);
|
||||
return request;
|
||||
}
|
||||
|
||||
/// <summary>"Merge sequences?": the Alps merge, with the typed photo count.</summary>
|
||||
public static async Task<ConfirmRequest?> MergeRequestAsync(ShellViewModel shell)
|
||||
{
|
||||
if (await ShowAsync(shell, "server-copies-merge") is not { } dialog) return null;
|
||||
dialog.AllHereCommand.Execute(null);
|
||||
await dialog.PlanNowAsync();
|
||||
var request = dialog.MergePlan is { } plan ? dialog.MergeRequest(plan) : null;
|
||||
shell.Server.CloseDialog(dialog);
|
||||
return request;
|
||||
}
|
||||
|
||||
/// <summary>Back to the sync table with no dialog and no search.</summary>
|
||||
public static void Reset(ShellViewModel shell)
|
||||
{
|
||||
if (shell.Server.Dialog is { } open) shell.Server.CloseDialog(open);
|
||||
shell.Server.Sync.ShowFilter(SyncFilter.All, string.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Ui.Controls;
|
||||
|
||||
namespace Chronos.App.Server.Copies;
|
||||
|
||||
/// <summary>What a row of Server › Matches offers (design §8.1).</summary>
|
||||
public enum CopyAction
|
||||
{
|
||||
Compare,
|
||||
Integrate,
|
||||
Merge,
|
||||
KeepApart,
|
||||
AskAgain,
|
||||
Unlink,
|
||||
Review,
|
||||
KeepHere,
|
||||
UploadAgain,
|
||||
ToTrash,
|
||||
Pause,
|
||||
Resume,
|
||||
}
|
||||
|
||||
/// <summary>What the signed-in account allows a pair's actions; Server is null when signed out.</summary>
|
||||
/// <param name="Server">The signed-in server's key, or null.</param>
|
||||
/// <param name="ServerName">The name shown for that server.</param>
|
||||
/// <param name="CanIntegrate">The server announces the capabilities an Integrate needs.</param>
|
||||
/// <param name="CanUpload">The account may upload.</param>
|
||||
/// <param name="Busy">The pair's sequences an Integrate or Merge job holds.</param>
|
||||
public readonly record struct CopyRights(string? Server, string? ServerName, bool CanIntegrate, bool CanUpload, bool Busy = false);
|
||||
|
||||
/// <summary>The words, glyphs and actions of a pair (design §8.1): plain functions of a <see cref="FoundCopy"/>, like <see cref="SyncText"/>.</summary>
|
||||
public static class CopyText
|
||||
{
|
||||
/// <summary>The state glyph, word and tooltip of a pair; <paramref name="progress"/> is the Integrate job's step (done, total).</summary>
|
||||
public static (StatusKind Kind, string Text, string ToolTip) State(FoundCopy copy, string? serverName = null, (long Done, long Total)? progress = null)
|
||||
{
|
||||
var deleted = copy.Score.DeletedThere;
|
||||
if (copy.RemoteGone && copy.State == CopyState.KeptApart)
|
||||
return (StatusKind.Offline, Loc.L("Server.Copies.State.KeptHere"), Loc.L("Tooltips.Server.Copies.State.KeptHere"));
|
||||
if (copy.RemoteGone)
|
||||
return (StatusKind.Warning, Loc.L("Server.Copies.State.RemoteGone"), Loc.L("Tooltips.Server.Copies.State.RemoteGone"));
|
||||
if (copy.State is CopyState.Linked or CopyState.Integrated && deleted > 0)
|
||||
{
|
||||
var key = copy.Kind == CopyKind.LocalLocal ? "Server.Copies.State.DeletedOther" : "Server.Copies.State.DeletedThere";
|
||||
return (StatusKind.Warning, Loc.L(key, Formatting.Count(deleted)), Loc.Plural("Tooltips.Server.Copies.State.DeletedThere", deleted));
|
||||
}
|
||||
return copy.State switch
|
||||
{
|
||||
CopyState.Candidate => (StatusKind.Warning, Loc.L("Server.Copies.State.Candidate"),
|
||||
Loc.L("Tooltips.Server.Copies.State.Candidate", SharedPercent(copy.Score))),
|
||||
CopyState.KeptApart => (StatusKind.Offline, Loc.L("Server.Copies.State.KeptApart"),
|
||||
Loc.L("Tooltips.Server.Copies.State.KeptApart", Formatting.Date(copy.AnsweredAt ?? copy.UpdatedAt))),
|
||||
CopyState.Linked => (StatusKind.Synced, Loc.L("Server.Copies.State.Linked"), Loc.L("Tooltips.Server.Copies.State.Linked")),
|
||||
CopyState.Integrating => (StatusKind.Running,
|
||||
Loc.L("Server.Copies.State.Integrating", Formatting.Count(progress?.Done ?? 0), Formatting.Count(progress?.Total ?? 0)),
|
||||
Loc.L("Tooltips.Server.Copies.State.Integrating")),
|
||||
_ => (StatusKind.Done, Loc.L("Server.Copies.State.Integrated"), Loc.L("Tooltips.Server.Copies.State.Integrated")),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The share of the smaller side's photos the other holds too, in whole per cent ("98").</summary>
|
||||
public static string SharedPercent(CopyScore score) =>
|
||||
Math.Round(Math.Clamp(score.Containment, 0, 1000) / 10.0).ToString("0", Loc.Culture);
|
||||
|
||||
/// <summary>"Main archive · 1,204 photos": where one side of a pair lies.</summary>
|
||||
public static string Where(CopyFacts facts, bool isServer) =>
|
||||
Loc.Plural(isServer ? "Server.Copies.Where.Server" : "Server.Copies.Where.Archive", facts.Photos, facts.Where);
|
||||
|
||||
/// <summary>"Lighthouse · 1,204 photos · 18.2 GB": a side of the dialog's header.</summary>
|
||||
public static string Facts(CopyFacts facts) => Loc.Plural("Server.Copies.Facts", facts.Photos, facts.Where, Formatting.Bytes(facts.Bytes));
|
||||
|
||||
/// <summary>The row's buttons in the order of design §8.1.</summary>
|
||||
public static IReadOnlyList<CopyAction> Actions(FoundCopy copy, Core.Model.JobState? job = null)
|
||||
{
|
||||
var local = copy.Kind == CopyKind.LocalLocal;
|
||||
if (copy.RemoteGone)
|
||||
return copy.State == CopyState.KeptApart ? [CopyAction.UploadAgain] : [CopyAction.KeepHere, CopyAction.UploadAgain, CopyAction.ToTrash];
|
||||
return copy.State switch
|
||||
{
|
||||
CopyState.Candidate => [CopyAction.Compare, local ? CopyAction.Merge : CopyAction.Integrate, CopyAction.KeepApart],
|
||||
CopyState.KeptApart => [CopyAction.Compare, CopyAction.AskAgain],
|
||||
CopyState.Linked when copy.Score.DeletedThere > 0 => [CopyAction.Compare, CopyAction.Integrate, CopyAction.Unlink, CopyAction.Review],
|
||||
CopyState.Linked => [CopyAction.Compare, CopyAction.Integrate, CopyAction.Unlink],
|
||||
CopyState.Integrating => [job == Core.Model.JobState.Paused ? CopyAction.Resume : CopyAction.Pause],
|
||||
_ when copy.Score.DeletedThere > 0 => [CopyAction.Compare, CopyAction.Unlink, CopyAction.Review],
|
||||
_ => [CopyAction.Compare, CopyAction.Unlink],
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The button's label ("Compare…", "Merge…").</summary>
|
||||
public static string Label(CopyAction action) => action switch
|
||||
{
|
||||
CopyAction.Merge => Loc.L("Server.Copies.Action.MergeRow"),
|
||||
CopyAction.Pause => Loc.L("Server.Sync.Action.Pause"),
|
||||
CopyAction.Resume => Loc.L("Server.Sync.Action.Resume"),
|
||||
_ => Loc.L("Server.Copies.Action." + action),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Why the action cannot be pressed now, or null when it can: a pair of a server needs that server signed in; Integrate
|
||||
/// a server that announces the capabilities; Upload again the upload right; nothing that moves files while a job holds it.
|
||||
/// </summary>
|
||||
public static string? Blocked(FoundCopy copy, CopyAction action, CopyRights rights)
|
||||
{
|
||||
if (action is CopyAction.Pause or CopyAction.Resume or CopyAction.KeepApart or CopyAction.AskAgain or CopyAction.KeepHere) return null;
|
||||
if (copy.Kind == CopyKind.LocalServer && action is not CopyAction.ToTrash
|
||||
&& !string.Equals(copy.Server, rights.Server, StringComparison.OrdinalIgnoreCase))
|
||||
return Loc.L("Tooltips.Server.Copies.SignIn", copy.Server ?? string.Empty);
|
||||
if (rights.Busy && action is CopyAction.Integrate or CopyAction.Merge or CopyAction.ToTrash or CopyAction.UploadAgain)
|
||||
return Loc.L("Errors.Copies.Busy");
|
||||
return action switch
|
||||
{
|
||||
CopyAction.Integrate when !rights.CanIntegrate => Loc.L("Tooltips.Server.Copies.NeedsNewerServer"),
|
||||
CopyAction.UploadAgain when !rights.CanUpload => Loc.L("Tooltips.Server.Sync.UploadAll.NoRight"),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>What the button does; for a disabled one, why not.</summary>
|
||||
public static string ToolTip(FoundCopy copy, CopyAction action, CopyRights rights) => Blocked(copy, action, rights) ?? action switch
|
||||
{
|
||||
CopyAction.UploadAgain => Loc.L("Tooltips.Server.Copies.UploadAgain", rights.ServerName ?? copy.Server ?? string.Empty),
|
||||
CopyAction.ToTrash => Loc.L("Tooltips.Server.Copies.ToTrashSequence"),
|
||||
CopyAction.Pause => Loc.L("Tooltips.Server.Sync.Pause"),
|
||||
CopyAction.Resume => Loc.L("Tooltips.Server.Sync.Resume"),
|
||||
_ => Loc.L("Tooltips.Server.Copies." + action),
|
||||
};
|
||||
|
||||
/// <summary>Sorting (design §8.1): pairs asking for attention first, then the stronger hints, then by title.</summary>
|
||||
public static IEnumerable<FoundCopyView> Sorted(IEnumerable<FoundCopyView> pairs) => pairs
|
||||
.OrderByDescending(p => p.Copy.NeedsAttention)
|
||||
.ThenByDescending(p => p.Copy.Score.Hints)
|
||||
.ThenBy(p => p.Here.Title, StringComparer.CurrentCultureIgnoreCase);
|
||||
|
||||
/// <summary>The search of the Matches list: either title.</summary>
|
||||
public static bool Matches(FoundCopyView pair, string search) => search.Length == 0
|
||||
|| pair.Here.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase)
|
||||
|| pair.There.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase);
|
||||
|
||||
/// <summary>The word of a photo class ("Only here").</summary>
|
||||
public static string Class(PhotoClass c) => Loc.L("Server.Copies.Class." + c);
|
||||
|
||||
public static string ClassToolTip(PhotoClass c) => Loc.L("Tooltips.Server.Copies.Class." + c);
|
||||
|
||||
/// <summary>The glyph of a photo class: what an Integrate settles by itself is fine; what waits for a choice is a warning.</summary>
|
||||
public static StatusKind ClassKind(PhotoClass c) => c switch
|
||||
{
|
||||
PhotoClass.Same or PhotoClass.Converted => StatusKind.Done,
|
||||
PhotoClass.SameUnhashed => StatusKind.Queued,
|
||||
PhotoClass.OnlyHere or PhotoClass.OnlyThere => StatusKind.Synced,
|
||||
PhotoClass.DeletedHere => StatusKind.Offline,
|
||||
_ => StatusKind.Warning,
|
||||
};
|
||||
|
||||
/// <summary>The sentence of a block (each maps to one <c>Errors.Copies.*</c> key).</summary>
|
||||
public static string Block(CopyBlock block, string title, string? server, string? need = null, int unchosen = 0) => block switch
|
||||
{
|
||||
CopyBlock.NeedsNewerServer => Loc.L("Errors.Copies.NeedsNewerServer", server ?? string.Empty),
|
||||
CopyBlock.LinkTaken => Loc.L("Errors.Copies.LinkTaken", title, server ?? string.Empty),
|
||||
CopyBlock.NoSpace => Loc.L("Errors.Copies.NoSpace", title, need ?? string.Empty),
|
||||
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile => Loc.L("Errors.Copies." + block, title),
|
||||
CopyBlock.UnsentWorkspace => Loc.L("Errors.Copies.Unsent", title),
|
||||
CopyBlock.BothLinked => Loc.L("Errors.Copies.BothLinked", server ?? string.Empty),
|
||||
CopyBlock.TrashBlocked => Loc.L("Errors.Copies.TrashBlocked", title, need ?? string.Empty),
|
||||
CopyBlock.DetailsUnchosen => Loc.Plural("Errors.Copies.DetailsUnchosen", unchosen),
|
||||
_ => Loc.L("Errors.Copies." + block),
|
||||
};
|
||||
|
||||
/// <summary>A block the user settles in the dialog itself: its line gets the one action Choose.</summary>
|
||||
public static bool HasChoose(CopyBlock block) => block is CopyBlock.DetailsUnchosen or CopyBlock.KeptUnchosen;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public sealed class SyncRowAction : ObservableObject
|
||||
}
|
||||
|
||||
public SyncAction Action { get; }
|
||||
public string Text => Loc.L("Server.Sync.Action." + Action);
|
||||
public string Text => Action == SyncAction.Compare ? Loc.L("Server.Copies.Action.Compare") : Loc.L("Server.Sync.Action." + Action);
|
||||
public ICommand Command => _command;
|
||||
|
||||
public string ToolTip
|
||||
@@ -68,12 +68,14 @@ public sealed class SyncRow : ObservableObject
|
||||
private readonly Func<SyncRow, SyncAction, Task> _act;
|
||||
private SyncEntry _entry;
|
||||
private SyncRights _rights;
|
||||
private SyncMark _mark;
|
||||
private IReadOnlyList<SyncRowAction> _actions = [];
|
||||
|
||||
public SyncRow(SyncEntry entry, SyncRights rights, Func<SyncRow, SyncAction, Task> act)
|
||||
public SyncRow(SyncEntry entry, SyncRights rights, Func<SyncRow, SyncAction, Task> act, SyncMark mark = default)
|
||||
{
|
||||
_entry = entry;
|
||||
_act = act;
|
||||
_mark = mark;
|
||||
UpdateActions(rights);
|
||||
}
|
||||
|
||||
@@ -82,14 +84,17 @@ public sealed class SyncRow : ObservableObject
|
||||
public string Title => _entry.Title;
|
||||
public string LocalText => SyncText.Local(_entry);
|
||||
public string ServerText => SyncText.Server(_entry);
|
||||
public StatusKind StateKind => SyncText.State(_entry).Kind;
|
||||
public string StateText => SyncText.State(_entry).Text;
|
||||
/// <summary>The row's match and Upload all local skip, if any (owner review 6, #73).</summary>
|
||||
public SyncMark Mark => _mark;
|
||||
|
||||
public StatusKind StateKind => SyncText.State(_entry, _mark).Kind;
|
||||
public string StateText => SyncText.State(_entry, _mark).Text;
|
||||
|
||||
/// <summary>"Clouds over the Langhe: In sync": what a screen reader announces when the state changes (not progress).</summary>
|
||||
public string StateAnnouncement => Loc.L("Server.Sync.Row.State", Title, StateText);
|
||||
|
||||
/// <summary>The state whole (its fixed column cuts the longer ones), then what it means or what differs.</summary>
|
||||
public string StateToolTip => string.Join(Loc.Separator, StateText, SyncText.State(_entry).ToolTip);
|
||||
public string StateToolTip => string.Join(Loc.Separator, StateText, SyncText.State(_entry, _mark).ToolTip);
|
||||
|
||||
/// <summary>Settings differ on both sides: the row is drawn on the warning tint (the word in the State column says it too).</summary>
|
||||
public bool IsConflict => _entry.Status == SyncStatus.Conflict && _entry.Transfer is null;
|
||||
@@ -101,9 +106,10 @@ public sealed class SyncRow : ObservableObject
|
||||
}
|
||||
|
||||
/// <summary>Takes a fresher comparison of the same sequence; buttons the row still offers are kept.</summary>
|
||||
public void Update(SyncEntry entry, SyncRights rights)
|
||||
public void Update(SyncEntry entry, SyncRights rights, SyncMark mark = default)
|
||||
{
|
||||
_entry = entry;
|
||||
_mark = mark;
|
||||
UpdateActions(rights);
|
||||
RaiseTexts();
|
||||
}
|
||||
@@ -130,7 +136,7 @@ public sealed class SyncRow : ObservableObject
|
||||
private void UpdateActions(SyncRights rights)
|
||||
{
|
||||
_rights = rights;
|
||||
var wanted = SyncText.Actions(_entry, rights);
|
||||
var wanted = SyncText.Actions(_entry, rights, _mark);
|
||||
if (!wanted.SequenceEqual(_actions.Select(a => a.Action)))
|
||||
{
|
||||
var kept = _actions.ToDictionary(a => a.Action);
|
||||
|
||||
@@ -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(() =>
|
||||
{
|
||||
|
||||
@@ -18,6 +18,9 @@ public enum SyncFilter
|
||||
LocalOnly,
|
||||
Remote,
|
||||
Conflicts,
|
||||
|
||||
/// <summary>Matches (owner review 6, #73): the list is <c>CopyList</c>, not sync rows.</summary>
|
||||
FoundCopies,
|
||||
}
|
||||
|
||||
/// <summary>What a row of the sync table offers.</summary>
|
||||
@@ -40,6 +43,19 @@ public enum SyncAction
|
||||
/// that keeps no projects, whose sequences open with proxies as before.
|
||||
/// </summary>
|
||||
OpenInWorkspace,
|
||||
|
||||
/// <summary>Compare the row's sequence with its match (owner review 6, #73).</summary>
|
||||
Compare,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the Matches list adds to a sync row (owner review 6, #73): the pair the row's sequence is in, and why Upload all
|
||||
/// local left it out.
|
||||
/// </summary>
|
||||
public readonly record struct SyncMark(Data.Copies.FoundCopy? Copy, Data.Copies.UploadSkip? Skipped, string? ServerName = null)
|
||||
{
|
||||
/// <summary>The row's sequence is in a pair nobody answered yet.</summary>
|
||||
public bool IsCandidate => Copy is { State: Data.Copies.CopyState.Candidate, RemoteGone: false };
|
||||
}
|
||||
|
||||
/// <summary>What the signed-in account may do (server permission bits), and whether its server keeps projects.</summary>
|
||||
@@ -163,6 +179,46 @@ public static class SyncText
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The State column with what the Matches list knows (owner review 6, #73): a transfer still shows first; then a sequence
|
||||
/// in an unanswered pair reads "match found", one whose server copy was deleted "deleted on server" or "kept here", and
|
||||
/// one Upload all local left out "skipped" with the reason.
|
||||
/// </summary>
|
||||
public static (StatusKind Kind, string Text, string ToolTip) State(SyncEntry entry, SyncMark mark)
|
||||
{
|
||||
if (entry.Transfer is not null) return State(entry);
|
||||
if (mark.Copy is { RemoteGone: true } gone)
|
||||
{
|
||||
return gone.State == Data.Copies.CopyState.KeptApart
|
||||
? (StatusKind.Offline, Loc.L("Server.Sync.State.KeptHere"), Loc.L("Tooltips.Server.Copies.State.KeptHere"))
|
||||
: (StatusKind.Warning, Loc.L("Server.Sync.State.RemoteGone"), Loc.L("Tooltips.Server.Copies.State.RemoteGone"));
|
||||
}
|
||||
if (mark.IsCandidate)
|
||||
return (StatusKind.Warning, Loc.L("Server.Sync.State.CopyFound"), Loc.L("Tooltips.Server.Sync.State.CopyFound", mark.ServerName ?? mark.Copy!.Server ?? string.Empty));
|
||||
if (mark.Skipped is { } why && entry.Status == SyncStatus.LocalOnly)
|
||||
return (StatusKind.Offline, Loc.L("Server.Sync.State.Skipped"), Loc.L("Tooltips.Server.Sync.State.Skipped", Loc.L("Tooltips.Server.Sync.Skip." + why)));
|
||||
return State(entry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The row's buttons with its match (design §8.1): a sequence in an unanswered pair offers Compare… first, then its usual
|
||||
/// buttons; a linked one offers Compare… last.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<SyncAction> Actions(SyncEntry entry, SyncRights rights, SyncMark mark)
|
||||
{
|
||||
var actions = Actions(entry, rights);
|
||||
if (entry.Transfer is not null || mark.Copy is null || mark.Copy.RemoteGone) return actions;
|
||||
if (mark.IsCandidate) return [SyncAction.Compare, .. actions];
|
||||
return entry.Link is not null ? [.. actions, SyncAction.Compare] : actions;
|
||||
}
|
||||
|
||||
/// <summary>The label of a detail line of the Compare dialog ("Deflicker window"); "Other setting" when unknown.</summary>
|
||||
public static string DetailLabel(string path)
|
||||
{
|
||||
var (key, _) = Setting(path);
|
||||
return key == "Server.Setting.Other" ? Loc.L("Server.Copies.Detail.OtherSetting") : Loc.L(key);
|
||||
}
|
||||
|
||||
/// <summary>One line for the State tooltip: "Deflicker window 41 here, 33 on the server · +2".</summary>
|
||||
public static string ConflictSummary(SyncEntry entry)
|
||||
{
|
||||
@@ -283,6 +339,9 @@ public static class SyncText
|
||||
/// <summary>The bytes an action moves (for the tooltips).</summary>
|
||||
public static long Size(SyncEntry entry, SyncAction action) => action switch
|
||||
{
|
||||
// A linked sequence sends only the photos the server lacks: their share of the sequence's bytes.
|
||||
SyncAction.Upload when entry is { Link.MissingRemote: > 0 and var missing, Local: { FrameCount: > 0 } local } && missing < local.FrameCount =>
|
||||
(long)Math.Round((double)local.TotalBytes * missing / local.FrameCount),
|
||||
SyncAction.Upload => entry.Local?.TotalBytes ?? 0,
|
||||
SyncAction.DownloadOriginals => entry.Link?.TotalBytes ?? 0,
|
||||
SyncAction.GetExports => entry.Link?.ExportsToGetBytes ?? 0,
|
||||
@@ -300,6 +359,7 @@ public static class SyncText
|
||||
SyncAction.GetExports => Loc.Plural("Tooltips.Server.Sync.GetExports", entry.Link!.ExportsToGet, Formatting.Bytes(Size(entry, action))),
|
||||
SyncAction.SendExports => Loc.Plural("Tooltips.Server.Sync.SendExports", entry.Link!.ExportsToSend, Formatting.Bytes(Size(entry, action))),
|
||||
SyncAction.OpenInWorkspace when !rights.KeepsProjects => Loc.L("Tooltips.Server.Sync.OpenInWorkspace.NoProjects"),
|
||||
SyncAction.Compare => Loc.L("Tooltips.Server.Copies.Compare"),
|
||||
_ => Loc.L("Tooltips.Server.Sync." + action),
|
||||
};
|
||||
|
||||
@@ -314,6 +374,7 @@ public static class SyncText
|
||||
SyncFilter.Remote => entry.Status is SyncStatus.RemoteOnly or SyncStatus.ProxiesOnly
|
||||
|| entry is { Status: SyncStatus.Transferring, HasLocalOriginals: false, Link: not null },
|
||||
SyncFilter.Conflicts => entry.Status == SyncStatus.Conflict,
|
||||
SyncFilter.FoundCopies => false,
|
||||
_ => true,
|
||||
}) && (search.Length == 0 || entry.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// The matches rows of Settings › Server (owner review 6, #73, design §7): Link matches, Integrate photos and Integrate
|
||||
/// projects, each option with its tooltip. Each value is stored and saved at once; the rows read <see cref="AppSettings"/>
|
||||
/// each time, so Reset and Import show the new values.
|
||||
/// </summary>
|
||||
public sealed class CopySettingsRows(AppSettings settings, Action save) : ObservableObject
|
||||
{
|
||||
public IReadOnlyList<SettingsOption<CopyLinking>> LinkingOptions { get; private set; } = LinkingList();
|
||||
public IReadOnlyList<SettingsOption<CopyPhotoPolicy>> PhotoOptions { get; private set; } = Photos();
|
||||
public IReadOnlyList<SettingsOption<CopyProjects>> ProjectOptions { get; private set; } = Projects();
|
||||
|
||||
public SettingsOption<CopyLinking> Linking
|
||||
{
|
||||
get => LinkingOptions.FirstOrDefault(o => o.Value == settings.CopyLinking) ?? LinkingOptions[0];
|
||||
set
|
||||
{
|
||||
if (value is null || value.Value == settings.CopyLinking) return;
|
||||
settings.CopyLinking = value.Value;
|
||||
save();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsOption<CopyPhotoPolicy> PhotoPolicy
|
||||
{
|
||||
get => PhotoOptions.FirstOrDefault(o => o.Value == settings.CopyPhotos) ?? PhotoOptions[0];
|
||||
set
|
||||
{
|
||||
if (value is null || value.Value == settings.CopyPhotos) return;
|
||||
settings.CopyPhotos = value.Value;
|
||||
save();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsOption<CopyProjects> ProjectsChoice
|
||||
{
|
||||
get => ProjectOptions.FirstOrDefault(o => o.Value == settings.CopyProjects) ?? ProjectOptions[0];
|
||||
set
|
||||
{
|
||||
if (value is null || value.Value == settings.CopyProjects) return;
|
||||
settings.CopyProjects = value.Value;
|
||||
save();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The defaults of a new installation.</summary>
|
||||
internal void Reset()
|
||||
{
|
||||
var defaults = new AppSettings();
|
||||
settings.CopyLinking = defaults.CopyLinking;
|
||||
settings.CopyPhotos = defaults.CopyPhotos;
|
||||
settings.CopyProjects = defaults.CopyProjects;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
/// <summary>Values another screen (or an import) changed, and labels in the current language.</summary>
|
||||
internal void Refresh()
|
||||
{
|
||||
LinkingOptions = LinkingList();
|
||||
PhotoOptions = Photos();
|
||||
ProjectOptions = Projects();
|
||||
OnAllPropertiesChanged();
|
||||
}
|
||||
|
||||
private static IReadOnlyList<SettingsOption<CopyLinking>> LinkingList() =>
|
||||
[
|
||||
new(CopyLinking.AskAlways, Loc.L("Settings.Server.CopyLinking.AskAlways"), Loc.L("Tooltips.Settings.CopyLinking.AskAlways")),
|
||||
new(CopyLinking.WhenIdentical, Loc.L("Settings.Server.CopyLinking.WhenIdentical"), Loc.L("Tooltips.Settings.CopyLinking.WhenIdentical")),
|
||||
new(CopyLinking.WhenHalfShared, Loc.L("Settings.Server.CopyLinking.WhenHalf"), Loc.L("Tooltips.Settings.CopyLinking.WhenHalf")),
|
||||
];
|
||||
|
||||
private static IReadOnlyList<SettingsOption<CopyPhotoPolicy>> Photos() =>
|
||||
[
|
||||
new(CopyPhotoPolicy.Union, Loc.L("Server.Copies.Policy.Union"), Loc.L("Tooltips.Settings.CopyPhotos.Union")),
|
||||
new(CopyPhotoPolicy.ChoosePerPhoto, Loc.L("Server.Copies.Policy.ChoosePerPhoto"), Loc.L("Tooltips.Settings.CopyPhotos.ChoosePerPhoto")),
|
||||
new(CopyPhotoPolicy.ThisPcWins, Loc.L("Server.Copies.Policy.ThisPcWins"), Loc.L("Tooltips.Settings.CopyPhotos.ThisPcWins")),
|
||||
new(CopyPhotoPolicy.OtherWins, Loc.L("Server.Copies.Policy.OtherWins"), Loc.L("Tooltips.Settings.CopyPhotos.OtherWins")),
|
||||
];
|
||||
|
||||
private static IReadOnlyList<SettingsOption<CopyProjects>> Projects() =>
|
||||
[
|
||||
new(CopyProjects.CopyAcross, Loc.L("Server.Copies.Projects.CopyAcross"), Loc.L("Tooltips.Settings.CopyProjects.CopyAcross")),
|
||||
new(CopyProjects.Leave, Loc.L("Server.Copies.Projects.Leave"), Loc.L("Tooltips.Settings.CopyProjects.Leave")),
|
||||
];
|
||||
}
|
||||
@@ -59,8 +59,8 @@ public sealed class SettingsPageItem(SettingsPage page, Func<IEnumerable<string>
|
||||
internal void Refresh() => OnAllPropertiesChanged();
|
||||
}
|
||||
|
||||
/// <summary>A choice of a settings dropdown.</summary>
|
||||
public sealed record SettingsOption<T>(T Value, string Label)
|
||||
/// <summary>A choice of a settings dropdown; <paramref name="ToolTip"/> says what the choice does (null: the box's tooltip only).</summary>
|
||||
public sealed record SettingsOption<T>(T Value, string Label, string? ToolTip = null)
|
||||
{
|
||||
public override string ToString() => Label;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using Chronos.App.Import;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Library;
|
||||
using Chronos.App.Server;
|
||||
using Chronos.App.Server.Copies;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Imaging.Geometry;
|
||||
@@ -189,6 +190,7 @@ public static class ScreenCapture
|
||||
|
||||
written += await CaptureEditorAsync(window, shell, sample, directory);
|
||||
written += await CaptureRemoteEditorAsync(window, shell, sample, directory);
|
||||
written += await CaptureCopiesAsync(window, shell, sample, directory);
|
||||
Log.Info("capture", $"{written} screenshot(s) written to {Path.GetFullPath(directory)}");
|
||||
if (written == 0) Environment.ExitCode = 1;
|
||||
}
|
||||
@@ -291,6 +293,58 @@ public static class ScreenCapture
|
||||
return written;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matches (owner review 6, #73, design §8.7), last as they add sequences of their own: the list, its toast, the dialog
|
||||
/// at each part and list, the plan with and without a block, the merge, the two destructive confirmations, the sync rows
|
||||
/// a pair marks, the Library's cards, the empty list, and the list signed out (local pairs only).
|
||||
/// </summary>
|
||||
private static async Task<int> CaptureCopiesAsync(MainWindow window, ShellViewModel shell, SampleData sample, string directory)
|
||||
{
|
||||
var written = 0;
|
||||
var engine = await sample.FillCopiesAsync();
|
||||
await shell.Library.RefreshAsync();
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
foreach (var view in CopyScenes.Views)
|
||||
{
|
||||
DismissToasts(window);
|
||||
await CopyScenes.ShowAsync(shell, view);
|
||||
written += await SaveAsync(window, directory, view, theme);
|
||||
}
|
||||
CopyScenes.Reset(shell);
|
||||
if (await CopyScenes.ReplaceRequestAsync(shell) is { } replace)
|
||||
written += await SaveDialogAsync(new ConfirmDialog(replace), directory, "server-copies-replace-confirm", theme);
|
||||
if (await CopyScenes.MergeRequestAsync(shell) is { } merge)
|
||||
written += await SaveDialogAsync(new ConfirmDialog(merge), directory, "server-copies-confirm", theme);
|
||||
CopyScenes.Reset(shell);
|
||||
DismissToasts(window);
|
||||
await LibraryScenes.ShowCopiesAsync(shell, CopyScenes.Alps);
|
||||
written += await SaveAsync(window, directory, "library-copies", theme, waitForThumbnails: shell);
|
||||
shell.Library.SearchText = string.Empty;
|
||||
}
|
||||
|
||||
// No pair at all, then signed out: only this PC's own pairs stay (the chip shows with two archives).
|
||||
shell.Services.Sync.Copies = new SampleCopyEngine();
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
DismissToasts(window);
|
||||
await CopyScenes.ShowAsync(shell, "server-copies");
|
||||
written += await SaveAsync(window, directory, "server-copies-empty", theme);
|
||||
}
|
||||
shell.Services.Sync.Copies = engine;
|
||||
CopyScenes.Reset(shell);
|
||||
await shell.Services.Server.SignOutAsync();
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
DismissToasts(window);
|
||||
await CopyScenes.ShowAsync(shell, "server-copies");
|
||||
written += await SaveAsync(window, directory, "server-copies-signedout", theme);
|
||||
}
|
||||
return written;
|
||||
}
|
||||
private static void SelectSyncFilter(ShellViewModel shell, SyncFilter filter) =>
|
||||
shell.Server.Sync.Chips.First(c => c.Filter == filter).SelectCommand.Execute(null);
|
||||
|
||||
|
||||
@@ -15,9 +15,32 @@ namespace Chronos.App.Workspace;
|
||||
public sealed class WorkspaceProjectItem(WorkspaceEntry entry, SequenceItem? sequence) : ObservableObject
|
||||
{
|
||||
private WorkspaceStatus? _status;
|
||||
private string? _twinHome;
|
||||
private string? _twinProject;
|
||||
|
||||
public WorkspaceEntry Entry { get; } = entry;
|
||||
|
||||
/// <summary>
|
||||
/// The other home of the same time-lapse (a linked or integrated match) when it has a workspace project too; null
|
||||
/// otherwise (owner review 6, #73). The picker shows a muted Twin chip after the name.
|
||||
/// </summary>
|
||||
public string? TwinHome => _twinHome;
|
||||
|
||||
public bool HasTwin => _twinHome is not null;
|
||||
|
||||
/// <summary>"Also at nas: Vertical."</summary>
|
||||
public string? TwinToolTip => _twinHome is null ? null : Loc.L("Tooltips.Editor.Picker.Twin", _twinHome, _twinProject ?? string.Empty);
|
||||
|
||||
/// <summary>Marks the item as the twin of <paramref name="project"/> at <paramref name="home"/> (null: none).</summary>
|
||||
public void SetTwin(string? home, string? project)
|
||||
{
|
||||
_twinHome = home;
|
||||
_twinProject = project;
|
||||
OnPropertyChanged(nameof(TwinHome));
|
||||
OnPropertyChanged(nameof(HasTwin));
|
||||
OnPropertyChanged(nameof(TwinToolTip));
|
||||
}
|
||||
|
||||
/// <summary>The sequence's row of the library, for its thumbnail; null when the index no longer has it.</summary>
|
||||
public SequenceItem? Sequence { get; } = sequence;
|
||||
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
using System.Windows.Controls;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Library;
|
||||
using Chronos.App.Sections;
|
||||
using Chronos.App.Server;
|
||||
using Chronos.App.Server.Copies;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.App.Tests.Windows;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Testing;
|
||||
using Chronos.Ui.Controls;
|
||||
|
||||
namespace Chronos.App.Tests.Server;
|
||||
|
||||
/// <summary>
|
||||
/// Server › Matches on the capture sample pairs (owner review 6, #73): the list and its chip, the Compare dialog in the
|
||||
/// window, its plan and blocks, the confirmations, the Library's match cards and the Settings rows.
|
||||
/// </summary>
|
||||
[WindowsOnly]
|
||||
[Serial]
|
||||
[Timeout(300_000)]
|
||||
public sealed class CopyScreenSmokeTests
|
||||
{
|
||||
[Test]
|
||||
public Task TheMatchesListOrdersThePairsAndEveryActionSaysWhatItDoes() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await StartAsync();
|
||||
var shell = app.Shell;
|
||||
var table = shell.Server.Sync;
|
||||
var list = table.Copies;
|
||||
await CopyScenes.ShowAsync(shell, "server-copies");
|
||||
|
||||
Assert.True(table.IsMatches);
|
||||
Assert.True(table.ShowCopyList, "the Matches list replaces the sync table");
|
||||
Assert.GreaterOrEqual(list.Count, 5);
|
||||
Assert.Equal(list.Count, table.Chips.Single(c => c.Filter == SyncFilter.FoundCopies).Count);
|
||||
Assert.True(list.AttentionCount > 0);
|
||||
// Pairs that ask for a choice come first.
|
||||
Assert.True(list.Rows[0].IsConflict);
|
||||
Assert.True(list.Rows.SkipWhile(r => r.IsConflict).All(r => !r.IsConflict), "attention first, then the rest");
|
||||
foreach (var row in list.Rows)
|
||||
{
|
||||
Assert.False(string.IsNullOrWhiteSpace(row.StateToolTip), $"{row.Title}: the state has a tooltip");
|
||||
foreach (var action in row.Actions)
|
||||
{
|
||||
Assert.False(string.IsNullOrWhiteSpace(action.ToolTip), $"{row.Title}: {action.Text} has a tooltip");
|
||||
Assert.LessOrEqual(action.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length, 3, $"\"{action.Text}\" is at most three words");
|
||||
}
|
||||
}
|
||||
var lighthouse = list.Rows.Single(r => r.Title == CopyScenes.Lighthouse);
|
||||
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Integrate, CopyAction.KeepApart], lighthouse.Actions.Select(a => a.Action));
|
||||
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Merge, CopyAction.KeepApart],
|
||||
list.Rows.Single(r => r.Title == CopyScenes.Alps).Actions.Select(a => a.Action));
|
||||
await app.ExpectAsync<ServerView>("server-copies");
|
||||
|
||||
// The search narrows the pairs, by either title.
|
||||
table.SearchText = "Alps";
|
||||
Assert.Count(1, list.Rows);
|
||||
table.SearchText = string.Empty;
|
||||
|
||||
// The sync table marks the sequence of an unanswered pair and offers Compare… first.
|
||||
table.ShowFilter(SyncFilter.All);
|
||||
var marked = table.Rows.First(r => r.Title == CopyScenes.Lighthouse);
|
||||
Assert.Equal(Loc.L("Server.Sync.State.CopyFound"), marked.StateText);
|
||||
Assert.Equal(SyncAction.Compare, marked.Actions[0].Action);
|
||||
CopyScenes.Reset(shell);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task TheCompareDialogWaitsForTheDetailsAndConfirmsWhatItReplaces() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await StartAsync();
|
||||
var shell = app.Shell;
|
||||
var server = shell.Server;
|
||||
var list = server.Sync.Copies;
|
||||
await CopyScenes.ShowAsync(shell, "server-copies");
|
||||
|
||||
// Integrate… opens on the details while one waits for a choice.
|
||||
var pair = list.Pairs.Single(p => p.Here.Title == CopyScenes.Lighthouse);
|
||||
var dialog = Assert.NotNull(list.Open(pair, CopyDialogPart.Plan, integrate: true));
|
||||
await dialog.LoadAsync();
|
||||
Assert.True(server.IsDialogOpen);
|
||||
Assert.False(server.IsContentEnabled, "the screen behind the dialog takes no input");
|
||||
Assert.Equal(CopyDialogPart.Details, dialog.Part);
|
||||
Assert.Equal(3, dialog.Unchosen);
|
||||
await app.ExpectAsync<ServerView>("server-copies-details");
|
||||
|
||||
// The footer: one primary action, Cancel answers Esc; both say what they do.
|
||||
var cancel = app.FindAll<Button>().Single(b => b.IsVisible && b.IsCancel);
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Copies.Cancel"), cancel.ToolTip);
|
||||
Assert.Contains(app.FindAll<Button>(), b => b.IsVisible && b.Content as string == dialog.ApplyText && b.ToolTip is not null);
|
||||
|
||||
// The plan is blocked until every detail is chosen; the block line offers Choose.
|
||||
dialog.Part = CopyDialogPart.Plan;
|
||||
await dialog.PlanNowAsync();
|
||||
var block = Assert.Contains(dialog.Blocks, b => b.Block == CopyBlock.DetailsUnchosen);
|
||||
Assert.True(block.HasChoose);
|
||||
Assert.False(dialog.ApplyCommand.CanExecute(null));
|
||||
Assert.Equal(block.Text, dialog.ApplyToolTip);
|
||||
dialog.AllHereCommand.Execute(null);
|
||||
Assert.Equal(0, dialog.Unchosen);
|
||||
await dialog.PlanNowAsync();
|
||||
Assert.False(dialog.Blocks.Any(b => b.Block == CopyBlock.DetailsUnchosen), "every detail chosen");
|
||||
Assert.True(dialog.ApplyCommand.CanExecute(null));
|
||||
Assert.NotEmpty(dialog.HereLines);
|
||||
await app.ExpectAsync<ServerView>("server-copies-plan");
|
||||
|
||||
// This PC's version wins: the server's versions go to its trash, so the confirmation is destructive.
|
||||
dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ThisPcWins);
|
||||
await dialog.PlanNowAsync();
|
||||
var replace = CopyDialogViewModel.ReplaceRequest(Assert.NotNull(dialog.Plan));
|
||||
Assert.True(replace.IsDestructive);
|
||||
Assert.Equal(Loc.L("Server.Copies.Confirm.Replace.Title"), replace.Heading);
|
||||
|
||||
// Cancel closes the dialog and gives the screen back.
|
||||
dialog.CloseCommand.Execute(null);
|
||||
Assert.False(server.IsDialogOpen);
|
||||
Assert.True(server.IsContentEnabled);
|
||||
|
||||
// A local pair merges into the kept copy, preselected; the confirmation asks for the dropped photo count.
|
||||
var merge = Assert.NotNull(await CopyScenes.ShowAsync(shell, "server-copies-merge"));
|
||||
Assert.True(merge.IsMerge);
|
||||
Assert.Count(2, merge.KeepOptions);
|
||||
Assert.Count(1, merge.KeepOptions.Where(o => o.IsChecked));
|
||||
merge.AllHereCommand.Execute(null);
|
||||
await merge.PlanNowAsync();
|
||||
var plan = Assert.NotNull(merge.MergePlan);
|
||||
var request = merge.MergeRequest(plan);
|
||||
Assert.True(request.IsDestructive);
|
||||
var dropped = list.Pairs.Single(p => p.Here.Title == CopyScenes.Alps) is var alps && plan.KeepId == alps.Copy.LocalId ? alps.There : alps.Here;
|
||||
Assert.Equal(dropped.Photos.ToString(Loc.Culture), request.TypedConfirmation);
|
||||
await app.ExpectAsync<ServerView>("server-copies-merge");
|
||||
CopyScenes.Reset(shell);
|
||||
Assert.False(server.IsDialogOpen);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task TheLibraryAndSettingsShowTheMatches() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await StartAsync();
|
||||
var shell = app.Shell;
|
||||
|
||||
// A card in a pair that asks for a choice carries the match status and offers Compare….
|
||||
await LibraryScenes.ShowCopiesAsync(shell, CopyScenes.Alps);
|
||||
var item = Assert.Contains(shell.Library.Items, i => i.HasMatch && i.Title == CopyScenes.Alps);
|
||||
Assert.NotNull(item.MatchStatus);
|
||||
Assert.Contains(item.Statuses, s => s == item.MatchStatus);
|
||||
Assert.True(shell.Library.CompareItemCommand.CanExecute(item));
|
||||
await app.ExpectAsync<LibraryView>("library-copies", waitForThumbnails: true);
|
||||
shell.Library.CompareItemCommand.Execute(item);
|
||||
Assert.Equal(SectionKey.Server, shell.Current.Key);
|
||||
Assert.True(shell.Server.Sync.IsMatches);
|
||||
Assert.Equal(CopyScenes.Alps, shell.Server.Sync.SearchText);
|
||||
CopyScenes.Reset(shell);
|
||||
|
||||
// Settings › Server: three rows, every option with its tooltip, each choice saved at once.
|
||||
var rows = shell.Settings.CopyRows;
|
||||
foreach (var option in rows.LinkingOptions.Cast<object>().Concat(rows.PhotoOptions).Concat(rows.ProjectOptions))
|
||||
{
|
||||
var (label, tip) = option switch
|
||||
{
|
||||
SettingsOption<CopyLinking> o => (o.Label, o.ToolTip),
|
||||
SettingsOption<CopyPhotoPolicy> o => (o.Label, o.ToolTip),
|
||||
SettingsOption<CopyProjects> o => (o.Label, o.ToolTip),
|
||||
_ => (string.Empty, null),
|
||||
};
|
||||
Assert.False(string.IsNullOrWhiteSpace(tip), $"{label} has a tooltip");
|
||||
Assert.LessOrEqual(label.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length, 3, $"\"{label}\" is at most three words");
|
||||
}
|
||||
rows.Linking = rows.LinkingOptions.First(o => o.Value == CopyLinking.WhenIdentical);
|
||||
Assert.Equal(CopyLinking.WhenIdentical, shell.Services.Settings.CopyLinking);
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
shell.Settings.Page = SettingsPage.Server;
|
||||
await app.ExpectAsync<SettingsView>("settings-server");
|
||||
Assert.Contains(app.FindAll<ComboBox>(), c => c.IsVisible && Equals(c.SelectedItem, rows.Linking) && c.ToolTip is not null);
|
||||
});
|
||||
|
||||
private static async Task<ScreenSmokeTests.SampleApp> StartAsync()
|
||||
{
|
||||
var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var shell = app.Shell;
|
||||
await app.Sample.FillAsync();
|
||||
await shell.Services.Server.RestoreAsync();
|
||||
Assert.NotNull(await shell.Services.Sync.RefreshAsync());
|
||||
await app.Sample.FillCopiesAsync();
|
||||
await shell.Library.RefreshAsync();
|
||||
await shell.Server.Sync.ReloadAsync();
|
||||
return app;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
using System.Globalization;
|
||||
using Chronos.App.Server;
|
||||
using Chronos.App.Server.Copies;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Copies;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Testing;
|
||||
using Chronos.Ui.Controls;
|
||||
|
||||
namespace Chronos.App.Tests.Server;
|
||||
|
||||
/// <summary>Words, glyphs and actions of a match (owner review 6, #73, design §8.1), and the sync rows a match marks.</summary>
|
||||
[Serial]
|
||||
public sealed class CopyTextTests
|
||||
{
|
||||
private const string Nas = "https://nas.local:8443";
|
||||
private static readonly CopyRights SignedIn = new(Nas, "Studio NAS", CanIntegrate: true, CanUpload: true);
|
||||
|
||||
private static readonly Sequence Local = new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
ArchiveId = Guid.CreateVersion7(),
|
||||
Title = "Lighthouse 2026-08-13",
|
||||
Folder = "2026/lighthouse",
|
||||
FrameCount = 1_204,
|
||||
TotalBytes = 18_200_000_000,
|
||||
Status = SequenceStatus.ProxiesBuilt,
|
||||
};
|
||||
|
||||
private static readonly SyncLink Link = new()
|
||||
{
|
||||
Server = Nas,
|
||||
RemoteId = Guid.CreateVersion7(),
|
||||
Title = "Lighthouse 2026-08-13",
|
||||
TotalBytes = 18_200_000_000,
|
||||
RemoteStatus = SequenceStatus.ProxiesBuilt,
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void EachStateOffersTheActionsOfTheTable()
|
||||
{
|
||||
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Integrate, CopyAction.KeepApart], CopyText.Actions(Copy(CopyState.Candidate)));
|
||||
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Merge, CopyAction.KeepApart], CopyText.Actions(Copy(CopyState.Candidate, CopyKind.LocalLocal)));
|
||||
Assert.SequenceEqual([CopyAction.Compare, CopyAction.AskAgain], CopyText.Actions(Copy(CopyState.KeptApart)));
|
||||
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Integrate, CopyAction.Unlink], CopyText.Actions(Copy(CopyState.Linked)));
|
||||
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Integrate, CopyAction.Unlink, CopyAction.Review],
|
||||
CopyText.Actions(Copy(CopyState.Linked, deletedThere: 3)));
|
||||
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Unlink], CopyText.Actions(Copy(CopyState.Integrated)));
|
||||
Assert.SequenceEqual([CopyAction.Compare, CopyAction.Unlink, CopyAction.Review], CopyText.Actions(Copy(CopyState.Integrated, deletedThere: 3)));
|
||||
Assert.SequenceEqual([CopyAction.Pause], CopyText.Actions(Copy(CopyState.Integrating), JobState.Running));
|
||||
Assert.SequenceEqual([CopyAction.Resume], CopyText.Actions(Copy(CopyState.Integrating), JobState.Paused));
|
||||
|
||||
// The server deleted its copy: keep it here, send it again or move it to the trash; once kept, only send again.
|
||||
Assert.SequenceEqual([CopyAction.KeepHere, CopyAction.UploadAgain, CopyAction.ToTrash], CopyText.Actions(Copy(CopyState.Linked, gone: true)));
|
||||
Assert.SequenceEqual([CopyAction.UploadAgain], CopyText.Actions(Copy(CopyState.KeptApart, gone: true)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheStateGlyphFollowsWhatThePairAsksFor()
|
||||
{
|
||||
Assert.Equal(StatusKind.Warning, CopyText.State(Copy(CopyState.Candidate)).Kind);
|
||||
Assert.Equal(StatusKind.Offline, CopyText.State(Copy(CopyState.KeptApart)).Kind);
|
||||
Assert.Equal(StatusKind.Synced, CopyText.State(Copy(CopyState.Linked)).Kind);
|
||||
Assert.Equal(StatusKind.Running, CopyText.State(Copy(CopyState.Integrating), progress: (3, 10)).Kind);
|
||||
Assert.Equal(StatusKind.Done, CopyText.State(Copy(CopyState.Integrated)).Kind);
|
||||
Assert.Equal((StatusKind.Warning, Loc.L("Server.Copies.State.DeletedThere", "3")),
|
||||
Head(CopyText.State(Copy(CopyState.Integrated, deletedThere: 3))));
|
||||
Assert.Equal((StatusKind.Warning, Loc.L("Server.Copies.State.DeletedOther", "3")),
|
||||
Head(CopyText.State(Copy(CopyState.Integrated, CopyKind.LocalLocal, deletedThere: 3))));
|
||||
Assert.Equal((StatusKind.Warning, Loc.L("Server.Copies.State.RemoteGone")), Head(CopyText.State(Copy(CopyState.Linked, gone: true))));
|
||||
Assert.Equal((StatusKind.Offline, Loc.L("Server.Copies.State.KeptHere")), Head(CopyText.State(Copy(CopyState.KeptApart, gone: true))));
|
||||
// The candidate's tooltip says how much the two share.
|
||||
Assert.Contains("98", CopyText.State(Copy(CopyState.Candidate)).ToolTip);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnActionThatCannotRunSaysWhy()
|
||||
{
|
||||
var candidate = Copy(CopyState.Candidate);
|
||||
Assert.Null(CopyText.Blocked(candidate, CopyAction.Integrate, SignedIn));
|
||||
// A pair of another server needs that server signed in; the answers that move nothing never do.
|
||||
var signedOut = new CopyRights(null, null, false, false);
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Copies.SignIn", Nas), CopyText.Blocked(candidate, CopyAction.Compare, signedOut));
|
||||
Assert.Null(CopyText.Blocked(candidate, CopyAction.KeepApart, signedOut));
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Copies.NeedsNewerServer"), CopyText.Blocked(candidate, CopyAction.Integrate, SignedIn with { CanIntegrate = false }));
|
||||
Assert.Equal(Loc.L("Errors.Copies.Busy"), CopyText.Blocked(candidate, CopyAction.Integrate, SignedIn with { Busy = true }));
|
||||
Assert.Null(CopyText.Blocked(candidate, CopyAction.Compare, SignedIn with { Busy = true }));
|
||||
var gone = Copy(CopyState.Linked, gone: true);
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Sync.UploadAll.NoRight"), CopyText.Blocked(gone, CopyAction.UploadAgain, SignedIn with { CanUpload = false }));
|
||||
// A local pair needs no server.
|
||||
Assert.Null(CopyText.Blocked(Copy(CopyState.Candidate, CopyKind.LocalLocal), CopyAction.Merge, signedOut));
|
||||
// The tooltip of a disabled button is its reason.
|
||||
Assert.Equal(Loc.L("Errors.Copies.Busy"), CopyText.ToolTip(candidate, CopyAction.Integrate, SignedIn with { Busy = true }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AttentionComesFirstThenTheStrongerHints()
|
||||
{
|
||||
var kept = View(Copy(CopyState.KeptApart) with { Score = Score(hints: 900) }, "Aurora");
|
||||
var weak = View(Copy(CopyState.Candidate) with { Score = Score(hints: 100) }, "Bridge");
|
||||
var strong = View(Copy(CopyState.Candidate) with { Score = Score(hints: 800) }, "Comet");
|
||||
Assert.SequenceEqual(["Comet", "Bridge", "Aurora"], CopyText.Sorted([kept, weak, strong]).Select(p => p.Here.Title));
|
||||
Assert.True(CopyText.Matches(strong, "com"));
|
||||
Assert.True(CopyText.Matches(strong, "Comet (nas)"));
|
||||
Assert.False(CopyText.Matches(strong, "Aurora"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EveryWordResolvesInEnglishAndItalianAndLabelsStayShort()
|
||||
{
|
||||
var missing = new List<string>();
|
||||
void OnMissing(string key) => missing.Add(key);
|
||||
Loc.MissingKey += OnMissing;
|
||||
try
|
||||
{
|
||||
foreach (var culture in new[] { "en", "it" })
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo(culture));
|
||||
var gone = Copy(CopyState.Linked, gone: true);
|
||||
foreach (var action in Enum.GetValues<CopyAction>())
|
||||
{
|
||||
var label = CopyText.Label(action);
|
||||
Assert.LessOrEqual(label.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length, 3, $"{culture}: \"{label}\" is at most three words");
|
||||
Assert.False(string.IsNullOrWhiteSpace(CopyText.ToolTip(gone, action, SignedIn)), $"{culture}: {action} has a tooltip");
|
||||
}
|
||||
foreach (var c in Enum.GetValues<PhotoClass>())
|
||||
{
|
||||
Assert.False(string.IsNullOrWhiteSpace(CopyText.Class(c)), $"{culture}: {c}");
|
||||
Assert.False(string.IsNullOrWhiteSpace(CopyText.ClassToolTip(c)), $"{culture}: {c} has a tooltip");
|
||||
}
|
||||
foreach (var block in Enum.GetValues<CopyBlock>())
|
||||
Assert.False(string.IsNullOrWhiteSpace(CopyText.Block(block, "Lighthouse", "Studio NAS", "2 GB", 2)), $"{culture}: {block}");
|
||||
foreach (var state in Enum.GetValues<CopyState>())
|
||||
{
|
||||
foreach (var copy in new[] { Copy(state), Copy(state, deletedThere: 2), Copy(state, gone: true), Copy(state, CopyKind.LocalLocal, deletedThere: 2) })
|
||||
{
|
||||
var (_, text, tip) = CopyText.State(copy, "Studio NAS", (1, 4));
|
||||
Assert.False(string.IsNullOrWhiteSpace(text) || string.IsNullOrWhiteSpace(tip), $"{culture}: {state}");
|
||||
}
|
||||
}
|
||||
foreach (var why in Enum.GetValues<UploadSkip>())
|
||||
Assert.False(string.IsNullOrWhiteSpace(SyncText.State(Entry(SyncStatus.LocalOnly, link: null), new SyncMark(null, why)).ToolTip), $"{culture}: {why}");
|
||||
Assert.False(string.IsNullOrWhiteSpace(SyncText.ToolTip(Entry(SyncStatus.InSync), SyncAction.Compare)), $"{culture}: Compare has a tooltip");
|
||||
Assert.Equal(Loc.L("Server.Copies.Detail.OtherSetting"), SyncText.DetailLabel("nothing.known"));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.MissingKey -= OnMissing;
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
Assert.Empty(missing);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ASyncRowInAMatchSaysSoAndOffersCompare()
|
||||
{
|
||||
var entry = Entry(SyncStatus.LocalOnly, link: null);
|
||||
// The Matches chip lists pairs, never sync rows.
|
||||
Assert.False(SyncText.Matches(entry, SyncFilter.FoundCopies, string.Empty));
|
||||
|
||||
var editor = SyncRights.Of((long)RolePermissions.Default(UserRole.Editor));
|
||||
var candidate = new SyncMark(Copy(CopyState.Candidate), null, "Studio NAS");
|
||||
var (kind, text, tip) = SyncText.State(entry, candidate);
|
||||
Assert.Equal((StatusKind.Warning, Loc.L("Server.Sync.State.CopyFound")), (kind, text));
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Sync.State.CopyFound", "Studio NAS"), tip);
|
||||
Assert.SequenceEqual([SyncAction.Compare, SyncAction.Upload], SyncText.Actions(entry, editor, candidate));
|
||||
|
||||
// A linked row offers Compare last; one without a pair, nothing more.
|
||||
var linked = Entry(SyncStatus.InSync);
|
||||
Assert.SequenceEqual([SyncAction.Compare], SyncText.Actions(linked, editor, new SyncMark(Copy(CopyState.Linked), null)));
|
||||
Assert.Empty(SyncText.Actions(linked, editor, default));
|
||||
|
||||
// Deleted on the server, or kept here after that.
|
||||
Assert.Equal(Loc.L("Server.Sync.State.RemoteGone"), SyncText.State(linked, new SyncMark(Copy(CopyState.Linked, gone: true), null)).Text);
|
||||
Assert.Equal(Loc.L("Server.Sync.State.KeptHere"), SyncText.State(linked, new SyncMark(Copy(CopyState.KeptApart, gone: true), null)).Text);
|
||||
|
||||
// Upload all local left it out: "skipped", with the reason.
|
||||
var skipped = SyncText.State(entry, new SyncMark(null, UploadSkip.KeptApart));
|
||||
Assert.Equal((StatusKind.Offline, Loc.L("Server.Sync.State.Skipped")), (skipped.Kind, skipped.Text));
|
||||
Assert.Equal(Loc.L("Tooltips.Server.Sync.State.Skipped", Loc.L("Tooltips.Server.Sync.Skip.KeptApart")), skipped.ToolTip);
|
||||
// A transfer still shows first.
|
||||
var upload = new Job { Id = Guid.CreateVersion7(), Kind = JobKind.UploadCommit, State = JobState.Running };
|
||||
Assert.Equal(SyncText.State(entry with { Transfer = upload }), SyncText.State(entry with { Transfer = upload }, candidate));
|
||||
}
|
||||
|
||||
private static (StatusKind, string) Head((StatusKind Kind, string Text, string ToolTip) state) => (state.Kind, state.Text);
|
||||
|
||||
private static FoundCopy Copy(CopyState state, CopyKind kind = CopyKind.LocalServer, int deletedThere = 0, bool gone = false) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
Kind = kind,
|
||||
LocalId = Local.Id,
|
||||
Server = kind == CopyKind.LocalServer ? Nas : null,
|
||||
RemoteId = kind == CopyKind.LocalServer ? Link.RemoteId : null,
|
||||
OtherId = kind == CopyKind.LocalLocal ? Guid.CreateVersion7() : null,
|
||||
Evidence = CopyEvidence.Hashes,
|
||||
State = state,
|
||||
Score = Score(deletedThere: deletedThere),
|
||||
Fingerprint = "f",
|
||||
RemoteGoneHits = gone ? 2 : 0,
|
||||
UpdatedAt = new DateTimeOffset(2026, 11, 16, 9, 0, 0, TimeSpan.Zero),
|
||||
};
|
||||
|
||||
private static CopyScore Score(int deletedThere = 0, int hints = 500) =>
|
||||
new(1_178, 0, 0, 24, 0, 2, 0, deletedThere, 0, 1_204, 1_180, 980, 960, hints);
|
||||
|
||||
private static FoundCopyView View(FoundCopy copy, string title) =>
|
||||
new(copy, Facts(title, "Main archive", 1_204), Facts(title + " (nas)", "Studio NAS", 1_180));
|
||||
|
||||
private static CopyFacts Facts(string title, string where, int photos) =>
|
||||
new(title, where, null, photos, photos * 15_000_000L, null, null, null, photos, null, [], false);
|
||||
|
||||
private static SyncEntry Entry(SyncStatus status, SyncLink? link = null) =>
|
||||
new(Local, status == SyncStatus.LocalOnly ? link : link ?? Link, status, null);
|
||||
}
|
||||
Reference in new issue
Block a user