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/+address-hausnummer-plz-ort.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Einsatzdaten: the address takes a Hausnummer, PLZ and Ort next to the Straße and Ortsteil, so an Einsatz outside the home Gemeinde is located unambiguously in the workspace header and the PDF (#401).
19 changes: 16 additions & 3 deletions src/LageBuch.App.Shared/Views/IncidentDataDialogView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@
PlaceholderText="z. B. B 1.2 260715 123" />
</HeaderedContentControl>
</Grid>
<Grid ColumnDefinitions="3*,2*" ColumnSpacing="12">
<!-- #401: every address part is optional. Inside the home Gemeinde STRASSE, HAUSNR. and
ORTSTEIL are enough; PLZ and ORT are for überörtliche Hilfe. -->
<Grid ColumnDefinitions="3*,*" ColumnSpacing="12">
<HeaderedContentControl Grid.Column="0" Classes="field" Header="STRASSE">
<TextBox x:Name="IncidentDataStreetBox" Text="{Binding Street}" PlaceholderText="z. B. Hauptstr. 12" />
<TextBox x:Name="IncidentDataStreetBox" Text="{Binding Street}" PlaceholderText="z. B. Hauptstr." />
</HeaderedContentControl>
<HeaderedContentControl Grid.Column="1" Classes="field" Header="ORTSTEIL">
<HeaderedContentControl Grid.Column="1" Classes="field" Header="HAUSNR.">
<TextBox x:Name="IncidentDataHouseNumberBox" Text="{Binding HouseNumber}" PlaceholderText="12" />
</HeaderedContentControl>
</Grid>
<Grid ColumnDefinitions="2*,3*,3*" ColumnSpacing="12">
<HeaderedContentControl Grid.Column="0" Classes="field" Header="PLZ">
<TextBox x:Name="IncidentDataPostalCodeBox" Text="{Binding PostalCode}" PlaceholderText="82256" />
</HeaderedContentControl>
<HeaderedContentControl Grid.Column="1" Classes="field" Header="ORT">
<TextBox x:Name="IncidentDataPlaceBox" Text="{Binding Place}" PlaceholderText="z. B. Fürstenfeldbruck" />
</HeaderedContentControl>
<HeaderedContentControl Grid.Column="2" Classes="field" Header="ORTSTEIL">
<TextBox x:Name="IncidentDataDistrictBox" Text="{Binding District}" PlaceholderText="z. B. Puch" />
</HeaderedContentControl>
</Grid>
Expand Down
3 changes: 2 additions & 1 deletion src/LageBuch.AppLogic/LocalIncidentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ public void SetScbaSafetyTrupp(Guid truppId, Guid? safetyTruppId) =>

public void SetKeyword(string? keyword) => Mutate(() => Incident.SetKeyword(keyword));

public void SetAddress(string? street, string? district) => Mutate(() => Incident.SetAddress(street, district));
public void SetAddress(string? street, string? district, string? houseNumber = null, string? postalCode = null, string? place = null) =>
Mutate(() => Incident.SetAddress(street, district, houseNumber, postalCode, place));

public void SetStatus(string? status) => Mutate(() => Incident.SetStatus(status));

Expand Down
37 changes: 29 additions & 8 deletions src/LageBuch.AppLogic/ViewModels/IncidentDataDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace LageBuch.AppLogic.ViewModels;

/// <summary>
/// The "Einsatzdaten" overlay behind the workspace header's edit affordance: Stichwort,
/// Einsatznummer, Straße and Ortsteil edited together, buffered until SPEICHERN (the CO-Messung
/// editor's contract, #242). It replaces the inline Einsatznummer editor (#69) -- the number is
/// Einsatznummer and the address (Straße, Hausnummer, PLZ, Ort, Ortsteil; #401) edited together,
/// buffered until SPEICHERN (the CO-Messung editor's contract, #242). It replaces the inline Einsatznummer editor (#69) -- the number is
/// still typically unknown at creation and added once ILS calls back, but it is now one field of
/// several rather than the only one editable after the fact; the address in particular had no UI
/// at all before, so the PDF's "Adresse" line was always empty. Closed fires on Speichern AND
Expand All @@ -29,6 +29,9 @@ public IncidentDataDialogViewModel(IIncidentSession session, Action onChanged)
_keyword = incident.Keyword;
_incidentNumber = incident.IncidentNumber?.Value;
_street = incident.Street;
_houseNumber = incident.HouseNumber;
_postalCode = incident.PostalCode;
_place = incident.Place;
_district = incident.District;
}

Expand All @@ -43,6 +46,15 @@ public IncidentDataDialogViewModel(IIncidentSession session, Action onChanged)
[ObservableProperty]
private string? _street;

[ObservableProperty]
private string? _houseNumber;

[ObservableProperty]
private string? _postalCode;

[ObservableProperty]
private string? _place;

[ObservableProperty]
private string? _district;

Expand All @@ -65,8 +77,7 @@ public bool HasChanges
var incident = _session.Incident;
return Normalize(Keyword) != incident.Keyword
|| Normalize(IncidentNumber) != incident.IncidentNumber?.Value
|| Normalize(Street) != incident.Street
|| Normalize(District) != incident.District;
|| AddressDiffers(incident);
}
}

Expand All @@ -81,8 +92,6 @@ private void Save()
var incident = _session.Incident;
var keyword = Normalize(Keyword);
var number = Normalize(IncidentNumber);
var street = Normalize(Street);
var district = Normalize(District);

var changed = false;
if (keyword != incident.Keyword)
Expand All @@ -97,9 +106,14 @@ private void Save()
changed = true;
}

if (street != incident.Street || district != incident.District)
if (AddressDiffers(incident))
{
_session.SetAddress(street, district);
_session.SetAddress(
Normalize(Street),
Normalize(District),
Normalize(HouseNumber),
Normalize(PostalCode),
Normalize(Place));
changed = true;
}

Expand Down Expand Up @@ -134,6 +148,13 @@ private void ConfirmDiscard()
[RelayCommand]
private void CancelDiscard() => IsDiscardConfirmOpen = false;

private bool AddressDiffers(Domain.Incident incident) =>
Normalize(Street) != incident.Street
|| Normalize(HouseNumber) != incident.HouseNumber
|| Normalize(PostalCode) != incident.PostalCode
|| Normalize(Place) != incident.Place
|| Normalize(District) != incident.District;

private static string? Normalize(string? value) =>
string.IsNullOrWhiteSpace(value) ? null : value.Trim();
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public IncidentWorkspaceViewModel(IIncidentSession session, IClock clock, ITicke
// Seed the backing fields directly so initialization doesn't trigger a write-back/save.
_keywordDisplay = _session.Incident.Keyword;
_incidentNumberInput = _session.Incident.IncidentNumber?.Value ?? string.Empty;
_addressDisplay = Formatting.Address(_session.Incident.Street, _session.Incident.District);
_addressDisplay = Formatting.Address(_session.Incident);

// The header is a projection of the incident's head data; any mutation -- the Einsatzdaten
// dialog on this device, or (host or joined client alike) a command from another device
Expand Down Expand Up @@ -325,7 +325,7 @@ private void RefreshIncidentData()
var incident = _session.Incident;
KeywordDisplay = incident.Keyword;
IncidentNumberInput = incident.IncidentNumber?.Value ?? string.Empty;
AddressDisplay = Formatting.Address(incident.Street, incident.District);
AddressDisplay = Formatting.Address(incident);
OnPropertyChanged(nameof(OperatorDisplay));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void ShowOperatorStage(Incident joined, MasterDataSet hostMasterData)
PersonOptions = OwnDisplayNames(_personnel);
CallSignOptions = hostMasterData.RadioCallSigns;
var keyword = string.IsNullOrWhiteSpace(joined.Keyword) ? "Unbenannter Einsatz" : joined.Keyword;
JoinedIncidentDisplay = Formatting.Address(joined.Street, joined.District) is { } address
JoinedIncidentDisplay = Formatting.Address(joined) is { } address
? $"{keyword} · {address}"
: keyword;
ErrorMessage = null;
Expand Down
2 changes: 1 addition & 1 deletion src/LageBuch.Documents/Sections/IncidentHeaderSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static void ComposeTitleBlock(IContainer container, Incident incident)
row.RelativeItem().Text(t =>
{
t.Span("Adresse: ").SemiBold();
t.Span(Formatting.OrDash(Formatting.Address(incident.Street, incident.District)));
t.Span(Formatting.OrDash(Formatting.Address(incident)));
});
});

Expand Down
19 changes: 15 additions & 4 deletions src/LageBuch.Domain/Formatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,25 @@ public static string Upper(string value)
public static string OrDash(string? value) =>
string.IsNullOrWhiteSpace(value) ? "—" : value;

// "Straße, Ortsteil" with blank parts dropped; null when neither is set. Shared by the
// workspace header and the PDF header so the two never render the address differently.
public static string? Address(string? street, string? district)
// "Straße Hausnr., Ortsteil, PLZ Ort" with blank parts dropped, in the order of a German
// postal address; null when nothing is set. Shared by the workspace header and the PDF
// header so the two never render the address differently.
public static string? Address(
string? street, string? district, string? houseNumber = null, string? postalCode = null, string? place = null)
{
var joined = string.Join(", ", new[] { street, district }.Where(s => !string.IsNullOrWhiteSpace(s)));
var joined = Join(", ", Join(" ", street, houseNumber), district, Join(" ", postalCode, place));
return joined.Length == 0 ? null : joined;
}

public static string? Address(Incident incident)
{
ArgumentNullException.ThrowIfNull(incident);
return Address(incident.Street, incident.District, incident.HouseNumber, incident.PostalCode, incident.Place);
}

private static string Join(string separator, params string?[] parts) =>
string.Join(separator, parts.OfType<string>().Select(s => s.Trim()).Where(s => s.Length > 0));

public static string Level(TaskImportance importance) => importance switch
{
TaskImportance.High => "Hoch",
Expand Down
28 changes: 24 additions & 4 deletions src/LageBuch.Domain/Incident.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ private Incident()

public string? Street { get; private set; }

public string? HouseNumber { get; private set; }

public string? PostalCode { get; private set; }

/// <summary>The Ort, for an Einsatz outside the home Gemeinde (#401); <see cref="District"/> stays the Ortsteil.</summary>
public string? Place { get; private set; }

public string? District { get; private set; }

public string? Status { get; private set; }
Expand Down Expand Up @@ -144,7 +151,10 @@ public static Incident Rehydrate(
IEnumerable<IncidentTask> tasks,
IEnumerable<Building> buildings,
IEnumerable<Dwelling> dwellings,
IEnumerable<InvolvedParty> involvedParties)
IEnumerable<InvolvedParty> involvedParties,
string? houseNumber = null,
string? postalCode = null,
string? place = null)
{
var incident = new Incident
{
Expand All @@ -154,6 +164,9 @@ public static Incident Rehydrate(
IncidentNumber = incidentNumber,
Keyword = keyword,
Street = street,
HouseNumber = houseNumber,
PostalCode = postalCode,
Place = place,
District = district,
Status = status,
ClosedAt = closedAt,
Expand Down Expand Up @@ -285,11 +298,16 @@ public void SetKeyword(string? keyword)
Keyword = string.IsNullOrWhiteSpace(keyword) ? null : keyword.Trim();
}

public void SetAddress(string? street, string? district)
// Every part is optional, and an omitted one is cleared: the one-Gemeinde workflow stays
// Straße + Ortsteil, and the PLZ and Ort only matter for überörtliche Hilfe (#401).
public void SetAddress(string? street, string? district, string? houseNumber = null, string? postalCode = null, string? place = null)
{
EnsureOpen();
Street = string.IsNullOrWhiteSpace(street) ? null : street.Trim();
District = string.IsNullOrWhiteSpace(district) ? null : district.Trim();
Street = TrimToNull(street);
HouseNumber = TrimToNull(houseNumber);
PostalCode = TrimToNull(postalCode);
Place = TrimToNull(place);
District = TrimToNull(district);
}

public void SetStatus(string? status)
Expand Down Expand Up @@ -803,6 +821,8 @@ public int NextFreeScbaTruppNumber() =>
// bucket; anything else is compared trimmed, the same way names are. Ordinal-ignore-case rather
// than InvariantCulture: these are operator-typed labels, not identifiers, and the app compares
// every other such value this way.
private static string? TrimToNull(string? value) => string.IsNullOrWhiteSpace(value) ? null : value.Trim();

private static string NormalizeSection(string? value) => string.IsNullOrWhiteSpace(value) ? string.Empty : value.Trim();

public AtemschutzTrupp AddScbaTrupp(
Expand Down
12 changes: 9 additions & 3 deletions src/LageBuch.Persistence/IncidentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static void Write(string path, Incident incident, bool migrate)

Run(
inserts,
"INSERT INTO incident_meta (id, started_at, state, incident_number, ils_number, keyword, street, district, status, closed_at, closed_by) " + "VALUES ($id,$started,$state,$num,$ils,$kw,$street,$district,$status,$closedAt,$closedBy);",
"INSERT INTO incident_meta (id, started_at, state, incident_number, ils_number, keyword, street, district, status, closed_at, closed_by, house_number, postal_code, place) " + "VALUES ($id,$started,$state,$num,$ils,$kw,$street,$district,$status,$closedAt,$closedBy,$houseNumber,$postalCode,$place);",
p =>
{
p("$id", incident.Id.ToString());
Expand All @@ -85,6 +85,9 @@ private static void Write(string path, Incident incident, bool migrate)
p("$status", (object?)incident.Status ?? DBNull.Value);
p("$closedAt", (object?)incident.ClosedAt?.ToString(Iso) ?? DBNull.Value);
p("$closedBy", (object?)incident.ClosedBy ?? DBNull.Value);
p("$houseNumber", (object?)incident.HouseNumber ?? DBNull.Value);
p("$postalCode", (object?)incident.PostalCode ?? DBNull.Value);
p("$place", (object?)incident.Place ?? DBNull.Value);
});

for (var i = 0; i < incident.Checklists.Count; i++)
Expand Down Expand Up @@ -547,7 +550,7 @@ public static Incident Load(string path)

var meta = ReadRow(
cn,
"SELECT id, started_at, state, incident_number, ils_number, keyword, street, district, status, closed_at, closed_by FROM incident_meta LIMIT 1;");
"SELECT id, started_at, state, incident_number, ils_number, keyword, street, district, status, closed_at, closed_by, house_number, postal_code, place FROM incident_meta LIMIT 1;");

// One query per table, grouped in C# -- the same shape as editsByEntry below. Items whose
// list_id matches no list row are dropped: V23 fills list_id for every row it finds, so a
Expand Down Expand Up @@ -826,7 +829,10 @@ public static Incident Load(string path)
tasks,
buildings,
dwellings,
involvedParties);
involvedParties,
meta[11] as string,
meta[12] as string,
meta[13] as string);
}

private static DateTimeOffset ParseDate(string s) =>
Expand Down
25 changes: 24 additions & 1 deletion src/LageBuch.Persistence/Sqlite/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace LageBuch.Persistence.Sqlite;

public static class Migrations
{
public const int CurrentVersion = 25;
public const int CurrentVersion = 26;

public static int GetVersion(SqliteConnection cn)
{
Expand Down Expand Up @@ -165,6 +165,16 @@ public static void Migrate(SqliteConnection cn)
ApplyV25(cn, tx);
}

// Stryker disable all : V26 only adds nullable columns that SchemaGuard.Reconcile below adds
// identically on every open, so skipping it is unobservable; the step stays for the version
// history and as the place a later backfill would go.
if (version < 26)
{
ApplyV26(cn, tx);

// Stryker restore all
}

// 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
Expand Down Expand Up @@ -793,6 +803,19 @@ created_at TEXT NOT NULL
Exec(cn, tx, sql25);
}

// Hausnummer, PLZ and Ort next to Straße and Ortsteil (#401), for an Einsatz outside the home
// Gemeinde. All nullable: an older file opens with them blank and reads exactly as before.
// Stryker disable all : SchemaGuard.Reconcile adds these same columns on every open, so no
// mutant here can change the file's final shape (see the call site).
private static void ApplyV26(SqliteConnection cn, SqliteTransaction tx)
{
SchemaHelpers.AddColumnIfMissing(cn, tx, "incident_meta", "house_number", "TEXT");
SchemaHelpers.AddColumnIfMissing(cn, tx, "incident_meta", "postal_code", "TEXT");
SchemaHelpers.AddColumnIfMissing(cn, tx, "incident_meta", "place", "TEXT");

// Stryker restore all
}

private static void SetVersion(SqliteConnection cn, SqliteTransaction tx, int version)
{
Exec(cn, tx, "DELETE FROM schema_version;");
Expand Down
3 changes: 3 additions & 0 deletions src/LageBuch.Persistence/Sqlite/SchemaGuard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ internal static class SchemaGuard
new("incident_meta", "keyword", "TEXT", false, null),
new("incident_meta", "street", "TEXT", false, null),
new("incident_meta", "district", "TEXT", false, null),
new("incident_meta", "house_number", "TEXT", false, null),
new("incident_meta", "postal_code", "TEXT", false, null),
new("incident_meta", "place", "TEXT", false, null),
new("incident_meta", "status", "TEXT", false, null),
new("incident_meta", "closed_at", "TEXT", false, null),
new("incident_meta", "closed_by", "TEXT", false, null),
Expand Down
2 changes: 1 addition & 1 deletion src/LageBuch.Sync/CommandApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static class CommandApplier
incident.SetKeyword(c.Keyword);
break;
case SetAddressCommand c:
incident.SetAddress(c.Street, c.District);
incident.SetAddress(c.Street, c.District, c.HouseNumber, c.PostalCode, c.Place);
break;
case SetStatusCommand c:
incident.SetStatus(c.Status);
Expand Down
2 changes: 1 addition & 1 deletion src/LageBuch.Sync/IIncidentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void AddScbaTrupp(

void SetKeyword(string? keyword);

void SetAddress(string? street, string? district);
void SetAddress(string? street, string? district, string? houseNumber = null, string? postalCode = null, string? place = null);

void SetStatus(string? status);

Expand Down
5 changes: 4 additions & 1 deletion src/LageBuch.Sync/IncidentSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public sealed record IncidentSnapshot(
// Defaulted like DwellingDto.Readings: a snapshot without the key reads as "no Beteiligte".
IReadOnlyList<InvolvedPartyDto>? InvolvedParties = null,
long Revision = 0,
Guid Epoch = default);
Guid Epoch = default,
string? HouseNumber = null,
string? PostalCode = null,
string? Place = null);

public sealed record TimerDto(
string Key,
Expand Down
3 changes: 2 additions & 1 deletion src/LageBuch.Sync/RemoteIncidentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ public void SetScbaSafetyTrupp(Guid truppId, Guid? safetyTruppId) =>

public void SetKeyword(string? keyword) => Send(new SetKeywordCommand(keyword));

public void SetAddress(string? street, string? district) => Send(new SetAddressCommand(street, district));
public void SetAddress(string? street, string? district, string? houseNumber = null, string? postalCode = null, string? place = null) =>
Send(new SetAddressCommand(street, district, houseNumber, postalCode, place));

public void SetStatus(string? status) => Send(new SetStatusCommand(status));

Expand Down
Loading
Loading