From 8daf101406de4330735fa2915b729346f8087ab3 Mon Sep 17 00:00:00 2001 From: Brian Wieder Date: Tue, 30 Apr 2024 22:44:22 -0700 Subject: [PATCH 1/8] Rework glucose dialog This ports https://github.com/Artificial-Pancreas/iAPS/pull/272 into Open-iAPS. This is part of #47 Co-Authored-By: Deniz Cengiz <48965855+dnzxy@users.noreply.github.com> --- .../DataTable/DataTableStateModel.swift | 4 +- .../DataTable/View/DataTableRootView.swift | 102 ++++++++++++------ 2 files changed, 69 insertions(+), 37 deletions(-) diff --git a/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift b/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift index b828e908c..5b81451d2 100644 --- a/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift +++ b/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift @@ -13,7 +13,7 @@ extension DataTable { @Published var mode: Mode = .treatments @Published var treatments: [Treatment] = [] @Published var glucose: [Glucose] = [] - @Published var manualGlcuose: Decimal = 0 + @Published var manualGlucose: Decimal = 0 @Published var maxBolus: Decimal = 0 @Published var externalInsulinAmount: Decimal = 0 @Published var externalInsulinDate = Date() @@ -182,7 +182,7 @@ extension DataTable { } func addManualGlucose() { - let glucose = units == .mmolL ? manualGlcuose.asMgdL : manualGlcuose + let glucose = units == .mmolL ? manualGlucose.asMgdL : manualGlucose let now = Date() let id = UUID().uuidString diff --git a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift index 8f7eafc68..5d0f2a194 100644 --- a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift +++ b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift @@ -11,7 +11,7 @@ extension DataTable { @State private var removeCarbsAlert: Alert? @State private var isRemoveInsulinAlertPresented = false @State private var removeInsulinAlert: Alert? - @State private var newGlucose = false + @State private var showManualGlucose = false @State private var showExternalInsulin = false @State private var isAmountUnconfirmed = true @@ -74,34 +74,8 @@ extension DataTable { }) { addExternalInsulinView } - .popup(isPresented: newGlucose, alignment: .top, direction: .bottom) { - VStack(spacing: 20) { - HStack { - Text("New Glucose") - DecimalTextField(" ... ", value: $state.manualGlcuose, formatter: glucoseFormatter) - Text(state.units.rawValue) - }.padding(.horizontal, 20) - HStack { - let limitLow: Decimal = state.units == .mmolL ? 2.2 : 40 - let limitHigh: Decimal = state.units == .mmolL ? 21 : 380 - Button { newGlucose = false } - label: { Text("Cancel") }.frame(maxWidth: .infinity, alignment: .leading) - - Button { - state.addManualGlucose() - newGlucose = false - } - label: { Text("Save") } - .frame(maxWidth: .infinity, alignment: .trailing) - // .disabled(state.manualGlcuose < limitLow || state.manualGlcuose > limitHigh) - - }.padding(20) - } - .frame(maxHeight: 140) - .background( - RoundedRectangle(cornerRadius: 8, style: .continuous) - .fill(Color(colorScheme == .dark ? UIColor.systemGray2 : UIColor.systemGray6)) - ) + .sheet(isPresented: $showManualGlucose) { + addGlucoseView } } @@ -137,13 +111,71 @@ extension DataTable { private var glucoseList: some View { List { - Button { newGlucose = true } - label: { Text("Add") }.frame(maxWidth: .infinity, alignment: .trailing) - .padding(.trailing, 20) + HStack { + Text("Time").foregroundStyle(.secondary) + Spacer() + Text(state.units.rawValue).foregroundStyle(.secondary) + Button( + action: { + showManualGlucose = true + state.manualGlucose = 0 + }, + label: { Image(systemName: "plus.circle.fill").foregroundStyle(.secondary) + } + ).buttonStyle(.borderless) + } + if !state.glucose.isEmpty { + ForEach(state.glucose) { item in + glucoseView(item) + } + .onDelete(perform: deleteGlucose) + } else { + HStack { + Text(NSLocalizedString("No data.", comment: "No data text when no entries in history list")) + } + } + } + } + + private var addGlucoseView: some View { + NavigationView { + VStack { + Form { + Section { + HStack { + Text("New Glucose") + DecimalTextField( + " ... ", + value: $state.manualGlucose, + formatter: glucoseFormatter, + autofocus: true, + cleanInput: true + ) + Text(state.units.rawValue).foregroundStyle(.secondary) + } + } + + Section { + HStack { + let limitLow: Decimal = state.units == .mmolL ? 0.8 : 40 + let limitHigh: Decimal = state.units == .mmolL ? 14 : 720 - ForEach(state.glucose) { item in - glucoseView(item) - }.onDelete(perform: deleteGlucose) + Button { + state.addManualGlucose() + isAmountUnconfirmed = false + showManualGlucose = false + } + label: { Text("Save") } + .frame(maxWidth: .infinity, alignment: .center) + .disabled(state.manualGlucose < limitLow || state.manualGlucose > limitHigh) + } + } + } + } + .onAppear(perform: configureView) + .navigationTitle("Add Glucose") + .navigationBarTitleDisplayMode(.automatic) + .navigationBarItems(leading: Button("Close", action: { showManualGlucose = false })) } } From c8de2f2d460b7d96288bc574fa6dd94bbb26d974 Mon Sep 17 00:00:00 2001 From: Brian Wieder Date: Wed, 1 May 2024 20:29:47 -0700 Subject: [PATCH 2/8] Swipe to delete, and move add buttons Co-Authored-By: Deniz Cengiz <48965855+dnzxy@users.noreply.github.com> --- .../Modules/DataTable/DataTableDataFlow.swift | 2 - .../DataTable/DataTableStateModel.swift | 4 +- .../DataTable/View/DataTableRootView.swift | 256 ++++++++++-------- 3 files changed, 140 insertions(+), 122 deletions(-) diff --git a/FreeAPS/Sources/Modules/DataTable/DataTableDataFlow.swift b/FreeAPS/Sources/Modules/DataTable/DataTableDataFlow.swift index 4fe22ba99..6011a6c07 100644 --- a/FreeAPS/Sources/Modules/DataTable/DataTableDataFlow.swift +++ b/FreeAPS/Sources/Modules/DataTable/DataTableDataFlow.swift @@ -141,8 +141,6 @@ enum DataTable { if isExternal ?? false { bolusText += " " + NSLocalizedString("External", comment: "External Insulin") - } else if isSMB ?? false { - bolusText += " " + NSLocalizedString("SMB", comment: "SMB") } return numberFormatter diff --git a/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift b/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift index 5b81451d2..4549268ea 100644 --- a/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift +++ b/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift @@ -156,8 +156,8 @@ extension DataTable { .store(in: &lifetime) } - func deleteGlucose(at index: Int) { - let id = glucose[index].id + func deleteGlucose(_ glucose: Glucose) { + let id = glucose.id provider.deleteGlucose(id: id) let fetchRequest: NSFetchRequest diff --git a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift index 5d0f2a194..468980f7f 100644 --- a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift +++ b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift @@ -7,10 +7,11 @@ extension DataTable { let resolver: Resolver @StateObject var state = StateModel() - @State private var isRemoveCarbsAlertPresented = false - @State private var removeCarbsAlert: Alert? - @State private var isRemoveInsulinAlertPresented = false - @State private var removeInsulinAlert: Alert? + @State private var isRemoveHistoryItemAlertPresented: Bool = false + @State private var alertTitle: String = "" + @State private var alertMessage: String = "" + @State private var alertTreatmentToDelete: Treatment? + @State private var alertGlucoseToDelete: Glucose? @State private var showManualGlucose = false @State private var showExternalInsulin = false @State private var isAmountUnconfirmed = true @@ -64,7 +65,7 @@ extension DataTable { .navigationBarTitleDisplayMode(.automatic) .navigationBarItems( leading: Button("Close", action: state.hideModal), - trailing: state.mode == .glucose ? EditButton().asAny() : EmptyView().asAny() + trailing: state.mode == .glucose ? addGlucoseButton.asAny() : addInsulinButton.asAny() ) .sheet(isPresented: $showExternalInsulin, onDismiss: { if isAmountUnconfirmed { @@ -79,24 +80,35 @@ extension DataTable { } } - private var treatmentsList: some View { - List { - HStack { - Spacer() - Button(action: { showExternalInsulin = true - state.externalInsulinDate = Date() }, label: { - HStack { - Text("Add") - .foregroundColor(Color.secondary) - .font(.caption) - - Image(systemName: "syringe") - .foregroundColor(Color.accentColor) - }.frame(maxWidth: .infinity, alignment: .trailing) + private var addInsulinButton: some View { + Button(action: { showExternalInsulin = true + state.externalInsulinDate = Date() }, label: { + Text("Add") + .foregroundColor(Color.secondary) + .font(.caption) + Image(systemName: "syringe") + .foregroundColor(Color.accentColor) + }).buttonStyle(.borderless) + } - }).buttonStyle(.borderless) + private var addGlucoseButton: some View { + Button( + action: { + showManualGlucose = true + state.manualGlucose = 0 + }, + label: { + Text("Add") + .foregroundColor(Color.secondary) + .font(.caption) + Image(systemName: "drop") + .foregroundColor(Color.accentColor) } + ).buttonStyle(.borderless) + } + private var treatmentsList: some View { + List { if !state.treatments.isEmpty { ForEach(state.treatments) { item in treatmentView(item) @@ -111,24 +123,10 @@ extension DataTable { private var glucoseList: some View { List { - HStack { - Text("Time").foregroundStyle(.secondary) - Spacer() - Text(state.units.rawValue).foregroundStyle(.secondary) - Button( - action: { - showManualGlucose = true - state.manualGlucose = 0 - }, - label: { Image(systemName: "plus.circle.fill").foregroundStyle(.secondary) - } - ).buttonStyle(.borderless) - } if !state.glucose.isEmpty { ForEach(state.glucose) { item in glucoseView(item) } - .onDelete(perform: deleteGlucose) } else { HStack { Text(NSLocalizedString("No data.", comment: "No data text when no entries in history list")) @@ -181,84 +179,75 @@ extension DataTable { @ViewBuilder private func treatmentView(_ item: Treatment) -> some View { HStack { - Image(systemName: "circle.fill").foregroundColor(item.color) - Text(dateFormatter.string(from: item.date)) - .moveDisabled(true) - Text(item.type.name) + if item.type == .bolus || item.type == .carbs { + Image(systemName: "circle.fill").foregroundColor(item.color).padding(.vertical) + } else { + Image(systemName: "circle.fill").foregroundColor(item.color) + } + Text((item.isSMB ?? false) ? "SMB" : item.type.name) Text(item.amountText).foregroundColor(.secondary) if let duration = item.durationText { Text(duration).foregroundColor(.secondary) } + Spacer() + Text(dateFormatter.string(from: item.date)) + .moveDisabled(true) + } + .swipeActions { + // Only allow swipe to delete if a carb, fpu, or bolus entry. + if item.type == .carbs || item.type == .fpus || item.type == .bolus { + Button( + "Delete", + systemImage: "trash.fill", + role: .none, + action: { + alertTreatmentToDelete = item - if item.type == .carbs { - if item.note != "" { - Spacer() - Text(item.note ?? "").foregroundColor(.brown) - } - Spacer() - Image(systemName: "xmark.circle").foregroundColor(.secondary) - .contentShape(Rectangle()) - .padding(.vertical) - .onTapGesture { - removeCarbsAlert = Alert( - title: Text("Delete carbs?"), - message: Text(item.amountText), - primaryButton: .destructive( - Text("Delete"), - action: { state.deleteCarbs(item) } - ), - secondaryButton: .cancel() - ) - isRemoveCarbsAlertPresented = true - } - .alert(isPresented: $isRemoveCarbsAlertPresented) { - removeCarbsAlert! - } - } + if item.type == .carbs { + alertTitle = "Delete Carbs?" + alertMessage = dateFormatter.string(from: item.date) + ", " + item.amountText + } else if item.type == .fpus { + alertTitle = "Delete Carb Equivalents?" + alertMessage = "All FPUs of the meal will be deleted." + } else { + // item is insulin treatment; item.type == .bolus + alertTitle = "Delete Insulin?" + alertMessage = dateFormatter.string(from: item.date) + ", " + item.amountText - if item.type == .fpus { - Spacer() - Image(systemName: "xmark.circle").foregroundColor(.secondary) - .contentShape(Rectangle()) - .padding(.vertical) - .onTapGesture { - removeCarbsAlert = Alert( - title: Text("Delete carb equivalents?"), - message: Text(""), // Temporary fix. New to fix real amount of carb equivalents later - primaryButton: .destructive( - Text("Delete"), - action: { state.deleteCarbs(item) } - ), - secondaryButton: .cancel() - ) - isRemoveCarbsAlertPresented = true - } - .alert(isPresented: $isRemoveCarbsAlertPresented) { - removeCarbsAlert! + if item.isSMB ?? false { + // Add text snippet, so that alert message is more descriptive for SMBs + alertMessage += " SMB" + } + } + + isRemoveHistoryItemAlertPresented = true } + ).tint(.red) } + } + .disabled( + item.type == .tempBasal || item.type == .tempTarget || item.type == .resume || item + .type == .suspend + ) + .alert( + Text(NSLocalizedString(alertTitle, comment: "")), + isPresented: $isRemoveHistoryItemAlertPresented + ) { + Button("Cancel", role: .cancel) {} + Button("Delete", role: .destructive) { + guard let treatmentToDelete = alertTreatmentToDelete else { + debug(.default, "Cannot gracefully unwrap alertTreatmentToDelete!") + return + } - if item.type == .bolus { - Spacer() - Image(systemName: "xmark.circle").foregroundColor(.secondary) - .contentShape(Rectangle()) - .padding(.vertical) - .onTapGesture { - removeInsulinAlert = Alert( - title: Text("Delete insulin?"), - message: Text(item.amountText), - primaryButton: .destructive( - Text("Delete"), - action: { state.deleteInsulin(item) } - ), - secondaryButton: .cancel() - ) - isRemoveInsulinAlertPresented = true - } - .alert(isPresented: $isRemoveInsulinAlertPresented) { - removeInsulinAlert! - } + if treatmentToDelete.type == .carbs || treatmentToDelete.type == .fpus { + state.deleteCarbs(treatmentToDelete) + } else { + state.deleteInsulin(treatmentToDelete) + } } + } message: { + Text("\n" + NSLocalizedString(alertMessage, comment: "")) } } @@ -327,24 +316,55 @@ extension DataTable { } @ViewBuilder private func glucoseView(_ item: Glucose) -> some View { - VStack(alignment: .leading, spacing: 4) { - HStack { - Text(dateFormatter.string(from: item.glucose.dateString)) - Spacer() - Text(item.glucose.glucose.map { - glucoseFormatter.string(from: Double( - state.units == .mmolL ? $0.asMmolL : Decimal($0) - ) as NSNumber)! - } ?? "--") - Text(state.units.rawValue) - Text(item.glucose.direction?.symbol ?? "--") - } - Text("ID: " + item.glucose.id).font(.caption2).foregroundColor(.secondary) + HStack { + Text(item.glucose.glucose.map { + glucoseFormatter.string(from: Double( + state.units == .mmolL ? $0.asMmolL : Decimal($0) + ) as NSNumber)! + } ?? "--") + Text(item.glucose.direction?.symbol ?? "--") + Spacer() + + Text(dateFormatter.string(from: item.glucose.dateString)) } - } + .swipeActions { + Button( + "Delete", + systemImage: "trash.fill", + role: .none, + action: { + alertGlucoseToDelete = item - private func deleteGlucose(at offsets: IndexSet) { - state.deleteGlucose(at: offsets[offsets.startIndex]) + let valueText = glucoseFormatter.string(from: Double( + state.units == .mmolL ? Double(item.glucose.value.asMmolL) : item.glucose.value + ) as NSNumber)! + " " + state.units.rawValue + + alertTitle = "Delete Glucose?" + alertMessage = dateFormatter.string(from: item.glucose.dateString) + ", " + valueText + + isRemoveHistoryItemAlertPresented = true + } + ).tint(.red) + } + .alert( + Text(NSLocalizedString(alertTitle, comment: "")), + isPresented: $isRemoveHistoryItemAlertPresented + ) { + Button("Cancel", role: .cancel) {} + Button("Delete", role: .destructive) { + // gracefully unwrap value here. + // value cannot ever really be nil because it is an existing(!) table entry + // but just to be sure. + guard let glucoseToDelete = alertGlucoseToDelete else { + print("Cannot gracefully unwrap alertTreatmentToDelete!") + return + } + + state.deleteGlucose(glucoseToDelete) + } + } message: { + Text("\n" + NSLocalizedString(alertMessage, comment: "")) + } } } } From d3dcbc66a314b373cf526831c0b89abec097a878 Mon Sep 17 00:00:00 2001 From: Brian Wieder Date: Thu, 2 May 2024 20:20:56 -0700 Subject: [PATCH 3/8] Make add insulin/glucose buttons conform to guidelines --- .../Modules/DataTable/View/DataTableRootView.swift | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift index 468980f7f..edbac5d42 100644 --- a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift +++ b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift @@ -83,10 +83,9 @@ extension DataTable { private var addInsulinButton: some View { Button(action: { showExternalInsulin = true state.externalInsulinDate = Date() }, label: { - Text("Add") - .foregroundColor(Color.secondary) - .font(.caption) - Image(systemName: "syringe") + Text("Add Insulin") + .foregroundColor(Color.accentColor) + Image(systemName: "plus") .foregroundColor(Color.accentColor) }).buttonStyle(.borderless) } @@ -98,10 +97,9 @@ extension DataTable { state.manualGlucose = 0 }, label: { - Text("Add") - .foregroundColor(Color.secondary) - .font(.caption) - Image(systemName: "drop") + Text("Add Glucose") + .foregroundColor(Color.accentColor) + Image(systemName: "plus") .foregroundColor(Color.accentColor) } ).buttonStyle(.borderless) From d25e50ae1aca03fefe20077f1595f37d8b5cddbb Mon Sep 17 00:00:00 2001 From: Brian Wieder Date: Thu, 2 May 2024 20:48:53 -0700 Subject: [PATCH 4/8] Upload SMB treatment type to nightscout --- FreeAPS/Sources/Models/NightscoutTreatment.swift | 2 ++ FreeAPS/Sources/Models/PumpHistoryEvent.swift | 1 + 2 files changed, 3 insertions(+) diff --git a/FreeAPS/Sources/Models/NightscoutTreatment.swift b/FreeAPS/Sources/Models/NightscoutTreatment.swift index 82e1736eb..dee8bfb31 100644 --- a/FreeAPS/Sources/Models/NightscoutTreatment.swift +++ b/FreeAPS/Sources/Models/NightscoutTreatment.swift @@ -3,6 +3,8 @@ import Foundation func determineBolusEventType(for event: PumpHistoryEvent) -> EventType { if event.isExternalInsulin ?? false { return .nsExternalInsulin + } else if event.isSMB ?? false { + return .SMB } return event.type } diff --git a/FreeAPS/Sources/Models/PumpHistoryEvent.swift b/FreeAPS/Sources/Models/PumpHistoryEvent.swift index 283358998..0c606875d 100644 --- a/FreeAPS/Sources/Models/PumpHistoryEvent.swift +++ b/FreeAPS/Sources/Models/PumpHistoryEvent.swift @@ -46,6 +46,7 @@ struct PumpHistoryEvent: JSON, Equatable { enum EventType: String, JSON { case bolus = "Bolus" + case SMB = "SMB" case mealBolus = "Meal Bolus" case correctionBolus = "Correction Bolus" case snackBolus = "Snack Bolus" From 8a07d4d3be823f01b263aa006bc3c70280df94b2 Mon Sep 17 00:00:00 2001 From: Brian Wieder Date: Sun, 5 May 2024 19:58:00 -0700 Subject: [PATCH 5/8] Remove redundent SMB string --- FreeAPS/Sources/Models/PumpHistoryEvent.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FreeAPS/Sources/Models/PumpHistoryEvent.swift b/FreeAPS/Sources/Models/PumpHistoryEvent.swift index 0c606875d..5aaed4dcc 100644 --- a/FreeAPS/Sources/Models/PumpHistoryEvent.swift +++ b/FreeAPS/Sources/Models/PumpHistoryEvent.swift @@ -46,7 +46,7 @@ struct PumpHistoryEvent: JSON, Equatable { enum EventType: String, JSON { case bolus = "Bolus" - case SMB = "SMB" + case SMB case mealBolus = "Meal Bolus" case correctionBolus = "Correction Bolus" case snackBolus = "Snack Bolus" From c813bfa16d158d71ba68b9f9b9543097c42eeff5 Mon Sep 17 00:00:00 2001 From: Brian Wieder Date: Thu, 9 May 2024 18:36:00 -0700 Subject: [PATCH 6/8] Reword add insulin/glucose to log insulin/glucose. --- .../Modules/DataTable/View/DataTableRootView.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift index edbac5d42..b51261574 100644 --- a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift +++ b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift @@ -65,7 +65,7 @@ extension DataTable { .navigationBarTitleDisplayMode(.automatic) .navigationBarItems( leading: Button("Close", action: state.hideModal), - trailing: state.mode == .glucose ? addGlucoseButton.asAny() : addInsulinButton.asAny() + trailing: state.mode == .glucose ? logGlucoseButton.asAny() : logInsulinButton.asAny() ) .sheet(isPresented: $showExternalInsulin, onDismiss: { if isAmountUnconfirmed { @@ -80,24 +80,24 @@ extension DataTable { } } - private var addInsulinButton: some View { + private var logInsulinButton: some View { Button(action: { showExternalInsulin = true state.externalInsulinDate = Date() }, label: { - Text("Add Insulin") + Text("Log Insulin") .foregroundColor(Color.accentColor) Image(systemName: "plus") .foregroundColor(Color.accentColor) }).buttonStyle(.borderless) } - private var addGlucoseButton: some View { + private var logGlucoseButton: some View { Button( action: { showManualGlucose = true state.manualGlucose = 0 }, label: { - Text("Add Glucose") + Text("Log Glucose") .foregroundColor(Color.accentColor) Image(systemName: "plus") .foregroundColor(Color.accentColor) From 215b105f64851483ee2436a7dc2b83eed7de06fb Mon Sep 17 00:00:00 2001 From: Brian Wieder Date: Sat, 11 May 2024 15:29:10 -0700 Subject: [PATCH 7/8] add -> log --- .../Modules/DataTable/DataTableStateModel.swift | 4 ++-- .../Modules/DataTable/View/DataTableRootView.swift | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift b/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift index 4549268ea..d71fb3355 100644 --- a/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift +++ b/FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift @@ -181,7 +181,7 @@ extension DataTable { // try? coredataContext.save() } - func addManualGlucose() { + func logManualGlucose() { let glucose = units == .mmolL ? manualGlucose.asMgdL : manualGlucose let now = Date() let id = UUID().uuidString @@ -201,7 +201,7 @@ extension DataTable { debug(.default, "Manual Glucose saved to glucose.json") } - func addExternalInsulin() { + func logExternalInsulin() { guard externalInsulinAmount > 0 else { showModal(for: nil) return diff --git a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift index b51261574..a7731ef64 100644 --- a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift +++ b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift @@ -73,10 +73,10 @@ extension DataTable { state.externalInsulinDate = Date() } }) { - addExternalInsulinView + logExternalInsulinView } .sheet(isPresented: $showManualGlucose) { - addGlucoseView + logGlucoseView } } @@ -133,7 +133,7 @@ extension DataTable { } } - private var addGlucoseView: some View { + private var logGlucoseView: some View { NavigationView { VStack { Form { @@ -157,7 +157,7 @@ extension DataTable { let limitHigh: Decimal = state.units == .mmolL ? 14 : 720 Button { - state.addManualGlucose() + state.logManualGlucose() isAmountUnconfirmed = false showManualGlucose = false } @@ -169,7 +169,7 @@ extension DataTable { } } .onAppear(perform: configureView) - .navigationTitle("Add Glucose") + .navigationTitle("Log Glucose") .navigationBarTitleDisplayMode(.automatic) .navigationBarItems(leading: Button("Close", action: { showManualGlucose = false })) } @@ -249,7 +249,7 @@ extension DataTable { } } - var addExternalInsulinView: some View { + var logExternalInsulinView: some View { NavigationView { VStack { Form { @@ -278,7 +278,7 @@ extension DataTable { Section { HStack { Button { - state.addExternalInsulin() + state.logExternalInsulin() isAmountUnconfirmed = false showExternalInsulin = false } From 67ddedb393eb358e8c234ff1e9d5137b2b1f1303 Mon Sep 17 00:00:00 2001 From: Brian Wieder Date: Sun, 12 May 2024 10:00:54 -0700 Subject: [PATCH 8/8] Remove `.disabled` attribute that was not doing anything on treatment list. Rename `SMB` enum case EventType to `smb` to match other cases. Update navigation title of external insulin sheet to match manual glucose sheet. --- FreeAPS/Sources/Models/NightscoutTreatment.swift | 2 +- FreeAPS/Sources/Models/PumpHistoryEvent.swift | 2 +- .../Modules/DataTable/View/DataTableRootView.swift | 10 +++------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/FreeAPS/Sources/Models/NightscoutTreatment.swift b/FreeAPS/Sources/Models/NightscoutTreatment.swift index dee8bfb31..4f1f3821d 100644 --- a/FreeAPS/Sources/Models/NightscoutTreatment.swift +++ b/FreeAPS/Sources/Models/NightscoutTreatment.swift @@ -4,7 +4,7 @@ func determineBolusEventType(for event: PumpHistoryEvent) -> EventType { if event.isExternalInsulin ?? false { return .nsExternalInsulin } else if event.isSMB ?? false { - return .SMB + return .smb } return event.type } diff --git a/FreeAPS/Sources/Models/PumpHistoryEvent.swift b/FreeAPS/Sources/Models/PumpHistoryEvent.swift index 5aaed4dcc..e38f2082a 100644 --- a/FreeAPS/Sources/Models/PumpHistoryEvent.swift +++ b/FreeAPS/Sources/Models/PumpHistoryEvent.swift @@ -46,7 +46,7 @@ struct PumpHistoryEvent: JSON, Equatable { enum EventType: String, JSON { case bolus = "Bolus" - case SMB + case smb = "SMB" case mealBolus = "Meal Bolus" case correctionBolus = "Correction Bolus" case snackBolus = "Snack Bolus" diff --git a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift index a7731ef64..9739356c6 100644 --- a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift +++ b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift @@ -223,10 +223,6 @@ extension DataTable { ).tint(.red) } } - .disabled( - item.type == .tempBasal || item.type == .tempTarget || item.type == .resume || item - .type == .suspend - ) .alert( Text(NSLocalizedString(alertTitle, comment: "")), isPresented: $isRemoveHistoryItemAlertPresented @@ -283,7 +279,7 @@ extension DataTable { showExternalInsulin = false } label: { - Text("Log external insulin") + Text("Save") } .foregroundColor(amountWarningCondition ? Color.white : Color.accentColor) .frame(maxWidth: .infinity, alignment: .center) @@ -306,8 +302,8 @@ extension DataTable { } } .onAppear(perform: configureView) - .navigationTitle("External Insulin") - .navigationBarTitleDisplayMode(.inline) + .navigationTitle("Log External Insulin") + .navigationBarTitleDisplayMode(.automatic) .navigationBarItems(leading: Button("Close", action: { showExternalInsulin = false state.externalInsulinAmount = 0 })) }