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/+lagemeldung-textbausteine.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Lagemeldung fields Lage, Maßnahmen, Einheiten and Nachforderungen now offer the ETB's Textbausteine on "::", and the expanded text goes into the Funkspruch (#962).
10 changes: 6 additions & 4 deletions src/LageBuch.App.Shared/Views/SituationReportsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@
Command="{Binding SpellFieldCommand}" CommandParameter="{Binding Location}" />
</Grid>

<!-- The four free-text fields offer the ETB's Textbausteine on "::" (#962); MELDENDER and
EINSATZSTELLE are suggest fields, and SnippetCompletion attaches to a TextBox only. -->
<HeaderedContentControl Classes="field" Header="LAGE">
<Grid ColumnDefinitions="*,Auto" ColumnSpacing="6">
<TextBox Grid.Column="0" x:Name="SituationBox" Text="{Binding Situation}" IsReadOnly="{Binding !IsEditable}"
TextWrapping="Wrap"
TextWrapping="Wrap" b:SnippetCompletion.Snippets="{Binding TextSnippets}"
MaxLength="{x:Static vm:SituationReportsViewModel.MaxFieldLength}" />
<Button Grid.Column="1" Classes="ghost" Content="ABC" VerticalAlignment="Top"
ToolTip.Tip="Lage buchstabieren" AutomationProperties.Name="Lage buchstabieren"
Expand All @@ -177,7 +179,7 @@
<HeaderedContentControl Classes="field" Header="DURCHGEFÜHRTE MASSNAHMEN">
<Grid ColumnDefinitions="*,Auto" ColumnSpacing="6">
<TextBox Grid.Column="0" x:Name="MeasuresBox" Text="{Binding Measures}" IsReadOnly="{Binding !IsEditable}"
TextWrapping="Wrap"
TextWrapping="Wrap" b:SnippetCompletion.Snippets="{Binding TextSnippets}"
MaxLength="{x:Static vm:SituationReportsViewModel.MaxFieldLength}" />
<Button Grid.Column="1" Classes="ghost" Content="ABC" VerticalAlignment="Top"
ToolTip.Tip="Maßnahmen buchstabieren" AutomationProperties.Name="Maßnahmen buchstabieren"
Expand All @@ -188,7 +190,7 @@
<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"
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}"
Expand All @@ -203,7 +205,7 @@

<HeaderedContentControl Classes="field" Header="NACHFORDERUNGEN">
<TextBox x:Name="RequestsBox" Text="{Binding Requests}" IsReadOnly="{Binding !IsEditable}"
TextWrapping="Wrap"
TextWrapping="Wrap" b:SnippetCompletion.Snippets="{Binding TextSnippets}"
MaxLength="{x:Static vm:SituationReportsViewModel.MaxFieldLength}" />
</HeaderedContentControl>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,8 @@ private void BuildChildren()
.Select(street => street.Name.Trim())
.Where(name => name.Length > 0)
.Distinct(StringComparer.Ordinal)
.ToList());
.ToList(),
Etb.TextSnippets);

EtbTabs = new EtbTabsViewModel(Etb, SituationReports, reopenEtbTab);

Expand Down
13 changes: 12 additions & 1 deletion src/LageBuch.AppLogic/ViewModels/SituationReportsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CommunityToolkit.Mvvm.Input;
using LageBuch.Domain;
using LageBuch.Domain.SituationReports;
using LageBuch.Persistence.MasterData;
using LageBuch.Sync;

namespace LageBuch.AppLogic.ViewModels;
Expand Down Expand Up @@ -45,13 +46,16 @@ public sealed partial class SituationReportsViewModel : ObservableObject, INarro
/// them for VON and AN; none when omitted.</param>
/// <param name="addresses">The Stammdaten Straßen, each written as an address, offered for the
/// Einsatzstelle after the Einsatz's own address; none when omitted.</param>
/// <param name="textSnippets">The Textbausteine the free-text fields offer on <c>::</c>, the
/// ETB's; none when omitted.</param>
public SituationReportsViewModel(
IIncidentSession session,
Action onChanged,
string dispatchCentreName,
Action<string, string, Action>? requestConfirm = null,
IReadOnlyList<string>? callSigns = null,
IReadOnlyList<string>? addresses = null)
IReadOnlyList<string>? addresses = null,
IReadOnlyList<TextSnippet>? textSnippets = null)
{
ArgumentNullException.ThrowIfNull(session);
ArgumentNullException.ThrowIfNull(onChanged);
Expand All @@ -63,6 +67,7 @@ public SituationReportsViewModel(
IsReadOnly = session.IsReadOnly;
CallSignOptions = callSigns ?? [];
_addresses = addresses ?? [];
TextSnippets = textSnippets ?? [];
Reports = new ObservableCollection<SituationReportRow>();
RebuildRows();

Expand All @@ -87,6 +92,12 @@ public SituationReportsViewModel(
/// <summary>The Funkrufnamen Meldender suggests; a name outside them can still be typed.</summary>
public IReadOnlyList<string> CallSignOptions { get; }

/// <summary>
/// What Lage, Maßnahmen, Einheiten and Nachforderungen offer on <c>::</c>: the ETB's
/// Textbausteine, since a sent report becomes an ETB entry (#962).
/// </summary>
public IReadOnlyList<TextSnippet> TextSnippets { get; }

/// <summary>
/// What the Einsatzstelle suggests: the street in the Einsatzdaten first, as it stands now,
/// then the Stammdaten Straßen. Free text can still be typed.
Expand Down
137 changes: 137 additions & 0 deletions tests/LageBuch.Acceptance.Tests/SituationReportSnippetTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using Avalonia.Controls;
using Avalonia.Headless;
using Avalonia.Headless.XUnit;
using Avalonia.Input;
using Avalonia.Threading;
using Avalonia.VisualTree;
using LageBuch.App.Shared.Behaviors;
using LageBuch.App.Shared.Views;
using LageBuch.AppLogic;
using LageBuch.AppLogic.Services;
using LageBuch.AppLogic.ViewModels;
using LageBuch.Domain;
using LageBuch.Persistence.MasterData;

namespace LageBuch.Acceptance.Tests;

// ::kürzel in the LAGEMELDUNG's text fields (#962), typed the way a Funker would. A Lagemeldung ends up
// in the ETB, so its fields offer the ETB's Textbausteine. The expansion has to reach the Funkspruch and
// the draft: the view writes the draft when a field is left, not on every keystroke.
public class SituationReportSnippetTests
{
private static readonly TextSnippet[] Snippets =
{
new("fuk", "Feuer unter Kontrolle", "Lage", ForTasks: false),
new("fua", "Feuer aus, Nachlöscharbeiten laufen", "Lage", ForTasks: false),

// Matches "::fu" too, but is ticked for Aufgaben only: the Lagemeldung must not offer it.
new("fuw", "Wärmebildkamera nachfordern", "Aufgabe", ForEtb: false),
};

private static (Window Window, IncidentWorkspaceViewModel Vm, LocalIncidentSession Session) ShowWorkspace()
{
var session = TestSession.StartNew(
new FakeStore(),
new FixedClock(),
new SessionOperator("Muster", "Florian Musterstadt 11/1"),
"/x.fwincident",
Array.Empty<(string, bool)>(),
Array.Empty<(string, bool)>());
session.SetAddress("Blumenstraße", "Musterstadt-Nord", "13", "12345", "Musterstadt");
session.AddForceUnit("FF Musterstadt", 9, callSign: "HLF 1", officerCount: 1, scbaCount: 4);
session.AddSituationReport(
"Florian Musterstadt 11/1",
"Blumenstraße 13",
null,
"Brandbekämpfung mit einem C-Hohlstrahlrohr",
"FF Musterstadt (HLF 1) 0/1/8/9",
null);
var vm = new IncidentWorkspaceViewModel(
session,
new FixedClock(),
new NoopTicker(),
WorkspaceRenderHelper.MasterData() with { TextSnippets = Snippets },
new FakeDialogs(),
new NoopAlarmService(),
new NoopIncidentHostController());
var window = new Window { Content = new IncidentWorkspaceView { DataContext = vm }, Width = 1920, Height = 1032 };
window.Show();
Dispatcher.UIThread.RunJobs();
return (window, vm, session);
}

private static TextBox FocusField(Window window, string name)
{
WorkspaceRenderHelper.SelectModuleTab(window, "ETB", "LAGEMELDUNG");
var box = window.GetVisualDescendants().OfType<TextBox>().Single(c => c.Name == name);
box.Focus(NavigationMethod.Tab);
Dispatcher.UIThread.RunJobs();
return box;
}

private static void Capture(Window window, string name)
{
var dir = Environment.GetEnvironmentVariable("RENDER_OUT");
if (string.IsNullOrWhiteSpace(dir))
{
return;
}

Directory.CreateDirectory(dir);
Thread.Sleep(250);
Dispatcher.UIThread.RunJobs();
using var frame = window.CaptureRenderedFrame()!;
frame.SavePng(Path.Join(dir, name));
}

[AvaloniaTheory]
[InlineData("SituationBox")]
[InlineData("MeasuresBox")]
[InlineData("UnitsBox")]
[InlineData("RequestsBox")]
public void Every_lagemeldung_text_field_offers_the_etb_textbausteine(string field)
{
var (window, _, _) = ShowWorkspace();
var box = FocusField(window, field);

window.Type("::fu");

Assert.Equal(new[] { "fuk", "fua" }, SnippetCompletion.OfferedSnippets(box).Select(s => s.Shortcut));
}

[AvaloniaFact]
public void Typing_a_kuerzel_in_the_lage_opens_the_list()
{
var (window, _, _) = ShowWorkspace();
var box = FocusField(window, "SituationBox");

window.Type("Schuppen, ::fu");
Capture(window, "lagemeldung-textbausteine.png");

Assert.Equal(new[] { "fuk", "fua" }, SnippetCompletion.OfferedSnippets(box).Select(s => s.Shortcut));
Assert.True(SnippetCompletion.ClaimsEnter(box));
}

[AvaloniaFact]
public void Enter_expands_the_textbaustein_into_the_funkspruch_and_the_draft_without_sending_it()
{
var (window, vm, session) = ShowWorkspace();
var box = FocusField(window, "SituationBox");
var journal = session.Incident.Journal.Count;

window.Type("Schuppen, ::fuk");
window.Press(PhysicalKey.Enter);

Assert.Equal("Schuppen, Feuer unter Kontrolle ", box.Text);
Assert.Empty(SnippetCompletion.OfferedSnippets(box));
window.AssertFocused(box);
Assert.Contains("Schuppen, Feuer unter Kontrolle", vm.SituationReports.FunkspruchPreview, StringComparison.Ordinal);
Assert.False(session.Incident.SituationReports[0].IsSent);
Assert.Equal(journal, session.Incident.Journal.Count);

// Leaving the field writes the draft, with the expansion in it.
window.Press(PhysicalKey.Tab);
Dispatcher.UIThread.RunJobs();
Assert.StartsWith("Schuppen, Feuer unter Kontrolle", session.Incident.SituationReports[0].Situation, StringComparison.Ordinal);
}
}
28 changes: 28 additions & 0 deletions tests/LageBuch.AppLogic.Tests/IncidentWorkspaceViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,34 @@ public void The_etb_rail_entry_holds_the_journal_and_the_lagemeldung_as_tabs()
Assert.Equal(EtbTabsViewModel.JournalTab, vm.EtbTabs.SelectedTabIndex);
}

// #962: a Lagemeldung ends up in the ETB, so its fields offer the ETB's Textbausteine.
[Fact]
public void The_lagemeldung_offers_the_textbausteine_ticked_for_the_etb()
{
var clock = new FixedClock(T0);
var session = TestSession.StartNew(
new FakeStore(),
clock,
new SessionOperator("Müller"),
"/x.lagebuch",
new[] { ("A?", false) },
Array.Empty<(string, bool)>());
var md = Md() with
{
TextSnippets =
[
new TextSnippet("fuk", "Feuer unter Kontrolle", ForTasks: false),
new TextSnippet("stw", "Stadtwerke verständigen", ForEtb: false),
new TextSnippet("elw", "Lagemeldung an ELW"),
],
};
using var vm = new IncidentWorkspaceViewModel(
session, clock, new FakeTicker(), md, new FakeDialogs(), new FakeAlarmService(), new NoopIncidentHostController());

Assert.Equal(["fuk", "elw"], vm.SituationReports.TextSnippets.Select(s => s.Shortcut));
Assert.Equal(vm.Etb.TextSnippets, vm.SituationReports.TextSnippets);
}

[Fact]
public void Ctrl_l_opens_the_lagemeldung_tab_and_starts_a_draft_when_there_is_none()
{
Expand Down
14 changes: 14 additions & 0 deletions tests/LageBuch.AppLogic.Tests/SituationReportsViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using LageBuch.AppLogic.ViewModels;
using LageBuch.Domain;
using LageBuch.Domain.Etb;
using LageBuch.Persistence.MasterData;

namespace LageBuch.AppLogic.Tests;

Expand Down Expand Up @@ -56,6 +57,19 @@ public void Meldender_suggests_the_stammdaten_funkrufnamen()
Assert.Equal(callSigns, vm.CallSignOptions);
}

[Fact]
public void The_lage_fields_offer_the_textbausteine_they_are_given_and_none_without()
{
var (session, _) = NewSession();
TextSnippet[] snippets = [new("fuk", "Feuer unter Kontrolle")];

using var given = new SituationReportsViewModel(session, () => { }, "ILS", textSnippets: snippets);
using var none = NewVm(session);

Assert.Equal(snippets, given.TextSnippets);
Assert.Empty(none.TextSnippets);
}

[Fact]
public void Einsatzstelle_suggests_the_einsatzdaten_street_first_then_the_stammdaten_strassen()
{
Expand Down