Show warning alert before continuing import

Fixes #16
This commit is contained in:
Davide De Rosa 2018-10-27 14:40:52 +02:00
parent 8d2ce2e7ae
commit 0f43255676
5 changed files with 54 additions and 13 deletions

View File

@ -95,6 +95,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
try? fm.removeItem(at: url) try? fm.removeItem(at: url)
return true return true
} }
if let warning = parsedFile.warning {
ParsedFile.alertImportWarning(url: url, in: root, withWarning: warning) {
if $0 {
self.handleParsedFile(parsedFile, in: root)
} else {
try? fm.removeItem(at: url)
}
}
return true
}
handleParsedFile(parsedFile, in: root) handleParsedFile(parsedFile, in: root)
return true return true
} }

View File

@ -92,6 +92,7 @@ internal enum StoryboardSegue {
case disclaimerSegueIdentifier = "DisclaimerSegueIdentifier" case disclaimerSegueIdentifier = "DisclaimerSegueIdentifier"
case importHostSegueIdentifier = "ImportHostSegueIdentifier" case importHostSegueIdentifier = "ImportHostSegueIdentifier"
case selectProfileSegueIdentifier = "SelectProfileSegueIdentifier" case selectProfileSegueIdentifier = "SelectProfileSegueIdentifier"
case showImportedHostsSegueIdentifier = "ShowImportedHostsSegueIdentifier"
case versionSegueIdentifier = "VersionSegueIdentifier" case versionSegueIdentifier = "VersionSegueIdentifier"
} }
} }

View File

@ -41,6 +41,12 @@ class ImportedHostsViewController: UITableViewController {
title = L10n.ImportedHosts.title title = L10n.ImportedHosts.title
} }
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
parsedFile = nil
}
override func viewDidAppear(_ animated: Bool) { override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated) super.viewDidAppear(animated)
@ -56,22 +62,40 @@ class ImportedHostsViewController: UITableViewController {
present(alert, animated: true, completion: nil) present(alert, animated: true, completion: nil)
return return
} }
if let selectedIP = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: selectedIP, animated: true)
}
} }
// MARK: Actions // MARK: Actions
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
guard let cell = sender as? UITableViewCell, let indexPath = tableView.indexPath(for: cell) else {
return false // segue parses configuration file if not yet
} if parsedFile == nil {
let url = pendingConfigurationURLs[indexPath.row] guard let cell = sender as? UITableViewCell, let indexPath = tableView.indexPath(for: cell) else {
guard let parsedFile = ParsedFile.from(url, withErrorAlertIn: self) else { return false
if let selectedIP = tableView.indexPathForSelectedRow { }
tableView.deselectRow(at: selectedIP, animated: true) let url = pendingConfigurationURLs[indexPath.row]
guard let parsedFile = ParsedFile.from(url, withErrorAlertIn: self) else {
deselectSelectedRow()
return false
}
self.parsedFile = parsedFile
// postpone segue until alert dismissal
if let warning = parsedFile.warning {
ParsedFile.alertImportWarning(url: url, in: self, withWarning: warning) {
self.deselectSelectedRow()
if $0 {
self.perform(segue: StoryboardSegue.Organizer.importHostSegueIdentifier)
} else {
self.parsedFile = nil
}
}
return false
} }
return false
} }
self.parsedFile = parsedFile
return true return true
} }
@ -86,6 +110,12 @@ class ImportedHostsViewController: UITableViewController {
@IBAction private func close() { @IBAction private func close() {
dismiss(animated: true, completion: nil) dismiss(animated: true, completion: nil)
} }
private func deselectSelectedRow() {
if let selectedIP = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: selectedIP, animated: true)
}
}
} }
extension ImportedHostsViewController { extension ImportedHostsViewController {

View File

@ -176,7 +176,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
} }
private func addNewHost() { private func addNewHost() {
perform(segue: StoryboardSegue.Organizer.importHostSegueIdentifier) perform(segue: StoryboardSegue.Organizer.showImportedHostsSegueIdentifier)
} }
private func removeProfile(at indexPath: IndexPath) { private func removeProfile(at indexPath: IndexPath) {

View File

@ -194,7 +194,7 @@
</subviews> </subviews>
</tableViewCellContentView> </tableViewCellContentView>
<connections> <connections>
<segue destination="oga-go-FqD" kind="show" id="kwN-PZ-Zg5"/> <segue destination="oga-go-FqD" kind="show" identifier="ImportHostSegueIdentifier" id="kwN-PZ-Zg5"/>
</connections> </connections>
</tableViewCell> </tableViewCell>
</prototypes> </prototypes>
@ -293,7 +293,7 @@
<connections> <connections>
<segue destination="NVA-bQ-iIE" kind="presentation" identifier="AddProviderSegueIdentifier" modalPresentationStyle="formSheet" id="Win-5U-mIc"/> <segue destination="NVA-bQ-iIE" kind="presentation" identifier="AddProviderSegueIdentifier" modalPresentationStyle="formSheet" id="Win-5U-mIc"/>
<segue destination="a3d-vD-Pr7" kind="presentation" identifier="AboutSegueIdentifier" id="fd4-we-46n"/> <segue destination="a3d-vD-Pr7" kind="presentation" identifier="AboutSegueIdentifier" id="fd4-we-46n"/>
<segue destination="z6E-m6-Op0" kind="presentation" identifier="ImportHostSegueIdentifier" modalPresentationStyle="formSheet" id="TZv-OK-8vU"/> <segue destination="z6E-m6-Op0" kind="presentation" identifier="ShowImportedHostsSegueIdentifier" modalPresentationStyle="formSheet" id="TZv-OK-8vU"/>
</connections> </connections>
</tableViewController> </tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="bGp-H5-24W" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="bGp-H5-24W" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -567,6 +567,6 @@
</resources> </resources>
<inferredMetricsTieBreakers> <inferredMetricsTieBreakers>
<segue reference="HW6-RJ-VFY"/> <segue reference="HW6-RJ-VFY"/>
<segue reference="qQl-B5-moM"/> <segue reference="kwN-PZ-Zg5"/>
</inferredMetricsTieBreakers> </inferredMetricsTieBreakers>
</document> </document>