feat(jobs): show what mass passes do now on the desktop, the server section and the admin panel
A running job now says what it does now: "Verifying photo 812 of 2,400 · Harbour sunset · sequence 3 of 41". A paused or failed job says where it stopped. The line appears in the Jobs table under the target, in the job bar (at most 60 characters, the item dropped first, the bar text also its tooltip), in the Archive's recent maintenance (refreshed at most twice a second), in the editor's server-job line and in the sync tooltip. Byte jobs now count sizes in the bar. While connected, the Server section lists the server's running and paused jobs, live through the jobs API and the jobProgress events. Pause, Resume and Cancel are offered only to an account that manages the archive, which is what the server requires to act on someone else's job; for any other account the list is read-only. The list hides while nothing runs, and the capture gains a server-jobs scene. The admin panel's Jobs page and dashboard show the same line under the target and update it with every progress event. The steps, parts and sub-steps are in English and Italian, and an unknown step shows its counts only. Refs #65 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ee9505df22
commit
b95bc997d5
36 files changed
+1895
-28
No files matched your search
@@ -32,6 +32,12 @@ public sealed class JobEntry(Job job)
|
||||
public TimeSpan? Eta => Live?.Eta ?? Job.Eta;
|
||||
public string? Message => Live?.Message;
|
||||
|
||||
/// <summary>
|
||||
/// What the job does now (owner review 5, #65): the live detail while it runs, else the one stored with its last saved
|
||||
/// progress (where a paused or failed job stopped); null when its handler reports none.
|
||||
/// </summary>
|
||||
public JobDetail? Detail => Live?.Detail ?? Job.Detail;
|
||||
|
||||
/// <summary>0…1, or null while the total is unknown.</summary>
|
||||
public double? Fraction => Total > 0 ? Math.Clamp((double)Done / Total, 0, 1) : null;
|
||||
|
||||
|
||||
@@ -36,6 +36,17 @@ public sealed class JobRowViewModel : ObservableObject
|
||||
|
||||
public string Target => _entry.Job.TargetLabel ?? string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// What a running job does now, or where a paused or failed job stopped (owner review 5, #65), under the target; empty
|
||||
/// otherwise. Not announced: a screen reader hears state changes only (DECISIONS row 158).
|
||||
/// </summary>
|
||||
public string StatusText => JobText.RowStatus(_entry);
|
||||
|
||||
public bool HasStatus => StatusText.Length > 0;
|
||||
|
||||
/// <summary>The status line whole, then the speed and time left of a running job.</summary>
|
||||
public string StatusToolTip => JobText.RowStatusToolTip(_entry);
|
||||
|
||||
/// <summary>A schedule queued the job (owner review 2, R10): the row shows a "Scheduled" pill.</summary>
|
||||
public bool IsScheduled => _entry.Job.ScheduleId is not null;
|
||||
|
||||
@@ -136,6 +147,9 @@ public sealed class JobRowViewModel : ObservableObject
|
||||
return;
|
||||
}
|
||||
OnPropertyChanged(nameof(Progress));
|
||||
OnPropertyChanged(nameof(StatusText));
|
||||
OnPropertyChanged(nameof(HasStatus));
|
||||
OnPropertyChanged(nameof(StatusToolTip));
|
||||
OnPropertyChanged(nameof(PercentText));
|
||||
OnPropertyChanged(nameof(SpeedText));
|
||||
OnPropertyChanged(nameof(LeftText));
|
||||
|
||||
@@ -29,6 +29,141 @@ public static class JobText
|
||||
public static string Counter(long done, long total) =>
|
||||
total > 0 ? Loc.L("Jobs.Counter", Formatting.Count(done), Formatting.Count(total)) : string.Empty;
|
||||
|
||||
/// <summary>"1,240 / 3,600", or "52 GB / 1.1 TB" for a job that counts bytes; empty while the total is unknown.</summary>
|
||||
public static string Counter(JobKind kind, long done, long total) => total <= 0 ? string.Empty
|
||||
: CountsBytes(kind) ? Loc.L("Jobs.Counter", Formatting.Bytes(done), Formatting.Bytes(total))
|
||||
: Counter(done, total);
|
||||
|
||||
/// <summary>The longest status line the job bar shows (<see cref="Bar"/>); the item goes first, the full line is in the Jobs table.</summary>
|
||||
public const int BarStatusLength = 60;
|
||||
|
||||
/// <summary>
|
||||
/// What a job does now (owner review 5, #65), from its <paramref name="detail"/>: the step ("Verifying photo 812 of 2,400"),
|
||||
/// the item ("Harbour sunset", a folder kept left to right) and the part ("sequence 3 of 41"), each left out when empty;
|
||||
/// a clean-up or maintenance sub-step names itself in place of the step. A step this build does not know (a newer server)
|
||||
/// shows its counts only. Empty for no detail.
|
||||
/// </summary>
|
||||
public static string Status(JobDetail? detail) => Status(detail, int.MaxValue);
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="Status(JobDetail?)"/> in at most <paramref name="maxLength"/> characters: a longer line drops the item
|
||||
/// first, then is cut with an ellipsis.
|
||||
/// </summary>
|
||||
public static string Status(JobDetail? detail, int maxLength)
|
||||
{
|
||||
if (detail is null) return string.Empty;
|
||||
var (step, consumed) = StepPhrase(detail);
|
||||
var item = consumed ? null : ItemText(detail.Item);
|
||||
var part = PartPhrase(detail);
|
||||
var full = JoinParts(step, item, part);
|
||||
if (full.Length <= maxLength) return full;
|
||||
if (item is not null && JoinParts(step, null, part) is { Length: > 0 } shorter) full = shorter;
|
||||
return Cut(full, maxLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The status line of a Jobs row: what a running job does now; "Stopped at …" with where a paused or failed job stopped;
|
||||
/// empty for queued and finished jobs, and for a job whose handler reports no detail.
|
||||
/// </summary>
|
||||
public static string RowStatus(JobEntry entry)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(entry);
|
||||
return entry.State switch
|
||||
{
|
||||
JobState.Running => Status(entry.Detail),
|
||||
JobState.Paused or JobState.Failed when Status(entry.Job.Detail) is { Length: > 0 } status => Loc.L("Jobs.Detail.StoppedAt", status),
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The tooltip of a row's status line: the line whole, then the speed and the time left while the job runs.</summary>
|
||||
public static string RowStatusToolTip(JobEntry entry)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(entry);
|
||||
var parts = new List<string>(3);
|
||||
if (RowStatus(entry) is { Length: > 0 } status) parts.Add(status);
|
||||
if (entry.State == JobState.Running)
|
||||
{
|
||||
if (Speed(entry.Job.Kind, entry.ItemsPerSecond) is { Length: > 0 } speed) parts.Add(speed);
|
||||
if (entry.Eta is { } eta) parts.Add(Loc.L("Jobs.Bar.Left", Formatting.Duration(eta)));
|
||||
}
|
||||
return string.Join(Loc.Separator, parts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The step phrase, counted when the item is ("Verifying photo 812 of 2,400"), and whether it took the item's place (the
|
||||
/// named sub-step of a clean-up or maintenance).
|
||||
/// </summary>
|
||||
private static (string? Phrase, bool ConsumedItem) StepPhrase(JobDetail detail)
|
||||
{
|
||||
var counted = detail.ItemTotal > 0;
|
||||
var done = Formatting.Count(Math.Clamp(detail.ItemDone, 0, detail.ItemTotal));
|
||||
var total = Formatting.Count(detail.ItemTotal);
|
||||
var counts = counted ? Loc.L("Jobs.Detail.Count", done, total) : null;
|
||||
// A clean-up step ("job-history") and a maintenance step ("packs") name themselves.
|
||||
var named = detail.Step switch
|
||||
{
|
||||
JobStep.Cleanup => Known("Jobs.Schedule.Step." + Pascal(detail.Item)),
|
||||
JobStep.Maintenance => Known("Jobs.Maintenance.Step." + Pascal(detail.Item)),
|
||||
_ => null,
|
||||
};
|
||||
if (named is not null) return (JoinParts(Loc.L(named), counts, null), true);
|
||||
if (detail.Step == JobStep.None) return (counts, false);
|
||||
var key = "Jobs.Step." + detail.Step;
|
||||
// The item of a clean-up or maintenance step is a key, not data: one this build does not know is never shown.
|
||||
if (detail.Step is JobStep.Cleanup or JobStep.Maintenance) return (JoinParts(Known(key) is { } step ? Loc.L(step) : null, counts, null), true);
|
||||
if (counted && Known(key + ".Count") is { } countKey) return (Loc.L(countKey, done, total), false);
|
||||
if (Known(key) is null) return (counts, false);
|
||||
return (JoinParts(Loc.L(key), counts, null), false);
|
||||
}
|
||||
|
||||
/// <summary>"sequence 3 of 41" when the job has more than one part; null otherwise.</summary>
|
||||
private static string? PartPhrase(JobDetail detail)
|
||||
{
|
||||
if (detail.Parts <= 1) return null;
|
||||
var part = Formatting.Count(Math.Clamp(detail.Part, 0, detail.Parts));
|
||||
var parts = Formatting.Count(detail.Parts);
|
||||
return detail.PartUnit != JobPartUnit.None && Known("Jobs.Part." + detail.PartUnit) is { } key
|
||||
? Loc.L(key, part, parts)
|
||||
: Loc.L("Jobs.Detail.Count", part, parts);
|
||||
}
|
||||
|
||||
/// <summary>The item as data: a folder or a path kept left to right inside right-to-left text (DECISIONS row 218).</summary>
|
||||
private static string? ItemText(string? item)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(item)) return null;
|
||||
return item.Contains('/') || item.Contains('\\') ? Formatting.LeftToRight(item) : item;
|
||||
}
|
||||
|
||||
/// <summary>"job-history" → "JobHistory"; null for a key that is not one (data from a newer peer).</summary>
|
||||
private static string? Pascal(string? key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key) || key.Length > 40 || !key.All(c => char.IsAsciiLetterOrDigit(c) || c is '-' or '_')) return null;
|
||||
return string.Concat(key.Split('-', '_', StringSplitOptions.RemoveEmptyEntries).Select(p => char.ToUpperInvariant(p[0]) + p[1..]));
|
||||
}
|
||||
|
||||
/// <summary>The key when the catalog has it (the step, unit or sub-step of a newer peer may have none); null otherwise.</summary>
|
||||
private static string? Known(string? key) => key is not null && !key.EndsWith('.') && Loc.Get(key, Loc.Culture) is not null ? key : null;
|
||||
|
||||
private static string JoinParts(string? a, string? b, string? c)
|
||||
{
|
||||
var pieces = new List<string>(3);
|
||||
if (!string.IsNullOrEmpty(a)) pieces.Add(a);
|
||||
if (!string.IsNullOrEmpty(b)) pieces.Add(b);
|
||||
if (!string.IsNullOrEmpty(c)) pieces.Add(c);
|
||||
return string.Join(Loc.Separator, pieces);
|
||||
}
|
||||
|
||||
/// <summary>Cuts <paramref name="text"/> to <paramref name="max"/> characters with an ellipsis, closing a left-to-right island it cut into.</summary>
|
||||
private static string Cut(string text, int max)
|
||||
{
|
||||
if (text.Length <= max) return text;
|
||||
var length = Math.Max(1, max - 1);
|
||||
if (char.IsHighSurrogate(text[length - 1])) length--;
|
||||
var cut = text[..length] + "…";
|
||||
return cut.Count(c => c == '') > cut.Count(c => c == '') ? cut + "" : cut;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The "Left" column: time left while running, "after n" while queued, the finish time of the history.
|
||||
/// </summary>
|
||||
@@ -71,13 +206,17 @@ public static class JobText
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Job bar line (DESIGN §4): "Render · Harbour sunset · 2,232 / 3,600 · 11.3 fps · 2 min left".
|
||||
/// Job bar line (DESIGN §4): "Render · Harbour sunset · 2,232 / 3,600 · 11.3 fps · 2 min left"; with a detail, what the
|
||||
/// job does now in place of the counter ("Scan · Archive 2024 · Indexing photo 1,240 of 3,600 · folder 12 of 340 · 41/s ·
|
||||
/// 3 min left", at most <see cref="BarStatusLength"/> characters of it); a job that counts bytes shows sizes.
|
||||
/// </summary>
|
||||
public static string Bar(JobEntry entry)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(entry);
|
||||
var parts = new List<string>(5) { Kind(entry.Job.Kind) };
|
||||
if (!string.IsNullOrWhiteSpace(entry.Job.TargetLabel)) parts.Add(entry.Job.TargetLabel!);
|
||||
if (Counter(entry.Done, entry.Total) is { Length: > 0 } counter) parts.Add(counter);
|
||||
if (Status(entry.Detail, BarStatusLength) is { Length: > 0 } status) parts.Add(status);
|
||||
else if (Counter(entry.Job.Kind, entry.Done, entry.Total) is { Length: > 0 } counter) parts.Add(counter);
|
||||
if (Speed(entry.Job.Kind, entry.ItemsPerSecond) is { Length: > 0 } speed) parts.Add(speed);
|
||||
if (entry.Eta is { } eta) parts.Add(Loc.L("Jobs.Bar.Left", Formatting.Duration(eta)));
|
||||
return string.Join(Loc.Separator, parts);
|
||||
|
||||
Reference in new issue
Block a user