Fix JavaScript syntax error by building HTML incrementally instead of nested template literals
This commit is contained in:
1 parent
ce34482373
commit
54ed7aaffd
1 file changed
+54
-34
+54
-34
@@ -1305,14 +1305,24 @@ def jobs():
|
|||||||
try {
|
try {
|
||||||
const jobDiv = document.createElement('div');
|
const jobDiv = document.createElement('div');
|
||||||
jobDiv.className = 'job';
|
jobDiv.className = 'job';
|
||||||
jobDiv.innerHTML = `
|
|
||||||
|
// Build the HTML step by step to avoid syntax errors
|
||||||
|
let jobHTML = `
|
||||||
<h3>Job ${jobId.substring(0, 8)}</h3>
|
<h3>Job ${jobId.substring(0, 8)}</h3>
|
||||||
<p><strong>Status:</strong> <span class="status ${job.status}">${job.status.charAt(0).toUpperCase() + job.status.slice(1)}</span></p>
|
<p><strong>Status:</strong> <span class="status ${job.status}">${job.status.charAt(0).toUpperCase() + job.status.slice(1)}</span></p>`;
|
||||||
${job.status === 'processing' && job.progress ? `<p><strong>Progress:</strong> <span class="progress-text">${job.progress}</span></p>` : ''}
|
|
||||||
<p><strong>Files:</strong> ${job.files ? job.files.length : 0}</p>
|
// Add progress if processing
|
||||||
${job.zip_contents ? `
|
if (job.status === 'processing' && job.progress) {
|
||||||
<p><strong>ZIP Contents:</strong></p>
|
jobHTML += `<p><strong>Progress:</strong> <span class="progress-text">${job.progress}</span></p>`;
|
||||||
${Object.entries(job.zip_contents).map(([zipName, pdfFiles]) => `
|
}
|
||||||
|
|
||||||
|
jobHTML += `<p><strong>Files:</strong> ${job.files ? job.files.length : 0}</p>`;
|
||||||
|
|
||||||
|
// Add ZIP contents if available
|
||||||
|
if (job.zip_contents) {
|
||||||
|
jobHTML += `<p><strong>ZIP Contents:</strong></p>`;
|
||||||
|
Object.entries(job.zip_contents).forEach(([zipName, pdfFiles]) => {
|
||||||
|
jobHTML += `
|
||||||
<div class="zip-content">
|
<div class="zip-content">
|
||||||
<div class="zip-toggle" onclick="toggleZipDetails(this)">
|
<div class="zip-toggle" onclick="toggleZipDetails(this)">
|
||||||
<strong>${zipName}</strong> (${pdfFiles.length} files) ▶
|
<strong>${zipName}</strong> (${pdfFiles.length} files) ▶
|
||||||
@@ -1322,33 +1332,43 @@ def jobs():
|
|||||||
${pdfFiles.map(pdfFile => `<li>${pdfFile}</li>`).join('')}
|
${pdfFiles.map(pdfFile => `<li>${pdfFile}</li>`).join('')}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>`;
|
||||||
`).join('')}
|
});
|
||||||
` : ''}
|
}
|
||||||
${job.status === 'completed' ? (job.zip_name ? `
|
|
||||||
<p><a href="/download/${job.zip_name}" class="download-btn">Download ZIP</a>
|
// Add download/delete buttons if completed
|
||||||
<form method="post" action="/delete/${jobId}" style="display: inline;">
|
if (job.status === 'completed') {
|
||||||
<button type="submit" class="delete-btn" onclick="return confirm('Are you sure you want to delete this job?')">Delete Job</button>
|
if (job.zip_name) {
|
||||||
</form></p>
|
jobHTML += `
|
||||||
` : `
|
<p><a href="/download/${job.zip_name}" class="download-btn">Download ZIP</a>
|
||||||
<p><em>No files were successfully processed to create a ZIP archive.</em>
|
<form method="post" action="/delete/${jobId}" style="display: inline;">
|
||||||
<form method="post" action="/delete/${jobId}" style="display: inline;">
|
<button type="submit" class="delete-btn" onclick="return confirm('Are you sure you want to delete this job?')">Delete Job</button>
|
||||||
<button type="submit" class="delete-btn" onclick="return confirm('Are you sure you want to delete this job?')">Delete Job</button>
|
</form></p>`;
|
||||||
</form></p>
|
} else {
|
||||||
` : ''}
|
jobHTML += `
|
||||||
${job.skipped ? `
|
<p><em>No files were successfully processed to create a ZIP archive.</em>
|
||||||
<div class="skipped-section">
|
<form method="post" action="/delete/${jobId}" style="display: inline;">
|
||||||
<div class="skipped-toggle" onclick="toggleSkippedDetails(this)">
|
<button type="submit" class="delete-btn" onclick="return confirm('Are you sure you want to delete this job?')">Delete Job</button>
|
||||||
⚠️ Skipped Files (${job.skipped.length}) ▶
|
</form></p>`;
|
||||||
</div>
|
}
|
||||||
<div class="skipped-details">
|
|
||||||
<ul>
|
// Add skipped files section if any
|
||||||
${job.skipped.map(skipInfo => `<li><strong>${skipInfo[0]}</strong>: ${skipInfo[1]}</li>`).join('')}
|
if (job.skipped && job.skipped.length > 0) {
|
||||||
</ul>
|
jobHTML += `
|
||||||
</div>
|
<div class="skipped-section">
|
||||||
</div>
|
<div class="skipped-toggle" onclick="toggleSkippedDetails(this)">
|
||||||
` : ''}
|
⚠️ Skipped Files (${job.skipped.length}) ▶
|
||||||
`;
|
</div>
|
||||||
|
<div class="skipped-details">
|
||||||
|
<ul>
|
||||||
|
${job.skipped.map(skipInfo => `<li><strong>${skipInfo[0]}</strong>: ${skipInfo[1]}</li>`).join('')}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jobDiv.innerHTML = jobHTML;
|
||||||
console.log(`[updateJobs] HTML created for job ${jobId}`);
|
console.log(`[updateJobs] HTML created for job ${jobId}`);
|
||||||
|
|
||||||
// Insert job before the script tag
|
// Insert job before the script tag
|
||||||
|
|||||||
Reference in new issue
Block a user