Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -5,13 +5,34 @@ class PDFComplianceAnalyzer {
|
|
5 |
this.resultsContainer = document.getElementById('analysis-results');
|
6 |
this.reportContainer = document.getElementById('compliance-report');
|
7 |
this.reportContent = document.querySelector('.report-content');
|
|
|
|
|
|
|
8 |
|
9 |
this.initializeEventListeners();
|
|
|
10 |
}
|
11 |
|
12 |
initializeEventListeners() {
|
13 |
this.fileInput.addEventListener('change', (e) => this.handleFileChange(e));
|
14 |
this.setupDragAndDrop();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
}
|
16 |
|
17 |
setupDragAndDrop() {
|
@@ -33,39 +54,96 @@ class PDFComplianceAnalyzer {
|
|
33 |
|
34 |
uploadArea.addEventListener('drop', (e) => {
|
35 |
const files = Array.from(e.dataTransfer.files);
|
36 |
-
if (files.length > 0
|
37 |
-
this.
|
38 |
-
} else {
|
39 |
-
this.showError('Por favor, envie apenas arquivos PDF.');
|
40 |
}
|
41 |
});
|
42 |
}
|
43 |
|
44 |
handleFileChange(e) {
|
45 |
const file = e.target.files[0];
|
46 |
-
if (file
|
47 |
-
this.
|
48 |
-
} else {
|
49 |
-
this.showError('Por favor, selecione um arquivo PDF válido.');
|
50 |
}
|
51 |
}
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
async analyzePDF(file) {
|
54 |
this.showLoading(true);
|
|
|
55 |
this.clearResults();
|
56 |
|
57 |
try {
|
58 |
-
|
59 |
await this.validatePDF(file);
|
60 |
const report = await this.generateComplianceReport(file);
|
61 |
this.displayResults(report);
|
|
|
62 |
} catch (error) {
|
63 |
this.showError(error.message);
|
|
|
64 |
} finally {
|
65 |
this.showLoading(false);
|
|
|
66 |
}
|
67 |
}
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
async validatePDF(file) {
|
70 |
return new Promise((resolve, reject) => {
|
71 |
const reader = new FileReader();
|
@@ -87,7 +165,6 @@ class PDFComplianceAnalyzer {
|
|
87 |
}
|
88 |
|
89 |
async generateComplianceReport(file) {
|
90 |
-
// Simulação de análise de conformidade
|
91 |
await new Promise(resolve => setTimeout(resolve, 1500));
|
92 |
|
93 |
return {
|
@@ -113,31 +190,47 @@ class PDFComplianceAnalyzer {
|
|
113 |
displayResults(report) {
|
114 |
this.reportContainer.classList.remove('hidden');
|
115 |
|
116 |
-
const statusClass = report.status === 'compliant' ? '
|
117 |
const statusText = report.status === 'compliant' ? 'Conforme' : 'Não conforme';
|
118 |
|
119 |
this.reportContent.innerHTML = `
|
120 |
-
<div class="
|
121 |
-
<
|
122 |
-
<
|
|
|
|
|
|
|
|
|
|
|
123 |
</div>
|
124 |
|
125 |
<div class="report-section">
|
126 |
<h3>Detalhes do Documento</h3>
|
127 |
-
|
128 |
-
<
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
133 |
</div>
|
134 |
|
135 |
<div class="report-section">
|
136 |
<h3>Verificações de Conformidade</h3>
|
137 |
${report.checks.map(check => `
|
138 |
-
<div class="
|
139 |
-
<
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
</div>
|
142 |
`).join('')}
|
143 |
</div>
|
|
|
5 |
this.resultsContainer = document.getElementById('analysis-results');
|
6 |
this.reportContainer = document.getElementById('compliance-report');
|
7 |
this.reportContent = document.querySelector('.report-content');
|
8 |
+
this.progressContainer = document.getElementById('progress-container');
|
9 |
+
this.progressBar = document.getElementById('progress-bar');
|
10 |
+
this.toastElement = document.getElementById('toast');
|
11 |
|
12 |
this.initializeEventListeners();
|
13 |
+
this.initializeThemeToggle();
|
14 |
}
|
15 |
|
16 |
initializeEventListeners() {
|
17 |
this.fileInput.addEventListener('change', (e) => this.handleFileChange(e));
|
18 |
this.setupDragAndDrop();
|
19 |
+
|
20 |
+
// Keyboard navigation
|
21 |
+
document.addEventListener('keydown', (e) => {
|
22 |
+
if (e.key === 'Escape') this.closeToast();
|
23 |
+
});
|
24 |
+
}
|
25 |
+
|
26 |
+
initializeThemeToggle() {
|
27 |
+
const themeToggle = document.getElementById('theme-toggle');
|
28 |
+
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
29 |
+
|
30 |
+
document.body.classList.toggle('dark-theme', prefersDark);
|
31 |
+
|
32 |
+
themeToggle.addEventListener('click', () => {
|
33 |
+
document.body.classList.toggle('dark-theme');
|
34 |
+
this.showToast('Tema alterado');
|
35 |
+
});
|
36 |
}
|
37 |
|
38 |
setupDragAndDrop() {
|
|
|
54 |
|
55 |
uploadArea.addEventListener('drop', (e) => {
|
56 |
const files = Array.from(e.dataTransfer.files);
|
57 |
+
if (files.length > 0) {
|
58 |
+
this.validateAndProcessFile(files[0]);
|
|
|
|
|
59 |
}
|
60 |
});
|
61 |
}
|
62 |
|
63 |
handleFileChange(e) {
|
64 |
const file = e.target.files[0];
|
65 |
+
if (file) {
|
66 |
+
this.validateAndProcessFile(file);
|
|
|
|
|
67 |
}
|
68 |
}
|
69 |
|
70 |
+
validateAndProcessFile(file) {
|
71 |
+
if (file.type !== 'application/pdf') {
|
72 |
+
this.showToast('Por favor, envie apenas arquivos PDF.', 'error');
|
73 |
+
return;
|
74 |
+
}
|
75 |
+
|
76 |
+
if (file.size > 10 * 1024 * 1024) {
|
77 |
+
this.showToast('O arquivo excede o limite de 10MB.', 'error');
|
78 |
+
return;
|
79 |
+
}
|
80 |
+
|
81 |
+
this.analyzePDF(file);
|
82 |
+
}
|
83 |
+
|
84 |
async analyzePDF(file) {
|
85 |
this.showLoading(true);
|
86 |
+
this.showSkeleton();
|
87 |
this.clearResults();
|
88 |
|
89 |
try {
|
90 |
+
await this.simulateFileUpload(file);
|
91 |
await this.validatePDF(file);
|
92 |
const report = await this.generateComplianceReport(file);
|
93 |
this.displayResults(report);
|
94 |
+
this.showToast('Análise concluída com sucesso!', 'success');
|
95 |
} catch (error) {
|
96 |
this.showError(error.message);
|
97 |
+
this.showToast(error.message, 'error');
|
98 |
} finally {
|
99 |
this.showLoading(false);
|
100 |
+
this.hideSkeleton();
|
101 |
}
|
102 |
}
|
103 |
|
104 |
+
simulateFileUpload(file) {
|
105 |
+
return new Promise((resolve) => {
|
106 |
+
this.progressContainer.classList.remove('hidden');
|
107 |
+
let progress = 0;
|
108 |
+
|
109 |
+
const interval = setInterval(() => {
|
110 |
+
progress += 10;
|
111 |
+
this.progressBar.style.width = `${progress}%`;
|
112 |
+
|
113 |
+
if (progress >= 100) {
|
114 |
+
clearInterval(interval);
|
115 |
+
setTimeout(() => {
|
116 |
+
this.progressContainer.classList.add('hidden');
|
117 |
+
resolve();
|
118 |
+
}, 200);
|
119 |
+
}
|
120 |
+
}, 100);
|
121 |
+
});
|
122 |
+
}
|
123 |
+
|
124 |
+
showSkeleton() {
|
125 |
+
const template = document.getElementById('skeleton-template');
|
126 |
+
const skeleton = template.content.cloneNode(true);
|
127 |
+
this.resultsContainer.appendChild(skeleton);
|
128 |
+
}
|
129 |
+
|
130 |
+
hideSkeleton() {
|
131 |
+
const skeleton = document.querySelector('.skeleton-loader');
|
132 |
+
if (skeleton) skeleton.remove();
|
133 |
+
}
|
134 |
+
|
135 |
+
showToast(message, type = 'info') {
|
136 |
+
this.toastElement.textContent = message;
|
137 |
+
this.toastElement.className = `toast toast-${type}`;
|
138 |
+
this.toastElement.classList.remove('hidden');
|
139 |
+
|
140 |
+
setTimeout(() => this.closeToast(), 3000);
|
141 |
+
}
|
142 |
+
|
143 |
+
closeToast() {
|
144 |
+
this.toastElement.classList.add('hidden');
|
145 |
+
}
|
146 |
+
|
147 |
async validatePDF(file) {
|
148 |
return new Promise((resolve, reject) => {
|
149 |
const reader = new FileReader();
|
|
|
165 |
}
|
166 |
|
167 |
async generateComplianceReport(file) {
|
|
|
168 |
await new Promise(resolve => setTimeout(resolve, 1500));
|
169 |
|
170 |
return {
|
|
|
190 |
displayResults(report) {
|
191 |
this.reportContainer.classList.remove('hidden');
|
192 |
|
193 |
+
const statusClass = report.status === 'compliant' ? 'badge-success' : 'badge-error';
|
194 |
const statusText = report.status === 'compliant' ? 'Conforme' : 'Não conforme';
|
195 |
|
196 |
this.reportContent.innerHTML = `
|
197 |
+
<div class="report-header">
|
198 |
+
<span class="badge ${statusClass}">${statusText}</span>
|
199 |
+
<div class="confidence-meter">
|
200 |
+
<div class="progress">
|
201 |
+
<div class="progress-bar" style="width: ${report.confidence}%"></div>
|
202 |
+
</div>
|
203 |
+
<span>Confiança: ${report.confidence}%</span>
|
204 |
+
</div>
|
205 |
</div>
|
206 |
|
207 |
<div class="report-section">
|
208 |
<h3>Detalhes do Documento</h3>
|
209 |
+
<div class="table-container">
|
210 |
+
<table class="table">
|
211 |
+
${Object.entries(report.details).map(([key, value]) => `
|
212 |
+
<tr>
|
213 |
+
<th>${key}</th>
|
214 |
+
<td>${value}</td>
|
215 |
+
</tr>
|
216 |
+
`).join('')}
|
217 |
+
</table>
|
218 |
+
</div>
|
219 |
</div>
|
220 |
|
221 |
<div class="report-section">
|
222 |
<h3>Verificações de Conformidade</h3>
|
223 |
${report.checks.map(check => `
|
224 |
+
<div class="check-item">
|
225 |
+
<div class="check-header">
|
226 |
+
<span>${check.name}</span>
|
227 |
+
<span class="badge ${check.status === 'pass' ? 'badge-success' : 'badge-error'}">
|
228 |
+
${check.score}%
|
229 |
+
</span>
|
230 |
+
</div>
|
231 |
+
<div class="progress">
|
232 |
+
<div class="progress-bar" style="width: ${check.score}%"></div>
|
233 |
+
</div>
|
234 |
</div>
|
235 |
`).join('')}
|
236 |
</div>
|