aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-02-04 16:27:11 +0530
committerRoopesh Chander <roop@roopc.net>2019-02-05 12:36:34 +0530
commit657ec34d19274af9ab1fdc1c41e9192a39f5fa14 (patch)
treef8cc825dd8982c3473a163406ce9b19e63c053b9 /WireGuard/WireGuard
parentx25519: demand RNG is successful (diff)
downloadwireguard-apple-657ec34d19274af9ab1fdc1c41e9192a39f5fa14.tar.xz
wireguard-apple-657ec34d19274af9ab1fdc1c41e9192a39f5fa14.zip
macOS: Tunnel detail: Refactor calculation of tableViewModelRows
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift42
1 files changed, 30 insertions, 12 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
index 9e800092..e481a118 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
@@ -78,12 +78,15 @@ class TunnelDetailTableViewController: NSViewController {
let tunnelsManager: TunnelsManager
let tunnel: TunnelContainer
+
var tunnelViewModel: TunnelViewModel {
- didSet {
- updateTableViewModelRows()
- }
+ didSet { updateTableViewModelRowsBySection() }
+ }
+ private var tableViewModelRowsBySection = [[(isVisible: Bool, modelRow: TableViewModelRow)]]() {
+ didSet { updateTableViewModelRows() }
}
private var tableViewModelRows = [TableViewModelRow]()
+
private var statusObservationToken: AnyObject?
private var tunnelEditVC: TunnelEditViewController?
private var reloadRuntimeConfigurationTimer: Timer?
@@ -160,19 +163,34 @@ class TunnelDetailTableViewController: NSViewController {
view = containerView
}
- func updateTableViewModelRows() {
- tableViewModelRows = []
- for field in interfaceFields where !tunnelViewModel.interfaceData[field].isEmpty {
- tableViewModelRows.append(.interfaceFieldRow(field))
+ func updateTableViewModelRowsBySection() {
+ var modelRowsBySection = [[(isVisible: Bool, modelRow: TableViewModelRow)]]()
+
+ var interfaceSection = [(isVisible: Bool, modelRow: TableViewModelRow)]()
+ for field in interfaceFields {
+ interfaceSection.append((isVisible: !tunnelViewModel.interfaceData[field].isEmpty, modelRow: .interfaceFieldRow(field)))
}
+ interfaceSection.append((isVisible: true, modelRow: .spacerRow))
+ modelRowsBySection.append(interfaceSection)
+
for peerData in tunnelViewModel.peersData {
- tableViewModelRows.append(.spacerRow)
- for field in peerFields where !peerData[field].isEmpty {
- tableViewModelRows.append(.peerFieldRow(peer: peerData, field: field))
+ var peerSection = [(isVisible: Bool, modelRow: TableViewModelRow)]()
+ for field in peerFields {
+ peerSection.append((isVisible: !peerData[field].isEmpty, modelRow: .peerFieldRow(peer: peerData, field: field)))
}
+ peerSection.append((isVisible: true, modelRow: .spacerRow))
+ modelRowsBySection.append(peerSection)
}
- tableViewModelRows.append(.spacerRow)
- tableViewModelRows.append(.onDemandRow)
+
+ var onDemandSection = [(isVisible: Bool, modelRow: TableViewModelRow)]()
+ onDemandSection.append((isVisible: true, modelRow: .onDemandRow))
+ modelRowsBySection.append(onDemandSection)
+
+ tableViewModelRowsBySection = modelRowsBySection
+ }
+
+ func updateTableViewModelRows() {
+ tableViewModelRows = tableViewModelRowsBySection.flatMap { $0.filter { $0.isVisible }.map { $0.modelRow } }
}
func updateStatus() {