dochub-sdk 0.1.180 → 0.1.182
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 +52 -18
- package/package.json +1 -1
@@ -29,7 +29,8 @@ export enum DocHubDocumentType {
|
|
29
29
|
@Component
|
30
30
|
export class DocHubDocumentProto extends DocHubComponentProto implements IDocHubEditableComponent {
|
31
31
|
onRefresher: any = null; // Таймер отложенного выполнения обновления
|
32
|
-
|
32
|
+
followFiles: string[] | undefined; // Список файлов за изменениями которых нужно следить
|
33
|
+
baseURI: string | undefined; // URI документа от которого должны разрешаться все относительные ссылки
|
33
34
|
error: string | null = null; // Ошибка
|
34
35
|
isPending = true; // Признак внутренней работы. Например загрузка данных.
|
35
36
|
|
@@ -70,7 +71,7 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
70
71
|
|
71
72
|
destroyed() {
|
72
73
|
// Отключаем слежку за файлом
|
73
|
-
this.
|
74
|
+
this.refreshFilesFollow(true);
|
74
75
|
}
|
75
76
|
|
76
77
|
/**
|
@@ -84,7 +85,7 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
84
85
|
* Открываем редактор
|
85
86
|
*/
|
86
87
|
openEditor(): void {
|
87
|
-
this.
|
88
|
+
this.baseURI && DocHub.dataLake.openFileEditor(this.baseURI, {
|
88
89
|
targetPath: this.profile.$base
|
89
90
|
});
|
90
91
|
}
|
@@ -93,7 +94,7 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
93
94
|
* Обработка полученных данных документа.
|
94
95
|
* Можно перехватывать.
|
95
96
|
*/
|
96
|
-
processingData(data: any): any {
|
97
|
+
async processingData(data: any): Promise<any> {
|
97
98
|
return data;
|
98
99
|
}
|
99
100
|
|
@@ -101,10 +102,20 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
101
102
|
* Обработка полученных данных документа.
|
102
103
|
* Нужно переопределить для типа документа DocHubDocumentType.content
|
103
104
|
*/
|
104
|
-
processingContent(content: AxiosResponse) {
|
105
|
+
async processingContent(content: AxiosResponse): Promise<void> {
|
105
106
|
throw new DocHubError(`The document has ${this.getType()} type. It must have processingContent method. But, the method is not implemented.`);
|
106
107
|
}
|
107
108
|
|
109
|
+
/**
|
110
|
+
* Возвращает список отслеживаемых файлов.
|
111
|
+
* Может быть переопределен.
|
112
|
+
* @param files - Список файлов которые предполагается отслеживать
|
113
|
+
* @returns - Список файлов для отслеживания
|
114
|
+
*/
|
115
|
+
async processingFollowFiles(files: string[]): Promise<string[]> {
|
116
|
+
return files;
|
117
|
+
}
|
118
|
+
|
108
119
|
/**
|
109
120
|
* Возвращает схему данных для контроля структуры и состава данных.
|
110
121
|
* Необходимо переопределить.
|
@@ -114,7 +125,8 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
114
125
|
}
|
115
126
|
|
116
127
|
/**
|
117
|
-
* Возвращает тип
|
128
|
+
* Возвращает тип документа.
|
129
|
+
* Может быть переопределен.
|
118
130
|
*/
|
119
131
|
getType(): DocHubDocumentType {
|
120
132
|
return DocHubDocumentType.content;
|
@@ -134,18 +146,18 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
134
146
|
try {
|
135
147
|
if (!this.profile?.source) throw new DocHubError('Document must have field "source" in profile!');
|
136
148
|
this.isPending = true;
|
137
|
-
await this.
|
149
|
+
await this.refreshFilesFollow();
|
138
150
|
const template = (this.getType() === DocHubDocumentType.content) && this.profile?.template
|
139
151
|
&& (await DocHub.dataLake.pullFile(
|
140
|
-
DocHub.dataLake.resolveURI(this.
|
152
|
+
DocHub.dataLake.resolveURI(this.baseURI || this.profile?.template, this.profile?.template)
|
141
153
|
));
|
142
154
|
let result: AxiosResponse = (template || (this.getType() === DocHubDocumentType.data))
|
143
155
|
&& { data: await DocHub.dataLake.resolveDataSetProfile(this.profile, {
|
144
156
|
params: this.params,
|
145
|
-
baseURI: this.
|
157
|
+
baseURI: this.baseURI
|
146
158
|
}) } as AxiosResponse
|
147
159
|
|| (await DocHub.dataLake.pullFile(
|
148
|
-
DocHub.dataLake.resolveURI(this.
|
160
|
+
DocHub.dataLake.resolveURI(this.baseURI || this.profile?.source as string, this.profile?.source as string)
|
149
161
|
));
|
150
162
|
// Валидируем данные по структуре, если это требуется
|
151
163
|
if (template || (this.getType() === DocHubDocumentType.data)) {
|
@@ -157,7 +169,7 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
157
169
|
return;
|
158
170
|
}
|
159
171
|
// Если все в порядке, вызываем процессинг данных
|
160
|
-
result.data = this.processingData(result.data);
|
172
|
+
result.data = await this.processingData(result.data);
|
161
173
|
}
|
162
174
|
// Транслируем по шаблону
|
163
175
|
if (template) {
|
@@ -166,9 +178,10 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
166
178
|
data: DocHub.tools.mustache.render(template.data.toString(), result.data)
|
167
179
|
}
|
168
180
|
}
|
181
|
+
// Очищаем информацию об ошибке
|
182
|
+
this.error = null;
|
169
183
|
// Вызываем метод обработки полученного контента, если это требуется
|
170
184
|
(template || (this.getType() === DocHubDocumentType.content)) && this.processingContent(result);
|
171
|
-
this.error = null;
|
172
185
|
} catch (error) {
|
173
186
|
// eslint-disable-next-line no-console
|
174
187
|
console.error(error);
|
@@ -180,12 +193,33 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
180
193
|
}
|
181
194
|
|
182
195
|
// Обновляет URI файла за которым установлено наблюдение
|
183
|
-
async
|
184
|
-
//
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
196
|
+
async refreshFilesFollow(disable = false): Promise<void> {
|
197
|
+
// Очищаем ранее установленные отслеживания
|
198
|
+
for(const uri of this.followFiles || []) {
|
199
|
+
DocHub.dataLake.unfollowFile(uri, this.onRefresh);
|
200
|
+
}
|
201
|
+
const followFiles: string[] = [];
|
202
|
+
// Если нужно только очистить отслеживание - выходим
|
203
|
+
if (disable) return;
|
204
|
+
// Иначе...
|
205
|
+
// Определяем базовый файл
|
206
|
+
this.baseURI = (await DocHub.dataLake.getURIForPath(this.profile.$base) || []).pop();
|
207
|
+
// Если определить его не удалось, вываливаемся в ошибку
|
208
|
+
if (!this.baseURI) throw new DocHubError(`Can not resolve base URI for base path [${this.profile.$base}]`);
|
209
|
+
// Добавляем его в отслеживание
|
210
|
+
this.baseURI && followFiles.push(this.baseURI);
|
211
|
+
// Если указан шаблон, добавляем его в отслеживаемые файлы
|
212
|
+
if(this.profile?.template) {
|
213
|
+
followFiles.push(DocHub.dataLake.resolveURI(this.baseURI, this.profile.template));
|
214
|
+
} else if (typeof this.profile?.source === 'string' && this.getType() === DocHubDocumentType.content) {
|
215
|
+
// Если шаблона нет, но документ предполагает работу с содержимым файла, то отслеживаем source
|
216
|
+
followFiles.push(DocHub.dataLake.resolveURI(this.baseURI, this.profile?.source));
|
217
|
+
}
|
218
|
+
// Даем возможность повлиять на список отслеживаемых файлов через переопределенный метод
|
219
|
+
this.followFiles = await this.processingFollowFiles(followFiles);
|
220
|
+
// Устанавливаем отслеживание
|
221
|
+
for(const uri of this.followFiles || []) {
|
222
|
+
DocHub.dataLake.followFile(uri, this.onRefresh);
|
189
223
|
}
|
190
224
|
}
|
191
225
|
|