diff --git a/changelog.d/+etb-einsatzabschnitt.added.md b/changelog.d/+etb-einsatzabschnitt.added.md
new file mode 100644
index 00000000..c68c5035
--- /dev/null
+++ b/changelog.d/+etb-einsatzabschnitt.added.md
@@ -0,0 +1 @@
+ETB entries can be filed under an Einsatzabschnitt from the entry line or the edit panel, carry the Abschnitt as a badge in the grid and in the PDF, and a quick filter above the table shows one Abschnitt at a time (#971).
diff --git a/src/LageBuch.App.Shared/Views/EtbView.axaml b/src/LageBuch.App.Shared/Views/EtbView.axaml
index 3ce574ff..b7e57483 100644
--- a/src/LageBuch.App.Shared/Views/EtbView.axaml
+++ b/src/LageBuch.App.Shared/Views/EtbView.axaml
@@ -37,6 +37,37 @@
+
+
+
+
+
+
@@ -46,6 +77,15 @@
+
+
+
@@ -75,6 +115,9 @@
+
@@ -119,6 +162,28 @@
IsChecked="{Binding HideSystemEntries}" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -216,6 +291,12 @@
+
+
+
+
+
+
+
@@ -356,6 +440,9 @@
+
+
+
diff --git a/src/LageBuch.AppLogic/LocalIncidentSession.cs b/src/LageBuch.AppLogic/LocalIncidentSession.cs
index d67fa964..49d14ac7 100644
--- a/src/LageBuch.AppLogic/LocalIncidentSession.cs
+++ b/src/LageBuch.AppLogic/LocalIncidentSession.cs
@@ -125,16 +125,19 @@ public async Task ExportPdfAsync(IIncidentPdfExporter exporter, Incident
}
// --- IIncidentSession mutation surface: apply → persist → notify. ---
- public Guid AddJournalEntry(EtbDirection direction, string text, string? from = null, string? to = null)
+ public Guid AddJournalEntry(EtbDirection direction, string text, string? from = null, string? to = null, Guid? sectionId = null)
{
var id = Guid.Empty;
- Mutate(() => id = Incident.AddJournalEntry(_clock, RequireOperator(), direction, text, from, to).Id);
+ Mutate(() => id = Incident.AddJournalEntry(_clock, RequireOperator(), direction, text, from, to, sectionId: sectionId).Id);
return id;
}
public void EditJournalEntry(Guid entryId, string text) =>
Mutate(() => Incident.EditJournalEntry(_clock, RequireOperator(), entryId, text));
+ public void AssignJournalEntrySection(Guid entryId, Guid? sectionId) =>
+ Mutate(() => Incident.AssignJournalEntrySection(_clock, RequireOperator(), entryId, sectionId));
+
public void ToggleChecklistItem(Guid itemId) => Mutate(() => Incident.ToggleChecklistItem(_clock, RequireOperator(), itemId));
public void AssignRole(
diff --git a/src/LageBuch.AppLogic/ViewModels/EtbViewModel.cs b/src/LageBuch.AppLogic/ViewModels/EtbViewModel.cs
index e897be5a..57195aa4 100644
--- a/src/LageBuch.AppLogic/ViewModels/EtbViewModel.cs
+++ b/src/LageBuch.AppLogic/ViewModels/EtbViewModel.cs
@@ -71,6 +71,7 @@ public EtbViewModel(
CallSignOptions = masterData.RadioCallSigns;
TextSnippets = masterData.TextSnippets.Where(s => s.ForEtb).ToList();
Entries = new ObservableCollection();
+ FilterChoices = new ObservableCollection();
// Any change to the incident — from this tab, another tab, or (when joined) another device —
// brings the journal up to date through the same path.
@@ -102,6 +103,7 @@ public void Sync()
{
var journal = _session.Incident.Journal;
var reportNumbers = SituationReportNumbers();
+ var refiled = false;
for (var i = _all.Count; i < journal.Count; i++)
{
var row = ToRow(journal[i]);
@@ -116,11 +118,13 @@ public void Sync()
foreach (var entry in journal)
{
- if (!_byId.TryGetValue(entry.Id, out var current) || current.Edits.Count == entry.Edits.Count)
+ if (!_byId.TryGetValue(entry.Id, out var current)
+ || (current.Edits.Count == entry.Edits.Count && current.SectionId == entry.SectionId))
{
continue;
}
+ refiled |= current.SectionId != entry.SectionId;
current.Update(entry);
if (EditingEntry?.Id == entry.Id)
@@ -147,6 +151,79 @@ public void Sync()
{
ReconcileVisible();
}
+
+ SyncSections(refiled);
+ }
+
+ // The entry picker and the filter follow the Organisation: a formed, renamed or dissolved
+ // Abschnitt shows up here on the next change. Rebuilt only when what they show moved, so a
+ // focused chip keeps its focus and an open picker its list.
+ private void SyncSections(bool refiled)
+ {
+ var live = NodeChoices.Einsatzabschnitte(_session.Incident);
+ if (NewSectionId is { } chosen && live.All(n => n.Id != chosen))
+ {
+ _newSections = live;
+ NewSectionId = null; // dissolved meanwhile: the next entry must not be refused for it
+ }
+ else if (!_newSections.SequenceEqual(live))
+ {
+ _newSections = live;
+ NewSectionChoices = BuildNewSectionChoices();
+ }
+
+ // The filter also keeps every Abschnitt an entry is filed under, under the name it was filed
+ // with, so the entries of a dissolved Abschnitt stay findable.
+ var filters = new List<(Guid? Id, string Label)> { (null, AllSectionsLabel) };
+ filters.AddRange(live.Select(Option));
+ foreach (var row in _all)
+ {
+ if (row.SectionId is { } id && filters.All(f => f.Id != id))
+ {
+ filters.Add((id, row.SectionName ?? string.Empty));
+ }
+ }
+
+ if (!SameChoices(FilterChoices, filters))
+ {
+ Replace(FilterChoices, filters.Select(f => new EtbSectionChoice(f.Id, f.Label, id => SectionFilter = id)));
+ OnPropertyChanged(nameof(HasFilterChoices));
+ }
+
+ if (SectionFilter is { } filtered && filters.All(f => f.Id != filtered))
+ {
+ SectionFilter = null; // reconciles and marks "Alle" itself
+ }
+ else
+ {
+ MarkSelected();
+ if (refiled && SectionFilter is not null)
+ {
+ ReconcileVisible();
+ }
+ }
+ }
+
+ private static bool SameChoices(IEnumerable shown, IEnumerable<(Guid? Id, string Label)> wanted) =>
+ shown.Select(c => (c.NodeId, c.Label)).SequenceEqual(wanted);
+
+ private static (Guid? Id, string Label) Option(SectionOption option) => (option.Id, option.Label);
+
+ private static void Replace(ObservableCollection target, IEnumerable items)
+ {
+ target.Clear();
+ foreach (var item in items)
+ {
+ target.Add(item);
+ }
+ }
+
+ private void MarkSelected()
+ {
+ foreach (var choice in FilterChoices)
+ {
+ choice.IsSelected = choice.NodeId == SectionFilter;
+ }
}
// ETB entry id -> Lagemeldung Nr., for every report that has been sent.
@@ -189,6 +266,74 @@ private void RefreshTaskBadges()
public ObservableCollection Entries { get; }
+ /// The quick filter's first button, which shows every entry again.
+ public const string AllSectionsLabel = "Alle";
+
+ // The live Abschnitte the entry picker was last built from.
+ private IReadOnlyList _newSections = Array.Empty();
+
+ ///
+ /// The entry line's Abschnitt picker (#971): "nicht zugeordnet", then every live Abschnitt and
+ /// Unterabschnitt in the Organisation's order. "nicht zugeordnet" is current at first.
+ ///
+ [ObservableProperty]
+ private IReadOnlyList _newSectionChoices = Array.Empty();
+
+ /// What the closed entry picker says: the chosen Abschnitt, or "nicht zugeordnet".
+ public string NewSectionLabel => CurrentLabel(NewSectionChoices);
+
+ /// Whether the incident has an Abschnitt to file an entry under; the picker hides otherwise.
+ public bool HasSectionChoices => NewSectionChoices.Count > 1;
+
+ partial void OnNewSectionChoicesChanged(IReadOnlyList value)
+ {
+ OnPropertyChanged(nameof(NewSectionLabel));
+ OnPropertyChanged(nameof(HasSectionChoices));
+ }
+
+ ///
+ /// The Abschnitt the next entry is filed under, or null for none. Sticky on purpose, unlike VON:
+ /// radio traffic from one Abschnitt comes in runs, and the closed picker names the choice right
+ /// above the field, so it is always in view; VON is cleared because a leftover sender would put
+ /// the next message under the wrong unit without any such sign.
+ ///
+ [ObservableProperty]
+ private Guid? _newSectionId;
+
+ partial void OnNewSectionIdChanged(Guid? value) => NewSectionChoices = BuildNewSectionChoices();
+
+ private List BuildNewSectionChoices() =>
+ PickerChoices(_newSections.Select(Option), NewSectionId, id => NewSectionId = id);
+
+ // A picker's choices: "nicht zugeordnet" first, then the options, the current one marked.
+ private static List PickerChoices(IEnumerable<(Guid? Id, string Label)> options, Guid? current, Action pick) =>
+ options
+ .Prepend((null, NodeChoices.UnplacedLabel))
+ .Select(o => new NodeChoice(o.Id, o.Label, o.Id == current, new RelayCommand(() => pick(o.Id))))
+ .ToList();
+
+ private static string CurrentLabel(IReadOnlyList choices) =>
+ choices.FirstOrDefault(c => c.IsCurrent && c.NodeId is not null)?.Label ?? NodeChoices.UnplacedLabel;
+
+ ///
+ /// The quick filter above the grid: , then every live Abschnitt,
+ /// then any dissolved one an entry is still filed under, by the name it was filed with.
+ ///
+ public ObservableCollection FilterChoices { get; }
+
+ /// Whether there is an Abschnitt to filter by at all; "Alle" alone filters nothing.
+ public bool HasFilterChoices => FilterChoices.Count > 1;
+
+ /// Only the entries filed under this Abschnitt, by id; null shows them all.
+ [ObservableProperty]
+ private Guid? _sectionFilter;
+
+ partial void OnSectionFilterChanged(Guid? value)
+ {
+ MarkSelected();
+ ReconcileVisible();
+ }
+
// System-generated lines (Kräfte, Atemschutz, Einsatz-Lebenszyklus) are usually less important
// than human entries, so the operator can hide them. On by default (#223): a fresh incident
// should open on an empty-looking journal, not the "Einsatz begonnen" trace.
@@ -236,7 +381,9 @@ private List VisibleNewestFirst()
}
private bool IsVisible(EtbEntryRow row) =>
- !IsHiddenByKind(row) && (!ShowOnlySituationReports || row.SituationReportNumber is not null);
+ !IsHiddenByKind(row)
+ && (!ShowOnlySituationReports || row.SituationReportNumber is not null)
+ && (SectionFilter is null || row.SectionId == SectionFilter);
// The two "ausblenden" checkboxes, each taking only its own kind of line (#972).
private bool IsHiddenByKind(EtbEntryRow row) =>
@@ -318,7 +465,7 @@ private void AddEntry()
return;
}
- _session.AddJournalEntry(ManualDirection, NewText, NewFrom, NewTo); // Changed → Sync() renders it
+ _session.AddJournalEntry(ManualDirection, NewText, NewFrom, NewTo, NewSectionId); // Changed → Sync() renders it
var toDispatchCentre = IsToDispatchCentre(NewTo);
ClearNewEntry();
_onChanged();
@@ -334,7 +481,7 @@ private void AddEntryAndCreateTask()
return;
}
- var entryId = _session.AddJournalEntry(ManualDirection, NewText, NewFrom, NewTo);
+ var entryId = _session.AddJournalEntry(ManualDirection, NewText, NewFrom, NewTo, NewSectionId);
var text = NewText;
var toDispatchCentre = IsToDispatchCentre(NewTo);
ClearNewEntry();
@@ -403,10 +550,51 @@ private void ShowAddErrors(bool shown)
private bool CanEdit(EtbEntryRow row) => !IsReadOnly && row.IsEditable;
+ /// The edit panel's Abschnitt, as the picker shows it until SPEICHERN writes it.
+ private Guid? _editSectionId;
+
+ ///
+ /// The edit panel's Abschnitt picker: "nicht zugeordnet", every live Abschnitt and, when the
+ /// entry is filed under one since dissolved, that one by the name it was filed with.
+ ///
+ [ObservableProperty]
+ private IReadOnlyList _editSectionChoices = Array.Empty();
+
+ /// What the closed picker says: the chosen Abschnitt, or "nicht zugeordnet".
+ public string EditSectionLabel => CurrentLabel(EditSectionChoices);
+
+ /// Whether there is an Abschnitt to pick; "nicht zugeordnet" alone hides the picker.
+ public bool HasEditSectionChoices => EditSectionChoices.Count > 1;
+
+ partial void OnEditSectionChoicesChanged(IReadOnlyList value)
+ {
+ OnPropertyChanged(nameof(EditSectionLabel));
+ OnPropertyChanged(nameof(HasEditSectionChoices));
+ }
+
+ private void PickEditSection(Guid? id)
+ {
+ _editSectionId = id;
+ EditSectionChoices = BuildEditSectionChoices();
+ }
+
+ private List BuildEditSectionChoices()
+ {
+ var options = NodeChoices.Einsatzabschnitte(_session.Incident).Select(Option).ToList();
+ if (EditingEntry is { SectionId: { } filed } row && options.All(o => o.Id != filed))
+ {
+ options.Add((filed, row.SectionName ?? string.Empty));
+ }
+
+ return PickerChoices(options, _editSectionId, PickEditSection);
+ }
+
private void BeginEdit(EtbEntryRow row)
{
EditingEntry = row;
EditText = row.Text;
+ _editSectionId = row.SectionId;
+ EditSectionChoices = BuildEditSectionChoices();
ShowEditErrors(false); // a freshly opened panel starts quiet
HistoryEntry = null; // editing and viewing history are separate panels; only one at a time
}
@@ -431,7 +619,16 @@ private void SaveEdit()
return;
}
- _session.EditJournalEntry(EditingEntry!.Id, EditText); // Changed → Sync() renders it
+ // Read before the first write: its Changed may close this panel (see Sync).
+ var entry = EditingEntry!;
+ var section = _editSectionId;
+ var refiled = section != entry.SectionId;
+ _session.EditJournalEntry(entry.Id, EditText); // Changed → Sync() renders it
+ if (refiled)
+ {
+ _session.AssignJournalEntrySection(entry.Id, section);
+ }
+
EditingEntry = null;
EditText = string.Empty;
ShowEditErrors(false);
@@ -498,6 +695,10 @@ public sealed class EtbEntryRow : ObservableObject
{
private int? _situationReportNumber;
+ private Guid? _sectionId;
+
+ private string? _sectionName;
+
public EtbEntryRow(
EtbEntry entry,
Action beginEdit,
@@ -520,6 +721,8 @@ public EtbEntryRow(
IsMeasurement = EtbDirections.IsMeasurement(entry.Direction, entry.Text);
WasEdited = entry.Edits.Count > 0;
Edits = entry.Edits;
+ _sectionId = entry.SectionId;
+ _sectionName = entry.SectionName;
IsEditable = !EtbDirections.IsAppWritten(entry.Direction);
BeginEditCommand = new RelayCommand(() => beginEdit(this), () => canEdit(this));
@@ -564,6 +767,14 @@ public EtbEntryRow(
public bool IsEditable { get; }
+ /// The Einsatzabschnitt the entry is filed under (#971), or null; what the quick filter matches.
+ public Guid? SectionId => _sectionId;
+
+ /// The Abschnitt's name as it was when the entry was filed, for the row's badge.
+ public string? SectionName => _sectionName;
+
+ public bool HasSection => _sectionId is not null;
+
public bool CanCreateTask { get; }
public ICommand BeginEditCommand { get; }
@@ -630,7 +841,8 @@ public int? SituationReportNumber
///
/// Re-points this row at the current version of its entry, instead of the view model replacing
/// the row object, which the grid sees as a different item and deselects. An edit changes only
- /// the text and its history (), so nothing else is touched.
+ /// the text and its history (), and a re-filing the
+ /// Abschnitt (), so nothing else is touched.
///
public void Update(EtbEntry entry)
{
@@ -646,8 +858,42 @@ public void Update(EtbEntry entry)
OnPropertyChanged(nameof(Text));
OnPropertyChanged(nameof(Edits));
OnPropertyChanged(nameof(WasEdited));
+ if (_sectionId != entry.SectionId || !string.Equals(_sectionName, entry.SectionName, StringComparison.Ordinal))
+ {
+ _sectionId = entry.SectionId;
+ _sectionName = entry.SectionName;
+ OnPropertyChanged(nameof(SectionId));
+ OnPropertyChanged(nameof(SectionName));
+ OnPropertyChanged(nameof(HasSection));
+ }
// The first edit is what makes the history viewable at all.
ShowHistoryCommand.NotifyCanExecuteChanged();
}
}
+
+///
+/// One button of the ETB's Abschnitt quick filter (#971). A command per button and not a
+/// selection, for the reason given on ; the owner
+/// marks , which the view shows as the lit button.
+///
+public sealed partial class EtbSectionChoice : ObservableObject
+{
+ public EtbSectionChoice(Guid? nodeId, string label, Action onSelect)
+ {
+ ArgumentNullException.ThrowIfNull(onSelect);
+ NodeId = nodeId;
+ Label = label;
+ SelectCommand = new RelayCommand(() => onSelect(nodeId));
+ }
+
+ /// The Abschnitt, or null for the filter's "Alle".
+ public Guid? NodeId { get; }
+
+ public string Label { get; }
+
+ public IRelayCommand SelectCommand { get; }
+
+ [ObservableProperty]
+ private bool _isSelected;
+}
diff --git a/src/LageBuch.AppLogic/ViewModels/NodeChoices.cs b/src/LageBuch.AppLogic/ViewModels/NodeChoices.cs
index bedd8e30..b4eaa81e 100644
--- a/src/LageBuch.AppLogic/ViewModels/NodeChoices.cs
+++ b/src/LageBuch.AppLogic/ViewModels/NodeChoices.cs
@@ -37,6 +37,22 @@ public static IReadOnlyList Build(Incident incident, Guid? currentNo
return choices;
}
+ ///
+ /// The live Abschnitte and Unterabschnitte an ETB entry can be filed under (#971), in
+ /// order, each with its label. No Bereitstellung and no partner:
+ /// the ETB is filtered by Einsatzabschnitt, and neither of those is one.
+ ///
+ public static IReadOnlyList Einsatzabschnitte(Incident incident)
+ {
+ ArgumentNullException.ThrowIfNull(incident);
+ return ReportingLine.Of(incident)
+ .Select(e => e.Node)
+ .OfType()
+ .Where(n => n.Kind is CommandNodeKind.Abschnitt or CommandNodeKind.Unterabschnitt)
+ .Select(n => new SectionOption(n.Id, incident.NodeLabel(n.Id) ?? n.Name))
+ .ToList();
+ }
+
///
/// What a closed picker says: the label of the node marked current, or
/// when the unit counts as unplaced, so an empty picker still reads as one rather than a bare dash.
@@ -86,3 +102,6 @@ private static NodeChoice Choice(Guid? nodeId, string label, bool isCurrent, Act
/// Whether this is the entry in force, for the check mark.
/// Reports to the picker's owner.
public sealed record NodeChoice(Guid? NodeId, string Label, bool IsCurrent, IRelayCommand SelectCommand);
+
+/// An Einsatzabschnitt an ETB entry can be filed under, and what it is called (#971).
+public sealed record SectionOption(Guid Id, string Label);
diff --git a/src/LageBuch.Documents/Sections/EtbSection.cs b/src/LageBuch.Documents/Sections/EtbSection.cs
index d09e6b95..946cea15 100644
--- a/src/LageBuch.Documents/Sections/EtbSection.cs
+++ b/src/LageBuch.Documents/Sections/EtbSection.cs
@@ -56,6 +56,14 @@ public static void Compose(IContainer container, Incident incident)
// traceable in the artifact that leaves the app (#73).
table.Cell().Element(BodyCell).Column(col =>
{
+ // The Einsatzabschnitt as the entry was filed (#971): a small line above
+ // the text rather than a sixth column, which would squeeze the Eintrag on
+ // every row for the few that carry one.
+ if (entry.SectionName is { } section)
+ {
+ col.Item().Text($"Abschnitt {section}").FontSize(8).SemiBold().FontColor(Colors.Grey.Darken2);
+ }
+
col.Item().Text(entry.Text);
foreach (var edit in entry.Edits)
{
diff --git a/src/LageBuch.Domain/Etb/EtbEntry.cs b/src/LageBuch.Domain/Etb/EtbEntry.cs
index db770c9b..ebd92f61 100644
--- a/src/LageBuch.Domain/Etb/EtbEntry.cs
+++ b/src/LageBuch.Domain/Etb/EtbEntry.cs
@@ -26,6 +26,19 @@ private EtbEntry()
public IReadOnlyList Edits { get; private init; } = Array.Empty();
+ ///
+ /// The Einsatzabschnitt the entry belongs to (#971), or null for none. The quick filter matches
+ /// on this id, so a renamed Abschnitt does not split its entries in two.
+ ///
+ public Guid? SectionId { get; private init; }
+
+ ///
+ /// What was called when the entry was assigned to it, e.g.
+ /// "Nord / Zugang". A value, not a lookup: the entry reads the same once the Abschnitt is
+ /// renamed or dissolved, and in a file opened where the incident's nodes say otherwise.
+ ///
+ public string? SectionName { get; private init; }
+
public static EtbEntry Create(
DateTimeOffset timestamp,
EtbDirection direction,
@@ -67,7 +80,9 @@ public static EtbEntry Rehydrate(
string enteredBy,
string? from,
string? to,
- IEnumerable? edits = null)
+ IEnumerable? edits = null,
+ Guid? sectionId = null,
+ string? sectionName = null)
=> new()
{
Id = id,
@@ -78,8 +93,18 @@ public static EtbEntry Rehydrate(
From = from,
To = to,
Edits = (edits ?? Enumerable.Empty()).ToList(),
+ SectionId = sectionId,
+ SectionName = sectionId is null ? null : sectionName,
};
+ ///
+ /// This entry assigned to the Einsatzabschnitt , called
+ /// , or to none with null. Which nodes may be chosen is
+ /// 's rule, not this method's.
+ ///
+ public EtbEntry WithSection(Guid? sectionId, string? sectionName) =>
+ this with { SectionId = sectionId, SectionName = sectionId is null ? null : sectionName };
+
///
/// Corrects this entry's text, recording what it was before under so every
/// prior version stays reachable — unlike 's
diff --git a/src/LageBuch.Domain/Incident.cs b/src/LageBuch.Domain/Incident.cs
index 61f129f4..24f3eb68 100644
--- a/src/LageBuch.Domain/Incident.cs
+++ b/src/LageBuch.Domain/Incident.cs
@@ -50,6 +50,15 @@ public sealed class Incident
///
public const string PartnerLeadsNoUnits = "Einsatzleitungen anderer Organisationen führen keine eigenen Einheiten.";
+ ///
+ /// Why an ETB entry cannot be assigned to a Bereitstellung or a partner's Einsatzleitung (#971),
+ /// in German: the ETB is filtered by Einsatzabschnitt, and neither of those is one.
+ ///
+ public const string OnlyEinsatzabschnitteForEntries = "Ein ETB-Eintrag kann nur einem Abschnitt oder Unterabschnitt zugeordnet werden.";
+
+ /// Why an app-written ETB line cannot be filed under an Einsatzabschnitt (#971), in German.
+ public const string AppWrittenEntriesHaveNoSection = "Automatisch erzeugte Einträge werden keinem Abschnitt zugeordnet.";
+
private readonly Dictionary _navOverrides = new(StringComparer.Ordinal);
private readonly List _checklists = new();
private readonly List _journal = new();
@@ -522,7 +531,8 @@ public EtbEntry AddJournalEntry(
string text,
string? from = null,
string? to = null,
- Guid? id = null)
+ Guid? id = null,
+ Guid? sectionId = null)
{
EnsureOpen();
ArgumentNullException.ThrowIfNull(clock);
@@ -539,12 +549,76 @@ public EtbEntry AddJournalEntry(
throw new ArgumentException("Ungültige Richtung für einen ETB-Eintrag.", nameof(direction));
}
+ // The app's own lines say where they belong themselves; only what a person wrote is filed.
+ if (sectionId is not null && EtbDirections.IsAppWritten(direction))
+ {
+ throw new InvalidOperationException(AppWrittenEntriesHaveNoSection);
+ }
+
+ var sectionName = sectionId is { } section ? EntrySectionLabel(section) : null;
var unused = id is { } given && given != Guid.Empty && _journal.All(e => e.Id != given) ? id : null;
- var entry = EtbEntry.Create(clock.Now, direction, text, op, from, to, unused);
+ var entry = EtbEntry.Create(clock.Now, direction, text, op, from, to, unused).WithSection(sectionId, sectionName);
_journal.Add(entry);
return entry;
}
+ ///
+ /// Files a manually written ETB entry under a live Abschnitt or Unterabschnitt (#971), moves it
+ /// to another, or takes it out of any with null. The entry keeps the node's label as it reads
+ /// now, so it still reads the same after a rename. Moving it where it already is writes nothing;
+ /// every real change leaves a System line, like .
+ ///
+ public EtbEntry AssignJournalEntrySection(IClock clock, SessionOperator op, Guid entryId, Guid? sectionId)
+ {
+ EnsureOpen();
+ ArgumentNullException.ThrowIfNull(clock);
+ ArgumentNullException.ThrowIfNull(op);
+
+ var index = _journal.FindIndex(e => e.Id == entryId);
+ if (index < 0)
+ {
+ throw new KeyNotFoundException($"ETB-Eintrag {entryId} nicht gefunden.");
+ }
+
+ var existing = _journal[index];
+ if (EtbDirections.IsAppWritten(existing.Direction))
+ {
+ throw new InvalidOperationException(AppWrittenEntriesHaveNoSection);
+ }
+
+ var sectionName = sectionId is { } section ? EntrySectionLabel(section) : null;
+ if (existing.SectionId == sectionId)
+ {
+ return existing;
+ }
+
+ var assigned = existing.WithSection(sectionId, sectionName);
+ _journal[index] = assigned;
+ var text = sectionName is not null
+ ? $"ETB-Eintrag {existing.Timestamp:HH:mm} → {sectionName}"
+ : $"ETB-Eintrag {existing.Timestamp:HH:mm}: Abschnitt aufgehoben (vorher {existing.SectionName ?? "unbekannt"})";
+ AppendSystemEntry(clock, op, text);
+ return assigned;
+ }
+
+ // The label an entry filed under sectionId keeps, once the node has been checked to be a live
+ // Abschnitt or Unterabschnitt of this incident.
+ private string EntrySectionLabel(Guid sectionId)
+ {
+ var node = FindCommandNode(sectionId) ?? throw new KeyNotFoundException($"Abschnitt {sectionId} nicht gefunden.");
+ if (node.Kind is not (CommandNodeKind.Abschnitt or CommandNodeKind.Unterabschnitt))
+ {
+ throw new InvalidOperationException(OnlyEinsatzabschnitteForEntries);
+ }
+
+ if (!node.IsLive)
+ {
+ throw new InvalidOperationException("Abschnitt ist aufgelöst.");
+ }
+
+ return NodeLabel(node.Id) ?? node.Name;
+ }
+
///
/// Corrects a manually-typed ETB entry's text, preserving the prior wording under
/// . System-direction entries (Kräfte, Atemschutz,
diff --git a/src/LageBuch.Persistence/IncidentRepository.cs b/src/LageBuch.Persistence/IncidentRepository.cs
index 9f16e845..e3b93a70 100644
--- a/src/LageBuch.Persistence/IncidentRepository.cs
+++ b/src/LageBuch.Persistence/IncidentRepository.cs
@@ -138,7 +138,7 @@ private static void WriteJournal(InsertCommands inserts, Incident incident)
var e = incident.Journal[i];
Run(
inserts,
- "INSERT INTO etb_entries (id, ordinal, timestamp, direction, from_party, to_party, text, entered_by) VALUES ($id,$o,$ts,$dir,$from,$to,$txt,$by);",
+ "INSERT INTO etb_entries (id, ordinal, timestamp, direction, from_party, to_party, text, entered_by, section_id, section_name) VALUES ($id,$o,$ts,$dir,$from,$to,$txt,$by,$sid,$sname);",
p =>
{
p("$id", e.Id.ToString());
@@ -149,6 +149,8 @@ private static void WriteJournal(InsertCommands inserts, Incident incident)
p("$to", (object?)e.To ?? DBNull.Value);
p("$txt", e.Text);
p("$by", e.EnteredBy);
+ p("$sid", (object?)e.SectionId?.ToString() ?? DBNull.Value);
+ p("$sname", (object?)e.SectionName ?? DBNull.Value);
});
for (var j = 0; j < e.Edits.Count; j++)
@@ -761,7 +763,7 @@ public static Incident Load(string path)
var journal = ReadAll(
cn,
- "SELECT id, timestamp, direction, from_party, to_party, text, entered_by FROM etb_entries ORDER BY ordinal;",
+ "SELECT id, timestamp, direction, from_party, to_party, text, entered_by, section_id, section_name FROM etb_entries ORDER BY ordinal;",
r =>
{
var id = Guid.Parse(r.GetString(0));
@@ -773,7 +775,9 @@ public static Incident Load(string path)
r.GetString(6),
Str(r, 3),
Str(r, 4),
- editsByEntry.TryGetValue(id, out var eds) ? eds : null);
+ editsByEntry.TryGetValue(id, out var eds) ? eds : null,
+ NullableGuid(r, 7),
+ Str(r, 8));
});
var roles = ReadAll(
diff --git a/src/LageBuch.Persistence/Sqlite/Migrations.cs b/src/LageBuch.Persistence/Sqlite/Migrations.cs
index b67e66d3..3652eb1c 100644
--- a/src/LageBuch.Persistence/Sqlite/Migrations.cs
+++ b/src/LageBuch.Persistence/Sqlite/Migrations.cs
@@ -8,7 +8,7 @@ namespace LageBuch.Persistence.Sqlite;
public static class Migrations
{
- public const int CurrentVersion = 46;
+ public const int CurrentVersion = 47;
public static int GetVersion(SqliteConnection cn)
{
@@ -315,6 +315,11 @@ public static void Migrate(SqliteConnection cn)
ApplyV46(cn, tx);
}
+ if (version < 47)
+ {
+ ApplyV47(cn, tx);
+ }
+
// The version gate above is not proof that the steps it skipped ever ran: a build from a
// parallel branch numbers its own migrations too, so a file can carry a marker this lineage
// never put there and be missing a column no `version < N` will ever add back. Reconcile the
@@ -1385,6 +1390,18 @@ private static void ApplyV46(SqliteConnection cn, SqliteTransaction tx)
// Stryker restore all
}
+ // The Einsatzabschnitt an ETB entry belongs to (#971): its id, for the quick filter, and its
+ // label as it read at assignment, so the entry still reads the same once the Abschnitt is
+ // renamed or dissolved. Additive and nullable: an older entry reads back with no Abschnitt.
+ // Stryker disable all : SchemaGuard.Reconcile adds these same columns on every open (see V26).
+ private static void ApplyV47(SqliteConnection cn, SqliteTransaction tx)
+ {
+ SchemaHelpers.AddColumnIfMissing(cn, tx, "etb_entries", "section_id", "TEXT");
+ SchemaHelpers.AddColumnIfMissing(cn, tx, "etb_entries", "section_name", "TEXT");
+
+ // Stryker restore all
+ }
+
[SuppressMessage(
"Security",
"CA2100",
diff --git a/src/LageBuch.Persistence/Sqlite/SchemaGuard.cs b/src/LageBuch.Persistence/Sqlite/SchemaGuard.cs
index f5d0c155..da7070fa 100644
--- a/src/LageBuch.Persistence/Sqlite/SchemaGuard.cs
+++ b/src/LageBuch.Persistence/Sqlite/SchemaGuard.cs
@@ -99,6 +99,8 @@ internal static class SchemaGuard
new("command_nodes", "fuehrungsfahrzeug", "TEXT", false, null),
new("etb_entries", "from_party", "TEXT", false, null),
new("etb_entries", "to_party", "TEXT", false, null),
+ new("etb_entries", "section_id", "TEXT", false, null),
+ new("etb_entries", "section_name", "TEXT", false, null),
new("force_unit_edits", "previous_zugfuehrer_count", "INTEGER", true, "0"),
new("force_units", "call_sign", "TEXT", false, null),
new("force_units", "status", "TEXT", false, null),
diff --git a/src/LageBuch.Sync/CommandApplier.cs b/src/LageBuch.Sync/CommandApplier.cs
index 51053761..59de5fd8 100644
--- a/src/LageBuch.Sync/CommandApplier.cs
+++ b/src/LageBuch.Sync/CommandApplier.cs
@@ -40,11 +40,14 @@ public static class CommandApplier
switch (command)
{
case AddJournalEntryCommand c:
- incident.AddJournalEntry(clock, Operator(c.Operator), c.Direction, c.Text, c.From, c.To, c.EntryId);
+ incident.AddJournalEntry(clock, Operator(c.Operator), c.Direction, c.Text, c.From, c.To, c.EntryId, c.SectionId);
break;
case EditJournalEntryCommand c:
incident.EditJournalEntry(clock, Operator(c.Operator), c.EntryId, c.Text);
break;
+ case AssignJournalEntrySectionCommand c:
+ incident.AssignJournalEntrySection(clock, Operator(c.Operator), c.EntryId, c.SectionId);
+ break;
case ChangeOperatorCommand c:
incident.ChangeOperator(clock, Operator(c.From), Operator(c.To));
break;
diff --git a/src/LageBuch.Sync/IIncidentSession.cs b/src/LageBuch.Sync/IIncidentSession.cs
index a4de5e29..9b7b8bd4 100644
--- a/src/LageBuch.Sync/IIncidentSession.cs
+++ b/src/LageBuch.Sync/IIncidentSession.cs
@@ -58,10 +58,13 @@ public interface IIncidentSession
/// The new entry's id, known at once even on a joined device: it mints the id and the host
/// keeps it, so an Aufgabe can be linked to the entry before the host's snapshot arrives.
///
- Guid AddJournalEntry(EtbDirection direction, string text, string? from = null, string? to = null);
+ Guid AddJournalEntry(EtbDirection direction, string text, string? from = null, string? to = null, Guid? sectionId = null);
void EditJournalEntry(Guid entryId, string text);
+ /// Files an ETB entry under an Einsatzabschnitt, or under none with null (#971).
+ void AssignJournalEntrySection(Guid entryId, Guid? sectionId);
+
void ToggleChecklistItem(Guid itemId);
void AssignRole(
diff --git a/src/LageBuch.Sync/IncidentSnapshot.cs b/src/LageBuch.Sync/IncidentSnapshot.cs
index ad798bcb..deea90cd 100644
--- a/src/LageBuch.Sync/IncidentSnapshot.cs
+++ b/src/LageBuch.Sync/IncidentSnapshot.cs
@@ -140,7 +140,9 @@ public sealed record EtbEntryDto(
string EnteredBy,
string? From,
string? To,
- IReadOnlyList Edits);
+ IReadOnlyList Edits,
+ Guid? SectionId = null,
+ string? SectionName = null);
public sealed record EtbEntryEditDto(string PreviousText, string EditedBy, DateTimeOffset EditedAt);
diff --git a/src/LageBuch.Sync/RemoteIncidentSession.cs b/src/LageBuch.Sync/RemoteIncidentSession.cs
index 22ccce7c..ceed1ffc 100644
--- a/src/LageBuch.Sync/RemoteIncidentSession.cs
+++ b/src/LageBuch.Sync/RemoteIncidentSession.cs
@@ -447,16 +447,21 @@ public void ChangeOperator(SessionOperator op)
Operator = op;
}
- public Guid AddJournalEntry(EtbDirection direction, string text, string? from = null, string? to = null)
+ public Guid AddJournalEntry(EtbDirection direction, string text, string? from = null, string? to = null, Guid? sectionId = null)
{
var id = Guid.NewGuid();
- Send(new AddJournalEntryCommand(Op(), direction, text, from, to, id));
+
+ // Stryker disable once Statement : only Sync.Hosting.Tests drive RemoteIncidentSession (see AddChecklist).
+ Send(new AddJournalEntryCommand(Op(), direction, text, from, to, id, sectionId));
return id;
}
public void EditJournalEntry(Guid entryId, string text) =>
Send(new EditJournalEntryCommand(Op(), entryId, text));
+ public void AssignJournalEntrySection(Guid entryId, Guid? sectionId) =>
+ Send(new AssignJournalEntrySectionCommand(Op(), entryId, sectionId));
+
public void ToggleChecklistItem(Guid itemId) => Send(new ToggleChecklistItemCommand(Op(), itemId));
public void AssignRole(
diff --git a/src/LageBuch.Sync/SnapshotMapper.cs b/src/LageBuch.Sync/SnapshotMapper.cs
index 09a1d9dc..286e8930 100644
--- a/src/LageBuch.Sync/SnapshotMapper.cs
+++ b/src/LageBuch.Sync/SnapshotMapper.cs
@@ -49,7 +49,9 @@ public static IncidentSnapshot ToSnapshot(Incident incident)
e.EnteredBy,
e.From,
e.To,
- e.Edits.Select(x => new EtbEntryEditDto(x.PreviousText, x.EditedBy, x.EditedAt)).ToList())).ToList(),
+ e.Edits.Select(x => new EtbEntryEditDto(x.PreviousText, x.EditedBy, x.EditedAt)).ToList(),
+ e.SectionId,
+ e.SectionName)).ToList(),
incident.Roles.Select(r => new RoleAssignmentDto(r.Id, r.Role, r.PersonName, r.CallSign, r.From, r.To, r.Section, r.Phone, r.NodeId, r.Slot)).ToList(),
incident.Forces.Select(f => new ForceUnitDto(
f.Id,
@@ -203,7 +205,9 @@ public static Incident FromSnapshot(IncidentSnapshot snapshot)
e.EnteredBy,
e.From,
e.To,
- e.Edits.Select(x => new EtbEntryEdit(x.PreviousText, x.EditedBy, x.EditedAt)))),
+ e.Edits.Select(x => new EtbEntryEdit(x.PreviousText, x.EditedBy, x.EditedAt)),
+ e.SectionId,
+ e.SectionName)),
snapshot.Roles.Select(r => new RoleAssignment(r.Id, r.Role, r.PersonName, r.CallSign, r.From, r.To, r.Section, r.Phone, r.NodeId, r.Slot)),
snapshot.Forces.Select(f => ForceUnit.Rehydrate(
f.Id,
diff --git a/src/LageBuch.Sync/SyncCommand.cs b/src/LageBuch.Sync/SyncCommand.cs
index dac67b1d..d6f41577 100644
--- a/src/LageBuch.Sync/SyncCommand.cs
+++ b/src/LageBuch.Sync/SyncCommand.cs
@@ -17,6 +17,7 @@ namespace LageBuch.Sync;
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(AddJournalEntryCommand), "addJournalEntry")]
[JsonDerivedType(typeof(EditJournalEntryCommand), "editJournalEntry")]
+[JsonDerivedType(typeof(AssignJournalEntrySectionCommand), "assignJournalEntrySection")]
[JsonDerivedType(typeof(ToggleChecklistItemCommand), "toggleChecklistItem")]
[JsonDerivedType(typeof(AssignRoleCommand), "assignRole")]
[JsonDerivedType(typeof(TransferRoleCommand), "transferRole")]
@@ -96,11 +97,15 @@ public sealed record OperatorDto(string Name, string? CallSign);
// EntryId is minted by the sending device so it can link an Aufgabe to the entry at once; the
// host honours it unless it is taken. Defaulted, so a payload from an older client still reads.
+// SectionId (#971) is defaulted for the same reason: an older client's entry is filed nowhere.
public sealed record AddJournalEntryCommand(
- OperatorDto Operator, EtbDirection Direction, string Text, string? From, string? To, Guid? EntryId = null) : SyncCommand;
+ OperatorDto Operator, EtbDirection Direction, string Text, string? From, string? To, Guid? EntryId = null, Guid? SectionId = null) : SyncCommand;
public sealed record EditJournalEntryCommand(OperatorDto Operator, Guid EntryId, string Text) : SyncCommand;
+/// Files an ETB entry under an Einsatzabschnitt, moves it, or takes it out of any with a null (#971).
+public sealed record AssignJournalEntrySectionCommand(OperatorDto Operator, Guid EntryId, Guid? SectionId) : SyncCommand;
+
/// A new Lagebuchführer takes over at the sending device (#469). Only the ETB line and
/// the audit event need the host: every later command already carries the new operator.
public sealed record ChangeOperatorCommand(OperatorDto From, OperatorDto To) : SyncCommand;
diff --git a/src/LageBuch.Sync/SyncProtocol.cs b/src/LageBuch.Sync/SyncProtocol.cs
index 24fe2c7f..856b170d 100644
--- a/src/LageBuch.Sync/SyncProtocol.cs
+++ b/src/LageBuch.Sync/SyncProtocol.cs
@@ -262,15 +262,21 @@ public static class SyncProtocol
/// in the Funkrufname a Trupp already had, so no command changes. A peer at 44 drops the key
/// and offers its free Funkrufname box instead, so the floor stays at 44.
///
+ ///
+ /// 46: a client may send assignJournalEntrySection, addJournalEntry may carry a
+ /// sectionId, and the snapshot's ETB entries carry sectionId and
+ /// sectionName, the Einsatzabschnitt an entry is filed under (#971). A host at 45 would
+ /// reject the command, and would file a joined device's entry nowhere, so the floor rises to 46.
+ ///
///
- public const int ProtocolVersion = 45;
+ public const int ProtocolVersion = 46;
///
/// 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 for
/// when to raise this.
///
- public const int MinimumProtocolVersion = 44;
+ public const int MinimumProtocolVersion = 46;
///
/// What an absent or zero protocol number on the wire means: the contract as it stood at v0.6.1,
diff --git a/tests/LageBuch.Acceptance.Tests/EtbSectionStripTests.cs b/tests/LageBuch.Acceptance.Tests/EtbSectionStripTests.cs
new file mode 100644
index 00000000..0e449431
--- /dev/null
+++ b/tests/LageBuch.Acceptance.Tests/EtbSectionStripTests.cs
@@ -0,0 +1,189 @@
+using System.Diagnostics;
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Headless;
+using Avalonia.Headless.XUnit;
+using Avalonia.Threading;
+using Avalonia.VisualTree;
+using LageBuch.App.Shared.Controls;
+using LageBuch.App.Shared.Views;
+using LageBuch.AppLogic;
+using LageBuch.AppLogic.Services;
+using LageBuch.AppLogic.ViewModels;
+using LageBuch.Domain;
+using LageBuch.Domain.Leadership;
+using LageBuch.Persistence.MasterData;
+
+namespace LageBuch.Acceptance.Tests;
+
+// #971: the ETB's Einsatzabschnitt picker among the dock's fields, the quick filter above the grid and
+// the Abschnitt badge on a filed row. With RENDER_OUT set it also writes the PR screenshots.
+public class EtbSectionStripTests
+{
+ private static (Window Window, IncidentWorkspaceViewModel Vm, LocalIncidentSession Session) ShowWorkspace(bool withAbschnitte)
+ {
+ var session = TestSession.StartNew(
+ new FakeStore(),
+ new FixedClock(),
+ new SessionOperator(AnonymizedExampleData.OperatorSurname, "FFB 12/1"),
+ "/x.lagebuch",
+ Array.Empty<(string, bool)>(),
+ Array.Empty<(string, bool)>());
+ if (withAbschnitte)
+ {
+ session.AddCommandNode(CommandNodeKind.Abschnitt, "Nord");
+ session.AddCommandNode(CommandNodeKind.Abschnitt, "Süd");
+ var sued = session.Incident.CommandNodes.Single(n => n.Name == "Süd").Id;
+ session.AddCommandNode(CommandNodeKind.Unterabschnitt, "Tiefgarage", sued);
+ session.AddCommandNode(CommandNodeKind.Bereitstellung, "Festplatz");
+ }
+
+ var vm = new IncidentWorkspaceViewModel(
+ session,
+ new FixedClock(),
+ new NoopTicker(),
+ MasterDataSet.Empty with { Vehicles = AnonymizedExampleData.Vehicles },
+ new FakeDialogs(),
+ new NoopAlarmService(),
+ new NoopIncidentHostController());
+ var window = new Window { Content = new IncidentWorkspaceView { DataContext = vm }, Width = 1920, Height = 1032 };
+ window.Show();
+ Dispatcher.UIThread.RunJobs();
+ WorkspaceRenderHelper.SelectTab(window, "ETB");
+ Dispatcher.UIThread.RunJobs();
+ return (window, vm, session);
+ }
+
+ private static T Named(Window window, string name)
+ where T : Control =>
+ window.GetVisualDescendants().OfType().Single(c => c.Name == name);
+
+ private static List