|
|
@@ -11,21 +11,29 @@ extension Calibrations {
|
|
|
@Published var newCalibration: Decimal = 0
|
|
|
@Published var calibrations: [Calibration] = []
|
|
|
@Published var calibrate: (Double) -> Double = { $0 }
|
|
|
+ @Published var items: [Item] = []
|
|
|
|
|
|
var units: GlucoseUnits = .mmolL
|
|
|
|
|
|
override func subscribe() {
|
|
|
+ units = settingsManager.settings.units
|
|
|
+ calibrate = calibrationService.calibrate
|
|
|
+ setupCalibrations()
|
|
|
+ }
|
|
|
+
|
|
|
+ private func setupCalibrations() {
|
|
|
slope = calibrationService.slope
|
|
|
intercept = calibrationService.intercept
|
|
|
-
|
|
|
- units = settingsManager.settings.units
|
|
|
calibrations = calibrationService.calibrations
|
|
|
- calibrate = calibrationService.calibrate
|
|
|
+ items = calibrations.map {
|
|
|
+ Item(calibration: $0)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func addCalibration() {
|
|
|
defer {
|
|
|
- hideModal()
|
|
|
+ UIApplication.shared.endEditing()
|
|
|
+ setupCalibrations()
|
|
|
}
|
|
|
|
|
|
var glucose = newCalibration
|
|
|
@@ -37,7 +45,6 @@ extension Calibrations {
|
|
|
lastGlucose.dateString.addingTimeInterval(60 * 4.5) > Date(),
|
|
|
let unfiltered = lastGlucose.unfiltered
|
|
|
else {
|
|
|
- warning(.service, "Glucose is invalid for calibration")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -48,12 +55,18 @@ extension Calibrations {
|
|
|
|
|
|
func removeLast() {
|
|
|
calibrationService.removeLast()
|
|
|
- hideModal()
|
|
|
+ setupCalibrations()
|
|
|
}
|
|
|
|
|
|
func removeAll() {
|
|
|
calibrationService.removeAllCalibrations()
|
|
|
- hideModal()
|
|
|
+ setupCalibrations()
|
|
|
+ }
|
|
|
+
|
|
|
+ func removeAtIndex(_ index: Int) {
|
|
|
+ let calibration = calibrations[index]
|
|
|
+ calibrationService.removeCalibration(calibration)
|
|
|
+ setupCalibrations()
|
|
|
}
|
|
|
}
|
|
|
}
|