Titano: Library completion, remote editing, accessibility and RTL pass, remaining translations #3

Merged
Alby96 merged 117 commits from claude/keen-knuth-uhxv8w into main 2026-10-12 09:24:21 +02:00
4 changed files with 76 additions and 10 deletions
Showing only changes of commit afaa387daf - Show all commits

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
using Titano.Core.Model;
using Titano.Core.Project;
using Titano.Data.Repositories;
namespace Titano.Data.Processing;
/// <summary>
/// The index's hero frame (<see cref="Sequence.HeroFrameId"/>, the frame the Library shows) follows the project's hero
/// (<see cref="ProjectSettings.HeroFrame"/>, a frame index; frame indices are positions).
/// </summary>
public static class HeroFrame
{
/// <summary>
/// The <see cref="SequenceEdit.HeroFrameId"/> of a project whose hero went from <paramref name="before"/> to
/// <paramref name="after"/>: null when it did not change, else the frame at the new index, or <see cref="Guid.Empty"/>
/// (the first frame shows) when there is none.
/// </summary>
public static async Task<Guid?> EditAsync(TitanoDatabase db, Guid sequenceId, int? before, int? after, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(db);
if (before == after) return null;
if (after is not >= 0) return Guid.Empty;
var frames = await db.Frames.ListBySequenceAsync(sequenceId, after.Value - 1, 1, cancellationToken).ConfigureAwait(false);
return frames is [{ } frame] && frame.Index == after ? frame.Id : Guid.Empty;
}
}
+1 -9
View File
@@ -53,7 +53,7 @@ internal sealed class ProjectStore(TitanoDatabase db, SequenceWriter writer)
if (after == before) return false;
AtomicFile.WriteAllText(folder.ProjectPath, after);
// The Library shows the project's hero frame (advice fills it, a sync takes another PC's).
var hero = edited.HeroFrame == current.HeroFrame ? (Guid?)null : await HeroFrameIdAsync(sequence.Id, edited.HeroFrame, cancellationToken).ConfigureAwait(false);
var hero = await HeroFrame.EditAsync(db, sequence.Id, current.HeroFrame, edited.HeroFrame, cancellationToken).ConfigureAwait(false);
var result = await db.Sequences.EditAsync(sequence.Id, new SequenceEdit { SettingsJson = after, HeroFrameId = hero }, row.SettingsVersion,
cancellationToken).ConfigureAwait(false);
// A conflict means the API changed the settings meanwhile: apply the edit again on top of them.
@@ -61,12 +61,4 @@ internal sealed class ProjectStore(TitanoDatabase db, SequenceWriter writer)
}
}
}
/// <summary>The id of the frame at <paramref name="index"/> (frame indices are positions), or <see cref="Guid.Empty"/> to clear the hero.</summary>
private async Task<Guid> HeroFrameIdAsync(Guid sequenceId, int? index, CancellationToken cancellationToken)
{
if (index is not >= 0) return Guid.Empty;
var frames = await db.Frames.ListBySequenceAsync(sequenceId, index.Value - 1, 1, cancellationToken).ConfigureAwait(false);
return frames is [{ } frame] && frame.Index == index ? frame.Id : Guid.Empty;
}
}
+22 -1
View File
@@ -3,7 +3,9 @@ using System.Globalization;
using System.Text;
using System.Text.Json;
using Titano.Core.Model;
using Titano.Core.Project;
using Titano.Data;
using Titano.Data.Processing;
using Titano.Data.Repositories;
using Titano.Protocol;
using Titano.Server.Configuration;
@@ -131,7 +133,9 @@ public static class SequenceEndpoints
Rating = request.Rating,
Notes = request.Notes,
SettingsJson = request.SettingsJson,
HeroFrameId = request.HeroFrameId,
// A client that sends only the settings (the sync of a local copy) moves the hero frame with the project's hero.
HeroFrameId = request.HeroFrameId
?? (request.SettingsJson is { } settings ? await SettingsHeroAsync(db, id, settings, context.RequestAborted) : null),
};
var result = await db.Sequences.EditAsync(id, edit, expected, context.RequestAborted);
switch (result.Outcome)
@@ -293,6 +297,22 @@ public static class SequenceEndpoints
return false;
}
/// <summary>The hero frame edit of new settings: the frame of their hero when it is not the stored settings' hero.</summary>
private static async Task<Guid?> SettingsHeroAsync(TitanoDatabase db, Guid id, string settingsJson, CancellationToken ct)
{
if (await db.Sequences.GetAsync(id, ct) is not { } current) return null;
try
{
var before = string.IsNullOrWhiteSpace(current.SettingsJson) ? null : ProjectSettings.FromJson(current.SettingsJson).HeroFrame;
return await HeroFrame.EditAsync(db, id, before, ProjectSettings.FromJson(settingsJson).HeroFrame, ct);
}
catch (Exception ex) when (ex is JsonException or InvalidDataException)
{
// Not a project of this Titano (a newer one, or free JSON): its hero is unknown here, the stored one stays.
return null;
}
}
private static bool IsJson(string text)
{
try
@@ -314,6 +334,7 @@ public static class SequenceEndpoints
if (r.Rating is not null) fields.Add("rating");
if (r.Notes is not null) fields.Add("notes");
if (r.SettingsJson is not null) fields.Add("settings");
if (r.HeroFrameId is not null) fields.Add("hero");
return string.Join(", ", fields);
}
@@ -73,6 +73,33 @@ public sealed class RemoteEditingTests(TestContext context)
Assert.Null(cleared.HeroFrameId);
}
[Test]
public async Task SettingsAloneMoveTheHeroFrameWithTheProjectsHero()
{
await using var server = await TestServer.StartAsync(context);
var (editor, _, token) = await server.UserAsync("alberto", "editor");
using var client = Client(server, token);
await Uploads.UploadAsync(editor, Uploads.Photo(2000, 46), "a.CR3", sessionKey: "pier");
var second = await Uploads.UploadAsync(editor, Uploads.Photo(2000, 47), "b.CR3", sessionKey: "pier");
var id = second.SequenceId;
var read = await client.GetSequenceAsync(id, context.Cancellation);
// The sync of a local copy sends the project only.
var project = new ProjectSettings { HeroFrame = second.Index };
var hero = await client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, project.ToJson(), read.SettingsVersion),
context.Cancellation);
Assert.Equal(second.FrameId, hero.HeroFrameId);
var exposure = project with { Exposure = project.Exposure with { ExposureOffsetEv = 0.3 } };
var kept = await client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, exposure.ToJson(), hero.SettingsVersion),
context.Cancellation);
Assert.Equal(second.FrameId, kept.HeroFrameId, "other changes keep the hero");
var cleared = await client.UpdateSequenceAsync(id, new UpdateSequenceRequest(null, null, null, null, (exposure with { HeroFrame = null }).ToJson(),
kept.SettingsVersion), context.Cancellation);
Assert.Null(cleared.HeroFrameId, "no hero shows the first frame");
}
[Test]
public async Task JobsPostedOnePerPresetReadBackAsTheClientsJobs()
{