macOS: Tunnel detail: Refactor calculation of tableViewModelRows
This commit is contained in:
parent
e4277c2dfd
commit
5e704465a7
|
@ -78,12 +78,15 @@ class TunnelDetailTableViewController: NSViewController {
|
||||||
|
|
||||||
let tunnelsManager: TunnelsManager
|
let tunnelsManager: TunnelsManager
|
||||||
let tunnel: TunnelContainer
|
let tunnel: TunnelContainer
|
||||||
|
|
||||||
var tunnelViewModel: TunnelViewModel {
|
var tunnelViewModel: TunnelViewModel {
|
||||||
didSet {
|
didSet { updateTableViewModelRowsBySection() }
|
||||||
updateTableViewModelRows()
|
}
|
||||||
}
|
private var tableViewModelRowsBySection = [[(isVisible: Bool, modelRow: TableViewModelRow)]]() {
|
||||||
|
didSet { updateTableViewModelRows() }
|
||||||
}
|
}
|
||||||
private var tableViewModelRows = [TableViewModelRow]()
|
private var tableViewModelRows = [TableViewModelRow]()
|
||||||
|
|
||||||
private var statusObservationToken: AnyObject?
|
private var statusObservationToken: AnyObject?
|
||||||
private var tunnelEditVC: TunnelEditViewController?
|
private var tunnelEditVC: TunnelEditViewController?
|
||||||
private var reloadRuntimeConfigurationTimer: Timer?
|
private var reloadRuntimeConfigurationTimer: Timer?
|
||||||
|
@ -160,19 +163,34 @@ class TunnelDetailTableViewController: NSViewController {
|
||||||
view = containerView
|
view = containerView
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateTableViewModelRows() {
|
func updateTableViewModelRowsBySection() {
|
||||||
tableViewModelRows = []
|
var modelRowsBySection = [[(isVisible: Bool, modelRow: TableViewModelRow)]]()
|
||||||
for field in interfaceFields where !tunnelViewModel.interfaceData[field].isEmpty {
|
|
||||||
tableViewModelRows.append(.interfaceFieldRow(field))
|
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 {
|
for peerData in tunnelViewModel.peersData {
|
||||||
tableViewModelRows.append(.spacerRow)
|
var peerSection = [(isVisible: Bool, modelRow: TableViewModelRow)]()
|
||||||
for field in peerFields where !peerData[field].isEmpty {
|
for field in peerFields {
|
||||||
tableViewModelRows.append(.peerFieldRow(peer: peerData, field: field))
|
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() {
|
func updateStatus() {
|
||||||
|
|
Loading…
Reference in New Issue