diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-03-31 22:00:12 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-03-31 22:00:12 -0600 |
commit | d95742dd9f80506a0d773cbba7bc6a4508de1964 (patch) | |
tree | 86c6f8b50d3221d0b825e786aa36753ee0386646 /iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift | |
parent | 620cd5b1e2782adfd57660017878013f2fb896bd (diff) | |
download | etbsa-trackermap-mobile-d95742dd9f80506a0d773cbba7bc6a4508de1964.tar.gz etbsa-trackermap-mobile-d95742dd9f80506a0d773cbba7bc6a4508de1964.tar.bz2 etbsa-trackermap-mobile-d95742dd9f80506a0d773cbba7bc6a4508de1964.zip |
Added support for sharing and saving reports
Diffstat (limited to 'iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift')
-rw-r--r-- | iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift b/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift index 4731a57..e5b3e4b 100644 --- a/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift +++ b/iosApp/iosApp/Details/Reports/UnitReportsViewModel.swift @@ -1,11 +1,20 @@ -// -// UnitReportsViewModel.swift -// iosApp -// -// Created by Iván on 13/02/22. -// Copyright © 2022 orgName. All rights reserved. -// - +/** + * TrackerMap + * Copyright (C) 2021-2022 Iván Ávalos <avalos@disroot.org>, Henoch Ojeda <imhenoch@protonmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ import Foundation import Combine import shared @@ -14,6 +23,11 @@ class UnitReportsViewModel: ObservableObject { @Inject var reportController: ReportController @Inject var geofencesController: GeofencesController + enum XlsxAction { + case save + case share + } + @Published var deviceId: Int32? = nil @Published var reportType: ReportController.ReportType = .positions { didSet { @@ -34,6 +48,16 @@ class UnitReportsViewModel: ObservableObject { markers = [] case let report as ReportController.ReportStopsReport: markers = report.stops.compactMap { s in Marker.companion.fromStop(stop: s) } + case let report as ReportController.ReportXlsxReport: + print ("Got XLSX report!") + saveDocument = XlsxFile(bytes: report.data) + if xlsxAction == .save { + showExportDialog = true + } else { + let url = saveDocument.data.dataToFile(fileName: "report.xlsx") + activityItems = [url!] + showShareDialog = true + } default: break } @@ -43,6 +67,7 @@ class UnitReportsViewModel: ObservableObject { @Published var markers = [Marker]() @Published var selectedMarker: Marker? = nil + // Geofences @Published var geofences: [Int: Geofence] = [:] { didSet { flatGeofences = Array(geofences.values) @@ -50,6 +75,13 @@ class UnitReportsViewModel: ObservableObject { } @Published var flatGeofences: [Geofence] = [] + // Save and share + var xlsxAction: XlsxAction = .save + var saveDocument = XlsxFile() + @Published var showExportDialog: Bool = false + @Published var showShareDialog: Bool = false + @Published var activityItems: [Any] = [] + init(deviceId id: Int32?) { deviceId = id let collector = Collector<ReportController.Report>(callback: setReport) @@ -91,4 +123,14 @@ class UnitReportsViewModel: ObservableObject { ]) { _, _ in } } } + + func saveXlsxReport () { + xlsxAction = .save + fetchReport(xlsx: true) + } + + func shareXlsxReport () { + xlsxAction = .share + fetchReport(xlsx: true) + } } |