let tunnelsManager: TunnelsManager
let tunnel: TunnelContainer
- let tunnelViewModel: TunnelViewModel
+ var tunnelViewModel: TunnelViewModel
init(tunnelsManager tm: TunnelsManager, tunnel t: TunnelContainer) {
tunnelsManager = tm
}
@objc func editTapped() {
- print("Edit")
+ let editVC = TunnelEditTableViewController(tunnelsManager: tunnelsManager, tunnel: tunnel)
+ editVC.delegate = self
+ let editNC = UINavigationController(rootViewController: editVC)
+ present(editNC, animated: true)
+ }
+}
+
+// MARK: TunnelEditTableViewControllerDelegate
+
+extension TunnelDetailTableViewController: TunnelEditTableViewControllerDelegate {
+ func saved(tunnel: TunnelContainer) {
+ tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelProvider.tunnelConfiguration)
+ self.tableView.reloadData()
}
}
let erroringConfiguration = (tunnelViewModel.interfaceData.validatedConfiguration == nil) ? "Interface" : "Peer"
showErrorAlert(title: "Invalid \(erroringConfiguration)", message: errorMessage)
case .saved(let tunnelConfiguration):
- tunnelsManager.add(tunnelConfiguration: tunnelConfiguration) { [weak self] (tunnel, error) in
- if let error = error {
- print("Could not save: \(error)")
- self?.showErrorAlert(title: "Could not save", message: "Internal error")
- } else {
- self?.delegate?.saved(tunnel: tunnel)
- self?.dismiss(animated: true, completion: nil)
+ if let tunnel = tunnel {
+ // We're modifying an existing tunnel
+ tunnelsManager.modify(tunnel: tunnel, with: tunnelConfiguration) { [weak self] (error) in
+ if let error = error {
+ print("Could not modify tunnel: \(error)")
+ self?.showErrorAlert(title: "Could not save", message: "Internal error")
+ } else {
+ self?.delegate?.saved(tunnel: tunnel)
+ self?.dismiss(animated: true, completion: nil)
+ }
+ }
+ } else {
+ // We're adding a new tunnel
+ tunnelsManager.add(tunnelConfiguration: tunnelConfiguration) { [weak self] (tunnel, error) in
+ if let error = error {
+ print("Could not add tunnel: \(error)")
+ self?.showErrorAlert(title: "Could not save", message: "Internal error")
+ } else {
+ self?.delegate?.saved(tunnel: tunnel)
+ self?.dismiss(animated: true, completion: nil)
+ }
}
}
}