Skip to content

Commit c9e8923

Browse files
committed
ProjectCommitsViewController
1 parent b8d2c62 commit c9e8923

32 files changed

+376
-44
lines changed

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 50 additions & 8 deletions
Large diffs are not rendered by default.

Coding_iOS/Controllers/CodeListViewController.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "CodeListViewController.h"
1010
#import "CodeViewController.h"
1111
#import "ProjectViewController.h"
12+
#import "ProjectCommitsViewController.h"
1213

1314
@interface CodeListViewController ()
1415

@@ -27,6 +28,9 @@ - (void)viewDidLoad {
2728
listView.codeTreeFileOfRefBlock = ^(CodeTree_File *curCodeTreeFile, NSString *ref){
2829
[weakSelf goToVCWith:curCodeTreeFile andRef:ref];
2930
};
31+
listView.refChangedBlock = ^(NSString *ref){
32+
weakSelf.myCodeTree.ref = ref;
33+
};
3034
[self.view addSubview:listView];
3135
[listView mas_makeConstraints:^(MASConstraintMaker *make) {
3236
make.edges.equalTo(self.view);
@@ -43,9 +47,13 @@ - (void)configRightNavBtn{
4347

4448
- (void)rightNavBtnClicked{
4549
__weak typeof(self) weakSelf = self;
46-
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"退出代码查看"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
50+
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"查看提交记录", @"退出代码查看"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
4751
switch (index) {
4852
case 0:{
53+
[weakSelf goToCommitsVC];
54+
}
55+
break;
56+
case 1:{
4957
[weakSelf.navigationController.viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
5058
if (![obj isKindOfClass:[weakSelf class]]) {
5159
if ([obj isKindOfClass:[ProjectViewController class]]) {
@@ -100,4 +108,11 @@ - (void)goToVCWith:(CodeTree_File *)codeTreeFile andRef:(NSString *)ref{
100108
}
101109
}
102110

111+
- (void)goToCommitsVC{
112+
ProjectCommitsViewController *vc = [ProjectCommitsViewController new];
113+
vc.curProject = self.myProject;
114+
vc.curCommits = [Commits commitsWithRef:self.myCodeTree.ref Path:self.myCodeTree.path];
115+
[self.navigationController pushViewController:vc animated:YES];
116+
}
117+
103118
@end

Coding_iOS/Controllers/ProjectCommitsViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88

99
#import "BaseViewController.h"
1010
#import "Project.h"
11+
#import "Commits.h"
1112

1213
@interface ProjectCommitsViewController : BaseViewController
1314
@property (strong, nonatomic) Project *curProject;
15+
@property (strong, nonatomic) Commits *curCommits;
16+
@property (strong, nonatomic) NSString *ref, *path;
1417

1518
@end

Coding_iOS/Controllers/ProjectCommitsViewController.m

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,137 @@
77
//
88

99
#import "ProjectCommitsViewController.h"
10+
#import "CommitListCell.h"
11+
12+
#import "ODRefreshControl.h"
13+
#import "SVPullToRefresh.h"
14+
15+
#import "Coding_NetAPIManager.h"
16+
17+
#import "CommitFilesViewController.h"
18+
19+
@interface ProjectCommitsViewController ()
20+
<UITableViewDataSource, UITableViewDelegate>
21+
@property (strong, nonatomic) UITableView *myTableView;
22+
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
23+
24+
@end
1025

1126
@implementation ProjectCommitsViewController
27+
- (void)viewDidLoad{
28+
[super viewDidLoad];
29+
30+
self.title = [NSString stringWithFormat:@"%@:%@", _curCommits.ref, _curCommits.path];
31+
32+
_myTableView = ({
33+
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
34+
tableView.dataSource = self;
35+
tableView.delegate = self;
36+
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
37+
[tableView registerClass:[CommitListCell class] forCellReuseIdentifier:kCellIdentifier_CommitListCell];
38+
[self.view addSubview:tableView];
39+
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
40+
make.edges.equalTo(self.view);
41+
}];
42+
tableView;
43+
});
44+
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
45+
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
46+
47+
__weak typeof(self) weakSelf = self;
48+
[_myTableView addInfiniteScrollingWithActionHandler:^{
49+
[weakSelf refreshMore:YES];
50+
}];
51+
52+
[self refresh];
53+
}
54+
55+
- (void)refresh{
56+
[self refreshMore:NO];
57+
}
58+
59+
- (void)refreshMore:(BOOL)willLoadMore{
60+
if (_curCommits.isLoading) {
61+
return;
62+
}
63+
64+
if (willLoadMore && !_curCommits.canLoadMore) {
65+
[_myTableView.infiniteScrollingView stopAnimating];
66+
return;
67+
}
68+
69+
_curCommits.willLoadMore = willLoadMore;
70+
if (_curCommits.list.count <= 0) {
71+
[self.view beginLoading];
72+
}
73+
__weak typeof(self) weakSelf = self;
74+
75+
[[Coding_NetAPIManager sharedManager] request_Commits:_curCommits withPro:_curProject andBlock:^(id data, NSError *error) {
76+
[weakSelf.view endLoading];
77+
[weakSelf.myRefreshControl endRefreshing];
78+
if (data) {
79+
[weakSelf.curCommits configWithCommits:data];
80+
[weakSelf.myTableView reloadData];
81+
}
82+
[weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(weakSelf.curCommits.list > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
83+
[weakSelf refresh];
84+
}];
85+
}];
86+
}
87+
88+
#pragma mark TableViewHeader
89+
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
90+
return kScaleFrom_iPhone5_Desgin(24);
91+
}
92+
93+
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
94+
ListGroupItem *item = [_curCommits.listGroups objectAtIndex:section];
95+
return [tableView getHeaderViewWithStr:[item.date string_yyyy_MM_dd_EEE] andBlock:^(id obj) {
96+
DebugLog(@"\nitem.date.description :%@", item.date.description);
97+
}];
98+
}
99+
100+
#pragma mark Table
101+
102+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
103+
return _curCommits.listGroups.count;
104+
}
105+
106+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
107+
ListGroupItem *item = [_curCommits.listGroups objectAtIndex:section];
108+
return item.length;
109+
}
110+
111+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
112+
ListGroupItem *item = [_curCommits.listGroups objectAtIndex:indexPath.section];
113+
NSInteger row = indexPath.row + item.location;
114+
Commit *curCommit = [_curCommits.list objectAtIndex:row];
115+
CommitListCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_CommitListCell forIndexPath:indexPath];
116+
cell.curCommit = curCommit;
117+
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:60];
118+
return cell;
119+
}
120+
121+
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
122+
return [CommitListCell cellHeight];
123+
}
124+
125+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
126+
[tableView deselectRowAtIndexPath:indexPath animated:YES];
127+
128+
ListGroupItem *item = [_curCommits.listGroups objectAtIndex:indexPath.section];
129+
NSInteger row = indexPath.row + item.location;
130+
Commit *curCommit = [_curCommits.list objectAtIndex:row];
131+
132+
DebugLog(@"%@", curCommit.fullMessage);
133+
134+
CommitFilesViewController *vc = [CommitFilesViewController new];
135+
vc.curProject = _curProject;
136+
vc.ownerGK = _curProject.owner_user_name;
137+
vc.projectName = _curProject.name;
138+
vc.commitId = curCommit.commitId;
139+
[self.navigationController pushViewController:vc animated:YES];
140+
}
141+
12142

13143
@end

Coding_iOS/Controllers/ProjectViewController.m

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
#import "SettingTextViewController.h"
2929
#import "FolderToMoveViewController.h"
3030
#import "FileViewController.h"
31+
#import "ProjectCommitsViewController.h"
3132

3233
@interface ProjectViewController ()
3334

3435
@property (nonatomic, strong) NSMutableDictionary *projectContentDict;
35-
@property (nonatomic, strong) UIBarButtonItem *navAddBtn;
36+
37+
@property (strong, nonatomic) NSString *codeRef;
3638

3739
//项目成员
3840
@property (strong, nonatomic) ProjectMemberListViewController *proMemberVC;
@@ -118,18 +120,20 @@ - (void)configNavBtnWithMyProject{
118120
}
119121

120122
- (void)configRightBarButtonItemWithViewType:(ProjectViewType)viewType{
121-
if (!_navAddBtn) {
122-
_navAddBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"addBtn_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(navAddBtnClicked)];
123-
}
124-
125-
UIBarButtonItem *shouldBeItem = nil;
123+
UIBarButtonItem *navRightBtn = nil;
126124
if ((viewType == ProjectViewTypeMembers && [[Login curLoginUser].global_key isEqualToString:_myProject.owner_user_name])
127125
|| viewType == ProjectViewTypeTasks
128126
|| viewType == ProjectViewTypeTopics
129-
|| viewType == ProjectViewTypeFiles) {
130-
shouldBeItem = self.navAddBtn;
127+
|| viewType == ProjectViewTypeFiles
128+
|| viewType == ProjectViewTypeCodes) {
129+
navRightBtn = [[UIBarButtonItem alloc]
130+
initWithImage:[UIImage
131+
imageNamed:(viewType == ProjectViewTypeCodes ? @"timeBtn_Nav" : @"addBtn_Nav")]
132+
style:UIBarButtonItemStylePlain
133+
target:self
134+
action:@selector(navRightBtnClicked)];
131135
}
132-
[self.navigationItem setRightBarButtonItem:shouldBeItem animated:YES];
136+
[self.navigationItem setRightBarButtonItem:navRightBtn animated:YES];
133137
}
134138

135139
- (ProjectViewType)viewTypeFromIndex:(NSInteger)index{
@@ -235,6 +239,9 @@ - (void)refreshWithNewIndex:(NSInteger)newIndex{
235239
codeListView.codeTreeFileOfRefBlock = ^(CodeTree_File *curCodeTreeFile, NSString *ref){
236240
[weakSelf goToVCWith:curCodeTreeFile andRef:ref];
237241
};
242+
codeListView.refChangedBlock = ^(NSString *ref){
243+
weakSelf.codeRef = ref;
244+
};
238245
[codeListView addBranchTagButton];
239246
codeListView;
240247
});
@@ -403,7 +410,7 @@ - (void)goToVCWithItem:(HtmlMediaItem *)clickedItem activity:(ProjectActivity *)
403410
}
404411

405412
#pragma mark Mine M
406-
- (void)navAddBtnClicked{
413+
- (void)navRightBtnClicked{
407414
ProjectViewType curViewType = [self viewTypeFromIndex:_curIndex];
408415
switch (curViewType) {
409416
case ProjectViewTypeTasks:
@@ -459,6 +466,12 @@ - (void)navAddBtnClicked{
459466
}];
460467
}];
461468

469+
}
470+
case ProjectViewTypeCodes:{
471+
ProjectCommitsViewController *vc = [ProjectCommitsViewController new];
472+
vc.curProject = self.myProject;
473+
vc.curCommits = [Commits commitsWithRef:self.codeRef? self.codeRef: @"master" Path:@""];
474+
[self.navigationController pushViewController:vc animated:YES];
462475
}
463476
break;
464477
default:
655 Bytes
Loading
453 Bytes
Loading
699 Bytes
Loading
1 Byte
Loading
5 Bytes
Loading

0 commit comments

Comments
 (0)