Skip to content

Commit

Permalink
Huge update: switch endpoints, get different resource types
Browse files Browse the repository at this point in the history
# Conflicts:
#	SoF-MedList/AppDelegate.swift
#	Swift-SMART
  • Loading branch information
p2 committed Dec 15, 2016
1 parent 546c9d6 commit 1ac8430
Show file tree
Hide file tree
Showing 48 changed files with 1,289 additions and 631 deletions.
68 changes: 68 additions & 0 deletions App/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// AppDelegate.swift
// SoF-MedList
//
// Created by Pascal Pfiffner on 6/20/14.
// Copyright (c) 2014 SMART Platforms. All rights reserved.
//

import UIKit
import SMART


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

var endpointProvider = EndpointProvider()

func application(_ app: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool {
let splitViewController = self.window!.rootViewController as! UISplitViewController
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.endIndex-1] as! UINavigationController
splitViewController.delegate = navigationController.topViewController as! DetailViewController

// SMART tint color
window?.tintColor = UIColor(red:0.41, green:0.14, blue:0.44, alpha:1.0)

// configured endpoints
endpointProvider.endpoints = configuredEndpoints()

let masterNavi = splitViewController.viewControllers[splitViewController.viewControllers.startIndex] as! UINavigationController
let master = masterNavi.topViewController as! MasterViewController
master.endpointProvider = endpointProvider

return true
}

// You need this for Safari and Safari Web View Controller to work
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
guard let smart = endpointProvider.activeEndpoint?.client else {
window?.rootViewController?.show(error: AppError.noActiveEndpoint, title: "Not Set Up")
return false
}
if smart.awaitingAuthCallback {
return smart.didRedirect(to: url)
}
return false
}
}


enum AppError: Error, CustomStringConvertible {
case noEndpointProvider
case noActiveEndpoint
case noPatientSelected

var description: String {
switch self {
case .noEndpointProvider:
return "No endpoint provider is present, cannot continue"
case .noActiveEndpoint:
return "No endpoint (server) has been selected yet, please do that first"
case .noPatientSelected:
return "No patient has been selected, please do that first"
}
}
}

176 changes: 176 additions & 0 deletions App/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="H1p-Uh-vWS">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<scene sceneID="pY4-Hu-kfo">
<objects>
<navigationController id="RMx-3f-FxP" sceneMemberID="viewController">
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="Pmd-2v-anx">
<rect key="frame" x="0.0" y="0.0" width="1000" height="1000"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="7bK-jq-Zjz" kind="relationship" relationship="rootViewController" id="tsl-Nk-0bq"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="8fS-aE-onr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="9" y="-657"/>
</scene>
<!--Detail-->
<scene sceneID="yUG-lL-AsK">
<objects>
<viewController title="Detail" id="JEX-9P-axG" customClass="DetailViewController" customModule="SoF_Demo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="SYR-Wa-9uf"/>
<viewControllerLayoutGuide type="bottom" id="GAO-Cl-Wes"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="svH-Pt-448">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QMk-9X-Eql">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<subviews>
<view contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" translatesAutoresizingMaskIntoConstraints="NO" id="dpb-3y-FCS">
<rect key="frame" x="0.0" y="0.0" width="375" height="20"/>
<subviews>
<label clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="" lineBreakMode="clip" numberOfLines="0" minimumScaleFactor="0.59999999999999998" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0XM-y9-sOw">
<rect key="frame" x="16" y="8" width="351" height="0.0"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="0XM-y9-sOw" secondAttribute="trailingMargin" id="I2p-pe-NDu"/>
<constraint firstItem="0XM-y9-sOw" firstAttribute="top" secondItem="dpb-3y-FCS" secondAttribute="topMargin" id="gAb-sc-L4M"/>
<constraint firstItem="0XM-y9-sOw" firstAttribute="leading" secondItem="dpb-3y-FCS" secondAttribute="leadingMargin" id="j1j-CM-acL"/>
<constraint firstAttribute="bottomMargin" secondItem="0XM-y9-sOw" secondAttribute="bottomMargin" constant="12" id="y47-38-7cL"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="dpb-3y-FCS" secondAttribute="bottom" id="2rs-Kf-b0G"/>
<constraint firstItem="dpb-3y-FCS" firstAttribute="top" secondItem="QMk-9X-Eql" secondAttribute="top" id="fuh-XH-bdL"/>
<constraint firstItem="dpb-3y-FCS" firstAttribute="leading" secondItem="QMk-9X-Eql" secondAttribute="leading" id="qB0-Lx-SsX"/>
<constraint firstAttribute="trailing" secondItem="dpb-3y-FCS" secondAttribute="trailing" id="u4h-lu-Kty"/>
</constraints>
</scrollView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="dpb-3y-FCS" firstAttribute="width" secondItem="svH-Pt-448" secondAttribute="width" id="LPc-OU-T7n"/>
<constraint firstAttribute="trailing" secondItem="QMk-9X-Eql" secondAttribute="trailing" id="T8V-zY-ycs"/>
<constraint firstItem="QMk-9X-Eql" firstAttribute="top" secondItem="svH-Pt-448" secondAttribute="top" id="Vhw-Qh-xwd"/>
<constraint firstItem="GAO-Cl-Wes" firstAttribute="top" secondItem="QMk-9X-Eql" secondAttribute="bottom" id="h4U-1M-NJA"/>
<constraint firstItem="QMk-9X-Eql" firstAttribute="leading" secondItem="svH-Pt-448" secondAttribute="leading" id="oCh-cX-1Ge"/>
</constraints>
</view>
<toolbarItems/>
<navigationItem key="navigationItem" title="Resource JSON" id="mOI-FS-AaM"/>
<splitViewDetailSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="detailDescriptionLabel" destination="0XM-y9-sOw" id="deQ-Na-JPF"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="FJe-Yq-33r" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="765.60000000000002" y="54.422788605697157"/>
</scene>
<!--Split View Controller-->
<scene sceneID="Nki-YV-4Qg">
<objects>
<splitViewController id="H1p-Uh-vWS" sceneMemberID="viewController">
<toolbarItems/>
<connections>
<segue destination="RMx-3f-FxP" kind="relationship" relationship="masterViewController" id="BlO-5A-QYV"/>
<segue destination="vC3-pB-5Vb" kind="relationship" relationship="detailViewController" id="Tll-UG-LXB"/>
</connections>
</splitViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="cZU-Oi-B1e" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-779" y="-319"/>
</scene>
<!--Resources-->
<scene sceneID="smW-Zh-WAh">
<objects>
<tableViewController title="Resources" clearsSelectionOnViewWillAppear="NO" id="7bK-jq-Zjz" customClass="MasterViewController" customModule="SoF_Demo" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="r7i-6Z-zg0">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<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" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="Arm-wq-HPj" detailTextLabel="pST-Fl-wRu" style="IBUITableViewCellStyleValue1" id="WCw-Qf-5nD">
<rect key="frame" x="0.0" y="22" width="375" 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="342" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Arm-wq-HPj">
<rect key="frame" x="15" y="11" width="34" height="21"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="pST-Fl-wRu">
<rect key="frame" x="296" y="11" width="44" height="21"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</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="Title" id="Eg3-Nk-sE7">
<barButtonItem key="rightBarButtonItem" systemItem="bookmarks" id="hiv-Dm-I1C">
<connections>
<action selector="selectEndpoint:" destination="7bK-jq-Zjz" id="RmO-wv-GXR"/>
</connections>
</barButtonItem>
</navigationItem>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Rux-fX-hf1" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="766" y="-657"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="r7l-gg-dq7">
<objects>
<navigationController id="vC3-pB-5Vb" sceneMemberID="viewController">
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="DjV-YW-jjY">
<rect key="frame" x="0.0" y="0.0" width="1000" height="1000"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="JEX-9P-axG" kind="relationship" relationship="rootViewController" id="GKi-kA-LjT"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="SLD-UC-DBI" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="9" y="54"/>
</scene>
</scenes>
</document>
32 changes: 32 additions & 0 deletions App/Bundle+Utilities.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Bundle+Utilities.swift
// SoF-MedList
//
// Created by Pascal Pfiffner on 12/3/16.
// Copyright © 2016 SMART Platforms. All rights reserved.
//

import SMART


extension SMART.Bundle {

/**
Loop over the Bundle's `entry` and return all resources of the desired type.

Note: This does only work when passing in hardcoded types, if passing in `T.Type` from some other classes' property always simply checks
against `Resource`.
*/
func entries<T: Resource>(ofType type: T.Type) -> [T]? {
//print("===> Filtering for type \(T.self) [\(T.resourceType)]")
return entry?.filter() { return $0.resource is T }.map() { return $0.resource as! T }
}

/**
Workaround for the issue mentioned in `entries(ofType:)` - checks against the string representation in `T.Type.resourceType`.
*/
func entries<T: Resource>(ofType type: T.Type, typeName name: String) -> [Resource]? {
//print("===> Filtering for type \(T.self) [\(name)]")
return entry?.filter() { return nil != $0.resource && type(of: $0.resource!).resourceType == name }.map() { return $0.resource! }
}
}
Loading

0 comments on commit 1ac8430

Please sign in to comment.