Main Access Updates
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user