diff options
-rw-r--r-- | iosApp/iosApp.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | iosApp/iosApp/Details/Reports/UnitReportsView.swift | 22 | ||||
-rw-r--r-- | iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift | 71 |
3 files changed, 96 insertions, 1 deletions
diff --git a/iosApp/iosApp.xcodeproj/project.pbxproj b/iosApp/iosApp.xcodeproj/project.pbxproj index 9bd7b9a..abdf916 100644 --- a/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/iosApp/iosApp.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; }; 7555FF83242A565900829871 /* RootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* RootView.swift */; }; E312E74F27B366060018C5DE /* DevicesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E312E74E27B366060018C5DE /* DevicesViewModel.swift */; }; + E3141B8B27B9E91F00CE777C /* UnitReportsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3141B8A27B9E91F00CE777C /* UnitReportsViewModel.swift */; }; E3385A4F27B0D8A10025311C /* UnitCommandsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3385A4E27B0D8A10025311C /* UnitCommandsViewModel.swift */; }; E33A236027A4FD2C00DD647F /* UnitMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E33A235F27A4FD2C00DD647F /* UnitMapView.swift */; }; E33A236527A530F300DD647F /* SmallLabelStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E33A236427A530F300DD647F /* SmallLabelStyle.swift */; }; @@ -69,6 +70,7 @@ 7555FF82242A565900829871 /* RootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootView.swift; sourceTree = "<group>"; }; 7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; E312E74E27B366060018C5DE /* DevicesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DevicesViewModel.swift; sourceTree = "<group>"; }; + E3141B8A27B9E91F00CE777C /* UnitReportsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitReportsViewModel.swift; sourceTree = "<group>"; }; E3385A4E27B0D8A10025311C /* UnitCommandsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitCommandsViewModel.swift; sourceTree = "<group>"; }; E33A235F27A4FD2C00DD647F /* UnitMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnitMapView.swift; sourceTree = "<group>"; }; E33A236427A530F300DD647F /* SmallLabelStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallLabelStyle.swift; sourceTree = "<group>"; }; @@ -214,6 +216,7 @@ isa = PBXGroup; children = ( E396282527AFBD4E005D070E /* UnitReportsView.swift */, + E3141B8A27B9E91F00CE777C /* UnitReportsViewModel.swift */, ); path = Reports; sourceTree = "<group>"; @@ -396,6 +399,7 @@ E34A2F4827A7878200AD8AEB /* HyperlinkText.swift in Sources */, 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */, E39ABC4627A4EBD500965D05 /* DevicesView.swift in Sources */, + E3141B8B27B9E91F00CE777C /* UnitReportsViewModel.swift in Sources */, E38F242027A27B550069FC45 /* LoadingView.swift in Sources */, E38F241E27A270D50069FC45 /* UnitsView.swift in Sources */, 7555FF83242A565900829871 /* RootView.swift in Sources */, diff --git a/iosApp/iosApp/Details/Reports/UnitReportsView.swift b/iosApp/iosApp/Details/Reports/UnitReportsView.swift index 3e01e00..322e853 100644 --- a/iosApp/iosApp/Details/Reports/UnitReportsView.swift +++ b/iosApp/iosApp/Details/Reports/UnitReportsView.swift @@ -17,11 +17,31 @@ */ import SwiftUI import shared +import SwiftUIX struct UnitReportsView: View { + @StateObject var unitReportsViewModel: UnitReportsViewModel + var unit: UnitInformation + init (unit: UnitInformation) { + self.unit = unit + self._unitReportsViewModel = StateObject( + wrappedValue: UnitReportsViewModel(deviceId: unit.device.id)) + } + var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + VStack { + MapView(layer: $unitReportsViewModel.layer, + markers: $unitReportsViewModel.markers, + selected: $unitReportsViewModel.selectedMarker) + VStack { + HStack { + Text("period") + } + }.padding() + }.onAppear { + unitReportsViewModel.fetchReport() + } } } diff --git a/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift b/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift new file mode 100644 index 0000000..8f67d7a --- /dev/null +++ b/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift @@ -0,0 +1,71 @@ +// +// UnitReportsViewModel.swift +// iosApp +// +// Created by Iván on 13/02/22. +// Copyright © 2022 orgName. All rights reserved. +// + +import Foundation +import Combine +import shared + +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 report: ReportController.Report? = nil { + didSet { + switch report { + case let report as ReportController.ReportPositionsReport: + markers = report.positions.compactMap { p in Marker.companion.fromPosition(position: p)} + case is ReportController.ReportEventsReport: + markers = [] + case let report as ReportController.ReportStopsReport: + markers = report.stops.compactMap { s in Marker.companion.fromStop(stop: s) } + default: + break + } + } + } + @Published var layer = MapLayer.companion.defaultLayer + @Published var markers = [Marker]() + @Published var selectedMarker: Marker? = nil + + init(deviceId id: Int32?) { + deviceId = id + let collector = Collector<ReportController.Report>(callback: setReport) + reportController.reportFlow.collect(collector: collector) { _, _ in } + } + + func setReport (report: ReportController.Report) { + self.report = report + } + + func fetchReport(xlsx: Bool = false) { + if let id = deviceId { + reportController.fetchReport(deviceId: id, + reportType: reportType, + reportPeriod: reportPeriod, + xlsx: xlsx, eventTypes: [ + .deviceInactive, + .deviceMoving, + .deviceStopped, + .deviceOverspeed, + .deviceFuelDrop, + .commandResult, + .geofenceEnter, + .geofenceExit, + .alarm, + .ignitionOn, + .ignitionOff, + .maintenance, + .textMessage, + .driverChanged, + .unknown + ]) + } + } +} |