From 1db2d6389c1cce031c3cea790917468452bd1521 Mon Sep 17 00:00:00 2001 From: Scarriffle Date: Mon, 27 Jul 2026 13:27:02 +0200 Subject: [PATCH] iOS: Lagerort-Picker zeigen den vollen Pfad statt nur den Namen Wie im Web: alle Lagerort-Auswahlen (Einlagern, Einzelstueck/Item, Objekt-Bestand hinzufuegen/umlagern/entfernen, Mindestbestand je Ort) zeigen 'Hedingen -> Keller -> Schublade 1' statt nur 'Schublade 1', damit gleichnamige Orte unterscheidbar sind. Neuer Helfer StorageLocation.path(in:) bzw. locationPath(_:in:) in Models.swift. Co-Authored-By: Claude Opus 4.8 --- ios/Sources/CheckInFormView.swift | 2 +- ios/Sources/ItemViews.swift | 4 ++-- ios/Sources/Models.swift | 23 +++++++++++++++++++++++ ios/Sources/ObjectStockView.swift | 5 +++-- ios/Sources/ProductDetailView.swift | 2 +- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/ios/Sources/CheckInFormView.swift b/ios/Sources/CheckInFormView.swift index 4d9854e..30c9cf6 100644 --- a/ios/Sources/CheckInFormView.swift +++ b/ios/Sources/CheckInFormView.swift @@ -204,7 +204,7 @@ struct CheckInFormView: View { Picker("Lagerort", selection: $locationId) { Text("– keiner –").tag(String?.none) ForEach(locations) { location in - Text(location.name).tag(String?.some(location.id)) + Text(location.path(in: locations)).tag(String?.some(location.id)) } } Button { diff --git a/ios/Sources/ItemViews.swift b/ios/Sources/ItemViews.swift index 44bf50d..211f407 100644 --- a/ios/Sources/ItemViews.swift +++ b/ios/Sources/ItemViews.swift @@ -139,7 +139,7 @@ struct ItemEditView: View { Section { Picker("Lagerort", selection: $locationId) { Text("– ohne –").tag(String?.none) - ForEach(locations) { l in Text(l.name).tag(String?.some(l.id)) } + ForEach(locations) { l in Text(l.path(in: locations)).tag(String?.some(l.id)) } } Picker("Gekauft bei", selection: $shopId) { Text("– unbekannt –").tag(Int?.none) @@ -431,7 +431,7 @@ struct ItemAddSheet: View { Stepper("Anzahl: \(count)", value: $count, in: 1...200) Picker("Lagerort", selection: $locationId) { Text("– ohne –").tag(String?.none) - ForEach(locations) { l in Text(l.name).tag(String?.some(l.id)) } + ForEach(locations) { l in Text(l.path(in: locations)).tag(String?.some(l.id)) } } Picker("Gekauft bei", selection: $shopId) { Text("– unbekannt –").tag(Int?.none) diff --git a/ios/Sources/Models.swift b/ios/Sources/Models.swift index 91a6587..5ca353a 100644 --- a/ios/Sources/Models.swift +++ b/ios/Sources/Models.swift @@ -572,6 +572,29 @@ protocol TreeItem: Identifiable { extension CategoryItem: TreeItem {} extension StorageLocation: TreeItem {} +extension StorageLocation { + /// Voller Pfad „Hedingen → Keller → Schublade 1" aus der flachen Liste – + /// macht gleichnamige Orte in den Auswahlfeldern unterscheidbar. + func path(in all: [StorageLocation]) -> String { + let byId = Dictionary(all.map { ($0.id, $0) }, uniquingKeysWith: { a, _ in a }) + var teile = [name] + var gesehen: Set = [id] + var pid = parentId + while let cur = pid, !gesehen.contains(cur), let parent = byId[cur] { + teile.insert(parent.name, at: 0) + gesehen.insert(cur) + pid = parent.parentId + } + return teile.joined(separator: " → ") + } +} + +/// Pfad zu einer Lagerort-ID (leer, wenn unbekannt). +func locationPath(_ id: String?, in all: [StorageLocation]) -> String { + guard let id, let loc = all.first(where: { $0.id == id }) else { return "" } + return loc.path(in: all) +} + /// Shop / Bezugsquelle fuer Gegenstaende ("gekauft bei"). struct ShopItem: Codable, Identifiable, Hashable { let id: Int diff --git a/ios/Sources/ObjectStockView.swift b/ios/Sources/ObjectStockView.swift index 8a521d6..5763747 100644 --- a/ios/Sources/ObjectStockView.swift +++ b/ios/Sources/ObjectStockView.swift @@ -29,7 +29,8 @@ struct ObjectStockSection: View { private var einheit: String { product.unitName.isEmpty ? "Stück" : product.unitName } private func ortName(_ id: String?) -> String { guard let id else { return "Ohne Lagerort" } - return locations.first { $0.id == id }?.name ?? "Ort \(id)" + let pfad = locationPath(id, in: locations) + return pfad.isEmpty ? "Ort \(id)" : pfad } var body: some View { @@ -175,7 +176,7 @@ private struct LocationPicker: View { var body: some View { Picker(title, selection: $selection) { Text("– ohne Lagerort –").tag(String?.none) - ForEach(locations) { loc in Text(loc.name).tag(String?.some(loc.id)) } + ForEach(locations) { loc in Text(loc.path(in: locations)).tag(String?.some(loc.id)) } } } } diff --git a/ios/Sources/ProductDetailView.swift b/ios/Sources/ProductDetailView.swift index f6e87eb..46d24bd 100644 --- a/ios/Sources/ProductDetailView.swift +++ b/ios/Sources/ProductDetailView.swift @@ -443,7 +443,7 @@ struct ProductLocationMinView: View { HStack { Picker("Lagerort", selection: $row.locationId) { Text("– wählen –").tag(String?.none) - ForEach(locations) { l in Text(l.name).tag(String?.some(l.id)) } + ForEach(locations) { l in Text(l.path(in: locations)).tag(String?.some(l.id)) } } TextField("Menge", text: $row.amount) .keyboardType(.decimalPad)