Skip to content

Commit

Permalink
Add sub-lab view controller for buildings with many labs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdzombak committed Feb 12, 2012
1 parent d41d4f0 commit fad6879
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 15 deletions.
10 changes: 8 additions & 2 deletions CAENLabStatus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
93BBAB4714DCCBF800B19049 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 93BBAB4114DCCBF800B19049 /* Icon.png */; };
93BBAB4814DCCBF800B19049 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 93BBAB4214DCCBF800B19049 /* [email protected] */; };
93BBAB5B14DCF4BD00B19049 /* iTunesArtwork in Resources */ = {isa = PBXBuildFile; fileRef = 93BBAB5A14DCF4BD00B19049 /* iTunesArtwork */; };
93BBAB6B14E83AC000B19049 /* DZCSubLabsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 93BBAB6A14E83AC000B19049 /* DZCSubLabsViewController.m */; };
93D9F66414D3997600AD2152 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93D9F66314D3997600AD2152 /* UIKit.framework */; };
93D9F66614D3997600AD2152 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93D9F66514D3997600AD2152 /* Foundation.framework */; };
93D9F66814D3997600AD2152 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93D9F66714D3997600AD2152 /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -54,6 +55,8 @@
93BBAB4114DCCBF800B19049 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
93BBAB4214DCCBF800B19049 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
93BBAB5A14DCF4BD00B19049 /* iTunesArtwork */ = {isa = PBXFileReference; lastKnownFileType = file; path = iTunesArtwork; sourceTree = "<group>"; };
93BBAB6914E83AC000B19049 /* DZCSubLabsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DZCSubLabsViewController.h; sourceTree = "<group>"; };
93BBAB6A14E83AC000B19049 /* DZCSubLabsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DZCSubLabsViewController.m; sourceTree = "<group>"; };
93D9F65F14D3997600AD2152 /* CAENLabStatus.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CAENLabStatus.app; sourceTree = BUILT_PRODUCTS_DIR; };
93D9F66314D3997600AD2152 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
93D9F66514D3997600AD2152 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -180,10 +183,12 @@
93D9F68814D39C2B00AD2152 /* View Controllers */ = {
isa = PBXGroup;
children = (
93D9F68514D39C2500AD2152 /* DZCLabsViewController.h */,
93D9F68614D39C2500AD2152 /* DZCLabsViewController.m */,
93E80C5914D797F5008850FE /* DZCAboutViewController.h */,
93E80C5A14D797F5008850FE /* DZCAboutViewController.m */,
93D9F68514D39C2500AD2152 /* DZCLabsViewController.h */,
93D9F68614D39C2500AD2152 /* DZCLabsViewController.m */,
93BBAB6914E83AC000B19049 /* DZCSubLabsViewController.h */,
93BBAB6A14E83AC000B19049 /* DZCSubLabsViewController.m */,
);
name = "View Controllers";
sourceTree = "<group>";
Expand Down Expand Up @@ -382,6 +387,7 @@
93D9F6C414D5081F00AD2152 /* DZCHostInfoApiClient.m in Sources */,
93E80C5814D78812008850FE /* DZCLabStatusHelper.m in Sources */,
93E80C5C14D797F5008850FE /* DZCAboutViewController.m in Sources */,
93BBAB6B14E83AC000B19049 /* DZCSubLabsViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
12 changes: 8 additions & 4 deletions CAENLabStatus/DZCDataController.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ - (NSSet *)labs

if (!_labs) {
_labs = [NSSet setWithObjects:
[[DZCLab alloc] initWithBuilding:@"PIERPONT" room:@"B505" humanName:@"Pierpont B505" hostCount:[NSNumber numberWithInt:26] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"PIERPONT" room:@"B507" humanName:@"Pierpont B507" hostCount:[NSNumber numberWithInt:26] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"PIERPONT" room:@"B521" humanName:@"Pierpont B521" hostCount:[NSNumber numberWithInt:22] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"CSE" room:@"1695" humanName:@"CSE 1695" hostCount:[NSNumber numberWithInt:49] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"CSE" room:@"1620" humanName:@"CSE 1620" hostCount:[NSNumber numberWithInt:43] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"EECS" room:@"1230" humanName:@"EECS 1230" hostCount:[NSNumber numberWithInt:28] subLabs:nil],
Expand All @@ -261,14 +258,21 @@ - (NSSet *)labs
[[DZCLab alloc] initWithBuilding:@"SHAPIRO" room:@"B100" humanName:@"Ugli Basement" hostCount:[NSNumber numberWithInt:24] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"BURSLEY" room:@"2506" humanName:@"Bursley 2506" hostCount:[NSNumber numberWithInt:8] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"MO-JO" room:@"163" humanName:@"MoJo 163" hostCount:[NSNumber numberWithInt:3] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"PIERPONT" room:@"" humanName:@"Pierpont (all)" hostCount:[NSNumber numberWithInt:74]
subLabs:[NSSet setWithObjects:
[[DZCLab alloc] initWithBuilding:@"PIERPONT" room:@"B505" humanName:@"Pierpont B505" hostCount:[NSNumber numberWithInt:26] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"PIERPONT" room:@"B507" humanName:@"Pierpont B507" hostCount:[NSNumber numberWithInt:26] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"PIERPONT" room:@"B521" humanName:@"Pierpont B521" hostCount:[NSNumber numberWithInt:22] subLabs:nil],
nil]
],
[[DZCLab alloc] initWithBuilding:@"BAITS_COMAN" room:@"" humanName:@"Baits (all)" hostCount:[NSNumber numberWithInt:4]
subLabs:[NSSet setWithObjects:
[[DZCLab alloc] initWithBuilding:@"BAITS_COMAN" room:@"2300" humanName:@"Baits I 2300" hostCount:[NSNumber numberWithInt:1] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"BAITS_COMAN" room:@"1000" humanName:@"Baits II 1000" hostCount:[NSNumber numberWithInt:2] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"BAITS_COMAN" room:@"1209" humanName:@"Baits II 1209" hostCount:[NSNumber numberWithInt:1] subLabs:nil],
nil]
],
[[DZCLab alloc] initWithBuilding:@"DC" room:@"" humanName:@"Duderstadt Center (All)" hostCount:[NSNumber numberWithInt:345]
[[DZCLab alloc] initWithBuilding:@"DC" room:@"" humanName:@"Duderstadt Ctr (all)" hostCount:[NSNumber numberWithInt:345]
subLabs:[NSSet setWithObjects:
[[DZCLab alloc] initWithBuilding:@"DC" room:@"2E" humanName:@"2nd Floor East" hostCount:[NSNumber numberWithInt:12] subLabs:nil],
[[DZCLab alloc] initWithBuilding:@"DC" room:@"2S" humanName:@"2nd Floor South" hostCount:[NSNumber numberWithInt:20] subLabs:nil],
Expand Down
41 changes: 32 additions & 9 deletions CAENLabStatus/DZCLabsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import "DZCDataController.h"
#import "DZCLab.h"
#import "DZCAboutViewController.h"
#import "DZCSubLabsViewController.h"

static NSString *DZCLabsTableViewSectionTitles[DZCLabStatusCount];
static NSString *DZCLabsTableViewSectionCellIDs[DZCLabStatusCount];
Expand Down Expand Up @@ -58,7 +59,7 @@ - (void)viewDidLoad

self.navigationItem.rightBarButtonItem = self.editButtonItem;

self.tableView.allowsSelection = NO;
self.tableView.allowsSelection = YES;
self.tableView.allowsMultipleSelection = NO;

self.labOrdering = [self retrieveSavedSortOrder];
Expand Down Expand Up @@ -307,6 +308,16 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.showsReorderControl = NO;
}

if (status == DZCLabStatusOpen && lab.subLabs != nil && [lab.subLabs count] > 0) {
//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
//cell.userInteractionEnabled = YES;
} else {
//cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//cell.userInteractionEnabled = NO;
}

return cell;
}

Expand Down Expand Up @@ -374,15 +385,27 @@ - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPat

- (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];
*/

NSLog(@"pressed %d.%d", indexPath.section, indexPath.row);

DZCLab *lab = [(NSArray *)[self.labsByStatus objectForKey:[NSNumber numberWithInt:[self statusForSection:indexPath.section]]] objectAtIndex:indexPath.row];
if (lab.subLabs == nil || [lab.subLabs count] == 0) {
return;
}

DZCSubLabsViewController *subLabViewController = [[DZCSubLabsViewController alloc] initWithLab:lab];
subLabViewController.dataController = self.dataController;

[self.navigationController pushViewController:subLabViewController animated:YES];
}

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DZCLab *lab = [(NSArray *)[self.labsByStatus objectForKey:[NSNumber numberWithInt:[self statusForSection:indexPath.section]]] objectAtIndex:indexPath.row];

if (lab.subLabs == nil || [lab.subLabs count] == 0) {
return nil;
}

return indexPath;
}

#pragma mark - Property overrides
Expand Down
13 changes: 13 additions & 0 deletions CAENLabStatus/DZCSubLabsViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import <UIKit/UIKit.h>

@class DZCLab;
@class DZCDataController;

@interface DZCSubLabsViewController : UITableViewController

@property (nonatomic, readonly, strong) DZCLab *lab;
@property (nonatomic, strong) DZCDataController *dataController;

- (id)initWithLab:(DZCLab *)lab;

@end
151 changes: 151 additions & 0 deletions CAENLabStatus/DZCSubLabsViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#import "DZCSubLabsViewController.h"

#import "DZCTableViewCellOpenLab.h"
#import "DZCDataController.h"
#import "DZCLab.h"

@interface DZCSubLabsViewController ()

@property (nonatomic, strong) NSMutableArray *labs;

- (void)refreshData;
- (void)loadData;

@end

@implementation DZCSubLabsViewController

@synthesize lab = _lab, labs = _labs, dataController = _dataController;

- (id)initWithLab:(DZCLab *)lab
{
self = [super initWithStyle:UITableViewStylePlain];
if (self) {
_lab = lab;
}
return self;
}

#pragma mark - UIViewController View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];

self.tableView.allowsSelection = NO;
self.tableView.allowsMultipleSelection = NO;
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

self.navigationItem.title = self.lab.humanName;

[self loadData];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.subtype == UIEventSubtypeMotionShake) {
[self refreshData];
}

if ([super respondsToSelector:@selector(motionEnded:withEvent:)]) {
[super motionEnded:motion withEvent:event];
}
}

- (BOOL)canBecomeFirstResponder
{
return YES;
}

#pragma mark - Data managament

- (void)refreshData
{
[self.dataController clearCache];
[self loadData];
}

- (void)loadData
{
self.labs = nil;

for (DZCLab *lab in self.lab.subLabs) {
[self.labs addObject:lab];
}

[self.labs sortUsingSelector:@selector(compareHumanName:)];

[self.tableView reloadData];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.labs count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DZCTableViewCellOpenLab" owner:self options:nil];
cell = (UITableViewCell *)[nib objectAtIndex:0];
}

if ([self.labs count] < indexPath.row+1) {
return cell;
}

DZCLab *lab = [self.labs objectAtIndex:indexPath.row];

((DZCTableViewCellOpenLab *) cell).labNameLabel.text = lab.humanName;

[self.dataController machineCountsInLab:lab withBlock:^(NSNumber *used, NSNumber *total, DZCLab *l, NSError *error) {
if (error) {
((DZCTableViewCellOpenLab *) cell).labOpenCountLabel.text = @"...";
((DZCTableViewCellOpenLab *) cell).labTotalCountLabel.text = @"...";
return;
}

((DZCTableViewCellOpenLab *) cell).labOpenCountLabel.text = [NSString stringWithFormat:@"%d", [total intValue]-[used intValue]];
((DZCTableViewCellOpenLab *) cell).labTotalCountLabel.text = [NSString stringWithFormat:@"%d", [total intValue]];

if ([used floatValue]/[total floatValue] >= 0.9) {
((DZCTableViewCellOpenLab *) cell).labNameLabel.font = [UIFont systemFontOfSize:20.0];
((DZCTableViewCellOpenLab *) cell).labOpenCountLabel.font = [UIFont systemFontOfSize:20.0];
} else {
((DZCTableViewCellOpenLab *) cell).labNameLabel.font = [UIFont boldSystemFontOfSize:20.0];
((DZCTableViewCellOpenLab *) cell).labOpenCountLabel.font = [UIFont boldSystemFontOfSize:20.0];
}
}];

return cell;
}

#pragma mark - Property overrides

- (NSMutableArray *)labs {
if (!_labs) {
_labs = [NSMutableArray array];
}
return _labs;
}

@end

0 comments on commit fad6879

Please sign in to comment.