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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user