forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMRPRAcceptViewController.m
More file actions
150 lines (122 loc) · 5.23 KB
/
MRPRAcceptViewController.m
File metadata and controls
150 lines (122 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// MRPRAcceptViewController.m
// Coding_iOS
//
// Created by Ease on 15/6/1.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "MRPRAcceptViewController.h"
#import "TPKeyboardAvoidingTableView.h"
#import "Coding_NetAPIManager.h"
#import "MRPRAcceptEditCell.h"
#import "TextCheckMarkCell.h"
@interface MRPRAcceptViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) UITableView *myTableView;
@property (strong, nonatomic) UIButton *mergeBtn;
@property (strong, nonatomic) MRPR *curMRPR;
@end
@implementation MRPRAcceptViewController
- (void)viewDidLoad{
[super viewDidLoad];
self.title = @"合并此请求";
self.curMRPR = self.curMRPRInfo.mrpr;
self.curMRPR.del_source_branch = YES;
self.curMRPR.can_edit_src_branch = ([_curMRPR isMR] && _curMRPRInfo.can_edit_src_branch.boolValue);
NSString *fromStr, *toStr;
if (_curMRPR.isMR) {
fromStr = [NSString stringWithFormat:@" %@ ", _curMRPR.srcBranch];
toStr = [NSString stringWithFormat:@" %@ ", _curMRPR.desBranch];
}else{
fromStr = [NSString stringWithFormat:@" %@ : %@ ", _curMRPR.src_owner_name, _curMRPR.srcBranch];
toStr = [NSString stringWithFormat:@" %@ : %@ ", _curMRPR.des_owner_name, _curMRPR.desBranch];
}
self.curMRPR.message = [NSString stringWithFormat:@"Accept Merge Request #%@ : (%@ -> %@)", _curMRPR.iid.stringValue, fromStr, toStr];
_myTableView = ({
UITableView *tableView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.backgroundColor = kColorTableSectionBg;
tableView.dataSource = self;
tableView.delegate = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[tableView registerClass:[MRPRAcceptEditCell class] forCellReuseIdentifier:kCellIdentifier_MRPRAcceptEditCell];
[tableView registerClass:[TextCheckMarkCell class] forCellReuseIdentifier:kCellIdentifier_TextCheckMarkCell];
[self.view addSubview:tableView];
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
tableView;
});
_myTableView.tableFooterView = [self tableFooterView];
}
#pragma mark TableM
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if ([_curMRPR isMR] && _curMRPRInfo.can_edit_src_branch.boolValue) {
return 2;
}else{
return 1;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
MRPRAcceptEditCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_MRPRAcceptEditCell forIndexPath:indexPath];
cell.contentTextView.text = _curMRPR.message;
cell.contentChangedBlock = ^(NSString *messageStr){
_curMRPR.message = messageStr;
_mergeBtn.enabled = messageStr.length > 0;
};
return cell;
}else{
TextCheckMarkCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TextCheckMarkCell forIndexPath:indexPath];
cell.textStr = @"删除原分支";
cell.checked = _curMRPR.del_source_branch;
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CGFloat cellHeight = 0;
if (indexPath.section == 0) {
cellHeight = [MRPRAcceptEditCell cellHeight];
}else{
cellHeight = [TextCheckMarkCell cellHeight];
}
return cellHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 20)];
headerView.backgroundColor = kColorTableSectionBg;
return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 20.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.5;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 1 && indexPath.row == 0) {
_curMRPR.del_source_branch = !_curMRPR.del_source_branch;
[_myTableView reloadData];
}
}
- (UIView*)tableFooterView{
UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 90)];
_mergeBtn = [UIButton buttonWithStyle:StrapInfoStyle andTitle:@"确认合并" andFrame:CGRectMake(10, 0, kScreen_Width-10*2, 44) target:self action:@selector(mergeBtnClicked:)];
[_mergeBtn setCenter:footerV.center];
[footerV addSubview:_mergeBtn];
return footerV;
}
- (void)mergeBtnClicked:(id)sender{
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_MRPRAccept:_curMRPR andBlock:^(id data, NSError *error) {
if (data) {
if (weakSelf.completeBlock) {
weakSelf.completeBlock(data);
}
[self.navigationController popViewControllerAnimated:YES];
}
}];
}
@end