dochub-sdk 0.1.181 → 0.1.183
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 +55 -14
- 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
|
|
@@ -49,6 +50,14 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
49
50
|
default: {}
|
50
51
|
}) readonly params: IDocHubPresentationsParams;
|
51
52
|
|
53
|
+
/**
|
54
|
+
* Признак версии для печати
|
55
|
+
*/
|
56
|
+
@Prop({
|
57
|
+
type: Boolean,
|
58
|
+
default: false
|
59
|
+
}) readonly isPrintVersion: boolean;
|
60
|
+
|
52
61
|
/**
|
53
62
|
* Следим за изменением профиля документа
|
54
63
|
*/
|
@@ -70,7 +79,7 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
70
79
|
|
71
80
|
destroyed() {
|
72
81
|
// Отключаем слежку за файлом
|
73
|
-
this.
|
82
|
+
this.refreshFilesFollow(true);
|
74
83
|
}
|
75
84
|
|
76
85
|
/**
|
@@ -84,7 +93,7 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
84
93
|
* Открываем редактор
|
85
94
|
*/
|
86
95
|
openEditor(): void {
|
87
|
-
this.
|
96
|
+
this.baseURI && DocHub.dataLake.openFileEditor(this.baseURI, {
|
88
97
|
targetPath: this.profile.$base
|
89
98
|
});
|
90
99
|
}
|
@@ -105,6 +114,16 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
105
114
|
throw new DocHubError(`The document has ${this.getType()} type. It must have processingContent method. But, the method is not implemented.`);
|
106
115
|
}
|
107
116
|
|
117
|
+
/**
|
118
|
+
* Возвращает список отслеживаемых файлов.
|
119
|
+
* Может быть переопределен.
|
120
|
+
* @param files - Список файлов которые предполагается отслеживать
|
121
|
+
* @returns - Список файлов для отслеживания
|
122
|
+
*/
|
123
|
+
async processingFollowFiles(files: string[]): Promise<string[]> {
|
124
|
+
return files;
|
125
|
+
}
|
126
|
+
|
108
127
|
/**
|
109
128
|
* Возвращает схему данных для контроля структуры и состава данных.
|
110
129
|
* Необходимо переопределить.
|
@@ -114,7 +133,8 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
114
133
|
}
|
115
134
|
|
116
135
|
/**
|
117
|
-
* Возвращает тип
|
136
|
+
* Возвращает тип документа.
|
137
|
+
* Может быть переопределен.
|
118
138
|
*/
|
119
139
|
getType(): DocHubDocumentType {
|
120
140
|
return DocHubDocumentType.content;
|
@@ -134,18 +154,18 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
134
154
|
try {
|
135
155
|
if (!this.profile?.source) throw new DocHubError('Document must have field "source" in profile!');
|
136
156
|
this.isPending = true;
|
137
|
-
await this.
|
157
|
+
await this.refreshFilesFollow();
|
138
158
|
const template = (this.getType() === DocHubDocumentType.content) && this.profile?.template
|
139
159
|
&& (await DocHub.dataLake.pullFile(
|
140
|
-
DocHub.dataLake.resolveURI(this.
|
160
|
+
DocHub.dataLake.resolveURI(this.baseURI || this.profile?.template, this.profile?.template)
|
141
161
|
));
|
142
162
|
let result: AxiosResponse = (template || (this.getType() === DocHubDocumentType.data))
|
143
163
|
&& { data: await DocHub.dataLake.resolveDataSetProfile(this.profile, {
|
144
164
|
params: this.params,
|
145
|
-
baseURI: this.
|
165
|
+
baseURI: this.baseURI
|
146
166
|
}) } as AxiosResponse
|
147
167
|
|| (await DocHub.dataLake.pullFile(
|
148
|
-
DocHub.dataLake.resolveURI(this.
|
168
|
+
DocHub.dataLake.resolveURI(this.baseURI || this.profile?.source as string, this.profile?.source as string)
|
149
169
|
));
|
150
170
|
// Валидируем данные по структуре, если это требуется
|
151
171
|
if (template || (this.getType() === DocHubDocumentType.data)) {
|
@@ -181,12 +201,33 @@ export class DocHubDocumentProto extends DocHubComponentProto implements IDocHub
|
|
181
201
|
}
|
182
202
|
|
183
203
|
// Обновляет URI файла за которым установлено наблюдение
|
184
|
-
async
|
185
|
-
//
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
204
|
+
async refreshFilesFollow(disable = false): Promise<void> {
|
205
|
+
// Очищаем ранее установленные отслеживания
|
206
|
+
for(const uri of this.followFiles || []) {
|
207
|
+
DocHub.dataLake.unfollowFile(uri, this.onRefresh);
|
208
|
+
}
|
209
|
+
const followFiles: string[] = [];
|
210
|
+
// Если нужно только очистить отслеживание - выходим
|
211
|
+
if (disable) return;
|
212
|
+
// Иначе...
|
213
|
+
// Определяем базовый файл
|
214
|
+
this.baseURI = (await DocHub.dataLake.getURIForPath(this.profile.$base) || []).pop();
|
215
|
+
// Если определить его не удалось, вываливаемся в ошибку
|
216
|
+
if (!this.baseURI) throw new DocHubError(`Can not resolve base URI for base path [${this.profile.$base}]`);
|
217
|
+
// Добавляем его в отслеживание
|
218
|
+
this.baseURI && followFiles.push(this.baseURI);
|
219
|
+
// Если указан шаблон, добавляем его в отслеживаемые файлы
|
220
|
+
if(this.profile?.template) {
|
221
|
+
followFiles.push(DocHub.dataLake.resolveURI(this.baseURI, this.profile.template));
|
222
|
+
} else if (typeof this.profile?.source === 'string' && this.getType() === DocHubDocumentType.content) {
|
223
|
+
// Если шаблона нет, но документ предполагает работу с содержимым файла, то отслеживаем source
|
224
|
+
followFiles.push(DocHub.dataLake.resolveURI(this.baseURI, this.profile?.source));
|
225
|
+
}
|
226
|
+
// Даем возможность повлиять на список отслеживаемых файлов через переопределенный метод
|
227
|
+
this.followFiles = await this.processingFollowFiles(followFiles);
|
228
|
+
// Устанавливаем отслеживание
|
229
|
+
for(const uri of this.followFiles || []) {
|
230
|
+
DocHub.dataLake.followFile(uri, this.onRefresh);
|
190
231
|
}
|
191
232
|
}
|
192
233
|
|