Updated the master VC. logic to query molecular server.
This commit is contained in:
parent
ac38e271bc
commit
85f1da00d8
@ -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 */,
|
||||
);
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</navigationBar>
|
||||
<connections>
|
||||
<segue destination="7bK-jq-Zjz" kind="relationship" relationship="rootViewController" id="tsl-Nk-0bq"/>
|
||||
<segue destination="d7m-B4-a2J" kind="relationship" relationship="rootViewController" id="U56-ta-dWF"/>
|
||||
</connections>
|
||||
</navigationController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="8fS-aE-onr" sceneMemberID="firstResponder"/>
|
||||
@ -57,45 +57,73 @@
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-856" y="-330"/>
|
||||
</scene>
|
||||
<!--Master-->
|
||||
<scene sceneID="smW-Zh-WAh">
|
||||
<!--Master View Controller-->
|
||||
<scene sceneID="dks-EJ-Tgi">
|
||||
<objects>
|
||||
<tableViewController title="Master" clearsSelectionOnViewWillAppear="NO" id="7bK-jq-Zjz" customClass="MasterViewController" customModule="JSONCreator" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="r7i-6Z-zg0">
|
||||
<viewController id="d7m-B4-a2J" customClass="MasterViewController" customModule="JSONCreator" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="g4x-9a-zZX">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<prototypes>
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="Arm-wq-HPj" style="IBUITableViewCellStyleDefault" id="WCw-Qf-5nD">
|
||||
<rect key="frame" x="0.0" y="28" width="414" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="WCw-Qf-5nD" id="37f-cq-3Eg">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Arm-wq-HPj">
|
||||
<rect key="frame" x="20" y="0.0" width="374" height="43.5"/>
|
||||
<subviews>
|
||||
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="4Uk-eQ-EQn">
|
||||
<rect key="frame" x="0.0" y="146" width="414" height="716"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" textLabel="t3y-r5-cMH" style="IBUITableViewCellStyleDefault" id="k2y-BR-khS">
|
||||
<rect key="frame" x="0.0" y="28" width="414" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="k2y-BR-khS" id="NRL-rD-eae">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</label>
|
||||
</subviews>
|
||||
</tableViewCellContentView>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
<sections/>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="7bK-jq-Zjz" id="Gho-Na-rnu"/>
|
||||
<outlet property="delegate" destination="7bK-jq-Zjz" id="RA6-mI-bju"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
<navigationItem key="navigationItem" title="Master" id="Zdf-7t-Un8"/>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="Rux-fX-hf1" sceneMemberID="firstResponder"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="t3y-r5-cMH">
|
||||
<rect key="frame" x="20" y="0.0" width="374" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
</tableView>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="IP:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="SXL-ds-O0O">
|
||||
<rect key="frame" x="20" y="101.5" width="18.5" height="19.5"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="16"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Enter IP" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="8ES-JF-wQQ">
|
||||
<rect key="frame" x="46.5" y="96" width="347.5" height="30"/>
|
||||
<nil key="textColor"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="numbersAndPunctuation" returnKeyType="done" smartDashesType="no" smartInsertDeleteType="no" smartQuotesType="no" textContentType="url"/>
|
||||
</textField>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstItem="4Uk-eQ-EQn" firstAttribute="bottom" secondItem="sWB-DD-mBr" secondAttribute="bottom" id="1EE-Zt-vT1"/>
|
||||
<constraint firstItem="sWB-DD-mBr" firstAttribute="trailing" secondItem="8ES-JF-wQQ" secondAttribute="trailing" constant="20" id="5Nc-rO-Na3"/>
|
||||
<constraint firstItem="4Uk-eQ-EQn" firstAttribute="leading" secondItem="sWB-DD-mBr" secondAttribute="leading" id="5h4-de-VEb"/>
|
||||
<constraint firstItem="8ES-JF-wQQ" firstAttribute="centerY" secondItem="SXL-ds-O0O" secondAttribute="centerY" id="62j-61-bE9"/>
|
||||
<constraint firstItem="4Uk-eQ-EQn" firstAttribute="top" secondItem="8ES-JF-wQQ" secondAttribute="bottom" constant="20" id="A4e-rm-tbe"/>
|
||||
<constraint firstItem="8ES-JF-wQQ" firstAttribute="leading" secondItem="SXL-ds-O0O" secondAttribute="trailing" constant="8" id="AL1-Zm-i3c"/>
|
||||
<constraint firstItem="sWB-DD-mBr" firstAttribute="trailing" secondItem="4Uk-eQ-EQn" secondAttribute="trailing" id="DhH-Gw-OdP"/>
|
||||
<constraint firstItem="SXL-ds-O0O" firstAttribute="leading" secondItem="sWB-DD-mBr" secondAttribute="leading" constant="20" id="FIo-Dp-pZs"/>
|
||||
<constraint firstItem="8ES-JF-wQQ" firstAttribute="top" secondItem="sWB-DD-mBr" secondAttribute="top" constant="8" id="aPy-EJ-zp5"/>
|
||||
</constraints>
|
||||
<viewLayoutGuide key="safeArea" id="sWB-DD-mBr"/>
|
||||
</view>
|
||||
<navigationItem key="navigationItem" id="QQY-EX-HwK"/>
|
||||
<connections>
|
||||
<outlet property="ipTextField" destination="8ES-JF-wQQ" id="ngi-c0-NuP"/>
|
||||
<outlet property="tableView" destination="4Uk-eQ-EQn" id="l5E-2O-dib"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="0Mf-nP-reG" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="709" y="-630"/>
|
||||
<point key="canvasLocation" x="708.69565217391312" y="-630.13392857142856"/>
|
||||
</scene>
|
||||
<!--Navigation Controller-->
|
||||
<scene sceneID="r7l-gg-dq7">
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user