-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathProjectFolder.m
executable file
·102 lines (99 loc) · 3.08 KB
/
ProjectFolder.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
//
// ProjectFolder.m
// Coding_iOS
//
// Created by Ease on 14/11/13.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "ProjectFolder.h"
@implementation ProjectFolder
+ (ProjectFolder *)defaultFolder{
ProjectFolder *folder = [[ProjectFolder alloc] init];
folder.file_id = [NSNumber numberWithInteger:0];
folder.name = @"默认文件夹";
return folder;
}
+ (ProjectFolder *)shareFolder{
ProjectFolder *folder = [[ProjectFolder alloc] init];
folder.file_id = [NSNumber numberWithInteger:-1];
folder.name = @"分享中";
return folder;
}
+ (ProjectFolder *)outFolder{
ProjectFolder *folder = [[ProjectFolder alloc] init];
folder.file_id = [NSNumber numberWithInteger:0];
folder.name = @"移出目录";
return folder;
}
+ (ProjectFolder *)folderWithId:(NSNumber *)file_id{
ProjectFolder *folder = [[ProjectFolder alloc] init];
folder.sub_folders = [NSMutableArray array];
folder.file_id = file_id;
return folder;
}
- (ProjectFolder *)hasFolderWithId:(NSNumber *)file_id{
if (!file_id || !_file_id) {
return nil;
}
if (_file_id.integerValue == file_id.integerValue) {
return self;
}else{
for (ProjectFolder *sub_folder in self.sub_folders) {
if (sub_folder.file_id.integerValue == file_id.integerValue) {
return sub_folder;
}
}
}
return nil;
}
- (instancetype)init
{
self = [super init];
if (self) {
_propertyArrayMap = [NSDictionary dictionaryWithObjectsAndKeys:
@"ProjectFolder", @"sub_folders", nil];
}
return self;
}
- (BOOL)isDefaultFolder{
return _file_id && _file_id.integerValue == 0;
}
- (BOOL)isShareFolder{
return _file_id && _file_id.integerValue == -1;
}
- (BOOL)isOutFolder{
return _file_id && _file_id.integerValue == 0 && [_name isEqualToString:@"移出目录"];
}
- (BOOL)canCreatSubfolder{
return !((_parent_id && _parent_id.integerValue != 0) || [self isDefaultFolder]);
}
- (NSInteger)fileCountIncludeSub{
NSInteger fileCount = self.count.integerValue;
for (ProjectFolder *subFolder in self.sub_folders) {
fileCount += subFolder.fileCountIncludeSub;
}
return fileCount;
}
- (NSString *)toFilesPath{
if ([self isShareFolder]) {
return [NSString stringWithFormat:@"api/project/%@/shared_files", _project_id];
}else{
return [NSString stringWithFormat:@"api/project/%@/files/%@", _project_id, _file_id];
}
}
- (NSDictionary *)toFilesParams{
return @{@"height": @"90",
@"width": @"90",
@"page" : @"1",
@"pageSize": @(999999999)};
}
- (NSString *)toRenamePath{
return [NSString stringWithFormat:@"api/project/%@/dir/%@/name/%@", _project_id.stringValue, _file_id.stringValue, _next_name];
}
- (NSString *)toDeletePath{
return [NSString stringWithFormat:@"api/project/%@/rmdir/%@", _project_id.stringValue, _file_id.stringValue];
}
- (NSString *)toMoveToPath{
return [NSString stringWithFormat:@"api/project/%@/files/moveto/%@", _project_id.stringValue, _file_id.stringValue];
}
@end