dochub-sdk 0.1.358 → 0.1.359
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/classes/vue2/Documents.ts +26 -12
- package/package.json +1 -1
@@ -33,6 +33,8 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
33
33
|
onRefresher: any = null; // Таймер отложенного выполнения обновления
|
34
34
|
followFiles: string[] | undefined = undefined; // Список файлов за изменениями которых нужно следить
|
35
35
|
baseURI: string | undefined = undefined; // URI документа от которого должны разрешаться все относительные ссылки
|
36
|
+
templateURI: string | undefined = undefined; // URI файла шаблона, если он определен
|
37
|
+
sourceURI: string | undefined = undefined; // Файла источника, если он определен как файл
|
36
38
|
error: string | null = null; // Ошибка
|
37
39
|
isPending = true; // Признак внутренней работы. Например загрузка данных.
|
38
40
|
/**
|
@@ -168,21 +170,18 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
168
170
|
*/
|
169
171
|
async doRefresh(): Promise<void> {
|
170
172
|
try {
|
171
|
-
if (!this.
|
173
|
+
if (!this.sourceURI) throw new DocHubError('Document must have field "source" in profile!');
|
172
174
|
this.isPending = true;
|
173
175
|
await this.refreshFilesFollow();
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
));
|
176
|
+
// Если есть шаблон, загружаем его
|
177
|
+
const template = (this.getType() === DocHubDocumentType.content) && this.templateURI
|
178
|
+
&& (await DocHub.dataLake.pullFile(this.templateURI));
|
178
179
|
let result: AxiosResponse = (template || (this.getType() === DocHubDocumentType.data))
|
179
180
|
&& { data: await DocHub.dataLake.resolveDataSetProfile(this.profile, {
|
180
181
|
params: this.params,
|
181
182
|
baseURI: this.baseURI
|
182
183
|
}) } as AxiosResponse
|
183
|
-
||
|
184
|
-
DocHub.dataLake.resolveURI(this.baseURI || this.profile?.source as string, this.profile?.source as string)
|
185
|
-
));
|
184
|
+
|| await DocHub.dataLake.pullFile(this.sourceURI);
|
186
185
|
// Валидируем данные по структуре, если это требуется
|
187
186
|
if (template || (this.getType() === DocHubDocumentType.data)) {
|
188
187
|
const rules = new ajv({ allErrors: true });
|
@@ -216,26 +215,41 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
216
215
|
}
|
217
216
|
}
|
218
217
|
|
219
|
-
// Обновляет URI
|
218
|
+
// Обновляет URI файлов за которым установлено наблюдение
|
220
219
|
async refreshFilesFollow(disable = false): Promise<void> {
|
221
220
|
// Очищаем ранее установленные отслеживания
|
222
221
|
for(const uri of this.followFiles || []) {
|
223
222
|
DocHub.dataLake.unfollowFile(uri, this.onRefresh);
|
224
223
|
}
|
224
|
+
// Сбрасываем URI файлов
|
225
|
+
this.templateURI = undefined;
|
226
|
+
this.sourceURI = undefined;
|
227
|
+
this.baseURI = undefined;
|
225
228
|
// Если нужно только очистить отслеживание - выходим
|
226
229
|
if (disable) return;
|
227
|
-
const followFiles: string[] = [];
|
228
230
|
// Иначе...
|
231
|
+
const followFiles: string[] = [];
|
229
232
|
// Определяем базовый файл
|
230
233
|
this.baseURI = (await DocHub.dataLake.getURIForPath(this.profile.$base) || []).pop();
|
231
234
|
// Если определить его не удалось, вываливаемся в ошибку
|
232
235
|
if (!this.baseURI) throw new DocHubError(`Can not resolve base URI for base path [${this.profile.$base}]`);
|
236
|
+
const baseStruct = this.profile.$base.split('/');
|
233
237
|
// Если указан шаблон, добавляем его в отслеживаемые файлы
|
234
238
|
if(this.profile?.template) {
|
235
|
-
|
239
|
+
debugger;
|
240
|
+
const templatePath = [...baseStruct, 'template'].join('/');
|
241
|
+
this.templateURI = (await DocHub.dataLake.getURIForPath(templatePath) || []).pop()
|
242
|
+
|| DocHub.dataLake.resolveURI(this.baseURI, this.profile.template);
|
243
|
+
if (!this.templateURI) throw new DocHubError(`Can not resolve template URI for path [${templatePath}]`);
|
244
|
+
followFiles.push(this.templateURI);
|
236
245
|
} else if (typeof this.profile?.source === 'string' && this.getType() === DocHubDocumentType.content) {
|
246
|
+
debugger;
|
237
247
|
// Если шаблона нет, но документ предполагает работу с содержимым файла, то отслеживаем source
|
238
|
-
|
248
|
+
const sourcePath = [...baseStruct, 'source'].join('/');
|
249
|
+
this.sourceURI = (await DocHub.dataLake.getURIForPath(sourcePath) || []).pop()
|
250
|
+
|| DocHub.dataLake.resolveURI(this.baseURI, this.profile.source);
|
251
|
+
if (!this.sourceURI) throw new DocHubError(`Can not resolve source URI for path [${sourcePath}]`);
|
252
|
+
followFiles.push(this.sourceURI);
|
239
253
|
}
|
240
254
|
// Даем возможность повлиять на список отслеживаемых файлов через переопределенный метод
|
241
255
|
this.followFiles = await this.processingFollowFiles(followFiles);
|