diff --git a/RedmineMobile/RedmineMobile.xcodeproj/project.pbxproj b/RedmineMobile/RedmineMobile.xcodeproj/project.pbxproj index efb6266..fd2747f 100644 --- a/RedmineMobile/RedmineMobile.xcodeproj/project.pbxproj +++ b/RedmineMobile/RedmineMobile.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ D5DB80B61793016B0081662A /* OZLAccountViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D5DB80B41793016B0081662A /* OZLAccountViewController.xib */; }; D5DB80BA17930C830081662A /* OZLNetworkBase.m in Sources */ = {isa = PBXBuildFile; fileRef = D5DB80B917930C830081662A /* OZLNetworkBase.m */; }; D5DB80BD17930ECD0081662A /* OZLSingleton.m in Sources */ = {isa = PBXBuildFile; fileRef = D5DB80BC17930ECD0081662A /* OZLSingleton.m */; }; + D5DB80C217931C8B0081662A /* OZLModelProject.m in Sources */ = {isa = PBXBuildFile; fileRef = D5DB80C117931C8B0081662A /* OZLModelProject.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -96,6 +97,8 @@ D5DB80B917930C830081662A /* OZLNetworkBase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OZLNetworkBase.m; path = Utils/OZLNetworkBase.m; sourceTree = ""; }; D5DB80BB17930ECD0081662A /* OZLSingleton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OZLSingleton.h; path = Utils/OZLSingleton.h; sourceTree = ""; }; D5DB80BC17930ECD0081662A /* OZLSingleton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OZLSingleton.m; path = Utils/OZLSingleton.m; sourceTree = ""; }; + D5DB80C017931C8B0081662A /* OZLModelProject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OZLModelProject.h; path = Models/OZLModelProject.h; sourceTree = ""; }; + D5DB80C117931C8B0081662A /* OZLModelProject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OZLModelProject.m; path = Models/OZLModelProject.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -143,6 +146,7 @@ D5DB805F1792F2BF0081662A /* RedmineMobile */ = { isa = PBXGroup; children = ( + D5DB80BF17931C580081662A /* Models */, D5DB80AE1793008F0081662A /* Utils */, D5DB80A81792F4E40081662A /* ViewControllers */, D5DB80681792F2BF0081662A /* OZLAppDelegate.h */, @@ -261,6 +265,15 @@ name = Utils; sourceTree = ""; }; + D5DB80BF17931C580081662A /* Models */ = { + isa = PBXGroup; + children = ( + D5DB80C017931C8B0081662A /* OZLModelProject.h */, + D5DB80C117931C8B0081662A /* OZLModelProject.m */, + ); + name = Models; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -351,6 +364,7 @@ D5DB80B51793016B0081662A /* OZLAccountViewController.m in Sources */, D5DB80BA17930C830081662A /* OZLNetworkBase.m in Sources */, D5DB80BD17930ECD0081662A /* OZLSingleton.m in Sources */, + D5DB80C217931C8B0081662A /* OZLModelProject.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/RedmineMobile/RedmineMobile/Models/OZLModelProject.h b/RedmineMobile/RedmineMobile/Models/OZLModelProject.h new file mode 100644 index 0000000..359a270 --- /dev/null +++ b/RedmineMobile/RedmineMobile/Models/OZLModelProject.h @@ -0,0 +1,21 @@ +// +// OZLModelProject.h +// RedmineMobile +// +// Created by Lee Zhijie on 7/15/13. +// Copyright (c) 2013 Lee Zhijie. All rights reserved. +// + +#import + +@interface OZLModelProject : NSObject + +@property(nonatomic) int index; +@property(nonatomic,strong) NSString* description; +@property(nonatomic,strong) NSString* name; +@property(nonatomic) int parentId; +@property(nonatomic,strong) NSString* createdOn; +@property(nonatomic,strong) NSString* updatedOn; + +-(id)initWithDictionary:(NSDictionary*)dic; +@end diff --git a/RedmineMobile/RedmineMobile/Models/OZLModelProject.m b/RedmineMobile/RedmineMobile/Models/OZLModelProject.m new file mode 100644 index 0000000..e4df8e3 --- /dev/null +++ b/RedmineMobile/RedmineMobile/Models/OZLModelProject.m @@ -0,0 +1,34 @@ +// +// OZLModelProject.m +// RedmineMobile +// +// Created by Lee Zhijie on 7/15/13. +// Copyright (c) 2013 Lee Zhijie. All rights reserved. +// + +#import "OZLModelProject.h" + +@implementation OZLModelProject + +-(id)initWithDictionary:(NSDictionary*)dic +{ + self = [super init]; + if (!self) { + return nil; + } + + _index = [[dic objectForKey:@"id"] intValue]; + _name = [dic objectForKey:@"name"]; + _description = [dic objectForKey:@"description"]; + _createdOn = [dic objectForKey:@"created_on"]; + _updatedOn = [dic objectForKey:@"updated_on"]; + NSDictionary* parent = [dic objectForKey:@"parent"]; + if (parent) { + _parentId = [[parent objectForKey:@"id"] intValue]; + }else { + _parentId = -1; + } + return self; +} + +@end diff --git a/RedmineMobile/RedmineMobile/Utils/OZLNetwork.h b/RedmineMobile/RedmineMobile/Utils/OZLNetwork.h index e534f03..b232c86 100644 --- a/RedmineMobile/RedmineMobile/Utils/OZLNetwork.h +++ b/RedmineMobile/RedmineMobile/Utils/OZLNetwork.h @@ -10,6 +10,6 @@ @interface OZLNetwork : NSObject -+(void)getProjectListWithBlock:(void (^)(NSDictionary *result, NSError *error))block; ++(void)getProjectListWithParams:(NSDictionary*)params andBlock:(void (^)(NSArray *result, NSError *error))block; @end diff --git a/RedmineMobile/RedmineMobile/Utils/OZLNetwork.m b/RedmineMobile/RedmineMobile/Utils/OZLNetwork.m index 13dd4d0..0db8b6f 100644 --- a/RedmineMobile/RedmineMobile/Utils/OZLNetwork.m +++ b/RedmineMobile/RedmineMobile/Utils/OZLNetwork.m @@ -9,18 +9,25 @@ #import "OZLNetwork.h" #import "OZLNetworkBase.h" #import "AFHTTPRequestOperation.h" +#import "JSONKit.h" +#import "OZLModelProject.h" @implementation OZLNetwork -+(void)getProjectListWithBlock:(void (^)(NSDictionary *result, NSError *error))block ++(void)getProjectListWithParams:(NSDictionary*)params andBlock:(void (^)(NSArray *result, NSError *error))block; { NSString* path = @"/projects.json"; - NSDictionary* params = [[NSDictionary alloc] initWithObjectsAndKeys: nil]; [[OZLNetworkBase sharedClient] getPath:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { NSLog(@"the repsonse:%@",responseObject); - block(responseObject,nil); + NSMutableArray* projects = [[NSMutableArray alloc] init]; + + NSArray* projectsDic = [responseObject objectForKey:@"projects"]; + for (NSDictionary* p in projectsDic) { + [projects addObject:[[OZLModelProject alloc] initWithDictionary:p]]; + } + block(projects,nil); } @@ -28,7 +35,7 @@ if (block) { - block(nil, error); + block([NSArray array], error); } }]; diff --git a/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.m b/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.m index 1666a7d..110ec30 100644 --- a/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.m +++ b/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.m @@ -88,8 +88,6 @@ [[OZLSingleton sharedInstance] setRedmineUserKey:_redmineUserKey.text]; [[OZLSingleton sharedInstance] setRedmineHomeURL:_redmineHomeURL.text]; - [OZLNetwork getProjectListWithBlock:^(NSDictionary *respond, NSError *error) { - NSLog(@"respond:%@",respond.description); - }]; + [self showLeft]; } @end diff --git a/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.h b/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.h index 76b1df1..60e3387 100644 --- a/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.h +++ b/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.h @@ -8,7 +8,8 @@ #import -@interface OZLProjectListViewController : UIViewController +@interface OZLProjectListViewController : UIViewController +@property (strong, nonatomic) IBOutlet UITableView *projectsTableview; - (IBAction)showAccountView:(id)sender; @end diff --git a/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.m b/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.m index 42f7d35..e552295 100644 --- a/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.m +++ b/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.m @@ -10,8 +10,13 @@ #import "PPRevealSideViewController.h" #import "OZLProjectViewController.h" #import "OZLAccountViewController.h" +#import "OZLNetwork.h" +#import "OZLModelProject.h" -@interface OZLProjectListViewController () +@interface OZLProjectListViewController (){ + NSMutableArray* _projectList; + +} @end @@ -29,9 +34,20 @@ - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view from its nib. + _projectsTableview.delegate = self; + _projectsTableview.dataSource = self; + } +-(void) viewWillAppear:(BOOL)animated +{ + // refresh project list + [OZLNetwork getProjectListWithParams:nil andBlock:^(NSArray *result, NSError *error) { + NSLog(@"respond:%@",result.description); + _projectList = [[NSMutableArray alloc] initWithArray: result]; + [_projectsTableview reloadData]; + }]; +} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -53,4 +69,90 @@ [self.revealSideViewController popViewControllerWithNewCenterController:n animated:YES]; } +- (void)viewDidUnload { + [self setProjectsTableview:nil]; + [super viewDidUnload]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + + // Return the number of sections. + return [_projectList count]; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + + // Return the number of rows in the section. + return 1; +} + +-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return 44; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSString* cellidentifier = [NSString stringWithFormat:@"project_cell_id_%d",indexPath.row]; + UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellidentifier]; + if (!cell) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellidentifier]; + } + OZLModelProject* project = [_projectList objectAtIndex:indexPath.row]; + cell.textLabel.text = project.name; + cell.detailTextLabel.text = project.description; + 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:@[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 +{ + + +} + @end diff --git a/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.xib b/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.xib index c21fed3..dfd642c 100644 --- a/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.xib +++ b/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.xib @@ -36,12 +36,12 @@ 274 - + 292 {320, 44} - + _NS:9 NO IBCocoaTouchFramework @@ -49,7 +49,7 @@ 0 1 Account - + 3 MQA @@ -71,13 +71,13 @@ 16 - + 274 {{0, 45}, {320, 503}} _NS:9 - + YES IBCocoaTouchFramework YES @@ -91,7 +91,7 @@ {{0, 20}, {320, 548}} - + 3 MQA @@ -130,10 +130,18 @@ 3 + + + projectsTableview + + + + 20 + showAccountView: - + 7 @@ -152,8 +160,8 @@ 1 - - + + @@ -170,13 +178,13 @@ 4 - + 9 - + @@ -195,7 +203,7 @@ - 17 + 20 0