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:
@@ -204,7 +204,7 @@ struct CheckInFormView: View {
|
|||||||
Picker("Lagerort", selection: $locationId) {
|
Picker("Lagerort", selection: $locationId) {
|
||||||
Text("– keiner –").tag(String?.none)
|
Text("– keiner –").tag(String?.none)
|
||||||
ForEach(locations) { location in
|
ForEach(locations) { location in
|
||||||
Text(location.name).tag(String?.some(location.id))
|
Text(location.path(in: locations)).tag(String?.some(location.id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Button {
|
Button {
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ struct ItemEditView: View {
|
|||||||
Section {
|
Section {
|
||||||
Picker("Lagerort", selection: $locationId) {
|
Picker("Lagerort", selection: $locationId) {
|
||||||
Text("– ohne –").tag(String?.none)
|
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) {
|
Picker("Gekauft bei", selection: $shopId) {
|
||||||
Text("– unbekannt –").tag(Int?.none)
|
Text("– unbekannt –").tag(Int?.none)
|
||||||
@@ -431,7 +431,7 @@ struct ItemAddSheet: View {
|
|||||||
Stepper("Anzahl: \(count)", value: $count, in: 1...200)
|
Stepper("Anzahl: \(count)", value: $count, in: 1...200)
|
||||||
Picker("Lagerort", selection: $locationId) {
|
Picker("Lagerort", selection: $locationId) {
|
||||||
Text("– ohne –").tag(String?.none)
|
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) {
|
Picker("Gekauft bei", selection: $shopId) {
|
||||||
Text("– unbekannt –").tag(Int?.none)
|
Text("– unbekannt –").tag(Int?.none)
|
||||||
|
|||||||
@@ -572,6 +572,29 @@ protocol TreeItem: Identifiable {
|
|||||||
extension CategoryItem: TreeItem {}
|
extension CategoryItem: TreeItem {}
|
||||||
extension StorageLocation: 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").
|
/// Shop / Bezugsquelle fuer Gegenstaende ("gekauft bei").
|
||||||
struct ShopItem: Codable, Identifiable, Hashable {
|
struct ShopItem: Codable, Identifiable, Hashable {
|
||||||
let id: Int
|
let id: Int
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ struct ObjectStockSection: View {
|
|||||||
private var einheit: String { product.unitName.isEmpty ? "Stück" : product.unitName }
|
private var einheit: String { product.unitName.isEmpty ? "Stück" : product.unitName }
|
||||||
private func ortName(_ id: String?) -> String {
|
private func ortName(_ id: String?) -> String {
|
||||||
guard let id else { return "Ohne Lagerort" }
|
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 {
|
var body: some View {
|
||||||
@@ -175,7 +176,7 @@ private struct LocationPicker: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
Picker(title, selection: $selection) {
|
Picker(title, selection: $selection) {
|
||||||
Text("– ohne Lagerort –").tag(String?.none)
|
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)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ struct ProductLocationMinView: View {
|
|||||||
HStack {
|
HStack {
|
||||||
Picker("Lagerort", selection: $row.locationId) {
|
Picker("Lagerort", selection: $row.locationId) {
|
||||||
Text("– wählen –").tag(String?.none)
|
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)
|
TextField("Menge", text: $row.amount)
|
||||||
.keyboardType(.decimalPad)
|
.keyboardType(.decimalPad)
|
||||||
|
|||||||
Reference in New Issue
Block a user