Skip to content

Commit

Permalink
Menu is now pulled from ep2
Browse files Browse the repository at this point in the history
  • Loading branch information
ebaizel committed Dec 10, 2013
1 parent 0c31e84 commit 0b3647c
Show file tree
Hide file tree
Showing 15 changed files with 400 additions and 30 deletions.
1 change: 1 addition & 0 deletions PLConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "PLConnection.h"
#import "PLMenuItem.h"

static NSMutableArray *sharedConnectionList = nil;

Expand Down
21 changes: 21 additions & 0 deletions PLMenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// PLMenu.h
// Plate
//
// Created by emileleon on 12/10/13.
// Copyright (c) 2013 Plate SF. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "JSONSerializable.h"

@interface PLMenu : NSObject <JSONSerializable>

@property (nonatomic, strong) NSMutableArray *mains;
@property (nonatomic, strong) NSMutableArray *sides;
@property (nonatomic, strong) NSMutableArray *addons;
@property (nonatomic, strong) NSString *location;
@property (nonatomic, strong) NSDate *menuDate;


@end
63 changes: 63 additions & 0 deletions PLMenu.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// PLMenu.m
// Plate
//
// Created by emileleon on 12/10/13.
// Copyright (c) 2013 Plate SF. All rights reserved.
//

#import "PLMenu.h"
#import "PLMenuItem.h"

@implementation PLMenu

@synthesize mains, sides, addons, location, menuDate;

-(void)readFromJSONDictionary:(NSDictionary *)d
{
NSDictionary *response = [d objectForKey:@"response"];
NSDictionary *mainModifiers = [response valueForKeyPath:@"3.modifiers"];
if (mainModifiers) {

if (!mains) {
mains = [[NSMutableArray alloc]init];
}

for (NSString *key in mainModifiers) {

NSLog(@"key is %@", key);
NSDictionary *mainModifier = [mainModifiers objectForKey:key];
NSDictionary *mainItem = [mainModifier objectForKey:@"meta"];

PLMenuItem *plmi = [[PLMenuItem alloc] init];
[plmi setName:[mainModifier objectForKey:@"name"]];
// ### UNCOMMENT BELOW WHEN META IS WORKING
// [plmi setName:[mainItem objectForKey:@"name"]];
// [plmi setDescription:[mainItem objectForKey:@"description"]];
// [plmi setAllergies:[mainItem objectForKey:@"alergies"]];
// [plmi setIsGlutenFree:[[mainItem objectForKey:@"is_gluten_free"] boolValue]];
// [plmi setIsVegan:[[mainItem objectForKey:@"is_vegan"] boolValue]];
// [plmi setIsVegetarian:[[mainItem objectForKey:@"is_vegetarian"] boolValue]];

[mains addObject:plmi];
}
}

NSDictionary *sideModifiers = [response valueForKeyPath:@"4.modifiers"];
if (sideModifiers) {

if (!sides) {
sides = [[NSMutableArray alloc]init];
}

for (NSString *key in sideModifiers) {
NSDictionary *sideItem = [sideModifiers objectForKey:key];
PLMenuItem *plmi = [[PLMenuItem alloc] init];
[plmi setName:[sideItem objectForKey:@"name"]];
[sides addObject:plmi];
}
}

}

@end
5 changes: 5 additions & 0 deletions PLMenuItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ typedef enum {

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *plateId;
@property (nonatomic, strong) NSString *description;
@property (nonatomic, strong) NSString *allergies;
@property (assign) BOOL isGlutenFree;
@property (assign) BOOL isVegan;
@property (assign) BOOL isVegetarian;

-(id)initWithName:(NSString *)itemName itemType:(int)type;

Expand Down
6 changes: 4 additions & 2 deletions PLMenuItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

@implementation PLMenuItem

@synthesize name, plateId, description, allergies, isGlutenFree, isVegan, isVegetarian;

-(void)readFromJSONDictionary:(NSDictionary *)d
{
[self setName:@"Menu Item Name"];
//TODO: parse the json into the object
[self setName:[d objectForKey:@"meta.name"]];

}

-(id)initWithName:(NSString *)itemName itemType:(int)type
Expand Down
6 changes: 4 additions & 2 deletions PLPlateStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
//

#import <Foundation/Foundation.h>
#import "PLMenu.h"

@interface PLPlateStore : NSObject
{
NSArray *mainDishes;
PLMenu *menu;
}

+ (PLPlateStore *)sharedStore;
- (void)getMains:(void (^)(NSArray *mains, NSError *err))block;
- (void)clearCache;
- (void)getMenu:(void (^)(PLMenu *menuResult, NSError *err))block;


@end
38 changes: 25 additions & 13 deletions PLPlateStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,40 @@
#import "PLPlateStore.h"
#import "PLMenuItem.h"
#import "PLConnection.h"
#import "PLMenu.h"

@implementation PLPlateStore

- (void) getMains:(void (^)(NSArray *mains, NSError *err))block
- (void) getMenu:(void (^)(PLMenu *menuResult, NSError *err))block
{
if (mainDishes) {
block(mainDishes, nil);
if (menu) {
block(menu, nil);
} else {

NSMutableArray *results = [[NSMutableArray alloc]init];
[results addObject:[[PLMenuItem alloc]initWithName:@"Pan Seared Chilean Sea Bass" itemType:MenuItemMain]];
[results addObject:[[PLMenuItem alloc]initWithName:@"Kung Pao Chicken" itemType:MenuItemMain]];
[results addObject:[[PLMenuItem alloc]initWithName:@"Peking Duck" itemType:MenuItemMain]];
[results addObject:[[PLMenuItem alloc]initWithName:@"Fire Roasted Tofu" itemType:MenuItemMain]];
[results addObject:[[PLMenuItem alloc]initWithName:@"Golden Quinoa Dumplings" itemType:MenuItemMain]];

mainDishes = results;

block(results, nil);
NSURL *url = [NSURL URLWithString:@"http://ep2.gulosolutions.com/menus/get_modifiers/1"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];

PLMenu *menuRootObject = [[PLMenu alloc]init];
PLConnection *connect = [[PLConnection alloc]initWithRequest:req];
[connect setJsonRootObject:menuRootObject];

[connect setCompletionBlock:^(PLMenu *menuConnectResult, NSError *err) {
if (!err) {
menu = menuConnectResult;
block(menuConnectResult, nil);
} else {
block(nil, err);
}
}];
[connect start];
}
}

- (void)clearCache
{
menu = nil;
}

+ (PLPlateStore *)sharedStore
{
static PLPlateStore *sharedStore = nil;
Expand Down
3 changes: 1 addition & 2 deletions PLSelectMainsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
{
NSArray *mains;
}
@property (weak, nonatomic) IBOutlet UITableView *tableMains;
@property (nonatomic, weak) IBOutlet UITableView *tableMains;
@property (nonatomic, strong) PLSelectSidesViewController *sidesController;
//@property (nonatomic, strong) NSArray *mains;
@end
16 changes: 9 additions & 7 deletions PLSelectMainsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "PLSelectMainsViewController.h"
#import "PLSelectSidesViewController.h"
#import "PLPlateStore.h"
#import "PLMenu.h"

@interface PLSelectMainsViewController ()

Expand Down Expand Up @@ -72,13 +73,15 @@ - (void)fetchMains
[[self navigationItem] setTitleView:aiView];
[aiView startAnimating];

[[PLPlateStore sharedStore] getMains:^(NSArray *mainsResult, NSError *err) {
__weak PLSelectMainsViewController *weakSelf = self;

[[PLPlateStore sharedStore] getMenu:^(PLMenu *menuResult, NSError *err) {

[[self navigationItem] setTitleView:currentTitleView];
[[weakSelf navigationItem] setTitleView:currentTitleView];

if (!err) {
mains = mainsResult;
[[self tableMains] reloadData];
mains = [menuResult mains];
[[weakSelf tableMains] reloadData];
} else {
UIAlertView *av =[[UIAlertView alloc]
initWithTitle:@"Error"
Expand Down Expand Up @@ -109,9 +112,8 @@ - (void)viewDidLoad
// Do any additional setup after loading the view from its nib.
[self setTitle:@"Mains"];
[[self tableMains] setTableHeaderView:nil];
if (!mains) {
[self fetchMains];
}
[self fetchMains];

// self.automaticallyAdjustsScrollViewInsets = NO;
// self.edgesForExtendedLayout=UIRectEdgeNone;

Expand Down
3 changes: 2 additions & 1 deletion PLSelectMainsViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="PLSelectMainsViewController">
<connections>
<outlet property="tableMains" destination="lux-WJ-fgs" id="bwL-0e-Dk1"/>
<outlet property="view" destination="1" id="3"/>
</connections>
</placeholder>
Expand All @@ -14,7 +15,7 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" scrollEnabled="NO" style="plain" separatorStyle="default" rowHeight="50" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="lux-WJ-fgs">
<tableView clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="50" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="lux-WJ-fgs">
<rect key="frame" x="20" y="113" width="280" height="200"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<connections>
Expand Down
1 change: 1 addition & 0 deletions PLSelectSidesViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
{
NSArray *sides;
}
@property (weak, nonatomic) IBOutlet UITableView *tableSides;
@property (nonatomic, strong) PLOrderSummaryViewController *orderSummaryController;
@end
36 changes: 33 additions & 3 deletions PLSelectSidesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "PLSelectSidesViewController.h"
#import "PLOrderSummaryViewController.h"
#import "PLPlateStore.h"

@interface PLSelectSidesViewController ()

Expand All @@ -19,6 +20,35 @@ @implementation PLSelectSidesViewController

#pragma mark - Table view data source

- (void)fetchSides
{

UIView *currentTitleView = [[self navigationItem] titleView];
UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[[self navigationItem] setTitleView:aiView];
[aiView startAnimating];

__weak PLSelectSidesViewController *weakSelf = self;

[[PLPlateStore sharedStore] getMenu:^(PLMenu *menuResult, NSError *err) {

[[weakSelf navigationItem] setTitleView:currentTitleView];

if (!err) {
sides = [menuResult sides];
[[weakSelf tableSides] reloadData];
} else {
UIAlertView *av =[[UIAlertView alloc]
initWithTitle:@"Error"
message:[err localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[av show];
}
}];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
Expand All @@ -43,7 +73,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.layer.cornerRadius = 12.0f;
cell.layer.backgroundColor = [[UIColor grayColor] CGColor];

[[cell textLabel] setText:[sides objectAtIndex:[indexPath row]]];
[[cell textLabel] setText:[[sides objectAtIndex:[indexPath row]]name]];

return cell;
}
Expand All @@ -63,8 +93,8 @@ - (void)viewDidLoad
self.title = @"Sides";
self.orderSummaryController = [[PLOrderSummaryViewController alloc]init];

sides = [[NSArray alloc]initWithObjects:@"Broccolini", @"Mashed Potatoes", @"Moroccan Cauliflower", @"Pickled Beets",
@"Deviled Eggs", @"Kool Aid, no sugar", @"Peanut Butter, no jelly", @"Ham, no burger", nil];
[self fetchSides];

}


Expand Down
1 change: 1 addition & 0 deletions PLSelectSidesViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="PLSelectSidesViewController">
<connections>
<outlet property="tableSides" destination="eVj-sw-Qwj" id="4h3-5a-tAd"/>
<outlet property="view" destination="0N9-W6-mEK" id="5hf-UG-ql7"/>
</connections>
</placeholder>
Expand Down
6 changes: 6 additions & 0 deletions Plate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
0ADC532D185671A700258E1E /* PLMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ADC532C185671A700258E1E /* PLMenuItem.m */; };
0ADC53301856738400258E1E /* PLPlateStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ADC532F1856738400258E1E /* PLPlateStore.m */; };
0ADC53331856808F00258E1E /* PLConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ADC53321856808F00258E1E /* PLConnection.m */; };
0ADC533718579C6300258E1E /* PLMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ADC533618579C6300258E1E /* PLMenu.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -141,6 +142,8 @@
0ADC53311856808E00258E1E /* PLConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLConnection.h; sourceTree = "<group>"; };
0ADC53321856808F00258E1E /* PLConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLConnection.m; sourceTree = "<group>"; };
0ADC533418568E3600258E1E /* JSONSerializable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSONSerializable.h; sourceTree = "<group>"; };
0ADC533518579C6300258E1E /* PLMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLMenu.h; sourceTree = "<group>"; };
0ADC533618579C6300258E1E /* PLMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLMenu.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -270,6 +273,8 @@
0ABBE3E71843D0390031D3E2 = {
isa = PBXGroup;
children = (
0ADC533518579C6300258E1E /* PLMenu.h */,
0ADC533618579C6300258E1E /* PLMenu.m */,
0ADC533418568E3600258E1E /* JSONSerializable.h */,
0ADC53311856808E00258E1E /* PLConnection.h */,
0ADC53321856808F00258E1E /* PLConnection.m */,
Expand Down Expand Up @@ -478,6 +483,7 @@
0A318C63184532250023FFF5 /* PLStartOrderViewController.m in Sources */,
0A9D7DDA184A93C800BAE38D /* PLSelectMainsViewController.m in Sources */,
0A0D16981850FE750057F538 /* PLRewardsViewController.m in Sources */,
0ADC533718579C6300258E1E /* PLMenu.m in Sources */,
0A0D169D185102140057F538 /* PLSettingsViewController.m in Sources */,
0ABBE4001843D0390031D3E2 /* main.m in Sources */,
0A9D7DEC184C62CA00BAE38D /* PLSelectSidesViewController.m in Sources */,
Expand Down
Loading

0 comments on commit 0b3647c

Please sign in to comment.