Download index.html from morsebas/my-apps: direct link, hf CLI and curl.
- Browser
- Download file 39.7 kB
-
https://huggingface.co/spaces/morsebas/my-apps/resolve/main/index.html
- Command line
-
hf download hf://spaces/morsebas/my-apps/index.html
-
curl -L -o index.html https://huggingface.co/spaces/morsebas/my-apps/resolve/main/index.html
39.7 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Stock Alert Reporter</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| .custom-scrollbar::-webkit-scrollbar { | |
| width: 8px; | |
| height: 8px; | |
| } | |
| .custom-scrollbar::-webkit-scrollbar-track { | |
| background: #f1f1f1; | |
| border-radius: 10px; | |
| } | |
| .custom-scrollbar::-webkit-scrollbar-thumb { | |
| background: #888; | |
| border-radius: 10px; | |
| } | |
| .custom-scrollbar::-webkit-scrollbar-thumb:hover { | |
| background: #555; | |
| } | |
| .slide-fade-enter-active { | |
| transition: all 0.3s ease-out; | |
| } | |
| .slide-fade-leave-active { | |
| transition: all 0.3s cubic-bezier(1, 0.5, 0.8, 1); | |
| } | |
| .slide-fade-enter-from, | |
| .slide-fade-leave-to { | |
| transform: translateX(20px); | |
| opacity: 0; | |
| } | |
| .chart-container { | |
| font-family: Arial, sans-serif; | |
| border: 1px solid #ddd; | |
| padding: 10px; | |
| background-color: white; | |
| } | |
| .chart-table { | |
| border-collapse: collapse; | |
| width: 100%; | |
| } | |
| .chart-table th, .chart-table td { | |
| border: 1px solid #ddd; | |
| padding: 8px; | |
| text-align: left; | |
| } | |
| .chart-table th { | |
| background-color: #f2f2f2; | |
| } | |
| .chart-table tr:nth-child(even) { | |
| background-color: #f9f9f9; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <div class="container mx-auto p-4 max-w-5xl"> | |
| <!-- Header --> | |
| <header class="bg-blue-600 text-white p-6 rounded-lg shadow-md mb-6"> | |
| <div class="flex items-center justify-between"> | |
| <div> | |
| <h1 class="text-3xl font-bold">Stock Alert Reporter</h1> | |
| <p class="mt-2">Automate your inventory reports and get alerts when stock runs low</p> | |
| </div> | |
| <div class="bg-white p-3 rounded-full"> | |
| <i class="fas fa-boxes text-blue-600 text-3xl"></i> | |
| </div> | |
| </div> | |
| </header> | |
| <!-- Main Content --> | |
| <div class="bg-white rounded-lg shadow-md p-6 mb-6"> | |
| <!-- Connection Section --> | |
| <section class="mb-8"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-800 border-b pb-2 flex items-center"> | |
| <i class="fas fa-link mr-2 text-blue-500"></i> Google Sheets Connection | |
| </h2> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| <div> | |
| <label class="block text-gray-700 mb-2">Google Sheet URL</label> | |
| <input type="text" id="sheetUrl" placeholder="https://docs.google.com/spreadsheets/d/..." | |
| class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"> | |
| </div> | |
| <div> | |
| <label class="block text-gray-700 mb-2">Sheet Name</label> | |
| <input type="text" id="sheetName" placeholder="Sheet1" | |
| class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"> | |
| </div> | |
| </div> | |
| <button id="connectBtn" class="mt-4 bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-6 rounded-lg transition duration-300 flex items-center"> | |
| <i class="fas fa-plug mr-2"></i> Connect to Sheet | |
| </button> | |
| <div id="connectionStatus" class="mt-3 hidden p-3 rounded-lg"></div> | |
| </section> | |
| <!-- Report Configuration --> | |
| <section class="mb-8"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-800 border-b pb-2 flex items-center"> | |
| <i class="fas fa-cog mr-2 text-blue-500"></i> Report Configuration | |
| </h2> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6"> | |
| <!-- Basic Settings --> | |
| <div> | |
| <h3 class="font-medium text-gray-700 mb-3 flex items-center"> | |
| <i class="fas fa-info-circle mr-2 text-blue-400"></i> Basic Settings | |
| </h3> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Report Title</label> | |
| <input type="text" id="reportTitle" placeholder="Low Stock Alert - " | |
| class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Stock Threshold (months)</label> | |
| <input type="number" id="stockThreshold" value="1.5" step="0.1" min="0.1" | |
| class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Date Format</label> | |
| <select id="dateFormat" class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"> | |
| <option value="MM/DD/YYYY">MM/DD/YYYY</option> | |
| <option value="DD/MM/YYYY">DD/MM/YYYY</option> | |
| <option value="YYYY-MM-DD">YYYY-MM-DD</option> | |
| <option value="Month D, YYYY">Month D, YYYY</option> | |
| </select> | |
| </div> | |
| </div> | |
| <!-- Column Selection --> | |
| <div> | |
| <h3 class="font-medium text-gray-700 mb-3 flex items-center"> | |
| <i class="fas fa-columns mr-2 text-blue-400"></i> Column Selection | |
| </h3> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Columns to Include</label> | |
| <div id="columnSelection" class="border border-gray-300 rounded-lg p-3 max-h-48 overflow-y-auto custom-scrollbar"> | |
| <p class="text-gray-500 italic">Connect to a sheet to see available columns</p> | |
| </div> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Months of Stock Column</label> | |
| <select id="monthsStockColumn" class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" disabled> | |
| <option value="">Select column</option> | |
| </select> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Additional Variables --> | |
| <div class="mt-6"> | |
| <h3 class="font-medium text-gray-700 mb-3 flex items-center"> | |
| <i class="fas fa-plus-circle mr-2 text-blue-400"></i> Additional Variables | |
| </h3> | |
| <div class="flex items-center mb-3"> | |
| <select id="additionalVarSelect" class="flex-grow p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 mr-2" disabled> | |
| <option value="">Select additional variable</option> | |
| </select> | |
| <button id="addVarBtn" class="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-lg transition duration-300 flex items-center" disabled> | |
| <i class="fas fa-plus mr-2"></i> Add | |
| </button> | |
| </div> | |
| <div id="addedVariables" class="border border-gray-200 rounded-lg p-3 min-h-16"> | |
| <p class="text-gray-500 italic">No additional variables added yet</p> | |
| </div> | |
| </div> | |
| </section> | |
| <!-- Scheduling Options --> | |
| <section class="mb-8"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-800 border-b pb-2 flex items-center"> | |
| <i class="fas fa-clock mr-2 text-blue-500"></i> Scheduling Options | |
| </h2> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-4"> | |
| <div class="border border-gray-200 rounded-lg p-4 hover:border-blue-400 transition duration-300 cursor-pointer frequency-option" data-frequency="once"> | |
| <div class="flex items-center mb-2"> | |
| <input type="radio" name="frequency" id="frequencyOnce" class="mr-2" checked> | |
| <label for="frequencyOnce" class="font-medium">Send Once</label> | |
| </div> | |
| <p class="text-gray-600 text-sm">Send report immediately</p> | |
| </div> | |
| <div class="border border-gray-200 rounded-lg p-4 hover:border-blue-400 transition duration-300 cursor-pointer frequency-option" data-frequency="daily"> | |
| <div class="flex items-center mb-2"> | |
| <input type="radio" name="frequency" id="frequencyDaily" class="mr-2"> | |
| <label for="frequencyDaily" class="font-medium">Daily</label> | |
| </div> | |
| <p class="text-gray-600 text-sm">Send report every day</p> | |
| </div> | |
| <div class="border border-gray-200 rounded-lg p-4 hover:border-blue-400 transition duration-300 cursor-pointer frequency-option" data-frequency="weekly"> | |
| <div class="flex items-center mb-2"> | |
| <input type="radio" name="frequency" id="frequencyWeekly" class="mr-2"> | |
| <label for="frequencyWeekly" class="font-medium">Weekly</label> | |
| </div> | |
| <p class="text-gray-600 text-sm">Send report on specific days</p> | |
| </div> | |
| </div> | |
| <!-- Weekly Options (hidden by default) --> | |
| <div id="weeklyOptions" class="mt-4 hidden"> | |
| <h4 class="text-gray-700 mb-2">Select days to send:</h4> | |
| <div class="flex flex-wrap gap-2"> | |
| <label class="inline-flex items-center"> | |
| <input type="checkbox" class="form-checkbox h-5 w-5 text-blue-600" value="Monday"> | |
| <span class="ml-2 text-gray-700">Monday</span> | |
| </label> | |
| <label class="inline-flex items-center"> | |
| <input type="checkbox" class="form-checkbox h-5 w-5 text-blue-600" value="Tuesday"> | |
| <span class="ml-2 text-gray-700">Tuesday</span> | |
| </label> | |
| <label class="inline-flex items-center"> | |
| <input type="checkbox" class="form-checkbox h-5 w-5 text-blue-600" value="Wednesday"> | |
| <span class="ml-2 text-gray-700">Wednesday</span> | |
| </label> | |
| <label class="inline-flex items-center"> | |
| <input type="checkbox" class="form-checkbox h-5 w-5 text-blue-600" value="Thursday"> | |
| <span class="ml-2 text-gray-700">Thursday</span> | |
| </label> | |
| <label class="inline-flex items-center"> | |
| <input type="checkbox" class="form-checkbox h-5 w-5 text-blue-600" value="Friday"> | |
| <span class="ml-2 text-gray-700">Friday</span> | |
| </label> | |
| <label class="inline-flex items-center"> | |
| <input type="checkbox" class="form-checkbox h-5 w-5 text-blue-600" value="Saturday"> | |
| <span class="ml-2 text-gray-700">Saturday</span> | |
| </label> | |
| <label class="inline-flex items-center"> | |
| <input type="checkbox" class="form-checkbox h-5 w-5 text-blue-600" value="Sunday"> | |
| <span class="ml-2 text-gray-700">Sunday</span> | |
| </label> | |
| </div> | |
| </div> | |
| <!-- Time Selection --> | |
| <div class="mt-4"> | |
| <label class="block text-gray-700 mb-2">Send Time</label> | |
| <input type="time" id="sendTime" value="09:00" class="p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"> | |
| </div> | |
| </section> | |
| <!-- Email Configuration --> | |
| <section class="mb-8"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-800 border-b pb-2 flex items-center"> | |
| <i class="fas fa-envelope mr-2 text-blue-500"></i> Email Configuration | |
| </h2> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Recipient Email(s)</label> | |
| <textarea id="recipientEmails" placeholder="Enter email addresses, separated by commas" | |
| class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 h-20"></textarea> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Email Subject</label> | |
| <input type="text" id="emailSubject" placeholder="Low Stock Alert - [DATE]" | |
| class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Email Message</label> | |
| <textarea id="emailMessage" placeholder="Hello,\n\nHere's your low stock report for [DATE]..." | |
| class="w-full p-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 h-32"></textarea> | |
| </div> | |
| <div class="flex items-center"> | |
| <input type="checkbox" id="includeChart" class="form-checkbox h-5 w-5 text-blue-600" checked> | |
| <label for="includeChart" class="ml-2 text-gray-700">Include chart in email</label> | |
| </div> | |
| <div class="flex items-center mt-2"> | |
| <input type="checkbox" id="createSheetCopy" class="form-checkbox h-5 w-5 text-blue-600" checked> | |
| <label for="createSheetCopy" class="ml-2 text-gray-700">Create Google Sheet copy in recipient's Drive</label> | |
| </div> | |
| </section> | |
| <!-- Preview Section --> | |
| <section class="mb-8"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-800 border-b pb-2 flex items-center"> | |
| <i class="fas fa-eye mr-2 text-blue-500"></i> Report Preview | |
| </h2> | |
| <div class="bg-gray-100 p-4 rounded-lg"> | |
| <div id="emailPreview" class="bg-white p-6 rounded-lg shadow-inner"> | |
| <p class="text-gray-500 italic">Configure your report to see a preview</p> | |
| </div> | |
| </div> | |
| <button id="refreshPreviewBtn" class="mt-4 bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-2 px-6 rounded-lg transition duration-300 flex items-center"> | |
| <i class="fas fa-sync-alt mr-2"></i> Refresh Preview | |
| </button> | |
| </section> | |
| <!-- Action Buttons --> | |
| <div class="flex justify-between"> | |
| <button id="saveConfigBtn" class="bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-2 px-6 rounded-lg transition duration-300 flex items-center"> | |
| <i class="fas fa-save mr-2"></i> Save Configuration | |
| </button> | |
| <button id="sendReportBtn" class="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-6 rounded-lg transition duration-300 flex items-center"> | |
| <i class="fas fa-paper-plane mr-2"></i> Send Report Now | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Status Modal --> | |
| <div id="statusModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50"> | |
| <div class="bg-white rounded-lg p-6 max-w-md w-full"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-xl font-semibold" id="modalTitle">Processing</h3> | |
| <button id="closeModalBtn" class="text-gray-500 hover:text-gray-700"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <div id="modalContent" class="mb-4"> | |
| <div class="flex items-center"> | |
| <div id="statusSpinner" class="animate-spin h-5 w-5 mr-3 text-blue-600"> | |
| <i class="fas fa-circle-notch"></i> | |
| </div> | |
| <p id="statusMessage">Connecting to Google Sheets...</p> | |
| </div> | |
| </div> | |
| <div id="modalActions" class="flex justify-end hidden"> | |
| <button id="modalConfirmBtn" class="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-lg transition duration-300"> | |
| OK | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // UI Event Listeners | |
| document.querySelectorAll('.frequency-option').forEach(option => { | |
| option.addEventListener('click', function() { | |
| const frequency = this.getAttribute('data-frequency'); | |
| document.querySelector(`#frequency${frequency.charAt(0).toUpperCase() + frequency.slice(1)}`).checked = true; | |
| // Update UI | |
| document.querySelectorAll('.frequency-option').forEach(opt => { | |
| opt.classList.remove('border-blue-500', 'bg-blue-50'); | |
| }); | |
| this.classList.add('border-blue-500', 'bg-blue-50'); | |
| // Show/hide weekly options | |
| document.getElementById('weeklyOptions').classList.toggle('hidden', frequency !== 'weekly'); | |
| }); | |
| }); | |
| // Mock connection to Google Sheets | |
| document.getElementById('connectBtn').addEventListener('click', function() { | |
| const sheetUrl = document.getElementById('sheetUrl').value; | |
| const sheetName = document.getElementById('sheetName').value; | |
| if (!sheetUrl || !sheetName) { | |
| showStatus('Please enter both Sheet URL and Sheet Name', 'error'); | |
| return; | |
| } | |
| showModal('Connecting to Google Sheets...'); | |
| // Simulate API call | |
| setTimeout(() => { | |
| // Mock data - in a real extension, you would use the Google Sheets API | |
| const mockColumns = [ | |
| { id: 'A', name: 'SKU' }, | |
| { id: 'B', name: 'Product ID' }, | |
| { id: 'C', name: 'Product Name' }, | |
| { id: 'D', name: 'Size' }, | |
| { id: 'E', name: 'Color' }, | |
| { id: 'F', name: 'Category' }, | |
| { id: 'BD', name: 'Current Stock' }, | |
| { id: 'BE', name: 'Monthly Sales' }, | |
| { id: 'BF', name: 'Reorder Point' }, | |
| { id: 'BG', name: 'Lead Time (days)' }, | |
| { id: 'BH', name: 'Supplier' }, | |
| { id: 'BI', name: 'Cost Price' }, | |
| { id: 'BJ', name: 'Retail Price' }, | |
| { id: 'BK', name: 'Last Order Date' }, | |
| { id: 'BL', name: 'Months of Stock Left' }, | |
| { id: 'BM', name: 'Warehouse Location' } | |
| ]; | |
| // Populate column selection | |
| const columnSelection = document.getElementById('columnSelection'); | |
| columnSelection.innerHTML = ''; | |
| mockColumns.forEach(col => { | |
| const div = document.createElement('div'); | |
| div.className = 'flex items-center mb-2'; | |
| div.innerHTML = ` | |
| <input type="checkbox" id="col_${col.id}" value="${col.id}" data-name="${col.name}" class="column-checkbox form-checkbox h-5 w-5 text-blue-600" checked> | |
| <label for="col_${col.id}" class="ml-2 text-gray-700">${col.name} (${col.id})</label> | |
| `; | |
| columnSelection.appendChild(div); | |
| }); | |
| // Populate months of stock dropdown | |
| const monthsStockSelect = document.getElementById('monthsStockColumn'); | |
| monthsStockSelect.innerHTML = '<option value="">Select column</option>'; | |
| mockColumns.forEach(col => { | |
| const option = document.createElement('option'); | |
| option.value = col.id; | |
| option.textContent = `${col.name} (${col.id})`; | |
| if (col.id === 'BL') option.selected = true; | |
| monthsStockSelect.appendChild(option); | |
| }); | |
| monthsStockSelect.disabled = false; | |
| // Populate additional variables dropdown | |
| const additionalVarSelect = document.getElementById('additionalVarSelect'); | |
| additionalVarSelect.innerHTML = '<option value="">Select additional variable</option>'; | |
| mockColumns.forEach(col => { | |
| const option = document.createElement('option'); | |
| option.value = col.id; | |
| option.textContent = `${col.name} (${col.id})`; | |
| additionalVarSelect.appendChild(option); | |
| }); | |
| additionalVarSelect.disabled = false; | |
| document.getElementById('addVarBtn').disabled = false; | |
| showStatus('Successfully connected to Google Sheets!', 'success'); | |
| updatePreview(); | |
| closeModal(); | |
| }, 1500); | |
| }); | |
| // Add variable button | |
| document.getElementById('addVarBtn').addEventListener('click', function() { | |
| const select = document.getElementById('additionalVarSelect'); | |
| const selectedOption = select.options[select.selectedIndex]; | |
| if (!selectedOption.value) return; | |
| const addedVars = document.getElementById('addedVariables'); | |
| // Check if already added | |
| if (document.getElementById(`added_var_${selectedOption.value}`)) { | |
| showStatus('This variable is already added', 'warning'); | |
| return; | |
| } | |
| // Remove "no variables" message if present | |
| if (addedVars.querySelector('p.italic')) { | |
| addedVars.innerHTML = ''; | |
| } | |
| const varDiv = document.createElement('div'); | |
| varDiv.id = `added_var_${selectedOption.value}`; | |
| varDiv.className = 'flex items-center justify-between bg-gray-50 p-2 rounded mb-2'; | |
| varDiv.innerHTML = ` | |
| <span>${selectedOption.text}</span> | |
| <button class="remove-var-btn text-red-500 hover:text-red-700" data-id="${selectedOption.value}"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| `; | |
| addedVars.appendChild(varDiv); | |
| // Add event listener to remove button | |
| varDiv.querySelector('.remove-var-btn').addEventListener('click', function() { | |
| this.parentElement.remove(); | |
| if (addedVars.children.length === 0) { | |
| addedVars.innerHTML = '<p class="text-gray-500 italic">No additional variables added yet</p>'; | |
| } | |
| }); | |
| updatePreview(); | |
| }); | |
| // Refresh preview button | |
| document.getElementById('refreshPreviewBtn').addEventListener('click', updatePreview); | |
| // Send report button | |
| document.getElementById('sendReportBtn').addEventListener('click', function() { | |
| // Validate required fields | |
| if (!validateForm()) return; | |
| showModal('Generating and sending report...'); | |
| // Simulate sending process | |
| setTimeout(() => { | |
| document.getElementById('statusSpinner').classList.add('hidden'); | |
| document.getElementById('statusMessage').textContent = 'Report sent successfully!'; | |
| document.getElementById('modalActions').classList.remove('hidden'); | |
| }, 2500); | |
| }); | |
| // Save config button | |
| document.getElementById('saveConfigBtn').addEventListener('click', function() { | |
| showModal('Saving configuration...'); | |
| // Simulate save process | |
| setTimeout(() => { | |
| document.getElementById('statusSpinner').classList.add('hidden'); | |
| document.getElementById('statusMessage').textContent = 'Configuration saved successfully!'; | |
| document.getElementById('modalActions').classList.remove('hidden'); | |
| }, 1500); | |
| }); | |
| // Close modal button | |
| document.getElementById('closeModalBtn').addEventListener('click', closeModal); | |
| document.getElementById('modalConfirmBtn').addEventListener('click', closeModal); | |
| // Form inputs that should trigger preview update | |
| const previewInputs = [ | |
| 'reportTitle', 'stockThreshold', 'dateFormat', 'emailSubject', | |
| 'emailMessage', 'includeChart', 'createSheetCopy' | |
| ]; | |
| previewInputs.forEach(id => { | |
| document.getElementById(id).addEventListener('change', updatePreview); | |
| document.getElementById(id).addEventListener('input', updatePreview); | |
| }); | |
| // Column selection changes | |
| document.getElementById('columnSelection').addEventListener('change', updatePreview); | |
| document.getElementById('monthsStockColumn').addEventListener('change', updatePreview); | |
| // Helper functions | |
| function showStatus(message, type) { | |
| const statusDiv = document.getElementById('connectionStatus'); | |
| statusDiv.textContent = message; | |
| statusDiv.className = 'mt-3 p-3 rounded-lg '; | |
| if (type === 'success') { | |
| statusDiv.classList.add('bg-green-100', 'text-green-800'); | |
| } else if (type === 'error') { | |
| statusDiv.classList.add('bg-red-100', 'text-red-800'); | |
| } else if (type === 'warning') { | |
| statusDiv.classList.add('bg-yellow-100', 'text-yellow-800'); | |
| } | |
| statusDiv.classList.remove('hidden'); | |
| } | |
| function showModal(message) { | |
| document.getElementById('statusMessage').textContent = message; | |
| document.getElementById('statusSpinner').classList.remove('hidden'); | |
| document.getElementById('modalActions').classList.add('hidden'); | |
| document.getElementById('modalTitle').textContent = 'Processing'; | |
| document.getElementById('statusModal').classList.remove('hidden'); | |
| } | |
| function closeModal() { | |
| document.getElementById('statusModal').classList.add('hidden'); | |
| } | |
| function validateForm() { | |
| // Check if connected to sheet | |
| if (document.getElementById('columnSelection').querySelector('p.italic')) { | |
| showStatus('Please connect to a Google Sheet first', 'error'); | |
| return false; | |
| } | |
| // Check recipient emails | |
| const emails = document.getElementById('recipientEmails').value.trim(); | |
| if (!emails) { | |
| showStatus('Please enter at least one recipient email', 'error'); | |
| return false; | |
| } | |
| // Check months of stock column selected | |
| if (!document.getElementById('monthsStockColumn').value) { | |
| showStatus('Please select the months of stock column', 'error'); | |
| return false; | |
| } | |
| return true; | |
| } | |
| function updatePreview() { | |
| const previewDiv = document.getElementById('emailPreview'); | |
| const reportTitle = document.getElementById('reportTitle').value || 'Low Stock Alert'; | |
| const threshold = document.getElementById('stockThreshold').value || '1.5'; | |
| const dateFormat = document.getElementById('dateFormat').value; | |
| const emailSubject = document.getElementById('emailSubject').value || 'Low Stock Alert - [DATE]'; | |
| const emailMessage = document.getElementById('emailMessage').value || 'Hello,\n\nHere\'s your low stock report for [DATE].'; | |
| const includeChart = document.getElementById('includeChart').checked; | |
| const createSheetCopy = document.getElementById('createSheetCopy').checked; | |
| // Get selected columns | |
| const selectedColumns = []; | |
| document.querySelectorAll('.column-checkbox:checked').forEach(checkbox => { | |
| selectedColumns.push({ | |
| id: checkbox.value, | |
| name: checkbox.getAttribute('data-name') | |
| }); | |
| }); | |
| // Get months stock column | |
| const monthsStockCol = document.getElementById('monthsStockColumn').value; | |
| const monthsStockName = monthsStockCol ? | |
| document.getElementById('monthsStockColumn').options[document.getElementById('monthsStockColumn').selectedIndex].text.split(' (')[0] : ''; | |
| // Get added variables | |
| const addedVars = []; | |
| document.querySelectorAll('#addedVariables > div').forEach(div => { | |
| const varId = div.querySelector('button').getAttribute('data-id'); | |
| const varName = div.querySelector('span').textContent.split(' (')[0]; | |
| addedVars.push({ id: varId, name: varName }); | |
| }); | |
| // Format current date | |
| const now = new Date(); | |
| let formattedDate; | |
| switch(dateFormat) { | |
| case 'MM/DD/YYYY': | |
| formattedDate = `${(now.getMonth()+1).toString().padStart(2, '0')}/${now.getDate().toString().padStart(2, '0')}/${now.getFullYear()}`; | |
| break; | |
| case 'DD/MM/YYYY': | |
| formattedDate = `${now.getDate().toString().padStart(2, '0')}/${(now.getMonth()+1).toString().padStart(2, '0')}/${now.getFullYear()}`; | |
| break; | |
| case 'YYYY-MM-DD': | |
| formattedDate = `${now.getFullYear()}-${(now.getMonth()+1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`; | |
| break; | |
| case 'Month D, YYYY': | |
| const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; | |
| formattedDate = `${months[now.getMonth()]} ${now.getDate()}, ${now.getFullYear()}`; | |
| break; | |
| default: | |
| formattedDate = now.toLocaleDateString(); | |
| } | |
| // Generate preview HTML | |
| let previewHTML = ` | |
| <div class="mb-6"> | |
| <h2 class="text-2xl font-bold text-gray-800">${emailSubject.replace('[DATE]', formattedDate)}</h2> | |
| <p class="text-gray-600 mt-1">${now.toLocaleTimeString()}</p> | |
| </div> | |
| <div class="mb-6"> | |
| ${emailMessage.replace('[DATE]', formattedDate).replace(/\n/g, '<br>')} | |
| </div> | |
| `; | |
| if (includeChart) { | |
| // Mock chart data - in real extension this would come from Google Sheets | |
| const mockData = [ | |
| { SKU: 'PROD-001', Name: 'Premium Widget', Size: 'Large', Stock: 45, MonthsLeft: 1.2, Category: 'Widgets', Supplier: 'Acme Inc' }, | |
| { SKU: 'PROD-002', Name: 'Basic Widget', Size: 'Medium', Stock: 32, MonthsLeft: 1.1, Category: 'Widgets', Supplier: 'Globex Corp' }, | |
| { SKU: 'PROD-003', Name: 'Deluxe Gadget', Size: 'Small', Stock: 18, MonthsLeft: 0.8, Category: 'Gadgets', Supplier: 'Initech' }, | |
| { SKU: 'PROD-004', Name: 'Standard Gadget', Size: 'Large', Stock: 27, MonthsLeft: 1.4, Category: 'Gadgets', Supplier: 'Initech' }, | |
| { SKU: 'PROD-005', Name: 'Economy Thing', Size: 'Medium', Stock: 15, MonthsLeft: 0.9, Category: 'Things', Supplier: 'Acme Inc' } | |
| ].filter(item => item.MonthsLeft < parseFloat(threshold)); | |
| if (mockData.length > 0) { | |
| previewHTML += ` | |
| <div class="mb-6"> | |
| <h3 class="text-lg font-semibold mb-3">Products with stock below ${threshold} months</h3> | |
| <div class="chart-container"> | |
| <table class="chart-table"> | |
| <thead> | |
| <tr> | |
| ${selectedColumns.map(col => `<th>${col.name}</th>`).join('')} | |
| ${addedVars.map(v => `<th>${v.name}</th>`).join('')} | |
| </tr> | |
| </thead> | |
| <tbody> | |
| ${mockData.map(item => ` | |
| <tr> | |
| ${selectedColumns.map(col => `<td>${item[col.name.replace(' ', '')] || ''}</td>`).join('')} | |
| ${addedVars.map(v => `<td>${item[v.name.replace(' ', '')] || ''}</td>`).join('')} | |
| </tr> | |
| `).join('')} | |
| </tbody> | |
| </table> | |
| </div> | |
| <p class="text-sm text-gray-500 mt-2">This table is formatted for easy copy-pasting into Excel.</p> | |
| </div> | |
| `; | |
| } else { | |
| previewHTML += ` | |
| <div class="mb-6 bg-yellow-50 p-4 rounded-lg border border-yellow-200"> | |
| <p>No products found with stock below ${threshold} months.</p> | |
| </div> | |
| `; | |
| } | |
| } | |
| if (createSheetCopy) { | |
| previewHTML += ` | |
| <div class="mb-6 bg-blue-50 p-4 rounded-lg border border-blue-200"> | |
| <p>A copy of this report has been created in your Google Drive:</p> | |
| <p class="mt-2"><a href="#" class="text-blue-600 hover:underline">${reportTitle} - ${formattedDate}</a></p> | |
| <p class="text-sm text-gray-500 mt-2">The sheet contains all data from the original with filtering applied.</p> | |
| </div> | |
| `; | |
| } | |
| previewHTML += ` | |
| <div class="text-sm text-gray-500 border-t pt-4"> | |
| <p>This report was generated automatically by the Stock Alert Reporter extension.</p> | |
| </div> | |
| `; | |
| previewDiv.innerHTML = previewHTML; | |
| } | |
| }); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=morsebas/my-apps" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |