Download index.html from ltaimo/projects: direct link, hf CLI and curl.
- Browser
- Download file 37.2 kB
-
https://huggingface.co/spaces/ltaimo/projects/resolve/main/index.html
- Command line
-
hf download hf://spaces/ltaimo/projects/index.html
-
curl -L -o index.html https://huggingface.co/spaces/ltaimo/projects/resolve/main/index.html
37.2 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Excel Stock Manager</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> | |
| .cell:focus { | |
| outline: 2px solid #3b82f6; | |
| outline-offset: -1px; | |
| z-index: 10; | |
| } | |
| .selected { | |
| background-color: #bfdbfe; | |
| } | |
| .header-cell { | |
| background-color: #f3f4f6; | |
| font-weight: 600; | |
| position: sticky; | |
| top: 0; | |
| z-index: 20; | |
| } | |
| .row-header { | |
| background-color: #f3f4f6; | |
| font-weight: 600; | |
| position: sticky; | |
| left: 0; | |
| z-index: 20; | |
| } | |
| .corner-cell { | |
| background-color: #f3f4f6; | |
| position: sticky; | |
| top: 0; | |
| left: 0; | |
| z-index: 30; | |
| } | |
| .scroll-container { | |
| overflow: auto; | |
| height: calc(100vh - 120px); | |
| } | |
| .formula-bar { | |
| border-bottom: 1px solid #e5e7eb; | |
| } | |
| .tab-active { | |
| border-bottom: 2px solid #3b82f6; | |
| color: #3b82f6; | |
| } | |
| .autocomplete-items { | |
| position: absolute; | |
| border: 1px solid #d1d5db; | |
| border-top: none; | |
| z-index: 99; | |
| top: 100%; | |
| left: 0; | |
| right: 0; | |
| } | |
| .autocomplete-items div { | |
| padding: 8px; | |
| cursor: pointer; | |
| background-color: white; | |
| } | |
| .autocomplete-items div:hover { | |
| background-color: #e5e7eb; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50"> | |
| <div class="container mx-auto p-4"> | |
| <div class="bg-white rounded-lg shadow-lg overflow-hidden"> | |
| <!-- Header --> | |
| <div class="bg-blue-600 text-white p-4 flex justify-between items-center"> | |
| <div class="flex items-center"> | |
| <i class="fas fa-table text-2xl mr-3"></i> | |
| <h1 class="text-xl font-bold">Excel Stock Manager</h1> | |
| </div> | |
| <div class="flex space-x-2"> | |
| <button id="save-btn" class="bg-blue-700 hover:bg-blue-800 px-4 py-2 rounded flex items-center"> | |
| <i class="fas fa-save mr-2"></i> Save | |
| </button> | |
| <button id="load-btn" class="bg-blue-700 hover:bg-blue-800 px-4 py-2 rounded flex items-center"> | |
| <i class="fas fa-folder-open mr-2"></i> Load | |
| </button> | |
| <button id="export-btn" class="bg-blue-700 hover:bg-blue-800 px-4 py-2 rounded flex items-center"> | |
| <i class="fas fa-file-export mr-2"></i> Export | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Tabs --> | |
| <div class="flex border-b"> | |
| <button class="tab-active px-4 py-2 font-medium">Inventory</button> | |
| <button class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700">Suppliers</button> | |
| <button class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700">Reports</button> | |
| <button class="px-4 py-2 font-medium text-gray-500 hover:text-gray-700">Settings</button> | |
| </div> | |
| <!-- Toolbar --> | |
| <div class="flex items-center p-2 border-b bg-gray-50"> | |
| <div class="flex space-x-1 mr-4"> | |
| <button class="p-2 hover:bg-gray-200 rounded" title="Cut"> | |
| <i class="fas fa-cut"></i> | |
| </button> | |
| <button class="p-2 hover:bg-gray-200 rounded" title="Copy"> | |
| <i class="fas fa-copy"></i> | |
| </button> | |
| <button class="p-2 hover:bg-gray-200 rounded" title="Paste"> | |
| <i class="fas fa-paste"></i> | |
| </button> | |
| <button class="p-2 hover:bg-gray-200 rounded" title="Format Painter"> | |
| <i class="fas fa-paint-brush"></i> | |
| </button> | |
| </div> | |
| <div class="flex space-x-1 mr-4"> | |
| <button class="p-2 hover:bg-gray-200 rounded" title="Bold"> | |
| <i class="fas fa-bold"></i> | |
| </button> | |
| <button class="p-2 hover:bg-gray-200 rounded" title="Italic"> | |
| <i class="fas fa-italic"></i> | |
| </button> | |
| <button class="p-2 hover:bg-gray-200 rounded" title="Underline"> | |
| <i class="fas fa-underline"></i> | |
| </button> | |
| </div> | |
| <div class="flex space-x-1"> | |
| <button class="p-2 hover:bg-gray-200 rounded" title="Align Left"> | |
| <i class="fas fa-align-left"></i> | |
| </button> | |
| <button class="p-2 hover:bg-gray-200 rounded" title="Align Center"> | |
| <i class="fas fa-align-center"></i> | |
| </button> | |
| <button class="p-2 hover:bg-gray-200 rounded" title="Align Right"> | |
| <i class="fas fa-align-right"></i> | |
| </button> | |
| </div> | |
| <div class="flex space-x-1 ml-auto"> | |
| <button id="add-row-btn" class="bg-blue-500 hover:bg-blue-600 text-white px-3 py-1 rounded flex items-center"> | |
| <i class="fas fa-plus mr-1"></i> Add Row | |
| </button> | |
| <button id="delete-row-btn" class="bg-red-500 hover:bg-red-600 text-white px-3 py-1 rounded flex items-center"> | |
| <i class="fas fa-minus mr-1"></i> Delete Row | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Formula Bar --> | |
| <div class="formula-bar flex items-center p-1"> | |
| <div class="w-16 text-center font-mono text-sm text-gray-600" id="active-cell-address">A1</div> | |
| <div class="flex-1 relative"> | |
| <input type="text" id="formula-input" class="w-full border border-gray-300 p-1 font-mono text-sm" placeholder="Enter formula or value"> | |
| <div id="autocomplete-list" class="autocomplete-items hidden"></div> | |
| </div> | |
| <button id="enter-formula-btn" class="bg-blue-500 text-white px-2 py-1 ml-1 rounded"> | |
| <i class="fas fa-check"></i> | |
| </button> | |
| <button id="cancel-formula-btn" class="bg-gray-200 text-gray-700 px-2 py-1 ml-1 rounded"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <!-- Spreadsheet --> | |
| <div class="scroll-container"> | |
| <table id="spreadsheet" class="border-collapse"> | |
| <thead> | |
| <tr> | |
| <th class="corner-cell w-10 h-8 border border-gray-300"></th> | |
| <th class="header-cell w-40 border border-gray-300">Product ID</th> | |
| <th class="header-cell w-60 border border-gray-300">Product Name</th> | |
| <th class="header-cell w-40 border border-gray-300">Category</th> | |
| <th class="header-cell w-40 border border-gray-300">Supplier</th> | |
| <th class="header-cell w-40 border border-gray-300">Unit Price</th> | |
| <th class="header-cell w-40 border border-gray-300">Quantity</th> | |
| <th class="header-cell w-40 border border-gray-300">Total Value</th> | |
| <th class="header-cell w-40 border border-gray-300">Reorder Level</th> | |
| <th class="header-cell w-40 border border-gray-300">Status</th> | |
| </tr> | |
| </thead> | |
| <tbody id="sheet-body"> | |
| <!-- Rows will be added dynamically --> | |
| </tbody> | |
| </table> | |
| </div> | |
| <!-- Status Bar --> | |
| <div class="flex items-center justify-between p-2 border-t bg-gray-100 text-sm text-gray-600"> | |
| <div class="flex space-x-4"> | |
| <span id="selected-range">Ready</span> | |
| <span id="sum-value">Sum: $0.00</span> | |
| <span id="average-value">Avg: $0.00</span> | |
| <span id="count-value">Count: 0</span> | |
| </div> | |
| <div> | |
| <span id="last-saved">Last saved: Never</span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Modals --> | |
| <div id="save-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50"> | |
| <div class="bg-white rounded-lg p-6 w-96"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-lg font-bold">Save Inventory</h3> | |
| <button id="close-save-modal" class="text-gray-500 hover:text-gray-700"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">File Name</label> | |
| <input type="text" id="save-filename" class="w-full border border-gray-300 rounded p-2" placeholder="inventory.json"> | |
| </div> | |
| <div class="flex justify-end space-x-2"> | |
| <button id="cancel-save" class="px-4 py-2 bg-gray-200 text-gray-700 rounded">Cancel</button> | |
| <button id="confirm-save" class="px-4 py-2 bg-blue-500 text-white rounded">Save</button> | |
| </div> | |
| </div> | |
| </div> | |
| <div id="load-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50"> | |
| <div class="bg-white rounded-lg p-6 w-96"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-lg font-bold">Load Inventory</h3> | |
| <button id="close-load-modal" class="text-gray-500 hover:text-gray-700"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Select File</label> | |
| <input type="file" id="load-file" class="w-full border border-gray-300 rounded p-2" accept=".json"> | |
| </div> | |
| <div class="flex justify-end space-x-2"> | |
| <button id="cancel-load" class="px-4 py-2 bg-gray-200 text-gray-700 rounded">Cancel</button> | |
| <button id="confirm-load" class="px-4 py-2 bg-blue-500 text-white rounded">Load</button> | |
| </div> | |
| </div> | |
| </div> | |
| <div id="export-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50"> | |
| <div class="bg-white rounded-lg p-6 w-96"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-lg font-bold">Export Data</h3> | |
| <button id="close-export-modal" class="text-gray-500 hover:text-gray-700"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">Format</label> | |
| <select id="export-format" class="w-full border border-gray-300 rounded p-2"> | |
| <option value="csv">CSV (Comma Separated Values)</option> | |
| <option value="json">JSON</option> | |
| <option value="excel">Excel (XLSX)</option> | |
| </select> | |
| </div> | |
| <div class="mb-4"> | |
| <label class="block text-gray-700 mb-2">File Name</label> | |
| <input type="text" id="export-filename" class="w-full border border-gray-300 rounded p-2" placeholder="inventory_export"> | |
| </div> | |
| <div class="flex justify-end space-x-2"> | |
| <button id="cancel-export" class="px-4 py-2 bg-gray-200 text-gray-700 rounded">Cancel</button> | |
| <button id="confirm-export" class="px-4 py-2 bg-blue-500 text-white rounded">Export</button> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Sample data for autocomplete | |
| const categories = ["Electronics", "Clothing", "Food", "Furniture", "Office Supplies"]; | |
| const suppliers = ["TechCorp", "Fashion Inc", "Food Distributors", "Home & Office", "Global Suppliers"]; | |
| const statuses = ["In Stock", "Low Stock", "Out of Stock", "Discontinued"]; | |
| // Initialize spreadsheet with 20 rows | |
| const sheetBody = document.getElementById('sheet-body'); | |
| const rowCount = 20; | |
| let activeCell = null; | |
| let selectedRange = { startRow: -1, startCol: -1, endRow: -1, endCol: -1 }; | |
| let spreadsheetData = []; | |
| // Create initial data structure | |
| function initializeData() { | |
| for (let i = 0; i < rowCount; i++) { | |
| const rowData = { | |
| id: `P${1000 + i}`, | |
| name: `Product ${i + 1}`, | |
| category: categories[Math.floor(Math.random() * categories.length)], | |
| supplier: suppliers[Math.floor(Math.random() * suppliers.length)], | |
| price: (Math.random() * 100 + 10).toFixed(2), | |
| quantity: Math.floor(Math.random() * 100), | |
| reorder: Math.floor(Math.random() * 20 + 5), | |
| status: statuses[Math.floor(Math.random() * statuses.length)] | |
| }; | |
| rowData.total = (rowData.price * rowData.quantity).toFixed(2); | |
| spreadsheetData.push(rowData); | |
| } | |
| } | |
| // Render the spreadsheet | |
| function renderSpreadsheet() { | |
| sheetBody.innerHTML = ''; | |
| spreadsheetData.forEach((rowData, rowIndex) => { | |
| const row = document.createElement('tr'); | |
| // Row header | |
| const rowHeader = document.createElement('td'); | |
| rowHeader.className = 'row-header border border-gray-300 text-center'; | |
| rowHeader.textContent = rowIndex + 1; | |
| row.appendChild(rowHeader); | |
| // Product ID | |
| const idCell = createCell(rowData.id, rowIndex, 0); | |
| row.appendChild(idCell); | |
| // Product Name | |
| const nameCell = createCell(rowData.name, rowIndex, 1); | |
| row.appendChild(nameCell); | |
| // Category | |
| const categoryCell = createCell(rowData.category, rowIndex, 2); | |
| row.appendChild(categoryCell); | |
| // Supplier | |
| const supplierCell = createCell(rowData.supplier, rowIndex, 3); | |
| row.appendChild(supplierCell); | |
| // Unit Price | |
| const priceCell = createCell(rowData.price, rowIndex, 4); | |
| priceCell.classList.add('text-right'); | |
| row.appendChild(priceCell); | |
| // Quantity | |
| const quantityCell = createCell(rowData.quantity, rowIndex, 5); | |
| quantityCell.classList.add('text-right'); | |
| row.appendChild(quantityCell); | |
| // Total Value | |
| const totalCell = createCell(rowData.total, rowIndex, 6); | |
| totalCell.classList.add('text-right', 'font-medium'); | |
| row.appendChild(totalCell); | |
| // Reorder Level | |
| const reorderCell = createCell(rowData.reorder, rowIndex, 7); | |
| reorderCell.classList.add('text-right'); | |
| row.appendChild(reorderCell); | |
| // Status | |
| const statusCell = createCell(rowData.status, rowIndex, 8); | |
| if (rowData.status === "Low Stock") { | |
| statusCell.classList.add('text-yellow-600'); | |
| } else if (rowData.status === "Out of Stock") { | |
| statusCell.classList.add('text-red-600'); | |
| } | |
| row.appendChild(statusCell); | |
| sheetBody.appendChild(row); | |
| }); | |
| } | |
| function createCell(value, rowIndex, colIndex) { | |
| const cell = document.createElement('td'); | |
| cell.className = 'cell border border-gray-300 p-1'; | |
| cell.textContent = value; | |
| cell.dataset.row = rowIndex; | |
| cell.dataset.col = colIndex; | |
| cell.addEventListener('click', function() { | |
| handleCellClick(this, rowIndex, colIndex); | |
| }); | |
| cell.addEventListener('dblclick', function() { | |
| handleCellDoubleClick(this, rowIndex, colIndex); | |
| }); | |
| return cell; | |
| } | |
| function handleCellClick(cell, rowIndex, colIndex) { | |
| // Clear previous selection | |
| document.querySelectorAll('.selected').forEach(el => el.classList.remove('selected')); | |
| // Select the clicked cell | |
| cell.classList.add('selected'); | |
| activeCell = cell; | |
| // Update active cell address | |
| const colLetter = String.fromCharCode(65 + colIndex); | |
| document.getElementById('active-cell-address').textContent = `${colLetter}${rowIndex + 1}`; | |
| // Update formula bar with cell content | |
| document.getElementById('formula-input').value = spreadsheetData[rowIndex][getPropertyName(colIndex)] || ''; | |
| // Update selected range | |
| selectedRange = { | |
| startRow: rowIndex, | |
| startCol: colIndex, | |
| endRow: rowIndex, | |
| endCol: colIndex | |
| }; | |
| updateStatusBar(); | |
| } | |
| function handleCellDoubleClick(cell, rowIndex, colIndex) { | |
| const input = document.createElement('input'); | |
| input.type = 'text'; | |
| input.value = cell.textContent; | |
| input.className = 'w-full h-full p-1 border-0 focus:outline-none'; | |
| cell.innerHTML = ''; | |
| cell.appendChild(input); | |
| input.focus(); | |
| input.addEventListener('blur', function() { | |
| const newValue = input.value; | |
| cell.textContent = newValue; | |
| updateCellData(rowIndex, colIndex, newValue); | |
| }); | |
| input.addEventListener('keypress', function(e) { | |
| if (e.key === 'Enter') { | |
| const newValue = input.value; | |
| cell.textContent = newValue; | |
| updateCellData(rowIndex, colIndex, newValue); | |
| input.blur(); | |
| } | |
| }); | |
| } | |
| function getPropertyName(colIndex) { | |
| const properties = ['id', 'name', 'category', 'supplier', 'price', 'quantity', 'total', 'reorder', 'status']; | |
| return properties[colIndex]; | |
| } | |
| function updateCellData(rowIndex, colIndex, value) { | |
| const property = getPropertyName(colIndex); | |
| spreadsheetData[rowIndex][property] = value; | |
| // If quantity or price changes, update total | |
| if (property === 'quantity' || property === 'price') { | |
| const price = parseFloat(spreadsheetData[rowIndex].price) || 0; | |
| const quantity = parseFloat(spreadsheetData[rowIndex].quantity) || 0; | |
| spreadsheetData[rowIndex].total = (price * quantity).toFixed(2); | |
| // Update status based on quantity and reorder level | |
| const reorder = parseFloat(spreadsheetData[rowIndex].reorder) || 0; | |
| if (quantity === 0) { | |
| spreadsheetData[rowIndex].status = "Out of Stock"; | |
| } else if (quantity <= reorder) { | |
| spreadsheetData[rowIndex].status = "Low Stock"; | |
| } else { | |
| spreadsheetData[rowIndex].status = "In Stock"; | |
| } | |
| // Re-render the row to update all cells | |
| renderSpreadsheet(); | |
| } | |
| updateStatusBar(); | |
| } | |
| function updateStatusBar() { | |
| // Calculate sum, average, count for selected numeric cells | |
| let sum = 0; | |
| let count = 0; | |
| if (selectedRange.startRow === selectedRange.endRow && | |
| selectedRange.startCol === selectedRange.endCol) { | |
| // Single cell selected | |
| const cellValue = parseFloat(spreadsheetData[selectedRange.startRow][getPropertyName(selectedRange.startCol)]); | |
| if (!isNaN(cellValue)) { | |
| sum = cellValue; | |
| count = 1; | |
| } | |
| } else { | |
| // Range selected (not implemented in this simplified version) | |
| } | |
| document.getElementById('sum-value').textContent = `Sum: $${sum.toFixed(2)}`; | |
| document.getElementById('average-value').textContent = `Avg: $${(count > 0 ? sum / count : 0).toFixed(2)}`; | |
| document.getElementById('count-value').textContent = `Count: ${count}`; | |
| } | |
| // Formula bar autocomplete | |
| const formulaInput = document.getElementById('formula-input'); | |
| formulaInput.addEventListener('input', function() { | |
| const input = this.value.toLowerCase(); | |
| const autocompleteList = document.getElementById('autocomplete-list'); | |
| if (input.length === 0) { | |
| autocompleteList.classList.add('hidden'); | |
| return; | |
| } | |
| // Filter functions | |
| const functions = ['SUM', 'AVERAGE', 'COUNT', 'MAX', 'MIN', 'IF']; | |
| const filteredFunctions = functions.filter(fn => fn.toLowerCase().startsWith(input)); | |
| // Filter categories and suppliers if typing in category or supplier columns | |
| let filteredCategories = []; | |
| let filteredSuppliers = []; | |
| if (activeCell && (activeCell.dataset.col == 2 || input.startsWith('='))) { | |
| filteredCategories = categories.filter(cat => cat.toLowerCase().includes(input)); | |
| } | |
| if (activeCell && (activeCell.dataset.col == 3 || input.startsWith('='))) { | |
| filteredSuppliers = suppliers.filter(sup => sup.toLowerCase().includes(input)); | |
| } | |
| if (filteredFunctions.length === 0 && filteredCategories.length === 0 && filteredSuppliers.length === 0) { | |
| autocompleteList.classList.add('hidden'); | |
| return; | |
| } | |
| autocompleteList.innerHTML = ''; | |
| if (filteredFunctions.length > 0) { | |
| const funcGroup = document.createElement('div'); | |
| funcGroup.className = 'font-bold text-gray-500 px-2 py-1'; | |
| funcGroup.textContent = 'Functions'; | |
| autocompleteList.appendChild(funcGroup); | |
| filteredFunctions.forEach(func => { | |
| const item = document.createElement('div'); | |
| item.textContent = func; | |
| item.addEventListener('click', function() { | |
| formulaInput.value = `=${func}(`; | |
| formulaInput.focus(); | |
| autocompleteList.classList.add('hidden'); | |
| }); | |
| autocompleteList.appendChild(item); | |
| }); | |
| } | |
| if (filteredCategories.length > 0) { | |
| const catGroup = document.createElement('div'); | |
| catGroup.className = 'font-bold text-gray-500 px-2 py-1 mt-2'; | |
| catGroup.textContent = 'Categories'; | |
| autocompleteList.appendChild(catGroup); | |
| filteredCategories.forEach(cat => { | |
| const item = document.createElement('div'); | |
| item.textContent = cat; | |
| item.addEventListener('click', function() { | |
| formulaInput.value = cat; | |
| formulaInput.focus(); | |
| autocompleteList.classList.add('hidden'); | |
| }); | |
| autocompleteList.appendChild(item); | |
| }); | |
| } | |
| if (filteredSuppliers.length > 0) { | |
| const supGroup = document.createElement('div'); | |
| supGroup.className = 'font-bold text-gray-500 px-2 py-1 mt-2'; | |
| supGroup.textContent = 'Suppliers'; | |
| autocompleteList.appendChild(supGroup); | |
| filteredSuppliers.forEach(sup => { | |
| const item = document.createElement('div'); | |
| item.textContent = sup; | |
| item.addEventListener('click', function() { | |
| formulaInput.value = sup; | |
| formulaInput.focus(); | |
| autocompleteList.classList.add('hidden'); | |
| }); | |
| autocompleteList.appendChild(item); | |
| }); | |
| } | |
| autocompleteList.classList.remove('hidden'); | |
| }); | |
| // Hide autocomplete when clicking outside | |
| document.addEventListener('click', function(e) { | |
| if (e.target !== formulaInput) { | |
| document.getElementById('autocomplete-list').classList.add('hidden'); | |
| } | |
| }); | |
| // Formula bar buttons | |
| document.getElementById('enter-formula-btn').addEventListener('click', function() { | |
| if (activeCell) { | |
| const rowIndex = parseInt(activeCell.dataset.row); | |
| const colIndex = parseInt(activeCell.dataset.col); | |
| const newValue = formulaInput.value; | |
| activeCell.textContent = newValue; | |
| updateCellData(rowIndex, colIndex, newValue); | |
| } | |
| }); | |
| document.getElementById('cancel-formula-btn').addEventListener('click', function() { | |
| formulaInput.value = ''; | |
| if (activeCell) { | |
| const rowIndex = parseInt(activeCell.dataset.row); | |
| const colIndex = parseInt(activeCell.dataset.col); | |
| formulaInput.value = spreadsheetData[rowIndex][getPropertyName(colIndex)] || ''; | |
| } | |
| }); | |
| // Add row button | |
| document.getElementById('add-row-btn').addEventListener('click', function() { | |
| const newRow = { | |
| id: `P${1000 + spreadsheetData.length}`, | |
| name: `New Product`, | |
| category: categories[0], | |
| supplier: suppliers[0], | |
| price: "0.00", | |
| quantity: "0", | |
| reorder: "10", | |
| status: "In Stock", | |
| total: "0.00" | |
| }; | |
| spreadsheetData.push(newRow); | |
| renderSpreadsheet(); | |
| }); | |
| // Delete row button | |
| document.getElementById('delete-row-btn').addEventListener('click', function() { | |
| if (activeCell && spreadsheetData.length > 1) { | |
| const rowIndex = parseInt(activeCell.dataset.row); | |
| spreadsheetData.splice(rowIndex, 1); | |
| renderSpreadsheet(); | |
| // Select the first cell of the same row if it exists, or the previous row | |
| const newRowIndex = Math.min(rowIndex, spreadsheetData.length - 1); | |
| const newCell = document.querySelector(`td[data-row="${newRowIndex}"][data-col="0"]`); | |
| if (newCell) { | |
| handleCellClick(newCell, newRowIndex, 0); | |
| } | |
| } | |
| }); | |
| // Save modal | |
| document.getElementById('save-btn').addEventListener('click', function() { | |
| document.getElementById('save-modal').classList.remove('hidden'); | |
| }); | |
| document.getElementById('close-save-modal').addEventListener('click', function() { | |
| document.getElementById('save-modal').classList.add('hidden'); | |
| }); | |
| document.getElementById('cancel-save').addEventListener('click', function() { | |
| document.getElementById('save-modal').classList.add('hidden'); | |
| }); | |
| document.getElementById('confirm-save').addEventListener('click', function() { | |
| const filename = document.getElementById('save-filename').value || 'inventory.json'; | |
| const dataStr = JSON.stringify(spreadsheetData, null, 2); | |
| const dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr); | |
| const link = document.createElement('a'); | |
| link.setAttribute('href', dataUri); | |
| link.setAttribute('download', filename); | |
| document.body.appendChild(link); | |
| link.click(); | |
| document.body.removeChild(link); | |
| document.getElementById('save-modal').classList.add('hidden'); | |
| document.getElementById('last-saved').textContent = `Last saved: ${new Date().toLocaleString()}`; | |
| }); | |
| // Load modal | |
| document.getElementById('load-btn').addEventListener('click', function() { | |
| document.getElementById('load-modal').classList.remove('hidden'); | |
| }); | |
| document.getElementById('close-load-modal').addEventListener('click', function() { | |
| document.getElementById('load-modal').classList.add('hidden'); | |
| }); | |
| document.getElementById('cancel-load').addEventListener('click', function() { | |
| document.getElementById('load-modal').classList.add('hidden'); | |
| }); | |
| document.getElementById('confirm-load').addEventListener('click', function() { | |
| const fileInput = document.getElementById('load-file'); | |
| if (fileInput.files.length > 0) { | |
| const file = fileInput.files[0]; | |
| const reader = new FileReader(); | |
| reader.onload = function(e) { | |
| try { | |
| const data = JSON.parse(e.target.result); | |
| if (Array.isArray(data)) { | |
| spreadsheetData = data; | |
| renderSpreadsheet(); | |
| document.getElementById('load-modal').classList.add('hidden'); | |
| document.getElementById('last-saved').textContent = `Last saved: ${new Date().toLocaleString()}`; | |
| } else { | |
| alert('Invalid file format. Expected an array of inventory items.'); | |
| } | |
| } catch (error) { | |
| alert('Error parsing JSON file: ' + error.message); | |
| } | |
| }; | |
| reader.readAsText(file); | |
| } | |
| }); | |
| // Export modal | |
| document.getElementById('export-btn').addEventListener('click', function() { | |
| document.getElementById('export-modal').classList.remove('hidden'); | |
| }); | |
| document.getElementById('close-export-modal').addEventListener('click', function() { | |
| document.getElementById('export-modal').classList.add('hidden'); | |
| }); | |
| document.getElementById('cancel-export').addEventListener('click', function() { | |
| document.getElementById('export-modal').classList.add('hidden'); | |
| }); | |
| document.getElementById('confirm-export').addEventListener('click', function() { | |
| const format = document.getElementById('export-format').value; | |
| const filename = document.getElementById('export-filename').value || 'inventory_export'; | |
| if (format === 'csv') { | |
| exportToCSV(filename); | |
| } else if (format === 'json') { | |
| exportToJSON(filename); | |
| } else { | |
| alert('Excel export would require a library like SheetJS. This is a simplified demo.'); | |
| } | |
| document.getElementById('export-modal').classList.add('hidden'); | |
| }); | |
| function exportToCSV(filename) { | |
| let csv = 'Product ID,Product Name,Category,Supplier,Unit Price,Quantity,Total Value,Reorder Level,Status\n'; | |
| spreadsheetData.forEach(row => { | |
| csv += `"${row.id}","${row.name}","${row.category}","${row.supplier}",${row.price},${row.quantity},${row.total},${row.reorder},"${row.status}"\n`; | |
| }); | |
| const dataUri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv); | |
| const link = document.createElement('a'); | |
| link.setAttribute('href', dataUri); | |
| link.setAttribute('download', filename + '.csv'); | |
| document.body.appendChild(link); | |
| link.click(); | |
| document.body.removeChild(link); | |
| } | |
| function exportToJSON(filename) { | |
| const dataStr = JSON.stringify(spreadsheetData, null, 2); | |
| const dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(dataStr); | |
| const link = document.createElement('a'); | |
| link.setAttribute('href', dataUri); | |
| link.setAttribute('download', filename + '.json'); | |
| document.body.appendChild(link); | |
| link.click(); | |
| document.body.removeChild(link); | |
| } | |
| // Initialize the application | |
| initializeData(); | |
| renderSpreadsheet(); | |
| // Select the first cell by default | |
| const firstCell = document.querySelector('td[data-row="0"][data-col="0"]'); | |
| if (firstCell) { | |
| handleCellClick(firstCell, 0, 0); | |
| } | |
| }); | |
| </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=ltaimo/projects" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |