Spaces:
Sleeping
Sleeping
fix ui issue when downloading CR
Browse files- static/script.js +51 -5
static/script.js
CHANGED
|
@@ -45,6 +45,7 @@ function switchMode(mode) {
|
|
| 45 |
|
| 46 |
// Show version field only when the input looks like a spec (ETSI or 3GPP)
|
| 47 |
const ETSI_SPEC_RE = /^\d{3} \d{3}/;
|
|
|
|
| 48 |
const GPP_SPEC_RE = /^\d{2}\.\d{3}/;
|
| 49 |
|
| 50 |
function toggleVersionField() {
|
|
@@ -323,7 +324,17 @@ async function searchBM25() {
|
|
| 323 |
// Results display functions
|
| 324 |
function displaySingleResult(data) {
|
| 325 |
const resultsContent = document.getElementById('results-content');
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
resultsContent.innerHTML = `
|
| 328 |
<div class="result-item">
|
| 329 |
<div class="result-header">
|
|
@@ -333,16 +344,51 @@ function displaySingleResult(data) {
|
|
| 333 |
<div class="result-details">
|
| 334 |
${data.version ? `<div class="result-detail"><strong>Version:</strong> ${data.version}</div>` : ''}
|
| 335 |
${data.scope ? `<div class="result-detail"><strong>Scope:</strong> ${data.scope}</div>` : ''}
|
| 336 |
-
|
| 337 |
-
<strong>URL:</strong> <a href="${data.url}" target="_blank">${data.url}</a>
|
| 338 |
-
</div>
|
| 339 |
</div>
|
| 340 |
</div>
|
| 341 |
`;
|
| 342 |
-
|
| 343 |
showResults();
|
| 344 |
}
|
| 345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
function displayBatchResults(data) {
|
| 347 |
const resultsContent = document.getElementById('results-content');
|
| 348 |
let html = '';
|
|
|
|
| 45 |
|
| 46 |
// Show version field only when the input looks like a spec (ETSI or 3GPP)
|
| 47 |
const ETSI_SPEC_RE = /^\d{3} \d{3}/;
|
| 48 |
+
const ETSI_TDOC_RE = /^(?:SET|SCP|SETTEC|SETREQ|SCPTEC|SCPREQ)\(\d+\)\d+/i;
|
| 49 |
const GPP_SPEC_RE = /^\d{2}\.\d{3}/;
|
| 50 |
|
| 51 |
function toggleVersionField() {
|
|
|
|
| 324 |
// Results display functions
|
| 325 |
function displaySingleResult(data) {
|
| 326 |
const resultsContent = document.getElementById('results-content');
|
| 327 |
+
const isEtsiTdoc = ETSI_TDOC_RE.test(data.doc_id);
|
| 328 |
+
|
| 329 |
+
const urlBlock = isEtsiTdoc
|
| 330 |
+
? `<div class="result-detail">
|
| 331 |
+
<strong>URL:</strong> <span class="result-url-text">${data.url}</span>
|
| 332 |
+
<button class="btn btn-primary download-btn" onclick="downloadTdoc('${data.doc_id}')">Download</button>
|
| 333 |
+
</div>`
|
| 334 |
+
: `<div class="result-detail result-url">
|
| 335 |
+
<strong>URL:</strong> <a href="${data.url}" target="_blank">${data.url}</a>
|
| 336 |
+
</div>`;
|
| 337 |
+
|
| 338 |
resultsContent.innerHTML = `
|
| 339 |
<div class="result-item">
|
| 340 |
<div class="result-header">
|
|
|
|
| 344 |
<div class="result-details">
|
| 345 |
${data.version ? `<div class="result-detail"><strong>Version:</strong> ${data.version}</div>` : ''}
|
| 346 |
${data.scope ? `<div class="result-detail"><strong>Scope:</strong> ${data.scope}</div>` : ''}
|
| 347 |
+
${urlBlock}
|
|
|
|
|
|
|
| 348 |
</div>
|
| 349 |
</div>
|
| 350 |
`;
|
| 351 |
+
|
| 352 |
showResults();
|
| 353 |
}
|
| 354 |
|
| 355 |
+
async function downloadTdoc(docId) {
|
| 356 |
+
showLoading();
|
| 357 |
+
updateHeaderStats('Downloading...');
|
| 358 |
+
try {
|
| 359 |
+
const response = await fetch('/find/tdoc/download', {
|
| 360 |
+
method: 'POST',
|
| 361 |
+
headers: { 'Content-Type': 'application/json' },
|
| 362 |
+
body: JSON.stringify({ doc_id: docId })
|
| 363 |
+
});
|
| 364 |
+
if (response.ok) {
|
| 365 |
+
const blob = await response.blob();
|
| 366 |
+
const disposition = response.headers.get('Content-Disposition') || '';
|
| 367 |
+
const fnMatch = disposition.match(/filename="?([^";\n]+)"?/);
|
| 368 |
+
const filename = fnMatch ? fnMatch[1] : `${docId}.docx`;
|
| 369 |
+
const url = URL.createObjectURL(blob);
|
| 370 |
+
const a = document.createElement('a');
|
| 371 |
+
a.href = url;
|
| 372 |
+
a.download = filename;
|
| 373 |
+
document.body.appendChild(a);
|
| 374 |
+
a.click();
|
| 375 |
+
document.body.removeChild(a);
|
| 376 |
+
URL.revokeObjectURL(url);
|
| 377 |
+
updateHeaderStats('Downloaded');
|
| 378 |
+
} else {
|
| 379 |
+
const data = await response.json();
|
| 380 |
+
showError(data.detail);
|
| 381 |
+
updateHeaderStats('Error');
|
| 382 |
+
}
|
| 383 |
+
} catch (error) {
|
| 384 |
+
showError('Error connecting to server');
|
| 385 |
+
updateHeaderStats('Error');
|
| 386 |
+
console.error('Error:', error);
|
| 387 |
+
} finally {
|
| 388 |
+
hideLoading();
|
| 389 |
+
}
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
function displayBatchResults(data) {
|
| 393 |
const resultsContent = document.getElementById('results-content');
|
| 394 |
let html = '';
|