Added more pagination options

This commit is contained in:
2025-09-21 18:18:26 +02:00
parent af53b29818
commit e1891e8bd6
3 changed files with 58 additions and 12 deletions
+8 -4
View File
@@ -37,14 +37,18 @@ CONFIG: Final[list[dict[str, Any]]] = [
{'n': 'HIDE_WISHES', 'c': bool},
{'n': 'MINIFIGURES_DEFAULT_ORDER', 'd': '"rebrickable_minifigures"."name" ASC'}, # noqa: E501
{'n': 'MINIFIGURES_FOLDER', 'd': 'minifigs', 's': True},
{'n': 'MINIFIGURES_PAGINATION_SIZE_DESKTOP', 'd': 10, 'c': int},
{'n': 'MINIFIGURES_PAGINATION_SIZE_MOBILE', 'd': 5, 'c': int},
{'n': 'MINIFIGURES_SERVER_SIDE_PAGINATION', 'c': bool},
{'n': 'NO_THREADED_SOCKET', 'c': bool},
{'n': 'SERVER_SIDE_PAGINATION', 'c': bool},
{'n': 'PARTS_SERVER_SIDE_PAGINATION', 'c': bool},
{'n': 'SETS_SERVER_SIDE_PAGINATION', 'c': bool},
{'n': 'PARTS_DEFAULT_ORDER', 'd': '"rebrickable_parts"."name" ASC, "rebrickable_parts"."color_name" ASC, "bricktracker_parts"."spare" ASC'}, # noqa: E501
{'n': 'PARTS_FOLDER', 'd': 'parts', 's': True},
{'n': 'PARTS_PAGINATION_SIZE_DESKTOP', 'd': 50, 'c': int},
{'n': 'PARTS_PAGINATION_SIZE_MOBILE', 'd': 25, 'c': int},
{'n': 'PARTS_PAGINATION_SIZE_DESKTOP', 'd': 10, 'c': int},
{'n': 'PARTS_PAGINATION_SIZE_MOBILE', 'd': 10, 'c': int},
{'n': 'SETS_PAGINATION_SIZE_DESKTOP', 'd': 12, 'c': int},
{'n': 'SETS_PAGINATION_SIZE_MOBILE', 'd': 8, 'c': int},
{'n': 'SETS_PAGINATION_SIZE_MOBILE', 'd': 4, 'c': int},
{'n': 'PORT', 'd': 3333, 'c': int},
{'n': 'PURCHASE_DATE_FORMAT', 'd': '%d/%m/%Y'},
{'n': 'PURCHASE_CURRENCY', 'd': ''},
+6 -8
View File
@@ -4,8 +4,9 @@ from typing import Any, Dict, Tuple
def get_pagination_config(entity_type: str) -> Tuple[int, bool]:
"""Get pagination configuration for an entity type (sets, parts, minifigures)"""
# Check if pagination is enabled
use_pagination = current_app.config.get('SERVER_SIDE_PAGINATION', False)
# Check if pagination is enabled for this specific entity type
pagination_key = f'{entity_type.upper()}_SERVER_SIDE_PAGINATION'
use_pagination = current_app.config.get(pagination_key, False)
if not use_pagination:
return 0, False
@@ -15,12 +16,9 @@ def get_pagination_config(entity_type: str) -> Tuple[int, bool]:
is_mobile = any(device in user_agent for device in ['mobile', 'android', 'iphone', 'ipad'])
# Get appropriate config keys based on entity type
if entity_type.upper() == 'SETS':
desktop_key = 'SETS_PAGINATION_SIZE_DESKTOP'
mobile_key = 'SETS_PAGINATION_SIZE_MOBILE'
else: # parts and minifigures use the same config
desktop_key = 'PARTS_PAGINATION_SIZE_DESKTOP'
mobile_key = 'PARTS_PAGINATION_SIZE_MOBILE'
entity_upper = entity_type.upper()
desktop_key = f'{entity_upper}_PAGINATION_SIZE_DESKTOP'
mobile_key = f'{entity_upper}_PAGINATION_SIZE_MOBILE'
per_page = current_app.config[mobile_key] if is_mobile else current_app.config[desktop_key]
+44
View File
@@ -6,8 +6,52 @@ function isPaginationMode() {
return gridElement && gridElement.getAttribute('data-grid') === 'false';
}
// Filter state management
function initializeFilterState() {
const filterElement = document.getElementById('grid-filter');
const filterToggleButton = document.querySelector('[data-bs-target="#grid-filter"]');
if (!filterElement || !filterToggleButton) return;
// Key for localStorage specific to sets page
const FILTER_STATE_KEY = 'sets-filter-state';
// Restore filter state on page load
const savedState = localStorage.getItem(FILTER_STATE_KEY);
if (savedState === 'open') {
// Override the template state and show the filter
filterElement.classList.add('show');
filterToggleButton.setAttribute('aria-expanded', 'true');
} else if (savedState === 'closed') {
// Explicitly hide if it was closed by user
filterElement.classList.remove('show');
filterToggleButton.setAttribute('aria-expanded', 'false');
}
// Listen for filter toggle events
filterElement.addEventListener('show.bs.collapse', () => {
localStorage.setItem(FILTER_STATE_KEY, 'open');
});
filterElement.addEventListener('hide.bs.collapse', () => {
localStorage.setItem(FILTER_STATE_KEY, 'closed');
});
// Clear state when leaving the page
window.addEventListener('beforeunload', () => {
// Only clear if user is navigating away from sets page
const currentPath = window.location.pathname;
if (!currentPath.includes('/sets')) {
localStorage.removeItem(FILTER_STATE_KEY);
}
});
}
// Setup page functionality
document.addEventListener("DOMContentLoaded", () => {
// Initialize filter state management
initializeFilterState();
const searchInput = document.getElementById('grid-search');
const searchClear = document.getElementById('grid-search-clear');