@apia/uploader-controller 4.0.102 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/UploaderApi.d.ts +181 -0
- package/dist/UploaderApi.d.ts.map +1 -0
- package/dist/UploaderApi.js +1268 -0
- package/dist/UploaderApi.js.map +1 -0
- package/dist/UploaderModalController.d.ts +54 -0
- package/dist/UploaderModalController.d.ts.map +1 -0
- package/dist/UploaderModalController.js +269 -0
- package/dist/UploaderModalController.js.map +1 -0
- package/dist/directories/DirectoriesPicker.d.ts +29 -0
- package/dist/directories/DirectoriesPicker.d.ts.map +1 -0
- package/dist/directories/DirectoriesPicker.js +108 -0
- package/dist/directories/DirectoriesPicker.js.map +1 -0
- package/dist/directories/FilePicker.d.ts +14 -0
- package/dist/directories/FilePicker.d.ts.map +1 -0
- package/dist/directories/FilePicker.js +36 -0
- package/dist/directories/FilePicker.js.map +1 -0
- package/dist/directories/nodes/DirectoryPickerFolderNode.d.ts +16 -0
- package/dist/directories/nodes/DirectoryPickerFolderNode.d.ts.map +1 -0
- package/dist/directories/nodes/DirectoryPickerFolderNode.js +115 -0
- package/dist/directories/nodes/DirectoryPickerFolderNode.js.map +1 -0
- package/dist/directories/nodes/DocumentNode.d.ts +11 -0
- package/dist/directories/nodes/DocumentNode.d.ts.map +1 -0
- package/dist/directories/nodes/DocumentNode.js +16 -0
- package/dist/directories/nodes/DocumentNode.js.map +1 -0
- package/dist/directories/nodes/FilePickerFolderNode.d.ts +12 -0
- package/dist/directories/nodes/FilePickerFolderNode.d.ts.map +1 -0
- package/dist/directories/nodes/FilePickerFolderNode.js +91 -0
- package/dist/directories/nodes/FilePickerFolderNode.js.map +1 -0
- package/dist/directories/types.d.ts +57 -0
- package/dist/directories/types.d.ts.map +1 -0
- package/dist/directories/utils.d.ts +17 -0
- package/dist/directories/utils.d.ts.map +1 -0
- package/dist/directories/utils.js +17 -0
- package/dist/directories/utils.js.map +1 -0
- package/dist/index.d.ts +11 -618
- package/dist/index.js +9 -1893
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +285 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/util.d.ts +6 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +25 -0
- package/dist/util.js.map +1 -0
- package/package.json +5 -6
- package/LICENSE.md +0 -6
|
@@ -0,0 +1,1268 @@
|
|
|
1
|
+
import { EventEmitter, getLabel, arrayOrArray, downloadUrl, addBoundary, formatMessage, parseAsSize } from '@apia/util';
|
|
2
|
+
import { UploaderModalController } from './UploaderModalController.js';
|
|
3
|
+
import QueryString from 'qs';
|
|
4
|
+
import { makeObservable, observable } from 'mobx';
|
|
5
|
+
import { ApiaApi } from '@apia/api2';
|
|
6
|
+
import { parseFileDefinition } from './util.js';
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __publicField = (obj, key, value) => {
|
|
11
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
14
|
+
class UploaderApi extends EventEmitter {
|
|
15
|
+
constructor(props) {
|
|
16
|
+
super();
|
|
17
|
+
this.props = props;
|
|
18
|
+
__publicField(this, "maxFiles", Infinity);
|
|
19
|
+
__publicField(this, "modalController", null);
|
|
20
|
+
__publicField(this, "langs");
|
|
21
|
+
__publicField(this, "currentConfiguration");
|
|
22
|
+
__publicField(this, "showConfirmMessage", true);
|
|
23
|
+
__publicField(this, "state", {
|
|
24
|
+
progress: 0,
|
|
25
|
+
allowedTypes: [],
|
|
26
|
+
selectedDocTypeId: "1",
|
|
27
|
+
versioningFile: null,
|
|
28
|
+
inProgressFiles: [],
|
|
29
|
+
files: {},
|
|
30
|
+
selectedFiles: [],
|
|
31
|
+
hiddenFiles: [],
|
|
32
|
+
translatedFiles: /* @__PURE__ */ new Map(),
|
|
33
|
+
hasAllDocTypes: false
|
|
34
|
+
});
|
|
35
|
+
__publicField(this, "getConfirmDropModalMetadataString", ({
|
|
36
|
+
metadata
|
|
37
|
+
}) => {
|
|
38
|
+
return metadata?.filter?.((current) => !!current.value).map((current) => `${current.id}~${current.type}~${current.value}`).join(";") ?? [];
|
|
39
|
+
});
|
|
40
|
+
__publicField(this, "getConfirmDropModalPermissionsString", ({
|
|
41
|
+
poolsPermissions,
|
|
42
|
+
usersPermissions
|
|
43
|
+
}) => {
|
|
44
|
+
let returnString = "";
|
|
45
|
+
poolsPermissions.forEach(
|
|
46
|
+
(current) => returnString = `${returnString}${returnString.length > 0 ? "&" : ""}docPoolId=${current.poolId}&docPoolName=${current.poolName}&docPermType${current.poolId}=${String(current.canUpdate)}`
|
|
47
|
+
);
|
|
48
|
+
usersPermissions.forEach(
|
|
49
|
+
(current) => returnString = `${returnString}${returnString.length > 0 ? "&" : ""}docUserId=${current.userId}&docUsrLogin=${current.userLogin}&docPermType${current.userId}=${String(current.canUpdate)}`
|
|
50
|
+
);
|
|
51
|
+
return returnString;
|
|
52
|
+
});
|
|
53
|
+
__publicField(this, "getConfirmDropModalAdditionalMetadataString", (additionalMetadata) => {
|
|
54
|
+
return Object.values(additionalMetadata).filter((current) => !!current?.value).map((current) => `${current.title}~${current.value}`).join(";");
|
|
55
|
+
});
|
|
56
|
+
__publicField(this, "parseFileDefinition", (file) => {
|
|
57
|
+
return {
|
|
58
|
+
...parseFileDefinition(this.props.context, file, false),
|
|
59
|
+
canEdit: file.canEdit || file.canWrite,
|
|
60
|
+
canRead: file.canRead
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
makeObservable(this, {
|
|
64
|
+
state: observable
|
|
65
|
+
});
|
|
66
|
+
this.langs = this.props.context.docLangs;
|
|
67
|
+
}
|
|
68
|
+
get filesArray() {
|
|
69
|
+
return Object.values(this.state.files);
|
|
70
|
+
}
|
|
71
|
+
get id() {
|
|
72
|
+
return this.props.id;
|
|
73
|
+
}
|
|
74
|
+
get modalConfig() {
|
|
75
|
+
return this.props.modalConfig;
|
|
76
|
+
}
|
|
77
|
+
get context() {
|
|
78
|
+
return this.props.context;
|
|
79
|
+
}
|
|
80
|
+
async init() {
|
|
81
|
+
await this.ajaxUploadStart();
|
|
82
|
+
await this.reloadMetadata({
|
|
83
|
+
docTypeId: this.state.selectedDocTypeId
|
|
84
|
+
});
|
|
85
|
+
await this.loadCurrentDocuments();
|
|
86
|
+
}
|
|
87
|
+
buildModalController(conf) {
|
|
88
|
+
return new UploaderModalController(this, this.props.modalConfig, conf);
|
|
89
|
+
}
|
|
90
|
+
async onStartUpload(files) {
|
|
91
|
+
if (this.props.modalConfig.oneClickUpload) {
|
|
92
|
+
await this.saveDroppedFiles(files ?? []);
|
|
93
|
+
} else {
|
|
94
|
+
if (files) {
|
|
95
|
+
const result = await this.saveDroppedFiles(files ?? []);
|
|
96
|
+
if (!result)
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.modalController = this.buildModalController();
|
|
100
|
+
this.context.openModal();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async onTranslateUpload(conf, files) {
|
|
104
|
+
if (this.props.modalConfig.oneClickUpload) {
|
|
105
|
+
await this.saveDroppedFiles(files ?? [], conf);
|
|
106
|
+
} else {
|
|
107
|
+
await this.init();
|
|
108
|
+
let mustOpen = true;
|
|
109
|
+
if (files) {
|
|
110
|
+
const res = await this.saveDroppedFiles(files ?? [], conf);
|
|
111
|
+
if (!res) {
|
|
112
|
+
mustOpen = false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (mustOpen) {
|
|
116
|
+
this.modalController = this.buildModalController(conf);
|
|
117
|
+
this.context.openModal();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async onVersionUpload(file, conf = { newFiles: [] }) {
|
|
122
|
+
this.version(file, conf);
|
|
123
|
+
}
|
|
124
|
+
async autoLock() {
|
|
125
|
+
return new Promise((resolve) => {
|
|
126
|
+
resolve(false);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
notify(notification) {
|
|
130
|
+
this.props.context.notify(notification);
|
|
131
|
+
}
|
|
132
|
+
getAjaxUrl() {
|
|
133
|
+
return this.props.context.URL_REQUEST_AJAX;
|
|
134
|
+
}
|
|
135
|
+
getDocTypes() {
|
|
136
|
+
return this.state.allowedTypes;
|
|
137
|
+
}
|
|
138
|
+
getCurrentDocTypeId() {
|
|
139
|
+
return this.state.selectedDocTypeId;
|
|
140
|
+
}
|
|
141
|
+
getCurrentDocType() {
|
|
142
|
+
return this.state.allowedTypes.find(
|
|
143
|
+
(c) => c.id === this.state.selectedDocTypeId
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
getInProgressFiles() {
|
|
147
|
+
return this.state.inProgressFiles;
|
|
148
|
+
}
|
|
149
|
+
getHiddenFiles() {
|
|
150
|
+
return this.state.hiddenFiles;
|
|
151
|
+
}
|
|
152
|
+
getExistingFiles() {
|
|
153
|
+
return this.state.files;
|
|
154
|
+
}
|
|
155
|
+
getProgress() {
|
|
156
|
+
return this.state.progress;
|
|
157
|
+
}
|
|
158
|
+
getHasAllDocTypes() {
|
|
159
|
+
return this.state.hasAllDocTypes;
|
|
160
|
+
}
|
|
161
|
+
async getDocumentInfo({
|
|
162
|
+
docId: apiId,
|
|
163
|
+
downloadDocId: docId
|
|
164
|
+
}, newElem) {
|
|
165
|
+
const id = apiId ? this.getDocument(apiId).docId : docId;
|
|
166
|
+
const result = await ApiaApi.post(
|
|
167
|
+
this.context,
|
|
168
|
+
this.getDocumentInfoParameters({
|
|
169
|
+
action: "getDocumentInfo",
|
|
170
|
+
isAjax: true,
|
|
171
|
+
docId: id,
|
|
172
|
+
newElem,
|
|
173
|
+
ajaxUrl: this.getAjaxUrl()
|
|
174
|
+
})
|
|
175
|
+
);
|
|
176
|
+
if (result?.data) {
|
|
177
|
+
return result.data;
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* This method searches for the provided id in several places:
|
|
183
|
+
*
|
|
184
|
+
* If it's found in the current files, returns it.
|
|
185
|
+
* If not, it searches the provided docId in the translations map of each uploaded file.
|
|
186
|
+
*/
|
|
187
|
+
getDocument(docId) {
|
|
188
|
+
if (this.state.files[docId]) {
|
|
189
|
+
return this.state.files[docId];
|
|
190
|
+
} else {
|
|
191
|
+
for (const map of this.state.translatedFiles.values()) {
|
|
192
|
+
for (const file of map.values()) {
|
|
193
|
+
if (file.docId === docId) {
|
|
194
|
+
return file;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return void 0;
|
|
200
|
+
}
|
|
201
|
+
updateDocument(docId, newValue) {
|
|
202
|
+
if (this.state.files[docId]) {
|
|
203
|
+
this.state.files[docId] = { ...this.getDocument(docId), ...newValue };
|
|
204
|
+
} else {
|
|
205
|
+
this.state.translatedFiles.forEach((innerMap) => {
|
|
206
|
+
innerMap.forEach((doc, langKey) => {
|
|
207
|
+
if (doc.docId === docId) {
|
|
208
|
+
innerMap.set(langKey, { ...doc, ...newValue });
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
deleteDocument(docId) {
|
|
215
|
+
if (this.state.files[docId]) {
|
|
216
|
+
delete this.state.files[docId];
|
|
217
|
+
} else {
|
|
218
|
+
this.state.translatedFiles.forEach((innerMap) => {
|
|
219
|
+
innerMap.forEach((doc, langKey) => {
|
|
220
|
+
if (doc.docId === docId) {
|
|
221
|
+
innerMap.delete(langKey);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
clearFile(name) {
|
|
228
|
+
if (this.modalController) {
|
|
229
|
+
this.modalController.state.isReadonly = false;
|
|
230
|
+
}
|
|
231
|
+
this.state.inProgressFiles = this.state.inProgressFiles.filter(
|
|
232
|
+
(c) => c.name !== name
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
clearFiles() {
|
|
236
|
+
if (this.modalController) {
|
|
237
|
+
this.modalController.state.isReadonly = false;
|
|
238
|
+
}
|
|
239
|
+
this.state.inProgressFiles = [];
|
|
240
|
+
this.state.versioningFile = null;
|
|
241
|
+
this.state.hiddenFiles = [];
|
|
242
|
+
}
|
|
243
|
+
clearState() {
|
|
244
|
+
if (this.modalController) {
|
|
245
|
+
this.modalController.state.isReadonly = false;
|
|
246
|
+
}
|
|
247
|
+
this.state.selectedDocTypeId = this.getDocTypes().find(
|
|
248
|
+
(c) => String(c.id) === "1"
|
|
249
|
+
) ? "1" : this.getDocTypes()[0]?.id;
|
|
250
|
+
this.state.inProgressFiles = [];
|
|
251
|
+
this.state.versioningFile = null;
|
|
252
|
+
}
|
|
253
|
+
async checkLockDocument(id, shouldNotifyUnlocked = true) {
|
|
254
|
+
if (this.props.context.IN_MONITOR) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
if (Number(id) < 0)
|
|
258
|
+
return true;
|
|
259
|
+
const file = this.getDocument(id);
|
|
260
|
+
const result = await ApiaApi.post(
|
|
261
|
+
this.context,
|
|
262
|
+
this.getCheckLockDocumentParameters({
|
|
263
|
+
action: "checkLockDocument",
|
|
264
|
+
docId: file.docId,
|
|
265
|
+
ajaxUrl: this.getAjaxUrl()
|
|
266
|
+
})
|
|
267
|
+
);
|
|
268
|
+
const isLocked = result?.data?.success === "ok";
|
|
269
|
+
if (!isLocked && result?.data?.usr && result.data.usr !== this.props.context.currentUserLogin) {
|
|
270
|
+
this.notify({
|
|
271
|
+
message: `${getLabel("msgDocLocOthUsr", {}, this.props.context).text.split(".")[0]}: ${result.data.usr}.`,
|
|
272
|
+
type: "warning"
|
|
273
|
+
});
|
|
274
|
+
return result.data.usr;
|
|
275
|
+
}
|
|
276
|
+
if (!isLocked && shouldNotifyUnlocked && !await this.autoLock())
|
|
277
|
+
this.notify({
|
|
278
|
+
message: getLabel("msgDocMusBeLocForUpd", {}, this.props.context).text,
|
|
279
|
+
type: "warning"
|
|
280
|
+
});
|
|
281
|
+
return isLocked;
|
|
282
|
+
}
|
|
283
|
+
setCurrentDocTypeId(docTypeId) {
|
|
284
|
+
this.state.selectedDocTypeId = docTypeId;
|
|
285
|
+
}
|
|
286
|
+
async ajaxUploadStart(newFiles = []) {
|
|
287
|
+
if (this.props.context.IN_MONITOR) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const versioningFile = this.state.versioningFile;
|
|
291
|
+
const res = await ApiaApi.post(
|
|
292
|
+
this.context,
|
|
293
|
+
this.getAjaxUploadStartParameters({
|
|
294
|
+
action: "ajaxUploadStart",
|
|
295
|
+
isAjax: true,
|
|
296
|
+
docId: versioningFile?.docId,
|
|
297
|
+
docTypeId: newFiles.length === 1 ? versioningFile?.docTypeId || "1" : "1",
|
|
298
|
+
newDoc: !versioningFile,
|
|
299
|
+
useDocTypePermitted: false,
|
|
300
|
+
ajaxUrl: this.getAjaxUrl()
|
|
301
|
+
})
|
|
302
|
+
);
|
|
303
|
+
if (res?.data) {
|
|
304
|
+
const docTypes = arrayOrArray(res?.data?.function?.docTypes?.docType);
|
|
305
|
+
const hasGeneric = !!docTypes.find((c) => String(c.id) === "1");
|
|
306
|
+
this.state.allowedTypes = docTypes;
|
|
307
|
+
this.state.selectedDocTypeId = hasGeneric ? "1" : docTypes[0]?.id;
|
|
308
|
+
if (newFiles.length > 0) {
|
|
309
|
+
await this.saveDroppedFiles(newFiles);
|
|
310
|
+
}
|
|
311
|
+
return res?.data?.function.name === "fncDocumentLoadInformation" ? true : false;
|
|
312
|
+
} else {
|
|
313
|
+
console.error("Error starting upload, no file data");
|
|
314
|
+
throw new Error("No files data");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
async reloadMetadata(props, additionalProps) {
|
|
318
|
+
if (!this.modalController)
|
|
319
|
+
return;
|
|
320
|
+
const res = await ApiaApi.post(
|
|
321
|
+
this.context,
|
|
322
|
+
this.getReloadMetadataParameters({
|
|
323
|
+
ajaxUrl: this.getAjaxUrl(),
|
|
324
|
+
action: "reloadMetadata",
|
|
325
|
+
isAjax: true,
|
|
326
|
+
docId: props?.docId,
|
|
327
|
+
docTypeId: props?.docTypeId,
|
|
328
|
+
metadata: this.getConfirmDropModalMetadataString({
|
|
329
|
+
metadata: this.modalController?.allMetadata
|
|
330
|
+
}),
|
|
331
|
+
...additionalProps
|
|
332
|
+
})
|
|
333
|
+
);
|
|
334
|
+
if (res?.data && props?.docTypeId) {
|
|
335
|
+
const isFreeMetadata = this.state.allowedTypes.find(
|
|
336
|
+
(current) => current.id === props.docTypeId
|
|
337
|
+
)?.free ?? false;
|
|
338
|
+
this.modalController.state.metadata.freeMetadataArray = [];
|
|
339
|
+
this.modalController.state.metadata.metadataArray = [];
|
|
340
|
+
arrayOrArray(res.data.metadata).forEach((c) => {
|
|
341
|
+
if (c.free === "Y") {
|
|
342
|
+
this.modalController.state.metadata.freeMetadataArray.push(c);
|
|
343
|
+
} else {
|
|
344
|
+
this.modalController.state.metadata.metadataArray.push(c);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
this.modalController.state.metadata.isFreeMetadata = isFreeMetadata;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
async saveDroppedFiles(unprocessedFiles, conf) {
|
|
351
|
+
if (this.props.context.IN_MONITOR) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
const {
|
|
355
|
+
langId,
|
|
356
|
+
strictMode: isConfStrictMode = false,
|
|
357
|
+
translatingFile
|
|
358
|
+
} = conf ?? {};
|
|
359
|
+
const isStrictMode = isConfStrictMode || !!this.state.versioningFile || !!this.modalController?.state.fromDirectoryFile;
|
|
360
|
+
const docType = this.getCurrentDocTypeId();
|
|
361
|
+
if (!isStrictMode && !docType) {
|
|
362
|
+
this.notify({
|
|
363
|
+
message: `${getLabel("msgDropFileDel", {}, this.props.context).text}: ${unprocessedFiles.map((current) => current.name).join(", ")}.`,
|
|
364
|
+
type: "warning"
|
|
365
|
+
});
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
const allowedFiles = this.filterAlreadyUploadedFiles(
|
|
369
|
+
this.filterByFilesAmountLimit(
|
|
370
|
+
this.filterAcceptedFiles(
|
|
371
|
+
this.filterExistingFiles(
|
|
372
|
+
this.filterVersioningFiles(unprocessedFiles, conf),
|
|
373
|
+
conf
|
|
374
|
+
),
|
|
375
|
+
true,
|
|
376
|
+
docType
|
|
377
|
+
)
|
|
378
|
+
),
|
|
379
|
+
conf
|
|
380
|
+
);
|
|
381
|
+
if (allowedFiles.length > 0) {
|
|
382
|
+
const formData = new FormData();
|
|
383
|
+
allowedFiles.forEach(
|
|
384
|
+
(file) => formData.append("fileRepository", file, file.name)
|
|
385
|
+
);
|
|
386
|
+
await ApiaApi.post(
|
|
387
|
+
this.context,
|
|
388
|
+
this.getSaveDroppedFilesParameters({
|
|
389
|
+
action: "saveDroppedFiles",
|
|
390
|
+
docId: this.state.versioningFile?.docId,
|
|
391
|
+
ajaxUrl: this.getAjaxUrl(),
|
|
392
|
+
frmOut: !this.modalController,
|
|
393
|
+
docTypeId: this.state.selectedDocTypeId,
|
|
394
|
+
langId
|
|
395
|
+
}),
|
|
396
|
+
{
|
|
397
|
+
postData: formData,
|
|
398
|
+
axiosConfig: {
|
|
399
|
+
onUploadProgress: (ev) => this.state.progress = ev.loaded * 100 / ((ev.total ?? ev.loaded) * 2)
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
);
|
|
403
|
+
const ajaxUploadFileStatusParameters = this.getAjaxUploadFileStatusParameters({
|
|
404
|
+
action: "ajaxUploadFileStatus",
|
|
405
|
+
ajaxUrl: this.getAjaxUrl(),
|
|
406
|
+
delayForDrop: true,
|
|
407
|
+
isAjax: true
|
|
408
|
+
});
|
|
409
|
+
let tries = 0;
|
|
410
|
+
const checkUploadResult = async () => {
|
|
411
|
+
return new Promise(async (resolve) => {
|
|
412
|
+
tries += 1;
|
|
413
|
+
if (tries === 10) {
|
|
414
|
+
this.notify({
|
|
415
|
+
message: "Error while checking for uploadFileStatus, too many tries",
|
|
416
|
+
type: "error"
|
|
417
|
+
});
|
|
418
|
+
resolve(false);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const response = await ApiaApi.post(
|
|
422
|
+
this.context,
|
|
423
|
+
ajaxUploadFileStatusParameters
|
|
424
|
+
);
|
|
425
|
+
if (response && response.data) {
|
|
426
|
+
const hasMessages = arrayOrArray(
|
|
427
|
+
response.data?.sysMessages?.message ?? response.data?.sysExceptions?.exception ?? response.data?.exceptions?.exception ?? response.data.function.messages?.message
|
|
428
|
+
).length > 0 || !!response.data.function.dropLastMessage;
|
|
429
|
+
const uploadMessage = arrayOrArray(
|
|
430
|
+
response.data.function.messages?.message
|
|
431
|
+
).find((current) => current.name === "message");
|
|
432
|
+
if (uploadMessage)
|
|
433
|
+
this.notify({ message: uploadMessage.label, type: "warning" });
|
|
434
|
+
const method = response.data?.function.name;
|
|
435
|
+
this.state.progress = 44;
|
|
436
|
+
if (hasMessages) {
|
|
437
|
+
resolve(false);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (method === "fncProceedDocumentProcessing") {
|
|
441
|
+
resolve(true);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
if (tries === 10) {
|
|
445
|
+
resolve(method === "fncProceedDocumentProcessing");
|
|
446
|
+
}
|
|
447
|
+
setTimeout(() => {
|
|
448
|
+
checkUploadResult().then(resolve).catch(() => resolve(false));
|
|
449
|
+
}, 100);
|
|
450
|
+
} else {
|
|
451
|
+
resolve(false);
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
};
|
|
455
|
+
const hasUploadedCorrectly = await checkUploadResult();
|
|
456
|
+
this.state.progress = 66;
|
|
457
|
+
if (hasUploadedCorrectly) {
|
|
458
|
+
const shown = (this.state.inProgressFiles ?? []).map(
|
|
459
|
+
(file) => file.name
|
|
460
|
+
);
|
|
461
|
+
const postData = QueryString.stringify(
|
|
462
|
+
this.getProcessDroppedFilesPostdata({
|
|
463
|
+
useDocTypePermitted: true,
|
|
464
|
+
dropped: allowedFiles.map((file) => file.name).concat(shown),
|
|
465
|
+
shown
|
|
466
|
+
}),
|
|
467
|
+
{ arrayFormat: "repeat" }
|
|
468
|
+
);
|
|
469
|
+
const secondResult = await ApiaApi.post(
|
|
470
|
+
this.context,
|
|
471
|
+
this.getProcessDroppedFilesParameters({
|
|
472
|
+
action: "processDroppedFiles",
|
|
473
|
+
docId: this.state.versioningFile?.docId,
|
|
474
|
+
frmOut: !this.modalController,
|
|
475
|
+
ajaxUrl: this.getAjaxUrl()
|
|
476
|
+
}),
|
|
477
|
+
{
|
|
478
|
+
postData: postData.toString()
|
|
479
|
+
}
|
|
480
|
+
);
|
|
481
|
+
this.state.progress = 83;
|
|
482
|
+
if (secondResult?.data?.function?.principal?.docInfo) {
|
|
483
|
+
const acceptedByServerFiles = arrayOrArray(
|
|
484
|
+
secondResult.data.function?.principal?.docInfo
|
|
485
|
+
);
|
|
486
|
+
this.state.inProgressFiles = [
|
|
487
|
+
...this.state.inProgressFiles ?? [],
|
|
488
|
+
...acceptedByServerFiles.map(
|
|
489
|
+
(current) => [...this.state.inProgressFiles, ...unprocessedFiles].find(
|
|
490
|
+
(search) => search.name === current.docInfoName
|
|
491
|
+
)
|
|
492
|
+
).filter((current) => !!current)
|
|
493
|
+
];
|
|
494
|
+
this.state.progress = 100;
|
|
495
|
+
if (this.modalController)
|
|
496
|
+
this.modalController.state.fromDirectoryFile = null;
|
|
497
|
+
if (this.showConfirmMessage) {
|
|
498
|
+
this.notify({
|
|
499
|
+
type: "success",
|
|
500
|
+
message: getLabel(
|
|
501
|
+
"lblFileUploadedSuccessfully",
|
|
502
|
+
{},
|
|
503
|
+
this.props.context
|
|
504
|
+
).text
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
if (this.props.modalConfig.oneClickUpload) {
|
|
508
|
+
if (langId && translatingFile)
|
|
509
|
+
void this.confirmDropModal({ langId, translatingFile });
|
|
510
|
+
else
|
|
511
|
+
void this.confirmDropModal();
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
this.state.progress = 100;
|
|
516
|
+
return true;
|
|
517
|
+
} else {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
async checkWebDavLock(docId) {
|
|
522
|
+
if (this.props.context.IN_MONITOR) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
if (Number.parseInt(docId) < 0) {
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
return new Promise((resolve) => {
|
|
529
|
+
let tries = 10;
|
|
530
|
+
const checkLockAction = async () => {
|
|
531
|
+
const isLocked = await ApiaApi.post(
|
|
532
|
+
this.context,
|
|
533
|
+
this.getCheckWebDavLockParameters({
|
|
534
|
+
action: "isWebDavDocumentLocked",
|
|
535
|
+
docId,
|
|
536
|
+
ajaxUrl: this.props.context.URL_REQUEST_AJAX
|
|
537
|
+
})
|
|
538
|
+
);
|
|
539
|
+
if (isLocked?.data?.locked === true || isLocked?.data?.locked === void 0) {
|
|
540
|
+
if (--tries > 0) {
|
|
541
|
+
setTimeout(() => void checkLockAction(), 1e3);
|
|
542
|
+
} else {
|
|
543
|
+
this.notify({
|
|
544
|
+
message: getLabel("msgFailSyncDoc", {}, this.props.context).text
|
|
545
|
+
});
|
|
546
|
+
resolve(false);
|
|
547
|
+
}
|
|
548
|
+
} else {
|
|
549
|
+
resolve(true);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
void checkLockAction();
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
async checkSignature(file) {
|
|
556
|
+
let res = null;
|
|
557
|
+
if (Number(file.docId) >= 0)
|
|
558
|
+
res = await ApiaApi.get(
|
|
559
|
+
this.context,
|
|
560
|
+
this.getCheckSignatureParameters({
|
|
561
|
+
action: "viewDocSigns",
|
|
562
|
+
docId: file.docId,
|
|
563
|
+
lock: false,
|
|
564
|
+
isAjax: true,
|
|
565
|
+
react: true
|
|
566
|
+
})
|
|
567
|
+
);
|
|
568
|
+
return res;
|
|
569
|
+
}
|
|
570
|
+
async editDocument(id) {
|
|
571
|
+
if (this.props.context.IN_MONITOR) {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
const file = this.getDocument(id);
|
|
575
|
+
if (await this.checkLockDocument(file.docId) === true) {
|
|
576
|
+
const result = await ApiaApi.post(
|
|
577
|
+
this.context,
|
|
578
|
+
this.getEditDocumentParameters({
|
|
579
|
+
action: "updateWebDavDocument",
|
|
580
|
+
docId: file.docId,
|
|
581
|
+
isAjax: true
|
|
582
|
+
})
|
|
583
|
+
);
|
|
584
|
+
if (result?.data?.folderId) {
|
|
585
|
+
const sDocumentUrl = `${this.props.context.WEBDAV_SERVER}${result?.data?.folderId}/${file.docId}/${file.name || file.docName || ""}`;
|
|
586
|
+
const ProtocolInstallMessage = () => {
|
|
587
|
+
this.notify({
|
|
588
|
+
type: "warning",
|
|
589
|
+
message: getLabel(
|
|
590
|
+
"msgNoDocEdiProto",
|
|
591
|
+
{
|
|
592
|
+
text: {
|
|
593
|
+
TOK1: `<a href="${this.props.context.WEBDAV_INSTALLER_URL}" download>`,
|
|
594
|
+
TOK2: `</a>`
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
this.props.context
|
|
598
|
+
).text,
|
|
599
|
+
title: getLabel("lblEdit", {}, this.props.context).text
|
|
600
|
+
});
|
|
601
|
+
};
|
|
602
|
+
this.props.context.ITHit.WebDAV.Client.DavConstants.ProtocolTimeoutMs = 1e4;
|
|
603
|
+
await this.props.context.ITHit.WebDAV.Client.DocManager.DavProtocolEditDocument(
|
|
604
|
+
sDocumentUrl,
|
|
605
|
+
this.props.context.WEBDAV_SERVER,
|
|
606
|
+
ProtocolInstallMessage,
|
|
607
|
+
null,
|
|
608
|
+
"Current",
|
|
609
|
+
"ApiaWebDavCookie",
|
|
610
|
+
// Cookie(s) to copy.
|
|
611
|
+
"",
|
|
612
|
+
// URL to navigate to if any cookie from the list is not found.
|
|
613
|
+
"Edit"
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
async downloadVersion(fileId, version) {
|
|
619
|
+
const file = this.getDocument(fileId);
|
|
620
|
+
if (!file)
|
|
621
|
+
return;
|
|
622
|
+
if (Number.parseInt(fileId) < 0 || this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId))
|
|
623
|
+
await downloadUrl(
|
|
624
|
+
ApiaApi.makeUrl(this.context, {
|
|
625
|
+
action: "downloadDocument",
|
|
626
|
+
docId: file.downloadDocId,
|
|
627
|
+
version
|
|
628
|
+
})
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
async downloadDocument(id, version) {
|
|
632
|
+
const file = this.getDocument(id);
|
|
633
|
+
if (Number.parseInt(id) < 0 || this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId)) {
|
|
634
|
+
await downloadUrl(
|
|
635
|
+
ApiaApi.makeUrl(this.context, {
|
|
636
|
+
action: "downloadDocument",
|
|
637
|
+
docId: file.downloadDocId,
|
|
638
|
+
ajaxUrl: this.getAjaxUrl(),
|
|
639
|
+
version
|
|
640
|
+
})
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
async ajaxDeleteDocument(id, langId) {
|
|
645
|
+
const file = this.getDocument(id);
|
|
646
|
+
const isLocked = await this.checkLockDocument(file.docId);
|
|
647
|
+
if (isLocked === true) {
|
|
648
|
+
const result = await ApiaApi.post(
|
|
649
|
+
this.context,
|
|
650
|
+
this.getDeleteDocumentParameters({
|
|
651
|
+
action: "ajaxRemoveDocument",
|
|
652
|
+
docId: file.docId,
|
|
653
|
+
isAjax: true,
|
|
654
|
+
ajaxUrl: this.getAjaxUrl(),
|
|
655
|
+
langId
|
|
656
|
+
})
|
|
657
|
+
);
|
|
658
|
+
if (this.evaluateDeleteDocumentResult(result?.data)) {
|
|
659
|
+
this.deleteDocument(id);
|
|
660
|
+
this.emit("fileUploaded", null);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
async version(file, conf = { newFiles: [] }) {
|
|
665
|
+
const checkLock = await this.checkLockDocument(file.docId, true);
|
|
666
|
+
const isLocked = await this.checkWebDavLock(file.docId);
|
|
667
|
+
if (!(checkLock === true && isLocked))
|
|
668
|
+
return;
|
|
669
|
+
this.state.versioningFile = file;
|
|
670
|
+
const openVersionModal = () => {
|
|
671
|
+
if (!this.props.modalConfig.oneClickUpload) {
|
|
672
|
+
this.modalController = this.buildModalController({
|
|
673
|
+
versionFile: file
|
|
674
|
+
});
|
|
675
|
+
this.context.openModal();
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
if (!conf.newFiles || conf.newFiles.length === 0) {
|
|
679
|
+
openVersionModal();
|
|
680
|
+
}
|
|
681
|
+
await this.ajaxUploadStart();
|
|
682
|
+
if (file.docTypeId)
|
|
683
|
+
this.state.selectedDocTypeId = file.docTypeId;
|
|
684
|
+
await this.versionFileInfo(file);
|
|
685
|
+
const hasNewFiles = !!(conf.newFiles && conf.newFiles.length > 0);
|
|
686
|
+
if (hasNewFiles) {
|
|
687
|
+
const res = await this.saveDroppedFiles(conf.newFiles, {
|
|
688
|
+
langId: conf.langId,
|
|
689
|
+
translatingFile: conf.translatingFile,
|
|
690
|
+
shouldReset: false,
|
|
691
|
+
strictMode: true
|
|
692
|
+
});
|
|
693
|
+
if (res) {
|
|
694
|
+
openVersionModal();
|
|
695
|
+
}
|
|
696
|
+
} else {
|
|
697
|
+
await this.reloadMetadata({
|
|
698
|
+
docId: file.docId,
|
|
699
|
+
docTypeId: file.docTypeId
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
async versionFileInfo(file) {
|
|
704
|
+
const documentInfo = await this.getDocumentInfo({ docId: file.docId });
|
|
705
|
+
if (documentInfo?.function) {
|
|
706
|
+
const {
|
|
707
|
+
data: { general },
|
|
708
|
+
metadatas
|
|
709
|
+
} = documentInfo.function;
|
|
710
|
+
const isFreeMetadata = this.state.allowedTypes.find((current) => current.id === file.docTypeId)?.free ?? false;
|
|
711
|
+
if (this.modalController) {
|
|
712
|
+
this.modalController.state = {
|
|
713
|
+
description: general.docDesc,
|
|
714
|
+
docFolder: general.docFolder === "" ? void 0 : Number(general.docFolder),
|
|
715
|
+
docPath: general.docFolderPath,
|
|
716
|
+
permissions: {
|
|
717
|
+
allowAllType: general.docAllPoolPerm,
|
|
718
|
+
users: arrayOrArray(
|
|
719
|
+
documentInfo.function.data.permissions?.user
|
|
720
|
+
).map((current) => {
|
|
721
|
+
const returnObject = {
|
|
722
|
+
canUpdate: current.permType === "M",
|
|
723
|
+
userId: current.id,
|
|
724
|
+
userLogin: current.name
|
|
725
|
+
};
|
|
726
|
+
return returnObject;
|
|
727
|
+
}),
|
|
728
|
+
pools: arrayOrArray(
|
|
729
|
+
documentInfo.function.data.permissions?.pool
|
|
730
|
+
).map((current) => {
|
|
731
|
+
const returnObject = {
|
|
732
|
+
canUpdate: current.permType === "M",
|
|
733
|
+
poolId: current.id,
|
|
734
|
+
poolName: current.name
|
|
735
|
+
};
|
|
736
|
+
return returnObject;
|
|
737
|
+
})
|
|
738
|
+
},
|
|
739
|
+
docExpDate: general.docExpDate,
|
|
740
|
+
fileReqError: false,
|
|
741
|
+
fromDirectoryFile: null,
|
|
742
|
+
metadata: {
|
|
743
|
+
metadataArray: arrayOrArray(metadatas?.metadata),
|
|
744
|
+
freeMetadataArray: [],
|
|
745
|
+
isFreeMetadata
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
async pickFileById(id) {
|
|
752
|
+
const documentInfo = await this.getDocumentInfo(
|
|
753
|
+
{ downloadDocId: id },
|
|
754
|
+
true
|
|
755
|
+
);
|
|
756
|
+
if (documentInfo) {
|
|
757
|
+
const document = documentInfo.function.data.general;
|
|
758
|
+
const { permissions } = documentInfo.function.data;
|
|
759
|
+
if (this.modalController) {
|
|
760
|
+
this.setCurrentDocTypeId(document.docTypeId);
|
|
761
|
+
this.modalController.addDirectoryFile(document);
|
|
762
|
+
this.modalController.state.description = document.docDesc;
|
|
763
|
+
this.modalController.state.docExpDate = document.docExpDate;
|
|
764
|
+
this.modalController.state.permissions = {
|
|
765
|
+
pools: arrayOrArray(permissions?.pool).map((c) => {
|
|
766
|
+
return {
|
|
767
|
+
poolId: c.id,
|
|
768
|
+
poolName: c.name,
|
|
769
|
+
canUpdate: c.permType === "M"
|
|
770
|
+
};
|
|
771
|
+
}),
|
|
772
|
+
users: [
|
|
773
|
+
...arrayOrArray(permissions?.user).map((c) => {
|
|
774
|
+
return {
|
|
775
|
+
userId: c.id,
|
|
776
|
+
userLogin: c.name,
|
|
777
|
+
canUpdate: c.permType === "M"
|
|
778
|
+
};
|
|
779
|
+
})
|
|
780
|
+
],
|
|
781
|
+
allowAllType: document.docAllPoolPerm
|
|
782
|
+
};
|
|
783
|
+
this.modalController.changeDocType(document.docTypeId);
|
|
784
|
+
this.modalController.state.isReadonly = !documentInfo.function.currentUsrPems.usrCanModify;
|
|
785
|
+
}
|
|
786
|
+
void this.reloadMetadata(
|
|
787
|
+
{ docId: document.docId, docTypeId: document.docTypeId },
|
|
788
|
+
{
|
|
789
|
+
docReuse: true
|
|
790
|
+
}
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
async markFileToSign(id, langId) {
|
|
795
|
+
if (this.props.context.IN_MONITOR) {
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
const file = this.getDocument(id);
|
|
799
|
+
if (await this.checkLockDocument(file.docId) === true) {
|
|
800
|
+
const marked = await ApiaApi.post(
|
|
801
|
+
this.context,
|
|
802
|
+
this.getMarkFileToSignParameters({
|
|
803
|
+
action: "markDocTosign",
|
|
804
|
+
docId: file.docId,
|
|
805
|
+
isAjax: true,
|
|
806
|
+
ajaxUrl: this.getAjaxUrl(),
|
|
807
|
+
langId
|
|
808
|
+
})
|
|
809
|
+
);
|
|
810
|
+
if (marked?.data?.markedToSign !== void 0) {
|
|
811
|
+
if (this.state.files[id]) {
|
|
812
|
+
this.state.files[id].markedToSign = marked.data.markedToSign;
|
|
813
|
+
} else {
|
|
814
|
+
this.state.translatedFiles.forEach((innerMap) => {
|
|
815
|
+
innerMap.forEach((doc, langKey) => {
|
|
816
|
+
if (doc.docId === id) {
|
|
817
|
+
innerMap.set(langKey, {
|
|
818
|
+
...doc,
|
|
819
|
+
markedToSign: marked?.data?.markedToSign ?? false
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Por el momento realiza la descarga de todos los archivos
|
|
830
|
+
* que estén subidos.
|
|
831
|
+
*/
|
|
832
|
+
downloadMultipleDocuments() {
|
|
833
|
+
const files = this.filesArray;
|
|
834
|
+
if (files.length === 0)
|
|
835
|
+
return;
|
|
836
|
+
const docIds = this.state.selectedFiles;
|
|
837
|
+
const selectedFiles = files.filter(
|
|
838
|
+
(current) => docIds.find((search) => search === current.docId)
|
|
839
|
+
);
|
|
840
|
+
const ids = (selectedFiles.length > 0 ? selectedFiles : files).map((current) => current.downloadDocId).join("-");
|
|
841
|
+
void downloadUrl(
|
|
842
|
+
ApiaApi.makeUrl(
|
|
843
|
+
this.context,
|
|
844
|
+
this.getDownloadMultipleDocumentsParameters({
|
|
845
|
+
action: "multipleDownload",
|
|
846
|
+
docId: ids
|
|
847
|
+
})
|
|
848
|
+
),
|
|
849
|
+
"documents.zip"
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
async confirmDropModal(conf) {
|
|
853
|
+
if (this.props.context.IN_MONITOR) {
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
const { langId, translatingFile } = conf ?? {};
|
|
857
|
+
const cmbDocType = this.state.selectedDocTypeId;
|
|
858
|
+
const fromDirectoryFile = this.modalController?.state.fromDirectoryFile;
|
|
859
|
+
const docDesc = this.modalController?.description ?? "";
|
|
860
|
+
const docAllowAllType = this.props.modalConfig.oneClickUpload ? "M" : this.modalController?.allowAllType ?? "";
|
|
861
|
+
const docFolder = this.modalController?.docFolder;
|
|
862
|
+
const docExpDate = this.modalController?.docExpDate;
|
|
863
|
+
const metadata = this.modalController?.metadata ?? [];
|
|
864
|
+
const freeMetadata = this.modalController?.freeMetadata ?? [];
|
|
865
|
+
const poolsPermissions = this.modalController?.state.permissions.pools ?? [];
|
|
866
|
+
const usersPermissions = this.modalController?.state.permissions.users ?? [];
|
|
867
|
+
let postData = QueryString.stringify(
|
|
868
|
+
this.getConfirmDropModalPostdata({
|
|
869
|
+
cmbDocType,
|
|
870
|
+
docDesc,
|
|
871
|
+
docAllowAllType,
|
|
872
|
+
dropped: this.state.inProgressFiles.map((file) => file.name),
|
|
873
|
+
txtLangId: langId,
|
|
874
|
+
txtLangGroup: translatingFile?.docLangGroup,
|
|
875
|
+
docFolder
|
|
876
|
+
}),
|
|
877
|
+
{ arrayFormat: "repeat" }
|
|
878
|
+
);
|
|
879
|
+
postData = `${postData}${postData.length > 0 ? "&" : ""}${this.getConfirmDropModalPermissionsString({
|
|
880
|
+
poolsPermissions,
|
|
881
|
+
usersPermissions
|
|
882
|
+
})}&txtFreeMetadata=${this.getConfirmDropModalAdditionalMetadataString(
|
|
883
|
+
freeMetadata
|
|
884
|
+
)}&txtMetadata=${this.getConfirmDropModalMetadataString({
|
|
885
|
+
metadata: Object.values(metadata || {})
|
|
886
|
+
})}&docExpDate=${docExpDate ?? ""}`;
|
|
887
|
+
const result = await ApiaApi.post(
|
|
888
|
+
this.context,
|
|
889
|
+
this.getConfirmDropModalParameters({
|
|
890
|
+
ajaxUrl: this.getAjaxUrl(),
|
|
891
|
+
docId: fromDirectoryFile ? fromDirectoryFile.docId : this.state.versioningFile?.docId,
|
|
892
|
+
action: fromDirectoryFile ? "associateExistingFile" : "confirmDropModal",
|
|
893
|
+
fromForm: true,
|
|
894
|
+
...fromDirectoryFile ? {
|
|
895
|
+
docId: fromDirectoryFile.docId,
|
|
896
|
+
fromReuse: true,
|
|
897
|
+
uploadDocument: false
|
|
898
|
+
} : null
|
|
899
|
+
}),
|
|
900
|
+
{
|
|
901
|
+
postData: postData.toString()
|
|
902
|
+
}
|
|
903
|
+
);
|
|
904
|
+
if (result?.data?.function) {
|
|
905
|
+
const currentFiles = { ...this.state.files };
|
|
906
|
+
const versioningFile = this.state.versioningFile;
|
|
907
|
+
if (versioningFile && versioningFile.name) {
|
|
908
|
+
delete currentFiles[versioningFile.name];
|
|
909
|
+
}
|
|
910
|
+
const newFiles = arrayOrArray(
|
|
911
|
+
result.data.function.general
|
|
912
|
+
).map(
|
|
913
|
+
(current) => this.parseFileDefinition({
|
|
914
|
+
...current,
|
|
915
|
+
canWrite: true,
|
|
916
|
+
canRead: true,
|
|
917
|
+
canEdit: true
|
|
918
|
+
})
|
|
919
|
+
).filter((current) => !currentFiles[current.docId]).reduce((acc, current) => ({ ...acc, [current.docId]: current }), {});
|
|
920
|
+
if (langId && translatingFile) {
|
|
921
|
+
const firstFile = Object.values(newFiles)[0];
|
|
922
|
+
this.setTranslationFile(firstFile, translatingFile.docId, langId);
|
|
923
|
+
} else {
|
|
924
|
+
this.state.files = { ...currentFiles, ...newFiles };
|
|
925
|
+
}
|
|
926
|
+
this.clearFiles();
|
|
927
|
+
this.emit("fileUploaded", null);
|
|
928
|
+
return true;
|
|
929
|
+
}
|
|
930
|
+
return false;
|
|
931
|
+
}
|
|
932
|
+
getLoadCurrentDocumentsParameters(params) {
|
|
933
|
+
return params;
|
|
934
|
+
}
|
|
935
|
+
async loadCurrentDocuments() {
|
|
936
|
+
const result = await ApiaApi.post(
|
|
937
|
+
this.context,
|
|
938
|
+
this.getLoadCurrentDocumentsParameters({
|
|
939
|
+
ajaxUrl: this.getAjaxUrl(),
|
|
940
|
+
action: "ajaxLoadCurrent",
|
|
941
|
+
isAjax: true,
|
|
942
|
+
readOnly: this.props.context.readonly,
|
|
943
|
+
allowLock: true,
|
|
944
|
+
allowSign: true,
|
|
945
|
+
allowMultiple: true
|
|
946
|
+
}),
|
|
947
|
+
{}
|
|
948
|
+
);
|
|
949
|
+
if (result && result.data) {
|
|
950
|
+
const currentConfiguration = arrayOrArray(result.data.function.messages.message).reduce(
|
|
951
|
+
(prev, { name, label }) => ({ ...prev, [name]: Boolean(label) }),
|
|
952
|
+
{}
|
|
953
|
+
);
|
|
954
|
+
const currentFiles = result.data.function.general ? arrayOrArray(result.data.function.general).map(
|
|
955
|
+
this.parseFileDefinition
|
|
956
|
+
) : [];
|
|
957
|
+
this.currentConfiguration = currentConfiguration;
|
|
958
|
+
const nonTranslationFiles = [];
|
|
959
|
+
const translationFiles = [];
|
|
960
|
+
currentFiles.forEach((current) => {
|
|
961
|
+
if (current.docLang === void 0)
|
|
962
|
+
nonTranslationFiles.push(current);
|
|
963
|
+
else
|
|
964
|
+
translationFiles.push(current);
|
|
965
|
+
});
|
|
966
|
+
nonTranslationFiles.forEach((c) => {
|
|
967
|
+
this.state.files[c.docId] = c;
|
|
968
|
+
});
|
|
969
|
+
translationFiles.forEach((current) => {
|
|
970
|
+
const originalFile = nonTranslationFiles.find(
|
|
971
|
+
(search) => search.docLangGroup === current.docLangGroup
|
|
972
|
+
);
|
|
973
|
+
if (originalFile && current.docLang !== void 0) {
|
|
974
|
+
this.setTranslationFile(
|
|
975
|
+
current,
|
|
976
|
+
originalFile.docId,
|
|
977
|
+
Number(current.docLang)
|
|
978
|
+
);
|
|
979
|
+
} else
|
|
980
|
+
console.warn(
|
|
981
|
+
`The following file is translated but has no orignal file`,
|
|
982
|
+
current,
|
|
983
|
+
nonTranslationFiles
|
|
984
|
+
);
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
async lockDocument(id) {
|
|
989
|
+
if (this.props.context.IN_MONITOR) {
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
const file = this.getDocument(id);
|
|
993
|
+
if (file.markedToSign) {
|
|
994
|
+
this.notify({
|
|
995
|
+
message: getLabel("msgCantActFileMarkSign", {}, this.props.context).text,
|
|
996
|
+
type: "warning"
|
|
997
|
+
});
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
if (!file.isLocked || !file.isLockedByMe) {
|
|
1001
|
+
const isLocked = await this.checkLockDocument(file.docId, false);
|
|
1002
|
+
this.updateDocument(
|
|
1003
|
+
id,
|
|
1004
|
+
typeof isLocked === "string" ? this.parseFileDefinition({
|
|
1005
|
+
...file,
|
|
1006
|
+
userLocking: isLocked,
|
|
1007
|
+
lock: true,
|
|
1008
|
+
isLocked: true,
|
|
1009
|
+
lockedBy: isLocked
|
|
1010
|
+
}) : { ...file, isLocked }
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
const result = await ApiaApi.post(
|
|
1014
|
+
this.context,
|
|
1015
|
+
this.getLockDocumentParameters({
|
|
1016
|
+
action: "lockDocument",
|
|
1017
|
+
ajaxUrl: this.getAjaxUrl(),
|
|
1018
|
+
docId: file.docId,
|
|
1019
|
+
lock: file.isLocked,
|
|
1020
|
+
isAjax: true
|
|
1021
|
+
})
|
|
1022
|
+
);
|
|
1023
|
+
if (result?.data) {
|
|
1024
|
+
const resultFile = result.data.function?.data?.general;
|
|
1025
|
+
if (resultFile)
|
|
1026
|
+
this.updateDocument(
|
|
1027
|
+
resultFile.docId,
|
|
1028
|
+
this.parseFileDefinition({
|
|
1029
|
+
...file,
|
|
1030
|
+
...resultFile,
|
|
1031
|
+
isLocked: resultFile.locked,
|
|
1032
|
+
locked: resultFile.locked,
|
|
1033
|
+
lock: resultFile.locked
|
|
1034
|
+
})
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
evaluateDeleteDocumentResult(result) {
|
|
1039
|
+
return result?.function?.name === "fncDocumentRemove";
|
|
1040
|
+
}
|
|
1041
|
+
setTranslationFile(file, docId, langId) {
|
|
1042
|
+
if (!this.state.translatedFiles.has(docId)) {
|
|
1043
|
+
this.state.translatedFiles.set(docId, /* @__PURE__ */ new Map());
|
|
1044
|
+
}
|
|
1045
|
+
this.state.translatedFiles.get(docId)?.set(langId, file);
|
|
1046
|
+
}
|
|
1047
|
+
getCheckSignatureParameters(props) {
|
|
1048
|
+
return props;
|
|
1049
|
+
}
|
|
1050
|
+
getAjaxUploadFileStatusParameters(props) {
|
|
1051
|
+
return props;
|
|
1052
|
+
}
|
|
1053
|
+
getAjaxUploadStartParameters(props) {
|
|
1054
|
+
return props;
|
|
1055
|
+
}
|
|
1056
|
+
getConfirmDropModalParameters(props) {
|
|
1057
|
+
return props;
|
|
1058
|
+
}
|
|
1059
|
+
getCheckLockDocumentParameters(props) {
|
|
1060
|
+
return props;
|
|
1061
|
+
}
|
|
1062
|
+
getCheckWebDavLockParameters(props) {
|
|
1063
|
+
return props;
|
|
1064
|
+
}
|
|
1065
|
+
getConfirmDropModalPostdata(props) {
|
|
1066
|
+
return props;
|
|
1067
|
+
}
|
|
1068
|
+
getDeleteDocumentParameters(props) {
|
|
1069
|
+
return props;
|
|
1070
|
+
}
|
|
1071
|
+
getClearTempFilesParameters(props) {
|
|
1072
|
+
return props;
|
|
1073
|
+
}
|
|
1074
|
+
getDocumentInfoParameters(props) {
|
|
1075
|
+
return props;
|
|
1076
|
+
}
|
|
1077
|
+
getDownloadMultipleDocumentsParameters(props) {
|
|
1078
|
+
return props;
|
|
1079
|
+
}
|
|
1080
|
+
getEditDocumentParameters(props) {
|
|
1081
|
+
return props;
|
|
1082
|
+
}
|
|
1083
|
+
getLockDocumentParameters(props) {
|
|
1084
|
+
return props;
|
|
1085
|
+
}
|
|
1086
|
+
getMarkFileToSignParameters(props) {
|
|
1087
|
+
return props;
|
|
1088
|
+
}
|
|
1089
|
+
getProcessDroppedFilesParameters(props) {
|
|
1090
|
+
return props;
|
|
1091
|
+
}
|
|
1092
|
+
getProcessDroppedFilesPostdata(props) {
|
|
1093
|
+
return props;
|
|
1094
|
+
}
|
|
1095
|
+
getReloadMetadataParameters(props) {
|
|
1096
|
+
return props;
|
|
1097
|
+
}
|
|
1098
|
+
getSaveDroppedFilesParameters(props) {
|
|
1099
|
+
return props;
|
|
1100
|
+
}
|
|
1101
|
+
filterAlreadyUploadedFiles(files, conf) {
|
|
1102
|
+
const versioningFile = this.state.versioningFile;
|
|
1103
|
+
if (versioningFile)
|
|
1104
|
+
return files;
|
|
1105
|
+
const uploadedFiles = Object.values(this.state.files).filter(
|
|
1106
|
+
(file) => Number(file.docId) > 0
|
|
1107
|
+
);
|
|
1108
|
+
const existingFiles = [];
|
|
1109
|
+
const nonExistingFiles = [];
|
|
1110
|
+
if (conf?.langId) {
|
|
1111
|
+
const docId = conf.translatingFile?.docId ?? Infinity;
|
|
1112
|
+
const translationsMap = this.state.translatedFiles.get(String(docId));
|
|
1113
|
+
const alreadyUploadedToTranslationsFile = translationsMap ? Array.from(translationsMap.values()).find(
|
|
1114
|
+
(current) => (current.docName || current.name) === files[0]?.name
|
|
1115
|
+
) : void 0;
|
|
1116
|
+
if (alreadyUploadedToTranslationsFile)
|
|
1117
|
+
existingFiles.push(files[0]);
|
|
1118
|
+
} else
|
|
1119
|
+
files.forEach((file) => {
|
|
1120
|
+
if (uploadedFiles.find((search) => search.docName === file.name)) {
|
|
1121
|
+
existingFiles.push(file);
|
|
1122
|
+
} else
|
|
1123
|
+
nonExistingFiles.push(file);
|
|
1124
|
+
});
|
|
1125
|
+
if (existingFiles.length > 0) {
|
|
1126
|
+
void this.notify({
|
|
1127
|
+
message: `${getLabel("msgDropFileRep", {}, this.props.context).text}: ${existingFiles.map((current) => current.name).join(", ")}`,
|
|
1128
|
+
type: "warning"
|
|
1129
|
+
});
|
|
1130
|
+
return nonExistingFiles;
|
|
1131
|
+
}
|
|
1132
|
+
return files;
|
|
1133
|
+
}
|
|
1134
|
+
filterByFilesAmountLimit(files) {
|
|
1135
|
+
return files.slice(
|
|
1136
|
+
0,
|
|
1137
|
+
addBoundary(this.maxFiles - (this.state.inProgressFiles?.length ?? 0), 0)
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
filterAcceptedFiles(files, shouldNotify = true, docTypeId) {
|
|
1141
|
+
const docTypes = docTypeId !== void 0 ? this.state.allowedTypes.filter((c) => {
|
|
1142
|
+
return typeof docTypeId === "string" ? c.id === docTypeId : c.id === docTypeId.id;
|
|
1143
|
+
}) : this.state.allowedTypes;
|
|
1144
|
+
if (!docTypes.find((c) => c.docExts === "")) {
|
|
1145
|
+
const notAllowedFilesBecauseOfExtension = [];
|
|
1146
|
+
const notAllowedFilesBecauseOfSize = [];
|
|
1147
|
+
let maxSize = Infinity;
|
|
1148
|
+
const allowedFiles = files.filter((currentFile) => {
|
|
1149
|
+
const extension = (currentFile.name.match(/\.(\w+)$/) ?? [])[1];
|
|
1150
|
+
let isAllowed = true;
|
|
1151
|
+
if (!docTypes.find((currentDocType) => {
|
|
1152
|
+
if (!currentDocType.docExts.split(";").map((current) => current.toLowerCase()).includes(extension.toLowerCase())) {
|
|
1153
|
+
return false;
|
|
1154
|
+
}
|
|
1155
|
+
return true;
|
|
1156
|
+
})) {
|
|
1157
|
+
isAllowed = false;
|
|
1158
|
+
notAllowedFilesBecauseOfExtension.push(currentFile);
|
|
1159
|
+
}
|
|
1160
|
+
if (isAllowed && !docTypes.find((currentDocType) => {
|
|
1161
|
+
if (Number(currentDocType.maxSize) < currentFile.size) {
|
|
1162
|
+
maxSize = Number(currentDocType.maxSize);
|
|
1163
|
+
return false;
|
|
1164
|
+
}
|
|
1165
|
+
return true;
|
|
1166
|
+
})) {
|
|
1167
|
+
notAllowedFilesBecauseOfSize.push(currentFile);
|
|
1168
|
+
isAllowed = false;
|
|
1169
|
+
}
|
|
1170
|
+
if (!isAllowed)
|
|
1171
|
+
return false;
|
|
1172
|
+
return true;
|
|
1173
|
+
});
|
|
1174
|
+
if (shouldNotify) {
|
|
1175
|
+
let errorMessage = "";
|
|
1176
|
+
if (notAllowedFilesBecauseOfExtension.length > 0) {
|
|
1177
|
+
const filesNames = notAllowedFilesBecauseOfExtension.reduce(
|
|
1178
|
+
(accumulated, current) => {
|
|
1179
|
+
if (accumulated.length === 0)
|
|
1180
|
+
return current.name;
|
|
1181
|
+
return `${accumulated}, ${current.name}`;
|
|
1182
|
+
},
|
|
1183
|
+
""
|
|
1184
|
+
);
|
|
1185
|
+
errorMessage = `<strong>${getLabel("msgFileWrngExt", {}, this.props.context).text}</strong><br />${filesNames}`;
|
|
1186
|
+
}
|
|
1187
|
+
if (notAllowedFilesBecauseOfSize.length > 0) {
|
|
1188
|
+
const filesNames = notAllowedFilesBecauseOfSize.reduce(
|
|
1189
|
+
(accumulated, current) => {
|
|
1190
|
+
if (accumulated.length === 0)
|
|
1191
|
+
return current.name;
|
|
1192
|
+
return `${accumulated}, ${current.name}`;
|
|
1193
|
+
},
|
|
1194
|
+
""
|
|
1195
|
+
);
|
|
1196
|
+
if (errorMessage.length > 0)
|
|
1197
|
+
errorMessage = `${errorMessage} <br /><br />`;
|
|
1198
|
+
errorMessage = `${errorMessage}${formatMessage(
|
|
1199
|
+
getLabel("msgFileTooBig", {}, this.props.context).text,
|
|
1200
|
+
{
|
|
1201
|
+
TOK1: `<br />${filesNames}`,
|
|
1202
|
+
TOK2: `${parseAsSize(maxSize)}`
|
|
1203
|
+
}
|
|
1204
|
+
)}`;
|
|
1205
|
+
}
|
|
1206
|
+
if (errorMessage.length > 0)
|
|
1207
|
+
this.notify({
|
|
1208
|
+
message: errorMessage,
|
|
1209
|
+
type: "warning"
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
return allowedFiles;
|
|
1213
|
+
}
|
|
1214
|
+
return files;
|
|
1215
|
+
}
|
|
1216
|
+
filterExistingFiles(files, conf) {
|
|
1217
|
+
if (conf?.langId)
|
|
1218
|
+
return files;
|
|
1219
|
+
const currentFiles = this.state.inProgressFiles;
|
|
1220
|
+
const alreadyUploadedFiles = Object.values(this.state.files).filter(
|
|
1221
|
+
(current) => Number(current.docId) < 0
|
|
1222
|
+
);
|
|
1223
|
+
let alreadyIncludedFileNames = "";
|
|
1224
|
+
const filteredFiles = files.filter((current) => {
|
|
1225
|
+
const isIncluded = currentFiles.findIndex((search) => search.name === current.name) !== -1 || alreadyUploadedFiles.findIndex(
|
|
1226
|
+
(search) => search.docName === current.name
|
|
1227
|
+
) !== -1;
|
|
1228
|
+
if (isIncluded)
|
|
1229
|
+
alreadyIncludedFileNames = `${alreadyIncludedFileNames}${alreadyIncludedFileNames.length > 0 ? ", " : ""}${current.name}`;
|
|
1230
|
+
return !isIncluded;
|
|
1231
|
+
});
|
|
1232
|
+
if (alreadyIncludedFileNames.length > 0)
|
|
1233
|
+
this.notify({
|
|
1234
|
+
message: `${getLabel("msgDropFileRep", {}, this.props.context).text}: ${alreadyIncludedFileNames}`,
|
|
1235
|
+
type: "warning"
|
|
1236
|
+
});
|
|
1237
|
+
return filteredFiles;
|
|
1238
|
+
}
|
|
1239
|
+
filterVersioningFiles(files, conf) {
|
|
1240
|
+
const versioningFile = this.state.versioningFile;
|
|
1241
|
+
if (versioningFile) {
|
|
1242
|
+
const newFiles = files.filter(
|
|
1243
|
+
(current) => current.name === versioningFile.docName || current.name === versioningFile.name
|
|
1244
|
+
);
|
|
1245
|
+
if (newFiles.length === 0) {
|
|
1246
|
+
this.notify({
|
|
1247
|
+
type: "warning",
|
|
1248
|
+
message: getLabel("msgDocDiffFilename", {}, this.props.context).text
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
return newFiles;
|
|
1252
|
+
}
|
|
1253
|
+
return files;
|
|
1254
|
+
}
|
|
1255
|
+
getLoadFileSystemStructureTree() {
|
|
1256
|
+
return {
|
|
1257
|
+
useDocTypePermitted: true
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
getLoadFilesForFolderParameters() {
|
|
1261
|
+
return {
|
|
1262
|
+
useDocTypePermitted: true
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
export { UploaderApi };
|
|
1268
|
+
//# sourceMappingURL=UploaderApi.js.map
|