refactor common used data to sington

This commit is contained in:
zhijie 2013-07-24 11:23:41 +08:00
parent d086ff1b2c
commit d8c01cef28
8 changed files with 97 additions and 110 deletions

View File

@ -27,7 +27,7 @@
// THE SOFTWARE.
#import <Foundation/Foundation.h>
extern const NSString* NOTIFICATION_REDMINE_ACCOUNT_CHANGED;
extern NSString* NOTIFICATION_REDMINE_ACCOUNT_CHANGED;
@interface OZLConstants : NSObject

View File

@ -27,7 +27,7 @@
// THE SOFTWARE.
#import "OZLConstants.h"
const NSString* NOTIFICATION_REDMINE_ACCOUNT_CHANGED = @"NOTIFICATION_REDMINE_ACCOUNT_CHANGED";
NSString* NOTIFICATION_REDMINE_ACCOUNT_CHANGED = @"NOTIFICATION_REDMINE_ACCOUNT_CHANGED";
@implementation OZLConstants

View File

@ -46,6 +46,12 @@
//app status
@property(nonatomic) int lastProjectID;// last viewed project id
// app data
@property (strong, nonatomic) NSArray* trackerList;
@property (strong, nonatomic) NSArray* priorityList;
@property (strong, nonatomic) NSArray* statusList;
@property (strong, nonatomic) NSArray* userList;
@property (strong, nonatomic) NSArray* timeEntryActivityList;
@end

View File

@ -34,6 +34,7 @@
#import "OZLModelUser.h"
#import "OZLModelIssueStatus.h"
#import "MLTableAlert.h"
#import "OZLSingleton.h"
@interface OZLIssueCreateViewController () {
@ -66,6 +67,12 @@
{
[super viewDidLoad];
OZLSingleton* singleton = [OZLSingleton sharedInstance];
_trackerList = singleton.trackerList;
_statusList = singleton.statusList;
_userList = singleton.userList;
_priorityList = singleton.priorityList;
UIBarButtonItem* cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancel:)];
[self.navigationItem setLeftBarButtonItem:cancelBtn];
UIBarButtonItem* saveBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(onSave:)];

View File

@ -29,6 +29,7 @@
#import "OZLIssueDetailViewController.h"
#import "OZLIssueHistoryViewController.h"
#import "OZLIssueLogtimeViewController.h"
#import "OZLSingleton.h"
@interface OZLIssueDetailViewController ()
@ -58,6 +59,8 @@
{
[super viewDidLoad];
_timeEntryActivityList = [[OZLSingleton sharedInstance] timeEntryActivityList];
_subject.text = _issueData.subject;
_description.text = _issueData.description;
_progressbar.progress = _issueData.doneRatio/100;
@ -94,7 +97,6 @@
case 2:{//logtime
UIStoryboard *tableViewStoryboard = [UIStoryboard storyboardWithName:@"OZLIssueLogtimeViewController" bundle:nil];
OZLIssueLogtimeViewController* creator = [tableViewStoryboard instantiateViewControllerWithIdentifier:@"OZLIssueLogtimeViewController"];
[creator setTimeEntryActivityList:_timeEntryActivityList];
[creator setIssueData:_issueData];
[self.navigationController pushViewController:creator animated:YES];
}break;

View File

@ -78,7 +78,6 @@
{
OZLSingleton* singleton =[OZLSingleton sharedInstance];
[singleton setIssueListFilterType:_checkedCell[0]];
[singleton setIssueListSortType:_checkedCell[1]];
[singleton setIssueListSortAscending:_checkedCell[2]];

View File

@ -10,6 +10,7 @@
#import "MBProgressHUD.h"
#import "MLTableAlert.h"
#import "OZLNetwork.h"
#import "OZLSingleton.h"
@interface OZLIssueLogtimeViewController () {
MBProgressHUD* _HUD;
@ -35,6 +36,7 @@
// initialize data
_hourValue = 0;
_entry = [[OZLModelTimeEntries alloc] init];
_timeEntryActivityList = [[OZLSingleton sharedInstance] timeEntryActivityList];
UIBarButtonItem* cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancel:)];
[self.navigationItem setLeftBarButtonItem:cancelBtn];

View File

@ -148,70 +148,85 @@
{
_issueListOption = [[NSMutableDictionary alloc] init];
static int doneCount = 0;
const int totalCount = 5;
[OZLNetwork getTrackerListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
if (!error) {
_trackerList = result;
}else {
NSLog(@"get tracker list error : %@",error.description);
}
doneCount ++;
if (doneCount == totalCount) {
[self loadProjectDetail];
doneCount = 0;
}
}];
OZLSingleton* singleton = [OZLSingleton sharedInstance];
if (singleton.userList != nil) {
_trackerList = singleton.trackerList;
_statusList = singleton.statusList;
_userList = singleton.userList;
_priorityList = singleton.priorityList;
_timeEntryActivityList = singleton.timeEntryActivityList;
[self loadProjectDetail];
}else {
static int doneCount = 0;
const int totalCount = 5;
[OZLNetwork getTrackerListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
if (!error) {
_trackerList = result;
singleton.trackerList = _trackerList;
}else {
NSLog(@"get tracker list error : %@",error.description);
}
doneCount ++;
if (doneCount == totalCount) {
[self loadProjectDetail];
doneCount = 0;
}
}];
[OZLNetwork getIssueStatusListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
if (!error) {
_statusList = result;
}else {
NSLog(@"get issue status list error : %@",error.description);
}
doneCount ++;
if (doneCount == totalCount) {
[self loadProjectDetail];
doneCount = 0;
}
}];
[OZLNetwork getPriorityListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
if (!error) {
_priorityList = result;
}else {
NSLog(@"get priority list error : %@",error.description);
}
doneCount ++;
if (doneCount == totalCount) {
[self loadProjectDetail];
doneCount = 0;
}
}];
[OZLNetwork getUserListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
if (!error) {
_userList = result;
}else {
NSLog(@"get user list error : %@",error.description);
}
doneCount ++;
if (doneCount == totalCount) {
[self loadProjectDetail];
doneCount = 0;
}
}];
[OZLNetwork getIssueStatusListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
if (!error) {
_statusList = result;
singleton.statusList = _statusList;
}else {
NSLog(@"get issue status list error : %@",error.description);
}
doneCount ++;
if (doneCount == totalCount) {
[self loadProjectDetail];
doneCount = 0;
}
}];
[OZLNetwork getPriorityListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
if (!error) {
_priorityList = result;
singleton.priorityList = _priorityList;
}else {
NSLog(@"get priority list error : %@",error.description);
}
doneCount ++;
if (doneCount == totalCount) {
[self loadProjectDetail];
doneCount = 0;
}
}];
[OZLNetwork getUserListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
if (!error) {
_userList = result;
singleton.userList = _userList;
}else {
NSLog(@"get user list error : %@",error.description);
}
doneCount ++;
if (doneCount == totalCount) {
[self loadProjectDetail];
doneCount = 0;
}
}];
[OZLNetwork getTimeEntryListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
if (!error) {
_timeEntryActivityList = result;
}else {
NSLog(@"get user list error : %@",error.description);
}
doneCount ++;
if (doneCount == totalCount) {
[self loadProjectDetail];
doneCount = 0;
}
}];
[OZLNetwork getTimeEntryListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
if (!error) {
_timeEntryActivityList = result;
singleton.timeEntryActivityList = _timeEntryActivityList;
}else {
NSLog(@"get user list error : %@",error.description);
}
doneCount ++;
if (doneCount == totalCount) {
[self loadProjectDetail];
doneCount = 0;
}
}];
}
}
@ -307,45 +322,6 @@
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
@ -354,7 +330,6 @@
UIStoryboard *tableViewStoryboard = [UIStoryboard storyboardWithName:@"OZLIssueDetailViewController" bundle:nil];
OZLIssueDetailViewController* detail = [tableViewStoryboard instantiateViewControllerWithIdentifier:@"OZLIssueDetailViewController"];
[detail setIssueData:[_issuesList objectAtIndex:indexPath.row]];
[detail setTimeEntryActivityList:_timeEntryActivityList];
[self.navigationController pushViewController:detail animated:YES];
}
@ -363,10 +338,6 @@
UIStoryboard *tableViewStoryboard = [UIStoryboard storyboardWithName:@"OZLIssueCreateViewController" bundle:nil];
OZLIssueCreateViewController* creator = [tableViewStoryboard instantiateViewControllerWithIdentifier:@"OZLIssueCreateViewController"];
[creator setParentProject:_projectData];
creator.userList = _userList;
creator.trackerList = _trackerList;
creator.priorityList = _priorityList;
creator.statusList = _statusList;
//[self.navigationController presentModalViewController:creator animated:YES];
[self.navigationController pushViewController:creator animated:YES];
}