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

This commit is contained in:
Roopesh Chander 2018-10-23 17:48:07 +05:30
parent e8350b689f
commit 63f96b928a
2 changed files with 10 additions and 10 deletions

View File

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

View File

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