Доработан js и минимизация json
This commit is contained in:
@@ -7,8 +7,9 @@ import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.mi
|
||||
class ReportRenderer {
|
||||
constructor(data) {
|
||||
this.data = data;
|
||||
this.files = data.files || [];
|
||||
this.diagram = data.diagram;
|
||||
this.files = data.files || data.f || [];
|
||||
this.rules = data.rules || data.r || {};
|
||||
this.diagram = data.diagram || data.d || {};
|
||||
this.currentFileIndex = 0;
|
||||
|
||||
this.reportsContainer = document.getElementById('reports-container');
|
||||
@@ -24,12 +25,13 @@ class ReportRenderer {
|
||||
this.renderTabs();
|
||||
this.renderFileReports();
|
||||
this.setupTabNavigation();
|
||||
|
||||
// Активируем первый таб
|
||||
this.activateTab(0);
|
||||
}
|
||||
|
||||
renderTabs() {
|
||||
const tabsList = document.getElementById('tabs-list');
|
||||
if (!tabsList) return;
|
||||
|
||||
this.tabsList.innerHTML = '';
|
||||
|
||||
// Табы для файлов
|
||||
@@ -39,25 +41,30 @@ class ReportRenderer {
|
||||
tab.dataset.target = `file_${index}`;
|
||||
tab.dataset.index = index;
|
||||
|
||||
const total = (file.v.c?.length || 0) + (file.v.w?.length || 0) + (file.v.i?.length || 0);
|
||||
|
||||
tab.innerHTML = `
|
||||
${this.escapeHtml(file.fileName)}
|
||||
<span class="tab-badge">${file.totalViolations || this.calculateTotalViolations(file)}</span>
|
||||
${this.escapeHtml(file.n)}
|
||||
<span class="tab-badge">${total}</span>
|
||||
`;
|
||||
|
||||
this.tabsList.appendChild(tab);
|
||||
});
|
||||
|
||||
// Таб для диаграммы (если есть)
|
||||
if (this.diagram?.hasDiagram) {
|
||||
if (this.diagram.h || this.diagram.hasDiagram) {
|
||||
const diagramTab = document.createElement('button');
|
||||
diagramTab.className = 'tab';
|
||||
diagramTab.dataset.target = 'mermaid';
|
||||
diagramTab.textContent = 'Диаграмма';
|
||||
this.tabsList.appendChild(diagramTab);
|
||||
tabsList.appendChild(diagramTab);
|
||||
}
|
||||
}
|
||||
|
||||
renderFileReports() {
|
||||
const container = document.getElementById('reports-container');
|
||||
if (!container) return;
|
||||
|
||||
this.reportsContainer.innerHTML = '';
|
||||
|
||||
// Рендеринг отчетов по файлам
|
||||
@@ -67,6 +74,9 @@ class ReportRenderer {
|
||||
reportDiv.className = 'file-report';
|
||||
reportDiv.style.display = 'none';
|
||||
|
||||
const fileName = file.n || file.fileName || '';
|
||||
const violations = file.v || file.violations || {};
|
||||
|
||||
// Заголовок файла
|
||||
reportDiv.innerHTML = `
|
||||
<div class="file-title-container">
|
||||
@@ -75,27 +85,28 @@ class ReportRenderer {
|
||||
<path d="M14 2H6C4.9 2 4 2.9 4 4V20C4 21.1 4.9 22 6 22H18C19.1 22 20 21.1 20 20V8L14 2Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M14 2V8H20" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
<span class="file-name">${this.escapeHtml(file.fileName)}</span>
|
||||
<span class="file-name">${this.escapeHtml(fileName)}</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Секции по severity
|
||||
if (file.criticalViolations?.length > 0) {
|
||||
reportDiv.appendChild(this.createSeveritySection('critical', file.criticalViolations));
|
||||
// Добавляем секции нарушений
|
||||
if (file.v.c?.length > 0) {
|
||||
reportDiv.appendChild(this.createViolationSection('critical', file.v.c));
|
||||
}
|
||||
if (file.warningViolations?.length > 0) {
|
||||
reportDiv.appendChild(this.createSeveritySection('warning', file.warningViolations));
|
||||
if (file.v.w?.length > 0) {
|
||||
reportDiv.appendChild(this.createViolationSection('warning', file.v.w));
|
||||
}
|
||||
if (file.infoViolations?.length > 0) {
|
||||
reportDiv.appendChild(this.createSeveritySection('info', file.infoViolations));
|
||||
if (file.v.i?.length > 0) {
|
||||
reportDiv.appendChild(this.createViolationSection('info', file.v.i));
|
||||
}
|
||||
|
||||
this.reportsContainer.appendChild(reportDiv);
|
||||
});
|
||||
|
||||
// Контейнер для диаграммы (если есть)
|
||||
if (this.diagram?.hasDiagram) {
|
||||
if (this.diagram.h || this.diagram.hasDiagram) {
|
||||
const diagramContent = this.diagram.c || this.diagram.Content || '';
|
||||
const diagramDiv = document.createElement('div');
|
||||
diagramDiv.id = 'mermaid';
|
||||
diagramDiv.className = 'file-report';
|
||||
@@ -104,7 +115,7 @@ class ReportRenderer {
|
||||
diagramDiv.innerHTML = `
|
||||
<div class="diagram-toolbar">
|
||||
<div class="toolbar-search">
|
||||
<input type="text" id="diagramSearch" placeholder="Поиск по узлам (нажмите Enter)" />
|
||||
<input type="text" id="diagramSearch" placeholder="Поиск по узлам" />
|
||||
<button class="search-clear" type="button">✕</button>
|
||||
</div>
|
||||
<div class="toolbar-actions">
|
||||
@@ -131,7 +142,7 @@ class ReportRenderer {
|
||||
<div id="minimap"></div>
|
||||
</div>
|
||||
<div id="mermaidSource" style="display:none">
|
||||
${this.escapeHtml(this.diagram.mermaidContent)}
|
||||
${this.escapeHtml(diagramContent)}
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -139,7 +150,7 @@ class ReportRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
createSeveritySection(severity, violations) {
|
||||
createViolationSection(severity, violations) {
|
||||
const severityTitle = {
|
||||
critical: 'Critical',
|
||||
warning: 'Warning',
|
||||
@@ -149,15 +160,31 @@ class ReportRenderer {
|
||||
const section = document.createElement('div');
|
||||
section.className = `severity-section ${severity}`;
|
||||
|
||||
const tableRows = violations.map(v => `
|
||||
<tr>
|
||||
<td class="index">${v.index}</td>
|
||||
<td class="line">${v.line}</td>
|
||||
<td class="column">${v.column}</td>
|
||||
<td class="rule">${this.escapeHtml(v.ruleName)}</td>
|
||||
<td class="description">${this.escapeHtml(v.text)}</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
const tableRows = violations.map(violation => {
|
||||
// Получаем правило по ID
|
||||
const ruleId = violation.r || violation.ruleId;
|
||||
const rule = this.rules[ruleId] || { n: 'Unknown', t: 'Описание отсутствует' };
|
||||
|
||||
// Формируем текст с подстановкой параметров
|
||||
let text = rule.t || '';
|
||||
const args = violation.a || violation.args || [];
|
||||
|
||||
if (args.length > 0 && text.includes('{')) {
|
||||
args.forEach((arg, index) => {
|
||||
text = text.replace(new RegExp(`\\{${index}\\}`, 'g'), arg);
|
||||
});
|
||||
}
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td class="index">${violation.i || violation.index}</td>
|
||||
<td class="line">${violation.l || violation.line}</td>
|
||||
<td class="column">${violation.c || violation.column}</td>
|
||||
<td class="rule">${this.escapeHtml(rule.n || rule.name)}</td>
|
||||
<td class="description">${this.escapeHtml(text)}</td>
|
||||
</tr>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
section.innerHTML = `
|
||||
<div class="severity-header">
|
||||
|
||||
Reference in New Issue
Block a user