diff --git a/JSONCreator_iOS/JSONCreator.xcodeproj/project.pbxproj b/JSONCreator_iOS/JSONCreator.xcodeproj/project.pbxproj index d96f4e0..9a77bbf 100644 --- a/JSONCreator_iOS/JSONCreator.xcodeproj/project.pbxproj +++ b/JSONCreator_iOS/JSONCreator.xcodeproj/project.pbxproj @@ -21,7 +21,6 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ - 0AE3D04E2303009C00B844C7 /* QueryServerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE3D04D2303009C00B844C7 /* QueryServerCell.swift */; }; D2B1E3F322F4A68F0065F95C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2B1E3F222F4A68F0065F95C /* AppDelegate.swift */; }; D2B1E3F522F4A68F0065F95C /* MasterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2B1E3F422F4A68F0065F95C /* MasterViewController.swift */; }; D2B1E3F722F4A68F0065F95C /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2B1E3F622F4A68F0065F95C /* DetailViewController.swift */; }; @@ -54,7 +53,6 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 0AE3D04D2303009C00B844C7 /* QueryServerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryServerCell.swift; sourceTree = ""; }; D2B1E3EF22F4A68F0065F95C /* JSONCreator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JSONCreator.app; sourceTree = BUILT_PRODUCTS_DIR; }; D2B1E3F222F4A68F0065F95C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; D2B1E3F422F4A68F0065F95C /* MasterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterViewController.swift; sourceTree = ""; }; @@ -111,7 +109,6 @@ D2B1E3FB22F4A6930065F95C /* Assets.xcassets */, D2B1E3FD22F4A6930065F95C /* LaunchScreen.storyboard */, D2B1E40022F4A6930065F95C /* Info.plist */, - 0AE3D04D2303009C00B844C7 /* QueryServerCell.swift */, ); path = JSONCreator; sourceTree = ""; @@ -226,7 +223,6 @@ buildActionMask = 2147483647; files = ( D2B1E3F722F4A68F0065F95C /* DetailViewController.swift in Sources */, - 0AE3D04E2303009C00B844C7 /* QueryServerCell.swift in Sources */, D2B1E3F522F4A68F0065F95C /* MasterViewController.swift in Sources */, D2B1E3F322F4A68F0065F95C /* AppDelegate.swift in Sources */, ); diff --git a/JSONCreator_iOS/JSONCreator/AppDelegate.swift b/JSONCreator_iOS/JSONCreator/AppDelegate.swift index 8c3217b..0542ff1 100644 --- a/JSONCreator_iOS/JSONCreator/AppDelegate.swift +++ b/JSONCreator_iOS/JSONCreator/AppDelegate.swift @@ -34,10 +34,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele // Override point for customization after application launch. let splitViewController = window!.rootViewController as! UISplitViewController - let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController + let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count - 1] as! UINavigationController navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem splitViewController.delegate = self splitViewController.preferredDisplayMode = .allVisible + return true } @@ -66,9 +67,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele // MARK: - Split view func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool { - guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false } - guard let _ = secondaryAsNavController.topViewController as? DetailViewController else { return false } + + guard let secondaryAsNavController = secondaryViewController as? UINavigationController, + let _ = secondaryAsNavController.topViewController as? DetailViewController + else { return false } + return false } - + } diff --git a/JSONCreator_iOS/JSONCreator/DetailViewController.swift b/JSONCreator_iOS/JSONCreator/DetailViewController.swift index 81222f8..8a6a0de 100644 --- a/JSONCreator_iOS/JSONCreator/DetailViewController.swift +++ b/JSONCreator_iOS/JSONCreator/DetailViewController.swift @@ -11,9 +11,16 @@ import MVMCoreUI class DetailViewController: UIViewController { - + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + let textView = UITextView(frame: .zero) + //-------------------------------------------------- + // MARK: - Lifecycle + //-------------------------------------------------- + override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. @@ -37,6 +44,10 @@ class DetailViewController: UIViewController { navigationItem.setRightBarButtonItems([shareButton, buildButton], animated: true) } + //-------------------------------------------------- + // MARK: - Methods + //-------------------------------------------------- + func showError(_ error: NSError) { let alert = UIAlertController(title: "Error", message: "\(error)", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) @@ -77,6 +88,7 @@ class DetailViewController: UIViewController { } } +// MARK:- TextView Delegate extension DetailViewController: UITextViewDelegate { func textViewShouldEndEditing(_ textView: UITextView) -> Bool { guard textView.text.count > 0 else { diff --git a/JSONCreator_iOS/JSONCreator/MasterViewController.swift b/JSONCreator_iOS/JSONCreator/MasterViewController.swift index 7de0206..baa2a76 100644 --- a/JSONCreator_iOS/JSONCreator/MasterViewController.swift +++ b/JSONCreator_iOS/JSONCreator/MasterViewController.swift @@ -11,9 +11,16 @@ import MVMCore class MasterViewController: UITableViewController { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- let folderPath = Bundle.main.resourcePath! + "/JSON" + //-------------------------------------------------- + // MARK: - Life Cycle + //-------------------------------------------------- + override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. @@ -22,7 +29,9 @@ class MasterViewController: UITableViewController { tableView.rowHeight = UITableView.automaticDimension } + //-------------------------------------------------- // MARK: - Table View + //-------------------------------------------------- override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return try? FileManager.default.contentsOfDirectory(atPath: folderPath)[section] @@ -34,33 +43,33 @@ class MasterViewController: UITableViewController { override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - if section == 0 { - return try! FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath)[section]).count + 1 - } - return try! FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath)[section]).count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - - - if indexPath.section == 0 { - guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? QueryServerCell else { return UITableViewCell() } - cell.requestServer = requestJSON - return cell - - } else { + let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) - let name = try! FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath)[indexPath.section])[indexPath.row] + let name = try? FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath)[indexPath.section])[indexPath.row] cell.textLabel?.text = name if cell.interactions.first == nil { let dragInteraction = UIDragInteraction(delegate: self) cell.addInteraction(dragInteraction) } + return cell - } + } + + override 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.addTarget(self, action: #selector(requestJSON), for: .touchUpInside) + + return button } override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { @@ -68,6 +77,10 @@ class MasterViewController: UITableViewController { return true } + //-------------------------------------------------- + // MARK: - Methods + //-------------------------------------------------- + @objc func requestJSON() { let requestParameters = MVMCoreRequestParameters(actionMap: [:]) @@ -75,29 +88,34 @@ class MasterViewController: UITableViewController { pageType: "test", modules: ""))! + requestParameters?.alternateBaseURL = URL(string: "http://127.0.0.1/v1/molecularResponse") + MVMCoreDispatchUtility.performBlock(inBackground: { - MVMCoreLoadHandler.sharedGlobal()?.sendRequest(requestParameters!, locationForError: errorLocation, requestFinished: { json, error in if error != nil { // BAD } else { - // GOOD + // GOOD } }) }) } } +// MARK:- Drag Interaction Delegate extension MasterViewController: UIDragInteractionDelegate { + func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] { + let location = session.location(in: tableView) let indexPath = tableView.indexPathForRow(at: location) let sectionName = try! FileManager.default.contentsOfDirectory(atPath: folderPath)[indexPath!.section] let path = try! folderPath + "/" + sectionName + "/" + FileManager.default.contentsOfDirectory(atPath: folderPath + "/" + sectionName)[indexPath!.row] - let content = try! String.init(contentsOfFile: path) + let content = try! String(contentsOfFile: path) let provider = NSItemProvider(object: content as NSString) let item = UIDragItem(itemProvider: provider) + return [item] } } diff --git a/JSONCreator_iOS/JSONCreator/QueryServerCell.swift b/JSONCreator_iOS/JSONCreator/QueryServerCell.swift deleted file mode 100644 index 544349c..0000000 --- a/JSONCreator_iOS/JSONCreator/QueryServerCell.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// QueryServerCell.swift -// JSONCreator -// -// Created by Kevin Christiano on 8/13/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import UIKit - - -class QueryServerCell: UITableViewCell { - - var requestServer: (()->())? - - override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - - let button = UIButton(frame: .zero) - button.setTitle("RequestView", for: .normal) - button.backgroundColor = .yellow - button.addTarget(self, action: #selector(requestJSON), for: .touchUpInside) - contentView.addSubview(button) - NSLayoutConstraint.pinView(toSuperview: button, useMargins: true) - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - @objc func requestJSON() { - - requestServer?() - } -}