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
1 change: 1 addition & 0 deletions changelog.d/+vehicle-type-codes.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A new Stammdaten list of Fahrzeugkennungen fills an empty Fahrzeugtyp from the middle number of a Funkrufname (the 12 in "FFB 1/12/1") in the editor, the Kräfte form and the alarm import, the Fahrzeugtyp pickers list the MZF and sort alphabetically, and the Kräfte Fahrzeug picker reads by Wache and Funkrufname with numbers in order.
6 changes: 6 additions & 0 deletions docs/master-data.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@
{ "wache": "FF Musterstadt", "callSign": "Florian Musterstadt 11/1", "seats": 6, "hasZugfuehrer": true, "isOwn": true, "phone": "01 71 / 2 34 56 78", "email": "kdow@ff-musterstadt.example", "vehicleType": "KdoW" },
{ "wache": "FF Musterdorf", "callSign": "Florian Musterdorf 40/1", "seats": 9, "hasZugfuehrer": false, "isOwn": false, "vehicleType": "LF" }
],
"vehicleTypeCodes": [
{ "kennung": "10", "vehicleType": "KdoW" },
{ "kennung": "11", "vehicleType": "ELW 1" },
{ "kennung": "12", "vehicleType": "MZF" },
{ "kennung": "44", "vehicleType": "LF 20" }
],
"dispatchPlaceNames": [
{ "name": "Musterstadt", "abbreviation": "MST" }
],
Expand Down
14 changes: 14 additions & 0 deletions docs/master-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ Funkrufname the alarm already ends with, such as `Maisach 40/1`, needs no entry.
the list in an **Alarmierung** section. The list is used only for matching; nothing of it enters
an Einsatz.

## Fahrzeugkennungen

`vehicleTypeCodes` maps the Fahrzeugkennung, the middle number of a Funkrufname such as
`FFB 1/12/1` or `Florian Emmering 1/12/1`, to the Fahrzeugtyp it stands for:
`{ "kennung": "12", "vehicleType": "MZF" }`. Both fields are required and at most 16
characters, the cap a Fahrzeugtyp has everywhere. A Funkrufname that does not end in three numbers
split by slashes (`Florian Musterdorf 40/1`) has no Kennung and is left alone.

A vehicle whose Fahrzeugtyp is empty takes it from this list: in the editor as its Funkrufname is
typed, in the Kräfte form when it is picked, and in the alarm import, which also types a unit the
Stammdaten do not know. A Fahrzeugtyp already chosen is never replaced. For a Kennung listed twice
the first entry wins. The editor shows the list in a **Fahrzeugkennungen** section. Only the type's
text enters an Einsatz, never a reference to the list.

## Kontakte: die Notiz ist das Suchfeld

A personnel row carries an optional `email` and an optional `note` besides the
Expand Down
49 changes: 49 additions & 0 deletions src/LageBuch.App.Shared/Views/MasterDataEditorView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,55 @@
</DockPanel>
</DataTemplate>

<!-- Fahrzeugkennungen: the middle number of a Funkrufname and the Fahrzeugtyp it stands
for. The type offers the Fahrzeuge's suggestions; free text stays valid. Only a
repeated Kennung makes the order matter, so rows do not move. -->
<DataTemplate x:DataType="vm:VehicleTypeCodesSection">
<DockPanel Classes="add-below">
<TextBlock x:Name="VehicleTypeCodesHint" DockPanel.Dock="Top" Classes="secondary" FontSize="12"
TextWrapping="Wrap" Margin="0,0,0,10"
Text="Die mittlere Zahl im Funkrufnamen nennt den Fahrzeugtyp: „FFB 1/12/1“ hat die Kennung 12. Ein Fahrzeug ohne Typ erhält ihn hiermit, sobald sein Funkrufname eingetragen ist. Ein gewählter Typ bleibt." />
<Button DockPanel.Dock="Bottom" Classes="signal add-row" Content="+ HINZUFÜGEN"
HorizontalAlignment="Left" Margin="0,12,0,0" Command="{Binding AddCommand}" />
<Grid DockPanel.Dock="Top" ColumnDefinitions="120,*,32" Margin="0,0,0,6">
<TextBlock Grid.Column="0" Text="KENNUNG" Classes="overline" FontSize="10" />
<TextBlock Grid.Column="1" Text="FAHRZEUGTYP" Classes="overline" FontSize="10" />
</Grid>
<ScrollViewer>
<ItemsControl ItemsSource="{Binding Rows}" b:FocusNewItem.IsEnabled="True">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:VehicleTypeCodeRow">
<Grid ColumnDefinitions="120,*,32" Margin="0,0,0,6">
<TextBox x:Name="KennungBox" Grid.Column="0" AutomationProperties.Name="Kennung"
PlaceholderText="{x:Static md:AnonymizedExampleData.VehicleKennungPlaceholder}"
MaxLength="{x:Static md:VehicleTypeCode.MaxLength}"
Text="{Binding Kennung}" Margin="0,0,6,0" />
<Grid Grid.Column="1" Margin="0,0,6,0">
<AutoCompleteBox x:Name="VehicleTypeCodeTypeBox" AutomationProperties.Name="Fahrzeugtyp"
PlaceholderText="{x:Static md:AnonymizedExampleData.VehicleKennungTypePlaceholder}"
ItemsSource="{x:Static vm:VehicleRow.VehicleTypeOptions}"
FilterMode="ContainsOrdinal" MinimumPrefixLength="0"
Text="{Binding VehicleType}" />
<PathIcon Width="9" Height="9" HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,9,0" IsHitTestVisible="False"
Foreground="{StaticResource TextMutedBrush}"
Data="M7.41 8.59 12 13.17l4.59-4.58L18 10l-6 6-6-6z" />
</Grid>
<!-- ReflectionBinding: see the Links rows. -->
<Button Grid.Column="2" Classes="icon-btn" ToolTip.Tip="Entfernen"
AutomationProperties.Name="Entfernen"
Command="{ReflectionBinding $parent[ItemsControl].DataContext.RemoveCommand}"
CommandParameter="{Binding}">
<PathIcon Data="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" />
</Button>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</DockPanel>
</DataTemplate>

<!-- Vehicles editor (#76): Wache + Funkrufname + Fahrzeugtyp + Fahrzeugtelefon + E-Mail + Sitzplätze. -->
<DataTemplate x:DataType="vm:VehiclesSection">
<DockPanel Classes="add-below">
Expand Down
13 changes: 8 additions & 5 deletions src/LageBuch.AppLogic/Services/Dispatch/DispatchImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ public string JournalText()
/// Writes the alarm into a freshly started incident: the address, the Einsatzort, the alarm
/// entry and the ticked Einsatzmittel. A street the Stammdaten know fills in Ortsteil, PLZ and
/// Ort where all of its rows agree, as the Einsatzdaten dialog does (#461); otherwise the
/// alarm's own PLZ and Ort stand.
/// alarm's own PLZ and Ort stand. A unit without a Fahrzeugtyp takes the one its Funkrufname's
/// Kennung stands for in <paramref name="vehicleTypeCodes"/>; a type the Stammdaten give a
/// vehicle is never replaced.
/// </summary>
public void ApplyTo(IIncidentSession session, IReadOnlyList<Street> streets)
public void ApplyTo(IIncidentSession session, IReadOnlyList<Street> streets, IReadOnlyList<VehicleTypeCode>? vehicleTypeCodes = null)
{
ArgumentNullException.ThrowIfNull(session);
ArgumentNullException.ThrowIfNull(streets);
Expand Down Expand Up @@ -137,13 +139,14 @@ public void ApplyTo(IIncidentSession session, IReadOnlyList<Street> streets)
{
if (unit.Vehicle is { } vehicle)
{
var preset = VehiclePreset.Of(vehicle);
var preset = VehiclePreset.Of(vehicle, vehicleTypeCodes);
session.AddForceUnit(vehicle.Wache, preset.Strength, vehicle.CallSign, officerCount: preset.Officers, zugfuehrerCount: preset.Zugfuehrer, vehicleType: preset.VehicleType);
}
else
{
// Not in the Stammdaten: the Funkrufname as alarmed, Stärke still to be reported.
session.AddForceUnit(Alarm.Organisation ?? unit.Name, 0, unit.Name);
// Not in the Stammdaten: the Funkrufname as alarmed, Stärke still to be reported,
// and the type its Kennung stands for.
session.AddForceUnit(Alarm.Organisation ?? unit.Name, 0, unit.Name, vehicleType: VehicleTypeCode.TypeFor(unit.Name, vehicleTypeCodes ?? []));
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/LageBuch.AppLogic/ViewModels/ForcesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ public sealed partial class ForcesViewModel : ObservableObject, INarrowAware, IE
private readonly Action _onChanged;
private readonly Action<string, string, Action> _requestConfirm;
private readonly IReadOnlyList<Vehicle> _masterVehicles;
private readonly IReadOnlyList<VehicleTypeCode> _vehicleTypeCodes;

/// <summary>
/// <paramref name="requestConfirm"/> asks the host to confirm a destructive action before
Expand All @@ -417,6 +418,7 @@ public ForcesViewModel(
_onChanged = onChanged;
_requestConfirm = requestConfirm ?? ((_, _, onConfirmed) => onConfirmed());
_masterVehicles = masterData.Vehicles;
_vehicleTypeCodes = masterData.VehicleTypeCodes;
IsReadOnly = session.IsReadOnly;
StatusOptions = masterData.UnitStatus;
Forces = new ObservableCollection<ForceRow>(ByCallSign(session.Incident.Forces).Select(ToRow));
Expand Down Expand Up @@ -621,7 +623,8 @@ partial void OnNewBrigadeChanged(string value)
/// Fahrzeuge aller Wachen (#215): picking one derives Feuerwehr, so there is no need to type
/// it first. Ein bereits aufgenommenes Fahrzeug wird nicht noch einmal angeboten (#76
/// follow-up) — sein Funkrufname ist vergeben, bis seine Zeile entfernt wird. DistinctBy
/// schützt zusätzlich vor Duplikaten in Altdaten.
/// schützt zusätzlich vor Duplikaten in Altdaten. Sorted by Wache, then Funkrufname, numbers
/// by value, so "FFB 2/44/1" comes before "FFB 10/44/1"; the Stammdaten keep their own order.
/// </summary>
[ObservableProperty]
private IReadOnlyList<Vehicle> _vehicleOptions = Array.Empty<Vehicle>();
Expand All @@ -635,6 +638,8 @@ private void RefreshVehicleOptions()
VehicleOptions = _masterVehicles
.DistinctBy(v => v.CallSign, StringComparer.OrdinalIgnoreCase)
.Where(v => !taken.Contains(v.CallSign.Trim()))
.OrderBy(v => v.Wache.Trim(), CallSignOrder)
.ThenBy(v => v.CallSign.Trim(), CallSignOrder)
.ToArray();
}

Expand Down Expand Up @@ -666,7 +671,7 @@ partial void OnSelectedVehicleChanged(Vehicle? value)
NewCallSign = value.CallSign;

// Options first, so a type the catalogue lacks already has an entry to select.
var preset = VehiclePreset.Of(value);
var preset = VehiclePreset.Of(value, _vehicleTypeCodes);
NewVehicleTypeOptions = VehicleTypeChoices.For(preset.VehicleType);
NewVehicleType = VehicleTypeChoices.Of(preset.VehicleType);

Expand Down
2 changes: 1 addition & 1 deletion src/LageBuch.AppLogic/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private async Task NewIncidentAsync(NewIncidentRequest request)
keyword: dispatch?.Alarm.Keyword);
if (dispatch is not null)
{
dispatch.ApplyTo(session, md.Streets);
dispatch.ApplyTo(session, md.Streets, md.VehicleTypeCodes);
Dispatch?.MarkTaken(dispatch.Alarm);
}

Expand Down
14 changes: 13 additions & 1 deletion src/LageBuch.AppLogic/ViewModels/MasterDataEditorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public sealed partial class MasterDataEditorViewModel : ObservableObject, INarro
private PremisesSection _premises = null!;
private PersonnelSection _personnel = null!;
private VehiclesSection _vehicles = null!;
private VehicleTypeCodesSection _vehicleTypeCodes = null!;
Comment thread
DeepDiver1975 marked this conversation as resolved.
Resolved
private DispatchPlaceNamesSection _dispatchPlaceNames = null!;
private StreetsSection _streets = null!;
private TalkGroupsSection _talkGroups = null!;
Expand Down Expand Up @@ -300,7 +301,17 @@ private void PopulateSections(MasterDataSet set)
// Wachen and Funkrufnamen have no section of their own: they are derived from these
// rows (plus the roster), so the vehicle list is the single place to maintain them.
// The derived lists still serve as typing suggestions for further rows.
_vehicles = new VehiclesSection("Fahrzeuge", set.Vehicles, set.Brigades, set.RadioCallSigns, OnVehiclesChanged, RequestConfirm),
// A Funkrufname typed into a row with no type takes the one its Kennung stands for,
// read from the Fahrzeugkennungen as they stand in the editor, saved or not.
_vehicles = new VehiclesSection(
"Fahrzeuge",
set.Vehicles,
set.Brigades,
set.RadioCallSigns,
OnVehiclesChanged,
RequestConfirm,
callSign => VehicleTypeCode.TypeFor(callSign, _vehicleTypeCodes.ToValues())),
_vehicleTypeCodes = new VehicleTypeCodesSection("Fahrzeugkennungen", set.VehicleTypeCodes, MarkDirty, RequestConfirm),
_talkGroups = new TalkGroupsSection("Funkgruppen", set.TalkGroups, MarkDirty, RequestConfirm),

// How the alarm mail spells a place the Funkrufnamen abbreviate, so its Einsatzmittel
Expand Down Expand Up @@ -447,6 +458,7 @@ private MasterDataSet BuildSet() => _original with
Navigation = _navigation.ToValues(),
Personnel = _personnel.ToPeople(),
Vehicles = _vehicles.ToValues(),
VehicleTypeCodes = _vehicleTypeCodes.ToValues(),
DispatchPlaceNames = _dispatchPlaceNames.ToValues(),
TalkGroups = _talkGroups.ToValues(),
Gases = _gases.ToValues(),
Expand Down
12 changes: 9 additions & 3 deletions src/LageBuch.AppLogic/ViewModels/VehiclePreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ namespace LageBuch.AppLogic.ViewModels;
/// <param name="Zugfuehrer">1 when the vehicle carries a Zugführer, else 0.</param>
/// <param name="Officers">The Führungskraft: one, while a seat is left for it.</param>
/// <param name="Mannschaft">The remaining seats.</param>
/// <param name="VehicleType">The catalogue's code when it knows the type, the Stammdaten's text when it does not.</param>
/// <param name="VehicleType">
/// The catalogue's code when it knows the type, the Stammdaten's text when it does not; for a
/// vehicle with none, the type its Funkrufname's Kennung stands for in the Fahrzeugkennungen.
/// </param>
public sealed record VehiclePreset(int Zugfuehrer, int Officers, int Mannschaft, string? VehicleType)
{
public int Strength => Zugfuehrer + Officers + Mannschaft;

public static VehiclePreset Of(Vehicle vehicle)
/// <summary>What <paramref name="vehicle"/> brings in; <paramref name="typeCodes"/> only fill a type it lacks.</summary>
public static VehiclePreset Of(Vehicle vehicle, IReadOnlyList<VehicleTypeCode>? typeCodes = null)
{
ArgumentNullException.ThrowIfNull(vehicle);

Expand All @@ -24,7 +28,9 @@ public static VehiclePreset Of(Vehicle vehicle)
// of being added on top (#260).
var zugfuehrer = vehicle.HasZugfuehrer ? 1 : 0;
var remainingSeats = Math.Max(vehicle.Seats - zugfuehrer, 0);
var vehicleType = Domain.VehicleTypes.Find(vehicle.VehicleType)?.Code ?? Domain.VehicleTypes.FromStored(vehicle.VehicleType);
var vehicleType = Domain.VehicleTypes.Find(vehicle.VehicleType)?.Code
?? Domain.VehicleTypes.FromStored(vehicle.VehicleType)
?? VehicleTypeCode.TypeFor(vehicle.CallSign, typeCodes ?? []);
return new VehiclePreset(zugfuehrer, Math.Min(1, remainingSeats), Math.Max(remainingSeats - 1, 0), vehicleType);
}
}
20 changes: 16 additions & 4 deletions src/LageBuch.AppLogic/ViewModels/VehicleRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ namespace LageBuch.AppLogic.ViewModels;
/// Fahrzeugtyp of its taktisches Zeichen. Wache and Funkrufname carry suggestion lists from the
/// master data for the view's AutoCompleteBox, the Fahrzeugtyp the codes of
/// <see cref="VehicleTypes"/> -- free text stays valid, so they are suggestions, not a closed set.
/// An empty Fahrzeugtyp fills in from the Fahrzeugkennungen as the Funkrufname is typed; a type
/// already there is never replaced.
/// </summary>
public sealed partial class VehicleRow : ObservableObject
{
private readonly Action _onChanged;
private readonly Func<string, string?>? _typeForCallSign;

public VehicleRow(
string wache,
Expand All @@ -25,9 +28,11 @@ public VehicleRow(
string? vehicleType,
IReadOnlyList<string> wacheOptions,
IReadOnlyList<string> callSignOptions,
Action onChanged)
Action onChanged,
Func<string, string?>? typeForCallSign = null)
{
_onChanged = onChanged;
_typeForCallSign = typeForCallSign;
_wache = wache;
_callSign = callSign;
_seats = seats;
Expand All @@ -46,8 +51,8 @@ public VehicleRow(
/// <summary>Suggestions: the Funkrufnamen of the vehicles and roster as loaded (derived, not a separate list).</summary>
public IReadOnlyList<string> CallSignOptions { get; }

/// <summary>Suggestions: every Fahrzeugtyp the Lagekarte has a sign for.</summary>
public static IReadOnlyList<string> VehicleTypeOptions { get; } = VehicleTypes.All.Select(t => t.Code).ToList();
/// <summary>Suggestions: every Fahrzeugtyp the Lagekarte has a sign for, alphabetically.</summary>
public static IReadOnlyList<string> VehicleTypeOptions => VehicleTypeChoices.Catalogue;

[ObservableProperty]
private string _wache;
Expand All @@ -68,7 +73,14 @@ public VehicleRow(

partial void OnWacheChanged(string value) => _onChanged();

partial void OnCallSignChanged(string value) => _onChanged();
partial void OnCallSignChanged(string value)
{
_onChanged();
if (string.IsNullOrWhiteSpace(VehicleType) && _typeForCallSign?.Invoke(value) is { } type)
{
VehicleType = type;
}
}

partial void OnSeatsChanged(int value) => _onChanged();

Expand Down
30 changes: 17 additions & 13 deletions src/LageBuch.AppLogic/ViewModels/VehicleTypeChoices.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
using System.Globalization;
using LageBuch.Domain;

namespace LageBuch.AppLogic.ViewModels;

/// <summary>
/// The entries of a Fahrzeugtyp picker: one for none, then the catalogue's codes. The Kräfte grid
/// and the Kräfte form share it, so both offer the same list (#886).
/// The entries of a Fahrzeugtyp picker: one for none, then the catalogue's codes alphabetically.
/// The Kräfte grid and the Kräfte form share it, so both offer the same list (#886).
/// </summary>
public static class VehicleTypeChoices
{
/// <summary>The picker's entry for a unit without a Fahrzeugtyp: the bare Kraftfahrzeug sign.</summary>
public const string None = "ohne Typ";

// German order, as the Geräte use (#846): a person looks a code up in it, and it is read in
// the fixed culture Formatting applies, numbers by value, so "ELW 1" stays before "ELW 2".
private static readonly StringComparer Alphabetical = StringComparer.Create(
CultureInfo.GetCultureInfo("de-DE"), CompareOptions.IgnoreCase | CompareOptions.NumericOrdering);

/// <summary>The catalogue's codes, alphabetically: what every Fahrzeugtyp picker offers.</summary>
public static IReadOnlyList<string> Catalogue { get; } = [.. VehicleTypes.All.Select(t => t.Code).Order(Alphabetical)];

/// <summary>
/// The entries for a unit that records <paramref name="recorded"/>. A type the catalogue lacks
/// -- an old file, another Feuerwehr's Stammdaten -- is offered too, so the picker shows what is
/// recorded instead of going blank.
/// recorded instead of going blank; it comes right after <see cref="None"/>, ahead of the
/// catalogue.
/// </summary>
public static IReadOnlyList<string> For(string? recorded)
{
var codes = VehicleTypes.All.Select(t => t.Code).ToList();
if (recorded is not null && VehicleTypes.Find(recorded) is null)
{
codes.Insert(0, recorded);
}

return [None, .. codes];
}
public static IReadOnlyList<string> For(string? recorded) =>
recorded is not null && VehicleTypes.Find(recorded) is null
? [None, recorded, .. Catalogue]
: [None, .. Catalogue];

/// <summary>
/// The picker's entry for a recorded Fahrzeugtyp: the catalogue's code when it matches in
Expand Down
Loading
Loading