Permalink
Browse files

Hardcoded User again, GET Projects for each course

  • Loading branch information...
1 parent e35d717 commit 32e21cf4ec25aae8bf60720f389b11e4841a87eb @ardavis committed Feb 18, 2012
View
14 iSchoolManager.xcodeproj/project.pbxproj
@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
+ EB94757E14EDA266002ACF12 /* Project.m in Sources */ = {isa = PBXBuildFile; fileRef = EB94757D14EDA266002ACF12 /* Project.m */; };
+ EB94758E14EDA499002ACF12 /* ProjectsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EB94758D14EDA499002ACF12 /* ProjectsTableViewController.m */; };
EBCFF10614E6FEED00389E38 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EBCFF10514E6FEED00389E38 /* UIKit.framework */; };
EBCFF10814E6FEED00389E38 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EBCFF10714E6FEED00389E38 /* Foundation.framework */; };
EBCFF10A14E6FEED00389E38 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EBCFF10914E6FEED00389E38 /* CoreGraphics.framework */; };
@@ -65,6 +67,11 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
+ EB94757C14EDA266002ACF12 /* Project.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Project.h; sourceTree = "<group>"; };
+ EB94757D14EDA266002ACF12 /* Project.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Project.m; sourceTree = "<group>"; };
+ EB94757F14EDA2F5002ACF12 /* MyModels.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyModels.h; sourceTree = "<group>"; };
+ EB94758C14EDA498002ACF12 /* ProjectsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProjectsTableViewController.h; sourceTree = "<group>"; };
+ EB94758D14EDA499002ACF12 /* ProjectsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProjectsTableViewController.m; sourceTree = "<group>"; };
EBCFF10114E6FEED00389E38 /* iSchoolManager.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iSchoolManager.app; sourceTree = BUILT_PRODUCTS_DIR; };
EBCFF10514E6FEED00389E38 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
EBCFF10714E6FEED00389E38 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -158,6 +165,9 @@
EBCFF16314E7032D00389E38 /* CoursesTableViewController.m */,
EBCFF16714E73CF200389E38 /* AddCourseViewController.h */,
EBCFF16814E73CF200389E38 /* AddCourseViewController.m */,
+ EB94757F14EDA2F5002ACF12 /* MyModels.h */,
+ EB94758C14EDA498002ACF12 /* ProjectsTableViewController.h */,
+ EB94758D14EDA499002ACF12 /* ProjectsTableViewController.m */,
);
path = iSchoolManager;
sourceTree = "<group>";
@@ -178,6 +188,8 @@
children = (
EBCFF11D14E6FF3600389E38 /* Course.h */,
EBCFF11E14E6FF3600389E38 /* Course.m */,
+ EB94757C14EDA266002ACF12 /* Project.h */,
+ EB94757D14EDA266002ACF12 /* Project.m */,
);
name = Models;
sourceTree = "<group>";
@@ -299,6 +311,8 @@
EBCFF11F14E6FF3600389E38 /* Course.m in Sources */,
EBCFF16414E7032D00389E38 /* CoursesTableViewController.m in Sources */,
EBCFF16914E73CF300389E38 /* AddCourseViewController.m in Sources */,
+ EB94757E14EDA266002ACF12 /* Project.m in Sources */,
+ EB94758E14EDA499002ACF12 /* ProjectsTableViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN ...odeproj/project.xcworkspace/xcuserdata/ardavis.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
View
10 ...xcodeproj/project.xcworkspace/xcuserdata/ardavis.xcuserdatad/WorkspaceSettings.xcsettings
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IDEWorkspaceUserSettings_HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges</key>
+ <true/>
+ <key>IDEWorkspaceUserSettings_SnapshotAutomaticallyBeforeSignificantChanges</key>
+ <true/>
+</dict>
+</plist>
View
28 iSchoolManager.xcodeproj/xcuserdata/ardavis.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -17,5 +17,33 @@
landmarkName = "-objectLoader:didLoadObjects:"
landmarkType = "5">
</FileBreakpoint>
+ <FileBreakpoint
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ isPathRelative = "1"
+ filePath = "iSchoolManager/CoursesTableViewController.m"
+ timestampString = "350883230.202054"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "193"
+ endingLineNumber = "193"
+ landmarkName = "-tableView:commitEditingStyle:forRowAtIndexPath:"
+ landmarkType = "5">
+ </FileBreakpoint>
+ <FileBreakpoint
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ isPathRelative = "1"
+ filePath = "iSchoolManager/CoursesTableViewController.m"
+ timestampString = "351183256.846309"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "272"
+ endingLineNumber = "272"
+ landmarkName = "-prepareForSegue:sender:"
+ landmarkType = "5">
+ </FileBreakpoint>
</FileBreakpoints>
</Bucket>
View
53 iSchoolManager/AppDelegate.m
@@ -9,7 +9,7 @@
#import <RestKit/RestKit.h>
#import "AppDelegate.h"
#import "CoursesTableViewController.h"
-#import "Course.h"
+#import "MyModels.h"
@implementation AppDelegate
@@ -25,29 +25,62 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Enable automatic network activity indicator management
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
+
+#pragma mark - Reskit Mappings
+ // Incoming Mappings
+ RKObjectMapping *courseMapping = [RKObjectMapping mappingForClass:[Course class]];
+ RKObjectMapping *projectMapping = [RKObjectMapping mappingForClass:[Project class]];
+ // Outgoing Mappings
+ RKObjectMapping *courseSerializationMapping = [RKObjectMapping mappingForClass:[Course class]];
+ RKObjectMapping *projectSerializationMapping = [RKObjectMapping mappingForClass:[Project class]];
+
+#pragma mark - Restkit Course Setup
// Setup our incoming object mappings
- RKObjectMapping* courseMapping = [RKObjectMapping mappingForClass:[Course class]];
[courseMapping mapKeyPath:@"id" toAttribute:@"courseID"];
[courseMapping mapKeyPath:@"name" toAttribute:@"name"];
[courseMapping mapKeyPath:@"number" toAttribute:@"number"];
// Setup our outgoing object mapping
- RKObjectMapping *courseSerializationMapping = [RKObjectMapping
- mappingForClass:[Course class]];
[courseSerializationMapping mapKeyPath:@"courseID" toAttribute:@"id"];
[courseSerializationMapping mapKeyPath:@"name" toAttribute:@"name"];
[courseSerializationMapping mapKeyPath:@"number" toAttribute:@"number"];
- [objectManager.mappingProvider
- setSerializationMapping:courseSerializationMapping forClass:[Course class]];
-
// Register our mappings with the provider
[objectManager.mappingProvider setMapping:courseMapping forKeyPath:@""];
+ [objectManager.mappingProvider setSerializationMapping:courseSerializationMapping forClass:[Course class]];
+
+ // Routing
+ [objectManager.router routeClass:[Course class] toResourcePath:@"users/1/courses" forMethod:RKRequestMethodGET];
+ [objectManager.router routeClass:[Course class] toResourcePath:@"users/1/courses" forMethod:RKRequestMethodPOST];
+ [objectManager.router routeClass:[Course class] toResourcePath:@"users/1/courses/:courseID" forMethod:RKRequestMethodDELETE];
+
+
+#pragma mark - Restkit Project Setup
+ // Setup our incoming object mappings
+ [projectMapping mapKeyPath:@"id" toAttribute:@"projectID"];
+ [projectMapping mapKeyPath:@"course_id" toAttribute:@"courseID"];
+ [projectMapping mapKeyPath:@"title" toAttribute:@"title"];
+ [projectMapping mapKeyPath:@"description" toAttribute:@"desc"];
+ [projectMapping mapKeyPath:@"due_date" toAttribute:@"dueDate"];
+
+ [projectMapping mapRelationship:@"course" withMapping:courseMapping];
+
+ // Setup our outgoing mapping
+ [projectSerializationMapping mapKeyPath:@"projectID" toAttribute:@"id"];
+ [projectSerializationMapping mapKeyPath:@"courseID" toAttribute:@"course_id"];
+ [projectSerializationMapping mapKeyPath:@"title" toAttribute:@"title"];
+ [projectSerializationMapping mapKeyPath:@"desc" toAttribute:@"description"];
+ [projectSerializationMapping mapKeyPath:@"dueDate" toAttribute:@"due_date"];
+
+ // Register our mappings with the provider
+ [objectManager.mappingProvider setMapping:projectMapping forKeyPath:@"/projects"];
+ [objectManager.mappingProvider setSerializationMapping:projectSerializationMapping forClass:[Project class]];
- [objectManager.router routeClass:[Course class] toResourcePath:@"/courses" forMethod:RKRequestMethodGET];
- [objectManager.router routeClass:[Course class] toResourcePath:@"/courses" forMethod:RKRequestMethodPOST];
- [objectManager.router routeClass:[Course class] toResourcePath:@"/courses/:courseID" forMethod:RKRequestMethodDELETE];
+ // Routing
+ [objectManager.router routeClass:[Project class] toResourcePath:@"/projects" forMethod:RKRequestMethodGET];
+ [objectManager.router routeClass:[Project class] toResourcePath:@"/projects" forMethod:RKRequestMethodPOST];
+ [objectManager.router routeClass:[Project class] toResourcePath:@"/projects/:projectID" forMethod:RKRequestMethodDELETE];
return YES;
}
View
2 iSchoolManager/CoursesTableViewController.h
@@ -10,6 +10,8 @@
#import <RestKit/RestKit.h>
#import "AddCourseViewController.h"
+@class Course, Project;
+
@interface CoursesTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource, RKObjectLoaderDelegate>
- (IBAction)reloadCourses:(id)sender;
View
35 iSchoolManager/CoursesTableViewController.m
@@ -8,7 +8,7 @@
#import "CoursesTableViewController.h"
#import "AddCourseViewController.h"
-#import "Course.h"
+#import "MyModels.h"
#import <RestKit/RestKit.h>
@@ -112,14 +112,14 @@ - (void)loadCourses {
RKObjectManager* objectManager = [RKObjectManager sharedManager];
objectManager.client.baseURL = @"http://school_manager.dev";
- [objectManager loadObjectsAtResourcePath:@"/courses" delegate:self];
-// [objectManager loadObjectsAtResourcePath:@"/courses" delegate:self block:^(RKObjectLoader* loader) {
-// // School Manager returns statuses as a naked array in JSON, so we instruct the loader
-// // to user the appropriate object mapping
-// if ([objectManager.acceptMIMEType isEqualToString:RKMIMETypeJSON]) {
-// loader.objectMapping = [objectManager.mappingProvider objectMappingForClass:[Course class]];
-// }
-// }];
+// [objectManager loadObjectsAtResourcePath:@"/courses" delegate:self];
+ [objectManager loadObjectsAtResourcePath:@"/users/1/courses" delegate:self block:^(RKObjectLoader* loader) {
+ // School Manager returns courses as a naked array in JSON, so we instruct the loader
+ // to user the appropriate object mapping
+ if ([objectManager.acceptMIMEType isEqualToString:RKMIMETypeJSON]) {
+ loader.objectMapping = [objectManager.mappingProvider objectMappingForClass:[Course class]];
+ }
+ }];
}
#pragma mark - Table view data source
@@ -233,8 +233,8 @@ - (void)addCourseViewControllerDidFinish:(AddCourseViewController *)controller c
// Add the new course
[[RKObjectManager sharedManager] postObject:course delegate:self block:^(RKObjectLoader* loader) {
- loader.resourcePath = @"/users/23/courses";
- loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForKeyPath:@"/users/23/courses"];
+ loader.resourcePath = @"/users/1/courses";
+ loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForKeyPath:@"/users/1/courses"];
}];
}
@@ -252,13 +252,26 @@ - (void)addCourseViewControllerDidCancel:(AddCourseViewController *)controller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
+ // Get the index path of the tableView
+ NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
+
+ // Create a course based on what was clicked
+ Course *clicked = [self.courses objectAtIndex:indexPath.row];
+
+ NSLog(@"You clicked: %@, named: %@", clicked, clicked.name);
+
if ([[segue identifier] isEqualToString:@"ShowAddCourseView"])
{
// Get reference to the destination view controller
AddCourseViewController *vc = (AddCourseViewController *)[[[segue destinationViewController] viewControllers] objectAtIndex:0];
vc.delegate = self;
}
+ else if ([segue.destinationViewController respondsToSelector:@selector(setCourse:)])
+ {
+// [segue.destinationViewController performSelector:@selector(setCourse:) withObject:clicked];
+ [segue.destinationViewController setCourse:clicked];
+ }
}
- (void)reload
View
106 iSchoolManager/MainStoryboard.storyboard
@@ -10,7 +10,7 @@
<placeholder placeholderIdentifier="IBFirstResponder" id="8Zx-Lj-Lwe" userLabel="First Responder" sceneMemberID="firstResponder"/>
<tableViewController id="T4U-hk-agf" customClass="CoursesTableViewController" sceneMemberID="viewController">
<tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="JRt-ax-P0A">
- <rect key="frame" x="0.0" y="64" width="320" height="416"/>
+ <rect key="frame" x="0.0" y="64" width="320" height="372"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
@@ -38,29 +38,96 @@
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
+ <connections>
+ <segue destination="ipg-OI-ckA" kind="push" identifier="ShowProjectsForCourse" id="fWM-yj-Bfv"/>
+ </connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="T4U-hk-agf" id="QYl-WM-6fB"/>
<outlet property="delegate" destination="T4U-hk-agf" id="EUQ-t5-x4w"/>
</connections>
</tableView>
- <navigationItem key="navigationItem" title="Courses" id="ZXk-4e-KN4">
- <barButtonItem key="leftBarButtonItem" systemItem="refresh" id="Drc-7x-kl4">
+ <toolbarItems>
+ <barButtonItem systemItem="refresh" id="Drc-7x-kl4">
<connections>
<action selector="reloadCourses:" destination="T4U-hk-agf" id="1A6-sn-BFY"/>
</connections>
</barButtonItem>
- <barButtonItem key="rightBarButtonItem" systemItem="add" id="uj8-4p-Xep">
+ <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="I4s-bs-jYw"/>
+ <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="dw7-MD-qQD"/>
+ <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="CLf-Au-o7l"/>
+ <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="25J-A2-Mga"/>
+ <barButtonItem title="New Course" id="uj8-4p-Xep">
<connections>
<segue destination="dXX-nf-fGr" kind="modal" identifier="ShowAddCourseView" modalTransitionStyle="crossDissolve" id="aJJ-EB-fmo"/>
</connections>
</barButtonItem>
- </navigationItem>
+ </toolbarItems>
+ <navigationItem key="navigationItem" title="Courses" id="ZXk-4e-KN4"/>
+ <simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
</tableViewController>
</objects>
<point key="canvasLocation" x="822" y="-239"/>
</scene>
+ <scene sceneID="fwk-xa-5Fe">
+ <objects>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="HUB-fE-BP0" userLabel="First Responder" sceneMemberID="firstResponder"/>
+ <tableViewController id="ipg-OI-ckA" customClass="ProjectsTableViewController" sceneMemberID="viewController">
+ <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="Sl3-av-cfL">
+ <rect key="frame" x="0.0" y="64" width="320" height="372"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+ <prototypes>
+ <tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="ProjectCell" textLabel="L9X-4Q-3Y9" detailTextLabel="KZu-dc-bLZ" style="IBUITableViewCellStyleSubtitle" id="Tn4-wx-kj3">
+ <rect key="frame" x="0.0" y="22" width="320" height="44"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
+ <rect key="frame" x="0.0" y="0.0" width="300" height="43"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <subviews>
+ <label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="L9X-4Q-3Y9">
+ <rect key="frame" x="10" y="2" width="38" height="22"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+ </label>
+ <label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" text="Subtitle" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="KZu-dc-bLZ">
+ <rect key="frame" x="10" y="24" width="47" height="18"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <fontDescription key="fontDescription" type="system" pointSize="14"/>
+ <color key="textColor" red="0.50196078431372548" green="0.50196078431372548" blue="0.50196078431372548" alpha="1" colorSpace="calibratedRGB"/>
+ <color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+ </label>
+ </subviews>
+ <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
+ </view>
+ </tableViewCell>
+ </prototypes>
+ <connections>
+ <outlet property="dataSource" destination="ipg-OI-ckA" id="dg7-Kl-DvL"/>
+ <outlet property="delegate" destination="ipg-OI-ckA" id="92i-66-RVS"/>
+ </connections>
+ </tableView>
+ <toolbarItems>
+ <barButtonItem systemItem="refresh" id="Qpu-uf-Iv6">
+ <connections>
+ <action selector="reloadProjects:" destination="ipg-OI-ckA" id="PQO-Nf-Jmw"/>
+ </connections>
+ </barButtonItem>
+ <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="Ipu-JK-aZZ"/>
+ <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="0s1-uh-EMx"/>
+ <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="UUW-dv-ObJ"/>
+ <barButtonItem width="42" style="plain" systemItem="fixedSpace" id="fyV-Pq-Cmq"/>
+ <barButtonItem title="New Project" id="pMH-ii-gmg"/>
+ </toolbarItems>
+ <navigationItem key="navigationItem" title="Course Number" id="yVo-j4-V3G"/>
+ <simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
+ </tableViewController>
+ </objects>
+ <point key="canvasLocation" x="1296" y="-239"/>
+ </scene>
<scene sceneID="i4m-QI-BJZ">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="3vt-jZ-5vo" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -127,13 +194,17 @@
<scene sceneID="aAq-MI-GU6">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="PrU-lP-QPx" userLabel="First Responder" sceneMemberID="firstResponder"/>
- <navigationController id="Jt3-r6-Gqs" sceneMemberID="viewController">
+ <navigationController toolbarHidden="NO" id="Jt3-r6-Gqs" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="dPK-B0-nB8">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
+ <toolbar key="toolbar" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="ilf-kM-F6z">
+ <rect key="frame" x="0.0" y="436" width="320" height="44"/>
+ <autoresizingMask key="autoresizingMask"/>
+ </toolbar>
<connections>
<segue destination="T4U-hk-agf" kind="relationship" relationship="rootViewController" id="7cJ-XO-ILk"/>
</connections>
@@ -159,6 +230,29 @@
<point key="canvasLocation" x="1296" y="-833"/>
</scene>
</scenes>
+ <classes>
+ <class className="AddCourseViewController" superclassName="UIViewController">
+ <source key="sourceIdentifier" type="project" relativePath="./Classes/AddCourseViewController.h"/>
+ <relationships>
+ <relationship kind="action" name="cancel:"/>
+ <relationship kind="action" name="done:"/>
+ <relationship kind="outlet" name="inputCourseName" candidateClass="UITextField"/>
+ <relationship kind="outlet" name="inputCourseNumber" candidateClass="UITextField"/>
+ </relationships>
+ </class>
+ <class className="CoursesTableViewController" superclassName="UITableViewController">
+ <source key="sourceIdentifier" type="project" relativePath="./Classes/CoursesTableViewController.h"/>
+ <relationships>
+ <relationship kind="action" name="reloadCourses:"/>
+ </relationships>
+ </class>
+ <class className="ProjectsTableViewController" superclassName="UITableViewController">
+ <source key="sourceIdentifier" type="project" relativePath="./Classes/ProjectsTableViewController.h"/>
+ <relationships>
+ <relationship kind="action" name="reloadProjects:"/>
+ </relationships>
+ </class>
+ </classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
View
10 iSchoolManager/MyModels.h
@@ -0,0 +1,10 @@
+//
+// MyModels.h
+// iSchoolManager
+//
+// Created by Andrew Davis on 2/16/12.
+// Copyright (c) 2012 NASA. All rights reserved.
+//
+
+#import "Course.h"
+#import "Project.h"
View
25 iSchoolManager/Project.h
@@ -0,0 +1,25 @@
+//
+// Project.h
+// iSchoolManager
+//
+// Created by Andrew Davis on 2/16/12.
+// Copyright (c) 2012 NASA. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface Project : NSObject {
+ NSString* projectID;
+ NSString* courseID;
+ NSString* title;
+ NSString* desc;
+ NSString* dueDate;
+}
+
+@property (nonatomic, retain) NSString *projectID;
+@property (nonatomic, retain) NSString *courseID;
+@property (nonatomic, retain) NSString *title;
+@property (nonatomic, retain) NSString *desc;
+@property (nonatomic, retain) NSString *dueDate;
+
+@end
View
15 iSchoolManager/Project.m
@@ -0,0 +1,15 @@
+//
+// Project.m
+// iSchoolManager
+//
+// Created by Andrew Davis on 2/16/12.
+// Copyright (c) 2012 NASA. All rights reserved.
+//
+
+#import "Project.h"
+
+@implementation Project
+
+@synthesize projectID, courseID, title, desc, dueDate;
+
+@end
View
21 iSchoolManager/ProjectsTableViewController.h
@@ -0,0 +1,21 @@
+//
+// ProjectsTableViewController.h
+// iSchoolManager
+//
+// Created by Andrew Davis on 2/16/12.
+// Copyright (c) 2012 NASA. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import <RestKit/RestKit.h>
+
+@class Course, Project;
+
+@interface ProjectsTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource, RKObjectLoaderDelegate>
+
+- (IBAction)reloadProjects:(id)sender;
+
+@property (nonatomic, strong) NSMutableArray* projects;
+@property (nonatomic, strong) Course *course;
+
+@end
View
249 iSchoolManager/ProjectsTableViewController.m
@@ -0,0 +1,249 @@
+//
+// ProjectsTableViewController.m
+// iSchoolManager
+//
+// Created by Andrew Davis on 2/16/12.
+// Copyright (c) 2012 NASA. All rights reserved.
+//
+
+#import "ProjectsTableViewController.h"
+#import <RestKit/RestKit.h>
+#import "MyModels.h"
+
+@interface ProjectsTableViewController ()
+- (void)loadProjects;
+- (void)reload;
+@end
+
+@implementation ProjectsTableViewController
+
+@synthesize projects = _projects, course = _course;
+
+- (id)initWithStyle:(UITableViewStyle)style
+{
+ self = [super initWithStyle:style];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)didReceiveMemoryWarning
+{
+ // Releases the view if it doesn't have a superview.
+ [super didReceiveMemoryWarning];
+
+ // Release any cached data, images, etc that aren't in use.
+}
+
+#pragma mark - View lifecycle
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+
+ // Uncomment the following line to preserve selection between presentations.
+ // self.clearsSelectionOnViewWillAppear = NO;
+
+ // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+ // self.navigationItem.rightBarButtonItem = self.editButtonItem;
+}
+
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+- (void)viewWillAppear:(BOOL)animated
+{
+ [super viewWillAppear:animated];
+}
+
+- (void)viewDidAppear:(BOOL)animated
+{
+ [super viewDidAppear:animated];
+}
+
+- (void)viewWillDisappear:(BOOL)animated
+{
+ [super viewWillDisappear:animated];
+}
+
+- (void)viewDidDisappear:(BOOL)animated
+{
+ [super viewDidDisappear:animated];
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ // Return YES for supported orientations
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+- (void)loadView
+{
+ [super loadView];
+ [self loadProjects];
+}
+
+#pragma mark RKObjectLoaderDelegate methods
+
+- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
+ NSLog(@"Loaded payload: %@", [response bodyAsString]);
+}
+
+- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSMutableArray*)objects {
+ self.projects = objects;
+ for (int i = 0; i < self.projects.count; i++) {
+ Project *myProject = [self.projects objectAtIndex:i];
+ NSLog(@"Project #%i Title - %@", i, myProject.title);
+ NSLog(@"Project #%i Description - %@", i, myProject.desc);
+ NSLog(@"Project #%i ID - %@", i, myProject.projectID);
+ }
+ [self.tableView reloadData];
+
+}
+
+- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
+ UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [alert show];
+ NSLog(@"Hit error: %@", error);
+}
+
+- (void)loadProjects {
+
+ // Load the object model via RestKit
+ RKObjectManager* objectManager = [RKObjectManager sharedManager];
+ objectManager.client.baseURL = @"http://school_manager.dev";
+
+ // Setup the URL
+ NSLog(@"SELF.COURSE ID IS: %d", [[self.course courseID] intValue]);
+ NSString *url = [NSString stringWithFormat:@"/users/1/courses/%d/projects", [[self.course courseID] intValue]];
+
+ // [objectManager loadObjectsAtResourcePath:@"/courses" delegate:self];
+ [objectManager loadObjectsAtResourcePath:url delegate:self block:^(RKObjectLoader* loader) {
+
+ // School Manager returns projects as a naked array in JSON, so we instruct the loader
+ // to user the appropriate object mapping
+ if ([objectManager.acceptMIMEType isEqualToString:RKMIMETypeJSON]) {
+ loader.objectMapping = [objectManager.mappingProvider objectMappingForClass:[Project class]];
+ }
+ }];
+}
+
+#pragma mark - Table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+ // Return the number of sections.
+ return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ // Return the number of rows in the section.
+ return self.projects.count;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ static NSString *CellIdentifier = @"ProjectCell";
+
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ if (cell == nil) {
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
+ }
+
+ // Configure the cell...
+ Project *project = (Project *)[self.projects objectAtIndex:indexPath.row];
+
+ static NSDateFormatter *formatter = nil;
+
+ if (formatter == nil) {
+ formatter = [[NSDateFormatter alloc] init];
+ [formatter setDateStyle:NSDateFormatterMediumStyle];
+ }
+ [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
+
+ NSDate *date = [formatter dateFromString:project.dueDate];
+ [formatter setDateFormat:@"E, MMM dd 'at' h:mm a"]; // Mon, Feb 20 at 3:35 PM
+
+
+ cell.textLabel.text = project.title;
+ cell.detailTextLabel.text = [formatter stringFromDate:date];
+
+ return cell;
+}
+
+/*
+// Override to support conditional editing of the table view.
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the specified item to be editable.
+ return YES;
+}
+*/
+
+/*
+// Override to support editing the table view.
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ // Delete the row from the data source
+ [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
+ }
+ else if (editingStyle == UITableViewCellEditingStyleInsert) {
+ // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
+ }
+}
+*/
+
+/*
+// Override to support rearranging the table view.
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
+{
+}
+*/
+
+/*
+// Override to support conditional rearranging of the table view.
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Return NO if you do not want the item to be re-orderable.
+ return YES;
+}
+*/
+
+#pragma mark - Table view delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Navigation logic may go here. Create and push another view controller.
+ /*
+ <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
+ // ...
+ // Pass the selected object to the new view controller.
+ [self.navigationController pushViewController:detailViewController animated:YES];
+ */
+}
+
+#pragma mark course
+
+- (void)setCourse:(Course *)course {
+ _course = course;
+ self.title = course.number;
+}
+
+- (IBAction)reloadProjects:(id)sender {
+ [self reload];
+}
+
+- (void)reload
+{
+ [self loadProjects];
+ [self.tableView reloadData];
+}
+
+@end

0 comments on commit 32e21cf

Please sign in to comment.