Tunnel editing: Modifying a tunnel configuration
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
37f43759b8
commit
06c84a22ca
|
@ -20,7 +20,7 @@ class TunnelDetailTableViewController: UITableViewController {
|
||||||
|
|
||||||
let tunnelsManager: TunnelsManager
|
let tunnelsManager: TunnelsManager
|
||||||
let tunnel: TunnelContainer
|
let tunnel: TunnelContainer
|
||||||
let tunnelViewModel: TunnelViewModel
|
var tunnelViewModel: TunnelViewModel
|
||||||
|
|
||||||
init(tunnelsManager tm: TunnelsManager, tunnel t: TunnelContainer) {
|
init(tunnelsManager tm: TunnelsManager, tunnel t: TunnelContainer) {
|
||||||
tunnelsManager = tm
|
tunnelsManager = tm
|
||||||
|
@ -44,7 +44,19 @@ class TunnelDetailTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func editTapped() {
|
@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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,13 +63,27 @@ class TunnelEditTableViewController: UITableViewController {
|
||||||
let erroringConfiguration = (tunnelViewModel.interfaceData.validatedConfiguration == nil) ? "Interface" : "Peer"
|
let erroringConfiguration = (tunnelViewModel.interfaceData.validatedConfiguration == nil) ? "Interface" : "Peer"
|
||||||
showErrorAlert(title: "Invalid \(erroringConfiguration)", message: errorMessage)
|
showErrorAlert(title: "Invalid \(erroringConfiguration)", message: errorMessage)
|
||||||
case .saved(let tunnelConfiguration):
|
case .saved(let tunnelConfiguration):
|
||||||
tunnelsManager.add(tunnelConfiguration: tunnelConfiguration) { [weak self] (tunnel, error) in
|
if let tunnel = tunnel {
|
||||||
if let error = error {
|
// We're modifying an existing tunnel
|
||||||
print("Could not save: \(error)")
|
tunnelsManager.modify(tunnel: tunnel, with: tunnelConfiguration) { [weak self] (error) in
|
||||||
self?.showErrorAlert(title: "Could not save", message: "Internal error")
|
if let error = error {
|
||||||
} else {
|
print("Could not modify tunnel: \(error)")
|
||||||
self?.delegate?.saved(tunnel: tunnel)
|
self?.showErrorAlert(title: "Could not save", message: "Internal error")
|
||||||
self?.dismiss(animated: true, completion: nil)
|
} 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue