This repository was archived by the owner on Oct 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRadarViewController.swift
More file actions
200 lines (173 loc) · 5.57 KB
/
RadarViewController.swift
File metadata and controls
200 lines (173 loc) · 5.57 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import InterfaceBacked
import Sonar
import UIKit
protocol RadarViewDelegate: class {
func productTapped()
func areaTapped()
func versionTapped()
func classificationTapped()
func reproducibilityTapped()
func configurationTapped()
func titleTapped()
func descriptionTapped()
func stepsTapped()
func expectedTapped()
func actualTapped()
func notesTapped()
func attachmentsTapped()
func submitTapped()
func cancelTapped()
}
final class RadarViewController: UITableViewController, StoryboardBacked, StatusDisplay {
// MARK: - Properties
weak var delegate: RadarViewDelegate?
@IBOutlet weak var submitButton: UIButton!
var allRequiredFieldsSet: Bool {
// TODO: Determine required form fields
return true
}
var radar: RadarViewModel? {
didSet {
tableView.reloadData()
}
}
var duplicateOf = ""
var didSelectProduct: (Product) -> Void = { _ in }
// MARK: - User Actions
@IBAction func submitTapped() {
delegate?.submitTapped()
}
@IBAction func cancelTapped() {
delegate?.cancelTapped()
}
// MARK: - UITableViewController Methods
override func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 2 { return 1 }
return 6
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0, duplicateOf.isNotEmpty {
return "Duplicating Radar #\(duplicateOf)"
}
return ""
}
// swiftlint:disable cyclomatic_complexity
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell"), let radar = self.radar else { preconditionFailure() }
var left = ""
var right = ""
var rightPlaceholder: String?
var selectable = true
switch indexPath.section {
case 0:
switch indexPath.row {
case 0:
left = Localizable.Radar.product.localized
right = radar.product.name
case 1:
left = Localizable.Radar.area.localized
right = radar.area?.name ?? ""
selectable = Area.areas(for: radar.product).isNotEmpty
case 2:
left = Localizable.Radar.version.localized
right = radar.version
case 3:
left = Localizable.Radar.classification.localized
right = radar.classification.name
case 4:
left = Localizable.Radar.reproducibility.localized
right = radar.reproducibility.name
case 5:
left = Localizable.Radar.configuration.localized
right = radar.configuration
rightPlaceholder = Localizable.Global.optional.localized
default: break
}
case 1:
switch indexPath.row {
case 0:
left = Localizable.Radar.title.localized
right = radar.title
rightPlaceholder = Localizable.Global.required.localized
case 1:
left = Localizable.Radar.description.localized
right = radar.description
rightPlaceholder = Localizable.Global.required.localized
case 2:
left = Localizable.Radar.steps.localized
right = radar.steps
rightPlaceholder = Localizable.Global.required.localized
case 3:
left = Localizable.Radar.expected.localized
right = radar.expected
rightPlaceholder = Localizable.Global.required.localized
case 4:
left = Localizable.Radar.actual.localized
right = radar.actual
rightPlaceholder = Localizable.Global.required.localized
case 5:
left = Localizable.Radar.notes.localized
right = radar.notes
rightPlaceholder = Localizable.Global.required.localized
default: break
}
case 2:
left = Localizable.Radar.attachament.localized
right = Localizable.Radar.noAttachaments.localized
selectable = false // not implemented yet
default: break
}
cell.selectionStyle = (selectable) ? .blue : .none
cell.textLabel?.textColor = (selectable) ? UIColor.darkText : UIColor.lightGray
cell.textLabel?.text = left
if right.isNotEmpty {
cell.detailTextLabel?.text = right
cell.detailTextLabel?.textColor = view.tintColor
} else {
cell.detailTextLabel?.text = rightPlaceholder
cell.detailTextLabel?.textColor = UIColor.lightGray
}
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.section {
case 0:
switch indexPath.row {
case 0: delegate?.productTapped()
case 1: delegate?.areaTapped()
case 2: delegate?.versionTapped()
case 3: delegate?.classificationTapped()
case 4: delegate?.reproducibilityTapped()
case 5: delegate?.configurationTapped()
default: break
}
case 1:
switch indexPath.row {
case 0: delegate?.titleTapped()
case 1: delegate?.descriptionTapped()
case 2: delegate?.stepsTapped()
case 3: delegate?.expectedTapped()
case 4: delegate?.actualTapped()
case 5: delegate?.notesTapped()
default: break
}
case 2:
delegate?.attachmentsTapped()
default:
break
}
}
// MARK: - Private Methods
private func validateSubmitButton() {
if allRequiredFieldsSet {
submitButton.isEnabled = true
navigationItem.rightBarButtonItem?.isEnabled = true
} else {
submitButton.isEnabled = false
navigationItem.rightBarButtonItem?.isEnabled = false
}
}
}