From 438c0a9cbb1bcb594028cc4c7fcedfe4a802ef6f Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sun, 27 Feb 2022 00:05:29 -0600 Subject: Initial implementation of reports --- iosApp/iosApp/Details/DetailsView.swift | 2 +- .../iosApp/Details/Reports/UnitReportsView.swift | 55 ++++++++++++++++++++-- .../Details/Reports/UnitReportsViewModel.swift | 14 ++++-- iosApp/iosApp/Devices/DeviceRow.swift | 10 ++-- iosApp/iosApp/Map/MapView.swift | 5 +- iosApp/iosApp/Map/MapViewController.swift | 17 ++++--- iosApp/iosApp/Units/UnitsView.swift | 2 +- iosApp/iosApp/en.lproj/Localizable.strings | 15 ++++++ iosApp/iosApp/es-419.lproj/Localizable.strings | 15 ++++++ 9 files changed, 114 insertions(+), 21 deletions(-) (limited to 'iosApp') diff --git a/iosApp/iosApp/Details/DetailsView.swift b/iosApp/iosApp/Details/DetailsView.swift index c869369..9b75aec 100644 --- a/iosApp/iosApp/Details/DetailsView.swift +++ b/iosApp/iosApp/Details/DetailsView.swift @@ -50,7 +50,7 @@ struct DetailsView: View { .navigationBarTitleView( Picker(selection: $action) { Text("details").tag(DeviceRow.Action.details) - //Text("reports").tag(DeviceRow.Action.reports) + Text("reports").tag(DeviceRow.Action.reports) Text("commands").tag(DeviceRow.Action.commands) } label: { EmptyView() diff --git a/iosApp/iosApp/Details/Reports/UnitReportsView.swift b/iosApp/iosApp/Details/Reports/UnitReportsView.swift index 322e853..b73c9e7 100644 --- a/iosApp/iosApp/Details/Reports/UnitReportsView.swift +++ b/iosApp/iosApp/Details/Reports/UnitReportsView.swift @@ -34,11 +34,60 @@ struct UnitReportsView: View { VStack { MapView(layer: $unitReportsViewModel.layer, markers: $unitReportsViewModel.markers, - selected: $unitReportsViewModel.selectedMarker) + selected: $unitReportsViewModel.selectedMarker, + isReport: true) VStack { HStack { - Text("period") - } + Text("report-period") + Spacer() + Picker(selection: $unitReportsViewModel.reportPeriod) { + Text("period-today").tag(ReportDates.ReportPeriod.today) + Text("period-last-24").tag(ReportDates.ReportPeriod.last24) + Text("period-yesterday").tag(ReportDates.ReportPeriod.yesterday) + Text("period-this-week").tag(ReportDates.ReportPeriod.thisWeek) + Text("period-last-7").tag(ReportDates.ReportPeriod.last7) + Text("period-this-month").tag(ReportDates.ReportPeriod.thisMonth) + Text("period-last-30").tag(ReportDates.ReportPeriod.last30) + } label: { + switch unitReportsViewModel.reportPeriod { + case .today: + Text("period-today") + case .last24: + Text("period-last-24") + case .yesterday: + Text("period-yesterday") + case .thisWeek: + Text("period-this-week") + case .last7: + Text("period-last-7") + case .thisMonth: + Text("period-this-month") + case .last30: + Text("period-last-30") + default: + Text("period-today") + } + } + }.padding() + Picker(selection: $unitReportsViewModel.reportType) { + Text("report-positions").tag(ReportController.ReportType.positions) + Text("report-events").tag(ReportController.ReportType.events) + Text("report-stops").tag(ReportController.ReportType.stops) + } label: { + EmptyView() + }.pickerStyle(SegmentedPickerStyle()) + + HStack { + Group { + Button {} label: { + Text("report-save") + } + + Button {} label: { + Text("report-share") + } + }.frame(maxWidth: .infinity) + }.padding() }.padding() }.onAppear { unitReportsViewModel.fetchReport() diff --git a/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift b/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift index 8f67d7a..5e85e89 100644 --- a/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift +++ b/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift @@ -14,8 +14,16 @@ class UnitReportsViewModel: ObservableObject { @Inject var reportController: ReportController @Published var deviceId: Int32? = nil - @Published var reportType: ReportController.ReportType = .positions - @Published var reportPeriod: ReportDates.ReportPeriod = .today + @Published var reportType: ReportController.ReportType = .positions { + didSet { + fetchReport() + } + } + @Published var reportPeriod: ReportDates.ReportPeriod = .today { + didSet { + fetchReport() + } + } @Published var report: ReportController.Report? = nil { didSet { switch report { @@ -65,7 +73,7 @@ class UnitReportsViewModel: ObservableObject { .textMessage, .driverChanged, .unknown - ]) + ]) { _, _ in } } } } diff --git a/iosApp/iosApp/Devices/DeviceRow.swift b/iosApp/iosApp/Devices/DeviceRow.swift index 0439fff..ee3298d 100644 --- a/iosApp/iosApp/Devices/DeviceRow.swift +++ b/iosApp/iosApp/Devices/DeviceRow.swift @@ -172,9 +172,9 @@ struct DeviceRow: View { Label("details", systemImage: "info.circle") } - //let reports = Button { callback(.reports) } label: { - // Label("reports", systemImage: "clock") - //} + let reports = Button { callback(.reports) } label: { + Label("reports", systemImage: "clock") + } let commands = Button { callback(.commands) } label: { Label("commands", systemImage: "paperplane") @@ -182,12 +182,12 @@ struct DeviceRow: View { if isCell { commands - // reports + reports details } else { Group { details - // reports + reports commands } .frame(maxWidth: .infinity) diff --git a/iosApp/iosApp/Map/MapView.swift b/iosApp/iosApp/Map/MapView.swift index e52c034..05bd9f9 100644 --- a/iosApp/iosApp/Map/MapView.swift +++ b/iosApp/iosApp/Map/MapView.swift @@ -26,6 +26,7 @@ struct MapView: UIViewControllerRepresentable { @Binding var layer: MapLayer @Binding var markers: [Marker] @Binding var selected: Marker? + var isReport: Bool = false var markerCallback: MarkerCallback? class Coordinator { @@ -52,9 +53,9 @@ struct MapView: UIViewControllerRepresentable { if context.coordinator.oldMarkers != markers { print("center = \(context.coordinator.shouldCenter)") uiViewController.display(markers: markers, - isReport: false, + isReport: isReport, center: context.coordinator.shouldCenter) - context.coordinator.shouldCenter = false + context.coordinator.shouldCenter = false || isReport } context.coordinator.oldMarkers = markers diff --git a/iosApp/iosApp/Map/MapViewController.swift b/iosApp/iosApp/Map/MapViewController.swift index 131a511..2b4c7d4 100644 --- a/iosApp/iosApp/Map/MapViewController.swift +++ b/iosApp/iosApp/Map/MapViewController.swift @@ -211,7 +211,8 @@ class OurMaplyViewController: MaplyViewController { let vectorDesc: [AnyHashable : Any] = [ kMaplyColor: colorReport, - kMaplyVecWidth: 20.0 + kMaplyVecWidth: 10.0, + kMaplyWideVecImpl: kMaplyWideVecImplPerf ] let labelDesc: [AnyHashable : Any] = [ @@ -289,15 +290,19 @@ class OurMaplyViewController: MaplyViewController { "type": "FeatureCollection", "features": [ [ - "type": "LineString", - "coordinates": points.map({ point in - [point.x, point.y] - }) + "type": "Feature", + "properties": [], + "geometry": [ + "type": "LineString", + "coordinates": markers.map({ marker in + [marker.longitude, marker.latitude] + }) + ] ] ] ] if let vector = MaplyVectorObject(fromGeoJSONDictionary: geoJSON) { - if let objs = addVectors([vector], desc: vectorDesc, mode: .any) { + if let objs = addWideVectors([vector], desc: vectorDesc, mode: .any) { objects.append(objs) } } diff --git a/iosApp/iosApp/Units/UnitsView.swift b/iosApp/iosApp/Units/UnitsView.swift index a91511e..c14ae43 100644 --- a/iosApp/iosApp/Units/UnitsView.swift +++ b/iosApp/iosApp/Units/UnitsView.swift @@ -76,7 +76,7 @@ struct UnitsView: View { } } .navigationViewStyle(StackNavigationViewStyle()) - .sheet(isPresented: $unitsViewModel.showDetails) { + .fullScreenCover(isPresented: $unitsViewModel.showDetails) { print("Dismissed") } content: { DetailsView(isPresented: $unitsViewModel.showDetails, diff --git a/iosApp/iosApp/en.lproj/Localizable.strings b/iosApp/iosApp/en.lproj/Localizable.strings index 392bc1c..56a934b 100644 --- a/iosApp/iosApp/en.lproj/Localizable.strings +++ b/iosApp/iosApp/en.lproj/Localizable.strings @@ -53,6 +53,21 @@ "open-location-browser" = "Open location in browser"; "maps-url-template" = "https://www.google.com/maps/place/{y},{x}?z=19"; +"report-period" = "Period"; +"report-positions" = "Positions"; +"report-events" = "Events"; +"report-stops" = "Stops"; +"report-save" = "Save"; +"report-share" = "Share"; + +"period-today" = "Today"; +"period-last-24" = "Last 24H"; +"period-yesterday" = "Yesterday"; +"period-this-week" = "Week"; +"period-last-7" = "Last 7d"; +"period-this-month" = "Month"; +"period-last-30" = "Last 30d"; + "send-command" = "Send command"; "send-command-confirm" = "Are you sure you want to send the command?"; diff --git a/iosApp/iosApp/es-419.lproj/Localizable.strings b/iosApp/iosApp/es-419.lproj/Localizable.strings index 401582e..eae03df 100644 --- a/iosApp/iosApp/es-419.lproj/Localizable.strings +++ b/iosApp/iosApp/es-419.lproj/Localizable.strings @@ -53,6 +53,21 @@ "open-location-browser" = "Abrir ubicación en navegador"; "maps-url-template" = "https://www.google.com/maps/place/{y},{x}?z=19"; +"report-period" = "Periodo"; +"report-positions" = "Posiciones"; +"report-events" = "Eventos"; +"report-stops" = "Paradas"; +"report-save" = "Guardar"; +"report-share" = "Compartir"; + +"period-today" = "Hoy"; +"period-last-24" = "Últimas 24H"; +"period-yesterday" = "Ayer"; +"period-this-week" = "Semana"; +"period-last-7" = "Últimos 7d"; +"period-this-month" = "Mes"; +"period-last-30" = "Últimos 30d"; + "send-command" = "Enviar comando"; "send-command-confirm" = "¿Está seguro que desea enviar el comando?"; -- cgit v1.2.3