Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | 3x 2x 4x 4x 40x 40x 40x 3x 76x 60x 60x 60x 15x 48x 46x 46x 46x 46x 35x 35x 23x 20x 20x 23x 12x 11x 11x 12x 35x 35x 11x 11x 3x 2x 2x 3x 1x 2x 14x 14x 14x 4x 4x 14x 14x 13x 14x 4x 46x 46x 30x 30x 30x 47x 48x 48x 48x 1x 1x 48x 48x 47x 47x 47x 47x 48x 46x 47x 47x 1x 3x 2x 18x 14x 14x 4x 47x 47x 47x 47x 47x 47x | /*
Copyright (C) 2021 owner Roman Piontik R.Piontik@mail.ru
Copyright (C) 2022 Sber
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
In any derivative products, you must retain the information of
owner of the original code and provide clear attribution to the project
https://dochub.info
The use of this product or its derivatives for any purpose cannot be a secret.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Maintainers:
R.Piontik <r.piontik@mail.ru>
Contributors:
R.Piontik <r.piontik@mail.ru> - 2025
R.Piontik <r.piontik@mail.ru> - 2024
R.Piontik <r.piontik@mail.ru> - 2023
R.Piontik <r.piontik@mail.ru> - 2022
*/
import datasets from '@front/helpers/datasets';
import gateway from '@ide/gateway';
import uriTool from '@front/helpers/uri';
import requests from '@front/helpers/requests';
import {pageEventDocOnLoad, pageEventRegDoc} from '@front/clickstream/pageEvent.ts';
import {logComponentTree} from '@front/logger/loggerExtension';
import {SOURCE_ERROR, SOURCE_PENDING, SOURCE_READY} from '@front/helpers/docSource';
import {getLoggerWithTag} from '@global/logger/v2/logger.mjs';
import {openDocContextMenu} from './docContextMenuState';
const logger = getLoggerWithTag('f/c/D/DocMixin');
export default {
components: {
Box: {
template: `
<div v-on:contextmenu="onContextMenu">
<v-alert v-for="error in errors" v-bind:key="error.key" class="dh-alert dh-alert--error" icon="mdi-alert-circle-outline">
<div class="dh-alert__title">Ошибка компонента документа</div>
<dl class="dh-alert__fields">
<dt>Компонент</dt><dd>{{ error.componentName }}</dd>
<dt>Источник</dt><dd>{{ path }}</dd>
<template v-if="error.url">
<dt>URL</dt><dd><a v-bind:href="error.url" target="_blank" rel="noopener">{{ error.url }}</a></dd>
</template>
</dl>
<pre class="dh-alert__code">{{ error.message }}</pre>
</v-alert>
<slot v-if="!errors.length"></slot>
</div>`,
props: {
errors: {
type: Array,
default() {
return [];
}
},
path: {
type: String,
default: ''
}
},
emits: ['doc-contextmenu'],
methods: {
onContextMenu(event) {
this.$emit('doc-contextmenu', event);
}
}
}
},
methods: {
// Сохраняет состояние отображения документа
saveState() {
this.state.scrollY = window.scrollY;
this.state.scrollX = window.scrollX;
},
// Восстанавливает состояние отображение
loadState() {
logComponentTree('Mixin loadState', this);
//loadState вызывается после отрисовки компонента документа, так что фиксируем отрисовку тут
pageEventDocOnLoad();
if (this.state.scrollY !== null) {
window.scroll(this.state.scrollX, this.state.scrollY);
}
},
makeDataLakeID(path) {
return `("${path.slice(1).split('/').join('"."')}")`;
},
doRefresh() {
this.error = null;
if (this.source.refreshTimer) clearTimeout(this.source.refreshTimer);
this.source.refreshTimer = setTimeout(() => this.refresh(), 100);
},
refresh() {
// Базовый refresh завершает цепочку загрузки. Ошибка провайдера
// уже сохранена в sourceRefresh для отображения в документе.
this.sourceRefresh().catch(() => undefined);
},
sourceRefresh(isCurrent = () => true, reportCompletion = true) {
return new Promise((success, reject) => {
this.source.status = SOURCE_PENDING;
this.source.dataset = null;
if (this.isTemplate && this.profile?.source) {
const sourceBasePath = uriTool.getBaseURIOfPath(`${this.path}/source`) || this.baseURI;
this.source.provider.getData(null, this.profile, this.params, sourceBasePath)
.then((dataset) => {
if (isCurrent()) {
this.source.dataset = dataset;
this.source.status = SOURCE_READY;
}
success(dataset);
})
.catch((e) => {
if (isCurrent()) {
this.error = e;
this.source.status = SOURCE_ERROR;
}
reject(e);
})
.finally(() => {
this.$nextTick(() => {
if (reportCompletion && isCurrent()) this.loadState();
});
});
} else {
success(this.source.dataset = null);
// регистрируем что компонент документа отрисован (один из вариантов, если не попали в ветку if)
if (reportCompletion) pageEventDocOnLoad();
}
});
},
onChangeSource(data) {
if (data) {
this.saveState();
for (const source in data) {
if (source === requests.getIndexURL(this.url)) {
this.doRefresh();
}
}
}
},
showContextMenu(event) {
openDocContextMenu(event, this.contextMenu);
},
appendError(error, componentName) {
// Текст ошибки выводится интерполяцией и экранируется: в нем может быть ответ сервера
let message = (error?.message || error);
let url = null;
if (error?.response) {
message = error.response?.data?.error || JSON.stringify(error.response?.data) || '';
url = error.config?.url?.toString() || null;
}
let errorMessage = 'no error text';
if (typeof message === 'string') {
errorMessage = message?.slice(0, 1024)?.toString();
}
this.errors.push(
{
key: Date.now(),
message: errorMessage,
url,
componentName
}
);
},
clearErrors() {
this.errors = [];
}
},
computed: {
id() {
return this.path.split('/').pop();
},
isTemplate() {
return this.profile?.template;
},
baseURI() {
let result = uriTool.getBaseURIOfPath(this.path);
result?.startsWith('res://') && (result = requests.expandResourceURI(result));
return result;
},
contentBasePath() {
return uriTool.getBaseURIOfPath(`${this.path}/${this.isTemplate ? 'template' : 'source'}`) || this.baseURI;
},
url() {
let uri = this.profile.template || this.profile.source;
//признак, что ссылка на source указывает на вложенность (что метаданные и контент в одном файле)
let inlineContent = false;
if (uri === '.') {
inlineContent = true;
uri = this.contentBasePath;
}
uri?.startsWith('res://') && (uri = requests.expandResourceURI(uri));
let result = this.profile ? uriTool.makeURIByBaseURI(uri, this.contentBasePath).toString() : null;
Iif (!result) return null;
result += result.indexOf('?') > 0 ? '&' : '?';
result += `id=${this.id}&path=${encodeURI(this.path)}&inlineContent=${inlineContent}`;
return result;
},
isPrintVersion() {
return this.toPrint || this.$store.state.isPrintVersion;
}
},
props: {
// Признак того, что документ встроен в другой документ
inline: {
type: Boolean,
required: true
},
// Путь к данным профиля документа
path: {
type: String,
required: true
},
// Параметры передающиеся в запросы документа
params: {
type: Object,
required: true
},
// Признак рендеринга документа для печати
toPrint: {
type: Boolean,
required: false,
default: undefined
},
// Контекстное меню
contextMenu: {
type: Array,
default() {
return [];
}
},
// Профиль документа
profile: {
type: Object,
default() {
return {};
}
}
},
data() {
const provider = datasets();
return {
errors: [],
error: null,
state: {
scrollY: null,
scrollX: null
},
source: {
provider,
status: SOURCE_READY,
dataset: null,
refreshTimer: null
}
};
},
watch: {
path() { this.doRefresh(); },
params() { this.doRefresh(); },
profile() { this.doRefresh(); },
error(error) {
if (error) {
logger.error(() => `Ошибка запроса [${this.url}]`, error);
this.appendError(error, this.$options?.name || 'unknown');
} else
this.clearErrors();
}
},
created() {
// Следим за обновлением документа
logComponentTree('Mixin created', this);
//Когда документ создается, регистрируем его в событии загрузки страницы clickstream
pageEventRegDoc();
gateway.appendListener('source/changed', this.onChangeSource);
},
unmounted() {
gateway.removeListener('source/changed', this.onChangeSource);
},
mounted() {
logComponentTree('Mixin mounted', this);
this.doRefresh();
}
};
|