Update frontend to add tab organisation

This commit is contained in:
pjmalandrino 2025-05-22 14:25:59 +02:00
parent 23a8ae5d4e
commit 3f2d2ec856
3 changed files with 476 additions and 546 deletions

View file

@ -3,136 +3,140 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DocTags Analyzer and Visualizer</title> <title>DocTags Tools</title>
<link rel="stylesheet" href="static/styles.css"> <link rel="stylesheet" href="static/styles.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Fira+Code&display=swap" rel="stylesheet">
</head> </head>
<body> <body>
<div id="app-container"> <h1>DocTags Analyzer and Visualizer</h1>
<h1>DocTags Analyzer and Visualizer</h1>
<div class="card"> <!-- Settings Panel -->
<h3>Document Settings</h3> <div class="settings-panel">
<div class="settings-row">
<div class="form-group"> <div class="form-group">
<label for="pdf_file">Select PDF Document:</label> <label for="pdf_file">PDF File:</label>
<select id="pdf_file" name="pdf_file"></select> <select id="pdf_file" name="pdf_file"></select>
<div id="pdf-load-status" class="status mt-1"></div> <div id="pdf-load-status"></div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="page_num">Page Number:</label> <label for="page_num">Page Number:</label>
<input type="number" id="page_num" name="page_num" value="1" min="1"> <input type="number" id="page_num" name="page_num" value="1" min="1">
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="checkbox-container"> <label for="adjust">
<input type="checkbox" id="adjust" name="adjust" checked> <input type="checkbox" id="adjust" name="adjust" checked>
<span class="checkmark"></span>
Auto-adjust coordinates Auto-adjust coordinates
</label> </label>
</div> </div>
</div> </div>
</div>
<div class="pipeline-container"> <!-- Progress Indicator -->
<div class="step-card"> <div class="progress-indicator">
<h3> <div class="step-indicator" id="step-1">1</div>
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <div class="step-connector" id="connector-1"></div>
<rect x="2" y="2" width="20" height="8" rx="2" ry="2"></rect> <div class="step-indicator" id="step-2">2</div>
<rect x="2" y="14" width="20" height="8" rx="2" ry="2"></rect> <div class="step-connector" id="connector-2"></div>
<line x1="6" y1="6" x2="6" y2="6"></line> <div class="step-indicator" id="step-3">3</div>
<line x1="6" y1="18" x2="6" y2="18"></line> </div>
</svg>
Step 1: Analyze PDF
</h3>
<p>Extract DocTags structure from the selected PDF page</p>
<button id="analyzer-btn" onclick="runScript('analyzer')">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<path d="M12 18v-6"></path>
<path d="M8 18v-1"></path>
<path d="M16 18v-3"></path>
</svg>
Run Analyzer
</button>
<div id="analyzer-status" class="status mt-2"></div>
</div>
<div class="step-card"> <!-- Tabs Container -->
<h3> <div class="tabs-container">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <!-- Tab Buttons -->
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect> <div class="tab-buttons">
<circle cx="8.5" cy="8.5" r="1.5"></circle> <button class="tab-button active" onclick="switchTab('analyzer')">
<polyline points="21 15 16 10 5 21"></polyline> 📄 Step 1: Analyze PDF
</svg>
Step 2: Generate Visualization
</h3>
<p>Create visual representation of the extracted DocTags</p>
<button id="visualizer-btn" onclick="runScript('visualizer')">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="3" width="18" height="18" rx="2"></rect>
<path d="M3 9h18"></path>
<path d="M9 21V9"></path>
</svg>
Run Visualizer
</button>
<div id="visualizer-status" class="status mt-2"></div>
</div>
<div class="step-card">
<h3>
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path>
<polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline>
<line x1="12" y1="22.08" x2="12" y2="12"></line>
</svg>
Step 3: Extract Pictures
</h3>
<p>Extract images from the document based on DocTags</p>
<button id="extractor-btn" onclick="runScript('extractor')">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 22h16a2 2 0 0 0 2-2V9a1 1 0 0 0-1-1h-6.34a1 1 0 0 1-.7-.29l-3.32-3.3a1 1 0 0 0-.7-.29H4a2 2 0 0 0-2 2v14.93a2 2 0 0 0 2 2z"></path>
<polyline points="8 17 12 13 16 17"></polyline>
<line x1="12" y1="13" x2="12" y2="22"></line>
</svg>
Run Picture Extractor
</button>
<div id="extractor-status" class="status mt-2"></div>
</div>
</div>
<div id="output" class="hidden"></div>
<div id="image-container" class="hidden">
<h2>Visualization Result</h2>
<img id="result-image" src="" alt="Visualization">
</div>
<div id="environment-check" class="hidden">
<h3>Environment Status</h3>
<div id="env-details"></div>
</div>
<div class="debug-section">
<button onclick="checkEnvironment()">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path>
<polyline points="15 3 21 3 21 9"></polyline>
<line x1="10" y1="14" x2="21" y2="3"></line>
</svg>
Check Environment
</button> </button>
<button onclick="manuallyRunScript()"> <button class="tab-button" onclick="switchTab('visualizer')">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> 🎨 Step 2: Visualize
<polyline points="16 18 22 12 16 6"></polyline> </button>
<polyline points="8 6 2 12 8 18"></polyline> <button class="tab-button" onclick="switchTab('extractor')">
</svg> 🖼️ Step 3: Extract Pictures
Run Manual Command
</button> </button>
</div> </div>
<!-- Tab Contents -->
<div id="analyzer-tab" class="tab-content active">
<h3>📄 Analyze PDF</h3>
<p>Extract DocTags structure from the PDF page using AI-powered document analysis.</p>
<button id="analyzer-btn" onclick="runScript('analyzer')">
🚀 Run Analysis
</button>
<div id="analyzer-status" class="status hidden"></div>
<div class="tab-description">
<strong>What this does:</strong>
<ul>
<li>Converts the PDF page to an image</li>
<li>Uses AI to identify document structure (headers, text, images, tables)</li>
<li>Generates DocTags with precise coordinate information</li>
<li>Saves the results to the <code>results/</code> folder</li>
</ul>
</div>
</div>
<div id="visualizer-tab" class="tab-content">
<h3>🎨 Visualize DocTags</h3>
<p>Create a visual representation of the extracted DocTags with bounding boxes around detected elements.</p>
<button id="visualizer-btn" onclick="runScript('visualizer')" disabled>
🎨 Generate Visualization
</button>
<div id="visualizer-status" class="status hidden"></div>
<div id="image-container" class="hidden">
<h4>Visualization Result</h4>
<img id="result-image" src="" alt="Visualization">
</div>
<div class="tab-description">
<strong>What this does:</strong>
<ul>
<li>Reads the DocTags file from Step 1</li>
<li>Overlays colored rectangles on the original PDF page</li>
<li>Each element type gets a different color (headers, text, images, etc.)</li>
<li>Saves the visualization as a PNG image</li>
</ul>
</div>
</div>
<div id="extractor-tab" class="tab-content">
<h3>🖼️ Extract Pictures</h3>
<p>Extract individual images from the document based on the detected picture regions.</p>
<button id="extractor-btn" onclick="runScript('extractor')" disabled>
🖼️ Extract Images
</button>
<div id="extractor-status" class="status hidden"></div>
<div class="tab-description">
<strong>What this does:</strong>
<ul>
<li>Identifies picture regions from the DocTags</li>
<li>Crops and extracts individual images</li>
<li>Saves each image as a separate PNG file</li>
<li>Creates an HTML index of all extracted images</li>
</ul>
</div>
</div>
</div>
<!-- Output Section -->
<div id="output" class="output hidden"></div>
<!-- Environment Check -->
<div id="environment-check" class="hidden">
<h3>Environment Check</h3>
<div id="env-details"></div>
</div>
<!-- Debug Section -->
<div class="debug-section">
<button onclick="checkEnvironment()">🔍 Environment Check</button>
<button onclick="manuallyRunScript()">⚙️ Manual Command</button>
</div> </div>
<script src="static/app.js"></script> <script src="static/app.js"></script>

View file

@ -2,47 +2,47 @@
const activeTasks = {}; const activeTasks = {};
let pollingInterval = null; let pollingInterval = null;
// Helper functions for UI // Tab switching functionality
const UI = { function switchTab(tabName) {
showLoader: (elementId) => { // Hide all tab contents
const el = document.getElementById(elementId); const tabContents = document.querySelectorAll('.tab-content');
el.innerHTML = '<div class="loader"></div><span class="working">Processing...</span>'; tabContents.forEach(content => content.classList.remove('active'));
},
showSuccess: (elementId, message = 'Completed') => { // Remove active class from all tab buttons
const el = document.getElementById(elementId); const tabButtons = document.querySelectorAll('.tab-button');
el.innerHTML = `<span class="success">✓ ${message}</span>`; tabButtons.forEach(button => button.classList.remove('active'));
},
showError: (elementId, message = 'Failed') => { // Show selected tab content
const el = document.getElementById(elementId); document.getElementById(tabName + '-tab').classList.add('active');
el.innerHTML = `<span class="error">✗ ${message}</span>`;
}, // Add active class to selected tab button
showOutput: (content) => { event.target.classList.add('active');
const outputDiv = document.getElementById('output'); }
outputDiv.textContent = content;
outputDiv.classList.remove('hidden'); // Update progress indicator
// Scroll to show output function updateProgress(completedSteps) {
outputDiv.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); for (let i = 1; i <= 3; i++) {
}, const stepIndicator = document.getElementById(`step-${i}`);
showImage: (src) => { const connector = document.getElementById(`connector-${i}`);
const img = document.getElementById('result-image');
const container = document.getElementById('image-container'); if (i <= completedSteps) {
img.src = src; stepIndicator.classList.add('completed');
container.classList.remove('hidden'); stepIndicator.classList.remove('active');
// Scroll to show image if (connector) connector.classList.add('completed');
container.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } else if (i === completedSteps + 1) {
}, stepIndicator.classList.add('active');
enableButton: (buttonId) => { stepIndicator.classList.remove('completed');
document.getElementById(buttonId).disabled = false; } else {
}, stepIndicator.classList.remove('completed', 'active');
disableButton: (buttonId) => { if (connector) connector.classList.remove('completed');
document.getElementById(buttonId).disabled = true; }
} }
}; }
// Load PDF files on page load // Load PDF files on page load
window.addEventListener('DOMContentLoaded', function() { window.addEventListener('DOMContentLoaded', function() {
const pdfStatus = document.getElementById('pdf-load-status'); const pdfStatus = document.getElementById('pdf-load-status');
pdfStatus.innerHTML = '<div class="loader"></div><span class="working">Loading PDF files...</span>'; pdfStatus.innerHTML = '<div class="loader"></div> Loading PDF files...';
fetch('/pdf-files') fetch('/pdf-files')
.then(response => { .then(response => {
@ -54,7 +54,7 @@ window.addEventListener('DOMContentLoaded', function() {
.then(data => { .then(data => {
const select = document.getElementById('pdf_file'); const select = document.getElementById('pdf_file');
if (data.length === 0) { if (data.length === 0) {
UI.showError('pdf-load-status', 'No PDF files found in the current directory'); pdfStatus.innerHTML = '<span class="error">No PDF files found in the current directory</span>';
return; return;
} }
@ -64,11 +64,11 @@ window.addEventListener('DOMContentLoaded', function() {
option.textContent = file; option.textContent = file;
select.appendChild(option); select.appendChild(option);
}); });
UI.showSuccess('pdf-load-status', `Loaded ${data.length} PDF files`); pdfStatus.innerHTML = '<span class="success">Loaded ' + data.length + ' PDF files</span>';
}) })
.catch(error => { .catch(error => {
console.error('Error loading PDFs:', error); console.error('Error loading PDFs:', error);
UI.showError('pdf-load-status', `Error: ${error.message}`); pdfStatus.innerHTML = '<span class="error">Error: ' + error.message + '</span>';
}); });
// Run an environment check on startup // Run an environment check on startup
@ -81,59 +81,55 @@ function checkEnvironment() {
const envDetails = document.getElementById('env-details'); const envDetails = document.getElementById('env-details');
envDiv.classList.remove('hidden'); envDiv.classList.remove('hidden');
envDetails.innerHTML = '<div class="loader"></div><span class="working">Checking environment...</span>'; envDetails.innerHTML = '<div class="loader"></div> Checking environment...';
fetch('/check-environment') fetch('/check-environment')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
let html = '<div class="mt-2">'; let html = '<ul>';
// Current working directory // Current working directory
html += `<p><strong>Working directory:</strong> <code>${data.cwd}</code></p>`; html += '<li>Working directory: <code>' + data.cwd + '</code></li>';
// Python version // Python version
html += `<p><strong>Python version:</strong> <code>${data.python_version}</code></p>`; html += '<li>Python version: <code>' + data.python_version + '</code></li>';
// Required scripts check // Required scripts check
if (data.missing_scripts.length === 0) { if (data.missing_scripts.length === 0) {
html += '<p class="env-success">All required scripts found</p>'; html += '<li class="env-success">✓ All required scripts found</li>';
} else { } else {
html += `<p class="env-error">Missing scripts: <code>${data.missing_scripts.join(', ')}</code></p>`; html += '<li class="env-error">✗ Missing scripts: <code>' + data.missing_scripts.join(', ') + '</code></li>';
} }
// PDF files check // PDF files check
if (data.pdf_files.length > 0) { if (data.pdf_files.length > 0) {
html += `<p class="env-success">Found ${data.pdf_files.length} PDF files</p>`; html += '<li class="env-success">✓ Found ' + data.pdf_files.length + ' PDF files: <code>' + data.pdf_files.join(', ') + '</code></li>';
html += '<details class="mt-1"><summary>PDF Files</summary><ul>';
data.pdf_files.forEach(file => {
html += `<li><code>${file}</code></li>`;
});
html += '</ul></details>';
} else { } else {
html += '<p class="env-error">No PDF files found in the working directory</p>'; html += '<li class="env-error">✗ No PDF files found in the working directory</li>';
} }
// Results directory check // Results directory check
if (data.results_dir_exists) { if (data.results_dir_exists) {
html += '<p class="env-success">Results directory exists</p>'; html += '<li class="env-success">✓ Results directory exists</li>';
if (data.results_dir_writable) { if (data.results_dir_writable) {
html += '<p class="env-success">Results directory is writable</p>'; html += '<li class="env-success">✓ Results directory is writable</li>';
} else { } else {
html += '<p class="env-error">Results directory is not writable</p>'; html += '<li class="env-error">✗ Results directory is not writable</li>';
} }
} else { } else {
html += '<p class="env-error">Results directory does not exist</p>'; html += '<li class="env-error">✗ Results directory does not exist</li>';
} }
html += '</div>'; html += '</ul>';
// List of all files for debugging (collapsible) // List of all files for debugging
html += `<details class="mt-2"><summary>All files in directory (${data.files.length} files)</summary><pre>${data.files.join('\n')}</pre></details>`; html += '<details><summary>All files in directory (' + data.files.length + ' files)</summary><pre>' +
data.files.join('\n') + '</pre></details>';
envDetails.innerHTML = html; envDetails.innerHTML = html;
}) })
.catch(error => { .catch(error => {
envDetails.innerHTML = `<div class="env-error mt-2">Error checking environment: ${error.message}</div>`; envDetails.innerHTML = '<div class="env-error">Error checking environment: ' + error.message + '</div>';
}); });
} }
@ -142,7 +138,9 @@ function manuallyRunScript() {
const command = prompt("Enter command to run (e.g., 'python analyzer.py --image document.pdf --page 1')"); const command = prompt("Enter command to run (e.g., 'python analyzer.py --image document.pdf --page 1')");
if (!command) return; if (!command) return;
UI.showOutput(`Running command: ${command}\nPlease wait...`); const outputDiv = document.getElementById('output');
outputDiv.textContent = 'Running command: ' + command + '\nPlease wait...';
outputDiv.classList.remove('hidden');
// Create form data // Create form data
const formData = new FormData(); const formData = new FormData();
@ -155,12 +153,13 @@ function manuallyRunScript() {
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
UI.showOutput( outputDiv.textContent = 'Command: ' + command + '\n\n' +
`Command: ${command}\n\n${data.success ? 'Success!\n\n' : 'Failed!\n\n'}${data.output || ''}${data.error ? '\n\nError: ' + data.error : ''}` (data.success ? 'Success!\n\n' : 'Failed!\n\n') +
); (data.output || '') +
(data.error ? '\n\nError: ' + data.error : '');
}) })
.catch(error => { .catch(error => {
UI.showOutput(`Error running command: ${error.message}`); outputDiv.textContent = 'Error running command: ' + error.message;
}); });
} }
@ -200,24 +199,32 @@ function pollTasks() {
if (data.done) { if (data.done) {
if (data.success) { if (data.success) {
// Task completed successfully // Task completed successfully
UI.showSuccess(`${taskInfo.type}-status`, 'Completed'); statusElement.innerHTML = '<span class="success">✓ Completed successfully!</span>';
statusElement.classList.remove('hidden');
// Enable button // Enable button
UI.enableButton(`${taskInfo.type}-btn`); document.getElementById(`${taskInfo.type}-btn`).disabled = false;
// Display output // Display output
UI.showOutput(data.output); const outputDiv = document.getElementById('output');
outputDiv.textContent = data.output;
outputDiv.classList.remove('hidden');
// Show image if available for visualizer // Show image if available for visualizer
if (taskInfo.type === 'visualizer' && data.image_file) { if (taskInfo.type === 'visualizer' && data.image_file) {
UI.showImage(`/${data.image_file}?t=${new Date().getTime()}`); document.getElementById('result-image').src = '/' + data.image_file + '?t=' + new Date().getTime();
document.getElementById('image-container').classList.remove('hidden');
} }
// Enable next step button if applicable // Enable next step button and update progress
if (taskInfo.type === 'analyzer') { if (taskInfo.type === 'analyzer') {
UI.enableButton('visualizer-btn'); document.getElementById('visualizer-btn').disabled = false;
updateProgress(1);
} else if (taskInfo.type === 'visualizer') { } else if (taskInfo.type === 'visualizer') {
UI.enableButton('extractor-btn'); document.getElementById('extractor-btn').disabled = false;
updateProgress(2);
} else if (taskInfo.type === 'extractor') {
updateProgress(3);
} }
// Remove from active tasks // Remove from active tasks
@ -225,11 +232,14 @@ function pollTasks() {
checkAndStopPolling(); checkAndStopPolling();
} else { } else {
// Task failed // Task failed
UI.showError(`${taskInfo.type}-status`, data.error || 'Unknown error'); statusElement.innerHTML = '<span class="error">✗ Failed: ' + (data.error || 'Unknown error') + '</span>';
UI.enableButton(`${taskInfo.type}-btn`); statusElement.classList.remove('hidden');
document.getElementById(`${taskInfo.type}-btn`).disabled = false;
// Display error output // Display error output
UI.showOutput(`Error: ${data.error || 'Unknown error'}`); const outputDiv = document.getElementById('output');
outputDiv.textContent = 'Error: ' + (data.error || 'Unknown error');
outputDiv.classList.remove('hidden');
// Remove from active tasks // Remove from active tasks
delete activeTasks[taskId]; delete activeTasks[taskId];
@ -237,17 +247,12 @@ function pollTasks() {
} }
} else { } else {
// Still running // Still running
statusElement.innerHTML = '<div class="loader"></div><span class="working">Processing...</span>'; statusElement.innerHTML = '<div class="loader"></div><span class="working">Running...</span>';
statusElement.classList.remove('hidden');
} }
}) })
.catch(error => { .catch(error => {
console.error('Error checking task status:', error); console.error('Error checking task status:', error);
UI.showError(`${taskInfo.type}-status`, 'Failed to check status');
UI.enableButton(`${taskInfo.type}-btn`);
// Remove from active tasks to prevent endless error messages
delete activeTasks[taskId];
checkAndStopPolling();
}); });
} }
} }
@ -263,7 +268,8 @@ function runScript(script) {
} }
// Disable button // Disable button
UI.disableButton(`${script}-btn`); const button = document.getElementById(`${script}-btn`);
button.disabled = true;
// Create form data // Create form data
const formData = new FormData(); const formData = new FormData();
@ -272,7 +278,9 @@ function runScript(script) {
formData.append('adjust', adjust); formData.append('adjust', adjust);
// Show running status // Show running status
UI.showLoader(`${script}-status`); const statusElement = document.getElementById(`${script}-status`);
statusElement.innerHTML = '<div class="loader"></div><span class="working">Starting...</span>';
statusElement.classList.remove('hidden');
// Clear previous output // Clear previous output
document.getElementById('output').classList.add('hidden'); document.getElementById('output').classList.add('hidden');
@ -288,13 +296,14 @@ function runScript(script) {
case 'analyzer': case 'analyzer':
endpoint = '/run-analyzer'; endpoint = '/run-analyzer';
// Disable next step buttons // Disable next step buttons
UI.disableButton('visualizer-btn'); document.getElementById('visualizer-btn').disabled = true;
UI.disableButton('extractor-btn'); document.getElementById('extractor-btn').disabled = true;
updateProgress(0);
break; break;
case 'visualizer': case 'visualizer':
endpoint = '/run-visualizer'; endpoint = '/run-visualizer';
// Disable next step button // Disable next step button
UI.disableButton('extractor-btn'); document.getElementById('extractor-btn').disabled = true;
break; break;
case 'extractor': case 'extractor':
endpoint = '/run-extractor'; endpoint = '/run-extractor';
@ -324,25 +333,31 @@ function runScript(script) {
startPolling(); startPolling();
// Update status // Update status
UI.showLoader(`${script}-status`); statusElement.innerHTML = '<div class="loader"></div><span class="working">Running...</span>';
// Show initial output // Show initial output
UI.showOutput(data.message || 'Task started, please wait...'); const outputDiv = document.getElementById('output');
outputDiv.textContent = data.message || 'Task started, please wait...';
outputDiv.classList.remove('hidden');
} else { } else {
// Failed to start task // Failed to start task
UI.showError(`${script}-status`, 'Failed to start task'); statusElement.innerHTML = '<span class="error">✗ Failed to start task</span>';
UI.enableButton(`${script}-btn`); button.disabled = false;
// Show error // Show error
UI.showOutput(`Error: ${data.error || 'Failed to start task'}`); const outputDiv = document.getElementById('output');
outputDiv.textContent = 'Error: ' + (data.error || 'Failed to start task');
outputDiv.classList.remove('hidden');
} }
}) })
.catch(error => { .catch(error => {
console.error('Error starting task:', error); console.error('Error starting task:', error);
UI.showError(`${script}-status`, error.message); statusElement.innerHTML = '<span class="error">✗ ' + error.message + '</span>';
UI.enableButton(`${script}-btn`); button.disabled = false;
// Show error // Show error
UI.showOutput(`Error: ${error.message}`); const outputDiv = document.getElementById('output');
outputDiv.textContent = 'Error: ' + error.message;
outputDiv.classList.remove('hidden');
}); });
} }

View file

@ -1,431 +1,342 @@
/* Modern stylesheet for DocTags Analyzer and Visualizer */
:root {
/* Color palette */
--bg-color: #f8f1ee;
--primary-color: #195162;
--secondary-color: #618794;
--light-color: #e6eaf1;
--mint: #b9e9da;
--amber: #ffdb96;
--pale-rose: #ffc9c9;
--white: #ffffff;
--error: #e74c3c;
--success: #2ecc71;
--warning: #f39c12;
--shadow: rgba(25, 81, 98, 0.1);
/* Typography */
--font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
--font-mono: 'Fira Code', 'SF Mono', Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
}
/* Base styles */
body { body {
font-family: var(--font-sans); font-family: Arial, sans-serif;
background-color: var(--bg-color); max-width: 900px;
color: var(--primary-color);
line-height: 1.6;
margin: 0;
padding: 0;
}
#app-container {
max-width: 1200px;
margin: 0 auto; margin: 0 auto;
padding: 2rem; padding: 20px;
} background-color: #f5f5f5;
h1, h2, h3, h4, h5, h6 {
color: var(--primary-color);
margin-top: 0;
font-weight: 600;
} }
h1 { h1 {
font-size: 2.25rem; color: #333;
margin-bottom: 1.5rem; text-align: center;
position: relative; margin-bottom: 30px;
display: inline-block;
} }
h1::after { /* Common form styles */
content: '';
position: absolute;
width: 50%;
height: 4px;
background-color: var(--secondary-color);
bottom: -8px;
left: 0;
border-radius: 2px;
}
h3 {
font-size: 1.35rem;
color: var(--secondary-color);
margin-bottom: 1rem;
}
/* Card Component */
.card {
background-color: var(--white);
border-radius: 12px;
box-shadow: 0 8px 16px var(--shadow);
padding: 1.5rem;
margin-bottom: 1.5rem;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover {
transform: translateY(-4px);
box-shadow: 0 10px 20px var(--shadow);
}
/* Form Elements */
.form-group { .form-group {
margin-bottom: 1.5rem; margin-bottom: 15px;
} }
label { label {
display: block; display: block;
margin-bottom: 0.5rem; margin-bottom: 5px;
font-weight: 500; font-weight: bold;
color: var(--primary-color);
} }
select, input[type="number"], input[type="text"] { select, input {
padding: 8px;
width: 100%; width: 100%;
padding: 12px 16px; max-width: 300px;
border: 2px solid var(--light-color); border: 1px solid #ddd;
border-radius: 8px;
background-color: var(--white);
font-size: 1rem;
color: var(--primary-color);
transition: border-color 0.2s ease, box-shadow 0.2s ease;
-webkit-appearance: none;
appearance: none;
}
select {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23618794' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 16px center;
padding-right: 48px;
}
select:focus, input:focus {
outline: none;
border-color: var(--secondary-color);
box-shadow: 0 0 0 3px rgba(97, 135, 148, 0.25);
}
.checkbox-container {
display: flex;
align-items: center;
position: relative;
cursor: pointer;
user-select: none;
}
.checkbox-container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkmark {
height: 24px;
width: 24px;
background-color: var(--white);
border: 2px solid var(--light-color);
border-radius: 4px; border-radius: 4px;
margin-right: 10px;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
} }
.checkbox-container:hover input ~ .checkmark {
background-color: var(--light-color);
}
.checkbox-container input:checked ~ .checkmark {
background-color: var(--secondary-color);
border-color: var(--secondary-color);
}
.checkmark:after {
content: "";
display: none;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
.checkbox-container input:checked ~ .checkmark:after {
display: block;
}
/* Buttons */
button { button {
background-color: var(--secondary-color); padding: 12px 20px;
background-color: #4CAF50;
color: white; color: white;
border: none; border: none;
border-radius: 8px; border-radius: 4px;
padding: 12px 24px;
font-size: 1rem;
font-weight: 500;
cursor: pointer; cursor: pointer;
transition: background-color 0.2s ease, transform 0.1s ease; margin-right: 10px;
display: inline-flex; margin-bottom: 10px;
align-items: center; font-size: 14px;
justify-content: center; transition: background-color 0.3s;
} }
button:hover:not(:disabled) { button:hover {
background-color: var(--primary-color); background-color: #45a049;
transform: translateY(-2px);
}
button:active:not(:disabled) {
transform: translateY(0);
} }
button:disabled { button:disabled {
background-color: var(--light-color); background-color: #cccccc;
color: var(--secondary-color);
cursor: not-allowed; cursor: not-allowed;
opacity: 0.7;
} }
button svg { .output {
margin-right: 8px; margin-top: 20px;
padding: 15px;
border: 1px solid #ddd;
border-radius: 4px;
background-color: #fff;
white-space: pre-wrap;
max-height: 300px;
overflow-y: auto;
font-family: monospace;
font-size: 12px;
} }
/* Status indicators */ .hidden {
.status { display: none;
margin-top: 1rem; }
font-weight: 500;
img {
max-width: 100%;
margin-top: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
/* Tab styles */
.tabs-container {
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
overflow: hidden;
}
.tab-buttons {
display: flex; display: flex;
align-items: center; background-color: #f8f9fa;
border-bottom: 1px solid #ddd;
}
.tab-button {
flex: 1;
padding: 15px 20px;
background-color: transparent;
border: none;
cursor: pointer;
font-size: 16px;
font-weight: 500;
color: #666;
transition: all 0.3s;
border-bottom: 3px solid transparent;
}
.tab-button:hover {
background-color: #e9ecef;
color: #333;
}
.tab-button.active {
background-color: white;
color: #4CAF50;
border-bottom-color: #4CAF50;
}
.tab-content {
display: none;
padding: 30px;
background-color: white;
}
.tab-content.active {
display: block;
}
.tab-content h3 {
color: #333;
margin-top: 0;
margin-bottom: 10px;
}
.tab-content p {
color: #666;
margin-bottom: 20px;
}
/* Tab description styles */
.tab-description {
margin-top: 20px;
color: #666;
font-size: 14px;
}
.tab-description ul {
margin-top: 10px;
}
.tab-description li {
margin-bottom: 5px;
}
.tab-description code {
background-color: #f1f3f4;
padding: 2px 4px;
border-radius: 3px;
font-size: 13px;
}
/* Status styles */
.status {
font-weight: bold;
margin-top: 15px;
padding: 10px;
border-radius: 4px;
background-color: #f8f9fa;
} }
.error { .error {
color: var(--error); color: #d32f2f;
background-color: #ffebee;
} }
.success { .success {
color: var(--success); color: #43a047;
background-color: #e8f5e8;
} }
.working { .working {
color: var(--secondary-color); color: #1976d2;
background-color: #e3f2fd;
} }
.loader { .loader {
display: inline-block; border: 3px solid #f3f3f3;
width: 20px; border-top: 3px solid #3498db;
height: 20px;
margin-right: 10px;
border: 3px solid var(--light-color);
border-radius: 50%; border-radius: 50%;
border-top-color: var(--secondary-color); width: 16px;
animation: spin 1s ease-in-out infinite; height: 16px;
animation: spin 1s linear infinite;
display: inline-block;
vertical-align: middle;
margin-right: 8px;
} }
@keyframes spin { @keyframes spin {
to { transform: rotate(360deg); } 0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
} }
/* Pipeline Container */ /* Settings panel */
.pipeline-container { .settings-panel {
display: grid; background-color: #fff;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); padding: 20px;
gap: 1.5rem; border-radius: 8px;
margin: 2rem 0; margin-bottom: 20px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
} }
/* Step Cards */ .settings-row {
.step-card {
background-color: var(--white);
border-radius: 12px;
border-left: 5px solid var(--mint);
box-shadow: 0 4px 12px var(--shadow);
padding: 1.5rem;
transition: transform 0.2s ease, box-shadow 0.2s ease;
display: flex; display: flex;
flex-direction: column; gap: 20px;
align-items: end;
flex-wrap: wrap;
} }
.step-card:nth-child(2) { .settings-row .form-group {
border-left-color: var(--amber); flex: 1;
min-width: 200px;
} }
.step-card:nth-child(3) { /* Environment check styles */
border-left-color: var(--pale-rose);
}
.step-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 16px var(--shadow);
}
.step-card h3 {
margin-top: 0;
display: flex;
align-items: center;
}
.step-card h3 svg {
margin-right: 10px;
}
.step-card p {
color: var(--secondary-color);
margin-bottom: 1.5rem;
flex-grow: 1;
}
/* Environment Check Panel */
#environment-check { #environment-check {
background-color: var(--white); margin-top: 20px;
border-radius: 12px; padding: 15px;
box-shadow: 0 4px 12px var(--shadow); background-color: #fff3cd;
padding: 1.5rem; border: 1px solid #ffeeba;
margin-top: 2rem; border-radius: 4px;
} }
.env-success { .env-success {
color: var(--success); color: #155724;
display: flex;
align-items: center;
} }
.env-error { .env-error {
color: var(--error); color: #721c24;
display: flex;
align-items: center;
} }
.env-success::before, .env-error::before {
content: '';
display: inline-block;
width: 16px;
height: 16px;
margin-right: 8px;
border-radius: 50%;
}
.env-success::before {
background-color: var(--success);
}
.env-error::before {
background-color: var(--error);
}
/* Output Container */
#output {
background-color: var(--white);
border-radius: 12px;
padding: 1.5rem;
white-space: pre-wrap;
font-family: var(--font-mono);
font-size: 0.9rem;
line-height: 1.6;
color: var(--primary-color);
overflow-x: auto;
box-shadow: 0 4px 12px var(--shadow);
max-height: 300px;
overflow-y: auto;
}
/* Image Container */
#image-container {
background-color: var(--white);
border-radius: 12px;
padding: 1.5rem;
box-shadow: 0 4px 12px var(--shadow);
margin-top: 2rem;
}
#image-container h2 {
margin-top: 0;
margin-bottom: 1rem;
display: flex;
align-items: center;
}
#image-container h2::before {
content: '';
display: inline-block;
width: 24px;
height: 24px;
margin-right: 10px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23618794' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2' ry='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpolyline points='21 15 16 10 5 21'/%3E%3C/svg%3E");
background-repeat: no-repeat;
}
#result-image {
max-width: 100%;
border-radius: 8px;
box-shadow: 0 2px 8px var(--shadow);
}
/* Debug Section */
.debug-section { .debug-section {
margin-top: 3rem; margin-top: 30px;
padding-top: 1.5rem; border-top: 1px solid #ddd;
border-top: 1px dashed var(--light-color); padding-top: 20px;
text-align: center;
}
.debug-section button {
background-color: #6c757d;
margin: 0 5px;
}
.debug-section button:hover {
background-color: #5a6268;
}
/* Image container styles */
#image-container {
margin-top: 20px;
text-align: center;
}
#image-container h4 {
color: #333;
margin-bottom: 15px;
}
/* Progress indicator */
.progress-indicator {
display: flex; display: flex;
gap: 1rem; justify-content: center;
align-items: center;
margin: 20px 0;
} }
/* Utility Classes */ .step-indicator {
.hidden { width: 30px;
display: none !important; height: 30px;
border-radius: 50%;
background-color: #ddd;
color: white;
display: flex;
align-items: center;
justify-content: center;
margin: 0 10px;
font-weight: bold;
transition: background-color 0.3s;
} }
.mt-1 { .step-indicator.completed {
margin-top: 0.5rem; background-color: #4CAF50;
} }
.mt-2 { .step-indicator.active {
margin-top: 1rem; background-color: #2196F3;
} }
.mt-4 { .step-connector {
margin-top: 2rem; width: 50px;
height: 2px;
background-color: #ddd;
transition: background-color 0.3s;
} }
.mb-1 { .step-connector.completed {
margin-bottom: 0.5rem; background-color: #4CAF50;
} }
.mb-2 { /* Responsive design */
margin-bottom: 1rem;
}
.mb-4 {
margin-bottom: 2rem;
}
/* Responsive adjustments */
@media (max-width: 768px) { @media (max-width: 768px) {
#app-container { body {
padding: 1rem; padding: 10px;
} }
.pipeline-container { .tab-buttons {
grid-template-columns: 1fr; flex-direction: column;
} }
button { .tab-button {
width: 100%; text-align: center;
border-bottom: 1px solid #ddd;
border-right: none;
}
.tab-button.active {
border-bottom: 1px solid #4CAF50;
border-left: 3px solid #4CAF50;
}
.settings-row {
flex-direction: column;
gap: 10px;
}
.progress-indicator {
flex-wrap: wrap;
gap: 10px;
}
.step-connector {
display: none;
} }
} }