-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathProjectActivities.m
executable file
·153 lines (133 loc) · 4.13 KB
/
ProjectActivities.m
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
151
152
153
//
// ProjectActivities.m
// Coding_iOS
//
// Created by Ease on 14/12/1.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "ProjectActivities.h"
@implementation ProjectActivities
- (instancetype)init
{
self = [super init];
if (self) {
_listGroups = [[NSMutableArray alloc] init];
_list = [[NSMutableArray alloc] init];
_canLoadMore = YES;
_willLoadMore = _isLoading = NO;
_last_id = kDefaultLastId;
}
return self;
}
+ (ProjectActivities *)proActivitiesWithPro:(Project *)project type:(ProjectActivityType)type{
ProjectActivities *proActs = [[ProjectActivities alloc] init];
proActs.isOfUser = NO;
proActs.curProject = project;
proActs.project_id = project.id;
proActs.curUser = nil;
proActs.user_id = project.owner_id;
switch (type) {
case ProjectActivityTypeAll:
proActs.type = @"all";
break;
case ProjectActivityTypeTask:
proActs.type = @"task";
break;
case ProjectActivityTypeTopic:
proActs.type = @"topic";
break;
case ProjectActivityTypeWiki:
proActs.type = @"wiki";
break;
case ProjectActivityTypeFile:
proActs.type = @"file";
break;
case ProjectActivityTypeCode:
proActs.type = @"code";
break;
case ProjectActivityTypeOther:
proActs.type = @"other";
break;
default:
proActs.type = @"all";
break;
}
return proActs;
}
+ (ProjectActivities *)proActivitiesWithPro:(Project *)project user:(User *)user{
ProjectActivities *proActs = [[ProjectActivities alloc] init];
proActs.isOfUser = YES;
proActs.curProject = project;
proActs.project_id = project.id;
proActs.curUser = user;
proActs.user_id = user.id;
proActs.type = @"user";
return proActs;
}
- (NSString *)toPath{
NSString *path;
if (_isOfUser) {
path = [self toPathOfUser];
}else{
path = [self toPathOfType];
}
return path;
}
- (NSDictionary *)toParams{
NSDictionary *params;
if (_isOfUser) {
params = [self toParamsOfUser];
}else{
params = [self toParamsOfType];
}
return params;
}
- (NSString *)toPathOfType{
return [NSString stringWithFormat:@"api/project/%@/activities", _project_id.stringValue];
}
- (NSDictionary *)toParamsOfType{
return @{@"last_id" : _willLoadMore? self.last_id:kDefaultLastId,
@"user_id" : self.user_id,
@"type" : self.type};
}
- (NSString *)toPathOfUser{
return [NSString stringWithFormat:@"api/project/%@/activities/user/%@", _project_id.stringValue, _user_id.stringValue];
}
- (NSDictionary *)toParamsOfUser{
return @{@"last_id" : _willLoadMore? self.last_id:kDefaultLastId};
}
- (void)configWithProActList:(NSArray *)responseA{
if (responseA && [responseA count] > 0) {
self.canLoadMore = YES;
ProjectActivity *lastProAct = [responseA lastObject];
self.last_id = lastProAct.id;
if (self.willLoadMore) {
[_list addObjectsFromArray:responseA];
}else{
self.list = [NSMutableArray arrayWithArray:responseA];
}
[self refreshListGroupWithArray:responseA isAdd:self.willLoadMore];
}else{
self.canLoadMore = NO;
}
}
- (void)refreshListGroupWithArray:(NSArray *)responseA isAdd:(BOOL)isAdd{
if (!isAdd) {
[_listGroups removeAllObjects];
}
for (NSUInteger i = 0; i< [responseA count]; i++) {
ProjectActivity *curProAct = [responseA objectAtIndex:i];
NSUInteger location = [_list indexOfObject:curProAct];
if (location != NSNotFound) {
ListGroupItem *item = _listGroups.lastObject;
if (item && [item.date isSameDay:curProAct.created_at]) {
[item addOneItem];
}else{
item = [ListGroupItem itemWithDate:curProAct.created_at andLocation:location];
[item addOneItem];
[_listGroups addObject:item];
}
}
}
}
@end