Skip to content

Commit

Permalink
menu items are now fetched from the server
Browse files Browse the repository at this point in the history
  • Loading branch information
ebaizel committed Feb 8, 2014
1 parent d59f533 commit 76dc1f3
Show file tree
Hide file tree
Showing 30 changed files with 1,227 additions and 562 deletions.
1 change: 0 additions & 1 deletion PLALaCarteItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@

@interface PLALaCarteItem : PLMenuItem <NSCopying>

@property (nonatomic) int quantity;
@end
87 changes: 59 additions & 28 deletions PLALaCarteViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "PLMenuItemTableViewCell.h"
#import "PLBasketStore.h"
#import "Colours.h"
#import "PLPlateStore.h"

@interface PLALaCarteViewController ()

Expand Down Expand Up @@ -174,37 +175,67 @@ - (void)viewDidLoad

- (void)fetchALaCarteItems
{
// This will be a call out to server

NSMutableArray *mainItems = [[NSMutableArray alloc] init];
NSMutableArray *sideItems = [[NSMutableArray alloc] init];

[mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Beef Stroganoff" itemType:MenuItemMain itemId:@"1"]];
[mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Wild Salmon" itemType:MenuItemMain itemId:@"2"]];
[mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Moo Goo Gai Pan" itemType:MenuItemMain itemId:@"3"]];

[sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Eggplant" itemType:MenuItemSide itemId:@"4"]];
[sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Zucchini" itemType:MenuItemSide itemId:@"5"]];
[sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Broccoli" itemType:MenuItemSide itemId:@"6"]];
[sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Animal Crackers" itemType:MenuItemSide itemId:@"7"]];
[sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Fudge Ice Cream" itemType:MenuItemSide itemId:@"8"]];
[sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Spinach" itemType:MenuItemSide itemId:@"9"]];
[sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Artichokes" itemType:MenuItemSide itemId:@"10"]];
[sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Sardines" itemType:MenuItemSide itemId:@"11"]];

for (PLALaCarteItem *item in mainItems) {
item.price = 10.0;
}

for (PLALaCarteItem *item in sideItems) {
item.price = 4.0;
}

[self setMains:mainItems];
[self setSides:sideItems];

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

__weak PLALaCarteViewController *weakSelf = self;

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

[[weakSelf navigationItem] setTitleView:currentTitleView];

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

//- (void)fetchALaCarteItems
//{
// // This will be a call out to server
//
// NSMutableArray *mainItems = [[NSMutableArray alloc] init];
// NSMutableArray *sideItems = [[NSMutableArray alloc] init];
//
// [mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Beef Stroganoff" itemType:MenuItemMain itemId:@"1"]];
// [mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Wild Salmon" itemType:MenuItemMain itemId:@"2"]];
// [mainItems addObject:[[PLALaCarteItem alloc] initWithName:@"Moo Goo Gai Pan" itemType:MenuItemMain itemId:@"3"]];
//
// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Eggplant" itemType:MenuItemSide itemId:@"4"]];
// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Zucchini" itemType:MenuItemSide itemId:@"5"]];
// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Broccoli" itemType:MenuItemSide itemId:@"6"]];
// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Animal Crackers" itemType:MenuItemSide itemId:@"7"]];
// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Fudge Ice Cream" itemType:MenuItemSide itemId:@"8"]];
// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Spinach" itemType:MenuItemSide itemId:@"9"]];
// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Artichokes" itemType:MenuItemSide itemId:@"10"]];
// [sideItems addObject:[[PLALaCarteItem alloc] initWithName:@"Side of Sardines" itemType:MenuItemSide itemId:@"11"]];
//
// for (PLALaCarteItem *item in mainItems) {
// item.price = 10.0;
// }
//
// for (PLALaCarteItem *item in sideItems) {
// item.price = 4.0;
// }
//
// [self setMains:mainItems];
// [self setSides:sideItems];
//
//}

- (IBAction)actionContinue:(id)sender {
[[self navigationController] pushViewController:[[PLALaCarteSummaryViewController alloc]init] animated:YES];
}
Expand Down
1 change: 0 additions & 1 deletion PLAddOnItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@

@interface PLAddOnItem : PLMenuItem <NSCopying>

@property (nonatomic) int quantity;
@end
58 changes: 45 additions & 13 deletions PLAddOnViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#import "PLALaCarteSummaryViewController.h"
#import "PLAddOnSummaryViewController.h"
#import "Colours.h"
#import "PLPlateStore.h"
#import "PLMenu.h"

@interface PLAddOnViewController ()

Expand Down Expand Up @@ -149,25 +151,55 @@ - (void)viewDidLoad
// self.toolbarItems = [NSArray arrayWithObjects: flexibleSpaceLeft, barButton, nil];
}

-(void)fetchAddOnItems
- (void)fetchAddOnItems
{
NSMutableArray *addOnItems = [[NSMutableArray alloc]init];

[addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Coca Cola" itemType:MenuItemAddOn itemId:@"1"]];
[addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Cheez Whiz" itemType:MenuItemAddOn itemId:@"2"]];
[addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Faygo" itemType:MenuItemAddOn itemId:@"3"]];
[addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Frito Lays" itemType:MenuItemAddOn itemId:@"4"]];
[addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Chips Ahoy" itemType:MenuItemAddOn itemId:@"5"]];
[addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Saltines" itemType:MenuItemAddOn itemId:@"6"]];
[addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Vanilla Wafers" itemType:MenuItemAddOn itemId:@"7"]];
UIView *currentTitleView = [[self navigationItem] titleView];
UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[[self navigationItem] setTitleView:aiView];
[aiView startAnimating];

for (PLAddOnItem *item in addOnItems) {
item.price = 2.0;
}
__weak PLAddOnViewController *weakSelf = self;

[self setAddOns:addOnItems];
// PLPlate *plate = [[PLBasketStore sharedStore] plateBuilder];
[[PLPlateStore sharedStore]getAddOnMenu:^(PLMenu *menuResult, NSError *err) {

[[weakSelf navigationItem] setTitleView:currentTitleView];

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

//-(void)fetchAddOnItems
//{
// NSMutableArray *addOnItems = [[NSMutableArray alloc]init];
//
// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Coca Cola" itemType:MenuItemAddOn itemId:@"1"]];
// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Cheez Whiz" itemType:MenuItemAddOn itemId:@"2"]];
// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Faygo" itemType:MenuItemAddOn itemId:@"3"]];
// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Frito Lays" itemType:MenuItemAddOn itemId:@"4"]];
// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Chips Ahoy" itemType:MenuItemAddOn itemId:@"5"]];
// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Saltines" itemType:MenuItemAddOn itemId:@"6"]];
// [addOnItems addObject:[[PLAddOnItem alloc]initWithName:@"Vanilla Wafers" itemType:MenuItemAddOn itemId:@"7"]];
//
// for (PLAddOnItem *item in addOnItems) {
// item.price = 2.0;
// }
//
// [self setAddOns:addOnItems];
//}

- (IBAction)actionContinue:(id)sender {
[[self navigationController] pushViewController:[[PLAddOnSummaryViewController alloc]init] animated:YES];
}
Expand Down
46 changes: 31 additions & 15 deletions PLBasketStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "PLALaCarteItem.h"
#import "PLPlate.h"
#import "PLAddOnItem.h"
#import "PLPlateSize.h"

@implementation PLBasketStore

Expand Down Expand Up @@ -184,6 +185,17 @@ -(void)setPlateSize:(PlateSize)plateSize
[[self plateBuilder] setSize:plateSize];
}

-(void)setPlateType2:(PlateType)plateType
{
[[self plateBuilder] setType:plateType];
}

-(void)setPlateSize2:(PlateSize)plateSize
{
[[self plateBuilder] setSize:plateSize];
}


-(void)setPlateMain:(PLMenuItem *)mainEntree
{
[[self plateBuilder] setMain:mainEntree];
Expand All @@ -194,9 +206,10 @@ -(void)addPlateSide:(PLMenuItem *)newSide
// Make sure we do not exceed the allowed number of sides

int numSides = 0;
if ([[self plateBuilder] type] == OneMain) {
NSString *slug = [[[[PLBasketStore sharedStore] plateBuilder] plateTypeSize] typeSlug];
if ([slug isEqualToString:OneMainTwoSides]) {
numSides = 2;
} else if ([[self plateBuilder] type] == FourSides) {
} else if ([slug isEqualToString:FourSides]) {
numSides = 4;
}

Expand Down Expand Up @@ -305,25 +318,28 @@ -(float)totalCostOfItemsInBasket
{
float total = 0.0;
for (PLPlate *plate in [self plates]) {
if ([plate size] == Ultra) {
total += 15.0;
} else if ([plate size] == Fit) {
total += 12.0;
} else if ([plate size] == Kids) {
total += 8.0;
}
total += [[plate plateSize] price];
// if ([plate size] == Ultra) {
// total += 15.0;
// } else if ([plate size] == Fit) {
// total += 12.0;
// } else if ([plate size] == Kids) {
// total += 8.0;
// }
}

for (PLALaCarteItem *item in [self alaCarteItems]) {
if ([item itemType] == MenuItemMain) {
total += (10 * [item quantity]);
} else if ([item itemType] == MenuItemSide) {
total += (4 * [item quantity]);
}
total += [item price] * [item quantity];
// if ([item itemType] == MenuItemMain) {
// total += (10 * [item quantity]);
// } else if ([item itemType] == MenuItemSide) {
// total += (4 * [item quantity]);
// }
}

for (PLAddOnItem *item in [self addOns]) {
total += (2 * [item quantity]);
total += [item price] * [item quantity];
// total += (2 * [item quantity]);
}

return total;
Expand Down
4 changes: 2 additions & 2 deletions PLBasketViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.side2Label.text = @"";
}

if ([plate type] == FourSides) {

NSString *slug = [[[[PLBasketStore sharedStore] plateBuilder] plateTypeSize] typeSlug];
if ([slug isEqualToString:FourSides]) {
side = [[plate sides] objectAtIndex:2];
cell.side3Label.text = [side name];

Expand Down
1 change: 1 addition & 0 deletions PLConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{
NSURLConnection *internalConnection;
NSMutableData *container;
NSURLSessionDataTask *task;
}

@property (nonatomic, copy) NSURLRequest *request;
Expand Down
6 changes: 6 additions & 0 deletions PLConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ - (void) start
container = [[NSMutableData alloc]init];
internalConnection = [[NSURLConnection alloc] initWithRequest:[self request] delegate:self startImmediately:YES];

// NSURLSession *session = [NSURLSession sharedSession];
// task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//
// }];
// [task resume];

if (!sharedConnectionList) {
sharedConnectionList = [[NSMutableArray alloc]init];
}
Expand Down
6 changes: 5 additions & 1 deletion PLMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

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

@interface PLMenu : NSObject <JSONSerializable>

Expand All @@ -16,6 +18,8 @@
@property (nonatomic, strong) NSMutableArray *addons;
@property (nonatomic, strong) NSString *location;
@property (nonatomic, strong) NSDate *menuDate;

@property (nonatomic, strong) PLPlateSize *plateSize;
@property (nonatomic, strong) PLPlateTypeSize *plateTypeSize;
@property (nonatomic) MenuType menuType;

@end
Loading

0 comments on commit 76dc1f3

Please sign in to comment.