aboutsummaryrefslogtreecommitdiff
path: root/iosApp/iosApp/Details
diff options
context:
space:
mode:
Diffstat (limited to 'iosApp/iosApp/Details')
-rw-r--r--iosApp/iosApp/Details/Reports/UnitReportsView.swift133
-rw-r--r--iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift50
2 files changed, 115 insertions, 68 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