Skip to content

Commit

Permalink
Users can now create Universally Tracked events
Browse files Browse the repository at this point in the history
  • Loading branch information
redsn0w422 committed Feb 18, 2017
1 parent c7c1ebd commit 9ce8422
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
Binary file not shown.
57 changes: 36 additions & 21 deletions HackIllinois: QR/AddViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,52 @@
//

import UIKit
import Alamofire
import SwiftyJSON

class AddViewController: BaseViewController {

@IBOutlet var nameField: UITextField!
@IBOutlet var durationField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
let preferences = UserDefaults.standard
if preferences.object(forKey: "session") != nil
{
self.login_session = preferences.object(forKey: "session") as! String
}
}


/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/


@IBAction func cancelButton(_ sender: Any) {
print("cancel")
self.dismiss(animated: true, completion: nil)
}
@IBAction func saveButton(_ sender: Any) {
print("save")
self.dismiss(animated: true, completion: nil)
let role = self.check_permissions(key: self.login_session)
print(role)
if role != "ADMIN" {
self.dismiss(animated: true)
return
}
let headers: HTTPHeaders = [
"Authorization": self.login_session
]
let parameters: Parameters = [
"name": nameField.text!,
"duration": durationField.text!
]
print(parameters)
Alamofire.request("https://api.hackillinois.org/v1/tracking", method: .post,
parameters: parameters, encoding: JSONEncoding.default,
headers: headers).validate().responseJSON { [weak self] response in
print(response)
switch response.result {
case .success:
self?.dismiss(animated: true)
case .failure:
// self?.displayAlert(title: "ERROR!", message: "Could not create new event")
self?.dismiss(animated: true)
}
}
}
}
34 changes: 31 additions & 3 deletions HackIllinois: QR/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="noT-k3-Ta6">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C68" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="noT-k3-Ta6">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand Down Expand Up @@ -116,7 +116,7 @@
</objects>
<point key="canvasLocation" x="1751.2" y="38.23088455772114"/>
</scene>
<!--Add View Controller-->
<!--New Event-->
<scene sceneID="dkz-WM-Zfq">
<objects>
<viewController id="3F4-SQ-gnG" customClass="AddViewController" customModule="HackIllinois__QR" customModuleProvider="target" sceneMemberID="viewController">
Expand All @@ -127,9 +127,33 @@
<view key="view" contentMode="scaleToFill" id="DYl-Fe-Cqg">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Name" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="GyF-Nw-rTP">
<rect key="frame" x="30" y="104" width="315" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Duration" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Sac-Z4-vMw">
<rect key="frame" x="30" y="151" width="315" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Sac-Z4-vMw" firstAttribute="leading" secondItem="DYl-Fe-Cqg" secondAttribute="leadingMargin" constant="14" id="0Og-Kt-tDU"/>
<constraint firstAttribute="trailingMargin" secondItem="Sac-Z4-vMw" secondAttribute="trailing" constant="14" id="0Ue-5s-nAp"/>
<constraint firstItem="Sac-Z4-vMw" firstAttribute="top" secondItem="GyF-Nw-rTP" secondAttribute="bottom" constant="17" id="1Uj-za-Hkx"/>
<constraint firstItem="Sac-Z4-vMw" firstAttribute="centerX" secondItem="DYl-Fe-Cqg" secondAttribute="centerX" id="6Sb-HY-btG"/>
<constraint firstItem="GyF-Nw-rTP" firstAttribute="leading" secondItem="DYl-Fe-Cqg" secondAttribute="leadingMargin" constant="14" id="E3t-CN-eaR"/>
<constraint firstItem="GyF-Nw-rTP" firstAttribute="top" secondItem="lc2-9j-zBJ" secondAttribute="bottom" constant="40" id="GLE-Sy-QHT"/>
<constraint firstItem="GyF-Nw-rTP" firstAttribute="centerX" secondItem="DYl-Fe-Cqg" secondAttribute="centerX" id="aLa-za-hCh"/>
<constraint firstAttribute="trailingMargin" secondItem="GyF-Nw-rTP" secondAttribute="trailing" constant="14" id="poU-lG-i1W"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="BZI-bG-e1f">
<navigationItem key="navigationItem" title="New Event" id="BZI-bG-e1f">
<barButtonItem key="leftBarButtonItem" systemItem="cancel" id="8Kp-ho-ibR">
<connections>
<action selector="cancelButton:" destination="3F4-SQ-gnG" id="PkO-SJ-oB8"/>
Expand All @@ -141,6 +165,10 @@
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="durationField" destination="Sac-Z4-vMw" id="aMT-qk-B7k"/>
<outlet property="nameField" destination="GyF-Nw-rTP" id="mh9-PS-eII"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="b7y-gr-5hB" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down

0 comments on commit 9ce8422

Please sign in to comment.