Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+aufgaben-set-reminder-time.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An Aufgabe being edited takes the minutes until its reminder directly, shorter or longer than before and also on an Aufgabe without a timer, next to the "+5 MIN" button (#964).
16 changes: 13 additions & 3 deletions src/LageBuch.App.Shared/Views/TasksView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,23 @@
FilterMode="ContainsOrdinal" MinimumPrefixLength="0"
Text="{Binding EditAssignee}" />
</HeaderedContentControl>
<!-- The timer is not a field here: +5 MIN acts at once and the countdown beside it
moves, so there is nothing to save and nothing to get wrong. -->
<HeaderedContentControl Classes="field" Header="TIMER">
<!-- The time until the reminder is typed in minutes from now (#964), shorter or longer
than before, and SETZEN applies it at once, as +5 MIN does; the countdown beside
them moves. SPEICHERN takes a typed time along too, so it never vanishes with the
panel. The box opens on the minutes left, and empty without a timer. -->
<HeaderedContentControl Classes="field" Header="TIMER (MIN)"
Classes.invalid="{Binding EditTimerMinutesError, Converter={x:Static ObjectConverters.IsNotNull}}">
<StackPanel Orientation="Horizontal" Spacing="8">
<TextBlock x:Name="EditRemaining" VerticalAlignment="Center" MinWidth="72"
Text="{Binding EditingTask.RemainingDisplay, FallbackValue=''}"
Classes.due="{Binding EditingTask.IsOverdue, FallbackValue=False}" />
<TextBox x:Name="EditTimerBox" Width="70" Text="{Binding EditTimerMinutes}" b:IntegerOnly.IsEnabled="True"
AutomationProperties.Name="Erinnerung in Minuten"
ToolTip.Tip="Minuten bis zur Erinnerung, ab jetzt"
b:EnterSubmit.Command="{Binding SetEditingTimerCommand}" />
<Button x:Name="EditSetTimerButton" Content="SETZEN"
ToolTip.Tip="Erinnerung in so vielen Minuten"
Command="{Binding SetEditingTimerCommand}" />
<Button x:Name="EditExtendTimerButton" Content="+5 MIN"
ToolTip.Tip="Timer um 5 Minuten verlängern"
Command="{Binding ExtendEditingTimerCommand}" />
Expand Down
3 changes: 3 additions & 0 deletions src/LageBuch.AppLogic/LocalIncidentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ public void UpdateTask(Guid taskId, string text, string? assignee, TaskImportanc
public void ExtendTaskTimer(Guid taskId, int minutes) =>
Mutate(() => Incident.ExtendTaskTimer(taskId, minutes, _clock));

public void SetTaskTimer(Guid taskId, int minutes) =>
Mutate(() => Incident.SetTaskTimer(taskId, minutes, _clock));

public void AddScbaTrupp(
string designation,
IEnumerable<TruppMember> members,
Expand Down
95 changes: 89 additions & 6 deletions src/LageBuch.AppLogic/ViewModels/TasksViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,25 @@ private void ShowErrors(bool shown)
[NotifyPropertyChangedFor(nameof(ShowComposerButton))]
[NotifyCanExecuteChangedFor(nameof(SaveEditCommand))]
[NotifyCanExecuteChangedFor(nameof(ExtendEditingTimerCommand))]
[NotifyCanExecuteChangedFor(nameof(SetEditingTimerCommand))]
private TaskRow? _editingTask;

// Quiet until SETZEN (or SPEICHERN with a typed time) is pressed, like the text.
private bool _editTimerErrorShown;

// What the minutes box was last filled with, so SPEICHERN applies only a time someone typed:
// the countdown runs on while the panel is open, and an untouched box must not reset it.
private int? _editTimerPrefill;

/// <summary>
/// The minutes until the reminder, typed into the panel (#964). Opens on the minutes left,
/// rounded up, and empty when there is no timer or it has already run out.
/// </summary>
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(EditTimerMinutesError))]
[NotifyPropertyChangedFor(nameof(EditErrorSummary))]
private int? _editTimerMinutes;

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(EditTextError))]
[NotifyPropertyChangedFor(nameof(EditErrorSummary))]
Expand All @@ -333,7 +350,32 @@ private void ShowErrors(bool shown)
_editErrorsShown && string.IsNullOrWhiteSpace(EditText) ? ValidationMessages.Required : null;

/// <summary>Everything the edit panel is still waiting on, on one line beneath its fields (#412).</summary>
public string? EditErrorSummary => ValidationMessages.Summarize(EditTextError);
public string? EditErrorSummary => ValidationMessages.Summarize(EditTextError, EditTimerMinutesError);

/// <summary>Whether the minutes box holds no usable time, once SETZEN has been pressed (#964).</summary>
public string? EditTimerMinutesError =>
_editTimerErrorShown && !IsUsableTimer(EditTimerMinutes) ? ValidationMessages.ReminderMinutes : null;

private static bool IsUsableTimer(int? minutes) => minutes is >= 1 and <= IncidentTask.MaxTimerMinutes;

// The minutes left on the task, rounded up so a box that says 11 never rings in ten and a half.
private int? RemainingMinutes(Guid taskId)
{
var task = _session.Incident.Tasks.FirstOrDefault(t => t.Id == taskId);
if (task is null || task.DueAt == DateTimeOffset.MaxValue)
{
return null;
}

var left = task.DueAt - _clock.Now;
return left > TimeSpan.Zero ? (int)Math.Ceiling(left.TotalMinutes) : null;
}

private void PrefillTimer(Guid taskId)
{
_editTimerPrefill = RemainingMinutes(taskId);
EditTimerMinutes = _editTimerPrefill;
}

// A done task is history, as on the ETB: reopen it first.
private bool CanEdit(TaskRow row) => !IsReadOnly && !row.IsDone;
Expand All @@ -344,6 +386,7 @@ private void BeginEdit(TaskRow row)
EditAssignee = string.IsNullOrEmpty(row.Assignee) ? null : row.Assignee;
EditImportance = row.Importance;
EditUrgency = row.Urgency;
PrefillTimer(row.Id);
ShowEditErrors(false); // a freshly opened panel starts quiet
EditingTask = row;
SelectedTask = row; // the grid's selection marks the row the panel is about
Expand All @@ -354,8 +397,11 @@ private void BeginEdit(TaskRow row)
[RelayCommand(CanExecute = nameof(CanSaveEdit))]
private void SaveEdit()
{
ShowEditErrors(true);
if (EditTextError is not null || EditingTask is not { } row)
// A time typed but not yet SETZEN-ed goes with the save, rather than vanishing with the panel.
var timerTyped = EditTimerMinutes != _editTimerPrefill;
var timer = timerTyped ? EditTimerMinutes : null;
ShowEditErrors(true, showTimerError: timerTyped);
if (EditTextError is not null || EditTimerMinutesError is not null || EditingTask is not { } row)
{
return;
}
Expand All @@ -375,6 +421,12 @@ private void SaveEdit()
_session.UpdateTask(row.Id, text, assignee, importance, urgency);
_onChanged();
}

if (timer is { } minutes)
{
_session.SetTaskTimer(row.Id, minutes);
_onChanged();
}
}

[RelayCommand]
Expand All @@ -383,11 +435,36 @@ private void CancelEdit()
EditingTask = null;
EditText = string.Empty;
EditAssignee = null;
EditTimerMinutes = null;
_editTimerPrefill = null;
ShowEditErrors(false);
}

private bool CanExtendEditingTimer => !IsReadOnly && EditingTask is { HasTimer: true, IsDone: false };

// Unlike +5 MIN this needs no timer to start from: typing one gives the task its first.
private bool CanSetEditingTimer => !IsReadOnly && EditingTask is { IsDone: false };

/// <summary>
/// The panel's SETZEN (#964): replaces the time until the reminder with the typed minutes,
/// counted from now, shorter or longer than before. An action like +5 MIN, so it applies at once
/// and leaves the panel open; a box with no usable time says so and changes nothing.
/// </summary>
[RelayCommand(CanExecute = nameof(CanSetEditingTimer))]
private void SetEditingTimer()
{
ShowEditErrors(_editErrorsShown, showTimerError: true);
if (EditingTask is not { } row || EditTimerMinutes is not { } minutes || !IsUsableTimer(minutes))
{
return;
}

_session.SetTaskTimer(row.Id, minutes);
_onChanged();
_editTimerPrefill = minutes; // what the box says is now what is set
ShowEditErrors(_editErrorsShown, showTimerError: false);
}

/// <summary>
/// The panel's +5 MIN: an action rather than a field, so it applies at once and leaves the
/// panel open. An overdue task is put off from now, not from its passed due time.
Expand All @@ -402,12 +479,15 @@ private void ExtendEditingTimer()

_session.ExtendTaskTimer(row.Id, ExtendMinutes);
_onChanged();
PrefillTimer(row.Id); // the box follows, so a SPEICHERN after it does not take the time back
}

private void ShowEditErrors(bool shown)
private void ShowEditErrors(bool shown, bool showTimerError = false)
{
_editErrorsShown = shown;
_editTimerErrorShown = showTimerError;
OnPropertyChanged(nameof(EditTextError));
OnPropertyChanged(nameof(EditTimerMinutesError));
OnPropertyChanged(nameof(EditErrorSummary));
}

Expand Down Expand Up @@ -649,6 +729,7 @@ public void Sync()
}

ExtendEditingTimerCommand.NotifyCanExecuteChanged();
SetEditingTimerCommand.NotifyCanExecuteChanged();
RefreshHeader();
}

Expand Down Expand Up @@ -695,7 +776,7 @@ public TaskRow(
CreatedDisplay = SourceOf(session, task) is { } source
? $"{Formatting.Timestamp(task.CreatedAt)} · {task.CreatedBy} · aus ETB {Formatting.TimeOfDay(source.Timestamp)}"
: $"{Formatting.Timestamp(task.CreatedAt)} · {task.CreatedBy}";
HasTimer = task.DueAt != DateTimeOffset.MaxValue;
_hasTimer = task.DueAt != DateTimeOffset.MaxValue;
_text = task.Text;
_assignee = task.Assignee;
_importance = task.Importance;
Expand Down Expand Up @@ -734,6 +815,7 @@ public void Update(IncidentTask task, DateTimeOffset now)
Assignee = task.Assignee;
Importance = task.Importance;
Urgency = task.Urgency;
HasTimer = task.DueAt != DateTimeOffset.MaxValue; // SETZEN can give a task its first (#964)
CompletedDisplay = CompletedDisplayOf(task);
IsOverdue = IsOverdueAt(task, now);
RemainingDisplay = ComputeRemaining(task, now);
Expand All @@ -760,7 +842,8 @@ private static string CompletedDisplayOf(IncidentTask task) =>
public string CreatedDisplay { get; }

/// <summary>Whether the task runs on a timer at all; +5 MIN has nothing to extend otherwise.</summary>
public bool HasTimer { get; }
[ObservableProperty]
private bool _hasTimer;

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(ImportanceLabel))]
Expand Down
3 changes: 3 additions & 0 deletions src/LageBuch.AppLogic/ViewModels/ValidationMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static class ValidationMessages
/// <summary>A timer box emptied, or holding something that is not a count of minutes.</summary>
public const string TimerMinutes = "Minuten eintragen (0 oder mehr)";

/// <summary>The time until an existing Aufgabe's reminder (#964): at least a minute, at most a day.</summary>
public const string ReminderMinutes = "Minuten bis zur Erinnerung eintragen (1 bis 1440)";

/// <summary>A Beteiligte/r without a name, which nobody could look up again.</summary>
public const string NameRequired = "Name eingeben";

Expand Down
17 changes: 17 additions & 0 deletions src/LageBuch.Domain/Incident.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,23 @@ public IncidentTask ExtendTaskTimer(Guid taskId, int minutes, IClock clock)
return updated;
}

/// <summary>Sets the time until a task's reminder to minutes from now (#964). Silent like
/// <see cref="ExtendTaskTimer"/>. Unknown ids throw so a replayed command fails loudly.</summary>
public IncidentTask SetTaskTimer(Guid taskId, int minutes, IClock clock)
{
EnsureOpen();
ArgumentNullException.ThrowIfNull(clock);
var index = _tasks.FindIndex(t => t.Id == taskId);
if (index < 0)
{
throw new KeyNotFoundException($"Aufgabe {taskId} nicht gefunden.");
}

var updated = _tasks[index].WithTimer(minutes, clock.Now);
_tasks[index] = updated;
return updated;
}

private AtemschutzTrupp FindScbaTrupp(Guid truppId) =>
_scbaTrupps.FirstOrDefault(t => t.Id == truppId)
?? throw new KeyNotFoundException($"Atemschutz-Trupp {truppId} not found.");
Expand Down
35 changes: 32 additions & 3 deletions src/LageBuch.Domain/Tasks/IncidentTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ public enum TaskUrgency

/// <summary>
/// One operational to-do (#88). Immutable like every other aggregate child: completion produces a
/// replacement via <see cref="WithCompletion"/> rather than mutating. The due time is fixed at
/// creation (urgency drives the default, the operator may override) — un-checking never restarts
/// it, so a long-done task re-opened late simply shows as overdue again. <see cref="CreatedBy"/>
/// replacement via <see cref="WithCompletion"/> rather than mutating. The due time is set at
/// creation (urgency drives the default, the operator may override) and moves only when someone
/// moves it (+5 MIN, or a typed time since #964) — un-checking never restarts it, so a long-done
/// task re-opened late simply shows as overdue again. <see cref="CreatedBy"/>
/// may be "System" — reserved for machine-created tasks (the ILS reminder is expected to become
/// one eventually).
/// </summary>
Expand All @@ -30,6 +31,12 @@ public sealed record IncidentTask
// (same rationale as EtbEntry.MaxTextLength).
public const int MaxTextLength = 1000;

/// <summary>
/// The longest time until the reminder that <see cref="WithTimer"/> accepts: a day. Further out
/// than that is a typo rather than a plan, and it bounds what a sync peer can send.
/// </summary>
public const int MaxTimerMinutes = 24 * 60;

private IncidentTask()
{
}
Expand Down Expand Up @@ -184,6 +191,28 @@ public IncidentTask WithExtendedTimer(int minutes, DateTimeOffset now)
return this with { DueAt = baseline.AddMinutes(minutes) };
}

/// <summary>Sets the time until the reminder to <paramref name="minutesFromNow"/> (#964), which
/// replaces the due time whether it ends up shorter or longer than before. A task without a timer
/// gets one. A done task is history, as in the edit panel, so it refuses.</summary>
public IncidentTask WithTimer(int minutesFromNow, DateTimeOffset now)
{
if (minutesFromNow is < 1 or > MaxTimerMinutes)
{
// German: a joined client reads the host's refusal verbatim.
throw new ArgumentOutOfRangeException(
nameof(minutesFromNow),
minutesFromNow,
$"Die Minuten bis zur Erinnerung müssen zwischen 1 und {MaxTimerMinutes} liegen.");
}

if (IsCompleted)
{
throw new InvalidOperationException("Eine erledigte Aufgabe hat keinen Timer mehr.");
}

return this with { DueAt = now.AddMinutes(minutesFromNow) };
}

/// <summary>Urgency-driven default for the creation UIs' TIMER (MIN) field (#88).</summary>
public static int DefaultTimerMinutes(TaskUrgency urgency) => urgency switch
{
Expand Down
3 changes: 3 additions & 0 deletions src/LageBuch.Sync/CommandApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ public static class CommandApplier
case ExtendTaskTimerCommand c:
incident.ExtendTaskTimer(c.TaskId, c.Minutes, clock);
break;
case SetTaskTimerCommand c:
incident.SetTaskTimer(c.TaskId, c.Minutes, clock);
break;
case AddCoBuildingCommand c:
incident.AddCoBuilding(clock, Operator(c.Operator), c.Name, c.FloorCount, c.ApartmentsPerFloor, c.UndergroundFloorCount, c.ApartmentLabels, c.Gases?.OfType<GasDefinitionDto>().Select(g => g.ToDefinition()));
break;
Expand Down
4 changes: 4 additions & 0 deletions src/LageBuch.Sync/IIncidentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ void UpdateSituationReport(
/// <summary>Adds minutes to a task's due time (#246 "+5" quick action).</summary>
void ExtendTaskTimer(Guid taskId, int minutes);

/// <summary>Sets the time until a task's reminder to minutes from now (#964): shorter or longer
/// than before, and on a task that had no timer too.</summary>
void SetTaskTimer(Guid taskId, int minutes);

void AddScbaTrupp(
string designation,
IEnumerable<TruppMember> members,
Expand Down
3 changes: 3 additions & 0 deletions src/LageBuch.Sync/RemoteIncidentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,9 @@ public void UpdateTask(Guid taskId, string text, string? assignee, TaskImportanc
public void ExtendTaskTimer(Guid taskId, int minutes) =>
Send(new ExtendTaskTimerCommand(taskId, minutes));

public void SetTaskTimer(Guid taskId, int minutes) =>
Send(new SetTaskTimerCommand(taskId, minutes));

public void AddScbaTrupp(
string designation,
IEnumerable<TruppMember> members,
Expand Down
5 changes: 5 additions & 0 deletions src/LageBuch.Sync/SyncCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace LageBuch.Sync;
[JsonDerivedType(typeof(SetTaskCompletedCommand), "setTaskCompleted")]
[JsonDerivedType(typeof(UpdateTaskCommand), "updateTask")]
[JsonDerivedType(typeof(ExtendTaskTimerCommand), "extendTaskTimer")]
[JsonDerivedType(typeof(SetTaskTimerCommand), "setTaskTimer")]
[JsonDerivedType(typeof(AddCoBuildingCommand), "addCoBuilding")]
[JsonDerivedType(typeof(UpdateCoBuildingStructureCommand), "updateCoBuildingStructure")]
[JsonDerivedType(typeof(RemoveCoBuildingCommand), "removeCoBuilding")]
Expand Down Expand Up @@ -375,6 +376,10 @@ public sealed record UpdateTaskCommand(
// No operator (silent) -- the "+5" quick action.
public sealed record ExtendTaskTimerCommand(Guid TaskId, int Minutes) : SyncCommand;

// No operator (silent) -- the time until the reminder, typed (#964). Minutes rather than an
// absolute DueAt, like AddTaskCommand's TimerMinutes: the host counts them from its own clock.
public sealed record SetTaskTimerCommand(Guid TaskId, int Minutes) : SyncCommand;

// UndergroundFloorCount defaults to 0 so a pre-#218 payload deserializes as "keine
// Untergeschosse" instead of failing the contract (same convention as #76's OfficerCount).
// ApartmentLabels are an Objekt's Wohnungsbezeichnungen (#420), optional for the same reason; the
Expand Down
8 changes: 6 additions & 2 deletions src/LageBuch.Sync/SyncProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,19 @@ public static class SyncProtocol
/// Fahrzeugtyp is filled from. A peer at 42 drops the key and reads none, which only leaves its
/// new vehicles to be typed by hand, so the floor stays at 40.
/// </para>
/// <para>
/// 44: a client may send <c>setTaskTimer</c>, the time until an Aufgabe's reminder typed in
/// minutes (#964). A host at 43 does not know it, so the floor rises to 44.
/// </para>
/// </summary>
public const int ProtocolVersion = 43;
public const int ProtocolVersion = 44;

/// <summary>
/// The oldest contract this build still speaks. A peer below it is refused with a message naming
/// which end to update; a peer at or above it is served. See <see cref="ProtocolVersion"/> for
/// when to raise this.
/// </summary>
public const int MinimumProtocolVersion = 40;
public const int MinimumProtocolVersion = 44;

/// <summary>
/// What an absent or zero protocol number on the wire means: the contract as it stood at v0.6.1,
Expand Down
Loading