Skip to content

Commit c3be237

Browse files
committed
讨论改版-0.2
1 parent 527e54c commit c3be237

8 files changed

Lines changed: 51 additions & 42 deletions

File tree

Coding_iOS/Controllers/EditTopicViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef NS_ENUM(NSInteger, TopicEditType) {
1717

1818
@interface EditTopicViewController : BaseViewController
1919

20-
@property (strong, nonatomic) ProjectTopic *myProTopic;
20+
@property (strong, nonatomic) ProjectTopic *curProTopic;
2121
@property (nonatomic, assign) TopicEditType type;
2222

2323
@property (copy, nonatomic) void(^topicChangedBlock)(ProjectTopic *curTopic, TopicEditType type);

Coding_iOS/Controllers/EditTopicViewController.m

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ - (void)loadEditView{
118118
_inputTitleView.textColor = [UIColor colorWithHexString:@"0x222222"];
119119

120120

121-
_inputTitleView.font = [UIFont boldSystemFontOfSize:18];
121+
_inputTitleView.font = [UIFont systemFontOfSize:18];
122122
[_editView addSubview:_inputTitleView];
123123

124124
_inputContentView = [[EaseMarkdownTextView alloc] initWithFrame:CGRectZero];
@@ -161,16 +161,20 @@ - (void)loadEditView{
161161
//内容
162162
@weakify(self);
163163
RAC(self.navigationItem.rightBarButtonItem, enabled) = [RACSignal combineLatest:@[self.inputTitleView.rac_textSignal, self.inputContentView.rac_textSignal] reduce:^id (NSString *title, NSString *content){
164+
//刚开始编辑content的时候,title传过来的总是nil
165+
164166
@strongify(self);
165-
BOOL enabled = ([title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length > 0
166-
&& [content stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length > 0
167-
&& ![title isEqualToString:self.myProTopic.mdTitle]
168-
&& ![content isEqualToString:self.myProTopic.mdContent]);
167+
BOOL enabled = ([self.inputTitleView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length > 0
168+
&& [self.inputContentView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length > 0
169+
&& (![title isEqualToString:self.curProTopic.mdTitle] || ![content isEqualToString:self.curProTopic.mdContent]));
169170
return @(enabled);
170171
}];
171172
_inputTitleView.placeholder = self.type == TopicEditTypeFeedBack? @"反馈标题": @"讨论标题";
172173
[_inputTitleView setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
173174
_inputContentView.placeholder = self.type == TopicEditTypeFeedBack? @"反馈内容": @"讨论内容";
175+
176+
_inputTitleView.text = _curProTopic.mdTitle;
177+
_inputContentView.text = _curProTopic.mdContent;
174178
}
175179
_editView.hidden = NO;
176180
_preview.hidden = YES;
@@ -221,12 +225,12 @@ - (void)previewLoadMDData{
221225
#pragma mark nav_btn
222226

223227
- (void)saveBtnClicked{
224-
self.myProTopic.mdTitle = _inputTitleView.text;
225-
self.myProTopic.mdContent = _inputContentView.text;
228+
self.curProTopic.mdTitle = _inputTitleView.text;
229+
self.curProTopic.mdContent = _inputContentView.text;
226230
if (self.type == TopicEditTypeModify) {
227231
self.navigationItem.rightBarButtonItem.enabled = NO;
228232
@weakify(self);
229-
[[Coding_NetAPIManager sharedManager] request_ModifyProjectTpoic:self.myProTopic andBlock:^(id data, NSError *error) {
233+
[[Coding_NetAPIManager sharedManager] request_ModifyProjectTpoic:self.curProTopic andBlock:^(id data, NSError *error) {
230234
@strongify(self);
231235
self.navigationItem.rightBarButtonItem.enabled = YES;
232236
if (data) {
@@ -239,7 +243,7 @@ - (void)saveBtnClicked{
239243
}else{
240244
self.navigationItem.rightBarButtonItem.enabled = NO;
241245
@weakify(self);
242-
[[Coding_NetAPIManager sharedManager] request_AddProjectTpoic:self.myProTopic andBlock:^(id data, NSError *error) {
246+
[[Coding_NetAPIManager sharedManager] request_AddProjectTpoic:self.curProTopic andBlock:^(id data, NSError *error) {
243247
@strongify(self);
244248
self.navigationItem.rightBarButtonItem.enabled = YES;
245249
if (data) {

Coding_iOS/Controllers/ProjectViewController.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,9 @@ - (void)navAddBtnClicked{
435435
case ProjectViewTypeTopics:
436436
{
437437
EditTopicViewController *vc = [[EditTopicViewController alloc] init];
438-
vc.myProTopic = [ProjectTopic topicWithPro:self.myProject];
438+
vc.curProTopic = [ProjectTopic topicWithPro:self.myProject];
439439
vc.type = TopicEditTypeAdd;
440-
vc.topicChangedBlock = ^(ProjectTopic *topic, TopicEditType type){
441-
442-
};
440+
vc.topicChangedBlock = nil;
443441
[self.navigationController pushViewController:vc animated:YES];
444442
}
445443
break;

Coding_iOS/Controllers/TopicDetailViewController.m

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#import "SVPullToRefresh.h"
2424
#import "EditTaskViewController.h"
2525
#import "WebViewController.h"
26+
#import "EditTopicViewController.h"
2627

2728
@interface TopicDetailViewController ()
2829
@property (strong, nonatomic) UITableView *myTableView;
@@ -70,7 +71,7 @@ - (void)viewDidLoad
7071
tableView;
7172
});
7273
_refreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
73-
[_refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
74+
[_refreshControl addTarget:self action:@selector(refreshTopic) forControlEvents:UIControlEventValueChanged];
7475

7576
//评论
7677
__weak typeof(self) weakSelf = self;
@@ -90,7 +91,7 @@ - (void)viewDidLoad
9091
_myMsgInputView.curProject = _curTopic.project;
9192
_myMsgInputView.commentOfId = _curTopic.id;
9293
}
93-
[self refresh];
94+
[self refreshTopic];
9495
}
9596

9697
- (void)viewWillDisappear:(BOOL)animated{
@@ -117,6 +118,23 @@ - (void)didReceiveMemoryWarning
117118
// Dispose of any resources that can be recreated.
118119
}
119120

121+
#pragma mark nav
122+
- (void)configNavBtn{
123+
[self.navigationItem setRightBarButtonItem:[self.curTopic canEdit]? [UIBarButtonItem itemWithBtnTitle:@"编辑" target:self action:@selector(editBtnClicked)]: nil animated:YES];
124+
}
125+
126+
- (void)editBtnClicked{
127+
EditTopicViewController *vc = [[EditTopicViewController alloc] init];
128+
vc.curProTopic = self.curTopic;
129+
vc.type = TopicEditTypeModify;
130+
131+
__weak typeof(self) weakSelf = self;
132+
vc.topicChangedBlock = ^(ProjectTopic *topic, TopicEditType type){
133+
[weakSelf refreshTopic];
134+
};
135+
[self.navigationController pushViewController:vc animated:YES];
136+
}
137+
120138
#pragma mark UIMessageInputViewDelegate
121139
- (void)messageInputView:(UIMessageInputView *)inputView sendText:(NSString *)text{
122140
[self sendCommentMessage:text];
@@ -139,13 +157,6 @@ - (void)messageInputView:(UIMessageInputView *)inputView heightToBottomChenged:(
139157
}
140158

141159
#pragma mark Refresh M
142-
- (void)refresh{
143-
[self refreshTopic];
144-
__weak typeof(self) weakSelf = self;
145-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
146-
[weakSelf refreshComments];
147-
});
148-
}
149160

150161
- (void)refreshComments{
151162
if (_curTopic.isLoading) {
@@ -163,11 +174,15 @@ - (void)refreshTopic{
163174
[[Coding_NetAPIManager sharedManager] request_ProjectTopic_WithObj:_curTopic andBlock:^(id data, NSError *error) {
164175
[self.refreshControl endRefreshing];
165176
if (data) {
166-
[weakSelf.curTopic configWithRefreshedTopic:data];
177+
weakSelf.curTopic = data;
178+
167179
weakSelf.myMsgInputView.curProject = weakSelf.curTopic.project;
168180
weakSelf.myMsgInputView.commentOfId = _curTopic.id;
169181
weakSelf.myMsgInputView.toUser = nil;
182+
[weakSelf configNavBtn];
183+
170184
[weakSelf.myTableView reloadData];
185+
[weakSelf refreshComments];
171186
}
172187
}];
173188
}

Coding_iOS/Models/ProjectTopic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@
4545
- (NSString *)toCommentsPath;
4646
- (NSDictionary *)toCommentsParams;
4747
- (void)configWithComments:(ProjectTopics *)comments;
48-
- (void)configWithRefreshedTopic:(ProjectTopic *)topic;
4948

5049
- (NSString *)toDoCommentPath;
5150
- (NSDictionary *)toDoCommentParams;
5251
- (void)configWithComment:(ProjectTopic *)comment;
5352

5453
- (NSString *)toDeletePath;
54+
55+
- (BOOL)canEdit;
5556
@end

Coding_iOS/Models/ProjectTopic.m

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,6 @@ - (void)configWithComments:(ProjectTopics *)comments{
9191

9292
}
9393

94-
- (void)configWithRefreshedTopic:(ProjectTopic *)topic{
95-
self.child_count = topic.child_count;
96-
self.content = topic.htmlMedia.contentOrigional;
97-
self.title = topic.title;
98-
self.created_at = topic.created_at;
99-
self.current_user_role_id = topic.current_user_role_id;
100-
self.owner = topic.owner;
101-
self.project = topic.project;
102-
self.owner_id = topic.owner_id;
103-
self.project_id = topic.project_id;
104-
self.updated_at = topic.updated_at;
105-
self.parent_id = topic.parent_id;
106-
}
107-
10894
- (NSString *)toDoCommentPath{
10995
return [NSString stringWithFormat:@"api/project/%d/topic?parent=%d",_project_id.intValue, _id.intValue];
11096
}
@@ -124,4 +110,9 @@ - (NSString *)toDeletePath{
124110
return [NSString stringWithFormat:@"api/topic/%d", self.id.intValue];
125111
}
126112

113+
- (BOOL)canEdit{
114+
return (self.owner_id.integerValue == [Login curLoginUser].id.integerValue // 讨论创建者
115+
|| [Login isOwnerOfProjectWithOwnerId:self.project.owner_id]); //项目创建者
116+
}
117+
127118
@end

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,13 @@ - (void)request_ProjectTopic_WithObj:(ProjectTopic *)proTopic andBlock:(void (^)
704704
[MobClick event:kUmeng_Event_Request label:@"项目讨论详情"];
705705
proTopic.isTopicLoading = YES;
706706
//html详情
707-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:[proTopic toTopicPath] withParams:@{@"": [NSNumber numberWithInteger:0]} withMethodType:Get andBlock:^(id data, NSError *error) {
707+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:[proTopic toTopicPath] withParams:@{@"type": [NSNumber numberWithInteger:0]} withMethodType:Get andBlock:^(id data, NSError *error) {
708708
if (data) {
709709
//markdown详情
710710
id resultData = [data valueForKeyPath:@"data"];
711711
ProjectTopic *resultT = [NSObject objectOfClass:@"ProjectTopic" fromJSON:resultData];
712712

713-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:[proTopic toTopicPath] withParams:@{@"": [NSNumber numberWithInteger:1]} withMethodType:Get andBlock:^(id dataMD, NSError *errorMD) {
713+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:[proTopic toTopicPath] withParams:@{@"type": [NSNumber numberWithInteger:1]} withMethodType:Get andBlock:^(id dataMD, NSError *errorMD) {
714714
if (dataMD) {
715715
resultT.mdTitle = [[dataMD valueForKey:@"data"] valueForKey:@"title"];
716716
resultT.mdContent = [[dataMD valueForKey:@"data"] valueForKey:@"content"];

Coding_iOS/Views/Cell/TopicContentCell.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ - (void)setCurTopic:(ProjectTopic *)curTopic{
124124
[_commentCountLabel setY:curBottomY+2];
125125
_commentCountLabel.text = [NSString stringWithFormat:@"%d条评论", _curTopic.child_count.intValue];
126126
[_commentBtn setY:curBottomY];
127-
if (_curTopic.owner_id.integerValue == [Login curLoginUser].id.integerValue || [Login isOwnerOfProjectWithOwnerId:_curTopic.project.owner_id]) {
127+
if ([_curTopic canEdit]) {
128128
_deleteBtn.hidden = NO;
129129
[_deleteBtn setY:curBottomY];
130130
}else{

0 commit comments

Comments
 (0)