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 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-07-27 13:27:02 +02:00
parent c8c1686395
commit 1db2d6389c
5 changed files with 30 additions and 6 deletions

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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<String> = [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

View File

@@ -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)) }
}
}
}

View File

@@ -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)