Skip to content

Commit c066dc6

Browse files
committed
讨论详情(添加标签)
1 parent c6f1237 commit c066dc6

14 files changed

Lines changed: 210 additions & 88 deletions

Coding_iOS/Controllers/EditLabelViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
@interface EditLabelViewController : BaseViewController
1313

1414
@property (weak, nonatomic) ProjectTopic *curProTopic;
15+
@property (assign, nonatomic) BOOL isSaveChange;
16+
17+
@property (copy, nonatomic) void(^topicChangedBlock)();
1518

1619
@end

Coding_iOS/Controllers/EditLabelViewController.m

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
@interface EditLabelViewController () <UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate, UITextFieldDelegate>
2121
{
2222
NSString *_tempLabel;
23+
NSMutableArray *_tempArray;
2324
}
2425
@property (strong, nonatomic) NSMutableArray *labels;
2526

@@ -86,6 +87,12 @@ - (void)dealloc
8687
_myTableView.dataSource = nil;
8788
}
8889

90+
- (void)setCurProTopic:(ProjectTopic *)curProTopic
91+
{
92+
_curProTopic = curProTopic;
93+
_tempArray = [NSMutableArray arrayWithArray:_curProTopic.mdLabels];
94+
}
95+
8996
- (void)sendRequest
9097
{
9198
[self.view beginLoading];
@@ -95,7 +102,20 @@ - (void)sendRequest
95102
[weakSelf.view endLoading];
96103
if (data) {
97104
[_labels addObjectsFromArray:data];
98-
105+
for (ProjectTopicLabel *lbl in _labels) {
106+
for (ProjectTopicLabel *tLbl in _curProTopic.mdLabels) {
107+
if ([lbl.id integerValue] == [tLbl.id integerValue]) {
108+
tLbl.name = lbl.name;
109+
break;
110+
}
111+
}
112+
for (ProjectTopicLabel *tLbl in _tempArray) {
113+
if ([lbl.id integerValue] == [tLbl.id integerValue]) {
114+
tLbl.name = lbl.name;
115+
break;
116+
}
117+
}
118+
}
99119
[weakSelf.myTableView reloadData];
100120
}
101121
}];
@@ -115,22 +135,39 @@ - (NSString *)toDelPath:(NSInteger)index
115135
#pragma mark - click
116136
- (void)okBtnClick
117137
{
138+
_curProTopic.mdLabels = _tempArray;
118139

119-
[self.navigationController popViewControllerAnimated:YES];
140+
self.navigationItem.rightBarButtonItem.enabled = NO;
141+
if (_isSaveChange) {
142+
@weakify(self);
143+
[[Coding_NetAPIManager sharedManager] request_ModifyProjectTpoic:self.curProTopic andBlock:^(id data, NSError *error) {
144+
@strongify(self);
145+
self.navigationItem.rightBarButtonItem.enabled = YES;
146+
if (data) {
147+
_curProTopic.labels = [NSMutableArray arrayWithArray:_curProTopic.mdLabels];
148+
if (self.topicChangedBlock) {
149+
self.topicChangedBlock();
150+
}
151+
[self.navigationController popViewControllerAnimated:YES];
152+
}
153+
}];
154+
} else {
155+
[self.navigationController popViewControllerAnimated:YES];
156+
}
120157
}
121158

122159
- (void)addBtnClick:(UIButton *)sender
123160
{
124161
[_mCurrentTextField resignFirstResponder];
125162
if (_tempLabel.length > 0) {
126163
__weak typeof(self) weakSelf = self;
127-
[[Coding_NetAPIManager sharedManager] request_ProjectTopicLabel_Add_WithPath:[self toLabelPath] withParams:@{@"name" : [_tempLabel aliasedString], @"color" : @"#d8f3e4"} andBlock:^(id data, NSError *error) {
164+
[[Coding_NetAPIManager sharedManager] request_ProjectTopicLabel_Add_WithPath:[self toLabelPath] withParams:@{@"name" : [_tempLabel aliasedString], @"color" : kColorLabelBg} andBlock:^(id data, NSError *error) {
128165
if (!error) {
129166
ProjectTopicLabel *ptLabel = [[ProjectTopicLabel alloc] init];
130167
ptLabel.name = _tempLabel;
131168
ptLabel.id = data;
132169
ptLabel.owner_id = _curProTopic.project_id;
133-
ptLabel.color = @"#d8f3e4";
170+
ptLabel.color = kColorLabelBg;
134171
[_labels addObject:ptLabel];
135172
[weakSelf.myTableView reloadData];
136173
_tempLabel = @"";
@@ -172,6 +209,15 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
172209
EditLabelCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_EditLabelCell forIndexPath:indexPath];
173210
cell.nameLbl.text = ptLabel.name;
174211

212+
BOOL selected = FALSE;
213+
for (ProjectTopicLabel *lbl in _curProTopic.mdLabels) {
214+
if ([lbl.id integerValue] == [ptLabel.id integerValue]) {
215+
selected = TRUE;
216+
break;
217+
}
218+
}
219+
cell.selectBtn.selected = selected;
220+
175221
[cell setRightUtilityButtons:[self rightButtons] WithButtonWidth:[EditLabelCell cellHeight]];
176222
cell.delegate = self;
177223

@@ -202,6 +248,31 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
202248
if (indexPath.section > 0) {
203249
EditLabelCell *cell = (EditLabelCell *)[tableView cellForRowAtIndexPath:indexPath];
204250
cell.selectBtn.selected = !cell.selectBtn.selected;
251+
252+
ProjectTopicLabel *lbl = _labels[indexPath.row];
253+
254+
if (cell.selectBtn.selected) {
255+
BOOL add = TRUE;
256+
for (ProjectTopicLabel *tempLbl in _tempArray) {
257+
if ([tempLbl.id integerValue] == [lbl.id integerValue]) {
258+
add = FALSE;
259+
break;
260+
}
261+
}
262+
if (add) {
263+
[_tempArray addObject:lbl];
264+
self.navigationItem.rightBarButtonItem.enabled = YES;
265+
}
266+
} else {
267+
for (ProjectTopicLabel *tempLbl in _tempArray) {
268+
if ([tempLbl.id integerValue] == [lbl.id integerValue]) {
269+
[_tempArray removeObject:tempLbl];
270+
self.navigationItem.rightBarButtonItem.enabled = YES;
271+
272+
break;
273+
}
274+
}
275+
}
205276
}
206277
}
207278

@@ -255,38 +326,55 @@ - (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityBut
255326
NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell];
256327

257328
if (index == 0) {
258-
[self renameLabel:indexPath.row];
329+
[self renameBtnClick:indexPath.row];
259330
} else {
260331
__weak typeof(self) weakSelf = self;
261332
ProjectTopicLabel *ptLabel = [_labels objectAtIndex:indexPath.row];
262333
NSString *tip = [NSString stringWithFormat:@"确定要删除标签:%@", ptLabel.name];
263334
UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:tip buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
264335
if (index == 0) {
265-
[weakSelf deleteLabel:indexPath.row];
336+
[weakSelf deleteBtnClick:indexPath.row];
266337
}
267338
}];
268339
[actionSheet showInView:self.view];
269340
}
270341
}
271342

272-
- (void)renameLabel:(NSInteger)index
343+
- (void)renameBtnClick:(NSInteger)index
273344
{
274345
ResetLabelViewController *vc = [[ResetLabelViewController alloc] init];
275346
vc.ptLabel = [_labels objectAtIndex:index];
347+
vc.curProTopic = _curProTopic;
276348
[self.navigationController pushViewController:vc animated:YES];
277349
}
278350

279-
- (void)deleteLabel:(NSInteger)index
351+
- (void)deleteBtnClick:(NSInteger)index
280352
{
281353
__weak typeof(self) weakSelf = self;
282354
[[Coding_NetAPIManager sharedManager] request_ProjectTopicLabel_Del_WithPath:[self toDelPath:index] andBlock:^(id data, NSError *error) {
283355
if (!error) {
284-
[weakSelf.labels removeObjectAtIndex:index];
285-
[weakSelf.myTableView reloadData];
356+
[weakSelf deleteLabel:index];
286357
}
287358
}];
288359
}
289360

361+
- (void)deleteLabel:(NSInteger)index
362+
{
363+
ProjectTopicLabel *lbl = _labels[index];
364+
for (ProjectTopicLabel *tempLbl in _tempArray) {
365+
if ([tempLbl.id integerValue] == [lbl.id integerValue]) {
366+
[_tempArray removeObject:tempLbl];
367+
self.navigationItem.rightBarButtonItem.enabled = YES;
368+
break;
369+
}
370+
}
371+
[self.labels removeObjectAtIndex:index];
372+
[self.myTableView reloadData];
373+
}
374+
375+
- (void)renameLabel:(NSInteger)index
376+
{
377+
}
290378
#pragma mark - UITextFieldDelegate
291379
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
292380
{

Coding_iOS/Controllers/EditTopicViewController.m

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "WebContentManager.h"
1414
#import "EditLabelViewController.h"
1515
#import "TopicPreviewCell.h"
16+
#import "ProjectTopicLabel.h"
1617

1718
@interface EditTopicViewController ()<UIWebViewDelegate, UITableViewDataSource, UITableViewDelegate>
1819
{
@@ -72,7 +73,7 @@ - (void)viewDidLoad
7273
self.navigationItem.titleView = _segmentedControl;
7374
}
7475

75-
[self.navigationItem setRightBarButtonItem:[UIBarButtonItem itemWithBtnTitle:self.type == TopicEditTypeFeedBack? @"发送": @"完成" target:self action:@selector(saveBtnClicked)] animated:YES];
76+
[self.navigationItem setRightBarButtonItem:[UIBarButtonItem itemWithBtnTitle:self.type == TopicEditTypeFeedBack ? @"发送" : @"完成" target:self action:@selector(saveBtnClicked)] animated:YES];
7677
self.navigationItem.rightBarButtonItem.enabled = NO;
7778

7879
[[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardWillChangeFrameNotification object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification *aNotification) {
@@ -87,6 +88,17 @@ - (void)viewDidLoad
8788
self.curIndex = 0;
8889
}
8990

91+
- (void)viewWillAppear:(BOOL)animated
92+
{
93+
[super viewWillAppear:animated];
94+
95+
if (_curIndex == 0) {
96+
[self loadEditView];
97+
} else {
98+
[self loadPreview];
99+
}
100+
}
101+
90102
- (void)didReceiveMemoryWarning
91103
{
92104
[super didReceiveMemoryWarning];
@@ -122,31 +134,31 @@ - (void)loadLabelView
122134
if (_curProTopic.mdLabels.count > 0) {
123135
CGFloat x = 0.0f;
124136
CGFloat y = 0.0f;
125-
CGFloat limitW = kScreen_Width - kPaddingLeftWidth * 2 - 44;
137+
CGFloat limitW = kScreen_Width - kPaddingLeftWidth - 44;
126138

127-
for (NSString *str in _curProTopic.mdLabels) {
139+
for (ProjectTopicLabel *label in _curProTopic.mdLabels) {
128140
UILabel *tLbl = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 0, 0)];
129141

130142
tLbl.font = [UIFont systemFontOfSize:12];
131-
tLbl.text = str;
132-
tLbl.textColor = [UIColor colorWithHexString:@"0x3bbd79"];
143+
tLbl.text = label.name;
144+
tLbl.textColor = kColorLabelText;
133145
tLbl.textAlignment = NSTextAlignmentCenter;
134-
tLbl.backgroundColor = [UIColor redColor];
135-
tLbl.layer.cornerRadius = 5;
136-
146+
tLbl.layer.cornerRadius = 10;
147+
tLbl.layer.backgroundColor = kColorLabelBgColor.CGColor;
148+
137149
[tLbl sizeToFit];
138150

139-
CGFloat width = tLbl.frame.size.width + 10;
151+
CGFloat width = tLbl.frame.size.width + 20;
140152
if (x + width > limitW) {
141-
y += 20.0f;
153+
y += 26.0f;
142154
x = 0.0f;
143155
}
144-
[tLbl setFrame:CGRectMake(x, y, width - 4, 20 - 4)];
156+
[tLbl setFrame:CGRectMake(x, y, width - 4, 20)];
145157
x += width;
146158

147159
[_labelView addSubview:tLbl];
148160
}
149-
_labelH = y + 20;
161+
_labelH = y + 26;
150162

151163
} else {
152164
UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
@@ -156,7 +168,7 @@ - (void)loadLabelView
156168

157169
tLbl.font = [UIFont systemFontOfSize:14];
158170
tLbl.text = @"标签";
159-
tLbl.textColor = [UIColor colorWithHexString:@"0x3bbd79"];
171+
tLbl.textColor = kColorLabelText;
160172

161173
[_labelView addSubview:iconImg];
162174
[_labelView addSubview:tLbl];
@@ -217,6 +229,7 @@ - (void)loadEditView
217229
_inputContentView.text = _curProTopic.mdContent;
218230
}
219231

232+
220233
// 布局
221234
_inputContentView.textContainerInset = UIEdgeInsetsMake(10, kPaddingLeftWidth - 5, 8, kPaddingLeftWidth - 5);
222235

Coding_iOS/Controllers/ResetLabelViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ - (void)okBtnClick
7979
{
8080
if (_tempStr.length > 0) {
8181
__weak typeof(self) weakSelf = self;
82-
[[Coding_NetAPIManager sharedManager] request_ProjectTopicLabel_Modify_WithPath:[self toModifyPath] withParams:@{@"name" : _tempStr, @"color" : @"#d8f3e4", @"label_id" : _ptLabel.id} andBlock:^(id data, NSError *error) {
82+
[[Coding_NetAPIManager sharedManager] request_ProjectTopicLabel_Modify_WithPath:[self toModifyPath] withParams:@{@"name" : _tempStr, @"color" : kColorLabelBg, @"label_id" : _ptLabel.id} andBlock:^(id data, NSError *error) {
8383
if (!error) {
8484
[weakSelf.navigationController popViewControllerAnimated:YES];
8585
}

Coding_iOS/Controllers/TopicDetailViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313

1414
@interface TopicDetailViewController : BaseViewController<UITableViewDataSource, UITableViewDelegate, UIMessageInputViewDelegate>
15+
1516
@property (strong, nonatomic) ProjectTopic *curTopic;
17+
1618
@property (nonatomic, copy) void (^deleteTopicBlock)(ProjectTopic *);
19+
1720
- (void)refreshTopic;
1821
@end

Coding_iOS/Controllers/TopicDetailViewController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ - (void)addtitleBtnClick
125125
{
126126
EditLabelViewController *vc = [[EditLabelViewController alloc] init];
127127
vc.curProTopic = self.curTopic;
128+
vc.isSaveChange = TRUE;
129+
__weak typeof(self) weakSelf = self;
130+
vc.topicChangedBlock = ^(){
131+
[weakSelf refreshTopic];
132+
};
128133
[self.navigationController pushViewController:vc animated:YES];
129134
}
130135

Coding_iOS/Models/ProjectTopic.m

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "ProjectTopic.h"
1010
#import "Login.h"
11+
#import "ProjectTopicLabel.h"
1112

1213
@implementation ProjectTopic
1314

@@ -62,34 +63,35 @@ + (ProjectTopic *)topicWithId:(NSNumber *)topicId{
6263
return topic;
6364
}
6465

65-
- (NSString *)toTopicPath{
66+
- (NSString *)toTopicPath
67+
{
6668
return [NSString stringWithFormat:@"api/topic/%d", self.id.intValue];
6769
}
6870

6971
- (NSDictionary *)toEditParams
7072
{
71-
NSMutableString *tempStr = [[NSMutableString alloc] initWithString:@""];
72-
for (NSString *lbl in _mdLabels) {
73-
[tempStr appendString:lbl];
73+
NSMutableArray *tempAry = [NSMutableArray arrayWithCapacity:_mdLabels.count];
74+
for (ProjectTopicLabel *lbl in _mdLabels) {
75+
[tempAry addObject:lbl.id];
7476
}
7577
return @{@"title" : [_mdTitle aliasedString],
7678
@"content" : [_mdContent aliasedString],
77-
@"label" : tempStr};
79+
@"label" : tempAry};
7880
}
7981

80-
- (NSString *)toAddTopicPath{
82+
- (NSString *)toAddTopicPath
83+
{
8184
return [NSString stringWithFormat:@"api/project/%d/topic?parent=0", [self.project_id intValue]];
8285
}
8386
- (NSDictionary *)toAddTopicParams
8487
{
85-
//NSMutableString *tempStr = [[NSMutableString alloc] initWithString:@""];
86-
NSMutableString *tempStr = [[NSMutableString alloc] initWithString:@"Bug, Feature"];
87-
for (NSString *lbl in _mdLabels) {
88-
[tempStr appendString:lbl];
88+
NSMutableArray *tempAry = [NSMutableArray arrayWithCapacity:_mdLabels.count];
89+
for (ProjectTopicLabel *lbl in _mdLabels) {
90+
[tempAry addObject:lbl.id];
8991
}
9092
return @{@"title" : [_mdTitle aliasedString],
9193
@"content" : [_mdContent aliasedString],
92-
@"labels" : [tempStr aliasedString]};
94+
@"labels" : tempAry};
9395
}
9496

9597
- (NSString *)toCommentsPath{

Coding_iOS/Models/ProjectTopicLabel.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ - (instancetype)init
2020
_type = [NSNumber numberWithInteger:1];
2121

2222
_name = @"";
23-
_color = @"#d8f3e4";
23+
_color = kColorLabelBg;
2424
}
2525
return self;
2626
}

0 commit comments

Comments
 (0)