Permalink
Browse files

Refactoring: Resource editing

  • Loading branch information...
1 parent d4843d4 commit 871f6de9a1d9c689a7cfed27aa1f9fe45a943dc1 @dennisreimann committed Jun 19, 2013
@@ -0,0 +1,10 @@
+#import "IOCCollectionController.h"
+#import "IOCResourceEditingDelegate.h"
+
+@class GHIssue;
+
+@interface IOCAssigneeSelectionController : IOCCollectionController
+@property(nonatomic,weak)id<IOCResourceEditingDelegate> delegate;
+
+- (id)initWithIssue:(GHIssue *)issue;
+@end
@@ -1,4 +1,4 @@
-#import "IOCAssigneesController.h"
+#import "IOCAssigneeSelectionController.h"
#import "IOCUserObjectCell.h"
#import "GHRepository.h"
#import "GHIssue.h"
@@ -7,13 +7,13 @@
#import "SVProgressHUD.h"
-@interface IOCAssigneesController ()
+@interface IOCAssigneeSelectionController ()
@property(nonatomic,weak)GHIssue *issue;
@property(nonatomic,strong)NSIndexPath *selectedIndexPath;
@end
-@implementation IOCAssigneesController
+@implementation IOCAssigneeSelectionController
- (id)initWithIssue:(GHIssue *)issue {
self = [super initWithCollection:issue.repository.assignees];
@@ -61,7 +61,7 @@ - (void)viewWillDisappear:(BOOL)animated {
[SVProgressHUD showSuccessWithStatus:@"Saved assignee"];
self.issue.assignee = newAssignee;
[self.issue markAsChanged];
- [self.delegate performSelector:@selector(savedIssueObject:) withObject:self.issue];
+ [self.delegate performSelector:@selector(savedResource:) withObject:self.issue];
[self.navigationController popViewControllerAnimated:YES];
} failure:^(GHResource *instance, NSError *error) {
[SVProgressHUD showErrorWithStatus:@"Saving assignee failed"];
@@ -1,10 +0,0 @@
-#import "IOCCollectionController.h"
-#import "IOCIssueManagementDelegate.h"
-
-@class GHIssue;
-
-@interface IOCAssigneesController : IOCCollectionController
-@property(nonatomic,weak)id<IOCIssueManagementDelegate> delegate;
-
-- (id)initWithIssue:(GHIssue *)issue;
-@end
@@ -1,18 +1,18 @@
#import "IOCIssueController.h"
-#import "IOCIssueManagementDelegate.h"
+#import "IOCResourceEditingDelegate.h"
#import "IOCCommentController.h"
#import "IOCWebController.h"
#import "IOCTextCell.h"
#import "IOCLabeledCell.h"
#import "IOCCommentCell.h"
#import "IOCIssuesController.h"
-#import "IOCIssueObjectFormController.h"
+#import "IOCTitleBodyFormController.h"
#import "IOCUserController.h"
#import "IOCRepositoryController.h"
#import "IOCResourceStatusCell.h"
#import "IOCViewControllerFactory.h"
-#import "IOCMilestonesController.h"
-#import "IOCAssigneesController.h"
+#import "IOCMilestoneSelectionController.h"
+#import "IOCAssigneeSelectionController.h"
#import "GHUser.h"
#import "GHIssue.h"
#import "GHMilestone.h"
@@ -28,7 +28,7 @@
#import "NSString+Extensions.h"
-@interface IOCIssueController () <UIActionSheetDelegate, IOCIssueManagementDelegate, IOCTextCellDelegate, IOCCommentCellDelegate>
+@interface IOCIssueController () <UIActionSheetDelegate, IOCResourceEditingDelegate, IOCTextCellDelegate, IOCCommentCellDelegate>
@property(nonatomic,strong)GHIssue *issue;
@property(nonatomic,strong)IOCIssuesController *listController;
@property(nonatomic,strong)IOCResourceStatusCell *statusCell;
@@ -174,7 +174,7 @@ - (void)setupInfiniteScrolling {
}
// displaying the new data gets done via viewWillAppear
-- (void)savedIssueObject:(id)object {
+- (void)savedResource:(id)object {
[self displayIssueChange];
[self.listController reloadIssues];
}
@@ -207,7 +207,7 @@ - (IBAction)showActions:(id)sender {
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:NSLocalizedString(@"Edit", @"Action Sheet: Edit")]) {
- IOCIssueObjectFormController *formController = [[IOCIssueObjectFormController alloc] initWithIssueObject:self.issue];
+ IOCTitleBodyFormController *formController = [[IOCTitleBodyFormController alloc] initWithResource:self.issue name:@"issue"];
formController.delegate = self;
[self.navigationController pushViewController:formController animated:YES];
} else if ([buttonTitle isEqualToString:NSLocalizedString(@"Close", @"Action Sheet: Close")] || [buttonTitle isEqualToString:NSLocalizedString(@"Reopen", @"Action Sheet: Reopen")]) {
@@ -323,11 +323,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
} else if (indexPath.row == 1 && self.issue.user) {
viewController = [[IOCUserController alloc] initWithUser:self.issue.user];
} else if (indexPath.row == 2 && self.isAssignee) {
- viewController = [[IOCAssigneesController alloc] initWithIssue:self.issue];
- [(IOCAssigneesController *)viewController setDelegate:self];
+ viewController = [[IOCAssigneeSelectionController alloc] initWithIssue:self.issue];
+ [(IOCAssigneeSelectionController *)viewController setDelegate:self];
} else if (indexPath.row == 3 && self.isAssignee) {
- viewController = [[IOCMilestonesController alloc] initWithIssue:self.issue];
- [(IOCMilestonesController *)viewController setDelegate:self];
+ viewController = [[IOCMilestoneSelectionController alloc] initWithIssue:self.issue];
+ [(IOCMilestoneSelectionController *)viewController setDelegate:self];
}
}
if (viewController) {
@@ -1,3 +0,0 @@
-@protocol IOCIssueManagementDelegate <NSObject>
-- (void)savedIssueObject:(id)object;
-@end
@@ -1,8 +0,0 @@
-#import "IOCIssueManagementDelegate.h"
-
-
-@interface IOCIssueObjectFormController : UIViewController
-@property(nonatomic,weak)id<IOCIssueManagementDelegate> delegate;
-
-- (id)initWithIssueObject:(id)object;
-@end
@@ -1,7 +1,7 @@
#import "IOCIssuesController.h"
#import "IOCIssueController.h"
-#import "IOCIssueObjectFormController.h"
-#import "IOCIssueManagementDelegate.h"
+#import "IOCTitleBodyFormController.h"
+#import "IOCResourceEditingDelegate.h"
#import "IOCResourceStatusCell.h"
#import "IOCIssueObjectCell.h"
#import "GHIssue.h"
@@ -12,7 +12,7 @@
#define kIssueSortUpdated @"updated"
-@interface IOCIssuesController () <IOCIssueManagementDelegate>
+@interface IOCIssuesController () <IOCResourceEditingDelegate>
@property(nonatomic,strong)GHRepository *repository;
@property(nonatomic,strong)NSArray *objects;
@property(nonatomic,strong)UISegmentedControl *issuesControl;
@@ -72,7 +72,7 @@ - (void)viewDidLoad {
self.issuesControl.frame = controlFrame;
self.navigationItem.titleView = self.issuesControl;
if (self.repository) {
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(createNewIssue:)];
+ self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(createIssue:)];
}
self.issuesControl.selectedSegmentIndex = 0;
}
@@ -85,9 +85,9 @@ - (IBAction)switchChanged:(id)sender {
[self loadCollection];
}
-- (IBAction)createNewIssue:(id)sender {
+- (IBAction)createIssue:(id)sender {
GHIssue *issue = [[GHIssue alloc] initWithRepository:self.repository];
- IOCIssueObjectFormController *formController = [[IOCIssueObjectFormController alloc] initWithIssueObject:issue];
+ IOCTitleBodyFormController *formController = [[IOCTitleBodyFormController alloc] initWithResource:issue name:@"issue"];
formController.delegate = self;
[self.navigationController pushViewController:formController animated:YES];
}
@@ -97,8 +97,8 @@ - (void)reloadIssues {
}
// delegation method for newly created issues
-- (void)savedIssueObject:(id)object {
- [[self.objects objectAtIndex:0] insertObject:object atIndex:0];
+- (void)savedResource:(id)resource {
+ [[self.objects objectAtIndex:0] insertObject:resource atIndex:0];
[self.tableView reloadData];
}
@@ -0,0 +1,11 @@
+#import "IOCCollectionController.h"
+#import "IOCResourceEditingDelegate.h"
+
+
+@class GHIssue;
+
+@interface IOCMilestoneSelectionController : IOCCollectionController
+@property(nonatomic,weak)id<IOCResourceEditingDelegate> delegate;
+
+- (id)initWithIssue:(GHIssue *)issue;
+@end
@@ -1,4 +1,4 @@
-#import "IOCMilestonesController.h"
+#import "IOCMilestoneSelectionController.h"
#import "IOCMilestoneCell.h"
#import "GHRepository.h"
#import "GHMilestones.h"
@@ -7,13 +7,13 @@
#import "SVProgressHUD.h"
-@interface IOCMilestonesController ()
+@interface IOCMilestoneSelectionController ()
@property(nonatomic,weak)GHIssue *issue;
@property(nonatomic,strong)NSIndexPath *selectedIndexPath;
@end
-@implementation IOCMilestonesController
+@implementation IOCMilestoneSelectionController
- (id)initWithIssue:(GHIssue *)issue {
self = [super initWithCollection:issue.repository.milestones];
@@ -62,7 +62,7 @@ - (void)viewWillDisappear:(BOOL)animated {
[SVProgressHUD showSuccessWithStatus:@"Saved milestone"];
self.issue.milestone = newMilestone;
[self.issue markAsChanged];
- [self.delegate performSelector:@selector(savedIssueObject:) withObject:self.issue];
+ [self.delegate performSelector:@selector(savedResource:) withObject:self.issue];
[self.navigationController popViewControllerAnimated:YES];
} failure:^(GHResource *instance, NSError *error) {
[SVProgressHUD showErrorWithStatus:@"Saving milestone failed"];
@@ -1,10 +0,0 @@
-#import "IOCCollectionController.h"
-#import "IOCIssueManagementDelegate.h"
-
-@class GHIssue;
-
-@interface IOCMilestonesController : IOCCollectionController
-@property(nonatomic,weak)id<IOCIssueManagementDelegate> delegate;
-
-- (id)initWithIssue:(GHIssue *)issue;
-@end
@@ -5,7 +5,7 @@
#import "IOCLabeledCell.h"
#import "IOCCommentCell.h"
#import "IOCPullRequestsController.h"
-#import "IOCIssueObjectFormController.h"
+#import "IOCTitleBodyFormController.h"
#import "IOCUserController.h"
#import "IOCRepositoryController.h"
#import "IOCCommitsController.h"
@@ -241,7 +241,7 @@ - (IBAction)showActions:(id)sender {
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:NSLocalizedString(@"Edit", @"Action Sheet: Edit")]) {
- IOCIssueObjectFormController *formController = [[IOCIssueObjectFormController alloc] initWithIssueObject:self.pullRequest];
+ IOCTitleBodyFormController *formController = [[IOCTitleBodyFormController alloc] initWithResource:self.pullRequest name:@"pull request"];
[self.navigationController pushViewController:formController animated:YES];
} else if ([buttonTitle isEqualToString:NSLocalizedString(@"Merge", @"Action Sheet: Merge")]) {
[self mergePullRequest:nil];
@@ -0,0 +1,3 @@
+@protocol IOCResourceEditingDelegate <NSObject>
+- (void)savedResource:(id)object;
+@end
@@ -0,0 +1,12 @@
+#import "IOCResourceEditingDelegate.h"
+
+
+@class GHResource;
+
+@interface IOCTitleBodyFormController : UIViewController
+@property(nonatomic,weak)id<IOCResourceEditingDelegate> delegate;
+@property(nonatomic,strong)NSString *titleAttributeName;
+@property(nonatomic,strong)NSString *bodyAttributeName;
+
+- (id)initWithResource:(GHResource *)resource name:(NSString *)resourceName;
+@end
Oops, something went wrong.

0 comments on commit 871f6de

Please sign in to comment.