diff --git a/JSONCreator_iOS/JSONCreator.xcodeproj/project.pbxproj b/JSONCreator_iOS/JSONCreator.xcodeproj/project.pbxproj
index 9a77bbf..8542629 100644
--- a/JSONCreator_iOS/JSONCreator.xcodeproj/project.pbxproj
+++ b/JSONCreator_iOS/JSONCreator.xcodeproj/project.pbxproj
@@ -101,12 +101,12 @@
D2B1E3F122F4A68F0065F95C /* JSONCreator */ = {
isa = PBXGroup;
children = (
- D2B1E40922F4C9F00065F95C /* JSON */,
D2B1E3F222F4A68F0065F95C /* AppDelegate.swift */,
D2B1E3F422F4A68F0065F95C /* MasterViewController.swift */,
D2B1E3F622F4A68F0065F95C /* DetailViewController.swift */,
D2B1E3F822F4A68F0065F95C /* Main.storyboard */,
D2B1E3FB22F4A6930065F95C /* Assets.xcassets */,
+ D2B1E40922F4C9F00065F95C /* JSON */,
D2B1E3FD22F4A6930065F95C /* LaunchScreen.storyboard */,
D2B1E40022F4A6930065F95C /* Info.plist */,
);
diff --git a/JSONCreator_iOS/JSONCreator/AppDelegate.swift b/JSONCreator_iOS/JSONCreator/AppDelegate.swift
index 0542ff1..0d13d99 100644
--- a/JSONCreator_iOS/JSONCreator/AppDelegate.swift
+++ b/JSONCreator_iOS/JSONCreator/AppDelegate.swift
@@ -15,6 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
var window: UIWindow?
func itera(_ path: String) {
+
let fileManager = FileManager.default
let enumerator = fileManager.enumerator(atPath: path)!
for element in enumerator {
@@ -74,5 +75,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
return false
}
-
}
diff --git a/JSONCreator_iOS/JSONCreator/Base.lproj/Main.storyboard b/JSONCreator_iOS/JSONCreator/Base.lproj/Main.storyboard
index 5fd91d6..fb59f52 100644
--- a/JSONCreator_iOS/JSONCreator/Base.lproj/Main.storyboard
+++ b/JSONCreator_iOS/JSONCreator/Base.lproj/Main.storyboard
@@ -19,7 +19,7 @@
-
+
@@ -57,45 +57,73 @@
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
diff --git a/JSONCreator_iOS/JSONCreator/DetailViewController.swift b/JSONCreator_iOS/JSONCreator/DetailViewController.swift
index 8a6a0de..2bce530 100644
--- a/JSONCreator_iOS/JSONCreator/DetailViewController.swift
+++ b/JSONCreator_iOS/JSONCreator/DetailViewController.swift
@@ -23,12 +23,13 @@ class DetailViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
- // Do any additional setup after loading the view.
- guard textView.superview == nil else {
- return
- }
+
+ guard textView.superview == nil else { return }
+
+ textView.textDropDelegate = self
+
view.addSubview(textView)
- textView.font = UIFont.systemFont(ofSize: 40)
+ textView.font = UIFont.systemFont(ofSize: 30)
textView.translatesAutoresizingMaskIntoConstraints = false
textView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
textView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
@@ -49,12 +50,14 @@ class DetailViewController: UIViewController {
//--------------------------------------------------
func showError(_ error: NSError) {
+
let alert = UIAlertController(title: "Error", message: "\(error)", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
@objc func shareButtonPressed() {
+
if let text = textView.text {
let activityController = UIActivityViewController(activityItems: [text], applicationActivities: nil)
activityController.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
@@ -63,12 +66,14 @@ class DetailViewController: UIViewController {
}
@objc func play() {
+
do {
if let data = textView.text.data(using: .utf8), let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [AnyHashable: Any] {
let page = jsonObject.optionalDictionaryForKey(KeyPage)
let pageType = page?.optionalStringForKey(KeyPageType)
let template = page?.optionalStringForKey("template")
var errorObject = MVMCoreErrorObject(title: nil, message: "No Template Found", code: ErrorCode.initViewController.rawValue, domain: ErrorDomainNative, location: nil)
+
if let viewController = MVMCoreUIViewControllerMappingObject.shared()?.createMFViewController(ofTemplate: template, pageType: pageType), let loadObject = MVMCoreLoadObject(pageJSON: page, modulesJSON: nil, requestParameters: nil, dataForPage: nil, delegateObject: nil), viewController.shouldFinishProcessingLoad(loadObject, error: &errorObject!) {
let navigation = UINavigationController(rootViewController: viewController)
viewController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(close))
@@ -84,16 +89,18 @@ class DetailViewController: UIViewController {
}
@objc func close() {
+
MVMCoreNavigationHandler.shared()?.dismissTopViewController(animated: true)
}
}
// MARK:- TextView Delegate
extension DetailViewController: UITextViewDelegate {
+
func textViewShouldEndEditing(_ textView: UITextView) -> Bool {
- guard textView.text.count > 0 else {
- return true
- }
+
+ guard textView.text.count > 0 else { return true }
+
do {
if let data = textView.text.data(using: .utf8) {
let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])
@@ -109,9 +116,9 @@ extension DetailViewController: UITextViewDelegate {
}
func textViewDidEndEditing(_ textView: UITextView) {
- guard textView.text.count > 0 else {
- return
- }
+
+ guard textView.text.count > 0 else { return }
+
do {
if let data = textView.text.data(using: .utf8) {
let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])
@@ -126,3 +133,10 @@ extension DetailViewController: UITextViewDelegate {
}
}
}
+
+extension DetailViewController: UITextDropDelegate {
+
+ func textDroppableView(_ textDroppableView: UIView & UITextDroppable, willPerformDrop drop: UITextDropRequest) {
+ let hi = "d"
+ }
+}
diff --git a/JSONCreator_iOS/JSONCreator/MasterViewController.swift b/JSONCreator_iOS/JSONCreator/MasterViewController.swift
index baa2a76..4ce8057 100644
--- a/JSONCreator_iOS/JSONCreator/MasterViewController.swift
+++ b/JSONCreator_iOS/JSONCreator/MasterViewController.swift
@@ -10,7 +10,14 @@ import UIKit
import MVMCore
-class MasterViewController: UITableViewController {
+class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
+ //--------------------------------------------------
+ // MARK: - Outlets
+ //--------------------------------------------------
+
+ @IBOutlet weak var tableView: UITableView!
+ @IBOutlet weak var ipTextField: UITextField!
+
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
@@ -23,30 +30,33 @@ class MasterViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
- // Do any additional setup after loading the view.
-
+
+ tableView.delegate = self
+ tableView.dataSource = self
tableView.estimatedRowHeight = 80
tableView.rowHeight = UITableView.automaticDimension
+
+ ipTextField.text = "127.0.0.1:8181"
}
//--------------------------------------------------
// MARK: - Table View
//--------------------------------------------------
- override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
+ func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return try? FileManager.default.contentsOfDirectory(atPath: folderPath)[section]
}
- override func numberOfSections(in tableView: UITableView) -> Int {
+ func numberOfSections(in tableView: UITableView) -> Int {
return try! FileManager.default.contentsOfDirectory(atPath: folderPath).count
}
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return try! FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath)[section]).count
}
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
@@ -61,18 +71,18 @@ class MasterViewController: UITableViewController {
return cell
}
- override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
+ func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let button = UIButton(frame: .zero)
button.setTitle("RequestView", for: .normal)
button.backgroundColor = .red
- button.tag = section // why not.... ``\__(~_~)__/``
+ button.tag = section // why not... ``\__(~_~)__/``
button.addTarget(self, action: #selector(requestJSON), for: .touchUpInside)
return button
}
- override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
+ func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
@@ -83,20 +93,27 @@ class MasterViewController: UITableViewController {
@objc func requestJSON() {
- let requestParameters = MVMCoreRequestParameters(actionMap: [:])
- let errorLocation = (MVMCoreLoadHandler.sharedGlobal()?.errorLocation(forRequest: MVMCoreSessionTimeHandler.sharedSession(),
- pageType: "test",
- modules: ""))!
+ guard let ip = ipTextField.text else { return }
- requestParameters?.alternateBaseURL = URL(string: "http://127.0.0.1/v1/molecularResponse")
+ let requestParameters = MVMCoreRequestParameters(actionMap: [:])
+ let errorLocation = (MVMCoreLoadHandler.sharedGlobal()?.errorLocation(forRequest: MVMCoreSessionTimeHandler.sharedSession(), pageType: "stackTest", modules: ""))!
+
+ requestParameters?.alternateBaseURL = URL(string: "http://\(ip)/v1/molecularResponse")
MVMCoreDispatchUtility.performBlock(inBackground: {
MVMCoreLoadHandler.sharedGlobal()?.sendRequest(requestParameters!, locationForError: errorLocation, requestFinished: { json, error in
- if error != nil {
- // BAD
- } else {
- // GOOD
+ guard error == nil else { return }
+
+ do {
+ let data = try JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)
+ let convertedString = String(data: data, encoding: .utf8)
+
+ MVMCoreDispatchUtility.performSyncBlock(onMainThread: {
+ ((self.splitViewController?.viewControllers[1] as? UINavigationController)?.topViewController as? DetailViewController)?.textView.text = convertedString
+ })
+ } catch let myJSONError {
+ print(myJSONError)
}
})
})