Przeglądaj źródła

Explicitely parse settings to mmol/L for mmol/L users when uploading profiles to NS

Deniz Cengiz 1 rok temu
rodzic
commit
d4682df2e3

+ 76 - 0
FreeAPS/Sources/Modules/NightscoutConfig/View/ProfileImport/NightscoutImportResultView.swift

@@ -0,0 +1,76 @@
+import SwiftUI
+
+struct NightscoutImportResultView: View {
+    @ObservedObject var state: NightscoutConfig.StateModel
+
+    @State private var shouldDisplayHint: Bool = false
+    @State var hintDetent = PresentationDetent.large
+    @State var selectedVerboseHint: String?
+    @State var hintLabel: String?
+    @State private var decimalPlaceholder: Decimal = 0.0
+    @State private var booleanPlaceholder: Bool = false
+
+    @Environment(\.colorScheme) var colorScheme
+    var color: LinearGradient {
+        colorScheme == .dark ? LinearGradient(
+            gradient: Gradient(colors: [
+                Color.bgDarkBlue,
+                Color.bgDarkerDarkBlue
+            ]),
+            startPoint: .top,
+            endPoint: .bottom
+        )
+            :
+            LinearGradient(
+                gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
+                startPoint: .top,
+                endPoint: .bottom
+            )
+    }
+
+    var body: some View {
+        NavigationStack {
+            VStack(alignment: .leading, spacing: 10) {
+                Text(
+                    "Trio has successfully imported your default Nightscout profile and applied it as therapy settings. This has replaced your previous therapy settings."
+                )
+
+                Text("Please review the following settings")
+                
+                Navigation
+
+//                Text("• Basal Rates")
+//                Text("• Insulin Sensitivities")
+//                Text("• Carb Ratios")
+//                Text("• Glucose Targets")
+//                Text("• Duration of Insulin Action (DIA)")
+
+                Spacer()
+
+                Button {
+                    Task {
+                        await state.importSettings()
+                    }
+                } label: {
+                    Text("Start Import")
+                        .font(.title3)
+                        .frame(maxWidth: .infinity, alignment: .center)
+                }
+                .buttonStyle(.borderedProminent)
+                .disabled(state.url.isEmpty || state.connecting || state.backfilling)
+
+                Spacer()
+            }.padding()
+                .toolbar(content: {
+                    ToolbarItem(placement: .topBarLeading) {
+                        Button(action: { state.isProfileImportPresented = false }, label: {
+                            Text("Cancel")
+                        })
+                    }
+                })
+                .navigationTitle("Nightscout Import")
+                .navigationBarTitleDisplayMode(.automatic)
+                .scrollContentBackground(.hidden).background(color)
+        }
+    }
+}

+ 5 - 3
FreeAPS/Sources/Services/Network/NightscoutManager.swift

@@ -488,24 +488,26 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
                     return
                 }
 
+                let shouldParseToMmolL = settingsManager.settings.units == .mmolL
+
                 let sens = sensitivities.sensitivities.map { item in
                     NightscoutTimevalue(
                         time: String(item.start.prefix(5)),
-                        value: item.sensitivity,
+                        value: !shouldParseToMmolL ? item.sensitivity : item.sensitivity.asMmolL,
                         timeAsSeconds: item.offset * 60
                     )
                 }
                 let targetLow = targets.targets.map { item in
                     NightscoutTimevalue(
                         time: String(item.start.prefix(5)),
-                        value: item.low,
+                        value: !shouldParseToMmolL ? item.low : item.low.asMmolL,
                         timeAsSeconds: item.offset * 60
                     )
                 }
                 let targetHigh = targets.targets.map { item in
                     NightscoutTimevalue(
                         time: String(item.start.prefix(5)),
-                        value: item.high,
+                        value: !shouldParseToMmolL ? item.high : item.high.asMmolL,
                         timeAsSeconds: item.offset * 60
                     )
                 }