forked from cdzombak/CAENLabStatus-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sub-lab view controller for buildings with many labs
- Loading branch information
Showing
5 changed files
with
212 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */; }; | ||
|
@@ -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; }; | ||
|
@@ -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>"; | ||
|
@@ -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; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |