forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTasks.m
More file actions
executable file
·130 lines (116 loc) · 3.81 KB
/
Tasks.m
File metadata and controls
executable file
·130 lines (116 loc) · 3.81 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
//
// Tasks.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-16.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "Tasks.h"
@implementation Tasks
- (instancetype)init
{
self = [super init];
if (self) {
_propertyArrayMap = [NSDictionary dictionaryWithObjectsAndKeys:
@"Task", @"list", nil];
_canLoadMore = YES;
_isLoading = _willLoadMore = NO;
_page = [NSNumber numberWithInteger:1];
_pageSize = [NSNumber numberWithInteger:20];
_type = TaskQueryTypeAll;//processing.done
}
return self;
}
+ (Tasks *)tasksWithPro:(Project *)project owner:(User *)owner queryType:(TaskQueryType)type{
Tasks *tasks = [[Tasks alloc] init];
tasks.owner = owner;
tasks.backend_project_path = project.backend_project_path;
tasks.type = type;
tasks.entranceType = TaskEntranceTypeProject;
return tasks;
}
+ (Tasks *)tasksWithPro:(Project *)project queryType:(TaskQueryType)type{
Tasks *tasks = [[Tasks alloc] init];
tasks.project = project;
tasks.type = type;
tasks.entranceType = TaskEntranceTypeMine;
return tasks;
}
- (NSString *)queryType{
NSString *queryType;
switch (_type) {
case TaskQueryTypeAll:
queryType = @"all";
break;
case TaskQueryTypeProcessing:
queryType = @"processing";
break;
case TaskQueryTypeDone:
queryType = @"done";
break;
default:
queryType = @"all";
break;
}
return queryType;
}
- (NSDictionary *)toParams{
if (_entranceType == TaskEntranceTypeProject) {
return [self toParams_Project];
}else{
return [self toParams_Mine];
}
}
- (NSString *)toRequestPath{
if (_entranceType == TaskEntranceTypeProject) {
return [self toRequestPath_Project];
}else{
return [self toRequestPath_Mine];
}
}
- (NSDictionary *)toParams_Project{
return @{@"page" : (_willLoadMore? [NSNumber numberWithInteger:_page.intValue +1] : [NSNumber numberWithInteger:1]),
@"pageSize" : _pageSize};
}
- (NSString *)toRequestPath_Project{
NSString *path;
if (!_owner || !_owner.global_key) {
path = [NSString stringWithFormat:@"api%@/tasks/%@", self.backend_project_path, self.queryType];
}else{
path = [NSString stringWithFormat:@"api%@/tasks/user/%@/%@", self.backend_project_path, _owner.global_key, self.queryType];
}
return path;
}
- (NSDictionary *)toParams_Mine{
return @{@"page" : (_willLoadMore? [NSNumber numberWithInteger:_page.intValue +1] : [NSNumber numberWithInteger:1]),
@"pageSize" : _pageSize};
}
- (NSString *)toRequestPath_Mine{
NSString *path;
if (_project && _project.id.intValue != -1) {
path = [NSString stringWithFormat:@"api/tasks/project/%d/%@", _project.id.intValue, self.queryType];
}else{
path = [NSString stringWithFormat:@"api/tasks/%@", self.queryType];
}
return path;
}
- (void)configWithTasks:(Tasks *)resultA{
self.page = resultA.page;
self.totalPage = resultA.totalPage;
self.totalRow = resultA.totalRow;
if (_willLoadMore) {
[self.list addObjectsFromArray:resultA.list];
}else{
self.list = [NSMutableArray arrayWithArray:resultA.list];
}
self.canLoadMore = self.page.intValue < self.totalPage.intValue;
if (_list.count > 0) {
NSPredicate *donePredicate = [NSPredicate predicateWithFormat:@"status.intValue == %d", 2];
NSPredicate *processingPredicate = [NSPredicate predicateWithFormat:@"status.intValue == %d", 1];
_doneList = [self.list filteredArrayUsingPredicate:donePredicate];
_processingList = [self.list filteredArrayUsingPredicate:processingPredicate];
}else{
_doneList = _processingList = nil;
}
}
@end