<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport"…
- User
<div class="form-group"> <label for="senderId">Sender ID</label> <input type="text" id="senderId" placeholder="Enter Sender ID"> </div> <div class="form-group"> <label for="fileInput">Upload PDF/Image</label> <input type="file" id="fileInput" accept=".pdf, .jpg, .jpeg, .png"> </div> <button id="submitBtn">Submit</button> <div id="loader"></div> <!-- Line items and Image --> <div id="line-items-and-image" style="display:none;"> <div id="result-container" class="card-container"></div> <div id="image-display"></div> </div> <button id="generateJsonBtn" style="display:none;">Generate JSON</button> <div id="json-output"></div> <div id="additionalButtons" style="display:none;"> <button id="edit_fields">Edit Fields</button> <button id="createOrderCanonicalBtn">Create Order Canonical</button> </div> <div id="submitOrderContainer" style="display:none;"> <button id="submit_order_canonicalbtn">Submit Order Canonical</button> </div> <!-- XML and Image Display --> <div id="xml-and-image-container"> <div id="xml-container"></div> <div id="image-container"></div> </div>}); document.getElementById('edit_fields').addEventListener('click', function () { document.querySelectorAll('.editable-field').forEach(field => { field.readOnly = false; }); document.querySelectorAll('.line-item-value').forEach(field => { field.readOnly = false; }); alert("Fields are now editable."); }); document.getElementById('createOrderCanonicalBtn').addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/create_order_canonical', { method: 'POST', body: formData }) .then(response => response.text()) .then(data => { loader.style.display = 'none'; const xmlContainer = document.getElementById('xml-container'); if (!xmlContainer) { console.error('xml-container not found'); return; } xmlContainer.innerHTML = `<pre>${escapeHTML(data)}</pre>`; const imageContainer = document.getElementById('image-container'); const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageContainer.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('xml-and-image-container').style.display = 'flex'; }) .catch(error => { loader.style.display = 'none'; console.error('Error creating canonical order:', error); }); }); document.getElementById("submit_order_canonicalbtn").addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/submit_order_canonical', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { loader.style.display = 'none'; alert(data.message); }) .catch(error => { loader.style.display = 'none'; console.error('Error submitting canonical order:', error); }); checkIfEdited(original_json, generatedJsonData); }); function checkIfEdited(original, generated) { const keys = Object.keys(original); edited = false; keys.forEach(key => { if (key !== "line_items" && original[key] !== generated[key]) { edited = true; } else if (key === "line_items") { edited = JSON.stringify(original.line_items) !== JSON.stringify(generated.line_items); } }); if (edited) { addToTraining(); } } function addToTraining() { const jsonOutput = generatedJsonData; const fileInput = document.getElementById('fileInput').files[0]; const formData_add = new FormData(); formData_add.append('file', fileInput); formData_add.append('purchaseOrderNumber', jsonOutput.purchase_order_number); formData_add.append('json', JSON.stringify(jsonOutput)); fetch(api_url + '/add_to_training', { method: 'POST', body: formData_add }) .then(response => response.json()) .then(data => { alert(data.message); }) .catch(error => { console.error('Error adding to training:', error); }); } function escapeHTML(html) { return html.replace(/</g, '<').replace(/>/g, '>'); }Just for the submit button loader can we add a progress bar with the labels Processing PO, Creating image Encodings, Creating text Encodings, Extracting information
can you make it it look realistic and add some good styling to progress bar to look modern, don't remove the other parts loarder only for the submit button (first one)
- Assistant
Certainly! Below is an example of how you can add a progress bar with realistic loading labels to the submit button, while keeping the existing loader for other actions. The progress bar will have modern styling to enhance the overall user experience.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>File Upload & API Interaction</title> <style> body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f0f2f5; margin: 0; padding: 20px; } .container { max-width: 1200px; margin: 0 auto; background: #ffffff; padding: 30px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); } h2 { text-align: center; color: #333; font-size: 28px; margin-bottom: 20px; } .form-group { margin-bottom: 20px; } label { display: block; font-weight: 500; margin-bottom: 8px; color: #555; } input[type="text"], input[type="file"], button { width: 100%; padding: 14px; border-radius: 8px; border: 1px solid #ccc; box-sizing: border-box; font-size: 16px; transition: all 0.3s ease; } input[type="text"], input[type="file"] { background-color: #f9f9f9; } input[type="text"]:focus, input[type="file"]:focus { border-color: #28a745; outline: none; background-color: #ffffff; } button { background-color: #28a745; color: #ffffff; border: none; cursor: pointer; font-size: 18px; margin-top: 10px; } button:hover { background-color: #218838; } button:active { background-color: #1e7e34; } #loader { display: none; border: 4px solid #f3f3f3; border-radius: 50%; border-top: 4px solid #28a745; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 20px auto; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .progress-container { width: 100%; background: #f3f3f3; border-radius: 8px; overflow: hidden; height: 30px; margin-top: 20px; display: none; /* Initially hidden */ } .progress-bar { height: 100%; width: 0%; background: #28a745; transition: width 0.4s ease; position: relative; } .progress-bar span { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: #ffffff; font-weight: bold; } #json-output { margin-top: 20px; padding: 20px; background: #ffffff; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); font-family: monospace; white-space: pre-wrap; color: #333; } #line-items-and-image { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 30px; } .card-container { width: 48%; max-height: 600px; /* Set a fixed height */ overflow-y: auto; background: #f9f9f9; padding: 10px; border: 1px solid #ddd; border-radius: 8px; } .line-item-card { border: 1px solid #ddd; border-radius: 10px; padding: 20px; background-color: #ffffff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); margin-bottom: 20px; } .line-item-card h4 { margin: 0 0 15px; font-size: 18px; color: #333; } .line-item-label { font-size: 14px; font-weight: bold; color: #444; margin-bottom: 5px; } .line-item-value { font-size: 16px; color: #333; padding: 10px; background-color: #f9f9f9; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 10px; width: 100%; box-sizing: border-box; } #image-display { width: 48%; border: 1px solid #ddd; border-radius: 8px; text-align: center; background: #ffffff; overflow: hidden; } #image-display img { max-width: 100%; max-height: 100%; } #additionalButtons { display: flex; justify-content: space-between; margin-top: 20px; } #additionalButtons button { flex: 1; margin-right: 10px; } #additionalButtons button:last-child { margin-right: 0; } #submitOrderContainer { margin-top: 20px; display: flex; justify-content: flex-start; } #submit_order_canonicalbtn { background-color: #dc3545; color: #ffffff; border: none; padding: 14px; border-radius: 8px; cursor: pointer; font-size: 18px; } #submit_order_canonicalbtn:hover { background-color: #c82333; } #submit_order_canonicalbtn:active { background-color: #bd2130; } #xml-and-image-container { display: none; margin-top: 30px; display: flex; justify-content: space-between; } #xml-container, #image-container { max-height: 800px; width: 48%; overflow-x: auto; overflow-y: auto; border: 1px solid #ddd; /* Border around XML and image containers */ padding: 10px; /* Padding around XML and image content */ background: #ffffff; /* White background for XML and image content */ border-radius: 8px; /* Rounded corners */ } #xml-container { max-height: 800px; /* Limit height of XML container */ overflow-x: auto; /* Enable horizontal scrolling */ overflow-y: auto; /* Enable vertical scrolling */ white-space: nowrap; /* Prevent text wrapping */ border: 1px solid #ddd; /* Border around XML container */ padding: 10px; /* Padding around XML content */ background: #ffffff; /* White background for XML content */ border-radius: 8px; /* Rounded corners */ } #xml-container pre { margin: 0; /* Remove margin from preformatted text */ } #image-container img { width: 100%; height: 100%; } </style> </head> <body> <div class="container"> <h2>Upload File and Enter Sender ID</h2> <div class="form-group"> <label for="senderId">Sender ID</label> <input type="text" id="senderId" placeholder="Enter Sender ID"> </div> <div class="form-group"> <label for="fileInput">Upload PDF/Image</label> <input type="file" id="fileInput" accept=".pdf, .jpg, .jpeg, .png"> </div> <button id="submitBtn">Submit</button> <div class="progress-container" id="progressContainer"> <div class="progress-bar" id="progressBar"><span>Initializing...</span></div> </div> <div id="loader"></div> <!-- Line items and Image --> <div id="line-items-and-image" style="display:none;"> <div id="result-container" class="card-container"></div> <div id="image-display"></div> </div> <button id="generateJsonBtn" style="display:none;">Generate JSON</button> <div id="json-output"></div> <div id="additionalButtons" style="display:none;"> <button id="edit_fields">Edit Fields</button> <button id="createOrderCanonicalBtn">Create Order Canonical</button> </div> <div id="submitOrderContainer" style="display:none;"> <button id="submit_order_canonicalbtn">Submit Order Canonical</button> </div> <!-- XML and Image Display --> <div id="xml-and-image-container"> <div id="xml-container"></div> <div id="image-container"></div> </div> </div> <script> let generatedJsonData = {}; const api_url = "https://8c47-35-187-224-10.ngrok-free.app/"; let edited = false; let original_json = {}; document.getElementById('submitBtn').addEventListener('click', function () { const senderId = document.getElementById('senderId').value; const fileInput = document.getElementById('fileInput').files[0]; const resultContainer = document.getElementById('result-container'); resultContainer.innerHTML = ''; document.getElementById('json-output').innerHTML = ''; if (!senderId || !fileInput) { alert('Please enter Sender ID and upload a file.'); return; } const formData = new FormData(); formData.append('senderId', senderId); formData.append('file', fileInput); startProgressBar(); fetch(api_url + '/po_processing', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { stopProgressBar(); original_json = data; displayResults(data); document.getElementById('generateJsonBtn').style.display = 'block'; }) .catch(error => { stopProgressBar(); console.error('Error:', error); }); }); function startProgressBar() { const progressBar = document.getElementById('progressBar'); const progressContainer = document.getElementById('progressContainer'); progressContainer.style.display = 'block'; const steps = [ { label: 'Processing PO', percent: 25 }, { label: 'Creating Image Encodings', percent: 50 }, { label: 'Creating Text Encodings', percent: 75 }, { label: 'Extracting Information', percent: 100 } ]; let index = 0; function updateProgress() { if (index < steps.length) { progressBar.style.width = steps[index].percent + '%'; progressBar.querySelector('span').textContent = steps[index].label; index++; setTimeout(updateProgress, 1000); } } updateProgress(); } function stopProgressBar() { const progressContainer = document.getElementById('progressContainer'); setTimeout(function() { progressContainer.style.display = 'none'; }, 1500); } function displayResults(data) { const resultContainer = document.getElementById('result-container'); const imageDisplay = document.getElementById('image-display'); resultContainer.innerHTML = ''; for (const [key, value] of Object.entries(data)) { if (key !== 'line_items') { const div = document.createElement('div'); div.classList.add('form-group'); const label = document.createElement('label'); label.classList.add('line-item-label'); label.innerText = key; const input = document.createElement('input'); input.type = 'text'; input.value = value; input.classList.add('editable-field'); input.dataset.key = key; input.readOnly = true; div.appendChild(label); div.appendChild(input); resultContainer.appendChild(div); } } if (data.line_items && Array.isArray(data.line_items)) { data.line_items.sort((a, b) => a.line_number - b.line_number); data.line_items.forEach((item, index) => { const card = document.createElement('div'); card.classList.add('line-item-card'); card.innerHTML = `<h4>Line Item ${index + 1}</h4>`; Object.entries(item).forEach(([key, value]) => { const div = document.createElement('div'); div.classList.add('form-group'); const label = document.createElement('label'); label.classList.add('line-item-label'); label.innerText = key; const input = document.createElement('input'); input.type = 'text'; input.value = value; input.classList.add('line-item-value'); input.dataset.lineItemKey = key; input.readOnly = true; div.appendChild(label); div.appendChild(input); card.appendChild(div); }); resultContainer.appendChild(card); }); } const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageDisplay.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('line-items-and-image').style.display = 'flex'; document.getElementById('additionalButtons').style.display = 'flex'; document.getElementById('submitOrderContainer').style.display = 'flex'; } function generateJsonData() { const resultContainer = document.getElementById('result-container'); const finalData = {}; resultContainer.querySelectorAll('.editable-field').forEach(field => { finalData[field.dataset.key] = field.value; }); finalData.line_items = []; resultContainer.querySelectorAll('.line-item-card').forEach(card => { const lineItem = {}; card.querySelectorAll('.line-item-value').forEach(field => { lineItem[field.dataset.lineItemKey] = field.value; }); finalData.line_items.push(lineItem); }); return finalData; } document.getElementById('generateJsonBtn').addEventListener('click', function () { const jsonOutput = document.getElementById('json-output'); generatedJsonData = generateJsonData(); jsonOutput.innerHTML = `<textarea rows="10" style="width: 100%; box-sizing: border-box;">${JSON.stringify(generatedJsonData, null, 2)}</textarea>`; }); document.getElementById('edit_fields').addEventListener('click', function () { document.querySelectorAll('.editable-field').forEach(field => { field.readOnly = false; }); document.querySelectorAll('.line-item-value').forEach(field => { field.readOnly = false; }); alert("Fields are now editable."); }); document.getElementById('createOrderCanonicalBtn').addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/create_order_canonical', { method: 'POST', body: formData }) .then(response => response.text()) .then(data => { loader.style.display = 'none'; const xmlContainer = document.getElementById('xml-container'); if (!xmlContainer) { console.error('xml-container not found'); return; } xmlContainer.innerHTML = `<pre>${escapeHTML(data)}</pre>`; const imageContainer = document.getElementById('image-container'); const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageContainer.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('xml-and-image-container').style.display = 'flex'; }) .catch(error => { loader.style.display = 'none'; console.error('Error creating canonical order:', error); }); }); document.getElementById("submit_order_canonicalbtn").addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/submit_order_canonical', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { loader.style.display = 'none'; alert(data.message); }) .catch(error => { loader.style.display = 'none'; console.error('Error submitting canonical order:', error); }); checkIfEdited(original_json, generatedJsonData); }); function checkIfEdited(original, generated) { const keys = Object.keys(original); edited = false; keys.forEach(key => { if (key !== "line_items" && original[key] !== generated[key]) { edited = true; } else if (key === "line_items") { edited = JSON.stringify(original.line_items) !== JSON.stringify(generated.line_items); } }); if (edited) { addToTraining(); } } function addToTraining() { const jsonOutput = generatedJsonData; const fileInput = document.getElementById('fileInput').files[0]; const formData_add = new FormData(); formData_add.append('file', fileInput); formData_add.append('purchaseOrderNumber', jsonOutput.purchase_order_number); formData_add.append('json', JSON.stringify(jsonOutput)); fetch(api_url + '/add_to_training', { method: 'POST', body: formData_add }) .then(response => response.json()) .then(data => { alert(data.message); }) .catch(error => { console.error('Error adding to training:', error); }); } function escapeHTML(html) { return html.replace(/</g, '<').replace(/>/g, '>'); } </script> </body> </html>This implementation introduces a progress bar that simulates multiple steps in the submission process. It is invoked when the "Submit" button is clicked and updates over time with text labels to simulate the progress of different tasks. The progress is set to increment automatically, and the progress bar is hidden once completed. This visual animation enhances the user's experience by making the loading process more transparent and engaging.
- User
For the progress bar can you also show timer with seconds and mini seconds, and can you finish the progress bar only after getting the response, to look more realistic?
- Assistant
To create a more realistic experience with a progress bar that includes a timer and only completes once the response is received, we'll make the following changes:
- Show a timer with seconds and milliseconds.
- Keep the progress bar updating and only finish it when the response is actually received.
Here's how you can achieve this:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>File Upload & API Interaction</title> <style> body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f0f2f5; margin: 0; padding: 20px; } .container { max-width: 1200px; margin: 0 auto; background: #ffffff; padding: 30px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); } h2 { text-align: center; color: #333; font-size: 28px; margin-bottom: 20px; } .form-group { margin-bottom: 20px; } label { display: block; font-weight: 500; margin-bottom: 8px; color: #555; } input[type="text"], input[type="file"], button { width: 100%; padding: 14px; border-radius: 8px; border: 1px solid #ccc; box-sizing: border-box; font-size: 16px; transition: all 0.3s ease; } input[type="text"], input[type="file"] { background-color: #f9f9f9; } input[type="text"]:focus, input[type="file"]:focus { border-color: #28a745; outline: none; background-color: #ffffff; } button { background-color: #28a745; color: #ffffff; border: none; cursor: pointer; font-size: 18px; margin-top: 10px; } button:hover { background-color: #218838; } button:active { background-color: #1e7e34; } #loader { display: none; border: 4px solid #f3f3f3; border-radius: 50%; border-top: 4px solid #28a745; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 20px auto; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .progress-container { width: 100%; background: #f3f3f3; border-radius: 8px; overflow: hidden; height: 30px; margin-top: 20px; display: none; /* Initially hidden */ position: relative; } .progress-bar { height: 100%; width: 0%; background: #28a745; transition: width 0.1s linear; position: relative; display: flex; align-items: center; justify-content: center; color: #ffffff; font-weight: bold; font-size: 16px; } #json-output { margin-top: 20px; padding: 20px; background: #ffffff; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); font-family: monospace; white-space: pre-wrap; color: #333; } #line-items-and-image { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 30px; } .card-container { width: 48%; max-height: 600px; overflow-y: auto; background: #f9f9f9; padding: 10px; border: 1px solid #ddd; border-radius: 8px; } .line-item-card { border: 1px solid #ddd; border-radius: 10px; padding: 20px; background-color: #ffffff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); margin-bottom: 20px; } .line-item-card h4 { margin: 0 0 15px; font-size: 18px; color: #333; } .line-item-label { font-size: 14px; font-weight: bold; color: #444; margin-bottom: 5px; } .line-item-value { font-size: 16px; color: #333; padding: 10px; background-color: #f9f9f9; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 10px; width: 100%; box-sizing: border-box; } #image-display { width: 48%; border: 1px solid #ddd; border-radius: 8px; text-align: center; background: #ffffff; overflow: hidden; } #image-display img { max-width: 100%; max-height: 100%; } #additionalButtons { display: flex; justify-content: space-between; margin-top: 20px; } #additionalButtons button { flex: 1; margin-right: 10px; } #additionalButtons button:last-child { margin-right: 0; } #submitOrderContainer { margin-top: 20px; display: flex; justify-content: flex-start; } #submit_order_canonicalbtn { background-color: #dc3545; color: #ffffff; border: none; padding: 14px; border-radius: 8px; cursor: pointer; font-size: 18px; } #submit_order_canonicalbtn:hover { background-color: #c82333; } #submit_order_canonicalbtn:active { background-color: #bd2130; } #xml-and-image-container { display: none; margin-top: 30px; display: flex; justify-content: space-between; } #xml-container, #image-container { max-height: 800px; width: 48%; overflow-x: auto; overflow-y: auto; border: 1px solid #ddd; padding: 10px; background: #ffffff; border-radius: 8px; } #xml-container { max-height: 800px; overflow-x: auto; overflow-y: auto; white-space: nowrap; border: 1px solid #ddd; padding: 10px; background: #ffffff; border-radius: 8px; } #xml-container pre { margin: 0; } #image-container img { width: 100%; height: 100%; } </style> </head> <body> <div class="container"> <h2>Upload File and Enter Sender ID</h2> <div class="form-group"> <label for="senderId">Sender ID</label> <input type="text" id="senderId" placeholder="Enter Sender ID"> </div> <div class="form-group"> <label for="fileInput">Upload PDF/Image</label> <input type="file" id="fileInput" accept=".pdf, .jpg, .jpeg, .png"> </div> <button id="submitBtn">Submit</button> <div class="progress-container" id="progressContainer"> <div class="progress-bar" id="progressBar"> <span id="progressLabel">Initializing...</span> </div> </div> <div id="loader"></div> <!-- Line items and Image --> <div id="line-items-and-image" style="display:none;"> <div id="result-container" class="card-container"></div> <div id="image-display"></div> </div> <button id="generateJsonBtn" style="display:none;">Generate JSON</button> <div id="json-output"></div> <div id="additionalButtons" style="display:none;"> <button id="edit_fields">Edit Fields</button> <button id="createOrderCanonicalBtn">Create Order Canonical</button> </div> <div id="submitOrderContainer" style="display:none;"> <button id="submit_order_canonicalbtn">Submit Order Canonical</button> </div> <!-- XML and Image Display --> <div id="xml-and-image-container"> <div id="xml-container"></div> <div id="image-container"></div> </div> </div> <script> let generatedJsonData = {}; const api_url = "https://8c47-35-187-224-10.ngrok-free.app/"; let edited = false; let original_json = {}; let progressInterval, timerStart; document.getElementById('submitBtn').addEventListener('click', function () { const senderId = document.getElementById('senderId').value; const fileInput = document.getElementById('fileInput').files[0]; const resultContainer = document.getElementById('result-container'); resultContainer.innerHTML = ''; document.getElementById('json-output').innerHTML = ''; if (!senderId || !fileInput) { alert('Please enter Sender ID and upload a file.'); return; } const formData = new FormData(); formData.append('senderId', senderId); formData.append('file', fileInput); startProgressBar(); fetch(api_url + '/po_processing', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { stopProgressBar(); original_json = data; displayResults(data); document.getElementById('generateJsonBtn').style.display = 'block'; }) .catch(error => { stopProgressBar(); console.error('Error:', error); }); }); function startProgressBar() { const progressBar = document.getElementById('progressBar'); const progressLabel = document.getElementById('progressLabel'); const progressContainer = document.getElementById('progressContainer'); progressContainer.style.display = 'block'; const steps = [ { label: 'Processing PO', percent: 25 }, { label: 'Creating Image Encodings', percent: 50 }, { label: 'Creating Text Encodings', percent: 75 }, { label: 'Extracting Information', percent: 99 } // Keep it incomplete near the end ]; let index = 0; let currentTime = 0; function updateProgress() { if (index < steps.length) { progressBar.style.width = steps[index].percent + '%'; progressLabel.textContent = steps[index].label + ` (${(currentTime / 1000).toFixed(2)}s)`; index++; setTimeout(() => { if (index < steps.length) { updateProgress(); } }, 1000); } } updateProgress(); timerStart = performance.now(); progressInterval = setInterval(() => { const elapsed = performance.now() - timerStart; currentTime = elapsed; progressLabel.textContent = steps[Math.min(index, steps.length - 1)].label + ` (${(elapsed / 1000).toFixed(2)}s)`; }, 100); } function stopProgressBar() { const progressBar = document.getElementById('progressBar'); const progressLabel = document.getElementById('progressLabel'); clearInterval(progressInterval); // Complete the progress bar when stopping setTimeout(() => { progressBar.style.width = '100%'; progressLabel.textContent = 'Completed!'; setTimeout(() => { document.getElementById('progressContainer').style.display = 'none'; }, 1000); }, 500); } function displayResults(data) { const resultContainer = document.getElementById('result-container'); const imageDisplay = document.getElementById('image-display'); resultContainer.innerHTML = ''; for (const [key, value] of Object.entries(data)) { if (key !== 'line_items') { const div = document.createElement('div'); div.classList.add('form-group'); const label = document.createElement('label'); label.classList.add('line-item-label'); label.innerText = key; const input = document.createElement('input'); input.type = 'text'; input.value = value; input.classList.add('editable-field'); input.dataset.key = key; input.readOnly = true; div.appendChild(label); div.appendChild(input); resultContainer.appendChild(div); } } if (data.line_items && Array.isArray(data.line_items)) { data.line_items.sort((a, b) => a.line_number - b.line_number); data.line_items.forEach((item, index) => { const card = document.createElement('div'); card.classList.add('line-item-card'); card.innerHTML = `<h4>Line Item ${index + 1}</h4>`; Object.entries(item).forEach(([key, value]) => { const div = document.createElement('div'); div.classList.add('form-group'); const label = document.createElement('label'); label.classList.add('line-item-label'); label.innerText = key; const input = document.createElement('input'); input.type = 'text'; input.value = value; input.classList.add('line-item-value'); input.dataset.lineItemKey = key; input.readOnly = true; div.appendChild(label); div.appendChild(input); card.appendChild(div); }); resultContainer.appendChild(card); }); } const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageDisplay.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('line-items-and-image').style.display = 'flex'; document.getElementById('additionalButtons').style.display = 'flex'; document.getElementById('submitOrderContainer').style.display = 'flex'; } function generateJsonData() { const resultContainer = document.getElementById('result-container'); const finalData = {}; resultContainer.querySelectorAll('.editable-field').forEach(field => { finalData[field.dataset.key] = field.value; }); finalData.line_items = []; resultContainer.querySelectorAll('.line-item-card').forEach(card => { const lineItem = {}; card.querySelectorAll('.line-item-value').forEach(field => { lineItem[field.dataset.lineItemKey] = field.value; }); finalData.line_items.push(lineItem); }); return finalData; } document.getElementById('generateJsonBtn').addEventListener('click', function () { const jsonOutput = document.getElementById('json-output'); generatedJsonData = generateJsonData(); jsonOutput.innerHTML = `<textarea rows="10" style="width: 100%; box-sizing: border-box;">${JSON.stringify(generatedJsonData, null, 2)}</textarea>`; }); document.getElementById('edit_fields').addEventListener('click', function () { document.querySelectorAll('.editable-field').forEach(field => { field.readOnly = false; }); document.querySelectorAll('.line-item-value').forEach(field => { field.readOnly = false; }); alert("Fields are now editable."); }); document.getElementById('createOrderCanonicalBtn').addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/create_order_canonical', { method: 'POST', body: formData }) .then(response => response.text()) .then(data => { loader.style.display = 'none'; const xmlContainer = document.getElementById('xml-container'); if (!xmlContainer) { console.error('xml-container not found'); return; } xmlContainer.innerHTML = `<pre>${escapeHTML(data)}</pre>`; const imageContainer = document.getElementById('image-container'); const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageContainer.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('xml-and-image-container').style.display = 'flex'; }) .catch(error => { loader.style.display = 'none'; console.error('Error creating canonical order:', error); }); }); document.getElementById("submit_order_canonicalbtn").addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/submit_order_canonical', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { loader.style.display = 'none'; alert(data.message); }) .catch(error => { loader.style.display = 'none'; console.error('Error submitting canonical order:', error); }); checkIfEdited(original_json, generatedJsonData); }); function checkIfEdited(original, generated) { const keys = Object.keys(original); edited = false; keys.forEach(key => { if (key !== "line_items" && original[key] !== generated[key]) { edited = true; } else if (key === "line_items") { edited = JSON.stringify(original.line_items) !== JSON.stringify(generated.line_items); } }); if (edited) { addToTraining(); } } function addToTraining() { const jsonOutput = generatedJsonData; const fileInput = document.getElementById('fileInput').files[0]; const formData_add = new FormData(); formData_add.append('file', fileInput); formData_add.append('purchaseOrderNumber', jsonOutput.purchase_order_number); formData_add.append('json', JSON.stringify(jsonOutput)); fetch(api_url + '/add_to_training', { method: 'POST', body: formData_add }) .then(response => response.json()) .then(data => { alert(data.message); }) .catch(error => { console.error('Error adding to training:', error); }); } function escapeHTML(html) { return html.replace(/</g, '<').replace(/>/g, '>'); } </script> </body> </html>Key Changes:
- Progress Bar with Timer: The progress bar now includes a timer that updates every 100 milliseconds, showing elapsed seconds with millisecond precision.
- Realistic Completion: The progress bar fills up to 99% during simulated loading tasks. It doesn't complete until the server response is received. Once the response is received or the request is caught within error handling, the progress bar is quickly completed to 100% and then hidden after a brief pause.
- User
If you want more information the response usually gets in 40s if that helps?
- Assistant
Given that the server response typically takes around 40 seconds, you can adjust the progress bar simulation to reflect this duration more accurately. We'll distribute the progress bar's updating tasks over a 40-second interval but ensure it only completes fully once the response is received. Here's how you can incorporate this into the existing code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>File Upload & API Interaction</title> <style> body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f0f2f5; margin: 0; padding: 20px; } .container { max-width: 1200px; margin: 0 auto; background: #ffffff; padding: 30px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); } h2 { text-align: center; color: #333; font-size: 28px; margin-bottom: 20px; } .form-group { margin-bottom: 20px; } label { display: block; font-weight: 500; margin-bottom: 8px; color: #555; } input[type="text"], input[type="file"], button { width: 100%; padding: 14px; border-radius: 8px; border: 1px solid #ccc; box-sizing: border-box; font-size: 16px; transition: all 0.3s ease; } input[type="text"], input[type="file"] { background-color: #f9f9f9; } input[type="text"]:focus, input[type="file"]:focus { border-color: #28a745; outline: none; background-color: #ffffff; } button { background-color: #28a745; color: #ffffff; border: none; cursor: pointer; font-size: 18px; margin-top: 10px; } button:hover { background-color: #218838; } button:active { background-color: #1e7e34; } #loader { display: none; border: 4px solid #f3f3f3; border-radius: 50%; border-top: 4px solid #28a745; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 20px auto; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .progress-container { width: 100%; background: #f3f3f3; border-radius: 8px; overflow: hidden; height: 30px; margin-top: 20px; display: none; /* Initially hidden */ position: relative; } .progress-bar { height: 100%; width: 0%; background: #28a745; transition: width 0.1s linear; position: relative; display: flex; align-items: center; justify-content: center; color: #ffffff; font-weight: bold; font-size: 16px; } #json-output { margin-top: 20px; padding: 20px; background: #ffffff; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); font-family: monospace; white-space: pre-wrap; color: #333; } #line-items-and-image { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 30px; } .card-container { width: 48%; max-height: 600px; overflow-y: auto; background: #f9f9f9; padding: 10px; border: 1px solid #ddd; border-radius: 8px; } .line-item-card { border: 1px solid #ddd; border-radius: 10px; padding: 20px; background-color: #ffffff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); margin-bottom: 20px; } .line-item-card h4 { margin: 0 0 15px; font-size: 18px; color: #333; } .line-item-label { font-size: 14px; font-weight: bold; color: #444; margin-bottom: 5px; } .line-item-value { font-size: 16px; color: #333; padding: 10px; background-color: #f9f9f9; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 10px; width: 100%; box-sizing: border-box; } #image-display { width: 48%; border: 1px solid #ddd; border-radius: 8px; text-align: center; background: #ffffff; overflow: hidden; } #image-display img { max-width: 100%; max-height: 100%; } #additionalButtons { display: flex; justify-content: space-between; margin-top: 20px; } #additionalButtons button { flex: 1; margin-right: 10px; } #additionalButtons button:last-child { margin-right: 0; } #submitOrderContainer { margin-top: 20px; display: flex; justify-content: flex-start; } #submit_order_canonicalbtn { background-color: #dc3545; color: #ffffff; border: none; padding: 14px; border-radius: 8px; cursor: pointer; font-size: 18px; } #submit_order_canonicalbtn:hover { background-color: #c82333; } #submit_order_canonicalbtn:active { background-color: #bd2130; } #xml-and-image-container { display: none; margin-top: 30px; display: flex; justify-content: space-between; } #xml-container, #image-container { max-height: 800px; width: 48%; overflow-x: auto; overflow-y: auto; border: 1px solid #ddd; padding: 10px; background: #ffffff; border-radius: 8px; } #xml-container { max-height: 800px; overflow-x: auto; overflow-y: auto; white-space: nowrap; border: 1px solid #ddd; padding: 10px; background: #ffffff; border-radius: 8px; } #xml-container pre { margin: 0; } #image-container img { width: 100%; height: 100%; } </style> </head> <body> <div class="container"> <h2>Upload File and Enter Sender ID</h2> <div class="form-group"> <label for="senderId">Sender ID</label> <input type="text" id="senderId" placeholder="Enter Sender ID"> </div> <div class="form-group"> <label for="fileInput">Upload PDF/Image</label> <input type="file" id="fileInput" accept=".pdf, .jpg, .jpeg, .png"> </div> <button id="submitBtn">Submit</button> <div class="progress-container" id="progressContainer"> <div class="progress-bar" id="progressBar"> <span id="progressLabel">Initializing...</span> </div> </div> <div id="loader"></div> <!-- Line items and Image --> <div id="line-items-and-image" style="display:none;"> <div id="result-container" class="card-container"></div> <div id="image-display"></div> </div> <button id="generateJsonBtn" style="display:none;">Generate JSON</button> <div id="json-output"></div> <div id="additionalButtons" style="display:none;"> <button id="edit_fields">Edit Fields</button> <button id="createOrderCanonicalBtn">Create Order Canonical</button> </div> <div id="submitOrderContainer" style="display:none;"> <button id="submit_order_canonicalbtn">Submit Order Canonical</button> </div> <!-- XML and Image Display --> <div id="xml-and-image-container"> <div id="xml-container"></div> <div id="image-container"></div> </div> </div> <script> let generatedJsonData = {}; const api_url = "https://8c47-35-187-224-10.ngrok-free.app/"; let edited = false; let original_json = {}; let progressInterval, timerStart; document.getElementById('submitBtn').addEventListener('click', function () { const senderId = document.getElementById('senderId').value; const fileInput = document.getElementById('fileInput').files[0]; const resultContainer = document.getElementById('result-container'); resultContainer.innerHTML = ''; document.getElementById('json-output').innerHTML = ''; if (!senderId || !fileInput) { alert('Please enter Sender ID and upload a file.'); return; } const formData = new FormData(); formData.append('senderId', senderId); formData.append('file', fileInput); startProgressBar(); fetch(api_url + '/po_processing', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { stopProgressBar(); original_json = data; displayResults(data); document.getElementById('generateJsonBtn').style.display = 'block'; }) .catch(error => { stopProgressBar(true); console.error('Error:', error); }); }); function startProgressBar() { const progressBar = document.getElementById('progressBar'); const progressLabel = document.getElementById('progressLabel'); const progressContainer = document.getElementById('progressContainer'); progressContainer.style.display = 'block'; const steps = [ { label: 'Processing PO', percent: 10 }, { label: 'Creating Image Encodings', percent: 30 }, { label: 'Creating Text Encodings', percent: 60 }, { label: 'Extracting Information', percent: 90 } ]; let index = 0; let currentTime = 0; function updateProgress() { if (index < steps.length) { progressBar.style.width = steps[index].percent + '%'; progressLabel.textContent = steps[index].label + ` (${(currentTime / 1000).toFixed(2)}s)`; index++; setTimeout(() => { if (index < steps.length) { updateProgress(); } }, 10000); // Update roughly every 10 seconds for a 40s duration } } updateProgress(); timerStart = performance.now(); progressInterval = setInterval(() => { const elapsed = performance.now() - timerStart; currentTime = elapsed; progressLabel.textContent = steps[Math.min(index, steps.length - 1)].label + ` (${(elapsed / 1000).toFixed(2)}s)`; }, 100); } function stopProgressBar(hasError = false) { const progressBar = document.getElementById('progressBar'); const progressLabel = document.getElementById('progressLabel'); clearInterval(progressInterval); if (!hasError) { // Complete the progress bar when stopping without errors setTimeout(() => { progressBar.style.width = '100%'; progressLabel.textContent = 'Completed!'; setTimeout(() => { document.getElementById('progressContainer').style.display = 'none'; }, 1000); }, 500); } else { // Display error state progressLabel.textContent = 'Failed to process'; progressBar.style.backgroundColor = '#dc3545'; // Red color for error indication } } function displayResults(data) { const resultContainer = document.getElementById('result-container'); const imageDisplay = document.getElementById('image-display'); resultContainer.innerHTML = ''; for (const [key, value] of Object.entries(data)) { if (key !== 'line_items') { const div = document.createElement('div'); div.classList.add('form-group'); const label = document.createElement('label'); label.classList.add('line-item-label'); label.innerText = key; const input = document.createElement('input'); input.type = 'text'; input.value = value; input.classList.add('editable-field'); input.dataset.key = key; input.readOnly = true; div.appendChild(label); div.appendChild(input); resultContainer.appendChild(div); } } if (data.line_items && Array.isArray(data.line_items)) { data.line_items.sort((a, b) => a.line_number - b.line_number); data.line_items.forEach((item, index) => { const card = document.createElement('div'); card.classList.add('line-item-card'); card.innerHTML = `<h4>Line Item ${index + 1}</h4>`; Object.entries(item).forEach(([key, value]) => { const div = document.createElement('div'); div.classList.add('form-group'); const label = document.createElement('label'); label.classList.add('line-item-label'); label.innerText = key; const input = document.createElement('input'); input.type = 'text'; input.value = value; input.classList.add('line-item-value'); input.dataset.lineItemKey = key; input.readOnly = true; div.appendChild(label); div.appendChild(input); card.appendChild(div); }); resultContainer.appendChild(card); }); } const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageDisplay.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('line-items-and-image').style.display = 'flex'; document.getElementById('additionalButtons').style.display = 'flex'; document.getElementById('submitOrderContainer').style.display = 'flex'; } function generateJsonData() { const resultContainer = document.getElementById('result-container'); const finalData = {}; resultContainer.querySelectorAll('.editable-field').forEach(field => { finalData[field.dataset.key] = field.value; }); finalData.line_items = []; resultContainer.querySelectorAll('.line-item-card').forEach(card => { const lineItem = {}; card.querySelectorAll('.line-item-value').forEach(field => { lineItem[field.dataset.lineItemKey] = field.value; }); finalData.line_items.push(lineItem); }); return finalData; } document.getElementById('generateJsonBtn').addEventListener('click', function () { const jsonOutput = document.getElementById('json-output'); generatedJsonData = generateJsonData(); jsonOutput.innerHTML = `<textarea rows="10" style="width: 100%; box-sizing: border-box;">${JSON.stringify(generatedJsonData, null, 2)}</textarea>`; }); document.getElementById('edit_fields').addEventListener('click', function () { document.querySelectorAll('.editable-field').forEach(field => { field.readOnly = false; }); document.querySelectorAll('.line-item-value').forEach(field => { field.readOnly = false; }); alert("Fields are now editable."); }); document.getElementById('createOrderCanonicalBtn').addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/create_order_canonical', { method: 'POST', body: formData }) .then(response => response.text()) .then(data => { loader.style.display = 'none'; const xmlContainer = document.getElementById('xml-container'); if (!xmlContainer) { console.error('xml-container not found'); return; } xmlContainer.innerHTML = `<pre>${escapeHTML(data)}</pre>`; const imageContainer = document.getElementById('image-container'); const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageContainer.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('xml-and-image-container').style.display = 'flex'; }) .catch(error => { loader.style.display = 'none'; console.error('Error creating canonical order:', error); }); }); document.getElementById("submit_order_canonicalbtn").addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/submit_order_canonical', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { loader.style.display = 'none'; alert(data.message); }) .catch(error => { loader.style.display = 'none'; console.error('Error submitting canonical order:', error); }); checkIfEdited(original_json, generatedJsonData); }); function checkIfEdited(original, generated) { const keys = Object.keys(original); edited = false; keys.forEach(key => { if (key !== "line_items" && original[key] !== generated[key]) { edited = true; } else if (key === "line_items") { edited = JSON.stringify(original.line_items) !== JSON.stringify(generated.line_items); } }); if (edited) { addToTraining(); } } function addToTraining() { const jsonOutput = generatedJsonData; const fileInput = document.getElementById('fileInput').files[0]; const formData_add = new FormData(); formData_add.append('file', fileInput); formData_add.append('purchaseOrderNumber', jsonOutput.purchase_order_number); formData_add.append('json', JSON.stringify(jsonOutput)); fetch(api_url + '/add_to_training', { method: 'POST', body: formData_add }) .then(response => response.json()) .then(data => { alert(data.message); }) .catch(error => { console.error('Error adding to training:', error); }); } function escapeHTML(html) { return html.replace(/</g, '<').replace(/>/g, '>'); } </script> </body> </html>Key Adjustments
-
Progress Steps Duration: Distributed progress steps over approximately 40 seconds by using a 10-second delay between each step in
updateProgress. -
Progress Completion Timing: The progress bar now simulates reaching 90% by the time the server typically responds. Only after a response (or error), the bar completes to 100%.
-
Error Handling: If an error occurs during the fetch, the progress bar stops and displays an error message with a red color indication.
This approach provides realistic feedback by simulating work over an expected duration while ensuring completion aligns with the server's response.
-
- User
make the bar label normal text not bold and make it look modern like filling realistic
- Assistant
To enhance the realism and modern aesthetics of the progress bar, we'll adjust the label to be normal weight and refine the animation and styling for smoother, more natural progress. Here's how you can adjust the styling and behavior of the progress bar:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>File Upload & API Interaction</title> <style> body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f0f2f5; margin: 0; padding: 20px; } .container { max-width: 1200px; margin: 0 auto; background: #ffffff; padding: 30px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); } h2 { text-align: center; color: #333; font-size: 28px; margin-bottom: 20px; } .form-group { margin-bottom: 20px; } label { display: block; font-weight: 500; margin-bottom: 8px; color: #555; } input[type="text"], input[type="file"], button { width: 100%; padding: 14px; border-radius: 8px; border: 1px solid #ccc; box-sizing: border-box; font-size: 16px; transition: all 0.3s ease; } input[type="text"], input[type="file"] { background-color: #f9f9f9; } input[type="text"]:focus, input[type="file"]:focus { border-color: #28a745; outline: none; background-color: #ffffff; } button { background-color: #28a745; color: #ffffff; border: none; cursor: pointer; font-size: 18px; margin-top: 10px; } button:hover { background-color: #218838; } button:active { background-color: #1e7e34; } #loader { display: none; border: 4px solid #f3f3f3; border-radius: 50%; border-top: 4px solid #28a745; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 20px auto; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .progress-container { width: 100%; background: #f3f3f3; border-radius: 8px; overflow: hidden; height: 30px; margin-top: 20px; display: none; /* Initially hidden */ position: relative; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } .progress-bar { height: 100%; width: 0%; background: linear-gradient(to right, #28a745, #34d058); transition: width 0.5s ease-in-out; position: relative; display: flex; align-items: center; justify-content: center; color: #ffffff; font-weight: normal; font-size: 16px; } #json-output { margin-top: 20px; padding: 20px; background: #ffffff; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); font-family: monospace; white-space: pre-wrap; color: #333; } #line-items-and-image { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 30px; } .card-container { width: 48%; max-height: 600px; overflow-y: auto; background: #f9f9f9; padding: 10px; border: 1px solid #ddd; border-radius: 8px; } .line-item-card { border: 1px solid #ddd; border-radius: 10px; padding: 20px; background-color: #ffffff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); margin-bottom: 20px; } .line-item-card h4 { margin: 0 0 15px; font-size: 18px; color: #333; } .line-item-label { font-size: 14px; font-weight: bold; color: #444; margin-bottom: 5px; } .line-item-value { font-size: 16px; color: #333; padding: 10px; background-color: #f9f9f9; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 10px; width: 100%; box-sizing: border-box; } #image-display { width: 48%; border: 1px solid #ddd; border-radius: 8px; text-align: center; background: #ffffff; overflow: hidden; } #image-display img { max-width: 100%; max-height: 100%; } #additionalButtons { display: flex; justify-content: space-between; margin-top: 20px; } #additionalButtons button { flex: 1; margin-right: 10px; } #additionalButtons button:last-child { margin-right: 0; } #submitOrderContainer { margin-top: 20px; display: flex; justify-content: flex-start; } #submit_order_canonicalbtn { background-color: #dc3545; color: #ffffff; border: none; padding: 14px; border-radius: 8px; cursor: pointer; font-size: 18px; } #submit_order_canonicalbtn:hover { background-color: #c82333; } #submit_order_canonicalbtn:active { background-color: #bd2130; } #xml-and-image-container { display: none; margin-top: 30px; display: flex; justify-content: space-between; } #xml-container, #image-container { max-height: 800px; width: 48%; overflow-x: auto; overflow-y: auto; border: 1px solid #ddd; padding: 10px; background: #ffffff; border-radius: 8px; } #xml-container { max-height: 800px; overflow-x: auto; overflow-y: auto; white-space: nowrap; border: 1px solid #ddd; padding: 10px; background: #ffffff; border-radius: 8px; } #xml-container pre { margin: 0; } #image-container img { width: 100%; height: 100%; } </style> </head> <body> <div class="container"> <h2>Upload File and Enter Sender ID</h2> <div class="form-group"> <label for="senderId">Sender ID</label> <input type="text" id="senderId" placeholder="Enter Sender ID"> </div> <div class="form-group"> <label for="fileInput">Upload PDF/Image</label> <input type="file" id="fileInput" accept=".pdf, .jpg, .jpeg, .png"> </div> <button id="submitBtn">Submit</button> <div class="progress-container" id="progressContainer"> <div class="progress-bar" id="progressBar"> <span id="progressLabel">Initializing...</span> </div> </div> <div id="loader"></div> <!-- Line items and Image --> <div id="line-items-and-image" style="display:none;"> <div id="result-container" class="card-container"></div> <div id="image-display"></div> </div> <button id="generateJsonBtn" style="display:none;">Generate JSON</button> <div id="json-output"></div> <div id="additionalButtons" style="display:none;"> <button id="edit_fields">Edit Fields</button> <button id="createOrderCanonicalBtn">Create Order Canonical</button> </div> <div id="submitOrderContainer" style="display:none;"> <button id="submit_order_canonicalbtn">Submit Order Canonical</button> </div> <!-- XML and Image Display --> <div id="xml-and-image-container"> <div id="xml-container"></div> <div id="image-container"></div> </div> </div> <script> let generatedJsonData = {}; const api_url = "https://8c47-35-187-224-10.ngrok-free.app/"; let edited = false; let original_json = {}; let progressInterval, timerStart; document.getElementById('submitBtn').addEventListener('click', function () { const senderId = document.getElementById('senderId').value; const fileInput = document.getElementById('fileInput').files[0]; const resultContainer = document.getElementById('result-container'); resultContainer.innerHTML = ''; document.getElementById('json-output').innerHTML = ''; if (!senderId || !fileInput) { alert('Please enter Sender ID and upload a file.'); return; } const formData = new FormData(); formData.append('senderId', senderId); formData.append('file', fileInput); startProgressBar(); fetch(api_url + '/po_processing', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { stopProgressBar(); original_json = data; displayResults(data); document.getElementById('generateJsonBtn').style.display = 'block'; }) .catch(error => { stopProgressBar(true); console.error('Error:', error); }); }); function startProgressBar() { const progressBar = document.getElementById('progressBar'); const progressLabel = document.getElementById('progressLabel'); const progressContainer = document.getElementById('progressContainer'); progressContainer.style.display = 'block'; const steps = [ { label: 'Processing PO', percent: 10 }, { label: 'Creating Image Encodings', percent: 30 }, { label: 'Creating Text Encodings', percent: 60 }, { label: 'Extracting Information', percent: 90 } ]; let index = 0; let currentTime = 0; function updateProgress() { if (index < steps.length) { progressBar.style.width = steps[index].percent + '%'; progressLabel.textContent = steps[index].label + ` (${(currentTime / 1000).toFixed(2)}s)`; index++; setTimeout(() => { if (index < steps.length) { updateProgress(); } }, 10000); // Update roughly every 10 seconds for a 40s duration } } updateProgress(); timerStart = performance.now(); progressInterval = setInterval(() => { const elapsed = performance.now() - timerStart; currentTime = elapsed; progressLabel.textContent = steps[Math.min(index, steps.length - 1)].label + ` (${(elapsed / 1000).toFixed(2)}s)`; }, 100); } function stopProgressBar(hasError = false) { const progressBar = document.getElementById('progressBar'); const progressLabel = document.getElementById('progressLabel'); clearInterval(progressInterval); if (!hasError) { // Complete the progress bar when stopping without errors setTimeout(() => { progressBar.style.width = '100%'; progressLabel.textContent = 'Completed!'; setTimeout(() => { document.getElementById('progressContainer').style.display = 'none'; }, 1000); }, 500); } else { // Display error state progressLabel.textContent = 'Failed to process'; progressBar.style.backgroundColor = '#dc3545'; // Red color for error indication } } function displayResults(data) { const resultContainer = document.getElementById('result-container'); const imageDisplay = document.getElementById('image-display'); resultContainer.innerHTML = ''; for (const [key, value] of Object.entries(data)) { if (key !== 'line_items') { const div = document.createElement('div'); div.classList.add('form-group'); const label = document.createElement('label'); label.classList.add('line-item-label'); label.innerText = key; const input = document.createElement('input'); input.type = 'text'; input.value = value; input.classList.add('editable-field'); input.dataset.key = key; input.readOnly = true; div.appendChild(label); div.appendChild(input); resultContainer.appendChild(div); } } if (data.line_items && Array.isArray(data.line_items)) { data.line_items.sort((a, b) => a.line_number - b.line_number); data.line_items.forEach((item, index) => { const card = document.createElement('div'); card.classList.add('line-item-card'); card.innerHTML = `<h4>Line Item ${index + 1}</h4>`; Object.entries(item).forEach(([key, value]) => { const div = document.createElement('div'); div.classList.add('form-group'); const label = document.createElement('label'); label.classList.add('line-item-label'); label.innerText = key; const input = document.createElement('input'); input.type = 'text'; input.value = value; input.classList.add('line-item-value'); input.dataset.lineItemKey = key; input.readOnly = true; div.appendChild(label); div.appendChild(input); card.appendChild(div); }); resultContainer.appendChild(card); }); } const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageDisplay.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('line-items-and-image').style.display = 'flex'; document.getElementById('additionalButtons').style.display = 'flex'; document.getElementById('submitOrderContainer').style.display = 'flex'; } function generateJsonData() { const resultContainer = document.getElementById('result-container'); const finalData = {}; resultContainer.querySelectorAll('.editable-field').forEach(field => { finalData[field.dataset.key] = field.value; }); finalData.line_items = []; resultContainer.querySelectorAll('.line-item-card').forEach(card => { const lineItem = {}; card.querySelectorAll('.line-item-value').forEach(field => { lineItem[field.dataset.lineItemKey] = field.value; }); finalData.line_items.push(lineItem); }); return finalData; } document.getElementById('generateJsonBtn').addEventListener('click', function () { const jsonOutput = document.getElementById('json-output'); generatedJsonData = generateJsonData(); jsonOutput.innerHTML = `<textarea rows="10" style="width: 100%; box-sizing: border-box;">${JSON.stringify(generatedJsonData, null, 2)}</textarea>`; }); document.getElementById('edit_fields').addEventListener('click', function () { document.querySelectorAll('.editable-field').forEach(field => { field.readOnly = false; }); document.querySelectorAll('.line-item-value').forEach(field => { field.readOnly = false; }); alert("Fields are now editable."); }); document.getElementById('createOrderCanonicalBtn').addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/create_order_canonical', { method: 'POST', body: formData }) .then(response => response.text()) .then(data => { loader.style.display = 'none'; const xmlContainer = document.getElementById('xml-container'); if (!xmlContainer) { console.error('xml-container not found'); return; } xmlContainer.innerHTML = `<pre>${escapeHTML(data)}</pre>`; const imageContainer = document.getElementById('image-container'); const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageContainer.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('xml-and-image-container').style.display = 'flex'; }) .catch(error => { loader.style.display = 'none'; console.error('Error creating canonical order:', error); }); }); document.getElementById("submit_order_canonicalbtn").addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/submit_order_canonical', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { loader.style.display = 'none'; alert(data.message); }) .catch(error => { loader.style.display = 'none'; console.error('Error submitting canonical order:', error); }); checkIfEdited(original_json, generatedJsonData); }); function checkIfEdited(original, generated) { const keys = Object.keys(original); edited = false; keys.forEach(key => { if (key !== "line_items" && original[key] !== generated[key]) { edited = true; } else if (key === "line_items") { edited = JSON.stringify(original.line_items) !== JSON.stringify(generated.line_items); } }); if (edited) { addToTraining(); } } function addToTraining() { const jsonOutput = generatedJsonData; const fileInput = document.getElementById('fileInput').files[0]; const formData_add = new FormData(); formData_add.append('file', fileInput); formData_add.append('purchaseOrderNumber', jsonOutput.purchase_order_number); formData_add.append('json', JSON.stringify(jsonOutput)); fetch(api_url + '/add_to_training', { method: 'POST', body: formData_add }) .then(response => response.json()) .then(data => { alert(data.message); }) .catch(error => { console.error('Error adding to training:', error); }); } function escapeHTML(html) { return html.replace(/</g, '<').replace(/>/g, '>'); } </script> </body> </html>Enhancement Details:
-
Progress Label Styling: Changed the progress label's font weight to normal to better fit a smooth UI.
-
Gradient and Shadow: Used a gradient for the progress bar background to give it a more modern, dynamic look and added a subtle shadow for depth.
-
Smooth Animation: Set the
transitionproperty of the progress bar to ease-in-out for a smoother progress fill animation.
This setup ensures your progress bar looks modern and is more engaging for users, with a better visual flow thanks to the animation and styling adjustments.
-
- User
The bar height is not enough for the labels
- Assistant
If the labels within the progress bar are not fitting well due to insufficient height, we can increase the height of the progress bar and adjust the styling accordingly. This will ensure the labels are clearly visible and the bar looks balanced. Here’s how you can modify the progress bar’s styling to accommodate the labels:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>File Upload & API Interaction</title> <style> body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f0f2f5; margin: 0; padding: 20px; } .container { max-width: 1200px; margin: 0 auto; background: #ffffff; padding: 30px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); } h2 { text-align: center; color: #333; font-size: 28px; margin-bottom: 20px; } .form-group { margin-bottom: 20px; } label { display: block; font-weight: 500; margin-bottom: 8px; color: #555; } input[type="text"], input[type="file"], button { width: 100%; padding: 14px; border-radius: 8px; border: 1px solid #ccc; box-sizing: border-box; font-size: 16px; transition: all 0.3s ease; } input[type="text"], input[type="file"] { background-color: #f9f9f9; } input[type="text"]:focus, input[type="file"]:focus { border-color: #28a745; outline: none; background-color: #ffffff; } button { background-color: #28a745; color: #ffffff; border: none; cursor: pointer; font-size: 18px; margin-top: 10px; } button:hover { background-color: #218838; } button:active { background-color: #1e7e34; } #loader { display: none; border: 4px solid #f3f3f3; border-radius: 50%; border-top: 4px solid #28a745; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 20px auto; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .progress-container { width: 100%; background: #f3f3f3; border-radius: 8px; overflow: hidden; height: 40px; margin-top: 20px; display: none; /* Initially hidden */ position: relative; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } .progress-bar { height: 100%; width: 0%; background: linear-gradient(to right, #28a745, #34d058); transition: width 0.5s ease-in-out; position: relative; display: flex; align-items: center; justify-content: center; color: #ffffff; font-weight: normal; font-size: 16px; white-space: nowrap; } #json-output { margin-top: 20px; padding: 20px; background: #ffffff; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); font-family: monospace; white-space: pre-wrap; color: #333; } #line-items-and-image { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 30px; } .card-container { width: 48%; max-height: 600px; overflow-y: auto; background: #f9f9f9; padding: 10px; border: 1px solid #ddd; border-radius: 8px; } .line-item-card { border: 1px solid #ddd; border-radius: 10px; padding: 20px; background-color: #ffffff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); margin-bottom: 20px; } .line-item-card h4 { margin: 0 0 15px; font-size: 18px; color: #333; } .line-item-label { font-size: 14px; font-weight: bold; color: #444; margin-bottom: 5px; } .line-item-value { font-size: 16px; color: #333; padding: 10px; background-color: #f9f9f9; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 10px; width: 100%; box-sizing: border-box; } #image-display { width: 48%; border: 1px solid #ddd; border-radius: 8px; text-align: center; background: #ffffff; overflow: hidden; } #image-display img { max-width: 100%; max-height: 100%; } #additionalButtons { display: flex; justify-content: space-between; margin-top: 20px; } #additionalButtons button { flex: 1; margin-right: 10px; } #additionalButtons button:last-child { margin-right: 0; } #submitOrderContainer { margin-top: 20px; display: flex; justify-content: flex-start; } #submit_order_canonicalbtn { background-color: #dc3545; color: #ffffff; border: none; padding: 14px; border-radius: 8px; cursor: pointer; font-size: 18px; } #submit_order_canonicalbtn:hover { background-color: #c82333; } #submit_order_canonicalbtn:active { background-color: #bd2130; } #xml-and-image-container { display: none; margin-top: 30px; display: flex; justify-content: space-between; } #xml-container, #image-container { max-height: 800px; width: 48%; overflow-x: auto; overflow-y: auto; border: 1px solid #ddd; padding: 10px; background: #ffffff; border-radius: 8px; } #xml-container { max-height: 800px; overflow-x: auto; overflow-y: auto; white-space: nowrap; border: 1px solid #ddd; padding: 10px; background: #ffffff; border-radius: 8px; } #xml-container pre { margin: 0; } #image-container img { width: 100%; height: 100%; } </style> </head> <body> <div class="container"> <h2>Upload File and Enter Sender ID</h2> <div class="form-group"> <label for="senderId">Sender ID</label> <input type="text" id="senderId" placeholder="Enter Sender ID"> </div> <div class="form-group"> <label for="fileInput">Upload PDF/Image</label> <input type="file" id="fileInput" accept=".pdf, .jpg, .jpeg, .png"> </div> <button id="submitBtn">Submit</button> <div class="progress-container" id="progressContainer"> <div class="progress-bar" id="progressBar"> <span id="progressLabel">Initializing...</span> </div> </div> <div id="loader"></div> <!-- Line items and Image --> <div id="line-items-and-image" style="display:none;"> <div id="result-container" class="card-container"></div> <div id="image-display"></div> </div> <button id="generateJsonBtn" style="display:none;">Generate JSON</button> <div id="json-output"></div> <div id="additionalButtons" style="display:none;"> <button id="edit_fields">Edit Fields</button> <button id="createOrderCanonicalBtn">Create Order Canonical</button> </div> <div id="submitOrderContainer" style="display:none;"> <button id="submit_order_canonicalbtn">Submit Order Canonical</button> </div> <!-- XML and Image Display --> <div id="xml-and-image-container"> <div id="xml-container"></div> <div id="image-container"></div> </div> </div> <script> let generatedJsonData = {}; const api_url = "https://8c47-35-187-224-10.ngrok-free.app/"; let edited = false; let original_json = {}; let progressInterval, timerStart; document.getElementById('submitBtn').addEventListener('click', function () { const senderId = document.getElementById('senderId').value; const fileInput = document.getElementById('fileInput').files[0]; const resultContainer = document.getElementById('result-container'); resultContainer.innerHTML = ''; document.getElementById('json-output').innerHTML = ''; if (!senderId || !fileInput) { alert('Please enter Sender ID and upload a file.'); return; } const formData = new FormData(); formData.append('senderId', senderId); formData.append('file', fileInput); startProgressBar(); fetch(api_url + '/po_processing', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { stopProgressBar(); original_json = data; displayResults(data); document.getElementById('generateJsonBtn').style.display = 'block'; }) .catch(error => { stopProgressBar(true); console.error('Error:', error); }); }); function startProgressBar() { const progressBar = document.getElementById('progressBar'); const progressLabel = document.getElementById('progressLabel'); const progressContainer = document.getElementById('progressContainer'); progressContainer.style.display = 'block'; const steps = [ { label: 'Processing PO', percent: 10 }, { label: 'Creating Image Encodings', percent: 30 }, { label: 'Creating Text Encodings', percent: 60 }, { label: 'Extracting Information', percent: 90 } ]; let index = 0; let currentTime = 0; function updateProgress() { if (index < steps.length) { progressBar.style.width = steps[index].percent + '%'; progressLabel.textContent = steps[index].label + ` (${(currentTime / 1000).toFixed(2)}s)`; index++; setTimeout(() => { if (index < steps.length) { updateProgress(); } }, 10000); // Update roughly every 10 seconds for a 40s duration } } updateProgress(); timerStart = performance.now(); progressInterval = setInterval(() => { const elapsed = performance.now() - timerStart; currentTime = elapsed; progressLabel.textContent = steps[Math.min(index, steps.length - 1)].label + ` (${(elapsed / 1000).toFixed(2)}s)`; }, 100); } function stopProgressBar(hasError = false) { const progressBar = document.getElementById('progressBar'); const progressLabel = document.getElementById('progressLabel'); clearInterval(progressInterval); if (!hasError) { // Complete the progress bar when stopping without errors setTimeout(() => { progressBar.style.width = '100%'; progressLabel.textContent = 'Completed!'; setTimeout(() => { document.getElementById('progressContainer').style.display = 'none'; }, 1000); }, 500); } else { // Display error state progressLabel.textContent = 'Failed to process'; progressBar.style.backgroundColor = '#dc3545'; // Red color for error indication } } function displayResults(data) { const resultContainer = document.getElementById('result-container'); const imageDisplay = document.getElementById('image-display'); resultContainer.innerHTML = ''; for (const [key, value] of Object.entries(data)) { if (key !== 'line_items') { const div = document.createElement('div'); div.classList.add('form-group'); const label = document.createElement('label'); label.classList.add('line-item-label'); label.innerText = key; const input = document.createElement('input'); input.type = 'text'; input.value = value; input.classList.add('editable-field'); input.dataset.key = key; input.readOnly = true; div.appendChild(label); div.appendChild(input); resultContainer.appendChild(div); } } if (data.line_items && Array.isArray(data.line_items)) { data.line_items.sort((a, b) => a.line_number - b.line_number); data.line_items.forEach((item, index) => { const card = document.createElement('div'); card.classList.add('line-item-card'); card.innerHTML = `<h4>Line Item ${index + 1}</h4>`; Object.entries(item).forEach(([key, value]) => { const div = document.createElement('div'); div.classList.add('form-group'); const label = document.createElement('label'); label.classList.add('line-item-label'); label.innerText = key; const input = document.createElement('input'); input.type = 'text'; input.value = value; input.classList.add('line-item-value'); input.dataset.lineItemKey = key; input.readOnly = true; div.appendChild(label); div.appendChild(input); card.appendChild(div); }); resultContainer.appendChild(card); }); } const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageDisplay.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('line-items-and-image').style.display = 'flex'; document.getElementById('additionalButtons').style.display = 'flex'; document.getElementById('submitOrderContainer').style.display = 'flex'; } function generateJsonData() { const resultContainer = document.getElementById('result-container'); const finalData = {}; resultContainer.querySelectorAll('.editable-field').forEach(field => { finalData[field.dataset.key] = field.value; }); finalData.line_items = []; resultContainer.querySelectorAll('.line-item-card').forEach(card => { const lineItem = {}; card.querySelectorAll('.line-item-value').forEach(field => { lineItem[field.dataset.lineItemKey] = field.value; }); finalData.line_items.push(lineItem); }); return finalData; } document.getElementById('generateJsonBtn').addEventListener('click', function () { const jsonOutput = document.getElementById('json-output'); generatedJsonData = generateJsonData(); jsonOutput.innerHTML = `<textarea rows="10" style="width: 100%; box-sizing: border-box;">${JSON.stringify(generatedJsonData, null, 2)}</textarea>`; }); document.getElementById('edit_fields').addEventListener('click', function () { document.querySelectorAll('.editable-field').forEach(field => { field.readOnly = false; }); document.querySelectorAll('.line-item-value').forEach(field => { field.readOnly = false; }); alert("Fields are now editable."); }); document.getElementById('createOrderCanonicalBtn').addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/create_order_canonical', { method: 'POST', body: formData }) .then(response => response.text()) .then(data => { loader.style.display = 'none'; const xmlContainer = document.getElementById('xml-container'); if (!xmlContainer) { console.error('xml-container not found'); return; } xmlContainer.innerHTML = `<pre>${escapeHTML(data)}</pre>`; const imageContainer = document.getElementById('image-container'); const imageUrl = URL.createObjectURL(document.getElementById('fileInput').files[0]); imageContainer.innerHTML = `<img src="${imageUrl}" alt="Uploaded Image">`; document.getElementById('xml-and-image-container').style.display = 'flex'; }) .catch(error => { loader.style.display = 'none'; console.error('Error creating canonical order:', error); }); }); document.getElementById("submit_order_canonicalbtn").addEventListener('click', function () { const loader = document.getElementById('loader'); const senderId = document.getElementById('senderId').value; loader.style.display = 'block'; const formData = new FormData(); formData.append('senderId', senderId); generatedJsonData = generateJsonData(); formData.append('purchaseOrderNumber', generatedJsonData.purchase_order_number); formData.append('json', JSON.stringify(generatedJsonData)); fetch(api_url + '/submit_order_canonical', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { loader.style.display = 'none'; alert(data.message); }) .catch(error => { loader.style.display = 'none'; console.error('Error submitting canonical order:', error); }); checkIfEdited(original_json, generatedJsonData); }); function checkIfEdited(original, generated) { const keys = Object.keys(original); edited = false; keys.forEach(key => { if (key !== "line_items" && original[key] !== generated[key]) { edited = true; } else if (key === "line_items") { edited = JSON.stringify(original.line_items) !== JSON.stringify(generated.line_items); } }); if (edited) { addToTraining(); } } function addToTraining() { const jsonOutput = generatedJsonData; const fileInput = document.getElementById('fileInput').files[0]; const formData_add = new FormData(); formData_add.append('file', fileInput); formData_add.append('purchaseOrderNumber', jsonOutput.purchase_order_number); formData_add.append('json', JSON.stringify(jsonOutput)); fetch(api_url + '/add_to_training', { method: 'POST', body: formData_add }) .then(response => response.json()) .then(data => { alert(data.message); }) .catch(error => { console.error('Error adding to training:', error); }); } function escapeHTML(html) { return html.replace(/</g, '<').replace(/>/g, '>'); } </script> </body> </html>Key Adjustments:
-
Height Increase: The height of the
.progress-containerand.progress-barhas been increased to 40px to better accommodate the text. -
Whitespace Handling: Added
white-space: nowrap;to prevent the label text from wrapping, ensuring it fits well within the bar.
These adjustments make sure that the progress bar is more visible, easier to read, and maintains a modern aesthetic suitable for user interfaces.
-