Tunnel view model: The view model applies for both editing and viewing

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-10-23 17:48:07 +05:30
parent 20b49518da
commit 6243717a37
2 changed files with 10 additions and 10 deletions

View File

@ -10,7 +10,7 @@ import UIKit
class TunnelViewModel {
enum InterfaceEditField: String {
enum InterfaceField: String {
case name = "Name"
case privateKey = "Private key"
case publicKey = "Public key"
@ -21,7 +21,7 @@ class TunnelViewModel {
case dns = "DNS servers"
}
enum PeerEditField: String {
enum PeerField: String {
case publicKey = "Public key"
case preSharedKey = "Pre-shared key"
case endpoint = "Endpoint"
@ -32,11 +32,11 @@ class TunnelViewModel {
}
class InterfaceData {
var scratchpad: [InterfaceEditField: String] = [:]
var fieldsWithError: Set<InterfaceEditField> = []
var scratchpad: [InterfaceField: String] = [:]
var fieldsWithError: Set<InterfaceField> = []
var validatedConfiguration: InterfaceConfiguration? = nil
subscript(field: InterfaceEditField) -> String {
subscript(field: InterfaceField) -> String {
get {
if (scratchpad.isEmpty) {
// When starting to read a config, setup the scratchpad.
@ -148,15 +148,15 @@ class TunnelViewModel {
class PeerData {
var index: Int
var scratchpad: [PeerEditField: String] = [:]
var fieldsWithError: Set<PeerEditField> = []
var scratchpad: [PeerField: String] = [:]
var fieldsWithError: Set<PeerField> = []
var validatedConfiguration: PeerConfiguration? = nil
init(index: Int) {
self.index = index
}
subscript(field: PeerEditField) -> String {
subscript(field: PeerField) -> String {
get {
if (scratchpad.isEmpty) {
// When starting to read a config, setup the scratchpad.

View File

@ -12,13 +12,13 @@ import UIKit
class TunnelEditTableViewController: UITableViewController {
let interfaceEditFieldsBySection: [[TunnelViewModel.InterfaceEditField]] = [
let interfaceEditFieldsBySection: [[TunnelViewModel.InterfaceField]] = [
[.name],
[.privateKey, .publicKey, .generateKeyPair],
[.addresses, .listenPort, .mtu, .dns]
]
let peerEditFieldsBySection: [[TunnelViewModel.PeerEditField]] = [
let peerEditFieldsBySection: [[TunnelViewModel.PeerField]] = [
[.publicKey, .preSharedKey, .endpoint,
.allowedIPs, .excludePrivateIPs,
.persistentKeepAlive,