Main Access Updates

This commit is contained in:
Jason
2026-06-11 11:10:18 -05:00
parent 0632aa22e1
commit be1475dd8e
5 changed files with 737 additions and 5 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ app.register_blueprint(canvas_bp)
@app.route('/')
def home():
"""Redirect to login if not authenticated, otherwise show home"""
if 'user_id' not in session:
if 'username' not in session:
return redirect(url_for('auth.login_page'))
# If user hasn't selected a location yet, redirect to selection
+61
View File
@@ -30,6 +30,15 @@ def advanced_search():
"""Serve the advanced search page"""
return render_template('advanced_search.html')
@products_bp.route('/list')
@login_required
def product_list():
"""Serve the product listing page with search and pagination"""
# Check if user has permission to manage products
if not can_user('manage_products'):
return redirect(url_for('products.product_finder'))
return render_template('product_list.html')
@products_bp.route('/manage')
@login_required
def product_manager():
@@ -67,6 +76,58 @@ def get_products():
'products': products
})
@products_bp.route('/api/products/search', methods=['GET'])
@login_required
def search_products():
"""Search products with pagination and filtering"""
# Get query parameters
search_query = request.args.get('q', '').strip().lower()
page = int(request.args.get('page', 1))
per_page = int(request.args.get('per_page', 20))
location = request.args.get('location')
status_filter = request.args.get('status', 'all') # 'all', 'active', 'discontinued'
# Get all products
all_products = da.get_all_products(location=location)
# Filter by search query (description and product code)
if search_query:
filtered_products = [
p for p in all_products
if search_query in p.get('description', '').lower()
or search_query in p.get('productCode', '').lower()
]
else:
filtered_products = all_products
# Filter by status
if status_filter == 'active':
filtered_products = [p for p in filtered_products if not p.get('discontinued', False)]
elif status_filter == 'discontinued':
filtered_products = [p for p in filtered_products if p.get('discontinued', False)]
# Calculate pagination
total_products = len(filtered_products)
total_pages = (total_products + per_page - 1) // per_page if per_page > 0 else 1
start_idx = (page - 1) * per_page
end_idx = start_idx + per_page
# Get page slice
products_page = filtered_products[start_idx:end_idx]
return jsonify({
'status': 'success',
'products': products_page,
'pagination': {
'page': page,
'per_page': per_page,
'total_products': total_products,
'total_pages': total_pages,
'has_prev': page > 1,
'has_next': page < total_pages
}
})
@products_bp.route('/api/products/<product_code>', methods=['GET'])
@login_required
def get_product(product_code):
+2 -2
View File
@@ -79,10 +79,10 @@
let manageProductsLink = '';
if (data.permissions && data.permissions.manage_products) {
manageProductsLink = ` | <a href="{{ url_for('products.product_manager') }}" style="color: #6a4c93; text-decoration: none; font-weight: 500; cursor: pointer;"
manageProductsLink = ` | <a href="{{ url_for('products.product_list') }}" style="color: #6a4c93; text-decoration: none; font-weight: 500; cursor: pointer;"
onmouseover="this.style.textDecoration='underline'"
onmouseout="this.style.textDecoration='none'"
title="Manage Products">Manage Products</a>`;
title="Product Manager">Product Manager</a>`;
}
document.getElementById('userLocationInfo').innerHTML =
+630
View File
@@ -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>
+43 -2
View File
@@ -259,8 +259,9 @@
<body>
<div class="container">
<div class="nav-links">
<a href="/">← Back to Home</a>
<a href="{{ url_for('home') }}">← Back to Home</a>
<a href="/quiz/">Product Finder</a>
<a href="{{ url_for('products.product_list') }}">Product Manager</a>
</div>
<h1>Product Manager</h1>
@@ -756,7 +757,47 @@
}
// Initialize on page load
document.addEventListener('DOMContentLoaded', loadProductAttributes);
document.addEventListener('DOMContentLoaded', async () => {
await loadProductAttributes();
// Check if a product code was passed via URL parameter
const urlParams = new URLSearchParams(window.location.search);
const productCode = urlParams.get('product');
if (productCode) {
await loadProductByCode(productCode);
}
});
// Load a product by its code
async function loadProductByCode(productCode) {
try {
const response = await fetch(`/quiz/api/products/${encodeURIComponent(productCode)}`);
const data = await response.json();
if (data.status === 'success' && data.product) {
// Populate the form with the product data
const product = data.product;
// Fill in basic fields
document.getElementById('location').value = product.location || '';
document.getElementById('description').value = product.description || '';
document.getElementById('productCode').value = product.productCode || '';
document.getElementById('category').value = product.category || '';
// Set discontinued status
document.getElementById('discontinued').checked = product.discontinued || false;
// Note: You may need to add more field mappings based on your form structure
// This is a basic implementation to get started
console.log('Loaded product:', product);
} else {
console.error('Product not found:', productCode);
}
} catch (error) {
console.error('Error loading product:', error);
}
}
</script>
</body>
</html>