Skip to content
Merged
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
2 changes: 1 addition & 1 deletion changelog.d/+lagemeldung.added.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The ETB gains a LAGEMELDUNG tab (Strg+L, or from the Rückmeldung row) that drafts the periodic situation report to the ILS with Meldender, Einsatzstelle and Eingesetzte Einheiten prefilled, composes it into one Funkspruch, and on sending writes it to the ETB marked "LM n", restarts the Rückmeldung timer and lists it in the PDF Bericht, with a Buchstabier-Helfer (traditional, DIN 5009:2022 and NATO) beside it and in the journal (#592).
The ETB gains a LAGEMELDUNG tab (Strg+L, or from the Rückmeldung row) that drafts the periodic situation report to the ILS with Meldender and Einsatzstelle prefilled, composes it into one Funkspruch, and on sending writes it to the ETB marked "LM n", restarts the Rückmeldung timer and lists it in the PDF Bericht, with a Buchstabier-Helfer (traditional, DIN 5009:2022 and NATO) beside it and in the journal (#592).
16 changes: 3 additions & 13 deletions src/LageBuch.App.Shared/Views/SituationReportsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,9 @@
</HeaderedContentControl>

<HeaderedContentControl Classes="field" Header="EINGESETZTE EINHEITEN">
<Grid ColumnDefinitions="*,Auto" ColumnSpacing="6">
<TextBox Grid.Column="0" x:Name="UnitsBox" Text="{Binding Units}" IsReadOnly="{Binding !IsEditable}"
TextWrapping="Wrap" b:SnippetCompletion.Snippets="{Binding TextSnippets}"
MaxLength="{x:Static vm:SituationReportsViewModel.MaxFieldLength}" />
<Button Grid.Column="1" x:Name="RefreshUnitsButton" Classes="ghost" VerticalAlignment="Top"
IsVisible="{Binding IsEditable}"
ToolTip.Tip="Aus den Kräften neu übernehmen"
AutomationProperties.Name="Einheiten aus den Kräften neu übernehmen"
Command="{Binding RefreshUnitsCommand}">
<PathIcon Width="14" Height="14"
Data="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z" />
</Button>
</Grid>
<TextBox x:Name="UnitsBox" Text="{Binding Units}" IsReadOnly="{Binding !IsEditable}"
TextWrapping="Wrap" b:SnippetCompletion.Snippets="{Binding TextSnippets}"
MaxLength="{x:Static vm:SituationReportsViewModel.MaxFieldLength}" />
</HeaderedContentControl>

<HeaderedContentControl Classes="field" Header="NACHFORDERUNGEN">
Expand Down
41 changes: 3 additions & 38 deletions src/LageBuch.AppLogic/ViewModels/SituationReportsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ partial void OnSelectedReportChanged(SituationReportRow? oldValue, SituationRepo

/// <summary>
/// Starts a new draft, prefilled from the incident: Meldender from the Lagebuchführer's
/// Funkrufname, Einsatzstelle from the street, Eingesetzte Einheiten from the Kräfte.
/// Funkrufname, Einsatzstelle from the street. Eingesetzte Einheiten stays free text — what is
/// reported there ("2 Trupps unter PA") is not a list of the Kräfte.
/// </summary>
[RelayCommand(CanExecute = nameof(CanAdd))]
private void NewReport()
Expand All @@ -232,7 +233,7 @@ private void NewReport()
Formatting.StreetAddress(incident),
null,
null,
DescribeUnits(incident.Forces),
null,
null));
}

Expand All @@ -256,16 +257,6 @@ public void OpenNewestDraft()
NewReport();
}

private bool CanRefreshUnits => IsEditable;

/// <summary>Fills Eingesetzte Einheiten again from the Kräfte as they stand now.</summary>
[RelayCommand(CanExecute = nameof(CanRefreshUnits))]
private void RefreshUnits()
{
Units = DescribeUnits(_session.Incident.Forces);
CommitSelected();
}

[RelayCommand]
private void OpenHelper() => IsHelperOpen = true;

Expand Down Expand Up @@ -327,31 +318,6 @@ private void DeleteDraft()
() => Write(() => _session.RemoveSituationReport(row.Id)));
}

/// <summary>
/// The Kräfte as Eingesetzte Einheiten: each unit's name and Stärke, as the ETB names them.
/// Null when there are none, so the field stays empty rather than saying so.
/// </summary>
public static string? DescribeUnits(IEnumerable<ForceUnit> forces)
{
ArgumentNullException.ThrowIfNull(forces);
var text = string.Join(", ", forces.Select(u => $"{u.Label} {u.StrengthText}"));
if (text.Length == 0)
{
return null;
}

// A large Einsatz can name more units than the field holds; cut at the last whole unit.
if (text.Length > SituationReport.MaxFieldLength)
{
var cut = text.LastIndexOf(", ", SituationReport.MaxFieldLength - 2, StringComparison.Ordinal);

// Stryker disable once Equality : a unit's label is never empty, so the text never starts with ", " and cut is never 0.
text = (cut > 0 ? text[..cut] : text[..(SituationReport.MaxFieldLength - 2)]) + " …";
}

return text;
}

private bool CommitSelected() => SelectedReport is not { } row || Commit(row.Id);

// Writes the editor to the draft with this id, if it changed. False when a field is over its
Expand Down Expand Up @@ -481,7 +447,6 @@ private void Load(SituationReport? report)
OnPropertyChanged(nameof(EditorHeader));
SendCommand.NotifyCanExecuteChanged();
DeleteDraftCommand.NotifyCanExecuteChanged();
RefreshUnitsCommand.NotifyCanExecuteChanged();
}

private static string? Moved(string? before, string? now, string? editing) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static (Window Window, IncidentWorkspaceViewModel Vm, LocalIncidentSessi
"Blumenstraße 13",
"Feuer unter Kontrolle",
"Nachlöscharbeiten, Wärmebildkamera",
"FF Musterstadt (HLF 1) 0/1/8/9, FF Beispieldorf (LF 2) 0/1/5/6",
"2 Trupps unter PA, Wasserversorgung durch LF 2",
"1 RTW zur Bereitstellung");
var vm = new IncidentWorkspaceViewModel(
session,
Expand Down
78 changes: 2 additions & 76 deletions tests/LageBuch.AppLogic.Tests/SituationReportsViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static SituationReportsViewModel NewVm(
new(session, () => { }, "ILS", requestConfirm);

[Fact]
public void A_new_report_is_prefilled_from_the_funkrufname_the_street_and_the_kraefte()
public void A_new_report_is_prefilled_from_the_funkrufname_and_the_street_but_leaves_the_units_free()
{
var (session, _) = NewSession();
session.SetAddress("Blumenstraße", "Nord", "13", "12345", "Musterstadt");
Expand All @@ -41,7 +41,7 @@ public void A_new_report_is_prefilled_from_the_funkrufname_the_street_and_the_kr
Assert.Same(vm.Reports[0], vm.SelectedReport);
Assert.Equal("Florian Musterstadt 11/1", vm.Reporter);
Assert.Equal("Blumenstraße 13", vm.Location);
Assert.Equal("FF Musterstadt (HLF 1) 0/1/8/9, FF Beispieldorf 0/1/5/6", vm.Units);
Assert.Null(vm.Units);
Assert.Null(vm.Situation);
Assert.True(vm.IsEditable);
}
Expand Down Expand Up @@ -308,21 +308,6 @@ public void An_empty_draft_cannot_be_sent()
Assert.False(vm.SendCommand.CanExecute(null));
}

[Fact]
public void RefreshUnits_takes_over_the_kraefte_as_they_stand_now()
{
var (session, _) = NewSession();
using var vm = NewVm(session);
vm.NewReportCommand.Execute(null);
Assert.Null(vm.Units);
session.AddForceUnit("FF Musterstadt", 9, callSign: "HLF 1", officerCount: 1);

vm.RefreshUnitsCommand.Execute(null);

Assert.Equal("FF Musterstadt (HLF 1) 0/1/8/9", vm.Units);
Assert.Equal("FF Musterstadt (HLF 1) 0/1/8/9", session.Incident.SituationReports[0].Units);
}

[Fact]
public void Discarding_a_draft_asks_first_and_takes_it_out()
{
Expand Down Expand Up @@ -399,18 +384,6 @@ public void A_field_handed_to_the_helper_is_spelled_and_opens_it_on_a_phone()
Assert.StartsWith("Berta – Ludwig", vm.Helper.Spelled, StringComparison.Ordinal);
}

[Fact]
public void Units_longer_than_the_field_are_cut_at_the_last_whole_unit()
{
var forces = Enumerable.Range(1, 60).Select(i => ForceUnit.Create($"FF Musterstadt {i}", 9)).ToList();

var text = SituationReportsViewModel.DescribeUnits(forces);

Assert.NotNull(text);
Assert.True(text.Length <= SituationReportsViewModel.MaxFieldLength);
Assert.EndsWith("0/0/9/9 …", text, StringComparison.Ordinal);
}

// A draft with a Lage, saved, then opened read-only the way a closed Einsatz is reopened.
private static LocalIncidentSession ReadOnlySessionWithADraft()
{
Expand Down Expand Up @@ -561,10 +534,8 @@ public void A_report_sent_elsewhere_locks_the_editor_and_announces_it()
vm.PropertyChanged += (_, e) => changed.Add(e.PropertyName);
var send = 0;
var delete = 0;
var refresh = 0;
vm.SendCommand.CanExecuteChanged += (_, _) => send++;
vm.DeleteDraftCommand.CanExecuteChanged += (_, _) => delete++;
vm.RefreshUnitsCommand.CanExecuteChanged += (_, _) => refresh++;

session.SendSituationReport(session.Incident.SituationReports[0].Id, "ILS");

Expand All @@ -576,7 +547,6 @@ public void A_report_sent_elsewhere_locks_the_editor_and_announces_it()
Assert.Contains(nameof(SituationReportsViewModel.EditorHeader), changed);
Assert.True(send > 0);
Assert.True(delete > 0);
Assert.True(refresh > 0);
Assert.False(vm.SendCommand.CanExecute(null));
}

Expand Down Expand Up @@ -678,50 +648,6 @@ public void The_helper_opens_and_closes_on_a_phone_and_is_always_there_when_wide
Assert.True(vm.ShowHelperButton);
}

[Fact]
public void No_kraefte_means_no_eingesetzte_einheiten()
{
Assert.Null(SituationReportsViewModel.DescribeUnits([]));
}

[Fact]
public void Units_exactly_as_long_as_the_field_are_not_cut()
{
// 290 + " 0/0/9/9" + ", " + 292 + " 0/0/9/9" = 600 characters.
ForceUnit[] forces = [ForceUnit.Create(new string('A', 290), 9), ForceUnit.Create(new string('B', 292), 9)];

var text = SituationReportsViewModel.DescribeUnits(forces);

Assert.Equal(SituationReportsViewModel.MaxFieldLength, text?.Length);
Assert.EndsWith("B 0/0/9/9", text, StringComparison.Ordinal);
}

[Fact]
public void A_cut_never_leaves_the_text_longer_than_the_field()
{
// The second separator sits at 599, just past where a cut may still start.
ForceUnit[] forces =
[
ForceUnit.Create(new string('A', 291), 9),
ForceUnit.Create(new string('B', 290), 9),
ForceUnit.Create("C", 9),
];

var text = SituationReportsViewModel.DescribeUnits(forces);

Assert.NotNull(text);
Assert.True(text.Length <= SituationReportsViewModel.MaxFieldLength, $"{text.Length} characters");
Assert.Equal(new string('A', 291) + " 0/0/9/9 …", text);
}

[Fact]
public void A_single_unit_longer_than_the_field_is_cut_inside_its_name()
{
var text = SituationReportsViewModel.DescribeUnits([ForceUnit.Create(new string('A', 700), 9)]);

Assert.Equal(new string('A', SituationReportsViewModel.MaxFieldLength - 2) + " …", text);
}

[Fact]
public void A_row_shows_when_it_was_sent_or_else_when_it_was_started()
{
Expand Down