Skip to content

Commit 05c16ac

Browse files
committed
行内评论
1 parent 234a55b commit 05c16ac

12 files changed

Lines changed: 849 additions & 37 deletions

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159
4E53EB5A1AFB090E0034FE1C /* nav_page_unselected@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E53EB581AFB090E0034FE1C /* nav_page_unselected@2x.png */; };
160160
4E59E1D31A5E6B34004DAEEC /* TaskDescriptionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E59E1D21A5E6B34004DAEEC /* TaskDescriptionViewController.m */; };
161161
4E5A66951B268D160007A0AD /* UIView+PressMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E5A66941B268D160007A0AD /* UIView+PressMenu.m */; };
162-
4E5A66991B26EB210007A0AD /* diff.html in Resources */ = {isa = PBXBuildFile; fileRef = 4E5A66981B26EB210007A0AD /* diff.html */; };
163162
4E5C06E81AC2B34800F427C5 /* tipIcon_BranchMember@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E5C06E71AC2B34800F427C5 /* tipIcon_BranchMember@2x.png */; };
164163
4E5C06EB1AC4009100F427C5 /* CannotLoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E5C06EA1AC4009100F427C5 /* CannotLoginViewController.m */; };
165164
4E5C06EE1AC4405300F427C5 /* PasswordViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E5C06ED1AC4405300F427C5 /* PasswordViewController.m */; };
@@ -247,6 +246,7 @@
247246
4E743E6D1A88A3CC00DADDE5 /* EaseMarkdownTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E743E6C1A88A3CC00DADDE5 /* EaseMarkdownTextView.m */; };
248247
4E743E6F1A88ABF700DADDE5 /* blankpage_image_Hi@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E743E6E1A88ABF700DADDE5 /* blankpage_image_Hi@2x.png */; };
249248
4E753D441B8AFDEC003A00B9 /* FileEditViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E753D431B8AFDEC003A00B9 /* FileEditViewController.m */; };
249+
4E753D481B8DA099003A00B9 /* diff-ios.html in Resources */ = {isa = PBXBuildFile; fileRef = 4E753D471B8DA099003A00B9 /* diff-ios.html */; };
250250
4E76D4DE1A5A7B4A0094A35E /* text_clear_btn@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E76D4DD1A5A7B4A0094A35E /* text_clear_btn@2x.png */; };
251251
4E787DE21B0329B300F06E83 /* ProjectLineNote.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E787DE11B0329B300F06E83 /* ProjectLineNote.m */; };
252252
4E787DE51B03342000F06E83 /* ProjectActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E787DE41B03342000F06E83 /* ProjectActivity.m */; };
@@ -1123,7 +1123,6 @@
11231123
4E59E1D21A5E6B34004DAEEC /* TaskDescriptionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TaskDescriptionViewController.m; sourceTree = "<group>"; };
11241124
4E5A66931B268D160007A0AD /* UIView+PressMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+PressMenu.h"; sourceTree = "<group>"; };
11251125
4E5A66941B268D160007A0AD /* UIView+PressMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+PressMenu.m"; sourceTree = "<group>"; };
1126-
4E5A66981B26EB210007A0AD /* diff.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = diff.html; sourceTree = "<group>"; };
11271126
4E5C06E71AC2B34800F427C5 /* tipIcon_BranchMember@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tipIcon_BranchMember@2x.png"; sourceTree = "<group>"; };
11281127
4E5C06E91AC4009100F427C5 /* CannotLoginViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CannotLoginViewController.h; sourceTree = "<group>"; };
11291128
4E5C06EA1AC4009100F427C5 /* CannotLoginViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CannotLoginViewController.m; sourceTree = "<group>"; };
@@ -1246,6 +1245,7 @@
12461245
4E743E6E1A88ABF700DADDE5 /* blankpage_image_Hi@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "blankpage_image_Hi@2x.png"; sourceTree = "<group>"; };
12471246
4E753D421B8AFDEC003A00B9 /* FileEditViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileEditViewController.h; sourceTree = "<group>"; };
12481247
4E753D431B8AFDEC003A00B9 /* FileEditViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileEditViewController.m; sourceTree = "<group>"; };
1248+
4E753D471B8DA099003A00B9 /* diff-ios.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "diff-ios.html"; sourceTree = "<group>"; };
12491249
4E76D4DD1A5A7B4A0094A35E /* text_clear_btn@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "text_clear_btn@2x.png"; sourceTree = "<group>"; };
12501250
4E787DE01B0329B300F06E83 /* ProjectLineNote.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProjectLineNote.h; sourceTree = "<group>"; };
12511251
4E787DE11B0329B300F06E83 /* ProjectLineNote.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProjectLineNote.m; sourceTree = "<group>"; };
@@ -4062,7 +4062,7 @@
40624062
children = (
40634063
4EE083DD1ADB739300CA342E /* modules */,
40644064
4EE083DB1ADB736800CA342E /* service_terms.html */,
4065-
4E5A66981B26EB210007A0AD /* diff.html */,
4065+
4E753D471B8DA099003A00B9 /* diff-ios.html */,
40664066
8E1C3DF519E7F4CA00EF3032 /* address.json */,
40674067
);
40684068
path = Resources;
@@ -4890,7 +4890,6 @@
48904890
8EA6D19219E240C40076D59C /* timeline_icon_unread@2x.png in Resources */,
48914891
4E095A6D1B69F920008DC439 /* banner__page_selected@2x.png in Resources */,
48924892
4E217F141A70EDC700F6DF88 /* SVWebViewControllerActivitySafari-iPad@2x.png in Resources */,
4893-
4E5A66991B26EB210007A0AD /* diff.html in Resources */,
48944893
4EF91F641B00B62B0021C951 /* icon_not_locationed@2x.png in Resources */,
48954894
4E6383EA1B32791600D98648 /* checkbox_unchecked@2x.png in Resources */,
48964895
8EA6D19119E240C40076D59C /* timeline_icon_read@2x.png in Resources */,
@@ -4926,6 +4925,7 @@
49264925
8EA6D18519E240C40076D59C /* privatemessage_normal@2x.png in Resources */,
49274926
8EA6D18219E240C40076D59C /* splitlineImg@2x.png in Resources */,
49284927
8EA6D18119E240C40076D59C /* sex_woman_icon@2x.png in Resources */,
4928+
4E753D481B8DA099003A00B9 /* diff-ios.html in Resources */,
49294929
8E7612F41A08B1EA005BE797 /* tipIcon_TaskComment@2x.png in Resources */,
49304930
4E94C50C1B4D334B00EB668A /* pop_Task@2x.png in Resources */,
49314931
4E6383E01B32676600D98648 /* taskDeadline@2x.png in Resources */,

Coding_iOS/Controllers/CommitFilesViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
279279
vc.curProject = _curProject;
280280
vc.commitId = curFileChange.commitId;
281281
vc.filePath = curFileChange.path;
282+
vc.noteable_id = nil;
282283

283284
[self.navigationController pushViewController:vc animated:YES];
284285
}else if (indexPath.section == _listGroupKeys.count+ 1 && _curCommitInfo.commitComments.count > 0){

Coding_iOS/Controllers/FileChangeDetailViewController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
@interface FileChangeDetailViewController : BaseViewController
1414
@property (strong, nonatomic) NSString *linkUrlStr;
15+
@property (strong, nonatomic) NSString *noteable_id;
1516

1617
@property (strong, nonatomic) Project *curProject;
1718
@property (strong, nonatomic) NSString *commitId, *filePath;

Coding_iOS/Controllers/FileChangeDetailViewController.m

Lines changed: 95 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
#import "Coding_NetAPIManager.h"
1111
#import "WebContentManager.h"
1212
#import "CodeViewController.h"
13+
#import "AddMDCommentViewController.h"
1314

1415

1516
@interface FileChangeDetailViewController ()<UIWebViewDelegate>
1617
@property (strong, nonatomic) UIWebView *webContentView;
1718
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
18-
@property (strong, nonatomic) NSDictionary *rawData;
19+
@property (strong, nonatomic) NSDictionary *rawData, *commentsData;
1920
@property (strong, nonatomic) NSString *linkRef;
2021
@end
2122

@@ -50,15 +51,13 @@ - (void)viewDidLoad {
5051

5152
- (void)refresh{
5253
[self.view beginLoading];
53-
54-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:self.linkUrlStr withParams:nil withMethodType:Get andBlock:^(id data, NSError *error) {
54+
[[Coding_NetAPIManager sharedManager] request_FileDiffDetailWithPath:self.linkUrlStr andBlock:^(id data, NSError *error) {
5555
[self.view endLoading];
56-
57-
data = [data valueForKey:@"data"];
5856
if (data) {
59-
self.rawData = @{@"data" : data};
60-
if ([data isKindOfClass:[NSDictionary class]]) {
61-
self.linkRef = [data objectForKey:@"linkRef"];
57+
self.rawData = data[@"rawData"];
58+
self.commentsData = data[@"commentsData"];
59+
if ([self.rawData isKindOfClass:[NSDictionary class]]) {
60+
self.linkRef = self.rawData[@"data"][@"linkRef"];
6261
}
6362
[self refreshUI];
6463
}
@@ -70,9 +69,13 @@ - (void)refresh{
7069

7170
- (void)refreshUI{
7271
if (self.rawData) {
73-
NSData *JSONData = [NSJSONSerialization dataWithJSONObject:self.rawData options:NSJSONWritingPrettyPrinted error:nil];
74-
NSString *contentStr = [[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding];
75-
contentStr = [WebContentManager diffPatternedWithContent:contentStr];
72+
NSData *JSONDataRaw = [NSJSONSerialization dataWithJSONObject:self.rawData options:NSJSONWritingPrettyPrinted error:nil];
73+
NSString *contentStr = [[NSString alloc] initWithData:JSONDataRaw encoding:NSUTF8StringEncoding];
74+
75+
NSData *JSONDataComments = [NSJSONSerialization dataWithJSONObject:self.commentsData options:NSJSONWritingPrettyPrinted error:nil];
76+
NSString *commentsStr = [[NSString alloc] initWithData:JSONDataComments encoding:NSUTF8StringEncoding];
77+
78+
contentStr = [WebContentManager diffPatternedWithContent:contentStr andComments:commentsStr];
7679
[self.webContentView loadHTMLString:contentStr baseURL:nil];
7780
}
7881
self.navigationItem.rightBarButtonItem = self.linkRef.length > 0? [UIBarButtonItem itemWithBtnTitle:@"查看文件" target:self action:@selector(rightBarButtonClicked:)]: nil;
@@ -96,7 +99,14 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
9699
#pragma mark UIWebViewDelegate
97100
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
98101
DebugLog(@"strLink=[%@]",request.URL.absoluteString);
99-
return YES;
102+
NSString *strLink = request.URL.absoluteString;
103+
if ([strLink hasPrefix:@"coding://"]) {
104+
[self handleURL:request.URL];
105+
return NO;
106+
}
107+
else{
108+
return YES;
109+
}
100110
}
101111
- (void)webViewDidStartLoad:(UIWebView *)webView{
102112
[_activityIndicator startAnimating];
@@ -111,4 +121,77 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
111121
else
112122
DebugLog(@"%@", error.description);
113123
}
124+
#pragma mark Clicked One Line
125+
- (void)handleURL:(NSURL *)curURL{
126+
NSMutableDictionary *params = [self getParamsFromURLStr:curURL.absoluteString];
127+
if ([curURL.absoluteString hasPrefix:@"coding://line_note?"]) {
128+
NSString *title = [NSString stringWithFormat:@"Line %@", params[@"line"]];
129+
[[UIActionSheet bk_actionSheetCustomWithTitle:title buttonTitles:@[@"添加评论"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
130+
if (index == 0) {
131+
[self goToAddCommentWithParams:params];
132+
}
133+
}] showInView:self.view];
134+
}else if ([curURL.absoluteString hasPrefix:@"coding://line_note_comment?"]){
135+
NSString *title = [NSString stringWithFormat:@"%@ 的评论", params[@"clicked_user_name"]];
136+
BOOL belongToSelf = [params[@"clicked_user_name"] isEqualToString:[Login curLoginUser].global_key];
137+
[[UIActionSheet bk_actionSheetCustomWithTitle:title buttonTitles:@[belongToSelf? @"删除": @"回复"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
138+
if (index == 0) {
139+
if (belongToSelf) {
140+
[self doDeleteCommentWithParams:params];
141+
}else{
142+
[self goToAddCommentWithParams:params];
143+
}
144+
}
145+
}] showInView:self.view];
146+
}
147+
}
148+
149+
- (NSMutableDictionary *)getParamsFromURLStr:(NSString *)urlStr{
150+
urlStr = [[urlStr componentsSeparatedByString:@"?"] lastObject];
151+
NSMutableDictionary *params = [NSMutableDictionary new];
152+
for (NSString *param in [urlStr componentsSeparatedByString:@"&"]) {
153+
NSArray *elts = [param componentsSeparatedByString:@"="];
154+
if([elts count] < 2) continue;
155+
[params setObject:[elts objectAtIndex:1] forKey:[elts objectAtIndex:0]];
156+
}
157+
return params;
158+
}
159+
160+
- (void)goToAddCommentWithParams:(NSMutableDictionary *)params{
161+
AddMDCommentViewController *vc = [AddMDCommentViewController new];
162+
vc.curProject = _curProject;
163+
164+
NSString *requestPath = [[self.linkUrlStr componentsSeparatedByString:@"/git"] firstObject];
165+
requestPath = [requestPath stringByAppendingString:@"/git/line_notes"];
166+
vc.requestPath = requestPath;
167+
168+
vc.contentStr = params[@"clicked_user_name"]? [NSString stringWithFormat:@"@%@ ", params[@"clicked_user_name"]] : @"";
169+
170+
[params removeObjectsForKeys:@[@"clicked_line_note_id", @"clicked_user_name", @"clicked_user_name"]];
171+
if (self.noteable_id) {
172+
params[@"noteable_id"] = self.noteable_id;
173+
}
174+
if ([params[@"noteable_type"] hasSuffix:@"Request"]) {
175+
params[@"noteable_type"] = [params[@"noteable_type"] stringByAppendingString:@"Bean"];
176+
}
177+
vc.requestParams = params;
178+
179+
@weakify(self);
180+
vc.completeBlock = ^(id data){
181+
@strongify(self);
182+
if (data) {
183+
[self refresh];
184+
}
185+
};
186+
[self.navigationController pushViewController:vc animated:YES];
187+
}
188+
189+
- (void)doDeleteCommentWithParams:(NSMutableDictionary *)params{
190+
NSString *requestPath = [[self.linkUrlStr componentsSeparatedByString:@"/git"] firstObject];
191+
requestPath = [requestPath stringByAppendingFormat:@"/git/line_notes/%@", params[@"clicked_line_note_id"]];
192+
[[Coding_NetAPIManager sharedManager] request_DeleteLineNoteWithPath:requestPath andBlock:^(id data, NSError *error) {
193+
[self refresh];
194+
}];
195+
}
196+
114197
@end

Coding_iOS/Controllers/FileVersionsViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ - (void)viewDidLoad
4040
{
4141
[super viewDidLoad];
4242
// Do any additional setup after loading the view.
43-
self.title = self.curFile.name;
43+
self.title = @"历史版本";
4444

4545
// 添加myTableView
4646
_myTableView = ({

Coding_iOS/Controllers/MRPRFilesViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
174174
vc.curProject = _curProject;
175175
vc.commitId = curFileChange.commitId;
176176
vc.filePath = curFileChange.path;
177+
vc.noteable_id = _curMRPR.id.stringValue;
177178
[self.navigationController pushViewController:vc animated:YES];
178179
}
179180
}

0 commit comments

Comments
 (0)