-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataDetailView.swift
100 lines (92 loc) · 3.56 KB
/
DataDetailView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// DataDetailView.swift
// HyperClient (iOS)
//
// Created by Niko Ma on 3/30/22.
//
import SwiftUI
struct DataDetail: View {
@State var dataPair: ResponsePair
@State var showEditor = false
@Environment(\.dismiss) var dissmiss
@EnvironmentObject var clientVM: ClientViewModel
var body: some View {
List {
Group {
Section("实验名称") {
Text(dataPair.data.name)
}
Section("实验时间") {
Text(dataPair.data.experiment_time.toDate)
}
Section("作者") {
Text(dataPair.data.author)
}
Section("电子邮件") {
Text(dataPair.data.email)
}
Section("机构") {
Text(dataPair.data.institution)
}
Section("实验环境") {
Text(dataPair.data.environment)
}
Section("实验参数") {
Text(dataPair.data.parameters)
}
Section("详细信息") {
Text(dataPair.data.details)
}
Section("附件") {
ForEach(dataPair.data.attachment.components(separatedBy: " "), id: \.self) { str in
Text(str).onTapGesture {
UIApplication.shared.open(URL(string: str.trimmingCharacters(in: .whitespacesAndNewlines))!)
}.foregroundColor(.accentColor)
}
}
}
Group {
Section("数据哈希值") {
Text(dataPair.data.hash)
}
Section("数据验证结果") {
dataPair.authentication.result == true ? Image(systemName: "checkmark.circle").font(.system(size: 40)).foregroundColor(.green) : Image(systemName: "xmark.circle").font(.system(size: 40)).foregroundColor(.red)
}
NavigationLink {
historyList().environmentObject(clientVM).task {
await clientVM.fetchHistory(id: dataPair.data.id)
}
} label: {
Text("编辑历史")
}
}
}.toolbar {
ToolbarItem {
Button("编辑") {
showEditor = true
}
}
}.task {
dataPair.verify()
}
.popover(isPresented: $showEditor) {
CreateEntryView(clientVM: clientVM, name: dataPair.data.name, time: Date(timeIntervalSince1970: dataPair.data.experiment_time), author: dataPair.data.author, email: dataPair.data.email, institution: dataPair.data.institution, environment: dataPair.data.environment, parameters: dataPair.data.parameters, details: dataPair.data.details, attachment: dataPair.data.attachment, offset: dataPair.data.offset)
}
}
struct historyList: View {
@EnvironmentObject var clientVM: ClientViewModel
var body: some View {
List {
if let history = clientVM.history {
ForEach(history, id:\.self) { elem in
NavigationLink {
HistoryView(dataPair: elem)
} label: {
Text(elem.data.timestamp.toDate)
}
}
}
}
}
}
}