dochub-sdk 0.1.175 → 0.1.177
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 +57 -10
- package/package.json +1 -1
@@ -8,6 +8,23 @@ import type { IDocHubEditableComponent, IDocHubPresentationProfile, IDocHubPrese
|
|
8
8
|
import ajv from 'ajv';
|
9
9
|
import ajv_localize from 'ajv-i18n/localize/ru';
|
10
10
|
|
11
|
+
|
12
|
+
//********************************************
|
13
|
+
// !!!!!!! followURI не задается !!!!!
|
14
|
+
//********************************************
|
15
|
+
|
16
|
+
export enum DocHubDocumentType {
|
17
|
+
content = 'content', // Работает с неструктурированными данными.
|
18
|
+
// В поле source предполагается путь к файлу с данными.
|
19
|
+
// Если есть поле template, предполагается, что в нем ссылка на шаблон,
|
20
|
+
// а в source запрос для генерации данных для его заполнения.
|
21
|
+
// В результате работы вызовет метод processingContent
|
22
|
+
|
23
|
+
data = 'data' // Работает только со структурированными данными.
|
24
|
+
// Предполагается, что в source находится запрос.
|
25
|
+
// В результате работы вызовет метод processingData
|
26
|
+
}
|
27
|
+
|
11
28
|
@Component
|
12
29
|
export class DocHubDocumentProto extends DocHubComponentProto implements IDocHubEditableComponent {
|
13
30
|
onRefresher: any = null; // Таймер отложенного выполнения обновления
|
@@ -73,9 +90,17 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
73
90
|
|
74
91
|
/**
|
75
92
|
* Обработка полученных данных документа.
|
76
|
-
*
|
93
|
+
* Можно перехватывать.
|
77
94
|
*/
|
78
|
-
processingData(data: any
|
95
|
+
processingData(data: any): any {
|
96
|
+
return data;
|
97
|
+
}
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Обработка полученных данных документа.
|
101
|
+
* Нужно переопределить для типа документа DocHubDocumentType.content
|
102
|
+
*/
|
103
|
+
processingContent(content: any) {
|
79
104
|
throw new DocHubError('Not implemented.');
|
80
105
|
}
|
81
106
|
|
@@ -87,6 +112,13 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
87
112
|
return {};
|
88
113
|
}
|
89
114
|
|
115
|
+
/**
|
116
|
+
* Возвращает тип документа
|
117
|
+
*/
|
118
|
+
getType(): DocHubDocumentType {
|
119
|
+
return DocHubDocumentType.content;
|
120
|
+
}
|
121
|
+
|
90
122
|
/**
|
91
123
|
* Обрабатываем событие переключения языкового пакета
|
92
124
|
*/
|
@@ -101,23 +133,38 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
101
133
|
try {
|
102
134
|
this.isPending = true;
|
103
135
|
await this.refreshFileFollow();
|
104
|
-
|
105
|
-
|
136
|
+
const template = (this.getType() === DocHubDocumentType.content) && this.profile?.template
|
137
|
+
&& (await DocHub.dataLake.pullFile(
|
138
|
+
DocHub.dataLake.resolveURI(this.followURI || this.profile?.template, this.profile?.template)
|
139
|
+
)).data;
|
140
|
+
if (!this.profile?.source) throw new DocHubError('Document must have field "source" in profile!');
|
141
|
+
let result = (template || (this.getType() === DocHubDocumentType.data))
|
142
|
+
&& await DocHub.dataLake.resolveDataSetProfile(this.profile, {
|
106
143
|
params: this.params,
|
107
144
|
baseURI: this.followURI
|
108
|
-
})
|
109
|
-
|
145
|
+
})
|
146
|
+
|| (await DocHub.dataLake.pullFile(
|
147
|
+
DocHub.dataLake.resolveURI(this.followURI || this.profile?.source as string, this.profile?.source as string)
|
148
|
+
)).data;
|
149
|
+
// Валидируем данные по структуре, если это требуется
|
150
|
+
if (template || (this.getType() === DocHubDocumentType.data)) {
|
110
151
|
const rules = new ajv({ allErrors: true });
|
111
152
|
const validator = rules.compile(this.getSchemaData());
|
112
153
|
if (!validator(result)) {
|
113
154
|
ajv_localize(validator.errors);
|
114
155
|
this.error = JSON.stringify(validator.errors, null, 4);
|
115
156
|
return;
|
116
|
-
}
|
157
|
+
}
|
117
158
|
// Если все в порядке, вызываем процессинг данных
|
118
|
-
this.processingData(result);
|
119
|
-
|
120
|
-
|
159
|
+
result = this.processingData(result);
|
160
|
+
}
|
161
|
+
// Транслируем по шаблону
|
162
|
+
if (template) {
|
163
|
+
result = DocHub.tools.mustache.render(template.toString(), result);
|
164
|
+
}
|
165
|
+
// Вызываем метод обработки полученного контента, если это требуется
|
166
|
+
(template || (this.getType() === DocHubDocumentType.content)) && this.processingContent(result);
|
167
|
+
this.error = null;
|
121
168
|
} catch (error) {
|
122
169
|
// eslint-disable-next-line no-console
|
123
170
|
console.error(error);
|