aboutsummaryrefslogtreecommitdiff
path: root/iosApp
diff options
context:
space:
mode:
Diffstat (limited to 'iosApp')
-rw-r--r--iosApp/iosApp/Details/Reports/UnitReportsView.swift133
-rw-r--r--iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift50
-rw-r--r--iosApp/iosApp/Map/MapViewController.swift6
-rw-r--r--iosApp/iosApp/Units/UnitsViewModel.swift62
-rw-r--r--iosApp/iosApp/en.lproj/Localizable.strings3
-rw-r--r--iosApp/iosApp/es-419.lproj/Localizable.strings3
6 files changed, 173 insertions, 84 deletions
diff --git a/iosApp/iosApp/Details/Reports/UnitReportsView.swift b/iosApp/iosApp/Details/Reports/UnitReportsView.swift
index e189835..7fd45a1 100644
--- a/iosApp/iosApp/Details/Reports/UnitReportsView.swift
+++ b/iosApp/iosApp/Details/Reports/UnitReportsView.swift
@@ -31,6 +31,9 @@ struct UnitReportsView: View {
self.unit = unit
self._unitReportsViewModel = StateObject(
wrappedValue: UnitReportsViewModel(deviceId: unit.device.id))
+ // Source: https://stackoverflow.com/a/63607411
+ UITableView.appearance().contentInset.top = -35
+ UITableView.appearance().contentInset.bottom = -25
}
private var eventsConfig: TablerListConfig<EventInformation> {
@@ -111,76 +114,76 @@ struct UnitReportsView: View {
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")
+ // MARK: - Report type
+ 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(.segmented)
+ .padding()
+
+ Form {
+ // MARK: - Report period
+ Section {
+ HStack {
+ Text("report-period")
+ Spacer()
+ Picker(selection: $unitReportsViewModel.periodType, label: Text("report-period")) {
+ Text("period-today").tag(ReportDates.PeriodTypes.today)
+ Text("period-last-24").tag(ReportDates.PeriodTypes.last24)
+ Text("period-yesterday").tag(ReportDates.PeriodTypes.yesterday)
+ Text("period-this-week").tag(ReportDates.PeriodTypes.thisWeek)
+ Text("period-last-7").tag(ReportDates.PeriodTypes.last7)
+ Text("period-this-month").tag(ReportDates.PeriodTypes.thisMonth)
+ Text("period-last-30").tag(ReportDates.PeriodTypes.last30)
+ Text("period-custom").tag(ReportDates.PeriodTypes.custom)
}
+ .pickerStyle(.menu)
}
- }.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 {
- unitReportsViewModel.saveXlsxReport()
- } label: {
- Text("report-save")
+
+ if unitReportsViewModel.periodType == .custom {
+ DatePicker(selection: $unitReportsViewModel.fromDate, in: ...Date()) {
+ Text("period-from")
}
-
- Button {
- unitReportsViewModel.shareXlsxReport()
- } label: {
- Text("report-share")
- }
- }.frame(maxWidth: .infinity)
- }.padding()
- .sheet(isPresented: $unitReportsViewModel.showShareDialog) {
- ShareView(activityItems: $unitReportsViewModel.activityItems)
- }
- .fileExporter(isPresented: $unitReportsViewModel.showExportDialog,
- documents: [unitReportsViewModel.saveDocument],
- contentType: .xlsx) { result in
- switch result {
- case .success (let url):
- print ("Saved to \(url)")
- case .failure (let error):
- print (error.localizedDescription)
+
+ DatePicker(selection: $unitReportsViewModel.toDate, in: ...Date()) {
+ Text("period-to")
}
}
- }.padding()
+ }
+
+ // MARK: - Report actions
+ Section {
+ Button {
+ unitReportsViewModel.saveXlsxReport()
+ } label: {
+ Text("report-save")
+ }.frame(maxWidth: .infinity)
+
+ Button {
+ unitReportsViewModel.shareXlsxReport()
+ } label: {
+ Text("report-share")
+ }.frame(maxWidth: .infinity)
+ }
+ }
+ .frame(maxHeight: 150)
+ .sheet(isPresented: $unitReportsViewModel.showShareDialog) {
+ ShareView(activityItems: $unitReportsViewModel.activityItems)
+ }
+ .fileExporter(isPresented: $unitReportsViewModel.showExportDialog,
+ documents: [unitReportsViewModel.saveDocument],
+ contentType: .xlsx) { result in
+ switch result {
+ case .success (let url):
+ print ("Saved to \(url)")
+ case .failure (let error):
+ print (error.localizedDescription)
+ }
+ }
}.onAppear {
unitReportsViewModel.fetchReport()
}
diff --git a/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift b/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift
index e5b3e4b..450bfa7 100644
--- a/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift
+++ b/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift
@@ -29,12 +29,38 @@ class UnitReportsViewModel: ObservableObject {
}
@Published var deviceId: Int32? = nil
+
+ // MARK: - Report settings
@Published var reportType: ReportController.ReportType = .positions {
didSet {
fetchReport()
}
}
- @Published var reportPeriod: ReportDates.ReportPeriod = .today {
+ @Published var periodType: ReportDates.PeriodTypes = .today {
+ didSet {
+ switch periodType {
+ case .today:
+ reportPeriod = ReportDates.ReportPeriodToday()
+ case .last24:
+ reportPeriod = ReportDates.ReportPeriodLast24()
+ case .yesterday:
+ reportPeriod = ReportDates.ReportPeriodYesterday()
+ case .thisWeek:
+ reportPeriod = ReportDates.ReportPeriodThisWeek()
+ case .last7:
+ reportPeriod = ReportDates.ReportPeriodLast7()
+ case .thisMonth:
+ reportPeriod = ReportDates.ReportPeriodThisMonth()
+ case .last30:
+ reportPeriod = ReportDates.ReportPeriodLast30()
+ case .custom:
+ reportPeriod = ReportDates.ReportPeriodCustom(from: nil, to: nil)
+ default:
+ reportPeriod = ReportDates.ReportPeriodToday()
+ }
+ }
+ }
+ @Published var reportPeriod: ReportDates.ReportPeriod = ReportDates.ReportPeriodToday() {
didSet {
fetchReport()
}
@@ -67,7 +93,25 @@ class UnitReportsViewModel: ObservableObject {
@Published var markers = [Marker]()
@Published var selectedMarker: Marker? = nil
- // Geofences
+ @Published var fromDate: Date = Date() {
+ didSet {
+ if let custom = reportPeriod as? ReportDates.ReportPeriodCustom {
+ reportPeriod = custom.withFrom(
+ from: DateUtils.companion.iosDateToKotlin(date: fromDate))
+ }
+ }
+ }
+
+ @Published var toDate: Date = Calendar.current.startOfDay(for: Date()) {
+ didSet {
+ if let custom = reportPeriod as? ReportDates.ReportPeriodCustom {
+ reportPeriod = custom.withTo(
+ to: DateUtils.companion.iosDateToKotlin(date: toDate))
+ }
+ }
+ }
+
+ // MARK: - Geofences
@Published var geofences: [Int: Geofence] = [:] {
didSet {
flatGeofences = Array(geofences.values)
@@ -75,7 +119,7 @@ class UnitReportsViewModel: ObservableObject {
}
@Published var flatGeofences: [Geofence] = []
- // Save and share
+ // MARK: - Save and share
var xlsxAction: XlsxAction = .save
var saveDocument = XlsxFile()
@Published var showExportDialog: Bool = false
diff --git a/iosApp/iosApp/Map/MapViewController.swift b/iosApp/iosApp/Map/MapViewController.swift
index 3c38b89..07b72a6 100644
--- a/iosApp/iosApp/Map/MapViewController.swift
+++ b/iosApp/iosApp/Map/MapViewController.swift
@@ -20,7 +20,7 @@ import WhirlyGlobe
import shared
import GEOSwift
-typealias MarkerCallback = (Int32?) -> ()
+typealias MarkerCallback = (Int32?, Bool) -> ()
extension Geometry {
func getCoordinates() -> [Point] {
@@ -138,7 +138,7 @@ extension MapViewController: MaplyViewControllerDelegate {
func maplyViewController(_ viewC: MaplyViewController,
didTapAt coord: MaplyCoordinate) {
- markerCallback?(nil)
+ markerCallback?(nil, true)
}
func maplyViewController(_ viewC: MaplyViewController,
@@ -147,7 +147,7 @@ extension MapViewController: MaplyViewControllerDelegate {
onScreen screenPt: CGPoint) {
if let marker = selectedObj as? MaplyScreenMarker {
if let id = marker.userObject as? Int32 {
- markerCallback?(id)
+ markerCallback?(id, true)
}
}
}
diff --git a/iosApp/iosApp/Units/UnitsViewModel.swift b/iosApp/iosApp/Units/UnitsViewModel.swift
index 8ba6a4b..6a3ce19 100644
--- a/iosApp/iosApp/Units/UnitsViewModel.swift
+++ b/iosApp/iosApp/Units/UnitsViewModel.swift
@@ -49,12 +49,15 @@ class UnitsViewModel: ObservableObject {
}
}
@Published var markers: [Marker] = []
+ @Published var oldSelectedUnit: UnitInformation? = nil
@Published var selectedUnit: UnitInformation? = nil {
didSet {
- if let unit = selectedUnit {
- selectedMarker = Marker.companion.fromUnit(unit: unit)
- } else {
- selectedMarker = nil
+ if selectedUnit?.device.id != oldSelectedUnit?.device.id {
+ if let unit = selectedUnit {
+ selectedMarker = Marker.companion.fromUnit(unit: unit)
+ } else {
+ selectedMarker = nil
+ }
}
}
}
@@ -87,32 +90,65 @@ class UnitsViewModel: ObservableObject {
private func setUnits(units: [UnitInformation]) {
print("Positions")
self.units = units
+ updateSelectedUnit()
}
private func setGeofences(geofences: [Int: Geofence]) {
self.geofences = geofences
}
- func selectUnitWith(position id: Int32?) {
+ func selectUnit(unit: UnitInformation?, switchToMap: Bool = true) {
+ print ("Selecting unit \(unit?.device.name ?? "")")
+ oldSelectedUnit = selectedUnit
+ selectedUnit = unit
+ if unit != nil && switchToMap {
+ setDisplayMode(UnitsDisplayMode.map)
+ }
+ }
+
+ func selectUnitWith(position id: Int32?, switchToMap: Bool = true) {
if id == nil {
print("Deselecting unit")
- selectedUnit = nil
+ selectUnit(unit: nil, switchToMap: switchToMap)
return
}
- print("Selecting unit with position id: \(id ?? 0)")
- if let unit = units.first(where: {
- Int32(truncating: $0.position?.id ?? 0) == id
- }) {
- selectedUnit = unit
+ print("Selecting unit with position id: \(id!)")
+ let unit = units.first {
+ Int32(truncating: $0.position?.id ?? 0) == id!
}
+ selectUnit(unit: unit, switchToMap: switchToMap)
+ }
+
+ private func selectUnitWith(id: Int32?, switchToMap: Bool = true) {
+ if id == nil {
+ print("Deselecting unit")
+ selectUnit(unit: nil, switchToMap: switchToMap)
+ return
+ }
+ print("Selecting unit with device id: \(id!)")
+ let unit = units.first {
+ $0.device.id == id!
+ }
+ selectUnit(unit: unit, switchToMap: switchToMap)
+ }
+
+ private func updateSelectedUnit() {
+ if let selected = selectedUnit {
+ print("Updating selected unit with id: \(selected.device.id)")
+ selectUnitWith(id: selected.device.id, switchToMap: false)
+ }
+ }
+
+ func setDisplayMode(_ displayMode: UnitsDisplayMode) {
+ unitsDisplayMode = displayMode
}
func toggleDisplayMode() {
switch unitsDisplayMode {
case .map:
- unitsDisplayMode = .list
+ setDisplayMode(.list)
case .list:
- unitsDisplayMode = .map
+ setDisplayMode(.map)
}
}
diff --git a/iosApp/iosApp/en.lproj/Localizable.strings b/iosApp/iosApp/en.lproj/Localizable.strings
index ca8e5a1..0959a1f 100644
--- a/iosApp/iosApp/en.lproj/Localizable.strings
+++ b/iosApp/iosApp/en.lproj/Localizable.strings
@@ -68,6 +68,9 @@
"period-last-7" = "Last 7d";
"period-this-month" = "Month";
"period-last-30" = "Last 30d";
+"period-custom" = "Custom";
+"period-from" = "Start";
+"period-to" = "End";
"events-table-event" = "Event";
"events-table-datetime" = "Datetime";
diff --git a/iosApp/iosApp/es-419.lproj/Localizable.strings b/iosApp/iosApp/es-419.lproj/Localizable.strings
index 9abd96a..52267cc 100644
--- a/iosApp/iosApp/es-419.lproj/Localizable.strings
+++ b/iosApp/iosApp/es-419.lproj/Localizable.strings
@@ -68,6 +68,9 @@
"period-last-7" = "Últimos 7d";
"period-this-month" = "Mes";
"period-last-30" = "Últimos 30d";
+"period-custom" = "Personalizado";
+"period-from" = "Inicio";
+"period-to" = "Fin";
"events-table-event" = "Evento";
"events-table-datetime" = "Fecha y hora";