Fixed bug with updating frozen realm model
This commit is contained in:
parent
ba0ebedc59
commit
3f789ca959
@ -63,5 +63,26 @@
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.SwiftErrorBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "4F72AC4F-FBCE-4C10-8BC2-2F434652DB31"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "42580582-DA14-40D4-869A-FF91FCA9957C"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
breakpointStackSelectionBehavior = "1"
|
||||
scope = "1"
|
||||
stopOnStyle = "0">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
||||
@ -344,7 +344,7 @@ class EventsController: UIViewController, UITableViewDataSource, UITableViewDele
|
||||
@discardableResult
|
||||
func update(vehicle: Vehicle) -> Bool {
|
||||
do {
|
||||
if let realm = self.vehicle?.realm {
|
||||
if let v = self.vehicle, let realm = v.realm, !v.isFrozen {
|
||||
try ExceptionCatcher.catch {
|
||||
try realm.write {
|
||||
realm.add(vehicle, update: .all)
|
||||
|
||||
@ -136,48 +136,54 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource
|
||||
}
|
||||
}
|
||||
|
||||
func row(_ tag: String) -> LabelRow? {
|
||||
self.form.rowBy(tag: tag) as? LabelRow
|
||||
func update(row tag: String, with value: String) {
|
||||
if let row = self.form.rowBy(tag: tag) as? LabelRow {
|
||||
row.value = value
|
||||
row.reload()
|
||||
}
|
||||
}
|
||||
|
||||
func sourceStatusRow(_ tag: String) -> SourceStatusRow? {
|
||||
self.form.rowBy(tag: tag) as? SourceStatusRow
|
||||
func update(sourceStatusRow tag: String, with value: DebugInfoEntry) {
|
||||
if let row = self.form.rowBy(tag: tag) as? SourceStatusRow {
|
||||
row.value = value
|
||||
row.reload()
|
||||
}
|
||||
}
|
||||
|
||||
func updateReport() {
|
||||
self.row("Model")?.value = self.vehicle?.brand?.name?.original ?? "<unknown>"
|
||||
self.row("Year")?.value = String(self.vehicle?.year ?? 0)
|
||||
self.row("Color")?.value = self.vehicle?.color ?? "<unknown>"
|
||||
self.row("Category")?.value = self.vehicle?.category ?? "<unknown>"
|
||||
self.row("STP")?.value = self.stringFromBool(self.vehicle?.isRightWheel.value, yes: NSLocalizedString("Right", comment: ""), no: NSLocalizedString("Left", comment: ""))
|
||||
self.row("Japanese")?.value = self.stringFromBool(self.vehicle?.isJapanese.value, yes: NSLocalizedString("Yes", comment: ""), no: NSLocalizedString("No", comment: ""))
|
||||
self.update(row: "Model", with: self.vehicle?.brand?.name?.original ?? "<unknown>")
|
||||
self.update(row: "Year", with: String(self.vehicle?.year ?? 0))
|
||||
self.update(row: "Color", with: self.vehicle?.color ?? "<unknown>")
|
||||
self.update(row: "Category", with: self.vehicle?.category ?? "<unknown>")
|
||||
self.update(row: "STP", with: self.stringFromBool(self.vehicle?.isRightWheel.value, yes: NSLocalizedString("Right", comment: ""), no: NSLocalizedString("Left", comment: "")))
|
||||
self.update(row: "Japanese", with: self.stringFromBool(self.vehicle?.isJapanese.value, yes: NSLocalizedString("Yes", comment: ""), no: NSLocalizedString("No", comment: "")))
|
||||
|
||||
var num = self.vehicle?.getNumber() ?? "<unknown>"
|
||||
if self.vehicle?.outdated ?? false, let current = self.vehicle?.currentNumber {
|
||||
num = "\(self.vehicle!.getNumber()) (\(current))"
|
||||
}
|
||||
self.row("PlateNumber")?.value = num
|
||||
self.update(row: "PlateNumber", with: num)
|
||||
|
||||
self.row("VIN")?.value = self.vehicle?.vin1 ?? "<unknown>"
|
||||
self.row("STS")?.value = self.vehicle?.sts ?? "<unknown>"
|
||||
self.row("PTS")?.value = self.vehicle?.pts ?? "<unknown>"
|
||||
self.row("EngineNumber")?.value = self.vehicle?.engine?.number ?? "<unknown>"
|
||||
self.row("FuelType")?.value = self.vehicle?.engine?.fuelType ?? "<unknown>"
|
||||
self.row("Volume")?.value = String(self.vehicle?.engine?.volume.value ?? 0)
|
||||
self.row("PowerHP")?.value = String(self.vehicle?.engine?.powerHp ?? 0)
|
||||
self.row("PowerKw")?.value = String(self.vehicle?.engine?.powerKw.value ?? 0)
|
||||
self.row("Events")?.value = String(self.vehicle?.events.count ?? 0)
|
||||
self.row("OSAGO")?.value = String(self.vehicle?.osagoContracts.count ?? 0)
|
||||
self.row("Owners")?.value = String(self.vehicle?.ownershipPeriods.count ?? 0)
|
||||
self.row("Photos")?.value = String(self.vehicle?.photos.count ?? 0)
|
||||
self.row("Ads")?.value = String(self.vehicle?.ads.count ?? 0)
|
||||
self.update(row: "VIN", with: self.vehicle?.vin1 ?? "<unknown>")
|
||||
self.update(row: "STS", with: self.vehicle?.sts ?? "<unknown>")
|
||||
self.update(row: "PTS", with: self.vehicle?.pts ?? "<unknown>")
|
||||
self.update(row: "EngineNumber", with: self.vehicle?.engine?.number ?? "<unknown>")
|
||||
self.update(row: "FuelType", with: self.vehicle?.engine?.fuelType ?? "<unknown>")
|
||||
self.update(row: "Volume", with: String(self.vehicle?.engine?.volume.value ?? 0))
|
||||
self.update(row: "PowerHP", with: String(self.vehicle?.engine?.powerHp ?? 0))
|
||||
self.update(row: "PowerKw", with: String(self.vehicle?.engine?.powerKw.value ?? 0))
|
||||
self.update(row: "Events", with: String(self.vehicle?.events.count ?? 0))
|
||||
self.update(row: "OSAGO", with: String(self.vehicle?.osagoContracts.count ?? 0))
|
||||
self.update(row: "Owners", with: String(self.vehicle?.ownershipPeriods.count ?? 0))
|
||||
self.update(row: "Photos", with: String(self.vehicle?.photos.count ?? 0))
|
||||
self.update(row: "Ads", with: String(self.vehicle?.ads.count ?? 0))
|
||||
|
||||
if let dInfo = self.vehicle?.debugInfo {
|
||||
self.sourceStatusRow("DebugAutocod")?.value = dInfo.autocod
|
||||
self.sourceStatusRow("DebugVin01Vin")?.value = dInfo.vin01vin
|
||||
self.sourceStatusRow("DebugVin01Base")?.value = dInfo.vin01base
|
||||
self.sourceStatusRow("DebugVin01History")?.value = dInfo.vin01history
|
||||
self.sourceStatusRow("DebugNomerogram")?.value = dInfo.nomerogram
|
||||
self.update(sourceStatusRow: "DebugAutocod", with: dInfo.autocod)
|
||||
self.update(sourceStatusRow: "DebugVin01Vin", with: dInfo.vin01vin)
|
||||
self.update(sourceStatusRow: "DebugVin01Base", with: dInfo.vin01base)
|
||||
self.update(sourceStatusRow: "DebugVin01History", with: dInfo.vin01history)
|
||||
self.update(sourceStatusRow: "DebugNomerogram", with: dInfo.nomerogram)
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +205,7 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource
|
||||
break
|
||||
}
|
||||
|
||||
self.form.allSections.forEach { $0.reload() }
|
||||
self.updateReport()
|
||||
}
|
||||
|
||||
// MARK: - MediaBrowserViewControllerDataSource & MediaBrowserViewControllerDelegate
|
||||
|
||||
@ -171,7 +171,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
|
||||
self.show(error: error)
|
||||
}
|
||||
|
||||
let frozenVehicle = newVehicle.realm != nil ? newVehicle.freeze() : newVehicle
|
||||
let frozenVehicle = newVehicle.realm != nil ? newVehicle.clone() : newVehicle
|
||||
self.datasource.set(item: frozenVehicle, at: indexPath)
|
||||
self.updateDetailController(with: frozenVehicle)
|
||||
} onError: { err in
|
||||
|
||||
Loading…
Reference in New Issue
Block a user