forked from Alfresco/alfresco-ng2-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument-list.service.ts
188 lines (162 loc) · 6.34 KB
/
document-list.service.ts
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
AlfrescoApiService, AuthenticationService, ContentService, LogService, ThumbnailService
} from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { NodeEntry, NodePaging } from '@alfresco/js-api';
import { Observable, from, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class DocumentListService {
static ROOT_ID = '-root-';
constructor(authService: AuthenticationService,
private contentService: ContentService,
private apiService: AlfrescoApiService,
private logService: LogService,
private thumbnailService: ThumbnailService) {
}
/**
* Deletes a node.
* @param nodeId ID of the node to delete
* @returns Empty response when the operation is complete
*/
deleteNode(nodeId: string): Observable<any> {
return from(this.apiService.getInstance().nodes.deleteNode(nodeId));
}
/**
* Copy a node to destination node
*
* @param nodeId The id of the node to be copied
* @param targetParentId The id of the folder where the node will be copied
* @returns NodeEntry for the copied node
*/
copyNode(nodeId: string, targetParentId: string) {
return from(this.apiService.getInstance().nodes.copyNode(nodeId, { targetParentId })).pipe(
catchError((err) => this.handleError(err))
);
}
/**
* Moves a node to destination node.
*
* @param nodeId The id of the node to be moved
* @param targetParentId The id of the folder where the node will be moved
* @returns NodeEntry for the moved node
*/
moveNode(nodeId: string, targetParentId: string) {
return from(this.apiService.getInstance().nodes.moveNode(nodeId, { targetParentId })).pipe(
catchError((err) => this.handleError(err))
);
}
/**
* Gets the folder node with the specified relative name path below the root node.
* @param folder Path to folder.
* @param opts Options.
* @param includeFields Extra information to include (available options are "aspectNames", "isLink" and "association")
* @returns Details of the folder
*/
getFolder(folder: string, opts?: any, includeFields: string[] = []): Observable<NodePaging> {
let rootNodeId = DocumentListService.ROOT_ID;
if (opts && opts.rootFolderId) {
rootNodeId = opts.rootFolderId;
}
let includeFieldsRequest = ['path', 'properties', 'allowableOperations', 'permissions', 'aspectNames', ...includeFields]
.filter((element, index, array) => index === array.indexOf(element));
let params: any = {
includeSource: true,
include: includeFieldsRequest
};
if (folder) {
params.relativePath = folder;
}
if (opts) {
if (opts.maxItems) {
params.maxItems = opts.maxItems;
}
if (opts.skipCount) {
params.skipCount = opts.skipCount;
}
if (opts.where) {
params.where = opts.where;
}
}
return from(this.apiService.getInstance().nodes.getNodeChildren(rootNodeId, params)).pipe(
catchError((err) => this.handleError(err))
);
}
/**
* Gets a node via its node ID.
* @param nodeId ID of the target node
* @param includeFields Extra information to include (available options are "aspectNames", "isLink" and "association")
* @returns Details of the folder
*/
getNode(nodeId: string, includeFields: string[] = []): Observable<NodeEntry> {
let includeFieldsRequest = ['path', 'properties', 'allowableOperations', 'permissions', ...includeFields]
.filter((element, index, array) => index === array.indexOf(element));
let opts: any = {
includeSource: true,
include: includeFieldsRequest
};
return this.contentService.getNode(nodeId, opts);
}
/**
* Gets a folder node via its node ID.
* @param nodeId ID of the folder node
* @param includeFields Extra information to include (available options are "aspectNames", "isLink" and "association")
* @returns Details of the folder
*/
getFolderNode(nodeId: string, includeFields: string[] = []): Observable<NodeEntry> {
let includeFieldsRequest = ['path', 'properties', 'allowableOperations', 'permissions', 'aspectNames', ...includeFields]
.filter((element, index, array) => index === array.indexOf(element));
let opts: any = {
includeSource: true,
include: includeFieldsRequest
};
return from(this.apiService.getInstance().nodes.getNode(nodeId, opts)).pipe(
catchError((err) => this.handleError(err))
);
}
/**
* Get thumbnail URL for the given document node.
* @param node Node to get URL for.
* @returns Thumbnail URL string
*/
getDocumentThumbnailUrl(node: NodeEntry): string {
return this.thumbnailService.getDocumentThumbnailUrl(node);
}
/**
* Gets the icon that represents a MIME type.
* @param mimeType MIME type to get the icon for
* @returns Path to the icon file
*/
getMimeTypeIcon(mimeType: string): string {
return this.thumbnailService.getMimeTypeIcon(mimeType);
}
/**
* Gets a default icon for MIME types with no specific icon.
* @returns Path to the icon file
*/
getDefaultMimeTypeIcon(): string {
return this.thumbnailService.getDefaultMimeTypeIcon();
}
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
}