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

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