2022-07-02 22:16:19 -07:00
|
|
|
//
|
|
|
|
|
// AdminMessageList.swift
|
|
|
|
|
// Meshtastic
|
|
|
|
|
//
|
|
|
|
|
// Created by Garth Vander Houwen on 7/2/22.
|
|
|
|
|
//
|
|
|
|
|
/*
|
2023-02-02 21:23:42 -08:00
|
|
|
Abstract:
|
|
|
|
|
A view showing the details for a node.
|
|
|
|
|
*/
|
2022-07-02 22:16:19 -07:00
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import MapKit
|
|
|
|
|
import CoreLocation
|
|
|
|
|
|
|
|
|
|
struct AdminMessageList: View {
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2022-07-02 22:16:19 -07:00
|
|
|
@Environment(\.managedObjectContext) var context
|
|
|
|
|
@EnvironmentObject var bleManager: BLEManager
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2022-07-02 22:16:19 -07:00
|
|
|
var user: UserEntity?
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2022-07-02 22:16:19 -07:00
|
|
|
var body: some View {
|
2022-12-31 00:26:59 -08:00
|
|
|
let localeDateFormat = DateFormatter.dateFormat(fromTemplate: "yyMMddjmmssa", options: 0, locale: Locale.current)
|
|
|
|
|
let dateFormatString = (localeDateFormat ?? "MM/dd/YY j:mm:ss a")
|
2023-05-31 21:39:56 -07:00
|
|
|
|
2022-07-02 22:16:19 -07:00
|
|
|
List {
|
|
|
|
|
if user != nil {
|
2023-03-06 10:33:18 -08:00
|
|
|
|
|
|
|
|
ForEach( user!.adminMessageList.reversed() ) { am in
|
|
|
|
|
|
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
|
|
2023-05-05 09:27:24 -07:00
|
|
|
Text("\(am.adminDescription ?? "unknown".localized)")
|
2023-02-05 11:15:59 -08:00
|
|
|
.font(.caption)
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2023-02-05 11:15:59 -08:00
|
|
|
Text("Sent \(Date(timeIntervalSince1970: TimeInterval(am.messageTimestamp)).formattedDate(format: dateFormatString))")
|
|
|
|
|
.foregroundColor(.gray)
|
2023-02-02 21:23:42 -08:00
|
|
|
.font(.caption2)
|
2023-03-06 10:33:18 -08:00
|
|
|
|
|
|
|
|
HStack(spacing: 0) {
|
2023-02-05 11:15:59 -08:00
|
|
|
let ackErrorVal = RoutingError(rawValue: Int(am.ackError))
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2023-02-05 11:15:59 -08:00
|
|
|
if am.ackTimestamp > 0 {
|
2023-03-13 19:17:43 -07:00
|
|
|
if am.realACK {
|
2023-03-14 12:44:10 -07:00
|
|
|
|
2023-03-13 19:17:43 -07:00
|
|
|
Text(ackErrorVal?.display ?? "Empty Ack Error")
|
|
|
|
|
.foregroundColor(am.receivedACK ? .gray : .red)
|
|
|
|
|
.font(.caption2)
|
|
|
|
|
} else {
|
2023-05-31 21:39:56 -07:00
|
|
|
Text("Implicit ACK from another node")
|
2023-03-13 19:17:43 -07:00
|
|
|
.foregroundColor(.orange)
|
|
|
|
|
.font(.caption2)
|
|
|
|
|
}
|
2023-02-05 11:15:59 -08:00
|
|
|
}
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2023-03-13 19:17:43 -07:00
|
|
|
if am.receivedACK && am.ackTimestamp > 0 {
|
2023-02-05 11:15:59 -08:00
|
|
|
Text(" \(Date(timeIntervalSince1970: TimeInterval(am.ackTimestamp)).formattedDate(format: "h:mm:ss a"))")
|
2023-03-13 19:17:43 -07:00
|
|
|
.foregroundColor(am.realACK ? .gray : .orange)
|
2023-02-05 11:15:59 -08:00
|
|
|
.font(.caption2)
|
2023-02-02 21:23:42 -08:00
|
|
|
}
|
2022-07-02 22:16:19 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-30 17:24:01 -08:00
|
|
|
.navigationTitle("admin.log")
|
2022-07-02 22:16:19 -07:00
|
|
|
.navigationBarItems(trailing:
|
2023-02-02 21:23:42 -08:00
|
|
|
ZStack {
|
2022-07-02 22:16:19 -07:00
|
|
|
ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "????")
|
|
|
|
|
})
|
|
|
|
|
.onAppear {
|
|
|
|
|
self.bleManager.context = context
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|