Main Access Updates
This commit is contained in:
@@ -0,0 +1,630 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Product List - Product Finder</title>
|
||||
<link rel="stylesheet" href="{{ url_for('products.serve_css', filename='styles.css') }}">
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 25px 30px;
|
||||
margin-bottom: 25px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
margin: 0;
|
||||
color: #333;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #6a4c93;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #563d7c;
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 4px 12px rgba(106, 76, 147, 0.3);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #e0e0e0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #d0d0d0;
|
||||
}
|
||||
|
||||
.search-controls {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
flex: 1;
|
||||
min-width: 300px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.search-box input {
|
||||
width: 100%;
|
||||
padding: 12px 45px 12px 15px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 15px;
|
||||
transition: all 0.2s;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.search-box input:focus {
|
||||
outline: none;
|
||||
border-color: #6a4c93;
|
||||
box-shadow: 0 0 0 3px rgba(106, 76, 147, 0.1);
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.filter-group {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-group select {
|
||||
padding: 12px 15px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
background: white;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.filter-group select:focus {
|
||||
outline: none;
|
||||
border-color: #6a4c93;
|
||||
}
|
||||
|
||||
.stats {
|
||||
margin-top: 15px;
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.products-table-container {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.products-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.products-table thead {
|
||||
background: #f8f9fa;
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.products-table th {
|
||||
padding: 16px 20px;
|
||||
text-align: left;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.products-table td {
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.products-table tbody tr {
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.products-table tbody tr:hover {
|
||||
background: #f8f9fa;
|
||||
transform: scale(1.01);
|
||||
box-shadow: 0 2px 8px rgba(106, 76, 147, 0.1);
|
||||
}
|
||||
|
||||
.products-table tbody tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.product-code {
|
||||
font-weight: 700;
|
||||
color: #6a4c93;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.product-description {
|
||||
color: #555;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 4px 12px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.status-active {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.status-discontinued {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.status-icon {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.status-active .status-icon {
|
||||
background: #28a745;
|
||||
}
|
||||
|
||||
.status-discontinued .status-icon {
|
||||
background: #dc3545;
|
||||
}
|
||||
|
||||
.category-badge {
|
||||
background: #e3f2fd;
|
||||
color: #1565c0;
|
||||
padding: 4px 10px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.location-badge {
|
||||
color: #666;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.pagination-info {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.pagination-controls {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.pagination-btn {
|
||||
padding: 8px 16px;
|
||||
border: 2px solid #e0e0e0;
|
||||
background: white;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.pagination-btn:hover:not(:disabled) {
|
||||
border-color: #6a4c93;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.pagination-btn:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.pagination-btn.active {
|
||||
background: #6a4c93;
|
||||
color: white;
|
||||
border-color: #6a4c93;
|
||||
}
|
||||
|
||||
.page-numbers {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
background: whi1024px) {
|
||||
.products-table {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.products-table th,
|
||||
.products-table td {
|
||||
padding: 12px 10px;
|
||||
}
|
||||
|
||||
.products-table th:nth-child(3),
|
||||
.products-table td:nth-child(3) {
|
||||
display: none; /* Hide category on medium screens */
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.search-controls {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.header-top {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.products-table {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.products-table th,
|
||||
.products-table td {
|
||||
padding: 10px 8px;
|
||||
}
|
||||
|
||||
.products-table th:nth-child(4),
|
||||
.products-table td:nth-child(4) {
|
||||
display: none; /* Hide location on small screens */
|
||||
}
|
||||
|
||||
.product-description {
|
||||
max-width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<div class="header-top">
|
||||
<h1>📦 Product List</h1>
|
||||
<div class="header-actions">
|
||||
<a href="{{ url_for('products.product_manager') }}" class="btn btn-primary">
|
||||
Product Editor
|
||||
</a>
|
||||
<a href="{{ url_for('products.product_finder') }}" class="btn btn-secondary">
|
||||
Back to Quiz
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="search-controls">
|
||||
<div class="search-box">
|
||||
<input
|
||||
type="text"
|
||||
id="searchInput"
|
||||
placeholder="Search by product code or description..."
|
||||
>
|
||||
<span class="search-icon">🔍</span>
|
||||
</div>
|
||||
|
||||
<div class="filter-group">
|
||||
<label for="statusFilter" style="font-weight: 500; color: #555;">Status:</label>
|
||||
<select id="statusFilter">
|
||||
<option value="all">All Products</option>
|
||||
<option value="active">Active Only</option>
|
||||
<option value="discontinued">Discontinued Only</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="filter-group">
|
||||
<label for="perPageSelect" style="font-weight: 500; color: #555;">Per Page:</label>
|
||||
<select id="perPageSelect">
|
||||
<option value="10">10</option>
|
||||
<option value="20" selected>20</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stats" id="statsBar">
|
||||
Loading products...
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="productsContainer">
|
||||
<div class="loading">⏳ Loading products...</div>
|
||||
</div>
|
||||
|
||||
<div id="paginationContainer"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentPage = 1;
|
||||
let totalPages = 1;
|
||||
let searchTimeout = null;
|
||||
|
||||
// Initialize
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadProducts();
|
||||
|
||||
// Search input with debounce
|
||||
document.getElementById('searchInput').addEventListener('input', (e) => {
|
||||
clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(() => {
|
||||
currentPage = 1;
|
||||
loadProducts();
|
||||
}, 300);
|
||||
});
|
||||
|
||||
// Status filter change
|
||||
document.getElementById('statusFilter').addEventListener('change', () => {
|
||||
currentPage = 1;
|
||||
loadProducts();
|
||||
});
|
||||
|
||||
// Per page change
|
||||
document.getElementById('perPageSelect').addEventListener('change', () => {
|
||||
currentPage = 1;
|
||||
loadProducts();
|
||||
});
|
||||
});
|
||||
|
||||
async function loadProducts() {
|
||||
const searchQuery = document.getElementById('searchInput').value;
|
||||
const statusFilter = document.getElementById('statusFilter').value;
|
||||
const perPage = document.getElementById('perPageSelect').value;
|
||||
|
||||
const params = new URLSearchParams({
|
||||
q: searchQuery,
|
||||
status: statusFilter,
|
||||
page: currentPage,
|
||||
per_page: perPage
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await fetch(`/quiz/api/products/search?${params}`);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.status === 'success') {
|
||||
displayProducts(data.products);
|
||||
displayPagination(data.pagination);
|
||||
updateStats(data.pagination);
|
||||
} else {
|
||||
console.error('Error loading products:', data.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
document.getElementById('productsContainer').innerHTML = `
|
||||
<div class="empty-state">
|
||||
<h2>❌ Error Loading Products</h2>
|
||||
<p>Please try again later.</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
function displayProducts(products) {
|
||||
const container = document.getElementById('productsContainer');
|
||||
|
||||
if (products.length === 0) {
|
||||
container.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<h2>🔍 No Products Found</h2>
|
||||
<p>Try adjusting your search or filters.</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
const productsRows = products.map(product => {
|
||||
const isDiscontinued = product.discontinued;
|
||||
const statusClass = isDiscontinued ? 'status-discontinued' : 'status-active';
|
||||
const statusText = isDiscontinued ? 'Discontinued' : 'Active';
|
||||
|
||||
const category = product.category || 'N/A';
|
||||
const location = product.location || 'N/A';
|
||||
|
||||
return `
|
||||
<tr onclick="viewProduct('${product.productCode}')">
|
||||
<td><span class="product-code">${product.productCode}</span></td>
|
||||
<td class="product-description">${product.description}</td>
|
||||
<td><span class="category-badge">${category}</span></td>
|
||||
<td><span class="location-badge">📍 ${location}</span></td>
|
||||
<td>
|
||||
<div class="status-badge ${statusClass}">
|
||||
<span class="status-icon"></span>
|
||||
${statusText}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="products-table-container">
|
||||
<table class="products-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Product Code</th>
|
||||
<th>Description</th>
|
||||
<th>Category</th>
|
||||
<th>Location</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${productsRows}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function displayPagination(pagination) {
|
||||
const container = document.getElementById('paginationContainer');
|
||||
|
||||
if (pagination.total_pages <= 1) {
|
||||
container.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
totalPages = pagination.total_pages;
|
||||
currentPage = pagination.page;
|
||||
|
||||
// Generate page numbers (show 5 at a time)
|
||||
const pageNumbers = [];
|
||||
const start = Math.max(1, currentPage - 2);
|
||||
const end = Math.min(totalPages, currentPage + 2);
|
||||
|
||||
for (let i = start; i <= end; i++) {
|
||||
pageNumbers.push(`
|
||||
<button
|
||||
class="pagination-btn ${i === currentPage ? 'active' : ''}"
|
||||
onclick="goToPage(${i})"
|
||||
>
|
||||
${i}
|
||||
</button>
|
||||
`);
|
||||
}
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="pagination">
|
||||
<div class="pagination-info">
|
||||
Page ${pagination.page} of ${pagination.total_pages}
|
||||
</div>
|
||||
<div class="pagination-controls">
|
||||
<button
|
||||
class="pagination-btn"
|
||||
onclick="goToPage(${currentPage - 1})"
|
||||
${!pagination.has_prev ? 'disabled' : ''}
|
||||
>
|
||||
← Previous
|
||||
</button>
|
||||
<div class="page-numbers">
|
||||
${pageNumbers.join('')}
|
||||
</div>
|
||||
<button
|
||||
class="pagination-btn"
|
||||
onclick="goToPage(${currentPage + 1})"
|
||||
${!pagination.has_next ? 'disabled' : ''}
|
||||
>
|
||||
Next →
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function updateStats(pagination) {
|
||||
const statsBar = document.getElementById('statsBar');
|
||||
const start = (pagination.page - 1) * pagination.per_page + 1;
|
||||
const end = Math.min(pagination.page * pagination.per_page, pagination.total_products);
|
||||
|
||||
statsBar.textContent = `Showing ${start}-${end} of ${pagination.total_products} products`;
|
||||
}
|
||||
|
||||
function goToPage(page) {
|
||||
if (page < 1 || page > totalPages) return;
|
||||
currentPage = page;
|
||||
loadProducts();
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
function viewProduct(productCode) {
|
||||
// Navigate to product manager with the product selected
|
||||
window.location.href = `/quiz/manage?product=${encodeURIComponent(productCode)}`;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user