aboutsummaryrefslogtreecommitdiff
path: root/iosApp/iosApp/Details/Reports/UnitReportsView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'iosApp/iosApp/Details/Reports/UnitReportsView.swift')
-rw-r--r--iosApp/iosApp/Details/Reports/UnitReportsView.swift148
1 files changed, 146 insertions, 2 deletions
diff --git a/iosApp/iosApp/Details/Reports/UnitReportsView.swift b/iosApp/iosApp/Details/Reports/UnitReportsView.swift
index 26ddead..2143b3b 100644
--- a/iosApp/iosApp/Details/Reports/UnitReportsView.swift
+++ b/iosApp/iosApp/Details/Reports/UnitReportsView.swift
@@ -17,11 +17,155 @@
*/
import SwiftUI
import shared
+import SwiftUIX
+import Tabler
+
+extension EventInformation: Identifiable {}
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))
+ }
+
+ private var eventsConfig: TablerListConfig<EventInformation> {
+ TablerListConfig<EventInformation>(gridItems: eventsGridItems)
+ }
+
+ private var eventsGridItems: [GridItem] = [
+ GridItem(.flexible(minimum: 100), alignment: .leading),
+ GridItem(.flexible(minimum: 100), alignment: .leading),
+ GridItem(.flexible(minimum: 100, maximum: 150), alignment: .leading),
+ GridItem(.flexible(minimum: 150, maximum: 250), alignment: .leading),
+ ]
+
+ @ViewBuilder
+ private func eventsHeader(_ ctx: Binding<TablerContext<EventInformation>>) -> some View {
+ Text("events-table-datetime")
+ Text("events-table-event")
+ Text("events-table-geofence")
+ Text("events-table-address")
+ }
+
+ @ViewBuilder
+ private func eventsRow(_ element: EventInformation) -> some View {
+ if let eventTime = element.event.eventTime {
+ Text(Formatter.companion.formatDate(str: eventTime))
+ } else { Text("") }
+
+ if let eventType = element.event.type {
+ switch EventInformation.companion.stringToReportType(s: eventType) {
+ case .deviceOnline: Text("event-device-online")
+ case .deviceUnknown: Text("event-device-unknown")
+ case .deviceOffline: Text("event-device-offline")
+ case .deviceInactive: Text("event-device-inactive")
+ case .deviceMoving: Text("event-device-moving")
+ case .deviceStopped: Text("event-device-stopped")
+ case .deviceOverspeed: Text("event-device-overspeed")
+ case .deviceFuelDrop: Text("event-device-fuel-drop")
+ case .commandResult: Text("event-command-result")
+ case .geofenceEnter: Text("event-geofence-enter")
+ case .geofenceExit: Text("event-geofence-exit")
+ case .alarm: Text("event-alarm")
+ case .ignitionOn: Text("event-ignition-on")
+ case .ignitionOff: Text("event-ignition-off")
+ case .maintenance: Text("event-maintenance")
+ case .textMessage: Text("event-text-message")
+ case .driverChanged: Text("event-driver-changed")
+ default: Text("event-unknown")
+ }
+ } else { Text("") }
+
+ if let geofenceName = element.geofence?.name {
+ Text(geofenceName)
+ } else { Text("") }
+
+ if let positionAddress = element.position?.address {
+ Text(positionAddress)
+ } else { Text("") }
+ }
+
var body: some View {
- Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+ VStack {
+ if unitReportsViewModel.reportType == .events {
+ if let report = unitReportsViewModel.report as? ReportController.ReportEventsReport {
+ SidewaysScroller(minWidth: 1000) {
+ TablerList(eventsConfig,
+ headerContent: eventsHeader,
+ rowContent: eventsRow,
+ results: report.events)
+ }
+ } else {
+ Spacer()
+ }
+ } else {
+ MapView(layer: $unitReportsViewModel.layer,
+ markers: $unitReportsViewModel.markers,
+ geofences: $unitReportsViewModel.flatGeofences,
+ selected: $unitReportsViewModel.selectedMarker,
+ isReport: true)
+ }
+
+ VStack {
+ HStack {
+ 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()
+ }
}
}