Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 87472039be | |||
| c1089c349f | |||
| 3f6af51a43 | |||
| bc3cc176ef | |||
| 4a1a265fa8 | |||
| 7c95583345 | |||
| 65f23c1f12 | |||
| aa6c969a6b | |||
| 0bff20215c | |||
| d0147b8061 | |||
| ca0de215ab | |||
| 05b259e494 | |||
| f03fd82be1 | |||
| a769e5464b | |||
| 40871a1c10 | |||
| caac283905 | |||
| 4bc0ef5cc4 | |||
| ec4f44a3ab | |||
| 0a29543939 | |||
| 74fe14f09b | |||
| 787624c432 | |||
| eddf4311d3 | |||
| 90c0c20d75 |
+40
-3
@@ -134,6 +134,10 @@
|
||||
# Default: false
|
||||
# BK_HIDE_TABLE_MISSING_PARTS=true
|
||||
|
||||
# Optional: Hide the 'Checked' column from the parts table.
|
||||
# Default: false
|
||||
# BK_HIDE_TABLE_CHECKED_PARTS=true
|
||||
|
||||
# Optional: Hide the 'Wishlist' entry from the menu. Does not disable the route.
|
||||
# Default: false
|
||||
# BK_HIDE_WISHES=true
|
||||
@@ -262,9 +266,36 @@
|
||||
# Default: https://rebrickable.com/instructions/{path}
|
||||
# BK_REBRICKABLE_LINK_INSTRUCTIONS_PATTERN=
|
||||
|
||||
# Optional: User-Agent to use when querying Rebrickable outside of the Rebrick python library
|
||||
# Default: 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||
# BK_REBRICKABLE_USER_AGENT=
|
||||
# Optional: User-Agent to use when querying Rebrickable and Peeron outside of the Rebrick python library
|
||||
# Default: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36
|
||||
# BK_USER_AGENT=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36
|
||||
|
||||
# Legacy: User-Agent for Rebrickable (use BK_USER_AGENT instead)
|
||||
# BK_REBRICKABLE_USER_AGENT=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36
|
||||
|
||||
# Optional: Delay in milliseconds between Peeron page downloads to avoid being potentially blocked
|
||||
# Default: 1000
|
||||
# BK_PEERON_DOWNLOAD_DELAY=1000
|
||||
|
||||
# Optional: Minimum image size (width/height) for valid Peeron instruction pages
|
||||
# Images smaller than this are considered error placeholders and will be rejected
|
||||
# Default: 100
|
||||
# BK_PEERON_MIN_IMAGE_SIZE=100
|
||||
|
||||
# Optional: Pattern for Peeron instruction page URLs. Will be passed to Python .format()
|
||||
# Supports {set_number} and {version_number} parameters
|
||||
# Default: http://peeron.com/scans/{set_number}-{version_number}
|
||||
# BK_PEERON_INSTRUCTION_PATTERN=
|
||||
|
||||
# Optional: Pattern for Peeron thumbnail URLs. Will be passed to Python .format()
|
||||
# Supports {set_number} and {version_number} parameters
|
||||
# Default: http://belay.peeron.com/thumbs/{set_number}-{version_number}/
|
||||
# BK_PEERON_THUMBNAIL_PATTERN=
|
||||
|
||||
# Optional: Pattern for Peeron scan URLs. Will be passed to Python .format()
|
||||
# Supports {set_number} and {version_number} parameters
|
||||
# Default: http://belay.peeron.com/scans/{set_number}-{version_number}/
|
||||
# BK_PEERON_SCAN_PATTERN=
|
||||
|
||||
# Optional: Display Rebrickable links wherever applicable
|
||||
# Default: false
|
||||
@@ -301,6 +332,12 @@
|
||||
# Default: sets
|
||||
# BK_SETS_FOLDER=sets
|
||||
|
||||
# Optional: Enable set consolidation/grouping on the main sets page
|
||||
# When enabled, multiple copies of the same set are grouped together showing instance count
|
||||
# When disabled, each set copy is displayed individually (original behavior)
|
||||
# Default: false
|
||||
# BK_SETS_CONSOLIDATION=true
|
||||
|
||||
# Optional: Make the grid filters displayed by default, rather than collapsed
|
||||
# Default: false
|
||||
# BK_SHOW_GRID_FILTERS=true
|
||||
|
||||
+23
-1
@@ -23,7 +23,29 @@
|
||||
- Preserves selection state during dropdown consolidation
|
||||
- Consistent search behavior (instant for client-side, Enter key for server-side)
|
||||
- Mobile-friendly pagination navigation
|
||||
|
||||
- Add Peeron instructions integration
|
||||
- Full image caching system with automatic thumbnail generation
|
||||
- Optimized HTTP calls by downloading full images once and generating thumbnails locally
|
||||
- Automatic cache cleanup after PDF generation to save disk space
|
||||
- Add parts checking/inventory system
|
||||
- New "Checked" column in parts tables for tracking inventory progress
|
||||
- Checkboxes to mark parts as verified during set walkthrough
|
||||
- `BK_HIDE_TABLE_CHECKED_PARTS`: Environment variable to hide checked column
|
||||
- Add set consolidation/grouping functionality
|
||||
- Automatic grouping of duplicate sets on main sets page
|
||||
- Shows instance count with stack icon badge (e.g., "3 copies")
|
||||
- Expandable drawer interface to view all set copies individually
|
||||
- Full set cards for each instance with all badges, statuses, and functionality
|
||||
- `BK_SETS_CONSOLIDATION`: Environment variable to enable/disable consolidation (default: false)
|
||||
- Backwards compatible - when disabled, behaves exactly like original individual view
|
||||
- Improved theme filtering: handles duplicate theme names correctly
|
||||
- Fixed set number sorting: proper numeric sorting in both ascending and descending order
|
||||
- Mixed status indicators for consolidated sets: three-state checkboxes (unchecked/partial/checked) with count badges
|
||||
- Enhanced SQL aggregation with `IFNULL(SUM())` for accurate count statistics
|
||||
- Template logic handles three states: none (0/2), all (2/2), partial (1/2) with visual indicators
|
||||
- Purple overlay styling for partial states, disabled checkboxes for read-only consolidated status display
|
||||
- Individual sets maintain full interactive checkbox functionality
|
||||
|
||||
### 1.2.4
|
||||
|
||||
> **Warning**
|
||||
|
||||
+2
-1
@@ -60,7 +60,8 @@ def setup_app(app: Flask) -> None:
|
||||
# Setup the login manager
|
||||
LoginManager(app)
|
||||
|
||||
# I don't know :-)
|
||||
# Configure proxy header handling for reverse proxy deployments (nginx, Apache, etc.)
|
||||
# This ensures proper client IP detection and HTTPS scheme recognition
|
||||
app.wsgi_app = ProxyFix(
|
||||
app.wsgi_app,
|
||||
x_for=1,
|
||||
|
||||
@@ -34,6 +34,7 @@ CONFIG: Final[list[dict[str, Any]]] = [
|
||||
{'n': 'HIDE_SET_INSTRUCTIONS', 'c': bool},
|
||||
{'n': 'HIDE_TABLE_DAMAGED_PARTS', 'c': bool},
|
||||
{'n': 'HIDE_TABLE_MISSING_PARTS', 'c': bool},
|
||||
{'n': 'HIDE_TABLE_CHECKED_PARTS', 'c': bool},
|
||||
{'n': 'HIDE_WISHES', 'c': bool},
|
||||
{'n': 'MINIFIGURES_DEFAULT_ORDER', 'd': '"rebrickable_minifigures"."name" ASC'}, # noqa: E501
|
||||
{'n': 'MINIFIGURES_FOLDER', 'd': 'minifigs', 's': True},
|
||||
@@ -76,6 +77,7 @@ CONFIG: Final[list[dict[str, Any]]] = [
|
||||
{'n': 'RETIRED_SETS_PATH', 'd': './retired_sets.csv'},
|
||||
{'n': 'SETS_DEFAULT_ORDER', 'd': '"rebrickable_sets"."number" DESC, "rebrickable_sets"."version" ASC'}, # noqa: E501
|
||||
{'n': 'SETS_FOLDER', 'd': 'sets', 's': True},
|
||||
{'n': 'SETS_CONSOLIDATION', 'd': False, 'c': bool},
|
||||
{'n': 'SHOW_GRID_FILTERS', 'c': bool},
|
||||
{'n': 'SHOW_GRID_SORT', 'c': bool},
|
||||
{'n': 'SKIP_SPARE_PARTS', 'c': bool},
|
||||
|
||||
@@ -101,8 +101,9 @@ class BrickInstructions(object):
|
||||
|
||||
# Skip if we already have it
|
||||
if os.path.isfile(target):
|
||||
pdf_url = self.url()
|
||||
return self.socket.complete(
|
||||
message=f"File {self.filename} already exists, skipped"
|
||||
message=f'File {self.filename} already exists, skipped - <a href="{pdf_url}" target="_blank" class="btn btn-sm btn-primary ms-2"><i class="ri-external-link-line"></i> Open PDF</a>'
|
||||
)
|
||||
|
||||
# Fetch PDF via cloudscraper (to bypass Cloudflare)
|
||||
@@ -141,8 +142,9 @@ class BrickInstructions(object):
|
||||
|
||||
# Done!
|
||||
logger.info(f"Downloaded {self.filename}")
|
||||
pdf_url = self.url()
|
||||
self.socket.complete(
|
||||
message=f"File {self.filename} downloaded ({self.human_size()})"
|
||||
message=f'File {self.filename} downloaded ({self.human_size()}) - <a href="{pdf_url}" target="_blank" class="btn btn-sm btn-primary ms-2"><i class="ri-external-link-line"></i> Open PDF</a>'
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -111,6 +111,16 @@ class BrickMetadataList(BrickRecordList[T]):
|
||||
in new.filter(**kwargs)
|
||||
])
|
||||
|
||||
# Return the items as a dictionary mapping column names to UUIDs
|
||||
@classmethod
|
||||
def as_column_mapping(cls, /, **kwargs) -> dict:
|
||||
new = cls.new()
|
||||
|
||||
return {
|
||||
record.as_column(): record.fields.id
|
||||
for record in new.filter(**kwargs)
|
||||
}
|
||||
|
||||
# Grab a specific status
|
||||
@classmethod
|
||||
def get(cls, id: str | None, /, *, allow_none: bool = False) -> T:
|
||||
|
||||
@@ -159,6 +159,43 @@ class BrickPart(RebrickablePart):
|
||||
|
||||
return self
|
||||
|
||||
# Update checked state for part walkthrough
|
||||
def update_checked(self, json: Any | None, /) -> bool:
|
||||
# Handle both direct 'checked' key and changer.js 'value' key format
|
||||
if json:
|
||||
checked = json.get('checked', json.get('value', False))
|
||||
else:
|
||||
checked = False
|
||||
|
||||
checked = bool(checked)
|
||||
|
||||
# Update the field
|
||||
self.fields.checked = checked
|
||||
|
||||
BrickSQL().execute_and_commit(
|
||||
'part/update/checked',
|
||||
parameters=self.sql_parameters()
|
||||
)
|
||||
|
||||
return checked
|
||||
|
||||
# Compute the url for updating checked state
|
||||
def url_for_checked(self, /) -> str:
|
||||
# Different URL for a minifigure part
|
||||
if self.minifigure is not None:
|
||||
figure = self.minifigure.fields.figure
|
||||
else:
|
||||
figure = None
|
||||
|
||||
return url_for(
|
||||
'set.checked_part',
|
||||
id=self.fields.id,
|
||||
figure=figure,
|
||||
part=self.fields.part,
|
||||
color=self.fields.color,
|
||||
spare=self.fields.spare,
|
||||
)
|
||||
|
||||
# Update a problematic part
|
||||
def update_problem(self, problem: str, json: Any | None, /) -> int:
|
||||
amount: str | int = json.get('value', '') # type: ignore
|
||||
|
||||
@@ -0,0 +1,437 @@
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
import time
|
||||
from typing import Any, NamedTuple, TYPE_CHECKING
|
||||
from urllib.parse import urljoin
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import cloudscraper
|
||||
from flask import current_app, url_for
|
||||
import requests
|
||||
|
||||
from .exceptions import ErrorException
|
||||
if TYPE_CHECKING:
|
||||
from .socket import BrickSocket
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_peeron_user_agent():
|
||||
"""Get the User-Agent string for Peeron requests from config"""
|
||||
return current_app.config.get('REBRICKABLE_USER_AGENT',
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36')
|
||||
|
||||
|
||||
def get_peeron_download_delay():
|
||||
"""Get the delay in milliseconds between Peeron page downloads from config"""
|
||||
return current_app.config.get('PEERON_DOWNLOAD_DELAY', 1000)
|
||||
|
||||
|
||||
def get_min_image_size():
|
||||
"""Get the minimum image size for valid Peeron instruction pages from config"""
|
||||
return current_app.config.get('PEERON_MIN_IMAGE_SIZE', 100)
|
||||
|
||||
|
||||
def get_peeron_instruction_url(set_number: str, version_number: str):
|
||||
"""Get the Peeron instruction page URL using the configured pattern"""
|
||||
pattern = current_app.config.get('PEERON_INSTRUCTION_PATTERN', 'http://peeron.com/scans/{set_number}-{version_number}')
|
||||
return pattern.format(set_number=set_number, version_number=version_number)
|
||||
|
||||
|
||||
def get_peeron_thumbnail_url(set_number: str, version_number: str):
|
||||
"""Get the Peeron thumbnail base URL using the configured pattern"""
|
||||
pattern = current_app.config.get('PEERON_THUMBNAIL_PATTERN', 'http://belay.peeron.com/thumbs/{set_number}-{version_number}/')
|
||||
return pattern.format(set_number=set_number, version_number=version_number)
|
||||
|
||||
|
||||
def get_peeron_scan_url(set_number: str, version_number: str):
|
||||
"""Get the Peeron scan base URL using the configured pattern"""
|
||||
pattern = current_app.config.get('PEERON_SCAN_PATTERN', 'http://belay.peeron.com/scans/{set_number}-{version_number}/')
|
||||
return pattern.format(set_number=set_number, version_number=version_number)
|
||||
|
||||
|
||||
def create_peeron_scraper():
|
||||
"""Create a cloudscraper instance configured for Peeron"""
|
||||
scraper = cloudscraper.create_scraper()
|
||||
scraper.headers.update({
|
||||
"User-Agent": get_peeron_user_agent()
|
||||
})
|
||||
return scraper
|
||||
|
||||
|
||||
def get_peeron_cache_dir():
|
||||
"""Get the base directory for Peeron caching"""
|
||||
static_dir = Path(current_app.static_folder)
|
||||
cache_dir = static_dir / 'images' / 'peeron_cache'
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
return cache_dir
|
||||
|
||||
|
||||
def get_set_cache_dir(set_number: str, version_number: str) -> tuple[Path, Path]:
|
||||
"""Get cache directories for a specific set"""
|
||||
base_cache_dir = get_peeron_cache_dir()
|
||||
set_cache_key = f"{set_number}-{version_number}"
|
||||
|
||||
full_cache_dir = base_cache_dir / 'full' / set_cache_key
|
||||
thumb_cache_dir = base_cache_dir / 'thumbs' / set_cache_key
|
||||
|
||||
full_cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
thumb_cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
return full_cache_dir, thumb_cache_dir
|
||||
|
||||
|
||||
def cache_full_image_and_generate_thumbnail(image_url: str, page_number: str, set_number: str, version_number: str, session=None) -> tuple[str | None, str | None]:
|
||||
"""
|
||||
Download and cache full-size image, then generate a thumbnail preview.
|
||||
Uses the full-size scan URLs from Peeron.
|
||||
Returns (cached_image_path, thumbnail_url) or (None, None) if caching fails.
|
||||
"""
|
||||
try:
|
||||
full_cache_dir, thumb_cache_dir = get_set_cache_dir(set_number, version_number)
|
||||
|
||||
full_filename = f"{page_number}.jpg"
|
||||
thumb_filename = f"{page_number}.jpg"
|
||||
full_cache_path = full_cache_dir / full_filename
|
||||
thumb_cache_path = thumb_cache_dir / thumb_filename
|
||||
|
||||
# Return existing cached files if they exist
|
||||
if full_cache_path.exists() and thumb_cache_path.exists():
|
||||
set_cache_key = f"{set_number}-{version_number}"
|
||||
thumbnail_url = url_for('static', filename=f'images/peeron_cache/thumbs/{set_cache_key}/{thumb_filename}')
|
||||
return str(full_cache_path), thumbnail_url
|
||||
|
||||
# Download the full-size image using provided session or create new one
|
||||
if session is None:
|
||||
session = create_peeron_scraper()
|
||||
response = session.get(image_url, timeout=30)
|
||||
|
||||
if response.status_code == 200 and len(response.content) > 0:
|
||||
# Validate it's actually an image by checking minimum size
|
||||
min_size = get_min_image_size()
|
||||
if len(response.content) < min_size:
|
||||
logger.warning(f"Image too small, skipping cache: {image_url}")
|
||||
return None, None
|
||||
|
||||
# Write full-size image to cache
|
||||
with open(full_cache_path, 'wb') as f:
|
||||
f.write(response.content)
|
||||
|
||||
logger.debug(f"Cached full image: {image_url} -> {full_cache_path}")
|
||||
|
||||
# Generate thumbnail from the cached full image
|
||||
try:
|
||||
from PIL import Image
|
||||
with Image.open(full_cache_path) as img:
|
||||
# Create thumbnail (max 150px on longest side to match template)
|
||||
img.thumbnail((150, 150), Image.Resampling.LANCZOS)
|
||||
img.save(thumb_cache_path, 'JPEG', quality=85)
|
||||
|
||||
logger.debug(f"Generated thumbnail: {full_cache_path} -> {thumb_cache_path}")
|
||||
|
||||
set_cache_key = f"{set_number}-{version_number}"
|
||||
thumbnail_url = url_for('static', filename=f'images/peeron_cache/thumbs/{set_cache_key}/{thumb_filename}')
|
||||
return str(full_cache_path), thumbnail_url
|
||||
|
||||
except Exception as thumb_error:
|
||||
logger.error(f"Failed to generate thumbnail for {page_number}: {thumb_error}")
|
||||
# Clean up the full image if thumbnail generation failed
|
||||
if full_cache_path.exists():
|
||||
full_cache_path.unlink()
|
||||
return None, None
|
||||
else:
|
||||
logger.warning(f"Failed to download full image: {image_url}")
|
||||
return None, None
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error caching full image {image_url}: {e}")
|
||||
return None, None
|
||||
|
||||
|
||||
def clear_set_cache(set_number: str, version_number: str) -> int:
|
||||
"""
|
||||
Clear all cached files for a specific set after PDF generation.
|
||||
Returns the number of files deleted.
|
||||
"""
|
||||
try:
|
||||
full_cache_dir, thumb_cache_dir = get_set_cache_dir(set_number, version_number)
|
||||
deleted_count = 0
|
||||
|
||||
# Delete full images
|
||||
if full_cache_dir.exists():
|
||||
for cache_file in full_cache_dir.glob('*.jpg'):
|
||||
try:
|
||||
cache_file.unlink()
|
||||
deleted_count += 1
|
||||
logger.debug(f"Deleted cached full image: {cache_file}")
|
||||
except OSError as e:
|
||||
logger.warning(f"Failed to delete cache file {cache_file}: {e}")
|
||||
|
||||
# Remove directory if empty
|
||||
try:
|
||||
full_cache_dir.rmdir()
|
||||
except OSError:
|
||||
pass # Directory not empty or other error
|
||||
|
||||
# Delete thumbnails
|
||||
if thumb_cache_dir.exists():
|
||||
for cache_file in thumb_cache_dir.glob('*.jpg'):
|
||||
try:
|
||||
cache_file.unlink()
|
||||
deleted_count += 1
|
||||
logger.debug(f"Deleted cached thumbnail: {cache_file}")
|
||||
except OSError as e:
|
||||
logger.warning(f"Failed to delete cache file {cache_file}: {e}")
|
||||
|
||||
# Remove directory if empty
|
||||
try:
|
||||
thumb_cache_dir.rmdir()
|
||||
except OSError:
|
||||
pass # Directory not empty or other error
|
||||
|
||||
# Try to remove set directory if empty
|
||||
try:
|
||||
set_cache_key = f"{set_number}-{version_number}"
|
||||
full_cache_dir.parent.rmdir() if full_cache_dir.parent.name == set_cache_key else None
|
||||
thumb_cache_dir.parent.rmdir() if thumb_cache_dir.parent.name == set_cache_key else None
|
||||
except OSError:
|
||||
pass # Directory not empty or other error
|
||||
|
||||
logger.info(f"Set cache cleanup completed for {set_number}-{version_number}: {deleted_count} files deleted")
|
||||
return deleted_count
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error during set cache cleanup for {set_number}-{version_number}: {e}")
|
||||
return 0
|
||||
|
||||
|
||||
def clear_old_cache(max_age_days: int = 7) -> int:
|
||||
"""
|
||||
Clear old cache files across all sets.
|
||||
Returns the number of files deleted.
|
||||
"""
|
||||
try:
|
||||
base_cache_dir = get_peeron_cache_dir()
|
||||
if not base_cache_dir.exists():
|
||||
return 0
|
||||
|
||||
deleted_count = 0
|
||||
max_age_seconds = max_age_days * 24 * 60 * 60
|
||||
current_time = time.time()
|
||||
|
||||
# Clean both full and thumbs directories
|
||||
for cache_type in ['full', 'thumbs']:
|
||||
cache_type_dir = base_cache_dir / cache_type
|
||||
if cache_type_dir.exists():
|
||||
for set_dir in cache_type_dir.iterdir():
|
||||
if set_dir.is_dir():
|
||||
for cache_file in set_dir.glob('*.jpg'):
|
||||
file_age = current_time - os.path.getmtime(cache_file)
|
||||
if file_age > max_age_seconds:
|
||||
try:
|
||||
cache_file.unlink()
|
||||
deleted_count += 1
|
||||
logger.debug(f"Deleted old cache file: {cache_file}")
|
||||
except OSError as e:
|
||||
logger.warning(f"Failed to delete cache file {cache_file}: {e}")
|
||||
|
||||
# Remove empty directories
|
||||
try:
|
||||
if not any(set_dir.iterdir()):
|
||||
set_dir.rmdir()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
logger.info(f"Old cache cleanup completed: {deleted_count} files deleted")
|
||||
return deleted_count
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error during old cache cleanup: {e}")
|
||||
return 0
|
||||
|
||||
|
||||
class PeeronPage(NamedTuple):
|
||||
"""Represents a single instruction page from Peeron"""
|
||||
page_number: str
|
||||
original_image_url: str # Original Peeron full-size image URL
|
||||
cached_full_image_path: str # Local full-size cached image path
|
||||
cached_thumbnail_url: str # Local thumbnail URL for preview
|
||||
alt_text: str
|
||||
rotation: int = 0 # Rotation in degrees (0, 90, 180, 270)
|
||||
|
||||
|
||||
# Peeron instruction scraper
|
||||
class PeeronInstructions(object):
|
||||
socket: 'BrickSocket | None'
|
||||
set_number: str
|
||||
version_number: str
|
||||
pages: list[PeeronPage]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
set_number: str,
|
||||
version_number: str = '1',
|
||||
/,
|
||||
*,
|
||||
socket: 'BrickSocket | None' = None,
|
||||
):
|
||||
# Save the socket
|
||||
self.socket = socket
|
||||
|
||||
# Parse set number (handle both "4011" and "4011-1" formats)
|
||||
if '-' in set_number:
|
||||
parts = set_number.split('-', 1)
|
||||
self.set_number = parts[0]
|
||||
self.version_number = parts[1] if len(parts) > 1 else '1'
|
||||
else:
|
||||
self.set_number = set_number
|
||||
self.version_number = version_number
|
||||
|
||||
# Placeholder for pages
|
||||
self.pages = []
|
||||
|
||||
# Check if instructions exist on Peeron (lightweight)
|
||||
def exists(self, /) -> bool:
|
||||
"""Check if the set exists on Peeron without caching thumbnails"""
|
||||
try:
|
||||
base_url = get_peeron_instruction_url(self.set_number, self.version_number)
|
||||
scraper = create_peeron_scraper()
|
||||
response = scraper.get(base_url)
|
||||
|
||||
if response.status_code != 200:
|
||||
return False
|
||||
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
|
||||
# Check for "Browse instruction library" header (set not found)
|
||||
if soup.find('h1', string="Browse instruction library"):
|
||||
return False
|
||||
|
||||
# Look for thumbnail images to confirm instructions exist
|
||||
thumbnails = soup.select('table[cellspacing="5"] a img[src^="http://belay.peeron.com/thumbs/"]')
|
||||
return len(thumbnails) > 0
|
||||
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
# Find all available instruction pages on Peeron
|
||||
def find_pages(self, /) -> list[PeeronPage]:
|
||||
"""
|
||||
Scrape Peeron's HTML and return a list of available instruction pages.
|
||||
Similar to BrickInstructions.find_instructions() but for Peeron.
|
||||
"""
|
||||
base_url = get_peeron_instruction_url(self.set_number, self.version_number)
|
||||
thumb_base_url = get_peeron_thumbnail_url(self.set_number, self.version_number)
|
||||
scan_base_url = get_peeron_scan_url(self.set_number, self.version_number)
|
||||
|
||||
logger.debug(f"[find_pages] fetching HTML from {base_url!r}")
|
||||
|
||||
# Set up session with persistent cookies for Peeron (like working dl_peeron.py)
|
||||
scraper = create_peeron_scraper()
|
||||
|
||||
# Download the main HTML page to establish session and cookies
|
||||
try:
|
||||
logger.debug(f"[find_pages] Establishing session by visiting: {base_url}")
|
||||
response = scraper.get(base_url)
|
||||
logger.debug(f"[find_pages] Main page visit: HTTP {response.status_code}")
|
||||
if response.status_code != 200:
|
||||
raise ErrorException(f'Failed to load Peeron page for {self.set_number}-{self.version_number}. HTTP {response.status_code}')
|
||||
except requests.exceptions.RequestException as e:
|
||||
raise ErrorException(f'Failed to connect to Peeron: {e}')
|
||||
|
||||
# Parse HTML to locate instruction pages
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
|
||||
# Check for "Browse instruction library" header (set not found)
|
||||
if soup.find('h1', string="Browse instruction library"):
|
||||
raise ErrorException(f'Set {self.set_number}-{self.version_number} not found on Peeron')
|
||||
|
||||
# Locate all thumbnail images in the expected table structure
|
||||
# Use the configured thumbnail pattern to build the expected URL prefix
|
||||
thumb_base_url = get_peeron_thumbnail_url(self.set_number, self.version_number)
|
||||
thumbnails = soup.select(f'table[cellspacing="5"] a img[src^="{thumb_base_url}"]')
|
||||
|
||||
if not thumbnails:
|
||||
raise ErrorException(f'No instruction pages found for {self.set_number}-{self.version_number} on Peeron')
|
||||
|
||||
pages: list[PeeronPage] = []
|
||||
total_thumbnails = len(thumbnails)
|
||||
|
||||
# Initialize progress if socket is available
|
||||
if self.socket:
|
||||
self.socket.progress_total = total_thumbnails
|
||||
self.socket.progress_count = 0
|
||||
self.socket.progress(message=f"Starting to cache {total_thumbnails} full images")
|
||||
|
||||
for idx, img in enumerate(thumbnails, 1):
|
||||
thumb_url = img['src']
|
||||
|
||||
# Extract the page number from the thumbnail URL
|
||||
page_number = thumb_url.split('/')[-2]
|
||||
|
||||
# Build the full-size scan URL using the page number
|
||||
full_size_url = f"{scan_base_url}{page_number}/"
|
||||
|
||||
logger.debug(f"[find_pages] Page {page_number}: thumb={thumb_url}, full_size={full_size_url}")
|
||||
|
||||
# Create alt text for the page
|
||||
alt_text = f"LEGO Instructions {self.set_number}-{self.version_number} Page {page_number}"
|
||||
|
||||
# Report progress if socket is available
|
||||
if self.socket:
|
||||
self.socket.progress_count = idx
|
||||
self.socket.progress(message=f"Caching full image {idx} of {total_thumbnails}")
|
||||
|
||||
# Cache the full-size image and generate thumbnail preview using established session
|
||||
cached_full_path, cached_thumb_url = cache_full_image_and_generate_thumbnail(
|
||||
full_size_url, page_number, self.set_number, self.version_number, session=scraper
|
||||
)
|
||||
|
||||
# Skip this page if caching failed
|
||||
if not cached_full_path or not cached_thumb_url:
|
||||
logger.warning(f"[find_pages] Skipping page {page_number} due to caching failure")
|
||||
continue
|
||||
|
||||
page = PeeronPage(
|
||||
page_number=page_number,
|
||||
original_image_url=full_size_url,
|
||||
cached_full_image_path=cached_full_path,
|
||||
cached_thumbnail_url=cached_thumb_url,
|
||||
alt_text=alt_text
|
||||
)
|
||||
pages.append(page)
|
||||
|
||||
# Cache the pages for later use
|
||||
self.pages = pages
|
||||
|
||||
logger.debug(f"[find_pages] found {len(pages)} pages for {self.set_number}-{self.version_number}")
|
||||
return pages
|
||||
|
||||
# Find instructions with fallback to Peeron
|
||||
@staticmethod
|
||||
def find_instructions_with_peeron_fallback(set: str, /) -> tuple[list[tuple[str, str]], list[PeeronPage] | None]:
|
||||
"""
|
||||
Enhanced version of BrickInstructions.find_instructions() that falls back to Peeron.
|
||||
Returns (rebrickable_instructions, peeron_pages).
|
||||
If rebrickable_instructions is empty, peeron_pages will contain Peeron data.
|
||||
"""
|
||||
from .instructions import BrickInstructions
|
||||
|
||||
# First try Rebrickable
|
||||
try:
|
||||
rebrickable_instructions = BrickInstructions.find_instructions(set)
|
||||
return rebrickable_instructions, None
|
||||
except ErrorException as e:
|
||||
logger.info(f"Rebrickable failed for {set}: {e}. Trying Peeron fallback...")
|
||||
|
||||
# Fallback to Peeron
|
||||
try:
|
||||
peeron = PeeronInstructions(set)
|
||||
peeron_pages = peeron.find_pages()
|
||||
return [], peeron_pages
|
||||
except ErrorException as peeron_error:
|
||||
# Both failed, re-raise original Rebrickable error
|
||||
logger.info(f"Peeron also failed for {set}: {peeron_error}")
|
||||
raise e from peeron_error
|
||||
@@ -0,0 +1,200 @@
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
import time
|
||||
from typing import Any, TYPE_CHECKING
|
||||
|
||||
import cloudscraper
|
||||
from flask import current_app
|
||||
from PIL import Image
|
||||
|
||||
from .exceptions import DownloadException, ErrorException
|
||||
from .instructions import BrickInstructions
|
||||
from .peeron_instructions import PeeronPage, get_min_image_size, get_peeron_download_delay, get_peeron_instruction_url, create_peeron_scraper
|
||||
if TYPE_CHECKING:
|
||||
from .socket import BrickSocket
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# PDF generator for Peeron instruction pages
|
||||
class PeeronPDF(object):
|
||||
socket: 'BrickSocket'
|
||||
set_number: str
|
||||
version_number: str
|
||||
pages: list[PeeronPage]
|
||||
filename: str
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
set_number: str,
|
||||
version_number: str,
|
||||
pages: list[PeeronPage],
|
||||
/,
|
||||
*,
|
||||
socket: 'BrickSocket',
|
||||
):
|
||||
# Save the socket
|
||||
self.socket = socket
|
||||
|
||||
# Save set information
|
||||
self.set_number = set_number
|
||||
self.version_number = version_number
|
||||
self.pages = pages
|
||||
|
||||
# Generate filename following BrickTracker conventions
|
||||
self.filename = f"{set_number}-{version_number}_peeron.pdf"
|
||||
|
||||
# Download pages and create PDF
|
||||
def create_pdf(self, /) -> None:
|
||||
"""
|
||||
Downloads selected Peeron pages and merges them into a PDF.
|
||||
Uses progress updates via socket similar to BrickInstructions.download()
|
||||
"""
|
||||
try:
|
||||
target_path = self._get_target_path()
|
||||
|
||||
# Skip if we already have it
|
||||
if os.path.isfile(target_path):
|
||||
# Create BrickInstructions instance to get PDF URL
|
||||
instructions = BrickInstructions(self.filename)
|
||||
pdf_url = instructions.url()
|
||||
return self.socket.complete(
|
||||
message=f'File {self.filename} already exists, skipped - <a href="{pdf_url}" target="_blank" class="btn btn-sm btn-primary ms-2"><i class="ri-external-link-line"></i> Open PDF</a>'
|
||||
)
|
||||
|
||||
# Set up progress tracking
|
||||
total_pages = len(self.pages)
|
||||
self.socket.update_total(total_pages)
|
||||
self.socket.progress_count = 0
|
||||
self.socket.progress(message=f"Starting PDF creation from {total_pages} cached pages")
|
||||
|
||||
# Use cached images directly - no downloads needed!
|
||||
cached_files_with_rotation = []
|
||||
missing_pages = []
|
||||
|
||||
for i, page in enumerate(self.pages):
|
||||
# Check if cached file exists
|
||||
if os.path.isfile(page.cached_full_image_path):
|
||||
cached_files_with_rotation.append((page.cached_full_image_path, page.rotation))
|
||||
|
||||
# Update progress
|
||||
self.socket.progress_count += 1
|
||||
self.socket.progress(
|
||||
message=f"Processing cached page {page.page_number} ({i + 1}/{total_pages})"
|
||||
)
|
||||
else:
|
||||
missing_pages.append(page.page_number)
|
||||
logger.warning(f"Cached image missing for page {page.page_number}: {page.cached_full_image_path}")
|
||||
|
||||
if not cached_files_with_rotation:
|
||||
raise DownloadException(f"No cached images available for set {self.set_number}-{self.version_number}. Cache may have been cleared.")
|
||||
|
||||
elif len(cached_files_with_rotation) < total_pages:
|
||||
# Partial success
|
||||
error_msg = f"Only found {len(cached_files_with_rotation)}/{total_pages} cached images."
|
||||
if missing_pages:
|
||||
error_msg += f" Missing pages: {', '.join(missing_pages)}."
|
||||
logger.warning(error_msg)
|
||||
|
||||
# Create PDF from cached images with rotation
|
||||
self._create_pdf_from_images(cached_files_with_rotation, target_path)
|
||||
|
||||
# Success
|
||||
logger.info(f"Created PDF {self.filename} with {len(cached_files_with_rotation)} pages")
|
||||
|
||||
# Create BrickInstructions instance to get PDF URL
|
||||
instructions = BrickInstructions(self.filename)
|
||||
pdf_url = instructions.url()
|
||||
|
||||
self.socket.complete(
|
||||
message=f'PDF {self.filename} created with {len(cached_files_with_rotation)} pages - <a href="{pdf_url}" target="_blank" class="btn btn-sm btn-primary ms-2"><i class="ri-external-link-line"></i> Open PDF</a>'
|
||||
)
|
||||
|
||||
# Clean up set cache after successful PDF creation
|
||||
try:
|
||||
from .peeron_instructions import clear_set_cache
|
||||
deleted_count = clear_set_cache(self.set_number, self.version_number)
|
||||
if deleted_count > 0:
|
||||
logger.info(f"[create_pdf] Cleaned up {deleted_count} cache files for set {self.set_number}-{self.version_number}")
|
||||
except Exception as e:
|
||||
logger.warning(f"[create_pdf] Failed to clean set cache: {e}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error creating PDF {self.filename}: {e}")
|
||||
self.socket.fail(
|
||||
message=f"Error creating PDF {self.filename}: {e}"
|
||||
)
|
||||
|
||||
|
||||
# Create PDF from downloaded images
|
||||
def _create_pdf_from_images(self, image_paths_and_rotations: list[tuple[str, int]], output_path: str, /) -> None:
|
||||
"""Create a PDF from a list of image files with their rotations"""
|
||||
try:
|
||||
# Import FPDF (should be available from requirements)
|
||||
from fpdf import FPDF
|
||||
except ImportError:
|
||||
raise ErrorException("FPDF library not available. Install with: pip install fpdf2")
|
||||
|
||||
pdf = FPDF()
|
||||
|
||||
for i, (img_path, rotation) in enumerate(image_paths_and_rotations):
|
||||
try:
|
||||
# Open image and apply rotation if needed
|
||||
with Image.open(img_path) as image:
|
||||
# Apply rotation if specified
|
||||
if rotation != 0:
|
||||
# PIL rotation is counter-clockwise, so we negate for clockwise rotation
|
||||
image = image.rotate(-rotation, expand=True)
|
||||
|
||||
width, height = image.size
|
||||
|
||||
# Add page with image dimensions (convert pixels to mm)
|
||||
# 1 pixel = 0.264583 mm (assuming 96 DPI)
|
||||
page_width = width * 0.264583
|
||||
page_height = height * 0.264583
|
||||
|
||||
pdf.add_page(format=(page_width, page_height))
|
||||
|
||||
# Save rotated image to temporary file for FPDF
|
||||
temp_rotated_path = None
|
||||
if rotation != 0:
|
||||
import tempfile
|
||||
temp_fd, temp_rotated_path = tempfile.mkstemp(suffix='.jpg', prefix=f'peeron_rotated_{i}_')
|
||||
try:
|
||||
os.close(temp_fd) # Close file descriptor, we'll use the path
|
||||
image.save(temp_rotated_path, 'JPEG', quality=95)
|
||||
pdf.image(temp_rotated_path, x=0, y=0, w=page_width, h=page_height)
|
||||
finally:
|
||||
# Clean up rotated temp file
|
||||
if temp_rotated_path and os.path.exists(temp_rotated_path):
|
||||
os.remove(temp_rotated_path)
|
||||
else:
|
||||
pdf.image(img_path, x=0, y=0, w=page_width, h=page_height)
|
||||
|
||||
# Update progress
|
||||
progress_msg = f"Processing page {i + 1}/{len(image_paths_and_rotations)} into PDF"
|
||||
if rotation != 0:
|
||||
progress_msg += f" (rotated {rotation}°)"
|
||||
self.socket.progress(message=progress_msg)
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to add image {img_path} to PDF: {e}")
|
||||
continue
|
||||
|
||||
# Save the PDF
|
||||
pdf.output(output_path)
|
||||
|
||||
# Get target file path
|
||||
def _get_target_path(self, /) -> str:
|
||||
"""Get the full path where the PDF should be saved"""
|
||||
instructions_folder = os.path.join(
|
||||
current_app.static_folder, # type: ignore
|
||||
current_app.config['INSTRUCTIONS_FOLDER']
|
||||
)
|
||||
return os.path.join(instructions_folder, self.filename)
|
||||
|
||||
# Create BrickInstructions instance for the generated PDF
|
||||
def get_instructions(self, /) -> BrickInstructions:
|
||||
"""Return a BrickInstructions instance for the generated PDF"""
|
||||
return BrickInstructions(self.filename)
|
||||
+162
-31
@@ -24,6 +24,7 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
|
||||
# Queries
|
||||
all_query: str = 'set/list/all'
|
||||
consolidated_query: str = 'set/list/consolidated'
|
||||
damaged_minifigure_query: str = 'set/list/damaged_minifigure'
|
||||
damaged_part_query: str = 'set/list/damaged_part'
|
||||
generic_query: str = 'set/list/generic'
|
||||
@@ -46,8 +47,25 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
|
||||
# All the sets
|
||||
def all(self, /) -> Self:
|
||||
# Load the sets from the database
|
||||
self.list(do_theme=True)
|
||||
# Load the sets from the database with metadata context for filtering
|
||||
filter_context = {
|
||||
'owners': BrickSetOwnerList.as_columns(),
|
||||
'statuses': BrickSetStatusList.as_columns(),
|
||||
'tags': BrickSetTagList.as_columns(),
|
||||
}
|
||||
self.list(do_theme=True, **filter_context)
|
||||
|
||||
return self
|
||||
|
||||
# All sets in consolidated/grouped view
|
||||
def all_consolidated(self, /) -> Self:
|
||||
# Load the sets from the database using consolidated query with metadata context
|
||||
filter_context = {
|
||||
'owners_dict': BrickSetOwnerList.as_column_mapping(),
|
||||
'statuses_dict': BrickSetStatusList.as_column_mapping(),
|
||||
'tags_dict': BrickSetTagList.as_column_mapping(),
|
||||
}
|
||||
self.list(override_query=self.consolidated_query, do_theme=True, **filter_context)
|
||||
|
||||
return self
|
||||
|
||||
@@ -64,7 +82,8 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
owner_filter: str | None = None,
|
||||
purchase_location_filter: str | None = None,
|
||||
storage_filter: str | None = None,
|
||||
tag_filter: str | None = None
|
||||
tag_filter: str | None = None,
|
||||
use_consolidated: bool = True
|
||||
) -> tuple[Self, int]:
|
||||
# Convert theme name to theme ID for filtering
|
||||
theme_id_filter = None
|
||||
@@ -86,24 +105,51 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
'owners': BrickSetOwnerList.as_columns(),
|
||||
'statuses': BrickSetStatusList.as_columns(),
|
||||
'tags': BrickSetTagList.as_columns(),
|
||||
'owners_dict': BrickSetOwnerList.as_column_mapping(),
|
||||
'statuses_dict': BrickSetStatusList.as_column_mapping(),
|
||||
'tags_dict': BrickSetTagList.as_column_mapping(),
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Field mapping for sorting
|
||||
field_mapping = {
|
||||
'set': '"rebrickable_sets"."set"',
|
||||
'name': '"rebrickable_sets"."name"',
|
||||
'year': '"rebrickable_sets"."year"',
|
||||
'parts': '"rebrickable_sets"."number_of_parts"',
|
||||
'theme': '"rebrickable_sets"."theme_id"',
|
||||
'minifigures': '"total_minifigures"', # Use the alias from the SQL query
|
||||
'missing': '"total_missing"', # Use the alias from the SQL query
|
||||
'damaged': '"total_damaged"', # Use the alias from the SQL query
|
||||
'purchase-date': '"bricktracker_sets"."purchase_date"',
|
||||
'purchase-price': '"bricktracker_sets"."purchase_price"'
|
||||
}
|
||||
if use_consolidated:
|
||||
field_mapping = {
|
||||
'set': '"rebrickable_sets"."number", "rebrickable_sets"."version"',
|
||||
'name': '"rebrickable_sets"."name"',
|
||||
'year': '"rebrickable_sets"."year"',
|
||||
'parts': '"rebrickable_sets"."number_of_parts"',
|
||||
'theme': '"rebrickable_sets"."theme_id"',
|
||||
'minifigures': '"total_minifigures"',
|
||||
'missing': '"total_missing"',
|
||||
'damaged': '"total_damaged"',
|
||||
'instances': '"instance_count"', # New field for consolidated view
|
||||
'purchase-date': '"purchase_date"', # Use the MIN aggregated value
|
||||
'purchase-price': '"purchase_price"' # Use the MIN aggregated value
|
||||
}
|
||||
else:
|
||||
field_mapping = {
|
||||
'set': '"rebrickable_sets"."number", "rebrickable_sets"."version"',
|
||||
'name': '"rebrickable_sets"."name"',
|
||||
'year': '"rebrickable_sets"."year"',
|
||||
'parts': '"rebrickable_sets"."number_of_parts"',
|
||||
'theme': '"rebrickable_sets"."theme_id"',
|
||||
'minifigures': '"total_minifigures"', # Use the alias from the SQL query
|
||||
'missing': '"total_missing"', # Use the alias from the SQL query
|
||||
'damaged': '"total_damaged"', # Use the alias from the SQL query
|
||||
'purchase-date': '"bricktracker_sets"."purchase_date"',
|
||||
'purchase-price': '"bricktracker_sets"."purchase_price"'
|
||||
}
|
||||
|
||||
# Choose query based on whether filters are applied
|
||||
query_to_use = 'set/list/all_filtered' if has_filters else self.all_query
|
||||
# Choose query based on consolidation preference and filter complexity
|
||||
# Owner/tag filters still need to fall back to non-consolidated for now
|
||||
# due to complex aggregation requirements
|
||||
complex_filters = [owner_filter, tag_filter]
|
||||
if use_consolidated and not any(complex_filters):
|
||||
query_to_use = self.consolidated_query
|
||||
else:
|
||||
# Use filtered query when consolidation is disabled or complex filters applied
|
||||
query_to_use = 'set/list/all_filtered'
|
||||
|
||||
# Handle instructions filtering
|
||||
if status_filter in ['has-missing-instructions', '-has-missing-instructions']:
|
||||
@@ -114,6 +160,18 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
purchase_location_filter, storage_filter, tag_filter
|
||||
)
|
||||
|
||||
# Handle special case for set sorting with multiple columns
|
||||
if sort_field == 'set' and field_mapping:
|
||||
# Create custom order clause for set sorting
|
||||
direction = 'DESC' if sort_order.lower() == 'desc' else 'ASC'
|
||||
custom_order = f'"rebrickable_sets"."number" {direction}, "rebrickable_sets"."version" {direction}'
|
||||
filter_context['order'] = custom_order
|
||||
# Remove set from field mapping to avoid double-processing
|
||||
field_mapping_copy = field_mapping.copy()
|
||||
field_mapping_copy.pop('set', None)
|
||||
field_mapping = field_mapping_copy
|
||||
sort_field = None # Disable automatic ORDER BY construction
|
||||
|
||||
# Normal SQL-based filtering and pagination
|
||||
result, total_count = self.paginate(
|
||||
page=page,
|
||||
@@ -125,8 +183,11 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
**filter_context
|
||||
)
|
||||
|
||||
# Populate themes for filter dropdown from ALL sets, not just current page
|
||||
result._populate_themes_global()
|
||||
# Populate themes for filter dropdown from filtered dataset (not just current page)
|
||||
result._populate_themes_from_filtered_dataset(
|
||||
query_to_use,
|
||||
**filter_context
|
||||
)
|
||||
|
||||
return result, total_count
|
||||
|
||||
@@ -143,11 +204,36 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
def _theme_name_to_id(self, theme_name: str) -> str | None:
|
||||
"""Convert a theme name to theme ID for filtering"""
|
||||
try:
|
||||
from .sql import BrickSQL
|
||||
theme_list = BrickThemeList()
|
||||
|
||||
# Find all theme IDs that match the name
|
||||
matching_theme_ids = []
|
||||
for theme_id, theme in theme_list.themes.items():
|
||||
if theme.name.lower() == theme_name.lower():
|
||||
return str(theme_id)
|
||||
return None
|
||||
matching_theme_ids.append(str(theme_id))
|
||||
|
||||
if not matching_theme_ids:
|
||||
return None
|
||||
|
||||
# If only one match, return it
|
||||
if len(matching_theme_ids) == 1:
|
||||
return matching_theme_ids[0]
|
||||
|
||||
# Multiple matches - check which theme ID actually has sets in the user's collection
|
||||
sql = BrickSQL()
|
||||
for theme_id in matching_theme_ids:
|
||||
result = sql.fetchone(
|
||||
'set/check_theme_exists',
|
||||
theme_id=theme_id
|
||||
)
|
||||
count = result['count'] if result else 0
|
||||
if count > 0:
|
||||
return theme_id
|
||||
|
||||
# If none have sets, return the first match (fallback)
|
||||
return matching_theme_ids[0]
|
||||
|
||||
except Exception:
|
||||
# If themes can't be loaded, return None to disable theme filtering
|
||||
return None
|
||||
@@ -240,21 +326,53 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
purchase_location_filter, storage_filter, tag_filter
|
||||
)
|
||||
|
||||
def _populate_themes_global(self) -> None:
|
||||
"""Populate themes list from ALL sets, not just current page"""
|
||||
def _populate_themes_from_filtered_dataset(self, query_name: str, **filter_context) -> None:
|
||||
"""Populate themes list from filtered dataset (all pages, not just current page)"""
|
||||
try:
|
||||
# Load all sets to get all possible themes
|
||||
all_sets = BrickSetList().all()
|
||||
from .theme_list import BrickThemeList
|
||||
|
||||
# Use a simplified query to get just distinct theme_ids
|
||||
theme_context = dict(filter_context)
|
||||
theme_context.pop('limit', None)
|
||||
theme_context.pop('offset', None)
|
||||
|
||||
# Use a special lightweight query for themes
|
||||
theme_records = super().select(
|
||||
override_query='set/list/themes_only',
|
||||
**theme_context
|
||||
)
|
||||
|
||||
# Convert to theme names
|
||||
theme_list = BrickThemeList()
|
||||
themes = set()
|
||||
for record in all_sets.records:
|
||||
if hasattr(record, 'theme') and hasattr(record.theme, 'name'):
|
||||
themes.add(record.theme.name)
|
||||
for record in theme_records:
|
||||
theme_id = record.get('theme_id')
|
||||
if theme_id:
|
||||
theme = theme_list.get(theme_id)
|
||||
if theme and hasattr(theme, 'name'):
|
||||
themes.add(theme.name)
|
||||
|
||||
self.themes = list(themes)
|
||||
self.themes.sort()
|
||||
|
||||
except Exception:
|
||||
# Fall back to current page themes
|
||||
self._populate_themes()
|
||||
# Fall back to simpler approach: get themes from ALL sets (ignoring filters)
|
||||
# This is better than showing only current page themes
|
||||
try:
|
||||
from .theme_list import BrickThemeList
|
||||
all_sets = BrickSetList()
|
||||
all_sets.list(do_theme=True)
|
||||
|
||||
themes = set()
|
||||
for record in all_sets.records:
|
||||
if hasattr(record, 'theme') and hasattr(record.theme, 'name'):
|
||||
themes.add(record.theme.name)
|
||||
|
||||
self.themes = list(themes)
|
||||
self.themes.sort()
|
||||
except Exception:
|
||||
# Final fallback to current page themes
|
||||
self._populate_themes()
|
||||
|
||||
def _matches_search(self, record, search_query: str) -> bool:
|
||||
"""Check if record matches search query"""
|
||||
@@ -301,7 +419,7 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
reverse = sort_order == 'desc'
|
||||
|
||||
if sort_field == 'set':
|
||||
return sorted(records, key=lambda r: r.fields.set, reverse=reverse)
|
||||
return sorted(records, key=lambda r: self._set_sort_key(r.fields.set), reverse=reverse)
|
||||
elif sort_field == 'name':
|
||||
return sorted(records, key=lambda r: r.fields.name, reverse=reverse)
|
||||
elif sort_field == 'year':
|
||||
@@ -312,6 +430,19 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
|
||||
return records
|
||||
|
||||
|
||||
def _set_sort_key(self, set_number: str) -> tuple:
|
||||
"""Generate sort key for set numbers like '10121-1' -> (10121, 1)"""
|
||||
try:
|
||||
if '-' in set_number:
|
||||
main_part, version_part = set_number.split('-', 1)
|
||||
return (int(main_part), int(version_part))
|
||||
else:
|
||||
return (int(set_number), 0)
|
||||
except (ValueError, TypeError):
|
||||
# Fallback to string sorting if parsing fails
|
||||
return (float('inf'), set_number)
|
||||
|
||||
# Sets with a minifigure part damaged
|
||||
def damaged_minifigure(self, figure: str, /) -> Self:
|
||||
# Save the parameters to the fields
|
||||
|
||||
@@ -6,6 +6,8 @@ from flask_socketio import SocketIO
|
||||
|
||||
from .instructions import BrickInstructions
|
||||
from .instructions_list import BrickInstructionsList
|
||||
from .peeron_instructions import PeeronInstructions, PeeronPage
|
||||
from .peeron_pdf import PeeronPDF
|
||||
from .set import BrickSet
|
||||
from .socket_decorator import authenticated_socket, rebrickable_socket
|
||||
from .sql import close as sql_close
|
||||
@@ -18,8 +20,10 @@ MESSAGES: Final[dict[str, str]] = {
|
||||
'CONNECT': 'connect',
|
||||
'DISCONNECT': 'disconnect',
|
||||
'DOWNLOAD_INSTRUCTIONS': 'download_instructions',
|
||||
'DOWNLOAD_PEERON_PAGES': 'download_peeron_pages',
|
||||
'FAIL': 'fail',
|
||||
'IMPORT_SET': 'import_set',
|
||||
'LOAD_PEERON_PAGES': 'load_peeron_pages',
|
||||
'LOAD_SET': 'load_set',
|
||||
'PROGRESS': 'progress',
|
||||
'SET_LOADED': 'set_loaded',
|
||||
@@ -106,6 +110,84 @@ class BrickSocket(object):
|
||||
|
||||
BrickInstructionsList(force=True)
|
||||
|
||||
@self.socket.on(MESSAGES['LOAD_PEERON_PAGES'], namespace=self.namespace) # noqa: E501
|
||||
def load_peeron_pages(data: dict[str, Any], /) -> None:
|
||||
logger.debug('Socket: LOAD_PEERON_PAGES={data} (from: {fr})'.format(
|
||||
data=data, fr=request.remote_addr))
|
||||
|
||||
try:
|
||||
set_number = data.get('set', '')
|
||||
if not set_number:
|
||||
self.fail(message="Set number is required")
|
||||
return
|
||||
|
||||
# Create Peeron instructions instance with socket for progress reporting
|
||||
peeron = PeeronInstructions(set_number, socket=self)
|
||||
|
||||
# Find pages (this will report progress for thumbnail caching)
|
||||
pages = peeron.find_pages()
|
||||
|
||||
# Complete the operation (JavaScript will handle redirect)
|
||||
self.complete(message=f"Found {len(pages)} instruction pages on Peeron")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in load_peeron_pages: {e}")
|
||||
self.fail(message=f"Error loading Peeron pages: {e}")
|
||||
|
||||
@self.socket.on(MESSAGES['DOWNLOAD_PEERON_PAGES'], namespace=self.namespace) # noqa: E501
|
||||
@authenticated_socket(self)
|
||||
def download_peeron_pages(data: dict[str, Any], /) -> None:
|
||||
logger.debug('Socket: DOWNLOAD_PEERON_PAGES={data} (from: {fr})'.format(
|
||||
data=data,
|
||||
fr=request.sid, # type: ignore
|
||||
))
|
||||
|
||||
try:
|
||||
# Extract data from the request
|
||||
set_number = data.get('set', '')
|
||||
pages_data = data.get('pages', [])
|
||||
|
||||
if not set_number:
|
||||
raise ValueError("Set number is required")
|
||||
|
||||
if not pages_data:
|
||||
raise ValueError("No pages selected")
|
||||
|
||||
# Parse set number
|
||||
if '-' in set_number:
|
||||
parts = set_number.split('-', 1)
|
||||
set_num = parts[0]
|
||||
version_num = parts[1] if len(parts) > 1 else '1'
|
||||
else:
|
||||
set_num = set_number
|
||||
version_num = '1'
|
||||
|
||||
# Convert page data to PeeronPage objects
|
||||
pages = []
|
||||
for page_data in pages_data:
|
||||
page = PeeronPage(
|
||||
page_number=page_data.get('page_number', ''),
|
||||
original_image_url=page_data.get('original_image_url', ''),
|
||||
cached_full_image_path=page_data.get('cached_full_image_path', ''),
|
||||
cached_thumbnail_url='', # Not needed for PDF generation
|
||||
alt_text=page_data.get('alt_text', ''),
|
||||
rotation=page_data.get('rotation', 0)
|
||||
)
|
||||
pages.append(page)
|
||||
|
||||
# Create PDF generator and start download
|
||||
pdf_generator = PeeronPDF(set_num, version_num, pages, socket=self)
|
||||
pdf_generator.create_pdf()
|
||||
|
||||
# Note: Cache cleanup is handled automatically by pdf_generator.create_pdf()
|
||||
|
||||
# Refresh instructions list to include new PDF
|
||||
BrickInstructionsList(force=True)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in download_peeron_pages: {e}")
|
||||
self.fail(message=f"Error downloading Peeron pages: {e}")
|
||||
|
||||
@self.socket.on(MESSAGES['IMPORT_SET'], namespace=self.namespace)
|
||||
@rebrickable_socket(self)
|
||||
def import_set(data: dict[str, Any], /) -> None:
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
-- description: Add checked field to bricktracker_parts table for part walkthrough tracking
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
-- Add checked field to the bricktracker_parts table
|
||||
-- This allows users to track which parts they have checked during walkthroughs
|
||||
ALTER TABLE "bricktracker_parts" ADD COLUMN "checked" BOOLEAN DEFAULT 0;
|
||||
|
||||
COMMIT;
|
||||
@@ -9,6 +9,7 @@ SELECT
|
||||
--"bricktracker_parts"."rebrickable_inventory",
|
||||
"bricktracker_parts"."missing",
|
||||
"bricktracker_parts"."damaged",
|
||||
"bricktracker_parts"."checked",
|
||||
--"rebrickable_parts"."part",
|
||||
--"rebrickable_parts"."color_id",
|
||||
"rebrickable_parts"."color_name",
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
UPDATE "bricktracker_parts"
|
||||
SET "checked" = :checked
|
||||
WHERE "bricktracker_parts"."id" IS NOT DISTINCT FROM :id
|
||||
AND "bricktracker_parts"."figure" IS NOT DISTINCT FROM :figure
|
||||
AND "bricktracker_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_parts"."spare" IS NOT DISTINCT FROM :spare
|
||||
@@ -0,0 +1,4 @@
|
||||
SELECT COUNT(*) as count
|
||||
FROM "bricktracker_sets"
|
||||
INNER JOIN "rebrickable_sets" ON "bricktracker_sets"."set" = "rebrickable_sets"."set"
|
||||
WHERE "rebrickable_sets"."theme_id" = {{ theme_id }}
|
||||
@@ -8,7 +8,7 @@ AND (LOWER("rebrickable_sets"."name") LIKE LOWER('%{{ search_query }}%')
|
||||
{% endif %}
|
||||
|
||||
{% if theme_filter %}
|
||||
AND "rebrickable_sets"."theme_id" = '{{ theme_filter }}'
|
||||
AND "rebrickable_sets"."theme_id" = {{ theme_filter }}
|
||||
{% endif %}
|
||||
|
||||
{% if storage_filter %}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
SELECT
|
||||
(SELECT MIN("id") FROM "bricktracker_sets" WHERE "set" = "rebrickable_sets"."set") AS "id",
|
||||
"rebrickable_sets"."set",
|
||||
"rebrickable_sets"."number",
|
||||
"rebrickable_sets"."version",
|
||||
"rebrickable_sets"."name",
|
||||
"rebrickable_sets"."year",
|
||||
"rebrickable_sets"."theme_id",
|
||||
"rebrickable_sets"."number_of_parts",
|
||||
"rebrickable_sets"."image",
|
||||
"rebrickable_sets"."url",
|
||||
COUNT("bricktracker_sets"."id") AS "instance_count",
|
||||
IFNULL(SUM("problem_join"."total_missing"), 0) AS "total_missing",
|
||||
IFNULL(SUM("problem_join"."total_damaged"), 0) AS "total_damaged",
|
||||
IFNULL(MAX("minifigures_join"."total"), 0) AS "total_minifigures",
|
||||
-- Keep one representative instance for display purposes
|
||||
GROUP_CONCAT("bricktracker_sets"."id", '|') AS "instance_ids",
|
||||
REPLACE(GROUP_CONCAT(DISTINCT "bricktracker_sets"."storage"), ',', '|') AS "storage",
|
||||
MIN("bricktracker_sets"."purchase_date") AS "purchase_date",
|
||||
REPLACE(GROUP_CONCAT(DISTINCT "bricktracker_sets"."purchase_location"), ',', '|') AS "purchase_location",
|
||||
MIN("bricktracker_sets"."purchase_price") AS "purchase_price"
|
||||
{% block owners %}
|
||||
{% if owners_dict %}
|
||||
{% for column, uuid in owners_dict.items() %}
|
||||
, MAX("bricktracker_set_owners"."{{ column }}") AS "{{ column }}"
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block tags %}
|
||||
{% if tags_dict %}
|
||||
{% for column, uuid in tags_dict.items() %}
|
||||
, MAX("bricktracker_set_tags"."{{ column }}") AS "{{ column }}"
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block statuses %}
|
||||
{% if statuses_dict %}
|
||||
{% for column, uuid in statuses_dict.items() %}
|
||||
, MAX("bricktracker_set_statuses"."{{ column }}") AS "{{ column }}"
|
||||
, IFNULL(SUM("bricktracker_set_statuses"."{{ column }}"), 0) AS "{{ column }}_count"
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
FROM "bricktracker_sets"
|
||||
|
||||
INNER JOIN "rebrickable_sets"
|
||||
ON "bricktracker_sets"."set" IS NOT DISTINCT FROM "rebrickable_sets"."set"
|
||||
|
||||
-- LEFT JOIN + SELECT to avoid messing the total
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
"bricktracker_parts"."id",
|
||||
SUM("bricktracker_parts"."missing") AS "total_missing",
|
||||
SUM("bricktracker_parts"."damaged") AS "total_damaged"
|
||||
FROM "bricktracker_parts"
|
||||
GROUP BY "bricktracker_parts"."id"
|
||||
) "problem_join"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "problem_join"."id"
|
||||
|
||||
-- LEFT JOIN + SELECT to avoid messing the total
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
"bricktracker_minifigures"."id",
|
||||
SUM("bricktracker_minifigures"."quantity") AS "total"
|
||||
FROM "bricktracker_minifigures"
|
||||
GROUP BY "bricktracker_minifigures"."id"
|
||||
) "minifigures_join"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "minifigures_join"."id"
|
||||
|
||||
{% if owners_dict %}
|
||||
LEFT JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
{% endif %}
|
||||
|
||||
{% if statuses_dict %}
|
||||
LEFT JOIN "bricktracker_set_statuses"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_statuses"."id"
|
||||
{% endif %}
|
||||
|
||||
{% if tags_dict %}
|
||||
LEFT JOIN "bricktracker_set_tags"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_tags"."id"
|
||||
{% endif %}
|
||||
|
||||
{% block where %}
|
||||
WHERE 1=1
|
||||
{% if search_query %}
|
||||
AND (LOWER("rebrickable_sets"."name") LIKE LOWER('%{{ search_query }}%')
|
||||
OR LOWER("rebrickable_sets"."set") LIKE LOWER('%{{ search_query }}%'))
|
||||
{% endif %}
|
||||
|
||||
{% if theme_filter %}
|
||||
AND "rebrickable_sets"."theme_id" = {{ theme_filter }}
|
||||
{% endif %}
|
||||
|
||||
{% if storage_filter %}
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND bs_filter."storage" = '{{ storage_filter }}'
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
{% if purchase_location_filter %}
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND bs_filter."purchase_location" = '{{ purchase_location_filter }}'
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
{% if status_filter %}
|
||||
{% if status_filter == 'has-storage' %}
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND bs_filter."storage" IS NOT NULL AND bs_filter."storage" != ''
|
||||
)
|
||||
{% elif status_filter == '-has-storage' %}
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND bs_filter."storage" IS NOT NULL AND bs_filter."storage" != ''
|
||||
)
|
||||
{% elif status_filter.startswith('status-') %}
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
JOIN "bricktracker_set_statuses" ON bs_filter."id" = "bricktracker_set_statuses"."id"
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND "bricktracker_set_statuses"."{{ status_filter.replace('-', '_') }}" = 1
|
||||
)
|
||||
{% elif status_filter.startswith('-status-') %}
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
JOIN "bricktracker_set_statuses" ON bs_filter."id" = "bricktracker_set_statuses"."id"
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND "bricktracker_set_statuses"."{{ status_filter[1:].replace('-', '_') }}" = 1
|
||||
)
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
GROUP BY "rebrickable_sets"."set"
|
||||
|
||||
{% if status_filter %}
|
||||
{% if status_filter == 'has-missing' %}
|
||||
HAVING IFNULL(SUM("problem_join"."total_missing"), 0) > 0
|
||||
{% elif status_filter == '-has-missing' %}
|
||||
HAVING IFNULL(SUM("problem_join"."total_missing"), 0) = 0
|
||||
{% elif status_filter == 'has-damaged' %}
|
||||
HAVING IFNULL(SUM("problem_join"."total_damaged"), 0) > 0
|
||||
{% elif status_filter == '-has-damaged' %}
|
||||
HAVING IFNULL(SUM("problem_join"."total_damaged"), 0) = 0
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if order %}
|
||||
ORDER BY {{ order }}
|
||||
{% endif %}
|
||||
|
||||
{% if limit %}
|
||||
LIMIT {{ limit }}
|
||||
{% endif %}
|
||||
|
||||
{% if offset %}
|
||||
OFFSET {{ offset }}
|
||||
{% endif %}
|
||||
@@ -5,7 +5,7 @@ WHERE "bricktracker_sets"."id" IN (
|
||||
SELECT "bricktracker_parts"."id"
|
||||
FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."figure" IS NOT DISTINCT FROM :figure
|
||||
AND "bricktracker_parts"."missing" > 0
|
||||
AND "bricktracker_parts"."damaged" > 0
|
||||
GROUP BY "bricktracker_parts"."id"
|
||||
)
|
||||
{% endblock %}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
SELECT DISTINCT "rebrickable_sets"."theme_id"
|
||||
FROM "bricktracker_sets"
|
||||
|
||||
INNER JOIN "rebrickable_sets"
|
||||
ON "bricktracker_sets"."set" IS NOT DISTINCT FROM "rebrickable_sets"."set"
|
||||
|
||||
{% block where %}
|
||||
WHERE 1=1
|
||||
{% if search_query %}
|
||||
AND (LOWER("rebrickable_sets"."name") LIKE LOWER('%{{ search_query }}%')
|
||||
OR LOWER("rebrickable_sets"."set") LIKE LOWER('%{{ search_query }}%'))
|
||||
{% endif %}
|
||||
|
||||
{% if storage_filter %}
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND bs_filter."storage" = '{{ storage_filter }}'
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
{% if purchase_location_filter %}
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND bs_filter."purchase_location" = '{{ purchase_location_filter }}'
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
{% if status_filter %}
|
||||
{% if status_filter == 'has-storage' %}
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND bs_filter."storage" IS NOT NULL AND bs_filter."storage" != ''
|
||||
)
|
||||
{% elif status_filter == '-has-storage' %}
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND bs_filter."storage" IS NOT NULL AND bs_filter."storage" != ''
|
||||
)
|
||||
{% elif status_filter.startswith('status-') %}
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
JOIN "bricktracker_set_statuses" ON bs_filter."id" = "bricktracker_set_statuses"."id"
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND "bricktracker_set_statuses"."{{ status_filter.replace('-', '_') }}" = 1
|
||||
)
|
||||
{% elif status_filter.startswith('-status-') %}
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
JOIN "bricktracker_set_statuses" ON bs_filter."id" = "bricktracker_set_statuses"."id"
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND "bricktracker_set_statuses"."{{ status_filter[1:].replace('-', '_') }}" = 1
|
||||
)
|
||||
{% elif status_filter == 'has-missing' %}
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
JOIN "bricktracker_parts" ON bs_filter."id" = "bricktracker_parts"."id"
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND "bricktracker_parts"."missing" > 0
|
||||
)
|
||||
{% elif status_filter == '-has-missing' %}
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
JOIN "bricktracker_parts" ON bs_filter."id" = "bricktracker_parts"."id"
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND "bricktracker_parts"."missing" > 0
|
||||
)
|
||||
{% elif status_filter == 'has-damaged' %}
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
JOIN "bricktracker_parts" ON bs_filter."id" = "bricktracker_parts"."id"
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND "bricktracker_parts"."damaged" > 0
|
||||
)
|
||||
{% elif status_filter == '-has-damaged' %}
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM "bricktracker_sets" bs_filter
|
||||
JOIN "bricktracker_parts" ON bs_filter."id" = "bricktracker_parts"."id"
|
||||
WHERE bs_filter."set" = "rebrickable_sets"."set"
|
||||
AND "bricktracker_parts"."damaged" > 0
|
||||
)
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Final
|
||||
|
||||
__version__: Final[str] = '1.2.5'
|
||||
__database_version__: Final[int] = 17
|
||||
__version__: Final[str] = '1.3.0'
|
||||
__database_version__: Final[int] = 18
|
||||
|
||||
@@ -14,6 +14,7 @@ from .exceptions import exception_handler
|
||||
from ..instructions import BrickInstructions
|
||||
from ..instructions_list import BrickInstructionsList
|
||||
from ..parser import parse_set
|
||||
from ..peeron_instructions import PeeronInstructions
|
||||
from ..socket import MESSAGES
|
||||
from .upload import upload_helper
|
||||
|
||||
@@ -24,6 +25,22 @@ instructions_page = Blueprint(
|
||||
)
|
||||
|
||||
|
||||
def _render_peeron_select_page(set: str) -> str:
|
||||
"""Helper function to render the Peeron page selection interface with cached thumbnails."""
|
||||
peeron = PeeronInstructions(set)
|
||||
peeron_pages = peeron.find_pages() # This will use the cached thumbnails
|
||||
current_app.logger.debug(f"[peeron_loaded] Found {len(peeron_pages)} pages for {set}")
|
||||
return render_template(
|
||||
'peeron_select.html',
|
||||
download=True,
|
||||
pages=peeron_pages,
|
||||
set=set,
|
||||
path=current_app.config['SOCKET_PATH'],
|
||||
namespace=current_app.config['SOCKET_NAMESPACE'],
|
||||
messages=MESSAGES
|
||||
)
|
||||
|
||||
|
||||
# Index
|
||||
@instructions_page.route('/', methods=['GET'])
|
||||
@exception_handler(__file__)
|
||||
@@ -141,6 +158,10 @@ def download() -> str:
|
||||
except Exception:
|
||||
set = ''
|
||||
|
||||
# Check if this is a redirect after Peeron pages were loaded
|
||||
if request.args.get('peeron_loaded'):
|
||||
return _render_peeron_select_page(set)
|
||||
|
||||
return render_template(
|
||||
'instructions.html',
|
||||
download=True,
|
||||
@@ -160,12 +181,50 @@ def do_download() -> str:
|
||||
except Exception:
|
||||
set = ''
|
||||
|
||||
return render_template(
|
||||
'instructions.html',
|
||||
download=True,
|
||||
instructions=BrickInstructions.find_instructions(set),
|
||||
set=set,
|
||||
path=current_app.config['SOCKET_PATH'],
|
||||
namespace=current_app.config['SOCKET_NAMESPACE'],
|
||||
messages=MESSAGES
|
||||
)
|
||||
# Check if this is a redirect after Peeron pages were loaded
|
||||
if request.args.get('peeron_loaded'):
|
||||
return _render_peeron_select_page(set)
|
||||
|
||||
# Try Rebrickable first
|
||||
try:
|
||||
from .instructions import BrickInstructions
|
||||
rebrickable_instructions = BrickInstructions.find_instructions(set)
|
||||
# Standard Rebrickable instructions found
|
||||
return render_template(
|
||||
'instructions.html',
|
||||
download=True,
|
||||
instructions=rebrickable_instructions,
|
||||
set=set,
|
||||
path=current_app.config['SOCKET_PATH'],
|
||||
namespace=current_app.config['SOCKET_NAMESPACE'],
|
||||
messages=MESSAGES
|
||||
)
|
||||
except Exception:
|
||||
# Rebrickable failed, check if Peeron has instructions (without caching thumbnails yet)
|
||||
try:
|
||||
peeron = PeeronInstructions(set)
|
||||
# Just check if pages exist, don't cache thumbnails yet
|
||||
if peeron.exists():
|
||||
# Peeron has instructions - show loading interface
|
||||
return render_template(
|
||||
'peeron_select.html',
|
||||
download=True,
|
||||
loading_peeron=True, # Flag to show loading state
|
||||
set=set,
|
||||
path=current_app.config['SOCKET_PATH'],
|
||||
namespace=current_app.config['SOCKET_NAMESPACE'],
|
||||
messages=MESSAGES
|
||||
)
|
||||
else:
|
||||
raise Exception("Not found on Peeron either")
|
||||
except Exception:
|
||||
return render_template(
|
||||
'instructions.html',
|
||||
download=True,
|
||||
instructions=[],
|
||||
set=set,
|
||||
error='No instructions found on Rebrickable or Peeron',
|
||||
path=current_app.config['SOCKET_PATH'],
|
||||
namespace=current_app.config['SOCKET_NAMESPACE'],
|
||||
messages=MESSAGES
|
||||
)
|
||||
|
||||
@@ -64,13 +64,17 @@ def list() -> str:
|
||||
owner_filter=owner_filter,
|
||||
purchase_location_filter=purchase_location_filter,
|
||||
storage_filter=storage_filter,
|
||||
tag_filter=tag_filter
|
||||
tag_filter=tag_filter,
|
||||
use_consolidated=current_app.config['SETS_CONSOLIDATION']
|
||||
)
|
||||
|
||||
pagination_context = build_pagination_context(page, per_page, total_count, is_mobile)
|
||||
else:
|
||||
# ORIGINAL MODE - Single page with all data for client-side search
|
||||
sets = BrickSetList().all()
|
||||
if current_app.config['SETS_CONSOLIDATION']:
|
||||
sets = BrickSetList().all_consolidated()
|
||||
else:
|
||||
sets = BrickSetList().all()
|
||||
pagination_context = None
|
||||
|
||||
template_context = {
|
||||
@@ -239,13 +243,44 @@ def deleted(*, id: str) -> str:
|
||||
@set_page.route('/<id>/details', methods=['GET'])
|
||||
@exception_handler(__file__)
|
||||
def details(*, id: str) -> str:
|
||||
return render_template(
|
||||
'set.html',
|
||||
item=BrickSet().select_specific(id),
|
||||
open_instructions=request.args.get('open_instructions'),
|
||||
brickset_statuses=BrickSetStatusList.list(all=True),
|
||||
**set_metadata_lists(as_class=True)
|
||||
)
|
||||
# Load the specific set
|
||||
item = BrickSet().select_specific(id)
|
||||
|
||||
# Check if there are multiple instances of this set
|
||||
all_instances = BrickSetList()
|
||||
# Load all sets with metadata context for tags, owners, etc.
|
||||
filter_context = {
|
||||
'owners': BrickSetOwnerList.as_columns(),
|
||||
'statuses': BrickSetStatusList.as_columns(),
|
||||
'tags': BrickSetTagList.as_columns(),
|
||||
}
|
||||
all_instances.list(do_theme=True, **filter_context)
|
||||
|
||||
# Find all instances with the same set number
|
||||
same_set_instances = [
|
||||
record for record in all_instances.records
|
||||
if record.fields.set == item.fields.set
|
||||
]
|
||||
|
||||
# If consolidation is enabled and multiple instances exist, show consolidated view
|
||||
if current_app.config['SETS_CONSOLIDATION'] and len(same_set_instances) > 1:
|
||||
return render_template(
|
||||
'set.html',
|
||||
item=item,
|
||||
all_instances=same_set_instances,
|
||||
open_instructions=request.args.get('open_instructions'),
|
||||
brickset_statuses=BrickSetStatusList.list(all=True),
|
||||
**set_metadata_lists(as_class=True)
|
||||
)
|
||||
else:
|
||||
# Single instance or consolidation disabled, show normal view
|
||||
return render_template(
|
||||
'set.html',
|
||||
item=item,
|
||||
open_instructions=request.args.get('open_instructions'),
|
||||
brickset_statuses=BrickSetStatusList.list(all=True),
|
||||
**set_metadata_lists(as_class=True)
|
||||
)
|
||||
|
||||
|
||||
# Update problematic pieces of a set
|
||||
@@ -294,6 +329,50 @@ def problem_part(
|
||||
return jsonify({problem: amount})
|
||||
|
||||
|
||||
# Update checked state of parts during walkthrough
|
||||
@set_page.route('/<id>/parts/<part>/<int:color>/<int:spare>/checked', defaults={'figure': None}, methods=['POST']) # noqa: E501
|
||||
@set_page.route('/<id>/minifigures/<figure>/parts/<part>/<int:color>/<int:spare>/checked', methods=['POST']) # noqa: E501
|
||||
@login_required
|
||||
@exception_handler(__file__, json=True)
|
||||
def checked_part(
|
||||
*,
|
||||
id: str,
|
||||
figure: str | None,
|
||||
part: str,
|
||||
color: int,
|
||||
spare: int,
|
||||
) -> Response:
|
||||
brickset = BrickSet().select_specific(id)
|
||||
|
||||
if figure is not None:
|
||||
brickminifigure = BrickMinifigure().select_specific(brickset, figure)
|
||||
else:
|
||||
brickminifigure = None
|
||||
|
||||
brickpart = BrickPart().select_specific(
|
||||
brickset,
|
||||
part,
|
||||
color,
|
||||
spare,
|
||||
minifigure=brickminifigure,
|
||||
)
|
||||
|
||||
checked = brickpart.update_checked(request.json)
|
||||
|
||||
# Info
|
||||
logger.info('Set {set} ({id}): updated part ({part} color: {color}, spare: {spare}, minifigure: {figure}) checked state to {checked}'.format( # noqa: E501
|
||||
set=brickset.fields.set,
|
||||
id=brickset.fields.id,
|
||||
figure=figure,
|
||||
part=brickpart.fields.part,
|
||||
color=brickpart.fields.color,
|
||||
spare=brickpart.fields.spare,
|
||||
checked=checked
|
||||
))
|
||||
|
||||
return jsonify({'checked': checked})
|
||||
|
||||
|
||||
# Refresh a set
|
||||
@set_page.route('/refresh/<set>/', methods=['GET'])
|
||||
@set_page.route('/<id>/refresh', methods=['GET'])
|
||||
|
||||
@@ -11,3 +11,5 @@ requests
|
||||
tzdata
|
||||
bs4
|
||||
cloudscraper
|
||||
fpdf2
|
||||
pillow
|
||||
@@ -91,7 +91,7 @@ class BrickGridFilter {
|
||||
attribute: select.value,
|
||||
bool: true,
|
||||
value: "1"
|
||||
})
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -106,19 +106,48 @@ class BrickGridFilter {
|
||||
const attribute = current.getAttribute(`data-${filter.attribute}`);
|
||||
|
||||
// Bool check
|
||||
// Attribute not equal value, or undefined and value is truthy
|
||||
// For boolean attributes (like owner/tag filtering)
|
||||
if (filter.bool) {
|
||||
if ((attribute != null && attribute != filter.value) || (attribute == null && filter.value == "1")) {
|
||||
current.parentElement.classList.add("d-none");
|
||||
return;
|
||||
if (filter.value == "1") {
|
||||
// Looking for sets WITH this attribute
|
||||
// Hide if attribute is missing (null) or explicitly "0"
|
||||
// For owner/tag attributes: missing = doesn't have this owner/tag
|
||||
if (attribute == null || attribute == "0") {
|
||||
current.parentElement.classList.add("d-none");
|
||||
return;
|
||||
}
|
||||
} else if (filter.value == "0") {
|
||||
// Looking for sets WITHOUT this attribute
|
||||
// Hide if attribute is present and "1"
|
||||
// For owner/tag attributes: present and "1" = has this owner/tag
|
||||
if (attribute == "1") {
|
||||
current.parentElement.classList.add("d-none");
|
||||
return;
|
||||
}
|
||||
// Note: null (missing) is treated as "doesn't have" which is what we want for value="0"
|
||||
}
|
||||
}
|
||||
|
||||
// Value check
|
||||
// Attribute not equal value, or attribute undefined
|
||||
else if ((attribute != null && attribute != filter.value) || attribute == null) {
|
||||
// For consolidated cards, attributes may be comma or pipe-separated (e.g., "storage1,storage2" or "storage1|storage2")
|
||||
else if (attribute == null) {
|
||||
// Hide if attribute is missing
|
||||
current.parentElement.classList.add("d-none");
|
||||
return;
|
||||
} else if (attribute.includes(',') || attribute.includes('|')) {
|
||||
// Handle comma or pipe-separated values (consolidated cards)
|
||||
const separator = attribute.includes('|') ? '|' : ',';
|
||||
const values = attribute.split(separator).map(v => v.trim());
|
||||
if (!values.includes(filter.value)) {
|
||||
current.parentElement.classList.add("d-none");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Handle single values (regular cards)
|
||||
if (attribute != filter.value) {
|
||||
current.parentElement.classList.add("d-none");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
// Bulk operations for parts in set details page
|
||||
class PartsBulkOperations {
|
||||
constructor(accordionId) {
|
||||
this.accordionId = accordionId;
|
||||
this.setupModal();
|
||||
this.setupEventListeners();
|
||||
}
|
||||
|
||||
setupModal() {
|
||||
// Create Bootstrap modal if it doesn't exist
|
||||
if (!document.getElementById('partsConfirmModal')) {
|
||||
const modalHTML = `
|
||||
<div class="modal fade" id="partsConfirmModal" tabindex="-1" aria-labelledby="partsConfirmModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="partsConfirmModalLabel">Confirm Action</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p id="partsConfirmModalMessage"></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" id="partsConfirmModalConfirm">Confirm</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.body.insertAdjacentHTML('beforeend', modalHTML);
|
||||
}
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
// Mark all as missing (only if missing parts are not hidden)
|
||||
const markAllMissingBtn = document.getElementById(`mark-all-missing-${this.accordionId}`);
|
||||
if (markAllMissingBtn) {
|
||||
markAllMissingBtn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
this.confirmAndExecute(
|
||||
'Mark all parts as missing?',
|
||||
'This will set the missing count to the maximum quantity for all parts in this section.',
|
||||
() => this.markAllMissing()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Clear all missing (only if missing parts are not hidden)
|
||||
const clearAllMissingBtn = document.getElementById(`clear-all-missing-${this.accordionId}`);
|
||||
if (clearAllMissingBtn) {
|
||||
clearAllMissingBtn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
this.confirmAndExecute(
|
||||
'Clear all missing parts?',
|
||||
'This will clear the missing field for all parts in this section.',
|
||||
() => this.clearAllMissing()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Check all checkboxes (only if checked parts are not hidden)
|
||||
const checkAllBtn = document.getElementById(`check-all-${this.accordionId}`);
|
||||
if (checkAllBtn) {
|
||||
checkAllBtn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
this.checkAll();
|
||||
});
|
||||
}
|
||||
|
||||
// Uncheck all checkboxes (only if checked parts are not hidden)
|
||||
const uncheckAllBtn = document.getElementById(`uncheck-all-${this.accordionId}`);
|
||||
if (uncheckAllBtn) {
|
||||
uncheckAllBtn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
this.uncheckAll();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
confirmAndExecute(title, message, callback) {
|
||||
const modal = document.getElementById('partsConfirmModal');
|
||||
const modalTitle = document.getElementById('partsConfirmModalLabel');
|
||||
const modalMessage = document.getElementById('partsConfirmModalMessage');
|
||||
const confirmBtn = document.getElementById('partsConfirmModalConfirm');
|
||||
|
||||
// Set modal content
|
||||
modalTitle.textContent = title;
|
||||
modalMessage.textContent = message;
|
||||
|
||||
// Remove any existing event listeners and add new one
|
||||
const newConfirmBtn = confirmBtn.cloneNode(true);
|
||||
confirmBtn.parentNode.replaceChild(newConfirmBtn, confirmBtn);
|
||||
|
||||
newConfirmBtn.addEventListener('click', () => {
|
||||
const modalInstance = bootstrap.Modal.getInstance(modal);
|
||||
modalInstance.hide();
|
||||
callback();
|
||||
});
|
||||
|
||||
// Show modal
|
||||
const modalInstance = new bootstrap.Modal(modal);
|
||||
modalInstance.show();
|
||||
}
|
||||
|
||||
markAllMissing() {
|
||||
const accordionElement = document.getElementById(this.accordionId);
|
||||
if (!accordionElement) return;
|
||||
|
||||
// Find all rows in this accordion
|
||||
const rows = accordionElement.querySelectorAll('tbody tr');
|
||||
rows.forEach(row => {
|
||||
// Find the quantity cell (usually 4th column)
|
||||
const quantityCell = row.cells[3]; // Index 3 for quantity column
|
||||
const missingInput = row.querySelector('input[id*="-missing-"]');
|
||||
|
||||
if (quantityCell && missingInput) {
|
||||
// Extract quantity from cell text content
|
||||
const quantityText = quantityCell.textContent.trim();
|
||||
const quantity = parseInt(quantityText) || 1; // Default to 1 if can't parse
|
||||
|
||||
if (missingInput.value !== quantity.toString()) {
|
||||
missingInput.value = quantity.toString();
|
||||
// Trigger change event to activate BrickChanger
|
||||
missingInput.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
clearAllMissing() {
|
||||
const accordionElement = document.getElementById(this.accordionId);
|
||||
if (!accordionElement) return;
|
||||
|
||||
const missingInputs = accordionElement.querySelectorAll('input[id*="-missing-"]');
|
||||
missingInputs.forEach(input => {
|
||||
if (input.value !== '') {
|
||||
input.value = '';
|
||||
// Trigger change event to activate BrickChanger
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
checkAll() {
|
||||
const accordionElement = document.getElementById(this.accordionId);
|
||||
if (!accordionElement) return;
|
||||
|
||||
const checkboxes = accordionElement.querySelectorAll('input[id*="-checked-"][type="checkbox"]');
|
||||
checkboxes.forEach(checkbox => {
|
||||
if (!checkbox.checked) {
|
||||
checkbox.checked = true;
|
||||
// Trigger change event to activate BrickChanger
|
||||
checkbox.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
uncheckAll() {
|
||||
const accordionElement = document.getElementById(this.accordionId);
|
||||
if (!accordionElement) return;
|
||||
|
||||
const checkboxes = accordionElement.querySelectorAll('input[id*="-checked-"][type="checkbox"]');
|
||||
checkboxes.forEach(checkbox => {
|
||||
if (checkbox.checked) {
|
||||
checkbox.checked = false;
|
||||
// Trigger change event to activate BrickChanger
|
||||
checkbox.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize bulk operations for all part accordions when DOM is ready
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Find all hamburger menus and initialize bulk operations
|
||||
const hamburgerMenus = document.querySelectorAll('button[id^="hamburger-"]');
|
||||
hamburgerMenus.forEach(button => {
|
||||
const accordionId = button.id.replace('hamburger-', '');
|
||||
new PartsBulkOperations(accordionId);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
// Set details page functionality
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const collapseElement = document.getElementById('all-instances');
|
||||
const toggleIcon = document.getElementById('copies-toggle-icon');
|
||||
|
||||
if (collapseElement && toggleIcon) {
|
||||
collapseElement.addEventListener('shown.bs.collapse', function() {
|
||||
toggleIcon.className = 'ri-arrow-up-s-line fs-4';
|
||||
});
|
||||
|
||||
collapseElement.addEventListener('hidden.bs.collapse', function() {
|
||||
toggleIcon.className = 'ri-arrow-down-s-line fs-4';
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -193,4 +193,170 @@ function setupPaginationFilterDropdowns() {
|
||||
currentUrl.searchParams.set('page', '1');
|
||||
window.location.href = currentUrl.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// Set grouping functionality
|
||||
function initializeSetGrouping() {
|
||||
const groupToggle = document.getElementById('group-identical-sets');
|
||||
if (!groupToggle) return;
|
||||
|
||||
// Load saved state from localStorage
|
||||
const savedState = localStorage.getItem('groupIdenticalSets') === 'true';
|
||||
groupToggle.checked = savedState;
|
||||
|
||||
// Apply grouping on page load if enabled
|
||||
if (savedState) {
|
||||
applySetGrouping();
|
||||
}
|
||||
|
||||
// Listen for toggle changes
|
||||
groupToggle.addEventListener('change', function() {
|
||||
// Save state to localStorage
|
||||
localStorage.setItem('groupIdenticalSets', this.checked);
|
||||
|
||||
if (this.checked) {
|
||||
applySetGrouping();
|
||||
} else {
|
||||
removeSetGrouping();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function applySetGrouping() {
|
||||
const grid = document.getElementById('grid');
|
||||
if (!grid) return;
|
||||
|
||||
const setCards = Array.from(grid.children);
|
||||
const groupedSets = {};
|
||||
|
||||
// Group sets by rebrickable_set_id
|
||||
setCards.forEach(cardCol => {
|
||||
const setCard = cardCol.querySelector('.card[data-set-id]');
|
||||
if (!setCard) return;
|
||||
|
||||
const setId = setCard.getAttribute('data-set-id');
|
||||
const rebrickableId = setCard.getAttribute('data-rebrickable-id');
|
||||
|
||||
if (!rebrickableId) return;
|
||||
|
||||
if (!groupedSets[rebrickableId]) {
|
||||
groupedSets[rebrickableId] = [];
|
||||
}
|
||||
|
||||
groupedSets[rebrickableId].push({
|
||||
cardCol: cardCol,
|
||||
setId: setId,
|
||||
rebrickableId: rebrickableId
|
||||
});
|
||||
});
|
||||
|
||||
// Process each group
|
||||
Object.keys(groupedSets).forEach(rebrickableId => {
|
||||
const group = groupedSets[rebrickableId];
|
||||
|
||||
if (group.length > 1) {
|
||||
createGroupedSetDisplay(group);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createGroupedSetDisplay(setGroup) {
|
||||
const firstSet = setGroup[0];
|
||||
const firstCard = firstSet.cardCol.querySelector('.card');
|
||||
|
||||
if (!firstCard) return;
|
||||
|
||||
// Calculate aggregate stats
|
||||
let totalMissing = 0;
|
||||
let totalDamaged = 0;
|
||||
let allSetIds = [];
|
||||
|
||||
setGroup.forEach(set => {
|
||||
const card = set.cardCol.querySelector('.card');
|
||||
|
||||
// Get missing and damaged counts from existing data attributes
|
||||
const missingCount = parseInt(card.getAttribute('data-missing') || '0');
|
||||
const damagedCount = parseInt(card.getAttribute('data-damaged') || '0');
|
||||
|
||||
totalMissing += missingCount;
|
||||
totalDamaged += damagedCount;
|
||||
allSetIds.push(set.setId);
|
||||
});
|
||||
|
||||
// Create grouped card container
|
||||
const groupContainer = document.createElement('div');
|
||||
groupContainer.className = firstSet.cardCol.className + ' set-group-container';
|
||||
groupContainer.innerHTML = `
|
||||
<div class="card set-group-card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<div class="d-flex align-items-center">
|
||||
<button class="btn btn-sm btn-outline-primary me-2 group-toggle-btn"
|
||||
type="button" data-bs-toggle="collapse"
|
||||
data-bs-target="#group-${setGroup[0].rebrickableId}"
|
||||
aria-expanded="false">
|
||||
<i class="ri-arrow-right-line"></i>
|
||||
</button>
|
||||
<span class="fw-bold">${firstCard.querySelector('.card-title')?.textContent || 'Set'}</span>
|
||||
<span class="badge bg-secondary ms-2">${setGroup.length} sets</span>
|
||||
</div>
|
||||
<div class="d-flex gap-1">
|
||||
${totalMissing > 0 ? `<span class="badge bg-warning text-dark">${totalMissing} missing</span>` : ''}
|
||||
${totalDamaged > 0 ? `<span class="badge bg-danger">${totalDamaged} damaged</span>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse" id="group-${setGroup[0].rebrickableId}">
|
||||
<div class="card-body">
|
||||
<div class="row set-group-items"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Add individual set cards to the group
|
||||
const groupItems = groupContainer.querySelector('.set-group-items');
|
||||
setGroup.forEach(set => {
|
||||
const itemContainer = document.createElement('div');
|
||||
itemContainer.className = 'col-12 mb-2';
|
||||
|
||||
// Clone the original card but make it smaller
|
||||
const clonedCard = set.cardCol.querySelector('.card').cloneNode(true);
|
||||
clonedCard.classList.add('set-group-item');
|
||||
|
||||
itemContainer.appendChild(clonedCard);
|
||||
groupItems.appendChild(itemContainer);
|
||||
|
||||
// Hide the original card
|
||||
set.cardCol.style.display = 'none';
|
||||
set.cardCol.classList.add('grouped-set-hidden');
|
||||
});
|
||||
|
||||
// Insert the grouped container before the first hidden set
|
||||
firstSet.cardCol.parentNode.insertBefore(groupContainer, firstSet.cardCol);
|
||||
|
||||
// Add event listener to toggle arrow icon
|
||||
const toggleBtn = groupContainer.querySelector('.group-toggle-btn');
|
||||
const collapseElement = groupContainer.querySelector('.collapse');
|
||||
|
||||
collapseElement.addEventListener('shown.bs.collapse', () => {
|
||||
toggleBtn.querySelector('i').className = 'ri-arrow-down-line';
|
||||
});
|
||||
|
||||
collapseElement.addEventListener('hidden.bs.collapse', () => {
|
||||
toggleBtn.querySelector('i').className = 'ri-arrow-right-line';
|
||||
});
|
||||
}
|
||||
|
||||
function removeSetGrouping() {
|
||||
// Show all hidden sets
|
||||
const hiddenSets = document.querySelectorAll('.grouped-set-hidden');
|
||||
hiddenSets.forEach(setCol => {
|
||||
setCol.style.display = '';
|
||||
setCol.classList.remove('grouped-set-hidden');
|
||||
});
|
||||
|
||||
// Remove all group containers
|
||||
const groupContainers = document.querySelectorAll('.set-group-container');
|
||||
groupContainers.forEach(container => {
|
||||
container.remove();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// Peeron Socket class
|
||||
class BrickPeeronSocket extends BrickSocket {
|
||||
constructor(id, path, namespace, messages) {
|
||||
super(id, path, namespace, messages, true);
|
||||
|
||||
// Form elements (built based on the initial id)
|
||||
this.html_button = document.getElementById(id);
|
||||
this.html_files = document.getElementById(`${id}-files`);
|
||||
|
||||
if (this.html_button) {
|
||||
this.html_button.addEventListener("click", (e) => {
|
||||
this.execute();
|
||||
});
|
||||
}
|
||||
|
||||
// Setup select all button
|
||||
this.setup_select_all_button();
|
||||
|
||||
// Setup rotation buttons
|
||||
this.setup_rotation_buttons();
|
||||
|
||||
// Setup the socket
|
||||
this.setup();
|
||||
}
|
||||
|
||||
setup_select_all_button() {
|
||||
const selectAllButton = document.getElementById('peeron-select-all');
|
||||
if (selectAllButton) {
|
||||
selectAllButton.addEventListener('click', () => {
|
||||
const checkboxes = this.get_files();
|
||||
const allChecked = checkboxes.every(cb => cb.checked);
|
||||
checkboxes.forEach(cb => cb.checked = !allChecked);
|
||||
|
||||
// Update button text and icon
|
||||
if (allChecked) {
|
||||
selectAllButton.innerHTML = '<i class="ri-checkbox-multiple-line"></i> Select All';
|
||||
} else {
|
||||
selectAllButton.innerHTML = '<i class="ri-checkbox-blank-line"></i> Deselect All';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setup_rotation_buttons() {
|
||||
document.querySelectorAll('.peeron-rotate-btn').forEach(button => {
|
||||
button.addEventListener('click', (e) => {
|
||||
e.preventDefault(); // Prevent label click
|
||||
e.stopPropagation(); // Stop event bubbling
|
||||
|
||||
const targetId = button.getAttribute('data-target');
|
||||
const checkboxId = button.getAttribute('data-checkbox');
|
||||
const targetImg = document.getElementById(targetId);
|
||||
const checkbox = document.getElementById(checkboxId);
|
||||
|
||||
if (targetImg && checkbox) {
|
||||
let currentRotation = parseInt(button.getAttribute('data-rotation') || '0');
|
||||
currentRotation = (currentRotation + 90) % 360;
|
||||
|
||||
// Update image rotation
|
||||
targetImg.style.transform = `rotate(${currentRotation}deg)`;
|
||||
button.setAttribute('data-rotation', currentRotation.toString());
|
||||
|
||||
// Store rotation in checkbox data for later use
|
||||
checkbox.setAttribute('data-rotation', currentRotation.toString());
|
||||
|
||||
// Update the rotation icon to indicate current state
|
||||
const icon = button.querySelector('i');
|
||||
if (icon) {
|
||||
// Rotate the icon to match the image rotation
|
||||
icon.style.transform = `rotate(${currentRotation}deg)`;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Upon receiving a complete message
|
||||
complete(data) {
|
||||
super.complete(data);
|
||||
|
||||
// Clear progress display after completion
|
||||
if (this.html_progress_message) {
|
||||
this.html_progress_message.classList.add("d-none");
|
||||
this.html_progress_message.textContent = "";
|
||||
}
|
||||
|
||||
if (this.html_count) {
|
||||
this.html_count.classList.add("d-none");
|
||||
this.html_count.textContent = "";
|
||||
}
|
||||
|
||||
// Ensure spinner is hidden
|
||||
this.spinner(false);
|
||||
|
||||
this.toggle(true);
|
||||
}
|
||||
|
||||
// Execute the action
|
||||
execute() {
|
||||
if (!this.disabled && this.socket !== undefined && this.socket.connected) {
|
||||
this.toggle(false);
|
||||
|
||||
this.download_peeron_pages();
|
||||
}
|
||||
}
|
||||
|
||||
// Get the list of checkboxes describing files
|
||||
get_files(checked=false) {
|
||||
let files = [];
|
||||
|
||||
if (this.html_files) {
|
||||
files = [...this.html_files.querySelectorAll('input[type="checkbox"]')];
|
||||
|
||||
if (checked) {
|
||||
files = files.filter(file => file.checked);
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
// Download Peeron pages
|
||||
download_peeron_pages() {
|
||||
if (this.html_files) {
|
||||
const selectedFiles = this.get_files(true);
|
||||
|
||||
if (selectedFiles.length === 0) {
|
||||
this.fail({message: "Please select at least one page to download."});
|
||||
this.toggle(true);
|
||||
return;
|
||||
}
|
||||
|
||||
const pages = selectedFiles.map(checkbox => ({
|
||||
page_number: checkbox.getAttribute('data-page-number'),
|
||||
original_image_url: checkbox.getAttribute('data-original-image-url'),
|
||||
cached_full_image_path: checkbox.getAttribute('data-cached-full-image-path'),
|
||||
alt_text: checkbox.getAttribute('data-alt-text'),
|
||||
rotation: parseInt(checkbox.getAttribute('data-rotation') || '0')
|
||||
}));
|
||||
|
||||
this.clear();
|
||||
this.spinner(true);
|
||||
|
||||
const setElement = document.querySelector('input[name="download-set"]');
|
||||
const set = setElement ? setElement.value : '';
|
||||
|
||||
this.socket.emit(this.messages.DOWNLOAD_PEERON_PAGES, {
|
||||
set: set,
|
||||
pages: pages,
|
||||
total: pages.length,
|
||||
current: 0
|
||||
});
|
||||
} else {
|
||||
this.fail({message: "Could not find the list of pages to download"});
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle clicking on the button, or sending events
|
||||
toggle(enabled) {
|
||||
super.toggle(enabled);
|
||||
|
||||
if (this.html_files) {
|
||||
this.get_files().forEach(el => el.disabled = !enabled);
|
||||
}
|
||||
|
||||
if (this.html_button) {
|
||||
this.html_button.disabled = !enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Simple Peeron page loader using standard socket pattern
|
||||
class BrickPeeronPageLoader extends BrickSocket {
|
||||
constructor(set, path, namespace, messages) {
|
||||
// Use 'peeron-loader' as the ID for socket elements
|
||||
super('peeron-loader', path, namespace, messages, false);
|
||||
|
||||
this.set = set;
|
||||
this.setup();
|
||||
|
||||
// Auto-start loading when connected
|
||||
setTimeout(() => {
|
||||
if (this.socket && this.socket.connected) {
|
||||
this.loadPages();
|
||||
} else {
|
||||
this.socket.on('connect', () => this.loadPages());
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
loadPages() {
|
||||
this.socket.emit(this.messages.LOAD_PEERON_PAGES, {
|
||||
set: this.set
|
||||
});
|
||||
}
|
||||
|
||||
// Override complete to redirect when done
|
||||
complete(data) {
|
||||
super.complete(data);
|
||||
// Redirect to show the pages selection interface
|
||||
const params = new URLSearchParams();
|
||||
params.set('set', this.set);
|
||||
params.set('peeron_loaded', '1');
|
||||
window.location.href = `${window.location.pathname}?${params.toString()}`;
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,67 @@
|
||||
max-width: 150px;
|
||||
}
|
||||
|
||||
/* Checkbox column width constraint */
|
||||
.table-td-input:has(.form-check-input[type="checkbox"]) {
|
||||
width: 120px;
|
||||
max-width: 120px;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
/* Reserve space for status icon to prevent layout shift */
|
||||
.form-check-label i[id^="status-"] {
|
||||
display: inline-block;
|
||||
width: 1.2em;
|
||||
text-align: center;
|
||||
margin-left: 0.25rem;
|
||||
}
|
||||
|
||||
/* Hamburger menu styling */
|
||||
.table th .dropdown {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.table th .dropdown-toggle {
|
||||
border-radius: 0.375rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.25rem;
|
||||
border-color: #6c757d;
|
||||
}
|
||||
|
||||
.table th .dropdown-toggle:focus {
|
||||
box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
|
||||
}
|
||||
|
||||
.table th .dropdown-toggle:hover {
|
||||
background-color: #f8f9fa;
|
||||
border-color: #6c757d;
|
||||
}
|
||||
|
||||
/* Style dropdown items */
|
||||
.dropdown-menu .dropdown-header {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
color: #6c757d;
|
||||
padding: 0.25rem 1rem;
|
||||
}
|
||||
|
||||
.dropdown-menu .dropdown-item {
|
||||
font-size: 0.875rem;
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
|
||||
.dropdown-menu .dropdown-item:hover {
|
||||
background-color: #f8f9fa;
|
||||
color: #212529;
|
||||
}
|
||||
|
||||
.dropdown-menu .dropdown-item i {
|
||||
width: 1.25rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Fixes for sortable.js */
|
||||
.sortable {
|
||||
--th-color: #000 !important;
|
||||
@@ -99,4 +160,22 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* Partial Status Checkbox Styling */
|
||||
.partial-status {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.partial-status::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
right: 2px;
|
||||
bottom: 2px;
|
||||
background: #6f42c1;
|
||||
border-radius: 2px;
|
||||
opacity: 0.8;
|
||||
pointer-events: none;
|
||||
}
|
||||
@@ -105,6 +105,13 @@
|
||||
{% if request.endpoint == 'set.list' %}
|
||||
<script src="{{ url_for('static', filename='scripts/sets.js') }}"></script>
|
||||
{% endif %}
|
||||
{% if request.endpoint == 'set.details' %}
|
||||
<script src="{{ url_for('static', filename='scripts/parts-bulk-operations.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='scripts/set-details.js') }}"></script>
|
||||
{% endif %}
|
||||
{% if request.endpoint == 'instructions.download' or request.endpoint == 'instructions.do_download' %}
|
||||
<script src="{{ url_for('static', filename='scripts/socket/peeron.js') }}"></script>
|
||||
{% endif %}
|
||||
<script type="text/javascript">
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
setup_grids();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
{% if g.login.is_authenticated() %}
|
||||
<p class="border-bottom pb-2 px-2 text-center">
|
||||
<a class="btn btn-primary" href="{{ url_for('instructions.upload') }}"><i class="ri-upload-line"></i> Upload an instructions file</a>
|
||||
<a class="btn btn-primary" href="{{ url_for('instructions.download') }}"><i class="ri-download-line"></i> Download instructions from Rebrickable</a>
|
||||
<a class="btn btn-primary" href="{{ url_for('instructions.download') }}"><i class="ri-download-line"></i> Download instructions</a>
|
||||
<a href="{{ url_for('admin.admin', open_instructions=true) }}" class="btn btn-light border" role="button"><i class="ri-refresh-line"></i> Refresh the instructions cache</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<form method="POST" action="{{ url_for('instructions.do_download') }}">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0"><i class="ri-download-line"></i> Download instructions from Rebrickable</h5>
|
||||
<h5 class="mb-0"><i class="ri-download-line"></i> Download instructions</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<script type="text/javascript">
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
new BrickPeeronPageLoader(
|
||||
'{{ set }}',
|
||||
'{{ path }}',
|
||||
'{{ namespace }}',
|
||||
{
|
||||
COMPLETE: '{{ messages['COMPLETE'] }}',
|
||||
FAIL: '{{ messages['FAIL'] }}',
|
||||
LOAD_PEERON_PAGES: '{{ messages['LOAD_PEERON_PAGES'] }}',
|
||||
PROGRESS: '{{ messages['PROGRESS'] }}',
|
||||
}
|
||||
);
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,10 @@
|
||||
<script type="text/javascript">
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
new BrickPeeronSocket('peeron-download', '{{ path }}', '{{ namespace }}', {
|
||||
COMPLETE: '{{ messages['COMPLETE'] }}',
|
||||
DOWNLOAD_PEERON_PAGES: 'download_peeron_pages',
|
||||
FAIL: '{{ messages['FAIL'] }}',
|
||||
PROGRESS: '{{ messages['PROGRESS'] }}',
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -1,4 +1,4 @@
|
||||
{% macro header(title, id, parent, quantity=none, expanded=false, icon=none, class=none, danger=none, image=none, alt=none) %}
|
||||
{% macro header(title, id, parent, quantity=none, expanded=false, icon=none, class=none, danger=none, image=none, alt=none, hamburger_menu=none) %}
|
||||
{% if danger %}
|
||||
{% set icon='alert-fill' %}
|
||||
{% endif %}
|
||||
@@ -43,10 +43,10 @@
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro table(table_collection, title, id, parent, target, quantity=none, icon=none, image=none, alt=none, details=none, read_only=none) %}
|
||||
{% macro table(table_collection, title, id, parent, target, quantity=none, icon=none, image=none, alt=none, details=none, read_only=none, hamburger_menu=none) %}
|
||||
{% set size=table_collection | length %}
|
||||
{% if size %}
|
||||
{{ header(title, id, parent, quantity=quantity, icon=icon, class='p-0', image=image, alt=alt) }}
|
||||
{{ header(title, id, parent, quantity=quantity, icon=icon, class='p-0', image=image, alt=alt, hamburger_menu=hamburger_menu) }}
|
||||
{% if details %}
|
||||
<p class="border-top border-bottom p-2 text-center">
|
||||
{% if image %}
|
||||
@@ -57,7 +57,7 @@
|
||||
<a class="btn border bg-secondary-text" href="{{ details }}">{% if icon %}<i class="ri-{{ icon }}"></i>{% endif %} Details</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% with solo=true, all=false %}
|
||||
{% with solo=true, all=false, accordion_id=id %}
|
||||
{% include target %}
|
||||
{% endwith %}
|
||||
{{ footer() }}
|
||||
|
||||
+52
-12
@@ -75,14 +75,34 @@
|
||||
{% endmacro %}
|
||||
|
||||
{% macro purchase_location(item, purchase_locations, solo=false, last=false) %}
|
||||
{% if purchase_locations and item.fields.purchase_location in purchase_locations.mapping %}
|
||||
{% set purchase_location = purchase_locations.mapping[item.fields.purchase_location] %}
|
||||
{% if last %}
|
||||
{% set tooltip=purchase_location.fields.name %}
|
||||
{% if purchase_locations and item.fields.purchase_location %}
|
||||
{% if '|' in item.fields.purchase_location or ',' in item.fields.purchase_location %}
|
||||
{# Consolidated mode - multiple purchase locations #}
|
||||
{% set separator = '|' if '|' in item.fields.purchase_location else ',' %}
|
||||
{% set location_list = item.fields.purchase_location.split(separator) %}
|
||||
{% for location_id in location_list %}
|
||||
{% if location_id and location_id.strip() and location_id.strip() in purchase_locations.mapping %}
|
||||
{% set purchase_location = purchase_locations.mapping[location_id.strip()] %}
|
||||
{% if last %}
|
||||
{% set tooltip=purchase_location.fields.name %}
|
||||
{% else %}
|
||||
{% set text=purchase_location.fields.name %}
|
||||
{% endif %}
|
||||
{{ badge(check=purchase_location, solo=solo, last=last, color='light border', icon='building-line', text=text, tooltip=tooltip, collapsible='Location:') }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% set text=purchase_location.fields.name %}
|
||||
{# Single purchase location #}
|
||||
{% if item.fields.purchase_location.strip() and item.fields.purchase_location.strip() in purchase_locations.mapping %}
|
||||
{% set purchase_location = purchase_locations.mapping[item.fields.purchase_location.strip()] %}
|
||||
{% if last %}
|
||||
{% set tooltip=purchase_location.fields.name %}
|
||||
{% else %}
|
||||
{% set text=purchase_location.fields.name %}
|
||||
{% endif %}
|
||||
{{ badge(check=purchase_location, solo=solo, last=last, color='light border', icon='building-line', text=text, tooltip=tooltip, collapsible='Location:') }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{{ badge(check=purchase_location, solo=solo, last=last, color='light border', icon='building-line', text=text, tooltip=tooltip, collapsible='Location:') }}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
@@ -103,14 +123,34 @@
|
||||
{% endmacro %}
|
||||
|
||||
{% macro storage(item, storages, solo=false, last=false) %}
|
||||
{% if storages and item.fields.storage in storages.mapping %}
|
||||
{% set storage = storages.mapping[item.fields.storage] %}
|
||||
{% if last %}
|
||||
{% set tooltip=storage.fields.name %}
|
||||
{% if storages and item.fields.storage %}
|
||||
{% if '|' in item.fields.storage or ',' in item.fields.storage %}
|
||||
{# Consolidated mode - multiple storage locations #}
|
||||
{% set separator = '|' if '|' in item.fields.storage else ',' %}
|
||||
{% set storage_list = item.fields.storage.split(separator) %}
|
||||
{% for storage_id in storage_list %}
|
||||
{% if storage_id and storage_id.strip() and storage_id.strip() in storages.mapping %}
|
||||
{% set storage = storages.mapping[storage_id.strip()] %}
|
||||
{% if last %}
|
||||
{% set tooltip=storage.fields.name %}
|
||||
{% else %}
|
||||
{% set text=storage.fields.name %}
|
||||
{% endif %}
|
||||
{{ badge(url=storage.url(), solo=solo, last=last, color='light text-warning-emphasis bg-warning-subtle border border-warning-subtle', icon='archive-2-line', text=text, alt='Storage', tooltip=tooltip) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% set text=storage.fields.name %}
|
||||
{# Single storage location #}
|
||||
{% if item.fields.storage.strip() and item.fields.storage.strip() in storages.mapping %}
|
||||
{% set storage = storages.mapping[item.fields.storage.strip()] %}
|
||||
{% if last %}
|
||||
{% set tooltip=storage.fields.name %}
|
||||
{% else %}
|
||||
{% set text=storage.fields.name %}
|
||||
{% endif %}
|
||||
{{ badge(url=storage.url(), solo=solo, last=last, color='light text-warning-emphasis bg-warning-subtle border border-warning-subtle', icon='archive-2-line', text=text, alt='Storage', tooltip=tooltip) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{{ badge(url=item.url_for_storage(), solo=solo, last=last, color='light text-warning-emphasis bg-warning-subtle border border-warning-subtle', icon='archive-2-line', text=text, alt='Storage', tooltip=tooltip) }}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% macro header(image=true, color=false, parts=false, quantity=false, missing=true, missing_parts=false, damaged=true, damaged_parts=false, sets=false, minifigures=false) %}
|
||||
{% macro header(image=true, color=false, parts=false, quantity=false, missing=true, missing_parts=false, damaged=true, damaged_parts=false, sets=false, minifigures=false, checked=false, hamburger_menu=false, accordion_id='') %}
|
||||
<thead>
|
||||
<tr>
|
||||
{% if image %}
|
||||
@@ -26,6 +26,37 @@
|
||||
{% if minifigures %}
|
||||
<th data-table-number="true" scope="col"><i class="ri-group-line fw-normal"></i> Minifigures</th>
|
||||
{% endif %}
|
||||
{% if checked and not config['HIDE_TABLE_CHECKED_PARTS'] %}
|
||||
<th data-table-no-sort-and-search="true" class="no-sort" scope="col"><i class="ri-checkbox-line fw-normal"></i> Checked</th>
|
||||
{% endif %}
|
||||
{% if hamburger_menu and g.login.is_authenticated() %}
|
||||
{% set show_missing_menu = not config['HIDE_TABLE_MISSING_PARTS'] %}
|
||||
{% set show_checked_menu = not config['HIDE_TABLE_CHECKED_PARTS'] %}
|
||||
{% if show_missing_menu or show_checked_menu %}
|
||||
<th data-table-no-sort-and-search="true" class="no-sort text-end" scope="col">
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="hamburger-{{ accordion_id }}" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="ri-menu-line"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="hamburger-{{ accordion_id }}">
|
||||
{% if show_missing_menu %}
|
||||
<li><h6 class="dropdown-header">Missing Parts</h6></li>
|
||||
<li><a class="dropdown-item" href="#" id="mark-all-missing-{{ accordion_id }}"><i class="ri-question-line me-2"></i>Mark all as missing</a></li>
|
||||
<li><a class="dropdown-item" href="#" id="clear-all-missing-{{ accordion_id }}"><i class="ri-close-circle-line me-2"></i>Clear all missing</a></li>
|
||||
{% endif %}
|
||||
{% if show_missing_menu and show_checked_menu %}
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
{% endif %}
|
||||
{% if show_checked_menu %}
|
||||
<li><h6 class="dropdown-header">Checked Status</h6></li>
|
||||
<li><a class="dropdown-item" href="#" id="check-all-{{ accordion_id }}"><i class="ri-checkbox-line me-2"></i>Check all</a></li>
|
||||
<li><a class="dropdown-item" href="#" id="uncheck-all-{{ accordion_id }}"><i class="ri-checkbox-blank-line me-2"></i>Uncheck all</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</th>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
{% endmacro %}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<div class="table-responsive-sm">
|
||||
<table data-table="{% if all %}true{% endif %}" class="table table-striped align-middle {% if not all %}sortable mb-0{% endif %}" {% if all %}id="parts"{% endif %}>
|
||||
{{ table.header(color=true, quantity=not no_quantity, sets=all, minifigures=all) }}
|
||||
{{ table.header(color=true, quantity=not no_quantity, sets=all, minifigures=all, checked=not all and not read_only, hamburger_menu=not all and not read_only, accordion_id=accordion_id|default('')) }}
|
||||
<tbody>
|
||||
{% for item in table_collection %}
|
||||
<tr>
|
||||
@@ -40,6 +40,19 @@
|
||||
{% if all %}
|
||||
<td>{{ item.fields.total_sets }}</td>
|
||||
<td>{{ item.fields.total_minifigures }}</td>
|
||||
{% else %}
|
||||
{% if not config['HIDE_TABLE_CHECKED_PARTS'] and not read_only %}
|
||||
<td class="table-td-input">
|
||||
<center>{{ form.checkbox('', item.fields.id, item.html_id('checked'), item.url_for_checked(), item.fields.checked | default(false), parent='part', delete=read_only) }}</center>
|
||||
</td>
|
||||
{% endif %}
|
||||
{% if g.login.is_authenticated() and not read_only %}
|
||||
{% set show_missing_menu = not config['HIDE_TABLE_MISSING_PARTS'] %}
|
||||
{% set show_checked_menu = not config['HIDE_TABLE_CHECKED_PARTS'] %}
|
||||
{% if show_missing_menu or show_checked_menu %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %} - Download instructions from Peeron{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div class="container">
|
||||
{% if error %}<div class="alert alert-danger" role="alert"><strong>Error:</strong> {{ error }}.</div>{% endif %}
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<form method="POST" action="{{ url_for('instructions.do_download') }}">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0"><i class="ri-download-line"></i> Download instructions from Rebrickable</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label for="download-set" class="form-label">Set number (only one)</label>
|
||||
<input type="text" class="form-control" id="download-set" name="download-set" placeholder="107-1 or 1642-1 or ..." value="{{ set }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer text-end">
|
||||
<button type="submit" class="btn btn-primary"><i class="ri-search-line"></i> Search</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% if loading_peeron %}
|
||||
<div class="alert alert-info" role="alert">
|
||||
<i class="ri-information-line"></i> <strong>Found on Peeron:</strong> {{ set }} was not available on Rebrickable, loading instruction pages from Peeron...
|
||||
</div>
|
||||
|
||||
<!-- Socket elements for peeron-loader -->
|
||||
<div id="peeron-loader-fail" class="alert alert-danger d-none" role="alert"></div>
|
||||
<div id="peeron-loader-complete" class="alert alert-success d-none" role="alert"></div>
|
||||
<div class="mb-3">
|
||||
<p>
|
||||
Progress <span id="peeron-loader-count"></span>
|
||||
<span id="peeron-loader-spinner" class="d-none">
|
||||
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
|
||||
<span class="visually-hidden" role="status">Loading...</span>
|
||||
</span>
|
||||
</p>
|
||||
<div id="peeron-loader-progress" class="progress" role="progressbar" aria-label="Loading Peeron pages" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
|
||||
<div id="peeron-loader-progress-bar" class="progress-bar" style="width: 0%"></div>
|
||||
</div>
|
||||
<p id="peeron-loader-progress-message" class="text-center d-none"></p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if loading_peeron %}
|
||||
<!-- Include socket for automatic loading -->
|
||||
{% with set=set, path=path, namespace=namespace, messages=messages %}
|
||||
{% include 'instructions/peeron_loader_socket.html' %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% if pages %}
|
||||
<div id="peeron-loading-alert" class="alert alert-info" role="alert">
|
||||
<i class="ri-information-line"></i> <strong>Instructions found on Peeron:</strong> {{ set }} was not available on Rebrickable, but {{ pages|length }} instruction pages were found on Peeron.
|
||||
<div id="peeron-cache-progress" class="mt-2 d-none">
|
||||
<div class="progress" role="progressbar" aria-label="Caching thumbnails" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
|
||||
<div id="peeron-cache-progress-bar" class="progress-bar" style="width: 0%"></div>
|
||||
</div>
|
||||
<small id="peeron-cache-message" class="text-muted">Caching thumbnails...</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0"><i class="ri-checkbox-line"></i> Select instructions to download</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<div id="peeron-download-fail" class="alert alert-danger d-none" role="alert"></div>
|
||||
<div id="peeron-download-complete"></div>
|
||||
<div class="d-flex justify-content-between align-items-center border-bottom mb-3">
|
||||
<h5 class="mb-0">Available Instructions</h5>
|
||||
<button id="peeron-select-all" type="button" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="ri-checkbox-multiple-line"></i> Select All
|
||||
</button>
|
||||
</div>
|
||||
<div id="peeron-download-files" class="row g-2">
|
||||
{% for page in pages %}
|
||||
<div class="col-12 col-md-6 col-lg-4">
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-body p-2">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="peeron-page-{{ loop.index }}"
|
||||
data-page-number="{{ page.page_number }}"
|
||||
data-original-image-url="{{ page.original_image_url }}"
|
||||
data-cached-full-image-path="{{ page.cached_full_image_path }}"
|
||||
data-alt-text="{{ page.alt_text }}"
|
||||
data-rotation="0"
|
||||
autocomplete="off">
|
||||
<label class="form-check-label w-100" for="peeron-page-{{ loop.index }}">
|
||||
<div class="text-center position-relative">
|
||||
<div class="position-relative d-inline-block">
|
||||
<img id="peeron-img-{{ loop.index }}" src="{{ page.cached_thumbnail_url }}" alt="{{ page.alt_text }}"
|
||||
class="img-fluid mb-2 border rounded peeron-thumbnail" style="max-height: 150px; transform: rotate(0deg); transition: transform 0.3s ease;"
|
||||
data-index="{{ loop.index }}" data-total="{{ pages|length }}">
|
||||
<button type="button" class="btn btn-sm btn-light position-absolute top-0 end-0 p-1 me-1 mt-1 peeron-rotate-btn"
|
||||
data-target="peeron-img-{{ loop.index }}" data-checkbox="peeron-page-{{ loop.index }}" data-rotation="0"
|
||||
title="Rotate page" style="font-size: 0.7rem; line-height: 1;">
|
||||
<i class="ri-refresh-line"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="small fw-bold">Page {{ page.page_number }}</div>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="mb-3">
|
||||
<p>
|
||||
Progress <span id="peeron-download-count"></span>
|
||||
<span id="peeron-download-spinner" class="d-none">
|
||||
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
|
||||
<span class="visually-hidden" role="status">Loading...</span>
|
||||
</span>
|
||||
</p>
|
||||
<div id="peeron-download-progress" class="progress" role="progressbar" aria-label="Download Peeron instructions progress" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
|
||||
<div id="peeron-download-progress-bar" class="progress-bar" style="width: 0%"></div>
|
||||
</div>
|
||||
<p id="peeron-download-progress-message" class="text-center d-none"></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer text-end">
|
||||
<span id="peeron-download-status-icon" class="me-1"></span><span id="peeron-download-status" class="me-1"></span><button id="peeron-download" type="button" class="btn btn-primary"><i class="ri-download-line"></i> Download selected files</button>
|
||||
</div>
|
||||
</div>
|
||||
{% if not loading_peeron %}
|
||||
<!-- Include normal socket for downloading -->
|
||||
{% include 'instructions/peeron_socket.html' %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
+45
-3
@@ -6,9 +6,51 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
{% with solo=true, delete=delete %}
|
||||
{% include 'set/card.html' %}
|
||||
{% endwith %}
|
||||
{% if all_instances and all_instances | length > 1 %}
|
||||
<!-- Multiple instances view with drawer-style header -->
|
||||
<div class="alert alert-info mb-3">
|
||||
<!-- Clickable drawer header -->
|
||||
<div class="d-flex justify-content-between align-items-center" style="cursor: pointer;" data-bs-toggle="collapse"
|
||||
data-bs-target="#all-instances" aria-expanded="false" aria-controls="all-instances">
|
||||
<div>
|
||||
<h4 class="mb-1">
|
||||
<i class="ri-stack-line me-2"></i>Multiple Copies Available
|
||||
<span class="badge bg-primary ms-2">{{ all_instances | length }}</span>
|
||||
</h4>
|
||||
<p class="mb-0">This set has {{ all_instances | length }} copies in your collection. Click to view all copies individually.</p>
|
||||
</div>
|
||||
<i class="ri-arrow-down-s-line fs-4" id="copies-toggle-icon"></i>
|
||||
</div>
|
||||
|
||||
<!-- Collapsible instances section -->
|
||||
<div class="collapse mt-3" id="all-instances">
|
||||
<div class="border-top pt-3">
|
||||
<div class="row">
|
||||
{% set current_item_id = item.fields.id %}
|
||||
{% for instance in all_instances %}
|
||||
<div class="col-md-6 col-xl-4 d-flex align-items-stretch mb-3">
|
||||
{% with item=instance, index=loop.index0, tiny=false, current_viewing=(instance.fields.id == current_item_id) %}
|
||||
<div class="position-relative w-100">
|
||||
{% include 'set/card.html' %}
|
||||
</div>
|
||||
{% endwith %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% with solo=true, delete=delete %}
|
||||
{% include 'set/card.html' %}
|
||||
{% endwith %}
|
||||
{% else %}
|
||||
<!-- Single instance view -->
|
||||
{% with solo=true, delete=delete %}
|
||||
{% include 'set/card.html' %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+45
-9
@@ -3,9 +3,11 @@
|
||||
{% import 'macro/card.html' as card %}
|
||||
{% import 'macro/form.html' as form %}
|
||||
|
||||
<div {% if not solo %}id="set-{{ item.fields.id }}"{% endif %} class="card mb-3 flex-fill {% if solo %}card-solo{% endif %}"
|
||||
<div {% if not solo %}id="set-{{ item.fields.consolidated_id or item.fields.id }}"{% endif %} class="card mb-3 flex-fill {% if solo %}card-solo{% endif %}{% if current_viewing %} border-secondary{% endif %}"{% if current_viewing %} style="border-width: 3px !important;"{% endif %}
|
||||
data-set-id="{{ item.fields.consolidated_id or item.fields.id }}" data-rebrickable-id="{{ item.fields.set }}"
|
||||
{% if item.fields.instance_count is defined %}data-instance-count="{{ item.fields.instance_count }}" data-instance-ids="{{ item.fields.instance_ids }}"{% endif %}
|
||||
{% if not solo and not tiny %}
|
||||
data-index="{{ index }}" data-number="{{ item.fields.set }}" data-name="{{ item.fields.name | lower }}" data-parts="{{ item.fields.number_of_parts }}"
|
||||
data-index="{{ index }}" data-number="{{ item.fields.set }}" data-set="{{ item.fields.set.split('-')[0] | int }}{{ '%05d' | format(item.fields.set.split('-')[1] | int) }}" data-name="{{ item.fields.name | lower }}" data-parts="{{ item.fields.number_of_parts }}"
|
||||
data-year="{{ item.fields.year }}" data-theme="{{ item.theme.name | lower }}"
|
||||
{% if not config['HIDE_SET_INSTRUCTIONS'] %}
|
||||
data-has-missing-instructions="{{ (item.instructions | length == 0) | int }}"
|
||||
@@ -54,7 +56,7 @@
|
||||
>
|
||||
{{ card.header(item, item.fields.name, solo=solo, identifier=item.fields.set) }}
|
||||
{{ card.image(item, solo=solo, last=last, caption=item.fields.name, alt=item.fields.set) }}
|
||||
<div class="card-body border-bottom-0 {% if not solo %}p-1{% endif %}">
|
||||
<div class="card-body border-bottom-0 {% if not solo %}p-1{% endif %}"{% if current_viewing %} style="border-color: var(--bs-border-color) !important; border-width: 1px !important;"{% endif %}>
|
||||
{{ badge.theme(item.theme.name, solo=solo, last=last) }}
|
||||
{% for tag in brickset_tags %}
|
||||
{{ badge.tag(item, tag, solo=solo, last=last) }}
|
||||
@@ -63,6 +65,9 @@
|
||||
{{ badge.year(item.fields.year, solo=solo, last=last) }}
|
||||
{% endif %}
|
||||
{{ badge.parts(item.fields.number_of_parts, solo=solo, last=last) }}
|
||||
{% if item.fields.instance_count is defined and item.fields.instance_count > 1 %}
|
||||
<span class="badge bg-primary"><i class="ri-stack-line"></i> {{ item.fields.instance_count }} copies</span>
|
||||
{% endif %}
|
||||
{{ badge.total_minifigures(item.fields.total_minifigures, solo=solo, last=last) }}
|
||||
{{ badge.total_missing(item.fields.total_missing, solo=solo, last=last) }}
|
||||
{{ badge.total_damaged(item.fields.total_damaged, solo=solo, last=last) }}
|
||||
@@ -81,14 +86,45 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if not tiny and brickset_statuses | length %}
|
||||
<ul class="list-group list-group-flush card-check border-bottom-0">
|
||||
<ul class="list-group list-group-flush card-check border-bottom-0"{% if current_viewing %} style="border-color: var(--bs-border-color) !important; border-width: 1px !important;"{% endif %}>
|
||||
{% for status in brickset_statuses %}
|
||||
<li class="d-flex list-group-item {% if not solo %}p-1{% endif %} text-nowrap">{{ form.checkbox(status.fields.name, item.fields.id, status.as_dataset(), status.url_for_set_state(item.fields.id), item.fields[status.as_column()], parent='set', delete=delete) }}</li>
|
||||
<li class="d-flex list-group-item {% if not solo %}p-1{% endif %} text-nowrap">
|
||||
{% if item.fields.instance_count is defined and item.fields.instance_count > 1 %}
|
||||
{# Consolidated set - show mixed status indicator #}
|
||||
{% set status_count = item.fields[status.as_column() + '_count'] %}
|
||||
{% set total_count = item.fields.instance_count %}
|
||||
{% if status_count == 0 %}
|
||||
{# None checked #}
|
||||
<input class="form-check-input px-1" type="checkbox" disabled>
|
||||
<label class="form-check-label">
|
||||
{{ status.fields.name }}
|
||||
<small class="text-muted ms-1">(0/{{ total_count }})</small>
|
||||
</label>
|
||||
{% elif status_count == total_count %}
|
||||
{# All checked #}
|
||||
<input class="form-check-input px-1" type="checkbox" checked disabled>
|
||||
<label class="form-check-label">
|
||||
{{ status.fields.name }}
|
||||
<small class="text-muted ms-1">({{ total_count }}/{{ total_count }})</small>
|
||||
</label>
|
||||
{% else %}
|
||||
{# Partial - some checked #}
|
||||
<input class="form-check-input px-1 partial-status" type="checkbox" disabled>
|
||||
<label class="form-check-label">
|
||||
{{ status.fields.name }}
|
||||
<small class="text-muted ms-1">({{ status_count }}/{{ total_count }})</small>
|
||||
</label>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{# Individual set - use normal checkbox #}
|
||||
{{ form.checkbox(status.fields.name, item.fields.id, status.as_dataset(), status.url_for_set_state(item.fields.id), item.fields[status.as_column()], parent='set', delete=delete) }}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% if solo %}
|
||||
<div class="accordion accordion-flush border-top" id="set-details">
|
||||
<div class="accordion accordion-flush border-top" id="set-details"{% if current_viewing %} style="border-color: var(--bs-border-color) !important; border-width: 1px !important;"{% endif %}>
|
||||
{% if not delete %}
|
||||
{% if not config['HIDE_SET_INSTRUCTIONS'] %}
|
||||
{{ accordion.header('Instructions', 'instructions', 'set-details', expanded=open_instructions, quantity=item.instructions | length, icon='file-line', class='p-0') }}
|
||||
@@ -104,14 +140,14 @@
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if g.login.is_authenticated() %}
|
||||
<a class="list-group-item list-group-item-action" href="{{ url_for('instructions.download', set=item.fields.set) }}"><i class="ri-download-line"></i> Download instructions from Rebrickable</a>
|
||||
<a class="list-group-item list-group-item-action" href="{{ url_for('instructions.download', set=item.fields.set) }}"><i class="ri-download-line"></i> Download instructions</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{{ accordion.footer() }}
|
||||
{% endif %}
|
||||
{{ accordion.table(item.parts(), 'Parts', 'parts-inventory', 'set-details', 'part/table.html', icon='shapes-line')}}
|
||||
{{ accordion.table(item.parts(), 'Parts', 'parts-inventory', 'set-details', 'part/table.html', icon='shapes-line', hamburger_menu=g.login.is_authenticated())}}
|
||||
{% for minifigure in item.minifigures() %}
|
||||
{{ accordion.table(minifigure.parts(), minifigure.fields.name, minifigure.fields.figure, 'set-details', 'part/table.html', quantity=minifigure.fields.quantity, icon='group-line', image=minifigure.url_for_image(), alt=minifigure.fields.figure, details=minifigure.url())}}
|
||||
{{ accordion.table(minifigure.parts(), minifigure.fields.name, minifigure.fields.figure, 'set-details', 'part/table.html', quantity=minifigure.fields.quantity, icon='group-line', image=minifigure.url_for_image(), alt=minifigure.fields.figure, details=minifigure.url(), hamburger_menu=g.login.is_authenticated())}}
|
||||
{% endfor %}
|
||||
{% include 'set/management.html' %}
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user