|
|
@@ -7,72 +7,36 @@ extension NightscoutConfig {
|
|
|
let resolver: Resolver
|
|
|
let displayClose: Bool
|
|
|
@StateObject var state = StateModel()
|
|
|
- @State var importAlert: Alert?
|
|
|
- @State var isImportAlertPresented = false
|
|
|
- @State var importedHasRun = false
|
|
|
+ @State private var importAlert: Alert?
|
|
|
+ @State private var isImportAlertPresented = false
|
|
|
+ @State private var importedHasRun = false
|
|
|
|
|
|
@FetchRequest(
|
|
|
entity: ImportError.entity(),
|
|
|
- sortDescriptors: [NSSortDescriptor(key: "date", ascending: false)], predicate: NSPredicate(
|
|
|
- format: "date > %@", Date().addingTimeInterval(-1.minutes.timeInterval) as NSDate
|
|
|
- )
|
|
|
+ sortDescriptors: [NSSortDescriptor(key: "date", ascending: false)],
|
|
|
+ predicate: NSPredicate(format: "date > %@", Date().addingTimeInterval(-1.minutes.timeInterval) as NSDate)
|
|
|
) var fetchedErrors: FetchedResults<ImportError>
|
|
|
|
|
|
- private var portFormater: NumberFormatter {
|
|
|
- let formatter = NumberFormatter()
|
|
|
- formatter.allowsFloats = false
|
|
|
- return formatter
|
|
|
- }
|
|
|
-
|
|
|
var body: some View {
|
|
|
Form {
|
|
|
- Section {
|
|
|
- TextField("URL", text: $state.url)
|
|
|
- .disableAutocorrection(true)
|
|
|
- .textContentType(.URL)
|
|
|
- .autocapitalization(.none)
|
|
|
- .keyboardType(.URL)
|
|
|
- SecureField("API secret", text: $state.secret)
|
|
|
- .disableAutocorrection(true)
|
|
|
- .autocapitalization(.none)
|
|
|
- .textContentType(.password)
|
|
|
- .keyboardType(.asciiCapable)
|
|
|
- if !state.message.isEmpty {
|
|
|
- Text(state.message)
|
|
|
- }
|
|
|
- if state.connecting {
|
|
|
- HStack {
|
|
|
- Text("Connecting...")
|
|
|
- Spacer()
|
|
|
- ProgressView()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Section {
|
|
|
- Button("Connect") { state.connect() }
|
|
|
- .disabled(state.url.isEmpty || state.connecting)
|
|
|
- Button("Delete") { state.delete() }.foregroundColor(.red).disabled(state.connecting)
|
|
|
- }
|
|
|
+ NavigationLink("Connect", destination: NightscoutConnectView(state: state))
|
|
|
+ NavigationLink("Upload", destination: NightscoutUploadView(state: state))
|
|
|
+ NavigationLink("Fetch and Remote Control", destination: NightscoutFetchView(state: state))
|
|
|
|
|
|
- Section {
|
|
|
- Button("Open Nighstcout") {
|
|
|
- UIApplication.shared.open(URL(string: state.url)!, options: [:], completionHandler: nil)
|
|
|
- }
|
|
|
- .disabled(state.url.isEmpty || state.connecting)
|
|
|
- }
|
|
|
-
|
|
|
- Section {
|
|
|
- Toggle("Upload", isOn: $state.isUploadEnabled)
|
|
|
- if state.isUploadEnabled {
|
|
|
- Toggle("Glucose", isOn: $state.uploadGlucose).disabled(!state.changeUploadGlucose)
|
|
|
+ Section(
|
|
|
+ header: Text("Import Settings from Nightscout"),
|
|
|
+ footer: VStack(alignment: .leading, spacing: 2) {
|
|
|
+ Text(
|
|
|
+ "Importing settings from Nightscout will overwrite these settings in Trio Settings -> Configuration:"
|
|
|
+ )
|
|
|
+ Text(" • ") + Text("DIA (Pump settings)")
|
|
|
+ Text(" • ") + Text("Basal Profile")
|
|
|
+ Text(" • ") + Text("Insulin Sensitivities")
|
|
|
+ Text(" • ") + Text("Carb Ratios")
|
|
|
+ Text(" • ") + Text("Target Glucose")
|
|
|
}
|
|
|
- } header: {
|
|
|
- Text("Allow Uploads")
|
|
|
- }
|
|
|
-
|
|
|
- Section {
|
|
|
- Button("Import settings from Nightscout") {
|
|
|
+ ) {
|
|
|
+ Button("Import settings") {
|
|
|
importAlert = Alert(
|
|
|
title: Text("Import settings?"),
|
|
|
message: Text(
|
|
|
@@ -94,50 +58,38 @@ extension NightscoutConfig {
|
|
|
)
|
|
|
isImportAlertPresented.toggle()
|
|
|
}.disabled(state.url.isEmpty || state.connecting)
|
|
|
-
|
|
|
- } header: { Text("Import from Nightscout") }
|
|
|
-
|
|
|
- .alert(isPresented: $importedHasRun) {
|
|
|
- Alert(
|
|
|
- title: Text((fetchedErrors.first?.error ?? "").count < 4 ? "Settings imported" : "Import Error"),
|
|
|
- message: Text(
|
|
|
- (fetchedErrors.first?.error ?? "").count < 4 ?
|
|
|
- NSLocalizedString(
|
|
|
- "\nNow please verify all of your new settings thoroughly:\n\n* Basal Settings\n * Carb Ratios\n * Glucose Targets\n * Insulin Sensitivities\n * DIA\n\n in Trio Settings > Configuration.\n\nBad or invalid profile settings could have disatrous effects.",
|
|
|
- comment: "Imported Profiles Alert"
|
|
|
- ) :
|
|
|
- NSLocalizedString(fetchedErrors.first?.error ?? "", comment: "Import Error")
|
|
|
- ),
|
|
|
- primaryButton: .destructive(
|
|
|
- Text("OK")
|
|
|
- ),
|
|
|
- secondaryButton: .cancel()
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- Section {
|
|
|
- Toggle("Use local glucose server", isOn: $state.useLocalSource)
|
|
|
- HStack {
|
|
|
- Text("Port")
|
|
|
- DecimalTextField("", value: $state.localPort, formatter: portFormater)
|
|
|
- }
|
|
|
- } header: { Text("Local glucose source") }
|
|
|
+ .alert(isPresented: $importedHasRun) {
|
|
|
+ Alert(
|
|
|
+ title: Text((fetchedErrors.first?.error ?? "").count < 4 ? "Settings imported" : "Import Error"),
|
|
|
+ message: Text(
|
|
|
+ (fetchedErrors.first?.error ?? "").count < 4 ?
|
|
|
+ NSLocalizedString(
|
|
|
+ "\nNow please verify all of your new settings thoroughly: \n\n • DIA (Pump settings)\n • Basal Profile\n • Insulin Sensitivities\n • Carb Ratios\n • Target Glucose\n\n in Trio Settings -> Configuration.\n\nBad or invalid profile settings could have disastrous effects.",
|
|
|
+ comment: "Imported Profiles Alert"
|
|
|
+ ) :
|
|
|
+ NSLocalizedString(fetchedErrors.first?.error ?? "", comment: "Import Error")
|
|
|
+ ),
|
|
|
+ primaryButton: .destructive(
|
|
|
+ Text("OK")
|
|
|
+ ),
|
|
|
+ secondaryButton: .cancel()
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
Section {
|
|
|
Button("Backfill glucose") { state.backfillGlucose() }
|
|
|
.disabled(state.url.isEmpty || state.connecting || state.backfilling)
|
|
|
+ } header: { Text("Backfill glucose from Nightscout")
|
|
|
}
|
|
|
-
|
|
|
- Section {
|
|
|
- Toggle("Remote control", isOn: $state.allowAnnouncements)
|
|
|
- } header: { Text("Allow Remote control of Trio") }
|
|
|
}
|
|
|
- .onAppear(perform: configureView)
|
|
|
.navigationBarTitle("Nightscout Config")
|
|
|
.navigationBarTitleDisplayMode(.automatic)
|
|
|
.navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
|
|
|
.alert(isPresented: $isImportAlertPresented) {
|
|
|
importAlert!
|
|
|
}
|
|
|
+
|
|
|
+ .onAppear(perform: configureView)
|
|
|
}
|
|
|
}
|
|
|
}
|