Tunnel editing: Modifying a tunnel configuration
This commit is contained in:
parent
61cf3f8a5b
commit
34cc14fefa
|
@ -20,7 +20,7 @@ class TunnelDetailTableViewController: UITableViewController {
|
|||
|
||||
let tunnelsManager: TunnelsManager
|
||||
let tunnel: TunnelContainer
|
||||
let tunnelViewModel: TunnelViewModel
|
||||
var tunnelViewModel: TunnelViewModel
|
||||
|
||||
init(tunnelsManager tm: TunnelsManager, tunnel t: TunnelContainer) {
|
||||
tunnelsManager = tm
|
||||
|
@ -44,7 +44,19 @@ class TunnelDetailTableViewController: UITableViewController {
|
|||
}
|
||||
|
||||
@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"
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue