Tunnel creation: After saving the new tunnel, show the detail view
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
0fad01107c
commit
37f43759b8
|
@ -19,11 +19,13 @@ class TunnelDetailTableViewController: UITableViewController {
|
|||
]
|
||||
|
||||
let tunnelsManager: TunnelsManager
|
||||
let tunnel: TunnelContainer
|
||||
let tunnelViewModel: TunnelViewModel
|
||||
|
||||
init(tunnelsManager tm: TunnelsManager, tunnelConfiguration: TunnelConfiguration) {
|
||||
init(tunnelsManager tm: TunnelsManager, tunnel t: TunnelContainer) {
|
||||
tunnelsManager = tm
|
||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnelConfiguration)
|
||||
tunnel = t
|
||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: t.tunnelProvider.tunnelConfiguration)
|
||||
super.init(style: .grouped)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,16 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
protocol TunnelEditTableViewControllerDelegate: class {
|
||||
func saved(tunnel: TunnelContainer)
|
||||
}
|
||||
|
||||
// MARK: TunnelEditTableViewController
|
||||
|
||||
class TunnelEditTableViewController: UITableViewController {
|
||||
|
||||
weak var delegate: TunnelEditTableViewControllerDelegate? = nil
|
||||
|
||||
let interfaceFieldsBySection: [[TunnelViewModel.InterfaceField]] = [
|
||||
[.name],
|
||||
[.privateKey, .publicKey, .generateKeyPair],
|
||||
|
@ -20,11 +26,13 @@ class TunnelEditTableViewController: UITableViewController {
|
|||
]
|
||||
|
||||
let tunnelsManager: TunnelsManager
|
||||
let tunnel: TunnelContainer?
|
||||
let tunnelViewModel: TunnelViewModel
|
||||
|
||||
init(tunnelsManager tm: TunnelsManager) {
|
||||
init(tunnelsManager tm: TunnelsManager, tunnel t: TunnelContainer? = nil) {
|
||||
tunnelsManager = tm
|
||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: nil)
|
||||
tunnel = t
|
||||
tunnelViewModel = TunnelViewModel(tunnelConfiguration: t?.tunnelProvider.tunnelConfiguration)
|
||||
super.init(style: .grouped)
|
||||
self.modalPresentationStyle = .formSheet
|
||||
}
|
||||
|
@ -55,11 +63,12 @@ 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] (error) in
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ class TunnelsListTableViewController: UITableViewController {
|
|||
UIAlertAction(title: "Create from scratch", style: .default) { [weak self] (action) in
|
||||
if let s = self, let tunnelsManager = s.tunnelsManager {
|
||||
let editVC = TunnelEditTableViewController(tunnelsManager: tunnelsManager)
|
||||
editVC.delegate = s
|
||||
let editNC = UINavigationController(rootViewController: editVC)
|
||||
s.present(editNC, animated: true)
|
||||
}
|
||||
|
@ -55,6 +56,17 @@ class TunnelsListTableViewController: UITableViewController {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: TunnelEditTableViewControllerDelegate
|
||||
|
||||
extension TunnelsListTableViewController: TunnelEditTableViewControllerDelegate {
|
||||
func saved(tunnel: TunnelContainer) {
|
||||
guard let tunnelsManager = tunnelsManager else { return }
|
||||
let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager,
|
||||
tunnel: tunnel)
|
||||
showDetailViewController(tunnelDetailVC, sender: self) // Shall get propagated up to the split-vc
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: UITableViewDataSource
|
||||
|
||||
extension TunnelsListTableViewController {
|
||||
|
@ -81,9 +93,9 @@ extension TunnelsListTableViewController {
|
|||
extension TunnelsListTableViewController {
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
guard let tunnelsManager = tunnelsManager else { return }
|
||||
let tunnelConfiguration = tunnelsManager.tunnel(at: indexPath.row).tunnelProvider.tunnelConfiguration
|
||||
let tunnel = tunnelsManager.tunnel(at: indexPath.row)
|
||||
let tunnelDetailVC = TunnelDetailTableViewController(tunnelsManager: tunnelsManager,
|
||||
tunnelConfiguration: tunnelConfiguration)
|
||||
tunnel: tunnel)
|
||||
showDetailViewController(tunnelDetailVC, sender: self) // Shall get propagated up to the split-vc
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class TunnelsManager {
|
|||
completionHandler(TunnelsManager(tunnelProviders: []))
|
||||
}
|
||||
|
||||
func add(tunnelConfiguration: TunnelConfiguration, completionHandler: @escaping (Error?) -> Void) {
|
||||
func add(tunnelConfiguration: TunnelConfiguration, completionHandler: @escaping (TunnelContainer, Error?) -> Void) {
|
||||
let tunnelProvider = TunnelProviderManager(tunnelConfiguration: tunnelConfiguration)
|
||||
for tunnel in tunnels {
|
||||
tunnel.index = tunnel.index + 1
|
||||
|
@ -57,7 +57,7 @@ class TunnelsManager {
|
|||
let tunnel = TunnelContainer(tunnel: tunnelProvider, index: 0)
|
||||
tunnels.insert(tunnel, at: 0)
|
||||
delegate?.tunnelsAdded(atIndex: 0, numberOfTunnels: 1)
|
||||
completionHandler(nil)
|
||||
completionHandler(tunnel, nil)
|
||||
}
|
||||
|
||||
func modify(tunnel: TunnelContainer, with tunnelConfiguration: TunnelConfiguration, completionHandler: @escaping (Error?) -> Void) {
|
||||
|
|
Loading…
Reference in New Issue