Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 21d104280c | |||
| 5946f86dfa | |||
| 0155144881 | |||
| 1353153394 | |||
| 0f45192f8e | |||
| b02f851865 | |||
| bddfbb5235 | |||
| dc34916331 | |||
| a8d36bc5f1 | |||
| bd32ca5b8f | |||
| 2ed60e3fe3 | |||
| 0ec1d37c36 |
+65
-112
@@ -1,23 +1,3 @@
|
||||
# ================================================================================================
|
||||
# BrickTracker Configuration File
|
||||
# ================================================================================================
|
||||
#
|
||||
# FILE LOCATION (v1.3+):
|
||||
# ----------------------
|
||||
# This file can be placed in two locations:
|
||||
# 1. data/.env (RECOMMENDED) - Included in data volume backup, settings persist via admin panel
|
||||
# 2. .env (root) - Backward compatible
|
||||
#
|
||||
# Priority: data/.env > .env (root)
|
||||
#
|
||||
# The application automatically detects and uses the correct location at runtime.
|
||||
#
|
||||
# For Docker:
|
||||
# - Recommended: Place this file as data/.env (included in data volume)
|
||||
# - Backward compatible: Keep as .env in root (add "env_file: .env" to compose.yaml)
|
||||
#
|
||||
# ================================================================================================
|
||||
#
|
||||
# Note on *_DEFAULT_ORDER
|
||||
# If set, it will append a direct ORDER BY <whatever you set> to the SQL query
|
||||
# while listing objects. You can look at the structure of the SQLite database to
|
||||
@@ -61,11 +41,11 @@
|
||||
# Default: false
|
||||
# BK_BRICKLINK_LINKS=true
|
||||
|
||||
# Optional: Path to the database, relative to '/app/' folder
|
||||
# Optional: Path to the database.
|
||||
# Useful if you need it mounted in a Docker volume. Keep in mind that it will not
|
||||
# do any check on the existence of the path, or if it is dangerous.
|
||||
# Default: data/app.db
|
||||
# BK_DATABASE_PATH=data/app.db
|
||||
# Default: ./app.db
|
||||
# BK_DATABASE_PATH=/var/lib/bricktracker/app.db
|
||||
|
||||
# Optional: Format of the timestamp added to the database file when downloading it
|
||||
# Check https://docs.python.org/3/library/time.html#time.strftime for format details
|
||||
@@ -81,6 +61,10 @@
|
||||
# Default: 25
|
||||
# BK_DEFAULT_TABLE_PER_PAGE=50
|
||||
|
||||
# Optional: Maximum length for description text in badges before truncating with ellipsis
|
||||
# Default: 15
|
||||
# BK_DESCRIPTION_BADGE_MAX_LENGTH=15
|
||||
|
||||
# Optional: if set up, will add a CORS allow origin restriction to the socket.
|
||||
# Default:
|
||||
# Legacy name: DOMAIN_NAME
|
||||
@@ -106,9 +90,9 @@
|
||||
# Default: .pdf
|
||||
# BK_INSTRUCTIONS_ALLOWED_EXTENSIONS=.pdf, .docx, .png
|
||||
|
||||
# Optional: Folder where to store the instructions, relative to '/app/' folder
|
||||
# Default: data/instructions
|
||||
# BK_INSTRUCTIONS_FOLDER=data/instructions
|
||||
# Optional: Folder where to store the instructions, relative to the '/app/static/' folder
|
||||
# Default: instructions
|
||||
# BK_INSTRUCTIONS_FOLDER=/var/lib/bricktracker/instructions/
|
||||
|
||||
# Optional: Hide the 'Add' entry from the menu. Does not disable the route.
|
||||
# Default: false
|
||||
@@ -138,6 +122,13 @@
|
||||
# Default: false
|
||||
# BK_HIDE_ALL_MINIFIGURES=true
|
||||
|
||||
# Optional: Disable the individual/loose minifigures system. This hides all individual
|
||||
# minifigure UI elements and prevents adding new individual minifigures. The routes remain
|
||||
# accessible so existing individual minifigures can still be viewed. Users who only track
|
||||
# set-based minifigures can use this to simplify the interface. Does not disable the route.
|
||||
# Default: false
|
||||
# BK_DISABLE_INDIVIDUAL_MINIFIGURES=false
|
||||
|
||||
# Optional: Hide the 'Parts' entry from the menu. Does not disable the route.
|
||||
# Default: false
|
||||
# BK_HIDE_ALL_PARTS=true
|
||||
@@ -180,24 +171,19 @@
|
||||
# BK_HIDE_WISHES=true
|
||||
|
||||
# Optional: Change the default order of minifigures. By default ordered by insertion order.
|
||||
# Note: Minifigures are queried from a combined view that merges both set-based and individual minifigures.
|
||||
# Therefore, column references should use the "combined" table alias.
|
||||
# Useful column names for this option are:
|
||||
# - "rebrickable_minifigures"."figure": minifigure ID (e.g., "fig-001234")
|
||||
# - "rebrickable_minifigures"."number": minifigure ID as an integer (e.g., 1234)
|
||||
# - "rebrickable_minifigures"."name": minifigure name
|
||||
# - "rebrickable_minifigures"."number_of_parts": number of parts in the minifigure
|
||||
# - "bricktracker_minifigures"."quantity": quantity owned
|
||||
# - "total_missing": number of missing parts (composite field)
|
||||
# - "total_damaged": number of damaged parts (composite field)
|
||||
# - "total_quantity": total quantity across all sets (composite field)
|
||||
# - "total_sets": number of sets containing this minifigure (composite field)
|
||||
# Default: "rebrickable_minifigures"."name" ASC
|
||||
# Examples:
|
||||
# BK_MINIFIGURES_DEFAULT_ORDER="rebrickable_minifigures"."number" DESC
|
||||
# BK_MINIFIGURES_DEFAULT_ORDER="total_missing" DESC, "rebrickable_minifigures"."name" ASC
|
||||
# - "combined"."figure": minifigure ID (fig-xxxxx)
|
||||
# - "combined"."number": minifigure ID as an integer (xxxxx)
|
||||
# - "combined"."name": minifigure name
|
||||
# - "combined"."rowid": insertion order (for both set and individual minifigures)
|
||||
# Default: "combined"."name" ASC
|
||||
# BK_MINIFIGURES_DEFAULT_ORDER="combined"."name" ASC
|
||||
|
||||
# Optional: Folder where to store the minifigures images, relative to '/app/' folder
|
||||
# Default: data/minifigures
|
||||
# BK_MINIFIGURES_FOLDER=data/minifigures
|
||||
# Optional: Folder where to store the minifigures images, relative to the '/app/static/' folder
|
||||
# Default: minifigs
|
||||
# BK_MINIFIGURES_FOLDER=minifigures
|
||||
|
||||
# Optional: Disable threading on the task executed by the socket.
|
||||
# You should not need to change this parameter unless you are debugging something with the
|
||||
@@ -206,27 +192,20 @@
|
||||
# BK_NO_THREADED_SOCKET=true
|
||||
|
||||
# Optional: Change the default order of parts. By default ordered by insertion order.
|
||||
# Note: Parts are queried from a combined view that merges both set-based and individual minifigure parts.
|
||||
# Some columns use the "combined" table alias for fields from the merged view.
|
||||
# Useful column names for this option are:
|
||||
# - "bricktracker_parts"."part": part number (e.g., "3001")
|
||||
# - "bricktracker_parts"."spare": part is a spare part (0 or 1)
|
||||
# - "bricktracker_parts"."quantity": quantity of this part
|
||||
# - "bricktracker_parts"."missing": number of missing parts
|
||||
# - "bricktracker_parts"."damaged": number of damaged parts
|
||||
# - "combined"."part": part number
|
||||
# - "combined"."spare": part is a spare part (use "combined" not "bricktracker_parts")
|
||||
# - "rebrickable_parts"."name": part name
|
||||
# - "rebrickable_parts"."color_name": part color name
|
||||
# - "total_missing": total missing across all sets (composite field)
|
||||
# - "total_damaged": total damaged across all sets (composite field)
|
||||
# - "total_quantity": total quantity across all sets (composite field)
|
||||
# - "total_sets": number of sets containing this part (composite field)
|
||||
# - "total_minifigures": number of minifigures with this part (composite field)
|
||||
# Default: "rebrickable_parts"."name" ASC, "rebrickable_parts"."color_name" ASC, "bricktracker_parts"."spare" ASC
|
||||
# Examples:
|
||||
# - "total_missing": number of missing parts
|
||||
# Default: "rebrickable_parts"."name" ASC, "rebrickable_parts"."color_name" ASC, "combined"."spare" ASC
|
||||
# BK_PARTS_DEFAULT_ORDER="total_missing" DESC, "rebrickable_parts"."name" ASC
|
||||
# BK_PARTS_DEFAULT_ORDER="rebrickable_parts"."color_name" ASC, "rebrickable_parts"."name" ASC
|
||||
|
||||
# Optional: Folder where to store the parts images, relative to '/app/' folder
|
||||
# Default: data/parts
|
||||
# BK_PARTS_FOLDER=data/parts
|
||||
# Optional: Folder where to store the parts images, relative to the '/app/static/' folder
|
||||
# Default: parts
|
||||
# BK_PARTS_FOLDER=parts
|
||||
|
||||
# Optional: Enable server-side pagination for individual pages (recommended for large collections)
|
||||
# When enabled, pages use server-side pagination with configurable page sizes
|
||||
@@ -284,12 +263,9 @@
|
||||
|
||||
# Optional: Change the default order of purchase locations. By default ordered by insertion order.
|
||||
# Useful column names for this option are:
|
||||
# - "bricktracker_metadata_purchase_locations"."name": purchase location name
|
||||
# - "bricktracker_metadata_purchase_locations"."rowid": insertion order (special column)
|
||||
# - "bricktracker_metadata_purchase_locations"."name" ASC: storage name
|
||||
# Default: "bricktracker_metadata_purchase_locations"."name" ASC
|
||||
# Examples:
|
||||
# BK_PURCHASE_LOCATION_DEFAULT_ORDER="bricktracker_metadata_purchase_locations"."name" DESC
|
||||
# BK_PURCHASE_LOCATION_DEFAULT_ORDER="bricktracker_metadata_purchase_locations"."rowid" DESC
|
||||
# BK_PURCHASE_LOCATION_DEFAULT_ORDER="bricktracker_metadata_purchase_locations"."name" ASC
|
||||
|
||||
# Optional: Shuffle the lists on the front page.
|
||||
# Default: false
|
||||
@@ -305,23 +281,23 @@
|
||||
|
||||
# Optional: URL of the image representing a missing image in Rebrickable
|
||||
# Default: https://rebrickable.com/static/img/nil.png
|
||||
# BK_REBRICKABLE_IMAGE_NIL=https://rebrickable.com/static/img/nil.png
|
||||
# BK_REBRICKABLE_IMAGE_NIL=
|
||||
|
||||
# Optional: URL of the image representing a missing minifigure image in Rebrickable
|
||||
# Default: https://rebrickable.com/static/img/nil_mf.jpg
|
||||
# BK_REBRICKABLE_IMAGE_NIL_MINIFIGURE=https://rebrickable.com/static/img/nil_mf.jpg
|
||||
# BK_REBRICKABLE_IMAGE_NIL_MINIFIGURE=
|
||||
|
||||
# Optional: Pattern of the link to Rebrickable for a minifigure. Will be passed to Python .format()
|
||||
# Default: https://rebrickable.com/minifigs/{figure}
|
||||
# BK_REBRICKABLE_LINK_MINIFIGURE_PATTERN=https://rebrickable.com/minifigs/{figure}
|
||||
# BK_REBRICKABLE_LINK_MINIFIGURE_PATTERN=
|
||||
|
||||
# Optional: Pattern of the link to Rebrickable for a part. Will be passed to Python .format()
|
||||
# Default: https://rebrickable.com/parts/{part}/_/{color}
|
||||
# BK_REBRICKABLE_LINK_PART_PATTERN=https://rebrickable.com/parts/{part}/_/{color}
|
||||
# BK_REBRICKABLE_LINK_PART_PATTERN=
|
||||
|
||||
# Optional: Pattern of the link to Rebrickable for instructions. Will be passed to Python .format()
|
||||
# Default: https://rebrickable.com/instructions/{path}
|
||||
# BK_REBRICKABLE_LINK_INSTRUCTIONS_PATTERN=https://rebrickable.com/instructions/{path}
|
||||
# BK_REBRICKABLE_LINK_INSTRUCTIONS_PATTERN=
|
||||
|
||||
# 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
|
||||
@@ -367,33 +343,27 @@
|
||||
# Default: https://docs.google.com/spreadsheets/d/1rlYfEXtNKxUOZt2Mfv0H17DvK7bj6Pe0CuYwq6ay8WA/gviz/tq?tqx=out:csv&sheet=Sorted%20by%20Retirement%20Date
|
||||
# BK_RETIRED_SETS_FILE_URL=
|
||||
|
||||
# Optional: Path to the unofficial retired sets lists, relative to '/app/' folder
|
||||
# Optional: Path to the unofficial retired sets lists
|
||||
# You can name it whatever you want, but content has to be a CSV
|
||||
# Default: data/retired_sets.csv
|
||||
# BK_RETIRED_SETS_PATH=data/retired_sets.csv
|
||||
# Default: ./retired_sets.csv
|
||||
# BK_RETIRED_SETS_PATH=/var/lib/bricktracker/retired_sets.csv
|
||||
|
||||
# Optional: Change the default order of sets. By default ordered by insertion order.
|
||||
# Useful column names for this option are:
|
||||
# - "rebrickable_sets"."set": set number as a string (e.g., "10255-1")
|
||||
# - "rebrickable_sets"."number": the number part of set as text (e.g., "10255")
|
||||
# - "rebrickable_sets"."version": the version part of set as an integer (e.g., 1)
|
||||
# - "rebrickable_sets"."set": set number as a string
|
||||
# - "rebrickable_sets"."number": the number part of set as an integer
|
||||
# - "rebrickable_sets"."version": the version part of set as an integer
|
||||
# - "rebrickable_sets"."name": set name
|
||||
# - "rebrickable_sets"."year": set release year
|
||||
# - "rebrickable_sets"."number_of_parts": set number of parts
|
||||
# - "bricktracker_sets"."purchase_date": purchase date (as REAL/Julian day)
|
||||
# - "bricktracker_sets"."purchase_price": purchase price
|
||||
# - "total_missing": number of missing parts (composite field)
|
||||
# - "total_damaged": number of damaged parts (composite field)
|
||||
# - "total_minifigures": number of minifigures (composite field)
|
||||
# - "total_missing": number of missing parts
|
||||
# - "total_minifigures": number of minifigures
|
||||
# Default: "rebrickable_sets"."number" DESC, "rebrickable_sets"."version" ASC
|
||||
# Examples:
|
||||
# BK_SETS_DEFAULT_ORDER="rebrickable_sets"."year" DESC, "rebrickable_sets"."name" ASC
|
||||
# BK_SETS_DEFAULT_ORDER="rebrickable_sets"."number_of_parts" DESC
|
||||
# BK_SETS_DEFAULT_ORDER="total_missing" DESC, "rebrickable_sets"."year" ASC
|
||||
# BK_SETS_DEFAULT_ORDER="rebrickable_sets"."year" ASC
|
||||
|
||||
# Optional: Folder where to store the sets images, relative to '/app/' folder
|
||||
# Default: data/sets
|
||||
# BK_SETS_FOLDER=data/sets
|
||||
# Optional: Folder where to store the sets images, relative to the '/app/static/' folder
|
||||
# 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
|
||||
@@ -413,14 +383,10 @@
|
||||
# Default: true
|
||||
# BK_SHOW_SETS_DUPLICATE_FILTER=true
|
||||
|
||||
# Optional: Skip importing spare parts when downloading sets from Rebrickable
|
||||
# Optional: Skip saving or displaying spare parts
|
||||
# Default: false
|
||||
# BK_SKIP_SPARE_PARTS=true
|
||||
|
||||
# Optional: Hide spare parts from parts lists (spare parts must still be in database)
|
||||
# Default: false
|
||||
# BK_HIDE_SPARE_PARTS=true
|
||||
|
||||
# Optional: Namespace of the Socket.IO socket
|
||||
# Default: bricksocket
|
||||
# BK_SOCKET_NAMESPACE=customsocket
|
||||
@@ -431,21 +397,18 @@
|
||||
|
||||
# Optional: Change the default order of storages. By default ordered by insertion order.
|
||||
# Useful column names for this option are:
|
||||
# - "bricktracker_metadata_storages"."name": storage name
|
||||
# - "bricktracker_metadata_storages"."rowid": insertion order (special column)
|
||||
# - "bricktracker_metadata_storages"."name" ASC: storage name
|
||||
# Default: "bricktracker_metadata_storages"."name" ASC
|
||||
# Examples:
|
||||
# BK_STORAGE_DEFAULT_ORDER="bricktracker_metadata_storages"."name" DESC
|
||||
# BK_STORAGE_DEFAULT_ORDER="bricktracker_metadata_storages"."rowid" DESC
|
||||
# BK_STORAGE_DEFAULT_ORDER="bricktracker_metadata_storages"."name" ASC
|
||||
|
||||
# Optional: URL to the themes.csv.gz on Rebrickable
|
||||
# Default: https://cdn.rebrickable.com/media/downloads/themes.csv.gz
|
||||
# BK_THEMES_FILE_URL=
|
||||
|
||||
# Optional: Path to the themes file, relative to '/app/' folder
|
||||
# Optional: Path to the themes file
|
||||
# You can name it whatever you want, but content has to be a CSV
|
||||
# Default: data/themes.csv
|
||||
# BK_THEMES_PATH=data/themes.csv
|
||||
# Default: ./themes.csv
|
||||
# BK_THEMES_PATH=/var/lib/bricktracker/themes.csv
|
||||
|
||||
# Optional: Timezone to use to display datetimes
|
||||
# Check your system for available timezone/TZ values
|
||||
@@ -457,19 +420,14 @@
|
||||
# Default: false
|
||||
# BK_USE_REMOTE_IMAGES=true
|
||||
|
||||
# Optional: Change the default order of wishlist sets. By default ordered by insertion order.
|
||||
# Optional: Change the default order of sets. By default ordered by insertion order.
|
||||
# Useful column names for this option are:
|
||||
# - "bricktracker_wishes"."set": set number as a string (e.g., "10255-1")
|
||||
# - "bricktracker_wishes"."set": set number as a string
|
||||
# - "bricktracker_wishes"."name": set name
|
||||
# - "bricktracker_wishes"."year": set release year
|
||||
# - "bricktracker_wishes"."number_of_parts": set number of parts
|
||||
# - "bricktracker_wishes"."theme_id": theme ID
|
||||
# - "bricktracker_wishes"."rowid": insertion order (special column)
|
||||
# Default: "bricktracker_wishes"."rowid" DESC
|
||||
# Examples:
|
||||
# BK_WISHES_DEFAULT_ORDER="bricktracker_wishes"."year" DESC, "bricktracker_wishes"."name" ASC
|
||||
# BK_WISHES_DEFAULT_ORDER="bricktracker_wishes"."number_of_parts" DESC
|
||||
# BK_WISHES_DEFAULT_ORDER="bricktracker_wishes"."set" ASC
|
||||
# BK_WISHES_DEFAULT_ORDER="bricktracker_wishes"."set" DESC
|
||||
|
||||
# Optional: Show collection growth charts on the statistics page
|
||||
# Default: true
|
||||
@@ -479,8 +437,3 @@
|
||||
# When true, all sections start expanded. When false, all sections start collapsed.
|
||||
# Default: true
|
||||
# BK_STATISTICS_DEFAULT_EXPANDED=false
|
||||
|
||||
# Optional: Enable dark mode by default
|
||||
# When true, the application starts in dark mode.
|
||||
# Default: false
|
||||
# BK_DARK_MODE=true
|
||||
|
||||
+3
-2
@@ -17,7 +17,6 @@ static/sets/
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
*.code-workspace
|
||||
|
||||
# Temporary
|
||||
*.csv
|
||||
@@ -34,4 +33,6 @@ vitepress/
|
||||
|
||||
# Local data
|
||||
offline/
|
||||
data/
|
||||
TODO.md
|
||||
run-local.sh
|
||||
test-server.sh
|
||||
|
||||
+81
-176
@@ -1,160 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## 1.3
|
||||
## Unreleased
|
||||
|
||||
### Breaking Changes
|
||||
### 1.3
|
||||
|
||||
#### Data Folder Consolidation
|
||||
|
||||
> **Warning**
|
||||
> **BREAKING CHANGE**: Version 1.3 consolidates all user data into a single `data/` folder for easier backup and volume mapping.
|
||||
|
||||
- **Path handling**: All relative paths are now resolved relative to the application root (`/app` in Docker)
|
||||
- Example: `data/app.db` → `/app/data/app.db`
|
||||
|
||||
- **New default paths** (automatically used for new installations):
|
||||
- Database: `data/app.db` (was: `app.db` in root)
|
||||
- Configuration: `data/.env` (was: `.env` in root) - *optional, backward compatible*
|
||||
- CSV files: `data/*.csv` (was: `*.csv` in root)
|
||||
- Images/PDFs: `data/{sets,parts,minifigures,instructions}/` (was: `static/*`)
|
||||
|
||||
- **Configuration file (.env) location**:
|
||||
- New recommended location: `data/.env` (included in data volume, settings persist)
|
||||
- Backward compatible: `.env` in root still works (requires volume mount for admin panel persistence)
|
||||
- Priority: `data/.env` > `.env` (automatic detection, no migration required)
|
||||
|
||||
- **Migration options**:
|
||||
1. **Migrate to new structure** (recommended - single volume for all data including .env)
|
||||
2. **Keep current setup** (backward compatible - old paths continue to work)
|
||||
|
||||
See [Migration Guide](docs/migration_guide.md) for detailed instructions
|
||||
|
||||
#### Default Minifigures Folder Change
|
||||
|
||||
> **Warning**
|
||||
> **BREAKING CHANGE**: Default minifigures folder path changed from `minifigs` to `minifigures`
|
||||
|
||||
- **Impact**: Users who relied on the default `BK_MINIFIGURES_FOLDER` value (without explicitly setting it) will need to either:
|
||||
1. Set `BK_MINIFIGURES_FOLDER=minifigs` in their environment to maintain existing behavior, or
|
||||
2. Rename their existing `minifigs` folder to `minifigures`
|
||||
- **No impact**: Users who already have `BK_MINIFIGURES_FOLDER` explicitly configured
|
||||
- Improved consistency across documentation and Docker configurations
|
||||
|
||||
### New Features
|
||||
|
||||
- **Live Settings changes**
|
||||
- Added live environment variable configuration management system
|
||||
- Configuration Management interface in admin panel with live preview and badge system
|
||||
- **Live settings**: Can be changed without application restart (menu visibility, table display, pagination, features)
|
||||
- **Static settings**: Require restart but can be edited and saved to .env file (authentication, server, database, API keys)
|
||||
- Advanced badge system showing value status: True/False for booleans, Set/Default/Unset for other values, Changed indicator
|
||||
- Live API endpoints: `/admin/api/config/update` for immediate changes, `/admin/api/config/update-static` for .env updates
|
||||
- Form pre-population with current values and automatic page reload after successful live updates
|
||||
- Fixed environment variable lock detection in admin configuration panel
|
||||
- Resolved bug where all variables appeared "locked" after saving live settings
|
||||
- Lock detection now correctly identifies only Docker environment variables set before .env loading
|
||||
- Variables set via Docker's `environment:` directive remain properly locked
|
||||
- Variables from data/.env or root .env are correctly shown as editable
|
||||
- Added configuration persistence warning in admin panel
|
||||
- Warning banner shows when using .env in root (non-persistent)
|
||||
- Success banner shows when using data/.env (persistent)
|
||||
- Provides migration instructions directly in the UI
|
||||
- **Spare Parts**
|
||||
- Added spare parts control options
|
||||
- `BK_SKIP_SPARE_PARTS`: Skip importing spare parts when downloading sets from Rebrickable (parts not saved to database)
|
||||
- `BK_HIDE_SPARE_PARTS`: Hide spare parts from all parts lists (parts must still be in database)
|
||||
- Both options are live-changeable in admin configuration panel
|
||||
- Options can be used independently or together for flexible spare parts management
|
||||
- Affects all parts displays: /parts page, set details accordion, minifigure parts, and problem parts
|
||||
- **Pagination**
|
||||
- Added individual pagination control system per entity type
|
||||
- `BK_SETS_SERVER_SIDE_PAGINATION`: Enable/disable pagination for sets
|
||||
- `BK_PARTS_SERVER_SIDE_PAGINATION`: Enable/disable pagination for parts
|
||||
- `BK_MINIFIGURES_SERVER_SIDE_PAGINATION`: Enable/disable pagination for minifigures
|
||||
- Device-specific pagination sizes (desktop/mobile) for each entity type
|
||||
- Supports search, filtering, and sorting in both server-side and client-side modes
|
||||
- **Peeron Instructions**
|
||||
- Added 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
|
||||
- **Parts checkmark**
|
||||
- Added 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
|
||||
- **Set Consolidation**
|
||||
- Added 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
|
||||
- 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
|
||||
- **Statistics**
|
||||
- Added comprehensive statistics system (#91)
|
||||
- New Statistics page with collection analytics
|
||||
- Financial overview: total cost, average price, price range, investment tracking
|
||||
- Collection metrics: total sets, unique sets, parts count, minifigures count
|
||||
- Theme distribution statistics with clickable drill-down to filtered sets
|
||||
- Storage location statistics showing sets per location with value calculations
|
||||
- Purchase location analytics with spending patterns and date ranges
|
||||
- Problem tracking: missing and damaged parts statistics
|
||||
- Clickable numbers throughout statistics that filter to relevant sets
|
||||
- `BK_HIDE_STATISTICS`: Environment variable to hide statistics menu item
|
||||
- Year-based analytics: Sets by release year and purchases by year
|
||||
- Sets by Release Year: Shows collection distribution across LEGO release years
|
||||
- Purchases by Year: Tracks spending patterns and acquisition timeline
|
||||
- Year summary with peak collection/spending years and timeline insights
|
||||
- Enhanced statistics interface and functionality
|
||||
- Collapsible sections: All statistics sections have clickable headers to expand/collapse
|
||||
- Collection growth charts: Line charts showing sets, parts, and minifigures over time
|
||||
- Configuration options: `BK_STATISTICS_SHOW_CHARTS` and `BK_STATISTICS_DEFAULT_EXPANDED` environment variables
|
||||
- **Admin Page Section Expansion**
|
||||
- Added configurable admin page section expansion
|
||||
- `BK_ADMIN_DEFAULT_EXPANDED_SECTIONS`: Environment variable to specify which sections expand by default
|
||||
- Accepts comma-separated list of section names (e.g., "database,theme,instructions")
|
||||
- Valid sections: authentication, instructions, image, theme, retired, metadata, owner, purchase_location, status, storage, tag, database
|
||||
- URL parameters take priority over configuration (e.g., `?open_database=1`)
|
||||
- Database section expanded by default to maintain original behavior
|
||||
- Smart metadata handling: sub-section expansion automatically expands parent metadata section
|
||||
- **Duplicate Sets filter**
|
||||
- Added duplicate sets filter functionality
|
||||
- New filter button on Sets page to show only duplicate/consolidated sets
|
||||
- `BK_SHOW_SETS_DUPLICATE_FILTER`: Environment variable to show/hide the filter button (default: true)
|
||||
- Works with both server-side and client-side pagination modes
|
||||
- Consolidated mode: Shows sets that have multiple instances
|
||||
- Non-consolidated mode: Shows sets that appear multiple times in collection
|
||||
- **Bricklink Links**
|
||||
- Added BrickLink links for sets
|
||||
- BrickLink badge links now appear on set cards and set details pages alongside Rebrickable links
|
||||
- `BK_BRICKLINK_LINK_SET_PATTERN`: New environment variable for BrickLink set URL pattern (default: https://www.bricklink.com/v2/catalog/catalogitem.page?S={set_num})
|
||||
- Controlled by existing `BK_BRICKLINK_LINKS` environment variable
|
||||
- **Dark Mode**
|
||||
- Added dark mode support
|
||||
- `BK_DARK_MODE`: Environment variable to enable dark mode theme (default: false)
|
||||
- Uses Bootstrap 5.3's native dark mode with `data-bs-theme` attribute
|
||||
- Live-changeable via Admin > Live Settings
|
||||
- Setting persists across sessions via .env file
|
||||
- **Alphanumetic Set Number**
|
||||
- Added alphanumeric set number support
|
||||
- Database schema change: Set number column changed from INTEGER to TEXT
|
||||
- Supports LEGO promotional and special edition sets with letters in their numbers
|
||||
- Examples: "McDR6US-1", "COMCON035-1", "EG00021-1"
|
||||
|
||||
### Improvements
|
||||
|
||||
- Improved WebSocket/Socket.IO reliability for mobile devices
|
||||
- Changed connection strategy to polling-first with automatic WebSocket upgrade
|
||||
- Increased connection timeout to 30 seconds for slow mobile networks
|
||||
- Added ping/pong keepalive settings (30s timeout, 25s interval)
|
||||
- Improved server-side connection logging with user agent and transport details
|
||||
- Add individual pagination control system per entity type
|
||||
- `BK_SETS_SERVER_SIDE_PAGINATION`: Enable/disable pagination for sets
|
||||
- `BK_PARTS_SERVER_SIDE_PAGINATION`: Enable/disable pagination for parts
|
||||
- `BK_MINIFIGURES_SERVER_SIDE_PAGINATION`: Enable/disable pagination for minifigures
|
||||
- Device-specific pagination sizes (desktop/mobile) for each entity type
|
||||
- Supports search, filtering, and sorting in both server-side and client-side modes
|
||||
- Consolidated duplicate code across parts.js, problems.js, and minifigures.js
|
||||
- Created shared functions in collapsible-state.js for common operations
|
||||
- Fixed dynamic sort icons across all pages
|
||||
- Sort icons now properly toggle between ascending/descending states
|
||||
- Improved DataTable integration
|
||||
@@ -166,7 +23,76 @@ See [Migration Guide](docs/migration_guide.md) for detailed instructions
|
||||
- Preserves selection state during dropdown consolidation
|
||||
- Consistent search behavior (instant for client-side, Enter key for server-side)
|
||||
- Mobile-friendly pagination navigation
|
||||
- Added performance optimization
|
||||
- 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
|
||||
- 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
|
||||
- Add comprehensive statistics system (#91)
|
||||
- New Statistics page with collection analytics
|
||||
- Financial overview: total cost, average price, price range, investment tracking
|
||||
- Collection metrics: total sets, unique sets, parts count, minifigures count
|
||||
- Theme distribution statistics with clickable drill-down to filtered sets
|
||||
- Storage location statistics showing sets per location with value calculations
|
||||
- Purchase location analytics with spending patterns and date ranges
|
||||
- Problem tracking: missing and damaged parts statistics
|
||||
- Clickable numbers throughout statistics that filter to relevant sets
|
||||
- `BK_HIDE_STATISTICS`: Environment variable to hide statistics menu item
|
||||
- Year-based analytics: Sets by release year and purchases by year
|
||||
- Sets by Release Year: Shows collection distribution across LEGO release years
|
||||
- Purchases by Year: Tracks spending patterns and acquisition timeline
|
||||
- Year summary with peak collection/spending years and timeline insights
|
||||
- Enhanced statistics interface and functionality
|
||||
- Collapsible sections: All statistics sections have clickable headers to expand/collapse
|
||||
- Collection growth charts: Line charts showing sets, parts, and minifigures over time
|
||||
- Configuration options: `BK_STATISTICS_SHOW_CHARTS` and `BK_STATISTICS_DEFAULT_EXPANDED` environment variables
|
||||
- Add configurable admin page section expansion
|
||||
- `BK_ADMIN_DEFAULT_EXPANDED_SECTIONS`: Environment variable to specify which sections expand by default
|
||||
- Accepts comma-separated list of section names (e.g., "database,theme,instructions")
|
||||
- Valid sections: authentication, instructions, image, theme, retired, metadata, owner, purchase_location, status, storage, tag, database
|
||||
- URL parameters take priority over configuration (e.g., `?open_database=1`)
|
||||
- Database section expanded by default to maintain original behavior
|
||||
- Smart metadata handling: sub-section expansion automatically expands parent metadata section
|
||||
- Add duplicate sets filter functionality
|
||||
- New filter button on Sets page to show only duplicate/consolidated sets
|
||||
- `BK_SHOW_SETS_DUPLICATE_FILTER`: Environment variable to show/hide the filter button (default: true)
|
||||
- Works with both server-side and client-side pagination modes
|
||||
- Consolidated mode: Shows sets that have multiple instances
|
||||
- Non-consolidated mode: Shows sets that appear multiple times in collection
|
||||
- Add BrickLink links for sets
|
||||
- BrickLink badge links now appear on set cards and set details pages alongside Rebrickable links
|
||||
- `BK_BRICKLINK_LINK_SET_PATTERN`: New environment variable for BrickLink set URL pattern (default: https://www.bricklink.com/v2/catalog/catalogitem.page?S={set_num})
|
||||
- Controlled by existing `BK_BRICKLINK_LINKS` environment variable
|
||||
- Add live environment variable configuration management system
|
||||
- Configuration Management interface in admin panel with live preview and badge system
|
||||
- Live settings: Can be changed without application restart (menu visibility, table display, pagination, features)
|
||||
- Static settings: Require restart but can be edited and saved to .env file (authentication, server, database, API keys)
|
||||
- Advanced badge system showing value status: True/False for booleans, Set/Default/Unset for other values, Changed indicator
|
||||
- Live API endpoints: `/admin/api/config/update` for immediate changes, `/admin/api/config/update-static` for .env updates
|
||||
- Form pre-population with current values and automatic page reload after successful live updates
|
||||
- **BREAKING CHANGE**: Default minifigures folder path changed from `minifigs` to `minifigures`
|
||||
- Impact: Users who relied on the default `BK_MINIFIGURES_FOLDER` value (without explicitly setting it) will need to either:
|
||||
1. Set `BK_MINIFIGURES_FOLDER=minifigs` in their environment to maintain existing behavior, or
|
||||
2. Rename their existing `minifigs` folder to `minifigures`
|
||||
- No impact: Users who already have `BK_MINIFIGURES_FOLDER` explicitly configured
|
||||
- Improved consistency across documentation and Docker configurations
|
||||
- Add performance optimization
|
||||
- SQLite WAL Mode:
|
||||
- Increased cache size to 10,000 pages (~40MB) for faster query execution
|
||||
- Set temp_store to memory for accelerated temporary operations
|
||||
@@ -182,29 +108,8 @@ See [Migration Guide](docs/migration_guide.md) for detailed instructions
|
||||
- Statistics Query Optimization:
|
||||
- Replaced separate subqueries with efficient CTEs (Common Table Expressions)
|
||||
- Consolidated aggregations for set, part, minifigure, and financial statistics
|
||||
- Added default image handling for sets without images
|
||||
- Sets with null/missing images from Rebrickable API now display placeholder image
|
||||
- Automatic fallback to nil.png from parts folder for set previews
|
||||
- Copy of nil placeholder saved as set image for consistent display across all routes
|
||||
- Prevents errors when downloading sets that have no set_img_url in API response
|
||||
- Fixed instructions download from Rebrickable
|
||||
- Replaced cloudscraper with standard requests library
|
||||
- Resolves 403 Forbidden errors when downloading instruction PDFs
|
||||
- Fixed instructions display and URL generation
|
||||
- Fixed "Open PDF" button links to use correct data route
|
||||
- Corrected path resolution for data/instructions folder
|
||||
- Fixed instruction listing page to scan correct folder location
|
||||
- Fixed Peeron PDF creation to use correct data folder path
|
||||
- Fixed foreign key constraint error when adding sets
|
||||
- Rebrickable set is now inserted before BrickTracker set to satisfy FK constraints
|
||||
- Resolves "FOREIGN KEY constraint failed" error when adding sets
|
||||
- Fixed atomic transaction handling for set downloads
|
||||
- All database operations during set addition now use deferred execution
|
||||
- Ensures all-or-nothing behavior: if any part fails (set info, parts, minifigs), nothing is committed
|
||||
- Prevents partial set additions that would leave the database in an inconsistent state
|
||||
- Metadata updates (owners, tags) now defer until final commit
|
||||
|
||||
## 1.2.4
|
||||
### 1.2.4
|
||||
|
||||
> **Warning**
|
||||
> To use the new BrickLink color parameter in URLs, update your `.env` file:
|
||||
|
||||
+5
-8
@@ -2,16 +2,13 @@ FROM python:3-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy requirements first (so pip install can be cached)
|
||||
COPY requirements.txt .
|
||||
|
||||
# Python library requirements
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Bricktracker
|
||||
COPY . .
|
||||
|
||||
# Set executable permissions for entrypoint script
|
||||
RUN chmod +x entrypoint.sh
|
||||
# Fix line endings and set executable permissions for entrypoint script
|
||||
RUN sed -i 's/\r$//' entrypoint.sh && chmod +x entrypoint.sh
|
||||
|
||||
# Python library requirements
|
||||
RUN pip --no-cache-dir install -r requirements.txt
|
||||
|
||||
ENTRYPOINT ["./entrypoint.sh"]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
<img src="static/brick.png" height="100" width="100">
|
||||
|
||||
# BrickTracker
|
||||
|
||||
A web application for organizing and tracking LEGO sets, parts, and minifigures. Uses the Rebrickable API to fetch LEGO data and allows users to track missing pieces and collection status.
|
||||
@@ -20,13 +18,17 @@ A web application for organizing and tracking LEGO sets, parts, and minifigures.
|
||||
|
||||
Use the provided [compose.yaml](compose.yaml) file.
|
||||
|
||||
See [Quick Start](https://bricktracker.baerentsen.space/quick-start) to get up and running right away.
|
||||
See [Quickstart](docs/quickstart.md) to get up and running right away.
|
||||
|
||||
See [Walk Through](https://bricktracker.baerentsen.space/tutorial-first-steps) for a more detailed guide.
|
||||
See [Setup](docs/setup.md) for a more setup guide.
|
||||
|
||||
## Usage
|
||||
|
||||
See [first steps](docs/first-steps.md).
|
||||
|
||||
## Documentation
|
||||
|
||||
Most of the pages should be self explanatory to use.
|
||||
However, you can find more specific documentation in the [documentation](https://bricktracker.baerentsen.space/whatis).
|
||||
However, you can find more specific documentation in the [documentation](docs/DOCS.md).
|
||||
|
||||
You can find screenshots of the application in the [overview](https://bricktracker.baerentsen.space/overview) documentation.
|
||||
You can find screenshots of the application in the [overview](docs/overview.md) documentation file.
|
||||
|
||||
+2
-57
@@ -1,8 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from flask import current_app, Flask, g
|
||||
@@ -27,11 +25,11 @@ from bricktracker.views.admin.status import admin_status_page
|
||||
from bricktracker.views.admin.storage import admin_storage_page
|
||||
from bricktracker.views.admin.tag import admin_tag_page
|
||||
from bricktracker.views.admin.theme import admin_theme_page
|
||||
from bricktracker.views.data import data_page
|
||||
from bricktracker.views.error import error_404
|
||||
from bricktracker.views.index import index_page
|
||||
from bricktracker.views.instructions import instructions_page
|
||||
from bricktracker.views.login import login_page
|
||||
from bricktracker.views.individual_minifigure import individual_minifigure_page
|
||||
from bricktracker.views.minifigure import minifigure_page
|
||||
from bricktracker.views.part import part_page
|
||||
from bricktracker.views.set import set_page
|
||||
@@ -40,60 +38,7 @@ from bricktracker.views.storage import storage_page
|
||||
from bricktracker.views.wish import wish_page
|
||||
|
||||
|
||||
def load_env_file() -> None:
|
||||
"""Load .env file into os.environ with priority: data/.env > .env (root)
|
||||
|
||||
Also stores which BK_ variables were set via Docker environment (before loading .env)
|
||||
so we can detect locked variables in the admin panel.
|
||||
"""
|
||||
import json
|
||||
|
||||
data_env = Path('data/.env')
|
||||
root_env = Path('.env')
|
||||
|
||||
# Store which BK_ variables were already in environment BEFORE loading .env
|
||||
# These are "locked" (set via Docker's environment: directive)
|
||||
docker_env_vars = {k: v for k, v in os.environ.items() if k.startswith('BK_')}
|
||||
|
||||
# Store this in a way the admin panel can access it
|
||||
# We'll use an environment variable to store the JSON list of locked var names
|
||||
os.environ['_BK_DOCKER_ENV_VARS'] = json.dumps(list(docker_env_vars.keys()))
|
||||
|
||||
env_file = None
|
||||
if data_env.exists():
|
||||
env_file = data_env
|
||||
logging.info(f"Loading environment from: {data_env}")
|
||||
elif root_env.exists():
|
||||
env_file = root_env
|
||||
logging.info(f"Loading environment from: {root_env} (consider migrating to data/.env)")
|
||||
|
||||
if env_file:
|
||||
# Simple .env parser (no external dependencies needed)
|
||||
with open(env_file, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
# Skip comments and empty lines
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
# Parse key=value
|
||||
if '=' in line:
|
||||
key, value = line.split('=', 1)
|
||||
key = key.strip()
|
||||
value = value.strip()
|
||||
# Remove quotes if present
|
||||
if value.startswith('"') and value.endswith('"'):
|
||||
value = value[1:-1]
|
||||
elif value.startswith("'") and value.endswith("'"):
|
||||
value = value[1:-1]
|
||||
# Only set if not already in environment (environment variables take precedence)
|
||||
if key not in os.environ:
|
||||
os.environ[key] = value
|
||||
|
||||
|
||||
def setup_app(app: Flask) -> None:
|
||||
# Load .env file before configuration (if not already loaded by Docker Compose)
|
||||
load_env_file()
|
||||
|
||||
# Load the configuration
|
||||
BrickConfigurationList(app)
|
||||
|
||||
@@ -133,10 +78,10 @@ def setup_app(app: Flask) -> None:
|
||||
|
||||
# Register app routes
|
||||
app.register_blueprint(add_page)
|
||||
app.register_blueprint(data_page)
|
||||
app.register_blueprint(index_page)
|
||||
app.register_blueprint(instructions_page)
|
||||
app.register_blueprint(login_page)
|
||||
app.register_blueprint(individual_minifigure_page)
|
||||
app.register_blueprint(minifigure_page)
|
||||
app.register_blueprint(part_page)
|
||||
app.register_blueprint(set_page)
|
||||
|
||||
+11
-11
@@ -13,16 +13,18 @@ CONFIG: Final[list[dict[str, Any]]] = [
|
||||
{'n': 'BRICKLINK_LINK_PART_PATTERN', 'd': 'https://www.bricklink.com/v2/catalog/catalogitem.page?P={part}&C={color}'}, # noqa: E501
|
||||
{'n': 'BRICKLINK_LINK_SET_PATTERN', 'd': 'https://www.bricklink.com/v2/catalog/catalogitem.page?S={set_num}'}, # noqa: E501
|
||||
{'n': 'BRICKLINK_LINKS', 'c': bool},
|
||||
{'n': 'DATABASE_PATH', 'd': 'data/app.db'},
|
||||
{'n': 'DATABASE_PATH', 'd': './app.db'},
|
||||
{'n': 'DATABASE_TIMESTAMP_FORMAT', 'd': '%Y-%m-%d-%H-%M-%S'},
|
||||
{'n': 'DEBUG', 'c': bool},
|
||||
{'n': 'DEFAULT_TABLE_PER_PAGE', 'd': 25, 'c': int},
|
||||
{'n': 'DESCRIPTION_BADGE_MAX_LENGTH', 'd': 15, 'c': int},
|
||||
{'n': 'DISABLE_INDIVIDUAL_MINIFIGURES', 'c': bool},
|
||||
{'n': 'DOMAIN_NAME', 'e': 'DOMAIN_NAME', 'd': ''},
|
||||
{'n': 'FILE_DATETIME_FORMAT', 'd': '%d/%m/%Y, %H:%M:%S'},
|
||||
{'n': 'HOST', 'd': '0.0.0.0'},
|
||||
{'n': 'INDEPENDENT_ACCORDIONS', 'c': bool},
|
||||
{'n': 'INSTRUCTIONS_ALLOWED_EXTENSIONS', 'd': ['.pdf'], 'c': list}, # noqa: E501
|
||||
{'n': 'INSTRUCTIONS_FOLDER', 'd': 'data/instructions'},
|
||||
{'n': 'INSTRUCTIONS_FOLDER', 'd': 'instructions', 's': True},
|
||||
{'n': 'HIDE_ADD_SET', 'c': bool},
|
||||
{'n': 'HIDE_ADD_BULK_SET', 'c': bool},
|
||||
{'n': 'HIDE_ADMIN', 'c': bool},
|
||||
@@ -39,16 +41,16 @@ CONFIG: Final[list[dict[str, Any]]] = [
|
||||
{'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': 'data/minifigures'},
|
||||
{'n': 'MINIFIGURES_DEFAULT_ORDER', 'd': '"combined"."name" ASC'}, # noqa: E501
|
||||
{'n': 'MINIFIGURES_FOLDER', 'd': 'minifigures', 's': True},
|
||||
{'n': 'MINIFIGURES_PAGINATION_SIZE_DESKTOP', 'd': 10, 'c': int},
|
||||
{'n': 'MINIFIGURES_PAGINATION_SIZE_MOBILE', 'd': 5, 'c': int},
|
||||
{'n': 'MINIFIGURES_SERVER_SIDE_PAGINATION', 'c': bool},
|
||||
{'n': 'NO_THREADED_SOCKET', 'c': bool},
|
||||
{'n': 'PARTS_SERVER_SIDE_PAGINATION', 'c': bool},
|
||||
{'n': 'SETS_SERVER_SIDE_PAGINATION', 'c': bool},
|
||||
{'n': 'PARTS_DEFAULT_ORDER', 'd': '"rebrickable_parts"."name" ASC, "rebrickable_parts"."color_name" ASC, "bricktracker_parts"."spare" ASC'}, # noqa: E501
|
||||
{'n': 'PARTS_FOLDER', 'd': 'data/parts'},
|
||||
{'n': 'PARTS_DEFAULT_ORDER', 'd': '"rebrickable_parts"."name" ASC, "rebrickable_parts"."color_name" ASC, "combined"."spare" ASC'}, # noqa: E501
|
||||
{'n': 'PARTS_FOLDER', 'd': 'parts', 's': True},
|
||||
{'n': 'PARTS_PAGINATION_SIZE_DESKTOP', 'd': 10, 'c': int},
|
||||
{'n': 'PARTS_PAGINATION_SIZE_MOBILE', 'd': 5, 'c': int},
|
||||
{'n': 'PROBLEMS_PAGINATION_SIZE_DESKTOP', 'd': 10, 'c': int},
|
||||
@@ -77,24 +79,22 @@ CONFIG: Final[list[dict[str, Any]]] = [
|
||||
{'n': 'REBRICKABLE_LINKS', 'e': 'LINKS', 'c': bool},
|
||||
{'n': 'REBRICKABLE_PAGE_SIZE', 'd': 100, 'c': int},
|
||||
{'n': 'RETIRED_SETS_FILE_URL', 'd': 'https://docs.google.com/spreadsheets/d/1rlYfEXtNKxUOZt2Mfv0H17DvK7bj6Pe0CuYwq6ay8WA/gviz/tq?tqx=out:csv&sheet=Sorted%20by%20Retirement%20Date'}, # noqa: E501
|
||||
{'n': 'RETIRED_SETS_PATH', 'd': 'data/retired_sets.csv'},
|
||||
{'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': 'data/sets'},
|
||||
{'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': 'SHOW_SETS_DUPLICATE_FILTER', 'd': True, 'c': bool},
|
||||
{'n': 'SKIP_SPARE_PARTS', 'c': bool},
|
||||
{'n': 'HIDE_SPARE_PARTS', 'c': bool},
|
||||
{'n': 'SOCKET_NAMESPACE', 'd': 'bricksocket'},
|
||||
{'n': 'SOCKET_PATH', 'd': '/bricksocket/'},
|
||||
{'n': 'STORAGE_DEFAULT_ORDER', 'd': '"bricktracker_metadata_storages"."name" ASC'}, # noqa: E501
|
||||
{'n': 'THEMES_FILE_URL', 'd': 'https://cdn.rebrickable.com/media/downloads/themes.csv.gz'}, # noqa: E501
|
||||
{'n': 'THEMES_PATH', 'd': 'data/themes.csv'},
|
||||
{'n': 'THEMES_PATH', 'd': './themes.csv'},
|
||||
{'n': 'TIMEZONE', 'd': 'Etc/UTC'},
|
||||
{'n': 'USE_REMOTE_IMAGES', 'c': bool},
|
||||
{'n': 'WISHES_DEFAULT_ORDER', 'd': '"bricktracker_wishes"."rowid" DESC'},
|
||||
{'n': 'STATISTICS_SHOW_CHARTS', 'd': True, 'c': bool},
|
||||
{'n': 'STATISTICS_DEFAULT_EXPANDED', 'd': True, 'c': bool},
|
||||
{'n': 'DARK_MODE', 'c': bool},
|
||||
]
|
||||
|
||||
@@ -10,6 +10,7 @@ logger = logging.getLogger(__name__)
|
||||
LIVE_CHANGEABLE_VARS: Final[List[str]] = [
|
||||
'BK_BRICKLINK_LINKS',
|
||||
'BK_DEFAULT_TABLE_PER_PAGE',
|
||||
'BK_DESCRIPTION_BADGE_MAX_LENGTH',
|
||||
'BK_INDEPENDENT_ACCORDIONS',
|
||||
'BK_HIDE_ADD_SET',
|
||||
'BK_HIDE_ADD_BULK_SET',
|
||||
@@ -46,14 +47,12 @@ LIVE_CHANGEABLE_VARS: Final[List[str]] = [
|
||||
'BK_SHOW_GRID_SORT',
|
||||
'BK_SHOW_SETS_DUPLICATE_FILTER',
|
||||
'BK_SKIP_SPARE_PARTS',
|
||||
'BK_HIDE_SPARE_PARTS',
|
||||
'BK_USE_REMOTE_IMAGES',
|
||||
'BK_PEERON_DOWNLOAD_DELAY',
|
||||
'BK_PEERON_MIN_IMAGE_SIZE',
|
||||
'BK_REBRICKABLE_PAGE_SIZE',
|
||||
'BK_STATISTICS_SHOW_CHARTS',
|
||||
'BK_STATISTICS_DEFAULT_EXPANDED',
|
||||
'BK_DARK_MODE',
|
||||
# Default ordering and formatting
|
||||
'BK_INSTRUCTIONS_ALLOWED_EXTENSIONS',
|
||||
'BK_MINIFIGURES_DEFAULT_ORDER',
|
||||
@@ -85,6 +84,7 @@ RESTART_REQUIRED_VARS: Final[List[str]] = [
|
||||
'BK_AUTHENTICATION_KEY',
|
||||
'BK_DATABASE_PATH',
|
||||
'BK_DEBUG',
|
||||
'BK_DISABLE_INDIVIDUAL_MINIFIGURES',
|
||||
'BK_DOMAIN_NAME',
|
||||
'BK_HOST',
|
||||
'BK_PORT',
|
||||
@@ -109,20 +109,7 @@ class ConfigManager:
|
||||
"""Manages live configuration updates for BrickTracker"""
|
||||
|
||||
def __init__(self):
|
||||
# Check for .env in data folder first (v1.3+), fallback to root (backward compatibility)
|
||||
data_env = Path('data/.env')
|
||||
root_env = Path('.env')
|
||||
|
||||
if data_env.exists():
|
||||
self.env_file_path = data_env
|
||||
logger.info("Using configuration file: data/.env")
|
||||
elif root_env.exists():
|
||||
self.env_file_path = root_env
|
||||
logger.info("Using configuration file: .env (consider migrating to data/.env)")
|
||||
else:
|
||||
# Default to data/.env for new installations
|
||||
self.env_file_path = data_env
|
||||
logger.info("Configuration file will be created at: data/.env")
|
||||
self.env_file_path = Path('.env')
|
||||
|
||||
def get_current_config(self) -> Dict[str, Any]:
|
||||
"""Get current configuration values for live-changeable variables"""
|
||||
@@ -188,7 +175,7 @@ class ConfigManager:
|
||||
else:
|
||||
return []
|
||||
# Integer variables (pagination sizes, delays, etc.) - Check BEFORE boolean check
|
||||
if any(keyword in var_name.lower() for keyword in ['_size', '_page', 'delay', 'min_', 'per_page', 'page_size']):
|
||||
if any(keyword in var_name.lower() for keyword in ['_size', '_page', 'delay', 'min_', 'per_page', 'page_size', '_length']):
|
||||
try:
|
||||
return int(value)
|
||||
except (ValueError, TypeError):
|
||||
@@ -217,8 +204,6 @@ class ConfigManager:
|
||||
def _update_env_file(self, var_name: str, value: Any) -> None:
|
||||
"""Update the .env file with new value"""
|
||||
if not self.env_file_path.exists():
|
||||
# Ensure parent directory exists
|
||||
self.env_file_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
self.env_file_path.touch()
|
||||
|
||||
# Read current .env content
|
||||
@@ -321,11 +306,9 @@ class ConfigManager:
|
||||
'BK_SETS_CONSOLIDATION': 'Enable set consolidation/grouping functionality',
|
||||
'BK_SHOW_GRID_FILTERS': 'Show filter options on grids by default',
|
||||
'BK_SHOW_GRID_SORT': 'Show sort options on grids by default',
|
||||
'BK_SKIP_SPARE_PARTS': 'Skip importing spare parts when downloading sets from Rebrickable',
|
||||
'BK_HIDE_SPARE_PARTS': 'Hide spare parts from parts lists (spare parts must still be in database)',
|
||||
'BK_SKIP_SPARE_PARTS': 'Skip spare parts when importing sets',
|
||||
'BK_USE_REMOTE_IMAGES': 'Use remote images from Rebrickable CDN instead of local',
|
||||
'BK_STATISTICS_SHOW_CHARTS': 'Show collection growth charts on statistics page',
|
||||
'BK_STATISTICS_DEFAULT_EXPANDED': 'Expand all statistics sections by default',
|
||||
'BK_DARK_MODE': 'Enable dark mode theme'
|
||||
'BK_STATISTICS_DEFAULT_EXPANDED': 'Expand all statistics sections by default'
|
||||
}
|
||||
return help_text.get(var_name, 'No help available for this variable')
|
||||
@@ -60,7 +60,7 @@ class BrickConfiguration(object):
|
||||
if self.cast == bool and isinstance(value, str):
|
||||
value = value.lower() in ('true', 'yes', '1')
|
||||
|
||||
# Static path fixup (legacy - only for paths with s: True flag)
|
||||
# Static path fixup
|
||||
if self.static_path and isinstance(value, str):
|
||||
value = os.path.normpath(value)
|
||||
|
||||
@@ -70,10 +70,6 @@ class BrickConfiguration(object):
|
||||
# Remove static prefix
|
||||
value = value.removeprefix('static/')
|
||||
|
||||
# Normalize regular paths (not marked as static)
|
||||
elif not self.static_path and isinstance(value, str) and ('FOLDER' in self.name or 'PATH' in self.name):
|
||||
value = os.path.normpath(value)
|
||||
|
||||
# Type casting
|
||||
if self.cast is not None:
|
||||
self.value = self.cast(value)
|
||||
|
||||
@@ -0,0 +1,492 @@
|
||||
import logging
|
||||
import traceback
|
||||
from typing import Any, Self, TYPE_CHECKING
|
||||
from uuid import uuid4
|
||||
|
||||
from flask import current_app, url_for
|
||||
|
||||
from .exceptions import NotFoundException, DatabaseException, ErrorException
|
||||
from .parser import parse_minifig
|
||||
from .rebrickable import Rebrickable
|
||||
from .rebrickable_minifigure import RebrickableMinifigure
|
||||
from .set_owner_list import BrickSetOwnerList
|
||||
from .set_purchase_location_list import BrickSetPurchaseLocationList
|
||||
from .set_storage_list import BrickSetStorageList
|
||||
from .set_tag_list import BrickSetTagList
|
||||
from .sql import BrickSQL
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .socket import BrickSocket
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Individual minifigure (not associated with a set)
|
||||
class IndividualMinifigure(RebrickableMinifigure):
|
||||
# Queries
|
||||
select_query: str = 'individual_minifigure/select/by_id'
|
||||
light_query: str = 'individual_minifigure/select/light'
|
||||
insert_query: str = 'individual_minifigure/insert'
|
||||
|
||||
# Delete a individual minifigure
|
||||
def delete(self, /) -> None:
|
||||
BrickSQL().executescript(
|
||||
'individual_minifigure/delete/individual_minifigure',
|
||||
id=self.fields.id
|
||||
)
|
||||
|
||||
# Import a individual minifigure into the database
|
||||
def download(self, socket: 'BrickSocket', data: dict[str, Any], /) -> bool:
|
||||
# Load the minifigure
|
||||
if not self.load(socket, data, from_download=True):
|
||||
return False
|
||||
|
||||
try:
|
||||
# Insert into the database
|
||||
socket.auto_progress(
|
||||
message='Minifigure {figure}: inserting into database'.format(
|
||||
figure=self.fields.figure
|
||||
),
|
||||
increment_total=True,
|
||||
)
|
||||
|
||||
# Generate an UUID for self
|
||||
self.fields.id = str(uuid4())
|
||||
|
||||
# Save the storage
|
||||
storage = BrickSetStorageList.get(
|
||||
data.get('storage', ''),
|
||||
allow_none=True
|
||||
)
|
||||
self.fields.storage = storage.fields.id if storage else None
|
||||
|
||||
# Save the purchase location
|
||||
purchase_location = BrickSetPurchaseLocationList.get(
|
||||
data.get('purchase_location', ''),
|
||||
allow_none=True
|
||||
)
|
||||
self.fields.purchase_location = purchase_location.fields.id if purchase_location else None
|
||||
|
||||
# Save quantity and description
|
||||
self.fields.quantity = int(data.get('quantity', 1))
|
||||
self.fields.description = data.get('description', '')
|
||||
|
||||
# IMPORTANT: Insert rebrickable minifigure FIRST
|
||||
# bricktracker_individual_minifigures has FK to rebrickable_minifigures
|
||||
self.insert_rebrickable_loose()
|
||||
|
||||
# Now insert into bricktracker_individual_minifigures
|
||||
# Use no_defer=True to ensure the insert happens before we insert parts
|
||||
# (parts have a foreign key constraint on this id)
|
||||
self.insert(commit=False, no_defer=True)
|
||||
|
||||
# Save the owners
|
||||
owners: list[str] = list(data.get('owners', []))
|
||||
for id in owners:
|
||||
owner = BrickSetOwnerList.get(id)
|
||||
owner.update_individual_minifigure_state(self, state=True)
|
||||
|
||||
# Save the tags
|
||||
tags: list[str] = list(data.get('tags', []))
|
||||
for id in tags:
|
||||
tag = BrickSetTagList.get(id)
|
||||
tag.update_individual_minifigure_state(self, state=True)
|
||||
|
||||
# Load the parts (elements) for this minifigure
|
||||
if not self.download_parts(socket):
|
||||
return False
|
||||
|
||||
# Commit the transaction to the database
|
||||
socket.auto_progress(
|
||||
message='Minifigure {figure}: writing to the database'.format(
|
||||
figure=self.fields.figure
|
||||
),
|
||||
increment_total=True,
|
||||
)
|
||||
|
||||
BrickSQL().commit()
|
||||
|
||||
# Info
|
||||
logger.info('Minifigure {figure}: imported (id: {id})'.format(
|
||||
figure=self.fields.figure,
|
||||
id=self.fields.id,
|
||||
))
|
||||
|
||||
# Complete
|
||||
socket.complete(
|
||||
message='Minifigure {figure}: imported (<a href="{url}">Go to the minifigure</a>)'.format(
|
||||
figure=self.fields.figure,
|
||||
url=self.url()
|
||||
),
|
||||
download=True
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
socket.fail(
|
||||
message='Error while importing minifigure {figure}: {error}'.format(
|
||||
figure=self.fields.figure,
|
||||
error=e,
|
||||
)
|
||||
)
|
||||
|
||||
logger.debug(traceback.format_exc())
|
||||
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
# Download parts (elements) for this individual minifigure
|
||||
def download_parts(self, socket: 'BrickSocket', /) -> bool:
|
||||
"""Download minifigure parts using get_minifig_elements()"""
|
||||
try:
|
||||
# Check if we have cached parts data from load()
|
||||
if hasattr(self, '_cached_parts_response'):
|
||||
response = self._cached_parts_response
|
||||
logger.debug('Using cached parts data from load()')
|
||||
else:
|
||||
# Need to fetch parts data
|
||||
socket.auto_progress(
|
||||
message='Minifigure {figure}: loading parts from Rebrickable'.format(
|
||||
figure=self.fields.figure
|
||||
),
|
||||
increment_total=True,
|
||||
)
|
||||
|
||||
logger.debug('rebrick.lego.get_minifig_elements("{figure}")'.format(
|
||||
figure=self.fields.figure,
|
||||
))
|
||||
|
||||
# Load parts data from Rebrickable API
|
||||
import json
|
||||
from rebrick import lego
|
||||
|
||||
parameters = {
|
||||
'api_key': current_app.config['REBRICKABLE_API_KEY'],
|
||||
'page_size': current_app.config['REBRICKABLE_PAGE_SIZE'],
|
||||
}
|
||||
|
||||
response = json.loads(lego.get_minifig_elements(
|
||||
self.fields.figure,
|
||||
**parameters
|
||||
).read())
|
||||
|
||||
socket.auto_progress(
|
||||
message='Minifigure {figure}: saving parts to database'.format(
|
||||
figure=self.fields.figure
|
||||
),
|
||||
)
|
||||
|
||||
# Insert each part into individual_minifigure_parts table
|
||||
from .rebrickable_part import RebrickablePart
|
||||
|
||||
if 'results' in response:
|
||||
logger.debug(f'Processing {len(response["results"])} parts for minifigure {self.fields.figure}')
|
||||
|
||||
for idx, result in enumerate(response['results']):
|
||||
part_num = result['part']['part_num']
|
||||
color_id = result['color']['id']
|
||||
|
||||
logger.debug(
|
||||
f'Part {idx+1}/{len(response["results"])}: {part_num} '
|
||||
f'(color: {color_id}, quantity: {result["quantity"]})'
|
||||
)
|
||||
|
||||
# Insert rebrickable part data first
|
||||
part_data = RebrickablePart.from_rebrickable(result)
|
||||
logger.debug(f'Rebrickable part data keys: {list(part_data.keys())}')
|
||||
|
||||
# Insert into rebrickable_parts if not exists
|
||||
BrickSQL().execute(
|
||||
'rebrickable/part/insert',
|
||||
parameters=part_data,
|
||||
commit=False,
|
||||
)
|
||||
|
||||
# Download part image if not using remote images
|
||||
if not current_app.config['USE_REMOTE_IMAGES']:
|
||||
# Create a RebrickablePart instance for image download
|
||||
from .set import BrickSet
|
||||
try:
|
||||
part_instance = RebrickablePart(record=part_data)
|
||||
from .rebrickable_image import RebrickableImage
|
||||
RebrickableImage(
|
||||
BrickSet(), # Dummy set
|
||||
minifigure=self,
|
||||
part=part_instance,
|
||||
).download()
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f'Could not download image for part {part_num}: {e}'
|
||||
)
|
||||
|
||||
# Insert into bricktracker_individual_minifigure_parts
|
||||
individual_part_params = {
|
||||
'id': self.fields.id,
|
||||
'part': part_num,
|
||||
'color': color_id,
|
||||
'spare': result.get('is_spare', False),
|
||||
'quantity': result['quantity'],
|
||||
'element': result.get('element_id'),
|
||||
'rebrickable_inventory': result['id'],
|
||||
}
|
||||
logger.debug(f'Individual part params: {individual_part_params}')
|
||||
|
||||
BrickSQL().execute(
|
||||
'individual_minifigure/part/insert',
|
||||
parameters=individual_part_params,
|
||||
commit=False,
|
||||
)
|
||||
|
||||
logger.debug(f'Successfully inserted all {len(response["results"])} parts')
|
||||
else:
|
||||
logger.warning(f'No results in parts response for minifigure {self.fields.figure}')
|
||||
|
||||
# Clean up cached data
|
||||
if hasattr(self, '_cached_parts_response'):
|
||||
delattr(self, '_cached_parts_response')
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
socket.fail(
|
||||
message='Error loading parts for minifigure {figure}: {error}'.format(
|
||||
figure=self.fields.figure,
|
||||
error=e,
|
||||
)
|
||||
)
|
||||
logger.debug(traceback.format_exc())
|
||||
return False
|
||||
|
||||
# Insert the individual minifigure from Rebrickable
|
||||
def insert_rebrickable_loose(self, /) -> None:
|
||||
"""Insert rebrickable minifigure data (without set association)"""
|
||||
# Insert the Rebrickable minifigure to the database
|
||||
# Note: We override the parent's insert_rebrickable since we don't have a brickset
|
||||
from .rebrickable_image import RebrickableImage
|
||||
|
||||
# Explicitly build parameters for rebrickable_minifigures insert
|
||||
params = {
|
||||
'figure': self.fields.figure,
|
||||
'number': self.fields.number,
|
||||
'name': self.fields.name,
|
||||
'image': self.fields.image,
|
||||
'number_of_parts': self.fields.number_of_parts,
|
||||
}
|
||||
|
||||
BrickSQL().execute(
|
||||
RebrickableMinifigure.insert_query,
|
||||
parameters=params,
|
||||
commit=False,
|
||||
)
|
||||
|
||||
# Download image locally if not using remote images
|
||||
if not current_app.config['USE_REMOTE_IMAGES']:
|
||||
# Create a dummy BrickSet for RebrickableImage
|
||||
# RebrickableImage checks minifigure first before set, so this works
|
||||
from .set import BrickSet
|
||||
try:
|
||||
RebrickableImage(
|
||||
BrickSet(), # Dummy set - not used since minifigure takes priority
|
||||
minifigure=self,
|
||||
).download()
|
||||
logger.debug(f'Downloaded image for individual minifigure {self.fields.figure}')
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f'Could not download image for individual minifigure {self.fields.figure}: {e}'
|
||||
)
|
||||
|
||||
# Load the minifigure from Rebrickable
|
||||
def load(
|
||||
self,
|
||||
socket: 'BrickSocket',
|
||||
data: dict[str, Any],
|
||||
/,
|
||||
*,
|
||||
from_download=False,
|
||||
) -> bool:
|
||||
# Reset the progress
|
||||
socket.progress_count = 0
|
||||
socket.progress_total = 2
|
||||
|
||||
try:
|
||||
# Check if individual minifigures are disabled
|
||||
from flask import current_app
|
||||
if current_app.config.get('DISABLE_INDIVIDUAL_MINIFIGURES', False):
|
||||
raise ErrorException(
|
||||
'Individual minifigures system is disabled. '
|
||||
'Only set-based minifigures can be added.'
|
||||
)
|
||||
|
||||
socket.auto_progress(message='Parsing minifigure number')
|
||||
figure = parse_minifig(str(data['figure']))
|
||||
|
||||
socket.auto_progress(
|
||||
message='Minifigure {figure}: loading from Rebrickable'.format(
|
||||
figure=figure,
|
||||
),
|
||||
)
|
||||
|
||||
logger.debug('rebrick.lego.get_minifig_elements("{figure}")'.format(
|
||||
figure=figure,
|
||||
))
|
||||
|
||||
# Load from Rebrickable using get_minifig_elements
|
||||
# This gives us both minifigure info and parts in one call
|
||||
import json
|
||||
from rebrick import lego
|
||||
|
||||
parameters = {
|
||||
'api_key': current_app.config['REBRICKABLE_API_KEY'],
|
||||
'page_size': current_app.config['REBRICKABLE_PAGE_SIZE'],
|
||||
}
|
||||
|
||||
response = json.loads(lego.get_minifig_elements(
|
||||
figure,
|
||||
**parameters
|
||||
).read())
|
||||
|
||||
# Extract minifigure info from the first part's metadata
|
||||
if 'results' in response and len(response['results']) > 0:
|
||||
first_part = response['results'][0]
|
||||
|
||||
# Build minifigure data from the response
|
||||
self.fields.figure = first_part['set_num']
|
||||
self.fields.number_of_parts = response['count']
|
||||
|
||||
# We need to fetch the proper name and image from get_minifig()
|
||||
# This is a small additional call but gives us the proper minifigure data
|
||||
try:
|
||||
# get_minifig() only needs api_key, not page_size
|
||||
minifig_params = {
|
||||
'api_key': current_app.config['REBRICKABLE_API_KEY']
|
||||
}
|
||||
minifig_response = json.loads(lego.get_minifig(
|
||||
figure,
|
||||
**minifig_params
|
||||
).read())
|
||||
self.fields.name = minifig_response.get('name', f"Minifigure {figure}")
|
||||
|
||||
# Use the minifig image from get_minifig() - this is the assembled minifig
|
||||
self.fields.image = minifig_response.get('set_img_url')
|
||||
|
||||
# Extract number from figure (e.g., fig-005997 -> 5997)
|
||||
try:
|
||||
self.fields.number = int(figure.split('-')[1])
|
||||
except:
|
||||
self.fields.number = 0
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f'Could not fetch minifigure name: {e}')
|
||||
self.fields.name = f"Minifigure {figure}"
|
||||
# Try to extract number anyway
|
||||
try:
|
||||
self.fields.number = int(figure.split('-')[1])
|
||||
except:
|
||||
self.fields.number = 0
|
||||
|
||||
# Fallback: try to extract image from first part with element_id
|
||||
self.fields.image = None
|
||||
for result in response['results']:
|
||||
if result.get('element_id') and result['part'].get('part_img_url'):
|
||||
self.fields.image = result['part']['part_img_url']
|
||||
break
|
||||
|
||||
# Store the parts data for later use in download
|
||||
self._cached_parts_response = response
|
||||
else:
|
||||
raise NotFoundException(f'Minifigure {figure} has no parts in Rebrickable')
|
||||
|
||||
socket.emit('MINIFIGURE_LOADED', self.short(
|
||||
from_download=from_download
|
||||
))
|
||||
|
||||
if not from_download:
|
||||
socket.complete(
|
||||
message='Minifigure {figure}: loaded from Rebrickable'.format(
|
||||
figure=self.fields.figure
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
# Check if this is the "disabled" error - if so, show cleaner message
|
||||
error_msg = str(e)
|
||||
if 'Individual minifigures system is disabled' in error_msg:
|
||||
socket.fail(message=error_msg)
|
||||
else:
|
||||
socket.fail(
|
||||
message='Could not load the minifigure from Rebrickable: {error}. Data: {data}'.format(
|
||||
error=error_msg,
|
||||
data=data,
|
||||
)
|
||||
)
|
||||
|
||||
if not isinstance(e, (NotFoundException, ErrorException)):
|
||||
logger.debug(traceback.format_exc())
|
||||
|
||||
return False
|
||||
|
||||
# Return a short form of the minifigure
|
||||
def short(self, /, *, from_download: bool = False) -> dict[str, Any]:
|
||||
return {
|
||||
'download': from_download,
|
||||
'image': self.url_for_image(),
|
||||
'name': self.fields.name,
|
||||
'figure': self.fields.figure,
|
||||
}
|
||||
|
||||
# Select a individual minifigure by ID
|
||||
def select_by_id(self, id: str, /) -> Self:
|
||||
# Save the ID parameter
|
||||
self.fields.id = id
|
||||
|
||||
# Import status list here to get metadata columns
|
||||
from .set_status_list import BrickSetStatusList
|
||||
|
||||
# Pass metadata columns to the query with correct table names for individual minifigures
|
||||
context = {
|
||||
'owners': ', ' + BrickSetOwnerList.as_columns(table='bricktracker_individual_minifigure_owners') if BrickSetOwnerList.list() else '',
|
||||
'statuses': ', ' + BrickSetStatusList.as_columns(table='bricktracker_individual_minifigure_statuses', all=True) if BrickSetStatusList.list(all=True) else '',
|
||||
'tags': ', ' + BrickSetTagList.as_columns(table='bricktracker_individual_minifigure_tags') if BrickSetTagList.list() else '',
|
||||
}
|
||||
|
||||
if not self.select(**context):
|
||||
raise NotFoundException(
|
||||
'Individual minifigure with ID {id} was not found in the database'.format(
|
||||
id=id,
|
||||
),
|
||||
)
|
||||
|
||||
return self
|
||||
|
||||
# URL to this individual minifigure instance
|
||||
def url(self, /) -> str:
|
||||
return url_for('individual_minifigure.details', id=self.fields.id)
|
||||
|
||||
# URL for updating quantity
|
||||
def url_for_quantity(self, /) -> str:
|
||||
return url_for('individual_minifigure.update_quantity', id=self.fields.id)
|
||||
|
||||
# URL for updating description
|
||||
def url_for_description(self, /) -> str:
|
||||
return url_for('individual_minifigure.update_description', id=self.fields.id)
|
||||
|
||||
# Parts
|
||||
def generic_parts(self, /):
|
||||
from .part_list import BrickPartList
|
||||
return BrickPartList().from_individual_minifigure(self)
|
||||
|
||||
# Override from_rebrickable to handle minifigure data
|
||||
@staticmethod
|
||||
def from_rebrickable(data: dict[str, Any], /, **_) -> dict[str, Any]:
|
||||
# Extracting number
|
||||
number = int(str(data['set_num'])[5:])
|
||||
|
||||
return {
|
||||
'figure': str(data['set_num']),
|
||||
'number': int(number),
|
||||
'name': str(data['set_name']),
|
||||
'image': data.get('set_img_url'),
|
||||
'number_of_parts': int(data.get('num_parts', 0)),
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import logging
|
||||
from typing import Self
|
||||
|
||||
from .individual_minifigure import IndividualMinifigure
|
||||
from .record_list import BrickRecordList
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Individual minifigures list
|
||||
class IndividualMinifigureList(BrickRecordList[IndividualMinifigure]):
|
||||
# Queries
|
||||
instances_by_figure_query: str = 'individual_minifigure/select/instances_by_figure'
|
||||
using_storage_query: str = 'individual_minifigure/list/using_storage'
|
||||
without_storage_query: str = 'individual_minifigure/list/without_storage'
|
||||
|
||||
def __init__(self, /):
|
||||
super().__init__()
|
||||
|
||||
# Load all individual instances of a specific minifigure figure
|
||||
def instances_by_figure(self, figure: str, /) -> Self:
|
||||
# Save the figure parameter
|
||||
self.fields.figure = figure
|
||||
|
||||
# Import metadata lists to get columns
|
||||
from .set_owner_list import BrickSetOwnerList
|
||||
from .set_status_list import BrickSetStatusList
|
||||
from .set_tag_list import BrickSetTagList
|
||||
|
||||
# Prepare context with metadata columns
|
||||
context = {
|
||||
'owners': BrickSetOwnerList.as_columns(table='bricktracker_individual_minifigure_owners') if BrickSetOwnerList.list() else 'NULL AS "no_owners"',
|
||||
'statuses': BrickSetStatusList.as_columns(table='bricktracker_individual_minifigure_statuses', all=True) if BrickSetStatusList.list(all=True) else 'NULL AS "no_statuses"',
|
||||
'tags': BrickSetTagList.as_columns(table='bricktracker_individual_minifigure_tags') if BrickSetTagList.list() else 'NULL AS "no_tags"',
|
||||
}
|
||||
|
||||
# Load the instances from the database
|
||||
self.list(override_query=self.instances_by_figure_query, **context)
|
||||
|
||||
return self
|
||||
|
||||
# Load all individual minifigures using a specific storage
|
||||
def using_storage(self, storage: 'BrickSetStorage', /) -> Self:
|
||||
# Save the storage parameter
|
||||
self.fields.storage = storage.fields.id
|
||||
|
||||
# Load the minifigures from the database
|
||||
self.list(override_query=self.using_storage_query)
|
||||
|
||||
return self
|
||||
|
||||
# Load all individual minifigures without storage
|
||||
def without_storage(self, /) -> Self:
|
||||
# Load minifigures with no storage
|
||||
self.list(override_query=self.without_storage_query)
|
||||
|
||||
return self
|
||||
|
||||
# Base individual minifigure list
|
||||
def list(
|
||||
self,
|
||||
/,
|
||||
*,
|
||||
override_query: str | None = None,
|
||||
order: str | None = None,
|
||||
limit: int | None = None,
|
||||
**context,
|
||||
) -> None:
|
||||
# Load the individual minifigures from the database
|
||||
for record in super().select(
|
||||
override_query=override_query,
|
||||
order=order,
|
||||
limit=limit,
|
||||
**context
|
||||
):
|
||||
individual_minifigure = IndividualMinifigure(record=record)
|
||||
self.records.append(individual_minifigure)
|
||||
@@ -13,6 +13,7 @@ import requests
|
||||
from werkzeug.datastructures import FileStorage
|
||||
from werkzeug.utils import secure_filename
|
||||
import re
|
||||
import cloudscraper
|
||||
|
||||
from .exceptions import ErrorException, DownloadException
|
||||
if TYPE_CHECKING:
|
||||
@@ -105,34 +106,12 @@ class BrickInstructions(object):
|
||||
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>'
|
||||
)
|
||||
|
||||
# Use plain requests instead of cloudscraper
|
||||
session = requests.Session()
|
||||
session.headers.update({
|
||||
'User-Agent': current_app.config['REBRICKABLE_USER_AGENT'],
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
|
||||
'Accept-Language': 'en-US,en;q=0.5',
|
||||
'DNT': '1',
|
||||
'Connection': 'keep-alive',
|
||||
'Upgrade-Insecure-Requests': '1',
|
||||
'Sec-Fetch-Dest': 'document',
|
||||
'Sec-Fetch-Mode': 'navigate',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'Cache-Control': 'max-age=0'
|
||||
# Fetch PDF via cloudscraper (to bypass Cloudflare)
|
||||
scraper = cloudscraper.create_scraper()
|
||||
scraper.headers.update({
|
||||
"User-Agent": current_app.config['REBRICKABLE_USER_AGENT']
|
||||
})
|
||||
|
||||
# Visit the set's instructions listing page first to establish session cookies
|
||||
set_number = None
|
||||
if self.rebrickable:
|
||||
set_number = self.rebrickable.fields.set
|
||||
elif self.set:
|
||||
set_number = self.set
|
||||
|
||||
if set_number:
|
||||
instructions_page = f"https://rebrickable.com/instructions/{set_number}/"
|
||||
session.get(instructions_page)
|
||||
session.headers.update({"Referer": instructions_page})
|
||||
|
||||
resp = session.get(path, stream=True, allow_redirects=True)
|
||||
resp = scraper.get(path, stream=True)
|
||||
if not resp.ok:
|
||||
raise DownloadException(f"Failed to download: HTTP {resp.status_code}")
|
||||
|
||||
@@ -193,16 +172,11 @@ class BrickInstructions(object):
|
||||
if filename is None:
|
||||
filename = self.filename
|
||||
|
||||
folder = current_app.config['INSTRUCTIONS_FOLDER']
|
||||
|
||||
# If folder is absolute, use it directly
|
||||
# Otherwise, make it relative to app root (not static folder)
|
||||
if os.path.isabs(folder):
|
||||
base_path = folder
|
||||
else:
|
||||
base_path = os.path.join(current_app.root_path, folder)
|
||||
|
||||
return os.path.join(base_path, filename)
|
||||
return os.path.join(
|
||||
current_app.static_folder, # type: ignore
|
||||
current_app.config['INSTRUCTIONS_FOLDER'],
|
||||
filename
|
||||
)
|
||||
|
||||
# Rename an instructions file
|
||||
def rename(self, filename: str, /) -> None:
|
||||
@@ -243,16 +217,10 @@ class BrickInstructions(object):
|
||||
|
||||
folder: str = current_app.config['INSTRUCTIONS_FOLDER']
|
||||
|
||||
# Determine which route to use based on folder path
|
||||
# If folder contains 'data' (new structure), use data route
|
||||
# Otherwise use static route (legacy)
|
||||
if 'data' in folder:
|
||||
return url_for('data.serve_data_file', folder='instructions', filename=self.filename)
|
||||
else:
|
||||
# Legacy: folder is relative to static/
|
||||
folder_clean = folder.removeprefix('static/')
|
||||
path = os.path.join(folder_clean, self.filename)
|
||||
return url_for('static', filename=path)
|
||||
# Compute the path
|
||||
path = os.path.join(folder, self.filename)
|
||||
|
||||
return url_for('static', filename=path)
|
||||
|
||||
# Return the icon depending on the extension
|
||||
def icon(self, /) -> str:
|
||||
@@ -269,33 +237,20 @@ class BrickInstructions(object):
|
||||
@staticmethod
|
||||
def find_instructions(set: str, /) -> list[Tuple[str, str]]:
|
||||
"""
|
||||
Scrape Rebrickable's HTML and return a list of
|
||||
Scrape Rebrickable’s HTML and return a list of
|
||||
(filename_slug, download_url). Duplicate slugs get _1, _2, …
|
||||
"""
|
||||
page_url = f"https://rebrickable.com/instructions/{set}/"
|
||||
logger.debug(f"[find_instructions] fetching HTML from {page_url!r}")
|
||||
|
||||
# Use plain requests instead of cloudscraper
|
||||
session = requests.Session()
|
||||
session.headers.update({
|
||||
'User-Agent': current_app.config['REBRICKABLE_USER_AGENT'],
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
|
||||
'Accept-Language': 'en-US,en;q=0.5',
|
||||
'DNT': '1',
|
||||
'Connection': 'keep-alive',
|
||||
'Upgrade-Insecure-Requests': '1',
|
||||
'Sec-Fetch-Dest': 'document',
|
||||
'Sec-Fetch-Mode': 'navigate',
|
||||
'Sec-Fetch-Site': 'none',
|
||||
'Cache-Control': 'max-age=0'
|
||||
})
|
||||
|
||||
resp = session.get(page_url)
|
||||
# Solve Cloudflare’s challenge
|
||||
scraper = cloudscraper.create_scraper()
|
||||
scraper.headers.update({'User-Agent': current_app.config['REBRICKABLE_USER_AGENT']})
|
||||
resp = scraper.get(page_url)
|
||||
if not resp.ok:
|
||||
raise ErrorException(f'Failed to load instructions page for {set}. HTTP {resp.status_code}')
|
||||
|
||||
soup = BeautifulSoup(resp.content, 'html.parser')
|
||||
# Match download links with or without query parameters (e.g., ?cfe=timestamp&cfk=key)
|
||||
link_re = re.compile(r'^/instructions/\d+/.+/download/')
|
||||
|
||||
raw: list[tuple[str, str]] = []
|
||||
@@ -308,10 +263,8 @@ class BrickInstructions(object):
|
||||
alt_text = img['alt'].removeprefix('LEGO Building Instructions for ') # type: ignore
|
||||
slug = re.sub(r'[^A-Za-z0-9]+', '-', alt_text).strip('-')
|
||||
|
||||
# Build the absolute download URL - this preserves query parameters
|
||||
# BeautifulSoup's a['href'] includes the full href with ?cfe=...&cfk=... params
|
||||
# Build the absolute download URL
|
||||
download_url = urljoin('https://rebrickable.com', a['href']) # type: ignore
|
||||
logger.debug(f"[find_instructions] Found download link: {download_url}")
|
||||
raw.append((slug, download_url))
|
||||
|
||||
if not raw:
|
||||
|
||||
@@ -36,14 +36,11 @@ class BrickInstructionsList(object):
|
||||
|
||||
# Try to list the files in the instruction folder
|
||||
try:
|
||||
folder_config: str = current_app.config['INSTRUCTIONS_FOLDER']
|
||||
|
||||
# If folder is absolute, use it directly
|
||||
# Otherwise, make it relative to app root (not static folder)
|
||||
if os.path.isabs(folder_config):
|
||||
folder = folder_config
|
||||
else:
|
||||
folder = os.path.join(current_app.root_path, folder_config)
|
||||
# Make a folder relative to static
|
||||
folder: str = os.path.join(
|
||||
current_app.static_folder, # type: ignore
|
||||
current_app.config['INSTRUCTIONS_FOLDER'],
|
||||
)
|
||||
|
||||
for file in os.scandir(folder):
|
||||
instruction = BrickInstructions(file)
|
||||
|
||||
@@ -9,6 +9,7 @@ from .exceptions import DatabaseException, ErrorException, NotFoundException
|
||||
from .record import BrickRecord
|
||||
from .sql import BrickSQL
|
||||
if TYPE_CHECKING:
|
||||
from .individual_minifigure import IndividualMinifigure
|
||||
from .set import BrickSet
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -18,16 +19,20 @@ logger = logging.getLogger(__name__)
|
||||
class BrickMetadata(BrickRecord):
|
||||
kind: str
|
||||
|
||||
# Set state endpoint
|
||||
set_state_endpoint: str
|
||||
# Endpoints (optional, not all metadata types use all of these)
|
||||
set_state_endpoint: str = ''
|
||||
individual_minifigure_state_endpoint: str = ''
|
||||
individual_minifigure_value_endpoint: str = ''
|
||||
|
||||
# Queries
|
||||
delete_query: str
|
||||
insert_query: str
|
||||
select_query: str
|
||||
update_field_query: str
|
||||
update_set_state_query: str
|
||||
update_set_value_query: str
|
||||
update_set_state_query: str = ''
|
||||
update_set_value_query: str = ''
|
||||
update_individual_minifigure_state_query: str = ''
|
||||
update_individual_minifigure_value_query: str = ''
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -106,6 +111,21 @@ class BrickMetadata(BrickRecord):
|
||||
metadata_id=self.fields.id
|
||||
)
|
||||
|
||||
# URL to change the selected state of this metadata item for an individual minifigure
|
||||
def url_for_individual_minifigure_state(self, id: str, /) -> str:
|
||||
return url_for(
|
||||
self.individual_minifigure_state_endpoint,
|
||||
id=id,
|
||||
metadata_id=self.fields.id
|
||||
)
|
||||
|
||||
# URL to change the value for an individual minifigure
|
||||
def url_for_individual_minifigure_value(self, id: str, /) -> str:
|
||||
return url_for(
|
||||
self.individual_minifigure_value_endpoint,
|
||||
id=id
|
||||
)
|
||||
|
||||
# Select a specific metadata (with an id)
|
||||
def select_specific(self, id: str, /) -> Self:
|
||||
# Save the parameters to the fields
|
||||
@@ -191,15 +211,19 @@ class BrickMetadata(BrickRecord):
|
||||
parameters['set_id'] = brickset.fields.id
|
||||
parameters['state'] = state
|
||||
|
||||
rows, _ = BrickSQL().execute(
|
||||
rows, _ = BrickSQL().execute_and_commit(
|
||||
self.update_set_state_query,
|
||||
parameters=parameters,
|
||||
defer=True,
|
||||
name=self.as_column(),
|
||||
)
|
||||
|
||||
# Note: rows will be -1 when deferred, so we can't validate here
|
||||
# Validation will happen at final commit in set.py
|
||||
if rows != 1:
|
||||
raise DatabaseException('Could not update the {kind} "{name}" state for set {set} ({id})'.format( # noqa: E501
|
||||
kind=self.kind,
|
||||
name=self.fields.name,
|
||||
set=brickset.fields.set,
|
||||
id=brickset.fields.id,
|
||||
))
|
||||
|
||||
# Info
|
||||
logger.info('{kind} "{name}" state changed to "{state}" for set {set} ({id})'.format( # noqa: E501
|
||||
@@ -212,6 +236,65 @@ class BrickMetadata(BrickRecord):
|
||||
|
||||
return state
|
||||
|
||||
# Check if this metadata has a specific individual minifigure
|
||||
def has_individual_minifigure(
|
||||
self,
|
||||
individual_minifigure: 'IndividualMinifigure',
|
||||
/,
|
||||
) -> bool:
|
||||
"""Check if this owner/tag/status is assigned to a individual minifigure"""
|
||||
# Determine the table name based on metadata type
|
||||
table_name = f'bricktracker_individual_minifigure_{self.kind}s'
|
||||
column_name = f'{self.kind}_{self.fields.id}'
|
||||
|
||||
# Query to check if the relationship exists using raw SQL
|
||||
sql = BrickSQL()
|
||||
query = f'SELECT COUNT(*) as count FROM "{table_name}" WHERE "id" = ? AND "{column_name}" = 1'
|
||||
result = sql.cursor.execute(query, (individual_minifigure.fields.id,)).fetchone()
|
||||
|
||||
return result and result['count'] > 0
|
||||
|
||||
# Update the selected state of this metadata item for a individual minifigure
|
||||
def update_individual_minifigure_state(
|
||||
self,
|
||||
individual_minifigure: 'IndividualMinifigure',
|
||||
/,
|
||||
*,
|
||||
json: Any | None = None,
|
||||
state: Any | None = None
|
||||
) -> Any:
|
||||
if state is None and json is not None:
|
||||
state = json.get('value', False)
|
||||
|
||||
parameters = self.sql_parameters()
|
||||
parameters['id'] = individual_minifigure.fields.id
|
||||
parameters['state'] = state
|
||||
|
||||
rows, _ = BrickSQL().execute_and_commit(
|
||||
self.update_individual_minifigure_state_query,
|
||||
parameters=parameters,
|
||||
name=self.as_column(),
|
||||
)
|
||||
|
||||
if rows != 1:
|
||||
raise DatabaseException('Could not update the {kind} "{name}" state for individual minifigure {figure} ({id})'.format(
|
||||
kind=self.kind,
|
||||
name=self.fields.name,
|
||||
figure=individual_minifigure.fields.figure,
|
||||
id=individual_minifigure.fields.id,
|
||||
))
|
||||
|
||||
# Info
|
||||
logger.info('{kind} "{name}" state changed to "{state}" for individual minifigure {figure} ({id})'.format(
|
||||
kind=self.kind,
|
||||
name=self.fields.name,
|
||||
state=state,
|
||||
figure=individual_minifigure.fields.figure,
|
||||
id=individual_minifigure.fields.id,
|
||||
))
|
||||
|
||||
return state
|
||||
|
||||
# Update the selected value of this metadata item for a set
|
||||
def update_set_value(
|
||||
self,
|
||||
|
||||
@@ -39,9 +39,10 @@ class BrickMetadataList(BrickRecordList[T]):
|
||||
# Queries
|
||||
select_query: str
|
||||
|
||||
# Set endpoints
|
||||
set_state_endpoint: str
|
||||
set_value_endpoint: str
|
||||
# List-specific endpoints (for operations on the list itself)
|
||||
set_state_endpoint: str = ''
|
||||
set_value_endpoint: str = ''
|
||||
individual_minifigure_value_endpoint: str = ''
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -99,12 +100,15 @@ class BrickMetadataList(BrickRecordList[T]):
|
||||
|
||||
# Return the items as columns for a select
|
||||
@classmethod
|
||||
def as_columns(cls, /, **kwargs) -> str:
|
||||
def as_columns(cls, /, table: str | None = None, **kwargs) -> str:
|
||||
new = cls.new()
|
||||
|
||||
# Use provided table name or default to class table
|
||||
table_name = table if table is not None else cls.table
|
||||
|
||||
return ', '.join([
|
||||
'"{table}"."{column}"'.format(
|
||||
table=cls.table,
|
||||
table=table_name,
|
||||
column=record.as_column(),
|
||||
)
|
||||
for record
|
||||
@@ -184,3 +188,11 @@ class BrickMetadataList(BrickRecordList[T]):
|
||||
cls.set_value_endpoint,
|
||||
id=id,
|
||||
)
|
||||
|
||||
# URL to change the selected value of this metadata item for an individual minifigure
|
||||
@classmethod
|
||||
def url_for_individual_minifigure_value(cls, id: str, /) -> str:
|
||||
return url_for(
|
||||
cls.individual_minifigure_value_endpoint,
|
||||
id=id,
|
||||
)
|
||||
|
||||
@@ -43,19 +43,6 @@ class BrickMinifigureList(BrickRecordList[BrickMinifigure]):
|
||||
|
||||
return self
|
||||
|
||||
# Load all minifigures with problems filter
|
||||
def all_filtered(self, /, problems_filter: str = 'all', theme_id: str = 'all', year: str = 'all') -> Self:
|
||||
context = {}
|
||||
if problems_filter and problems_filter != 'all':
|
||||
context['problems_filter'] = problems_filter
|
||||
if theme_id and theme_id != 'all':
|
||||
context['theme_id'] = theme_id
|
||||
if year and year != 'all':
|
||||
context['year'] = year
|
||||
|
||||
self.list(override_query=self.all_query, **context)
|
||||
return self
|
||||
|
||||
# Load all minifigures by owner
|
||||
def all_by_owner(self, owner_id: str | None = None, /) -> Self:
|
||||
# Save the owner_id parameter
|
||||
@@ -66,31 +53,10 @@ class BrickMinifigureList(BrickRecordList[BrickMinifigure]):
|
||||
|
||||
return self
|
||||
|
||||
# Load all minifigures by owner with problems filter
|
||||
def all_by_owner_filtered(self, /, owner_id: str | None = None, problems_filter: str = 'all', theme_id: str = 'all', year: str = 'all') -> Self:
|
||||
# Save the owner_id parameter
|
||||
self.fields.owner_id = owner_id
|
||||
|
||||
context = {}
|
||||
if problems_filter and problems_filter != 'all':
|
||||
context['problems_filter'] = problems_filter
|
||||
if theme_id and theme_id != 'all':
|
||||
context['theme_id'] = theme_id
|
||||
if year and year != 'all':
|
||||
context['year'] = year
|
||||
|
||||
# Load the minifigures from the database
|
||||
self.list(override_query=self.all_by_owner_query, **context)
|
||||
|
||||
return self
|
||||
|
||||
# Load minifigures with pagination support
|
||||
def all_filtered_paginated(
|
||||
self,
|
||||
owner_id: str | None = None,
|
||||
problems_filter: str = 'all',
|
||||
theme_id: str = 'all',
|
||||
year: str = 'all',
|
||||
search_query: str | None = None,
|
||||
page: int = 1,
|
||||
per_page: int = 50,
|
||||
@@ -108,23 +74,15 @@ class BrickMinifigureList(BrickRecordList[BrickMinifigure]):
|
||||
if search_query:
|
||||
filter_context['search_query'] = search_query
|
||||
|
||||
if problems_filter and problems_filter != 'all':
|
||||
filter_context['problems_filter'] = problems_filter
|
||||
|
||||
if theme_id and theme_id != 'all':
|
||||
filter_context['theme_id'] = theme_id
|
||||
|
||||
if year and year != 'all':
|
||||
filter_context['year'] = year
|
||||
|
||||
# Field mapping for sorting
|
||||
field_mapping = {
|
||||
'name': '"rebrickable_minifigures"."name"',
|
||||
'parts': '"rebrickable_minifigures"."number_of_parts"',
|
||||
'name': '"combined"."name"',
|
||||
'parts': '"combined"."number_of_parts"',
|
||||
'quantity': '"total_quantity"',
|
||||
'missing': '"total_missing"',
|
||||
'damaged': '"total_damaged"',
|
||||
'sets': '"total_sets"'
|
||||
'sets': '"total_sets"',
|
||||
'individual': '"total_individual"'
|
||||
}
|
||||
|
||||
# Use the base pagination method
|
||||
@@ -155,7 +113,7 @@ class BrickMinifigureList(BrickRecordList[BrickMinifigure]):
|
||||
if current_app.config['RANDOM']:
|
||||
order = 'RANDOM()'
|
||||
else:
|
||||
order = '"bricktracker_minifigures"."rowid" DESC'
|
||||
order = '"combined"."rowid" DESC'
|
||||
|
||||
self.list(override_query=self.last_query, order=order, limit=limit)
|
||||
|
||||
|
||||
+44
-15
@@ -5,29 +5,58 @@ from .exceptions import ErrorException
|
||||
def parse_set(set: str, /) -> str:
|
||||
number, _, version = set.partition('-')
|
||||
|
||||
# Set number can be alphanumeric (e.g., "McDR6US", "10312", "COMCON035")
|
||||
# Just validate it's not empty
|
||||
if not number or number.strip() == '':
|
||||
raise ErrorException('Set number cannot be empty')
|
||||
|
||||
# Clean up the number (trim whitespace)
|
||||
number = number.strip()
|
||||
|
||||
# Version defaults to 1 if not provided
|
||||
# Making sure both are integers
|
||||
if version == '':
|
||||
version = '1'
|
||||
version = 1
|
||||
|
||||
# Version must be a positive integer
|
||||
try:
|
||||
version_int = int(version)
|
||||
number = int(number)
|
||||
except Exception:
|
||||
raise ErrorException('Number "{number}" is not a number'.format(
|
||||
number=number,
|
||||
))
|
||||
|
||||
try:
|
||||
version = int(version)
|
||||
except Exception:
|
||||
raise ErrorException('Version "{version}" is not a number'.format(
|
||||
version=version,
|
||||
))
|
||||
|
||||
if version_int < 0:
|
||||
raise ErrorException('Version "{version}" should be positive'.format(
|
||||
# Make sure both are positive
|
||||
if number < 0:
|
||||
raise ErrorException('Number "{number}" should be positive'.format(
|
||||
number=number,
|
||||
))
|
||||
|
||||
if version < 0:
|
||||
raise ErrorException('Version "{version}" should be positive'.format( # noqa: E501
|
||||
version=version,
|
||||
))
|
||||
|
||||
return '{number}-{version}'.format(number=number, version=version_int)
|
||||
return '{number}-{version}'.format(number=number, version=version)
|
||||
|
||||
|
||||
# Make sense of string supposed to contain a minifigure ID
|
||||
def parse_minifig(figure: str, /) -> str:
|
||||
# Minifigure format is typically fig-XXXXXX
|
||||
# We'll accept with or without the 'fig-' prefix
|
||||
figure = figure.strip()
|
||||
|
||||
if not figure.startswith('fig-'):
|
||||
# Try to add the prefix if it's just numbers
|
||||
if figure.isdigit():
|
||||
figure = 'fig-{figure}'.format(figure=figure.zfill(6))
|
||||
else:
|
||||
raise ErrorException('Minifigure "{figure}" must start with "fig-"'.format(
|
||||
figure=figure,
|
||||
))
|
||||
|
||||
# Validate format: fig-XXXXXX where X can be digits or letters
|
||||
parts = figure.split('-')
|
||||
if len(parts) != 2 or parts[0] != 'fig':
|
||||
raise ErrorException('Invalid minifigure format "{figure}". Expected format: fig-XXXXXX'.format(
|
||||
figure=figure,
|
||||
))
|
||||
|
||||
return figure
|
||||
|
||||
+104
-2
@@ -181,7 +181,18 @@ class BrickPart(RebrickablePart):
|
||||
|
||||
# Compute the url for updating checked state
|
||||
def url_for_checked(self, /) -> str:
|
||||
# Different URL for a minifigure part
|
||||
# Check if this is an individual minifigure (has minifigure with id field, no brickset)
|
||||
if self.minifigure is not None and hasattr(self.minifigure.fields, 'id') and self.brickset is None:
|
||||
# Individual minifigure part
|
||||
return url_for(
|
||||
'individual_minifigure.checked_part',
|
||||
id=self.minifigure.fields.id,
|
||||
part=self.fields.part,
|
||||
color=self.fields.color,
|
||||
spare=self.fields.spare,
|
||||
)
|
||||
|
||||
# Set-based part (with or without minifigure)
|
||||
if self.minifigure is not None:
|
||||
figure = self.minifigure.fields.figure
|
||||
else:
|
||||
@@ -228,7 +239,19 @@ class BrickPart(RebrickablePart):
|
||||
|
||||
# Compute the url for problematic part
|
||||
def url_for_problem(self, problem: str, /) -> str:
|
||||
# Different URL for a minifigure part
|
||||
# Check if this is an individual minifigure (has minifigure with id field, no brickset)
|
||||
if self.minifigure is not None and hasattr(self.minifigure.fields, 'id') and self.brickset is None:
|
||||
# Individual minifigure part
|
||||
return url_for(
|
||||
'individual_minifigure.problem_part',
|
||||
id=self.minifigure.fields.id,
|
||||
part=self.fields.part,
|
||||
color=self.fields.color,
|
||||
spare=self.fields.spare,
|
||||
problem=problem,
|
||||
)
|
||||
|
||||
# Set-based part (with or without minifigure)
|
||||
if self.minifigure is not None:
|
||||
figure = self.minifigure.fields.figure
|
||||
else:
|
||||
@@ -243,3 +266,82 @@ class BrickPart(RebrickablePart):
|
||||
spare=self.fields.spare,
|
||||
problem=problem,
|
||||
)
|
||||
|
||||
# Select a specific part from an individual minifigure
|
||||
def select_specific_individual_minifigure(
|
||||
self,
|
||||
minifigure: 'BrickMinifigure',
|
||||
part: str,
|
||||
color: int,
|
||||
spare: int,
|
||||
/,
|
||||
) -> Self:
|
||||
# Save the parameters to the fields
|
||||
self.minifigure = minifigure
|
||||
self.fields.id = minifigure.fields.id
|
||||
self.fields.part = part
|
||||
self.fields.color = color
|
||||
self.fields.spare = spare
|
||||
|
||||
if not self.select(override_query='individual_minifigure/part/select/specific'):
|
||||
raise NotFoundException(
|
||||
'Part {part} with color {color} (spare: {spare}) from individual minifigure {figure} ({id}) was not found in the database'.format(
|
||||
part=self.fields.part,
|
||||
color=self.fields.color,
|
||||
spare=self.fields.spare,
|
||||
figure=self.minifigure.fields.figure,
|
||||
id=self.minifigure.fields.id,
|
||||
),
|
||||
)
|
||||
|
||||
return self
|
||||
|
||||
# Update a problematic part for individual minifigure
|
||||
def update_problem_individual_minifigure(self, problem: str, json: Any | None, /) -> int:
|
||||
amount: str | int = json.get('value', '') # type: ignore
|
||||
|
||||
# We need a positive integer
|
||||
try:
|
||||
if amount == '':
|
||||
amount = 0
|
||||
|
||||
amount = int(amount)
|
||||
|
||||
if amount < 0:
|
||||
amount = 0
|
||||
except Exception:
|
||||
raise ErrorException('"{amount}" is not a valid integer'.format(
|
||||
amount=amount
|
||||
))
|
||||
|
||||
if amount < 0:
|
||||
raise ErrorException('Cannot set a negative amount')
|
||||
|
||||
setattr(self.fields, problem, amount)
|
||||
|
||||
BrickSQL().execute_and_commit(
|
||||
'individual_minifigure/part/update/{problem}'.format(problem=problem),
|
||||
parameters=self.sql_parameters()
|
||||
)
|
||||
|
||||
return amount
|
||||
|
||||
# Update checked state for individual minifigure part
|
||||
def update_checked_individual_minifigure(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(
|
||||
'individual_minifigure/part/update/checked',
|
||||
parameters=self.sql_parameters()
|
||||
)
|
||||
|
||||
return checked
|
||||
|
||||
+27
-60
@@ -25,6 +25,7 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
all_query: str = 'part/list/all'
|
||||
all_by_owner_query: str = 'part/list/all_by_owner'
|
||||
different_color_query = 'part/list/with_different_color'
|
||||
individual_minifigure_query: str = 'individual_minifigure/part/list/from_instance'
|
||||
last_query: str = 'part/list/last'
|
||||
minifigure_query: str = 'part/list/from_minifigure'
|
||||
problem_query: str = 'part/list/problem'
|
||||
@@ -57,8 +58,8 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
|
||||
return self
|
||||
|
||||
# Load all parts with filters (owner, color, theme, year)
|
||||
def all_filtered(self, owner_id: str | None = None, color_id: str | None = None, theme_id: str | None = None, year: str | None = None, /) -> Self:
|
||||
# Load all parts with filters (owner and/or color)
|
||||
def all_filtered(self, owner_id: str | None = None, color_id: str | None = None, /) -> Self:
|
||||
# Save the filter parameters
|
||||
if owner_id is not None:
|
||||
self.fields.owner_id = owner_id
|
||||
@@ -73,13 +74,8 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
|
||||
# Prepare context for query
|
||||
context = {}
|
||||
# Hide spare parts from display if configured
|
||||
if current_app.config.get('HIDE_SPARE_PARTS', False):
|
||||
if current_app.config.get('SKIP_SPARE_PARTS', False):
|
||||
context['skip_spare_parts'] = True
|
||||
if theme_id and theme_id != 'all':
|
||||
context['theme_id'] = theme_id
|
||||
if year and year != 'all':
|
||||
context['year'] = year
|
||||
|
||||
# Load the parts from the database
|
||||
self.list(override_query=query, **context)
|
||||
@@ -91,8 +87,6 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
self,
|
||||
owner_id: str | None = None,
|
||||
color_id: str | None = None,
|
||||
theme_id: str | None = None,
|
||||
year: str | None = None,
|
||||
search_query: str | None = None,
|
||||
page: int = 1,
|
||||
per_page: int = 50,
|
||||
@@ -109,14 +103,9 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
|
||||
if color_id and color_id != 'all':
|
||||
filter_context['color_id'] = color_id
|
||||
if theme_id and theme_id != 'all':
|
||||
filter_context['theme_id'] = theme_id
|
||||
if year and year != 'all':
|
||||
filter_context['year'] = year
|
||||
if search_query:
|
||||
filter_context['search_query'] = search_query
|
||||
# Hide spare parts from display if configured
|
||||
if current_app.config.get('HIDE_SPARE_PARTS', False):
|
||||
if current_app.config.get('SKIP_SPARE_PARTS', False):
|
||||
filter_context['skip_spare_parts'] = True
|
||||
|
||||
# Field mapping for sorting
|
||||
@@ -205,13 +194,8 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
self.brickset = brickset
|
||||
self.minifigure = minifigure
|
||||
|
||||
# Prepare context for hiding spare parts if configured
|
||||
context = {}
|
||||
if current_app.config.get('HIDE_SPARE_PARTS', False):
|
||||
context['skip_spare_parts'] = True
|
||||
|
||||
# Load the parts from the database
|
||||
self.list(**context)
|
||||
self.list()
|
||||
|
||||
return self
|
||||
|
||||
@@ -224,13 +208,22 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
# Save the minifigure
|
||||
self.minifigure = minifigure
|
||||
|
||||
# Prepare context for hiding spare parts if configured
|
||||
context = {}
|
||||
if current_app.config.get('HIDE_SPARE_PARTS', False):
|
||||
context['skip_spare_parts'] = True
|
||||
|
||||
# Load the parts from the database
|
||||
self.list(override_query=self.minifigure_query, **context)
|
||||
self.list(override_query=self.minifigure_query)
|
||||
|
||||
return self
|
||||
|
||||
# Load parts from an individual minifigure instance
|
||||
def from_individual_minifigure(
|
||||
self,
|
||||
minifigure: 'BrickMinifigure',
|
||||
/,
|
||||
) -> Self:
|
||||
# Save the minifigure
|
||||
self.minifigure = minifigure
|
||||
|
||||
# Load the parts from the database using the instance-specific query
|
||||
self.list(override_query=self.individual_minifigure_query)
|
||||
|
||||
return self
|
||||
|
||||
@@ -260,7 +253,7 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
|
||||
return self
|
||||
|
||||
def problem_filtered(self, owner_id: str | None = None, color_id: str | None = None, theme_id: str | None = None, year: str | None = None, storage_id: str | None = None, tag_id: str | None = None, /) -> Self:
|
||||
def problem_filtered(self, owner_id: str | None = None, color_id: str | None = None, /) -> Self:
|
||||
# Save the filter parameters for client-side filtering
|
||||
if owner_id is not None:
|
||||
self.fields.owner_id = owner_id
|
||||
@@ -273,16 +266,7 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
context['owner_id'] = owner_id
|
||||
if color_id and color_id != 'all':
|
||||
context['color_id'] = color_id
|
||||
if theme_id and theme_id != 'all':
|
||||
context['theme_id'] = theme_id
|
||||
if year and year != 'all':
|
||||
context['year'] = year
|
||||
if storage_id and storage_id != 'all':
|
||||
context['storage_id'] = storage_id
|
||||
if tag_id and tag_id != 'all':
|
||||
context['tag_id'] = tag_id
|
||||
# Hide spare parts from display if configured
|
||||
if current_app.config.get('HIDE_SPARE_PARTS', False):
|
||||
if current_app.config.get('SKIP_SPARE_PARTS', False):
|
||||
context['skip_spare_parts'] = True
|
||||
|
||||
# Load the problematic parts from the database
|
||||
@@ -294,10 +278,6 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
self,
|
||||
owner_id: str | None = None,
|
||||
color_id: str | None = None,
|
||||
theme_id: str | None = None,
|
||||
year: str | None = None,
|
||||
storage_id: str | None = None,
|
||||
tag_id: str | None = None,
|
||||
search_query: str | None = None,
|
||||
page: int = 1,
|
||||
per_page: int = 50,
|
||||
@@ -310,18 +290,9 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
filter_context['owner_id'] = owner_id
|
||||
if color_id and color_id != 'all':
|
||||
filter_context['color_id'] = color_id
|
||||
if theme_id and theme_id != 'all':
|
||||
filter_context['theme_id'] = theme_id
|
||||
if year and year != 'all':
|
||||
filter_context['year'] = year
|
||||
if storage_id and storage_id != 'all':
|
||||
filter_context['storage_id'] = storage_id
|
||||
if tag_id and tag_id != 'all':
|
||||
filter_context['tag_id'] = tag_id
|
||||
if search_query:
|
||||
filter_context['search_query'] = search_query
|
||||
# Hide spare parts from display if configured
|
||||
if current_app.config.get('HIDE_SPARE_PARTS', False):
|
||||
if current_app.config.get('SKIP_SPARE_PARTS', False):
|
||||
filter_context['skip_spare_parts'] = True
|
||||
|
||||
# Field mapping for sorting
|
||||
@@ -350,9 +321,11 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
def sql_parameters(self, /) -> dict[str, Any]:
|
||||
parameters: dict[str, Any] = super().sql_parameters()
|
||||
|
||||
# Set id
|
||||
# Set id - prioritize brickset, then check minifigure
|
||||
if self.brickset is not None:
|
||||
parameters['id'] = self.brickset.fields.id
|
||||
elif self.minifigure is not None and hasattr(self.minifigure.fields, 'id'):
|
||||
parameters['id'] = self.minifigure.fields.id
|
||||
|
||||
# Use the minifigure number if present,
|
||||
if self.minifigure is not None:
|
||||
@@ -421,13 +394,7 @@ class BrickPartList(BrickRecordList[BrickPart]):
|
||||
|
||||
# Process each part
|
||||
number_of_parts: int = 0
|
||||
skip_spares = current_app.config.get('SKIP_SPARE_PARTS', False)
|
||||
|
||||
for part in inventory:
|
||||
# Skip spare parts if configured
|
||||
if skip_spares and part.fields.spare:
|
||||
continue
|
||||
|
||||
# Count the number of parts for minifigures
|
||||
if minifigure is not None:
|
||||
number_of_parts += part.fields.quantity
|
||||
|
||||
@@ -7,6 +7,7 @@ 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
|
||||
|
||||
@@ -52,12 +53,12 @@ def get_peeron_scan_url(set_number: str, version_number: str):
|
||||
|
||||
|
||||
def create_peeron_scraper():
|
||||
"""Create a requests session configured for Peeron"""
|
||||
session = requests.Session()
|
||||
session.headers.update({
|
||||
"""Create a cloudscraper instance configured for Peeron"""
|
||||
scraper = cloudscraper.create_scraper()
|
||||
scraper.headers.update({
|
||||
"User-Agent": get_peeron_user_agent()
|
||||
})
|
||||
return session
|
||||
return scraper
|
||||
|
||||
|
||||
def get_peeron_cache_dir():
|
||||
|
||||
@@ -4,6 +4,7 @@ import tempfile
|
||||
import time
|
||||
from typing import Any, TYPE_CHECKING
|
||||
|
||||
import cloudscraper
|
||||
from flask import current_app
|
||||
from PIL import Image
|
||||
|
||||
@@ -187,15 +188,10 @@ class PeeronPDF(object):
|
||||
# Get target file path
|
||||
def _get_target_path(self, /) -> str:
|
||||
"""Get the full path where the PDF should be saved"""
|
||||
folder = current_app.config['INSTRUCTIONS_FOLDER']
|
||||
|
||||
# If folder is absolute, use it directly
|
||||
# Otherwise, make it relative to app root (not static folder)
|
||||
if os.path.isabs(folder):
|
||||
instructions_folder = folder
|
||||
else:
|
||||
instructions_folder = os.path.join(current_app.root_path, folder)
|
||||
|
||||
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
|
||||
|
||||
@@ -53,23 +53,6 @@ class RebrickableImage(object):
|
||||
if os.path.exists(path):
|
||||
return
|
||||
|
||||
# Check if the original image field is null - copy nil placeholder instead
|
||||
if self.part is not None and self.part.fields.image is None:
|
||||
return
|
||||
if self.minifigure is not None and self.minifigure.fields.image is None:
|
||||
return
|
||||
if self.set.fields.image is None:
|
||||
# Copy nil.png from parts folder to sets folder with set number as filename
|
||||
parts_folder = current_app.config['PARTS_FOLDER']
|
||||
if not os.path.isabs(parts_folder):
|
||||
parts_folder = os.path.join(current_app.root_path, parts_folder)
|
||||
nil_source = os.path.join(parts_folder, f"{RebrickableImage.nil_name()}.{self.extension}")
|
||||
|
||||
if os.path.exists(nil_source):
|
||||
import shutil
|
||||
shutil.copy2(nil_source, path)
|
||||
return
|
||||
|
||||
url = self.url()
|
||||
if url is None:
|
||||
return
|
||||
@@ -113,16 +96,9 @@ class RebrickableImage(object):
|
||||
|
||||
# Return the path depending on the objects provided
|
||||
def path(self, /) -> str:
|
||||
folder = self.folder()
|
||||
# If folder is an absolute path (starts with /), use it directly
|
||||
# Otherwise, make it relative to app root (current_app.root_path)
|
||||
if folder.startswith('/'):
|
||||
base_path = folder
|
||||
else:
|
||||
base_path = os.path.join(current_app.root_path, folder)
|
||||
|
||||
return os.path.join(
|
||||
base_path,
|
||||
current_app.static_folder, # type: ignore
|
||||
self.folder(),
|
||||
'{id}.{ext}'.format(id=self.id(), ext=self.extension),
|
||||
)
|
||||
|
||||
@@ -140,11 +116,7 @@ class RebrickableImage(object):
|
||||
else:
|
||||
return self.minifigure.fields.image
|
||||
|
||||
# Handle set images - use nil placeholder if image is null
|
||||
if self.set.fields.image is None:
|
||||
return current_app.config['REBRICKABLE_IMAGE_NIL']
|
||||
else:
|
||||
return self.set.fields.image
|
||||
return self.set.fields.image
|
||||
|
||||
# Return the name of the nil image file
|
||||
@staticmethod
|
||||
@@ -180,21 +152,10 @@ class RebrickableImage(object):
|
||||
# _, extension = os.path.splitext(self.part_img_url)
|
||||
extension = '.jpg'
|
||||
|
||||
# Determine which route to use based on folder path
|
||||
# If folder contains 'data' (new structure), use data route
|
||||
# Otherwise use static route (legacy - relative paths like 'parts', 'sets')
|
||||
if 'data' in folder:
|
||||
# Extract the folder type from the folder_name config key
|
||||
# E.g., 'PARTS_FOLDER' -> 'parts', 'SETS_FOLDER' -> 'sets'
|
||||
folder_type = folder_name.replace('_FOLDER', '').lower()
|
||||
filename = '{name}{ext}'.format(name=name, ext=extension)
|
||||
return url_for('data.serve_data_file', folder=folder_type, filename=filename)
|
||||
else:
|
||||
# Legacy: folder is relative to static/ (e.g., 'parts' or 'static/parts')
|
||||
# Strip 'static/' prefix if present to avoid double /static/ in URL
|
||||
folder_clean = folder.removeprefix('static/')
|
||||
path = os.path.join(folder_clean, '{name}{ext}'.format(
|
||||
name=name,
|
||||
ext=extension,
|
||||
))
|
||||
return url_for('static', filename=path)
|
||||
# Compute the path
|
||||
path = os.path.join(folder, '{name}{ext}'.format(
|
||||
name=name,
|
||||
ext=extension,
|
||||
))
|
||||
|
||||
return url_for('static', filename=path)
|
||||
|
||||
@@ -155,18 +155,9 @@ class RebrickableSet(BrickRecord):
|
||||
|
||||
# Return a short form of the Rebrickable set
|
||||
def short(self, /, *, from_download: bool = False) -> dict[str, Any]:
|
||||
# Use nil image URL if set image is null
|
||||
image_url = self.fields.image
|
||||
if image_url is None:
|
||||
# Return path to nil.png from parts folder
|
||||
image_url = RebrickableImage.static_url(
|
||||
RebrickableImage.nil_name(),
|
||||
'PARTS_FOLDER'
|
||||
)
|
||||
|
||||
return {
|
||||
'download': from_download,
|
||||
'image': image_url,
|
||||
'image': self.fields.image,
|
||||
'name': self.fields.name,
|
||||
'set': self.fields.set,
|
||||
}
|
||||
@@ -205,18 +196,17 @@ class RebrickableSet(BrickRecord):
|
||||
@staticmethod
|
||||
def from_rebrickable(data: dict[str, Any], /, **_) -> dict[str, Any]:
|
||||
# Extracting version and number
|
||||
# Note: number can be alphanumeric (e.g., "McDR6US", "COMCON035")
|
||||
number, _, version = str(data['set_num']).partition('-')
|
||||
|
||||
return {
|
||||
'set': str(data['set_num']),
|
||||
'number': str(number), # Keep as string to support alphanumeric sets
|
||||
'number': int(number),
|
||||
'version': int(version),
|
||||
'name': str(data['name']),
|
||||
'year': int(data['year']),
|
||||
'theme_id': int(data['theme_id']),
|
||||
'number_of_parts': int(data['num_parts']),
|
||||
'image': str(data['set_img_url']) if data['set_img_url'] is not None else None,
|
||||
'image': str(data['set_img_url']),
|
||||
'url': str(data['set_url']),
|
||||
'last_modified': str(data['last_modified_dt']),
|
||||
}
|
||||
|
||||
+4
-6
@@ -59,10 +59,6 @@ class BrickSet(RebrickableSet):
|
||||
# Generate an UUID for self
|
||||
self.fields.id = str(uuid4())
|
||||
|
||||
# Insert the rebrickable set into database FIRST
|
||||
# This must happen before inserting bricktracker_sets due to FK constraint
|
||||
self.insert_rebrickable()
|
||||
|
||||
if not refresh:
|
||||
# Save the storage
|
||||
storage = BrickSetStorageList.get(
|
||||
@@ -78,8 +74,7 @@ class BrickSet(RebrickableSet):
|
||||
)
|
||||
self.fields.purchase_location = purchase_location.fields.id
|
||||
|
||||
# Insert into database (deferred - will execute at final commit)
|
||||
# All operations are atomic - if anything fails, nothing is committed
|
||||
# Insert into database
|
||||
self.insert(commit=False)
|
||||
|
||||
# Save the owners
|
||||
@@ -96,6 +91,9 @@ class BrickSet(RebrickableSet):
|
||||
tag = BrickSetTagList.get(id)
|
||||
tag.update_set_state(self, state=True)
|
||||
|
||||
# Insert the rebrickable set into database
|
||||
self.insert_rebrickable()
|
||||
|
||||
# Load the inventory
|
||||
if not BrickPartList.download(socket, self, refresh=refresh):
|
||||
return False
|
||||
|
||||
@@ -36,6 +36,7 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
using_minifigure_query: str = 'set/list/using_minifigure'
|
||||
using_part_query: str = 'set/list/using_part'
|
||||
using_storage_query: str = 'set/list/using_storage'
|
||||
without_storage_query: str = 'set/list/without_storage'
|
||||
|
||||
def __init__(self, /):
|
||||
super().__init__()
|
||||
@@ -670,10 +671,17 @@ class BrickSetList(BrickRecordList[BrickSet]):
|
||||
|
||||
return self
|
||||
|
||||
def without_storage(self, /) -> Self:
|
||||
# Load sets with no storage
|
||||
self.list(override_query=self.without_storage_query)
|
||||
|
||||
return self
|
||||
|
||||
|
||||
# Helper to build the metadata lists
|
||||
def set_metadata_lists(
|
||||
as_class: bool = False
|
||||
as_class: bool = False,
|
||||
hardcoded_statuses_only: bool = False
|
||||
) -> dict[
|
||||
str,
|
||||
Union[
|
||||
@@ -685,9 +693,20 @@ def set_metadata_lists(
|
||||
list[BrickSetTag]
|
||||
]
|
||||
]:
|
||||
# Get all statuses
|
||||
all_statuses = BrickSetStatusList.list(all=True)
|
||||
|
||||
# Filter to only hardcoded statuses if requested (for individual minifigures)
|
||||
if hardcoded_statuses_only:
|
||||
hardcoded_status_ids = ['minifigures_collected', 'set_checked', 'set_collected']
|
||||
statuses = [s for s in all_statuses if s.fields.id in hardcoded_status_ids]
|
||||
else:
|
||||
statuses = all_statuses
|
||||
|
||||
return {
|
||||
'brickset_owners': BrickSetOwnerList.list(),
|
||||
'brickset_purchase_locations': BrickSetPurchaseLocationList.list(as_class=as_class), # noqa: E501
|
||||
'brickset_statuses': statuses,
|
||||
'brickset_storages': BrickSetStorageList.list(as_class=as_class),
|
||||
'brickset_tags': BrickSetTagList.list(),
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ from .metadata import BrickMetadata
|
||||
class BrickSetOwner(BrickMetadata):
|
||||
kind: str = 'owner'
|
||||
|
||||
# Set state endpoint
|
||||
# Endpoints
|
||||
set_state_endpoint: str = 'set.update_owner'
|
||||
individual_minifigure_state_endpoint: str = 'individual_minifigure.update_owner'
|
||||
|
||||
# Queries
|
||||
delete_query: str = 'set/metadata/owner/delete'
|
||||
@@ -14,3 +15,4 @@ class BrickSetOwner(BrickMetadata):
|
||||
select_query: str = 'set/metadata/owner/select'
|
||||
update_field_query: str = 'set/metadata/owner/update/field'
|
||||
update_set_state_query: str = 'set/metadata/owner/update/state'
|
||||
update_individual_minifigure_state_query: str = 'individual_minifigure/metadata/owner/update/state'
|
||||
|
||||
@@ -15,6 +15,9 @@ class BrickSetOwnerList(BrickMetadataList[BrickSetOwner]):
|
||||
# Queries
|
||||
select_query = 'set/metadata/owner/list'
|
||||
|
||||
# Endpoints
|
||||
set_state_endpoint: str = 'set.update_owner'
|
||||
|
||||
# Instantiate the list with the proper class
|
||||
@classmethod
|
||||
def new(cls, /, *, force: bool = False) -> Self:
|
||||
|
||||
@@ -5,9 +5,13 @@ from .metadata import BrickMetadata
|
||||
class BrickSetPurchaseLocation(BrickMetadata):
|
||||
kind: str = 'purchase location'
|
||||
|
||||
# Endpoints
|
||||
individual_minifigure_value_endpoint: str = 'individual_minifigure.update_purchase_location'
|
||||
|
||||
# Queries
|
||||
delete_query: str = 'set/metadata/purchase_location/delete'
|
||||
insert_query: str = 'set/metadata/purchase_location/insert'
|
||||
select_query: str = 'set/metadata/purchase_location/select'
|
||||
update_field_query: str = 'set/metadata/purchase_location/update/field'
|
||||
update_set_value_query: str = 'set/metadata/purchase_location/update/value'
|
||||
update_individual_minifigure_value_query: str = 'individual_minifigure/metadata/purchase_location/update/value'
|
||||
|
||||
@@ -22,6 +22,9 @@ class BrickSetPurchaseLocationList(
|
||||
# Set value endpoint
|
||||
set_value_endpoint: str = 'set.update_purchase_location'
|
||||
|
||||
# Individual minifigure value endpoint
|
||||
individual_minifigure_value_endpoint: str = 'individual_minifigure.update_purchase_location'
|
||||
|
||||
# Load all purchase locations
|
||||
@classmethod
|
||||
def all(cls, /) -> Self:
|
||||
|
||||
@@ -7,8 +7,9 @@ from .metadata import BrickMetadata
|
||||
class BrickSetStatus(BrickMetadata):
|
||||
kind: str = 'status'
|
||||
|
||||
# Set state endpoint
|
||||
# Endpoints
|
||||
set_state_endpoint: str = 'set.update_status'
|
||||
individual_minifigure_state_endpoint: str = 'individual_minifigure.update_status'
|
||||
|
||||
# Queries
|
||||
delete_query: str = 'set/metadata/status/delete'
|
||||
@@ -16,6 +17,7 @@ class BrickSetStatus(BrickMetadata):
|
||||
select_query: str = 'set/metadata/status/select'
|
||||
update_field_query: str = 'set/metadata/status/update/field'
|
||||
update_set_state_query: str = 'set/metadata/status/update/state'
|
||||
update_individual_minifigure_state_query: str = 'individual_minifigure/metadata/status/update/state'
|
||||
|
||||
# Grab data from a form
|
||||
def from_form(self, form: dict[str, str], /) -> Self:
|
||||
|
||||
@@ -15,6 +15,9 @@ class BrickSetStatusList(BrickMetadataList[BrickSetStatus]):
|
||||
# Queries
|
||||
select_query = 'set/metadata/status/list'
|
||||
|
||||
# Endpoints
|
||||
set_state_endpoint: str = 'set.update_status'
|
||||
|
||||
# Filter the list of set status
|
||||
def filter(self, all: bool = False) -> list[BrickSetStatus]:
|
||||
return [
|
||||
|
||||
@@ -7,12 +7,16 @@ from flask import url_for
|
||||
class BrickSetStorage(BrickMetadata):
|
||||
kind: str = 'storage'
|
||||
|
||||
# Endpoints
|
||||
individual_minifigure_value_endpoint: str = 'individual_minifigure.update_storage'
|
||||
|
||||
# Queries
|
||||
delete_query: str = 'set/metadata/storage/delete'
|
||||
insert_query: str = 'set/metadata/storage/insert'
|
||||
select_query: str = 'set/metadata/storage/select'
|
||||
update_field_query: str = 'set/metadata/storage/update/field'
|
||||
update_set_value_query: str = 'set/metadata/storage/update/value'
|
||||
update_individual_minifigure_value_query: str = 'individual_minifigure/metadata/storage/update/value'
|
||||
|
||||
# Self url
|
||||
def url(self, /) -> str:
|
||||
|
||||
@@ -20,6 +20,9 @@ class BrickSetStorageList(BrickMetadataList[BrickSetStorage]):
|
||||
# Set value endpoint
|
||||
set_value_endpoint: str = 'set.update_storage'
|
||||
|
||||
# Individual minifigure value endpoint
|
||||
individual_minifigure_value_endpoint: str = 'individual_minifigure.update_storage'
|
||||
|
||||
# Load all storages
|
||||
@classmethod
|
||||
def all(cls, /) -> Self:
|
||||
|
||||
@@ -5,8 +5,9 @@ from .metadata import BrickMetadata
|
||||
class BrickSetTag(BrickMetadata):
|
||||
kind: str = 'tag'
|
||||
|
||||
# Set state endpoint
|
||||
# Endpoints
|
||||
set_state_endpoint: str = 'set.update_tag'
|
||||
individual_minifigure_state_endpoint: str = 'individual_minifigure.update_tag'
|
||||
|
||||
# Queries
|
||||
delete_query: str = 'set/metadata/tag/delete'
|
||||
@@ -14,3 +15,4 @@ class BrickSetTag(BrickMetadata):
|
||||
select_query: str = 'set/metadata/tag/select'
|
||||
update_field_query: str = 'set/metadata/tag/update/field'
|
||||
update_set_state_query: str = 'set/metadata/tag/update/state'
|
||||
update_individual_minifigure_state_query: str = 'individual_minifigure/metadata/tag/update/state'
|
||||
|
||||
@@ -15,6 +15,9 @@ class BrickSetTagList(BrickMetadataList[BrickSetTag]):
|
||||
# Queries
|
||||
select_query: str = 'set/metadata/tag/list'
|
||||
|
||||
# Endpoints
|
||||
set_state_endpoint: str = 'set.update_tag'
|
||||
|
||||
# Instantiate the list with the proper class
|
||||
@classmethod
|
||||
def new(cls, /, *, force: bool = False) -> Self:
|
||||
|
||||
+27
-39
@@ -22,9 +22,12 @@ MESSAGES: Final[dict[str, str]] = {
|
||||
'DOWNLOAD_INSTRUCTIONS': 'download_instructions',
|
||||
'DOWNLOAD_PEERON_PAGES': 'download_peeron_pages',
|
||||
'FAIL': 'fail',
|
||||
'IMPORT_MINIFIGURE': 'import_minifigure',
|
||||
'IMPORT_SET': 'import_set',
|
||||
'LOAD_MINIFIGURE': 'load_minifigure',
|
||||
'LOAD_PEERON_PAGES': 'load_peeron_pages',
|
||||
'LOAD_SET': 'load_set',
|
||||
'MINIFIGURE_LOADED': 'minifigure_loaded',
|
||||
'PROGRESS': 'progress',
|
||||
'SET_LOADED': 'set_loaded',
|
||||
}
|
||||
@@ -75,9 +78,6 @@ class BrickSocket(object):
|
||||
**kwargs,
|
||||
path=app.config['SOCKET_PATH'],
|
||||
async_mode='gevent',
|
||||
# Ping/pong settings for mobile network resilience
|
||||
ping_timeout=30, # Wait 30s for pong response before disconnecting
|
||||
ping_interval=25, # Send ping every 25s to keep connection alive
|
||||
)
|
||||
|
||||
# Store the socket in the app config
|
||||
@@ -89,23 +89,9 @@ class BrickSocket(object):
|
||||
self.connected()
|
||||
|
||||
@self.socket.on(MESSAGES['DISCONNECT'], namespace=self.namespace)
|
||||
def disconnect(reason=None) -> None:
|
||||
def disconnect() -> None:
|
||||
self.disconnected()
|
||||
|
||||
@self.socket.on('connect_error', namespace=self.namespace)
|
||||
def connect_error(data) -> None:
|
||||
logger.error(f'Socket CONNECT_ERROR: {data}')
|
||||
|
||||
@self.socket.on_error(namespace=self.namespace)
|
||||
def error_handler(e) -> None:
|
||||
logger.error(f'Socket ERROR: {e}')
|
||||
try:
|
||||
user_agent = request.headers.get('User-Agent', 'unknown')
|
||||
remote_addr = request.remote_addr
|
||||
logger.error(f'Socket ERROR details: ip={remote_addr}, ua={user_agent[:80]}...')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@self.socket.on(MESSAGES['DOWNLOAD_INSTRUCTIONS'], namespace=self.namespace) # noqa: E501
|
||||
@authenticated_socket(self)
|
||||
def download_instructions(data: dict[str, Any], /) -> None:
|
||||
@@ -224,6 +210,27 @@ class BrickSocket(object):
|
||||
|
||||
BrickSet().load(self, data)
|
||||
|
||||
@self.socket.on(MESSAGES['IMPORT_MINIFIGURE'], namespace=self.namespace)
|
||||
@rebrickable_socket(self)
|
||||
def import_minifigure(data: dict[str, Any], /) -> None:
|
||||
logger.debug('Socket: IMPORT_MINIFIGURE={data} (from: {fr})'.format(
|
||||
data=data,
|
||||
fr=request.sid, # type: ignore
|
||||
))
|
||||
|
||||
from .individual_minifigure import IndividualMinifigure
|
||||
IndividualMinifigure().download(self, data)
|
||||
|
||||
@self.socket.on(MESSAGES['LOAD_MINIFIGURE'], namespace=self.namespace)
|
||||
def load_minifigure(data: dict[str, Any], /) -> None:
|
||||
logger.debug('Socket: LOAD_MINIFIGURE={data} (from: {fr})'.format(
|
||||
data=data,
|
||||
fr=request.sid, # type: ignore
|
||||
))
|
||||
|
||||
from .individual_minifigure import IndividualMinifigure
|
||||
IndividualMinifigure().load(self, data)
|
||||
|
||||
# Update the progress auto-incrementing
|
||||
def auto_progress(
|
||||
self,
|
||||
@@ -249,32 +256,13 @@ class BrickSocket(object):
|
||||
|
||||
# Socket is connected
|
||||
def connected(self, /) -> Tuple[str, int]:
|
||||
# Get detailed connection info for debugging
|
||||
try:
|
||||
sid = request.sid # type: ignore
|
||||
transport = request.environ.get('HTTP_UPGRADE', 'polling')
|
||||
user_agent = request.headers.get('User-Agent', 'unknown')
|
||||
remote_addr = request.remote_addr
|
||||
|
||||
# Check if it's likely a mobile device
|
||||
is_mobile = any(x in user_agent.lower() for x in ['iphone', 'ipad', 'android', 'mobile'])
|
||||
|
||||
logger.info(
|
||||
f'Socket CONNECTED: sid={sid}, transport={transport}, '
|
||||
f'ip={remote_addr}, mobile={is_mobile}, ua={user_agent[:80]}...'
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f'Socket connected but failed to get details: {e}')
|
||||
logger.debug('Socket: client connected')
|
||||
|
||||
return '', 301
|
||||
|
||||
# Socket is disconnected
|
||||
def disconnected(self, /) -> None:
|
||||
try:
|
||||
sid = request.sid # type: ignore
|
||||
logger.info(f'Socket DISCONNECTED: sid={sid}')
|
||||
except Exception as e:
|
||||
logger.info(f'Socket disconnected (sid unavailable): {e}')
|
||||
logger.debug('Socket: client disconnected')
|
||||
|
||||
# Emit a message through the socket
|
||||
def emit(self, name: str, *arg, all=False) -> None:
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
-- Delete individual minifigure parts
|
||||
DELETE FROM "bricktracker_individual_minifigure_parts"
|
||||
WHERE "id" = :id;
|
||||
|
||||
-- Delete individual minifigure owners
|
||||
DELETE FROM "bricktracker_individual_minifigure_owners"
|
||||
WHERE "id" = :id;
|
||||
|
||||
-- Delete individual minifigure tags
|
||||
DELETE FROM "bricktracker_individual_minifigure_tags"
|
||||
WHERE "id" = :id;
|
||||
|
||||
-- Delete individual minifigure statuses
|
||||
DELETE FROM "bricktracker_individual_minifigure_statuses"
|
||||
WHERE "id" = :id;
|
||||
|
||||
-- Delete the individual minifigure itself
|
||||
DELETE FROM "bricktracker_individual_minifigures"
|
||||
WHERE "id" = :id;
|
||||
@@ -0,0 +1,15 @@
|
||||
INSERT OR IGNORE INTO "bricktracker_individual_minifigures" (
|
||||
"id",
|
||||
"figure",
|
||||
"quantity",
|
||||
"description",
|
||||
"storage",
|
||||
"purchase_location"
|
||||
) VALUES (
|
||||
:id,
|
||||
:figure,
|
||||
:quantity,
|
||||
:description,
|
||||
:storage,
|
||||
:purchase_location
|
||||
)
|
||||
@@ -0,0 +1,48 @@
|
||||
-- Get all individual minifigure instances for a specific storage location
|
||||
SELECT
|
||||
"bricktracker_individual_minifigures"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigures"."quantity",
|
||||
"bricktracker_individual_minifigures"."description",
|
||||
"bricktracker_individual_minifigures"."storage",
|
||||
"bricktracker_individual_minifigures"."purchase_location",
|
||||
"rebrickable_minifigures"."number",
|
||||
"rebrickable_minifigures"."name",
|
||||
"rebrickable_minifigures"."image",
|
||||
"rebrickable_minifigures"."number_of_parts",
|
||||
"storage_meta"."name" AS "storage_name",
|
||||
"purchase_meta"."name" AS "purchase_location_name",
|
||||
IFNULL("problem_join"."total_missing", 0) AS "total_missing",
|
||||
IFNULL("problem_join"."total_damaged", 0) AS "total_damaged"
|
||||
FROM "bricktracker_individual_minifigures"
|
||||
|
||||
INNER JOIN "rebrickable_minifigures"
|
||||
ON "bricktracker_individual_minifigures"."figure" = "rebrickable_minifigures"."figure"
|
||||
|
||||
LEFT JOIN "bricktracker_metadata_storages" AS "storage_meta"
|
||||
ON "bricktracker_individual_minifigures"."storage" = "storage_meta"."id"
|
||||
|
||||
LEFT JOIN "bricktracker_metadata_purchase_locations" AS "purchase_meta"
|
||||
ON "bricktracker_individual_minifigures"."purchase_location" = "purchase_meta"."id"
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
SUM("bricktracker_individual_minifigure_parts"."missing") AS "total_missing",
|
||||
SUM("bricktracker_individual_minifigure_parts"."damaged") AS "total_damaged"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
GROUP BY "bricktracker_individual_minifigure_parts"."id"
|
||||
) "problem_join"
|
||||
ON "bricktracker_individual_minifigures"."id" = "problem_join"."id"
|
||||
|
||||
WHERE "bricktracker_individual_minifigures"."storage" IS NOT DISTINCT FROM :storage
|
||||
|
||||
{% if order %}
|
||||
ORDER BY {{ order }}
|
||||
{% else %}
|
||||
ORDER BY "bricktracker_individual_minifigures"."rowid" DESC
|
||||
{% endif %}
|
||||
|
||||
{% if limit %}
|
||||
LIMIT {{ limit }}
|
||||
{% endif %}
|
||||
@@ -0,0 +1,48 @@
|
||||
-- Get all individual minifigure instances without storage
|
||||
SELECT
|
||||
"bricktracker_individual_minifigures"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigures"."quantity",
|
||||
"bricktracker_individual_minifigures"."description",
|
||||
"bricktracker_individual_minifigures"."storage",
|
||||
"bricktracker_individual_minifigures"."purchase_location",
|
||||
"rebrickable_minifigures"."number",
|
||||
"rebrickable_minifigures"."name",
|
||||
"rebrickable_minifigures"."image",
|
||||
"rebrickable_minifigures"."number_of_parts",
|
||||
"storage_meta"."name" AS "storage_name",
|
||||
"purchase_meta"."name" AS "purchase_location_name",
|
||||
IFNULL("problem_join"."total_missing", 0) AS "total_missing",
|
||||
IFNULL("problem_join"."total_damaged", 0) AS "total_damaged"
|
||||
FROM "bricktracker_individual_minifigures"
|
||||
|
||||
INNER JOIN "rebrickable_minifigures"
|
||||
ON "bricktracker_individual_minifigures"."figure" = "rebrickable_minifigures"."figure"
|
||||
|
||||
LEFT JOIN "bricktracker_metadata_storages" AS "storage_meta"
|
||||
ON "bricktracker_individual_minifigures"."storage" = "storage_meta"."id"
|
||||
|
||||
LEFT JOIN "bricktracker_metadata_purchase_locations" AS "purchase_meta"
|
||||
ON "bricktracker_individual_minifigures"."purchase_location" = "purchase_meta"."id"
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
SUM("bricktracker_individual_minifigure_parts"."missing") AS "total_missing",
|
||||
SUM("bricktracker_individual_minifigure_parts"."damaged") AS "total_damaged"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
GROUP BY "bricktracker_individual_minifigure_parts"."id"
|
||||
) "problem_join"
|
||||
ON "bricktracker_individual_minifigures"."id" = "problem_join"."id"
|
||||
|
||||
WHERE "bricktracker_individual_minifigures"."storage" IS NULL
|
||||
|
||||
{% if order %}
|
||||
ORDER BY {{ order }}
|
||||
{% else %}
|
||||
ORDER BY "bricktracker_individual_minifigures"."rowid" DESC
|
||||
{% endif %}
|
||||
|
||||
{% if limit %}
|
||||
LIMIT {{ limit }}
|
||||
{% endif %}
|
||||
@@ -0,0 +1,10 @@
|
||||
INSERT INTO "bricktracker_individual_minifigure_owners" (
|
||||
"id",
|
||||
"{{name}}"
|
||||
) VALUES (
|
||||
:id,
|
||||
:state
|
||||
)
|
||||
ON CONFLICT("id")
|
||||
DO UPDATE SET "{{name}}" = :state
|
||||
WHERE "bricktracker_individual_minifigure_owners"."id" IS NOT DISTINCT FROM :id
|
||||
@@ -0,0 +1,10 @@
|
||||
INSERT INTO "bricktracker_individual_minifigure_statuses" (
|
||||
"id",
|
||||
"{{name}}"
|
||||
) VALUES (
|
||||
:id,
|
||||
:state
|
||||
)
|
||||
ON CONFLICT("id")
|
||||
DO UPDATE SET "{{name}}" = :state
|
||||
WHERE "bricktracker_individual_minifigure_statuses"."id" IS NOT DISTINCT FROM :id
|
||||
@@ -0,0 +1,10 @@
|
||||
INSERT INTO "bricktracker_individual_minifigure_tags" (
|
||||
"id",
|
||||
"{{name}}"
|
||||
) VALUES (
|
||||
:id,
|
||||
:state
|
||||
)
|
||||
ON CONFLICT("id")
|
||||
DO UPDATE SET "{{name}}" = :state
|
||||
WHERE "bricktracker_individual_minifigure_tags"."id" IS NOT DISTINCT FROM :id
|
||||
@@ -0,0 +1,23 @@
|
||||
INSERT OR IGNORE INTO "bricktracker_individual_minifigure_parts" (
|
||||
"id",
|
||||
"part",
|
||||
"color",
|
||||
"spare",
|
||||
"quantity",
|
||||
"element",
|
||||
"rebrickable_inventory",
|
||||
"missing",
|
||||
"damaged",
|
||||
"checked"
|
||||
) VALUES (
|
||||
:id,
|
||||
:part,
|
||||
:color,
|
||||
:spare,
|
||||
:quantity,
|
||||
:element,
|
||||
:rebrickable_inventory,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
)
|
||||
@@ -0,0 +1,38 @@
|
||||
-- Query parts for a specific individual minifigure instance
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigure_parts"."part",
|
||||
"bricktracker_individual_minifigure_parts"."color",
|
||||
"bricktracker_individual_minifigure_parts"."spare",
|
||||
"bricktracker_individual_minifigure_parts"."quantity",
|
||||
"bricktracker_individual_minifigure_parts"."element",
|
||||
"bricktracker_individual_minifigure_parts"."missing" AS "total_missing",
|
||||
"bricktracker_individual_minifigure_parts"."damaged" AS "total_damaged",
|
||||
"bricktracker_individual_minifigure_parts"."checked",
|
||||
"rebrickable_parts"."color_name",
|
||||
"rebrickable_parts"."color_rgb",
|
||||
"rebrickable_parts"."color_transparent",
|
||||
"rebrickable_parts"."bricklink_color_id",
|
||||
"rebrickable_parts"."bricklink_color_name",
|
||||
"rebrickable_parts"."bricklink_part_num",
|
||||
"rebrickable_parts"."name",
|
||||
"rebrickable_parts"."image",
|
||||
"rebrickable_parts"."image_id",
|
||||
"rebrickable_parts"."url",
|
||||
"rebrickable_parts"."print",
|
||||
NULL AS "total_quantity",
|
||||
NULL AS "total_spare",
|
||||
NULL AS "total_sets",
|
||||
NULL AS "total_minifigures"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
INNER JOIN "rebrickable_parts"
|
||||
ON "bricktracker_individual_minifigure_parts"."part" = "rebrickable_parts"."part"
|
||||
AND "bricktracker_individual_minifigure_parts"."color" = "rebrickable_parts"."color_id"
|
||||
WHERE "bricktracker_individual_minifigure_parts"."id" IS NOT DISTINCT FROM :id
|
||||
|
||||
{% if order %}
|
||||
ORDER BY {{ order | replace('"combined"', '"bricktracker_individual_minifigure_parts"') | replace('"bricktracker_parts"', '"bricktracker_individual_minifigure_parts"') }}
|
||||
{% endif %}
|
||||
@@ -0,0 +1,33 @@
|
||||
-- Select a specific part from an individual minifigure instance
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigure_parts"."part",
|
||||
"bricktracker_individual_minifigure_parts"."color",
|
||||
"bricktracker_individual_minifigure_parts"."spare",
|
||||
"bricktracker_individual_minifigure_parts"."quantity",
|
||||
"bricktracker_individual_minifigure_parts"."element",
|
||||
"bricktracker_individual_minifigure_parts"."missing",
|
||||
"bricktracker_individual_minifigure_parts"."damaged",
|
||||
"bricktracker_individual_minifigure_parts"."checked",
|
||||
"rebrickable_parts"."color_name",
|
||||
"rebrickable_parts"."color_rgb",
|
||||
"rebrickable_parts"."color_transparent",
|
||||
"rebrickable_parts"."bricklink_color_id",
|
||||
"rebrickable_parts"."bricklink_color_name",
|
||||
"rebrickable_parts"."bricklink_part_num",
|
||||
"rebrickable_parts"."name",
|
||||
"rebrickable_parts"."image",
|
||||
"rebrickable_parts"."image_id",
|
||||
"rebrickable_parts"."url",
|
||||
"rebrickable_parts"."print"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
INNER JOIN "rebrickable_parts"
|
||||
ON "bricktracker_individual_minifigure_parts"."part" = "rebrickable_parts"."part"
|
||||
AND "bricktracker_individual_minifigure_parts"."color" = "rebrickable_parts"."color_id"
|
||||
WHERE "bricktracker_individual_minifigure_parts"."id" IS NOT DISTINCT FROM :id
|
||||
AND "bricktracker_individual_minifigure_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_individual_minifigure_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_individual_minifigure_parts"."spare" IS NOT DISTINCT FROM :spare
|
||||
@@ -0,0 +1,6 @@
|
||||
UPDATE "bricktracker_individual_minifigure_parts"
|
||||
SET "checked" = :checked
|
||||
WHERE "bricktracker_individual_minifigure_parts"."id" IS NOT DISTINCT FROM :id
|
||||
AND "bricktracker_individual_minifigure_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_individual_minifigure_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_individual_minifigure_parts"."spare" IS NOT DISTINCT FROM :spare
|
||||
@@ -0,0 +1,6 @@
|
||||
UPDATE "bricktracker_individual_minifigure_parts"
|
||||
SET "damaged" = :damaged
|
||||
WHERE "bricktracker_individual_minifigure_parts"."id" IS NOT DISTINCT FROM :id
|
||||
AND "bricktracker_individual_minifigure_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_individual_minifigure_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_individual_minifigure_parts"."spare" IS NOT DISTINCT FROM :spare
|
||||
@@ -0,0 +1,6 @@
|
||||
UPDATE "bricktracker_individual_minifigure_parts"
|
||||
SET "missing" = :missing
|
||||
WHERE "bricktracker_individual_minifigure_parts"."id" IS NOT DISTINCT FROM :id
|
||||
AND "bricktracker_individual_minifigure_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_individual_minifigure_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_individual_minifigure_parts"."spare" IS NOT DISTINCT FROM :spare
|
||||
@@ -0,0 +1,35 @@
|
||||
-- Get a specific individual minifigure instance by ID
|
||||
SELECT
|
||||
"bricktracker_individual_minifigures"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigures"."quantity",
|
||||
"bricktracker_individual_minifigures"."description",
|
||||
"bricktracker_individual_minifigures"."storage",
|
||||
"bricktracker_individual_minifigures"."purchase_location",
|
||||
"rebrickable_minifigures"."number",
|
||||
"rebrickable_minifigures"."name",
|
||||
"rebrickable_minifigures"."image",
|
||||
"rebrickable_minifigures"."number_of_parts",
|
||||
"storage_meta"."name" AS "storage_name",
|
||||
"purchase_meta"."name" AS "purchase_location_name"{{ owners }}{{ statuses }}{{ tags }}
|
||||
FROM "bricktracker_individual_minifigures"
|
||||
|
||||
INNER JOIN "rebrickable_minifigures"
|
||||
ON "bricktracker_individual_minifigures"."figure" = "rebrickable_minifigures"."figure"
|
||||
|
||||
LEFT JOIN "bricktracker_metadata_storages" AS "storage_meta"
|
||||
ON "bricktracker_individual_minifigures"."storage" = "storage_meta"."id"
|
||||
|
||||
LEFT JOIN "bricktracker_metadata_purchase_locations" AS "purchase_meta"
|
||||
ON "bricktracker_individual_minifigures"."purchase_location" = "purchase_meta"."id"
|
||||
|
||||
LEFT JOIN "bricktracker_individual_minifigure_owners"
|
||||
ON "bricktracker_individual_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_individual_minifigure_owners"."id"
|
||||
|
||||
LEFT JOIN "bricktracker_individual_minifigure_statuses"
|
||||
ON "bricktracker_individual_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_individual_minifigure_statuses"."id"
|
||||
|
||||
LEFT JOIN "bricktracker_individual_minifigure_tags"
|
||||
ON "bricktracker_individual_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_individual_minifigure_tags"."id"
|
||||
|
||||
WHERE "bricktracker_individual_minifigures"."id" = :id
|
||||
@@ -0,0 +1,52 @@
|
||||
-- Get all individual minifigure instances for a specific figure
|
||||
SELECT
|
||||
"bricktracker_individual_minifigures"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigures"."quantity",
|
||||
"bricktracker_individual_minifigures"."description",
|
||||
"bricktracker_individual_minifigures"."storage",
|
||||
"bricktracker_individual_minifigures"."purchase_location",
|
||||
"rebrickable_minifigures"."number",
|
||||
"rebrickable_minifigures"."name",
|
||||
"rebrickable_minifigures"."image",
|
||||
"rebrickable_minifigures"."number_of_parts",
|
||||
"storage_meta"."name" AS "storage_name",
|
||||
"purchase_meta"."name" AS "purchase_location_name",
|
||||
{{ owners }},
|
||||
{{ statuses }},
|
||||
{{ tags }},
|
||||
IFNULL("problem_join"."total_missing", 0) AS "total_missing",
|
||||
IFNULL("problem_join"."total_damaged", 0) AS "total_damaged"
|
||||
FROM "bricktracker_individual_minifigures"
|
||||
|
||||
INNER JOIN "rebrickable_minifigures"
|
||||
ON "bricktracker_individual_minifigures"."figure" = "rebrickable_minifigures"."figure"
|
||||
|
||||
LEFT JOIN "bricktracker_metadata_storages" AS "storage_meta"
|
||||
ON "bricktracker_individual_minifigures"."storage" = "storage_meta"."id"
|
||||
|
||||
LEFT JOIN "bricktracker_metadata_purchase_locations" AS "purchase_meta"
|
||||
ON "bricktracker_individual_minifigures"."purchase_location" = "purchase_meta"."id"
|
||||
|
||||
LEFT JOIN "bricktracker_individual_minifigure_owners"
|
||||
ON "bricktracker_individual_minifigures"."id" = "bricktracker_individual_minifigure_owners"."id"
|
||||
|
||||
LEFT JOIN "bricktracker_individual_minifigure_statuses"
|
||||
ON "bricktracker_individual_minifigures"."id" = "bricktracker_individual_minifigure_statuses"."id"
|
||||
|
||||
LEFT JOIN "bricktracker_individual_minifigure_tags"
|
||||
ON "bricktracker_individual_minifigures"."id" = "bricktracker_individual_minifigure_tags"."id"
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
SUM("bricktracker_individual_minifigure_parts"."missing") AS "total_missing",
|
||||
SUM("bricktracker_individual_minifigure_parts"."damaged") AS "total_damaged"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
GROUP BY "bricktracker_individual_minifigure_parts"."id"
|
||||
) "problem_join"
|
||||
ON "bricktracker_individual_minifigures"."id" = "problem_join"."id"
|
||||
|
||||
WHERE "bricktracker_individual_minifigures"."figure" = :figure
|
||||
|
||||
ORDER BY "bricktracker_individual_minifigures"."rowid" DESC
|
||||
@@ -0,0 +1,7 @@
|
||||
UPDATE "bricktracker_individual_minifigures"
|
||||
SET
|
||||
"quantity" = :quantity,
|
||||
"description" = :description,
|
||||
"storage" = :storage,
|
||||
"purchase_location" = :purchase_location
|
||||
WHERE "id" = :id
|
||||
@@ -1,4 +1,4 @@
|
||||
-- description: Performance optimization indexes
|
||||
-- Migration 0019: Performance optimization indexes
|
||||
|
||||
-- High-impact composite index for problem parts aggregation
|
||||
-- Used in set listings, statistics, and problem reports
|
||||
|
||||
@@ -1,58 +1,132 @@
|
||||
-- description: Change set number column from INTEGER to TEXT to support alphanumeric set numbers
|
||||
-- Migration 0020: Add individual minifigures and individual parts tables
|
||||
|
||||
-- Temporarily disable foreign key constraints for this migration
|
||||
-- This is necessary because we're recreating a table that other tables reference
|
||||
-- We verify integrity at the end to ensure safety
|
||||
PRAGMA foreign_keys=OFF;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
-- Create new table with TEXT number column
|
||||
CREATE TABLE "rebrickable_sets_new" (
|
||||
"set" TEXT NOT NULL,
|
||||
"number" TEXT NOT NULL,
|
||||
"version" INTEGER NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"year" INTEGER NOT NULL,
|
||||
"theme_id" INTEGER NOT NULL,
|
||||
"number_of_parts" INTEGER NOT NULL,
|
||||
"image" TEXT,
|
||||
"url" TEXT,
|
||||
"last_modified" TEXT,
|
||||
PRIMARY KEY("set")
|
||||
-- Individual minifigures table - tracks individual minifigures not associated with sets
|
||||
CREATE TABLE IF NOT EXISTS "bricktracker_individual_minifigures" (
|
||||
"id" TEXT NOT NULL,
|
||||
"figure" TEXT NOT NULL,
|
||||
"quantity" INTEGER NOT NULL DEFAULT 1,
|
||||
"description" TEXT,
|
||||
"storage" TEXT, -- Storage bin location
|
||||
"purchase_date" REAL, -- Purchase date
|
||||
"purchase_location" TEXT, -- Purchase location
|
||||
"purchase_price" REAL, -- Purchase price
|
||||
PRIMARY KEY("id"),
|
||||
FOREIGN KEY("figure") REFERENCES "rebrickable_minifigures"("figure"),
|
||||
FOREIGN KEY("storage") REFERENCES "bricktracker_metadata_storages"("id"),
|
||||
FOREIGN KEY("purchase_location") REFERENCES "bricktracker_metadata_purchase_locations"("id")
|
||||
);
|
||||
|
||||
-- Copy all data from old table to new table
|
||||
-- Cast INTEGER number to TEXT explicitly
|
||||
INSERT INTO "rebrickable_sets_new"
|
||||
SELECT
|
||||
"set",
|
||||
CAST("number" AS TEXT),
|
||||
"version",
|
||||
"name",
|
||||
"year",
|
||||
"theme_id",
|
||||
"number_of_parts",
|
||||
"image",
|
||||
"url",
|
||||
"last_modified"
|
||||
FROM "rebrickable_sets";
|
||||
-- Individual minifigure statuses
|
||||
CREATE TABLE IF NOT EXISTS "bricktracker_individual_minifigure_statuses" (
|
||||
"id" TEXT NOT NULL,
|
||||
"status_minifigures_collected" BOOLEAN NOT NULL DEFAULT 0,
|
||||
"status_set_checked" BOOLEAN NOT NULL DEFAULT 0,
|
||||
"status_set_collected" BOOLEAN NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY("id"),
|
||||
FOREIGN KEY("id") REFERENCES "bricktracker_individual_minifigures"("id")
|
||||
);
|
||||
|
||||
-- Drop old table
|
||||
DROP TABLE "rebrickable_sets";
|
||||
-- Individual minifigure owners
|
||||
CREATE TABLE IF NOT EXISTS "bricktracker_individual_minifigure_owners" (
|
||||
"id" TEXT NOT NULL,
|
||||
PRIMARY KEY("id"),
|
||||
FOREIGN KEY("id") REFERENCES "bricktracker_individual_minifigures"("id")
|
||||
);
|
||||
|
||||
-- Rename new table to original name
|
||||
ALTER TABLE "rebrickable_sets_new" RENAME TO "rebrickable_sets";
|
||||
-- Individual minifigure tags
|
||||
CREATE TABLE IF NOT EXISTS "bricktracker_individual_minifigure_tags" (
|
||||
"id" TEXT NOT NULL,
|
||||
PRIMARY KEY("id"),
|
||||
FOREIGN KEY("id") REFERENCES "bricktracker_individual_minifigures"("id")
|
||||
);
|
||||
|
||||
-- Recreate the index
|
||||
CREATE INDEX IF NOT EXISTS idx_rebrickable_sets_number_version
|
||||
ON rebrickable_sets(number, version);
|
||||
-- Parts table for individual minifigures - tracks constituent parts
|
||||
CREATE TABLE IF NOT EXISTS "bricktracker_individual_minifigure_parts" (
|
||||
"id" TEXT NOT NULL,
|
||||
"part" TEXT NOT NULL,
|
||||
"color" INTEGER NOT NULL,
|
||||
"spare" BOOLEAN NOT NULL,
|
||||
"quantity" INTEGER NOT NULL,
|
||||
"element" INTEGER,
|
||||
"rebrickable_inventory" INTEGER NOT NULL,
|
||||
"missing" INTEGER NOT NULL DEFAULT 0,
|
||||
"damaged" INTEGER NOT NULL DEFAULT 0,
|
||||
"checked" BOOLEAN DEFAULT 0,
|
||||
PRIMARY KEY("id", "part", "color", "spare"),
|
||||
FOREIGN KEY("id") REFERENCES "bricktracker_individual_minifigures"("id"),
|
||||
FOREIGN KEY("part", "color") REFERENCES "rebrickable_parts"("part", "color_id")
|
||||
);
|
||||
|
||||
-- Verify foreign key integrity before committing
|
||||
-- This ensures we haven't broken any references
|
||||
PRAGMA foreign_key_check;
|
||||
-- Individual parts table - tracks individual parts not associated with sets
|
||||
CREATE TABLE IF NOT EXISTS "bricktracker_individual_parts" (
|
||||
"id" TEXT NOT NULL,
|
||||
"part" TEXT NOT NULL,
|
||||
"color" INTEGER NOT NULL,
|
||||
"quantity" INTEGER NOT NULL DEFAULT 1,
|
||||
"description" TEXT,
|
||||
"storage" TEXT, -- Storage bin location
|
||||
"purchase_date" REAL, -- Purchase date
|
||||
"purchase_location" TEXT, -- Purchase location
|
||||
"purchase_price" REAL, -- Purchase price
|
||||
PRIMARY KEY("id"),
|
||||
FOREIGN KEY("part", "color") REFERENCES "rebrickable_parts"("part", "color_id"),
|
||||
FOREIGN KEY("storage") REFERENCES "bricktracker_metadata_storages"("id"),
|
||||
FOREIGN KEY("purchase_location") REFERENCES "bricktracker_metadata_purchase_locations"("id")
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
-- Individual part owners
|
||||
CREATE TABLE IF NOT EXISTS "bricktracker_individual_part_owners" (
|
||||
"id" TEXT NOT NULL,
|
||||
PRIMARY KEY("id"),
|
||||
FOREIGN KEY("id") REFERENCES "bricktracker_individual_parts"("id")
|
||||
);
|
||||
|
||||
-- Re-enable foreign key constraints
|
||||
PRAGMA foreign_keys=ON;
|
||||
-- Individual part tags
|
||||
CREATE TABLE IF NOT EXISTS "bricktracker_individual_part_tags" (
|
||||
"id" TEXT NOT NULL,
|
||||
PRIMARY KEY("id"),
|
||||
FOREIGN KEY("id") REFERENCES "bricktracker_individual_parts"("id")
|
||||
);
|
||||
|
||||
-- Individual part statuses
|
||||
CREATE TABLE IF NOT EXISTS "bricktracker_individual_part_statuses" (
|
||||
"id" TEXT NOT NULL,
|
||||
"status_minifigures_collected" BOOLEAN NOT NULL DEFAULT 0,
|
||||
"status_set_checked" BOOLEAN NOT NULL DEFAULT 0,
|
||||
"status_set_collected" BOOLEAN NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY("id"),
|
||||
FOREIGN KEY("id") REFERENCES "bricktracker_individual_parts"("id")
|
||||
);
|
||||
|
||||
-- Indexes for individual minifigures
|
||||
CREATE INDEX IF NOT EXISTS idx_bricktracker_individual_minifigures_figure
|
||||
ON bricktracker_individual_minifigures(figure);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bricktracker_individual_minifigures_storage
|
||||
ON bricktracker_individual_minifigures(storage);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bricktracker_individual_minifigures_purchase_location
|
||||
ON bricktracker_individual_minifigures(purchase_location);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bricktracker_individual_minifigures_purchase_date
|
||||
ON bricktracker_individual_minifigures(purchase_date);
|
||||
|
||||
-- Indexes for individual minifigure parts
|
||||
CREATE INDEX IF NOT EXISTS idx_bricktracker_individual_minifigure_parts_id_missing_damaged
|
||||
ON bricktracker_individual_minifigure_parts(id, missing, damaged);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bricktracker_individual_minifigure_parts_part_color
|
||||
ON bricktracker_individual_minifigure_parts(part, color);
|
||||
|
||||
-- Indexes for individual parts
|
||||
CREATE INDEX IF NOT EXISTS idx_bricktracker_individual_parts_part_color
|
||||
ON bricktracker_individual_parts(part, color);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bricktracker_individual_parts_storage
|
||||
ON bricktracker_individual_parts(storage);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bricktracker_individual_parts_purchase_location
|
||||
ON bricktracker_individual_parts(purchase_location);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bricktracker_individual_parts_purchase_date
|
||||
ON bricktracker_individual_parts(purchase_date);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
-- Migration 0021: Add existing owner/tag columns to individual minifigure and individual part metadata tables
|
||||
|
||||
-- Add owner columns to individual minifigure owners table
|
||||
ALTER TABLE "bricktracker_individual_minifigure_owners"
|
||||
ADD COLUMN "owner_32479d0a_cd3c_43c6_aa16_b3f378915b13" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE "bricktracker_individual_minifigure_owners"
|
||||
ADD COLUMN "owner_2f07518d_40e1_4279_b0d0_aa339f195cbf" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
-- Add tag columns to individual minifigure tags table
|
||||
ALTER TABLE "bricktracker_individual_minifigure_tags"
|
||||
ADD COLUMN "tag_b1b5c316_5caf_4b82_a085_ac4c7ab9b8db" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
-- Add owner columns to individual part owners table
|
||||
ALTER TABLE "bricktracker_individual_part_owners"
|
||||
ADD COLUMN "owner_32479d0a_cd3c_43c6_aa16_b3f378915b13" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE "bricktracker_individual_part_owners"
|
||||
ADD COLUMN "owner_2f07518d_40e1_4279_b0d0_aa339f195cbf" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
-- Add tag columns to individual part tags table
|
||||
ALTER TABLE "bricktracker_individual_part_tags"
|
||||
ADD COLUMN "tag_b1b5c316_5caf_4b82_a085_ac4c7ab9b8db" BOOLEAN NOT NULL DEFAULT 0;
|
||||
@@ -1,10 +1,11 @@
|
||||
-- Combined query for both set-based and individual minifigures
|
||||
SELECT
|
||||
"bricktracker_minifigures"."quantity",
|
||||
"rebrickable_minifigures"."figure",
|
||||
"rebrickable_minifigures"."number",
|
||||
"rebrickable_minifigures"."number_of_parts",
|
||||
"rebrickable_minifigures"."name",
|
||||
"rebrickable_minifigures"."image",
|
||||
"combined"."quantity",
|
||||
"combined"."figure",
|
||||
"combined"."number",
|
||||
"combined"."number_of_parts",
|
||||
"combined"."name",
|
||||
"combined"."image",
|
||||
{% block total_missing %}
|
||||
NULL AS "total_missing", -- dummy for order: total_missing
|
||||
{% endblock %}
|
||||
@@ -15,12 +16,44 @@ SELECT
|
||||
NULL AS "total_quantity", -- dummy for order: total_quantity
|
||||
{% endblock %}
|
||||
{% block total_sets %}
|
||||
NULL AS "total_sets" -- dummy for order: total_sets
|
||||
NULL AS "total_sets", -- dummy for order: total_sets
|
||||
{% endblock %}
|
||||
FROM "bricktracker_minifigures"
|
||||
{% block total_individual %}
|
||||
NULL AS "total_individual" -- dummy for order: total_individual
|
||||
{% endblock %}
|
||||
FROM (
|
||||
-- Set-based minifigures
|
||||
SELECT
|
||||
"bricktracker_minifigures"."id",
|
||||
"bricktracker_minifigures"."quantity",
|
||||
"rebrickable_minifigures"."figure",
|
||||
"rebrickable_minifigures"."number",
|
||||
"rebrickable_minifigures"."number_of_parts",
|
||||
"rebrickable_minifigures"."name",
|
||||
"rebrickable_minifigures"."image",
|
||||
"bricktracker_minifigures"."rowid" AS "rowid",
|
||||
'set' AS "source_type"
|
||||
FROM "bricktracker_minifigures"
|
||||
INNER JOIN "rebrickable_minifigures"
|
||||
ON "bricktracker_minifigures"."figure" IS NOT DISTINCT FROM "rebrickable_minifigures"."figure"
|
||||
|
||||
INNER JOIN "rebrickable_minifigures"
|
||||
ON "bricktracker_minifigures"."figure" IS NOT DISTINCT FROM "rebrickable_minifigures"."figure"
|
||||
UNION ALL
|
||||
|
||||
-- Individual minifigures
|
||||
SELECT
|
||||
"bricktracker_individual_minifigures"."id",
|
||||
"bricktracker_individual_minifigures"."quantity",
|
||||
"rebrickable_minifigures"."figure",
|
||||
"rebrickable_minifigures"."number",
|
||||
"rebrickable_minifigures"."number_of_parts",
|
||||
"rebrickable_minifigures"."name",
|
||||
"rebrickable_minifigures"."image",
|
||||
"bricktracker_individual_minifigures"."rowid" AS "rowid",
|
||||
'individual' AS "source_type"
|
||||
FROM "bricktracker_individual_minifigures"
|
||||
INNER JOIN "rebrickable_minifigures"
|
||||
ON "bricktracker_individual_minifigures"."figure" IS NOT DISTINCT FROM "rebrickable_minifigures"."figure"
|
||||
) AS "combined"
|
||||
|
||||
{% block join %}{% endblock %}
|
||||
|
||||
@@ -28,8 +61,6 @@ ON "bricktracker_minifigures"."figure" IS NOT DISTINCT FROM "rebrickable_minifig
|
||||
|
||||
{% block group %}{% endblock %}
|
||||
|
||||
{% block having %}{% endblock %}
|
||||
|
||||
{% if order %}
|
||||
ORDER BY {{ order }}
|
||||
{% endif %}
|
||||
|
||||
@@ -9,24 +9,22 @@ SUM(IFNULL("problem_join"."total_damaged", 0)) AS "total_damaged",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_quantity %}
|
||||
SUM(IFNULL("bricktracker_minifigures"."quantity", 0)) AS "total_quantity",
|
||||
SUM(IFNULL("combined"."quantity", 0)) AS "total_quantity",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_sets %}
|
||||
IFNULL(COUNT("bricktracker_minifigures"."id"), 0) AS "total_sets"
|
||||
SUM(CASE WHEN "combined"."source_type" = 'set' THEN 1 ELSE 0 END) AS "total_sets",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_individual %}
|
||||
SUM(CASE WHEN "combined"."source_type" = 'individual' THEN 1 ELSE 0 END) AS "total_individual"
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
{% if theme_id or year %}
|
||||
-- Join with sets for theme/year filtering
|
||||
INNER JOIN "bricktracker_sets" AS "filter_sets"
|
||||
ON "bricktracker_minifigures"."id" IS NOT DISTINCT FROM "filter_sets"."id"
|
||||
INNER JOIN "rebrickable_sets" AS "filter_rs"
|
||||
ON "filter_sets"."set" IS NOT DISTINCT FROM "filter_rs"."set"
|
||||
{% endif %}
|
||||
|
||||
-- LEFT JOIN + SELECT to avoid messing the total
|
||||
-- Combine parts from both set-based and individual minifigures
|
||||
LEFT JOIN (
|
||||
-- Set-based minifigure parts
|
||||
SELECT
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure",
|
||||
@@ -37,38 +35,33 @@ LEFT JOIN (
|
||||
GROUP BY
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure"
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Individual minifigure parts
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"combined"."figure",
|
||||
SUM("bricktracker_individual_minifigure_parts"."missing") AS "total_missing",
|
||||
SUM("bricktracker_individual_minifigure_parts"."damaged") AS "total_damaged"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures" ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
INNER JOIN "rebrickable_minifigures" AS "combined" ON "bricktracker_individual_minifigures"."figure" = "combined"."figure"
|
||||
GROUP BY
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"combined"."figure"
|
||||
) "problem_join"
|
||||
ON "bricktracker_minifigures"."id" IS NOT DISTINCT FROM "problem_join"."id"
|
||||
AND "rebrickable_minifigures"."figure" IS NOT DISTINCT FROM "problem_join"."figure"
|
||||
ON "combined"."id" IS NOT DISTINCT FROM "problem_join"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "problem_join"."figure"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
WHERE 1=1
|
||||
{% if theme_id and theme_id != 'all' %}
|
||||
AND "filter_rs"."theme_id" = {{ theme_id }}
|
||||
{% endif %}
|
||||
{% if year and year != 'all' %}
|
||||
AND "filter_rs"."year" = {{ year }}
|
||||
{% endif %}
|
||||
{% if search_query %}
|
||||
AND (LOWER("rebrickable_minifigures"."name") LIKE LOWER('%{{ search_query }}%'))
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block having %}
|
||||
{% if problems_filter %}
|
||||
HAVING 1=1
|
||||
{% if problems_filter == 'missing' %}
|
||||
AND SUM(IFNULL("problem_join"."total_missing", 0)) > 0
|
||||
{% elif problems_filter == 'damaged' %}
|
||||
AND SUM(IFNULL("problem_join"."total_damaged", 0)) > 0
|
||||
{% elif problems_filter == 'both' %}
|
||||
AND SUM(IFNULL("problem_join"."total_missing", 0)) > 0 AND SUM(IFNULL("problem_join"."total_damaged", 0)) > 0
|
||||
{% endif %}
|
||||
WHERE (LOWER("combined"."name") LIKE LOWER('%{{ search_query }}%'))
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"rebrickable_minifigures"."figure"
|
||||
"combined"."figure"
|
||||
{% endblock %}
|
||||
|
||||
@@ -10,35 +10,53 @@ SUM(IFNULL("problem_join"."total_damaged", 0)) AS "total_damaged",
|
||||
|
||||
{% block total_quantity %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN IFNULL("bricktracker_minifigures"."quantity", 0) ELSE 0 END) AS "total_quantity",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "set_owners"."owner_{{ owner_id }}" = 1 THEN IFNULL("combined"."quantity", 0)
|
||||
WHEN "combined"."source_type" = 'individual' AND "individual_owners"."owner_{{ owner_id }}" = 1 THEN IFNULL("combined"."quantity", 0)
|
||||
ELSE 0
|
||||
END) AS "total_quantity",
|
||||
{% else %}
|
||||
SUM(IFNULL("bricktracker_minifigures"."quantity", 0)) AS "total_quantity",
|
||||
SUM(IFNULL("combined"."quantity", 0)) AS "total_quantity",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_sets %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
COUNT(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "bricktracker_minifigures"."id" ELSE NULL END) AS "total_sets"
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "set_owners"."owner_{{ owner_id }}" = 1 THEN 1
|
||||
ELSE 0
|
||||
END) AS "total_sets",
|
||||
{% else %}
|
||||
COUNT("bricktracker_minifigures"."id") AS "total_sets"
|
||||
SUM(CASE WHEN "combined"."source_type" = 'set' THEN 1 ELSE 0 END) AS "total_sets",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_individual %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'individual' AND "individual_owners"."owner_{{ owner_id }}" = 1 THEN 1
|
||||
ELSE 0
|
||||
END) AS "total_individual"
|
||||
{% else %}
|
||||
SUM(CASE WHEN "combined"."source_type" = 'individual' THEN 1 ELSE 0 END) AS "total_individual"
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
-- Join with sets to get owner information
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
-- Join with set owners for set-based minifigures
|
||||
LEFT JOIN "bricktracker_sets"
|
||||
ON "combined"."id" = "bricktracker_sets"."id" AND "combined"."source_type" = 'set'
|
||||
|
||||
-- Join with rebrickable sets for theme/year filtering
|
||||
INNER JOIN "rebrickable_sets"
|
||||
ON "bricktracker_sets"."set" IS NOT DISTINCT FROM "rebrickable_sets"."set"
|
||||
LEFT JOIN "bricktracker_set_owners" AS "set_owners"
|
||||
ON "bricktracker_sets"."id" = "set_owners"."id"
|
||||
|
||||
-- Left join with set owners (using dynamic columns)
|
||||
LEFT JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
-- Join with individual minifigure owners for individual minifigures
|
||||
LEFT JOIN "bricktracker_individual_minifigure_owners" AS "individual_owners"
|
||||
ON "combined"."id" = "individual_owners"."id" AND "combined"."source_type" = 'individual'
|
||||
|
||||
-- LEFT JOIN + SELECT to avoid messing the total
|
||||
LEFT JOIN (
|
||||
-- Set-based minifigure parts
|
||||
SELECT
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure",
|
||||
@@ -51,31 +69,47 @@ LEFT JOIN (
|
||||
{% endif %}
|
||||
FROM "bricktracker_parts"
|
||||
INNER JOIN "bricktracker_sets" AS "parts_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "parts_sets"."id"
|
||||
ON "bricktracker_parts"."id" = "parts_sets"."id"
|
||||
LEFT JOIN "bricktracker_set_owners" AS "owner_parts"
|
||||
ON "parts_sets"."id" IS NOT DISTINCT FROM "owner_parts"."id"
|
||||
ON "parts_sets"."id" = "owner_parts"."id"
|
||||
WHERE "bricktracker_parts"."figure" IS NOT NULL
|
||||
GROUP BY
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure"
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Individual minifigure parts
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "owner_individual"."owner_{{ owner_id }}" = 1 THEN "bricktracker_individual_minifigure_parts"."missing" ELSE 0 END) AS "total_missing",
|
||||
SUM(CASE WHEN "owner_individual"."owner_{{ owner_id }}" = 1 THEN "bricktracker_individual_minifigure_parts"."damaged" ELSE 0 END) AS "total_damaged"
|
||||
{% else %}
|
||||
SUM("bricktracker_individual_minifigure_parts"."missing") AS "total_missing",
|
||||
SUM("bricktracker_individual_minifigure_parts"."damaged") AS "total_damaged"
|
||||
{% endif %}
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
LEFT JOIN "bricktracker_individual_minifigure_owners" AS "owner_individual"
|
||||
ON "bricktracker_individual_minifigures"."id" = "owner_individual"."id"
|
||||
GROUP BY
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"bricktracker_individual_minifigures"."figure"
|
||||
) "problem_join"
|
||||
ON "bricktracker_minifigures"."id" IS NOT DISTINCT FROM "problem_join"."id"
|
||||
AND "rebrickable_minifigures"."figure" IS NOT DISTINCT FROM "problem_join"."figure"
|
||||
ON "combined"."id" = "problem_join"."id"
|
||||
AND "combined"."figure" = "problem_join"."figure"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
{% set conditions = [] %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
{% set _ = conditions.append('"bricktracker_set_owners"."owner_' ~ owner_id ~ '" = 1') %}
|
||||
{% endif %}
|
||||
{% if theme_id and theme_id != 'all' %}
|
||||
{% set _ = conditions.append('"rebrickable_sets"."theme_id" = ' ~ theme_id) %}
|
||||
{% endif %}
|
||||
{% if year and year != 'all' %}
|
||||
{% set _ = conditions.append('"rebrickable_sets"."year" = ' ~ year) %}
|
||||
{% set _ = conditions.append('(("combined"."source_type" = \'set\' AND "set_owners"."owner_' ~ owner_id ~ '" = 1) OR ("combined"."source_type" = \'individual\' AND "individual_owners"."owner_' ~ owner_id ~ '" = 1))') %}
|
||||
{% endif %}
|
||||
{% if search_query %}
|
||||
{% set _ = conditions.append('(LOWER("rebrickable_minifigures"."name") LIKE LOWER(\'%' ~ search_query ~ '%\'))') %}
|
||||
{% set _ = conditions.append('(LOWER("combined"."name") LIKE LOWER(\'%' ~ search_query ~ '%\'))') %}
|
||||
{% endif %}
|
||||
{% if conditions %}
|
||||
WHERE {{ conditions | join(' AND ') }}
|
||||
@@ -84,18 +118,5 @@ WHERE {{ conditions | join(' AND ') }}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"rebrickable_minifigures"."figure"
|
||||
{% endblock %}
|
||||
|
||||
{% block having %}
|
||||
{% if problems_filter %}
|
||||
HAVING 1=1
|
||||
{% if problems_filter == 'missing' %}
|
||||
AND SUM(IFNULL("problem_join"."total_missing", 0)) > 0
|
||||
{% elif problems_filter == 'damaged' %}
|
||||
AND SUM(IFNULL("problem_join"."total_damaged", 0)) > 0
|
||||
{% elif problems_filter == 'both' %}
|
||||
AND SUM(IFNULL("problem_join"."total_missing", 0)) > 0 AND SUM(IFNULL("problem_join"."total_damaged", 0)) > 0
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
"combined"."figure"
|
||||
{% endblock %}
|
||||
@@ -1,28 +1,59 @@
|
||||
{% extends 'minifigure/base/base.sql' %}
|
||||
|
||||
{% block total_damaged %}
|
||||
SUM("bricktracker_parts"."damaged") AS "total_damaged",
|
||||
SUM("parts_combined"."damaged") AS "total_damaged",
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
LEFT JOIN "bricktracker_parts"
|
||||
ON "bricktracker_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_parts"."id"
|
||||
AND "rebrickable_minifigures"."figure" IS NOT DISTINCT FROM "bricktracker_parts"."figure"
|
||||
-- Join with parts from both set-based and individual minifigures
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure",
|
||||
"bricktracker_parts"."damaged"
|
||||
FROM "bricktracker_parts"
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigure_parts"."damaged"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
) AS "parts_combined"
|
||||
ON "combined"."id" IS NOT DISTINCT FROM "parts_combined"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "parts_combined"."figure"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
WHERE "rebrickable_minifigures"."figure" IN (
|
||||
SELECT "bricktracker_parts"."figure"
|
||||
FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_parts"."figure" IS NOT NULL
|
||||
AND "bricktracker_parts"."damaged" > 0
|
||||
GROUP BY "bricktracker_parts"."figure"
|
||||
WHERE "combined"."figure" IN (
|
||||
-- Find figures with damaged parts from both sources
|
||||
SELECT "figure"
|
||||
FROM (
|
||||
SELECT "bricktracker_parts"."figure"
|
||||
FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_parts"."figure" IS NOT NULL
|
||||
AND "bricktracker_parts"."damaged" > 0
|
||||
|
||||
UNION
|
||||
|
||||
SELECT "bricktracker_individual_minifigures"."figure"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
WHERE "bricktracker_individual_minifigure_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_individual_minifigure_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_individual_minifigure_parts"."damaged" > 0
|
||||
) AS "damaged_figures"
|
||||
GROUP BY "figure"
|
||||
)
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"rebrickable_minifigures"."figure"
|
||||
"combined"."figure"
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% extends 'minifigure/base/base.sql' %}
|
||||
|
||||
{% block where %}
|
||||
WHERE "bricktracker_minifigures"."id" IS NOT DISTINCT FROM :id
|
||||
WHERE "combined"."id" IS NOT DISTINCT FROM :id AND "combined"."source_type" = 'set'
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,21 +1,40 @@
|
||||
{% extends 'minifigure/base/base.sql' %}
|
||||
|
||||
{% block total_missing %}
|
||||
SUM("bricktracker_parts"."missing") AS "total_missing",
|
||||
SUM("parts_combined"."missing") AS "total_missing",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_damaged %}
|
||||
SUM("bricktracker_parts"."damaged") AS "total_damaged",
|
||||
SUM("parts_combined"."damaged") AS "total_damaged",
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
LEFT JOIN "bricktracker_parts"
|
||||
ON "bricktracker_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_parts"."id"
|
||||
AND "rebrickable_minifigures"."figure" IS NOT DISTINCT FROM "bricktracker_parts"."figure"
|
||||
-- Join with parts from both set-based and individual minifigures
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure",
|
||||
"bricktracker_parts"."missing",
|
||||
"bricktracker_parts"."damaged"
|
||||
FROM "bricktracker_parts"
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigure_parts"."missing",
|
||||
"bricktracker_individual_minifigure_parts"."damaged"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
) AS "parts_combined"
|
||||
ON "combined"."id" IS NOT DISTINCT FROM "parts_combined"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "parts_combined"."figure"
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"rebrickable_minifigures"."figure",
|
||||
"bricktracker_minifigures"."id"
|
||||
"combined"."figure",
|
||||
"combined"."id"
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,28 +1,59 @@
|
||||
{% extends 'minifigure/base/base.sql' %}
|
||||
|
||||
{% block total_missing %}
|
||||
SUM("bricktracker_parts"."missing") AS "total_missing",
|
||||
SUM("parts_combined"."missing") AS "total_missing",
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
LEFT JOIN "bricktracker_parts"
|
||||
ON "bricktracker_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_parts"."id"
|
||||
AND "rebrickable_minifigures"."figure" IS NOT DISTINCT FROM "bricktracker_parts"."figure"
|
||||
-- Join with parts from both set-based and individual minifigures
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure",
|
||||
"bricktracker_parts"."missing"
|
||||
FROM "bricktracker_parts"
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigure_parts"."missing"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
) AS "parts_combined"
|
||||
ON "combined"."id" IS NOT DISTINCT FROM "parts_combined"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "parts_combined"."figure"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
WHERE "rebrickable_minifigures"."figure" IN (
|
||||
SELECT "bricktracker_parts"."figure"
|
||||
FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_parts"."figure" IS NOT NULL
|
||||
AND "bricktracker_parts"."missing" > 0
|
||||
GROUP BY "bricktracker_parts"."figure"
|
||||
WHERE "combined"."figure" IN (
|
||||
-- Find figures with missing parts from both sources
|
||||
SELECT "figure"
|
||||
FROM (
|
||||
SELECT "bricktracker_parts"."figure"
|
||||
FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_parts"."figure" IS NOT NULL
|
||||
AND "bricktracker_parts"."missing" > 0
|
||||
|
||||
UNION
|
||||
|
||||
SELECT "bricktracker_individual_minifigures"."figure"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
WHERE "bricktracker_individual_minifigure_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_individual_minifigure_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_individual_minifigure_parts"."missing" > 0
|
||||
) AS "missing_figures"
|
||||
GROUP BY "figure"
|
||||
)
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"rebrickable_minifigures"."figure"
|
||||
"combined"."figure"
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,21 +1,34 @@
|
||||
{% extends 'minifigure/base/base.sql' %}
|
||||
|
||||
{% block total_quantity %}
|
||||
SUM("bricktracker_minifigures"."quantity") AS "total_quantity",
|
||||
SUM("combined"."quantity") AS "total_quantity",
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
WHERE "rebrickable_minifigures"."figure" IN (
|
||||
SELECT "bricktracker_parts"."figure"
|
||||
FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_parts"."figure" IS NOT NULL
|
||||
GROUP BY "bricktracker_parts"."figure"
|
||||
WHERE "combined"."figure" IN (
|
||||
-- Find figures from both set-based and individual minifigure parts
|
||||
SELECT "figure"
|
||||
FROM (
|
||||
SELECT "bricktracker_parts"."figure"
|
||||
FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_parts"."figure" IS NOT NULL
|
||||
|
||||
UNION
|
||||
|
||||
SELECT "bricktracker_individual_minifigures"."figure"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
WHERE "bricktracker_individual_minifigure_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_individual_minifigure_parts"."color" IS NOT DISTINCT FROM :color
|
||||
) AS "parts_figures"
|
||||
GROUP BY "figure"
|
||||
)
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"rebrickable_minifigures"."figure"
|
||||
"combined"."figure"
|
||||
{% endblock %}
|
||||
|
||||
@@ -9,16 +9,22 @@ IFNULL("problem_join"."total_damaged", 0) AS "total_damaged",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_quantity %}
|
||||
SUM(IFNULL("bricktracker_minifigures"."quantity", 0)) AS "total_quantity",
|
||||
SUM(IFNULL("combined"."quantity", 0)) AS "total_quantity",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_sets %}
|
||||
IFNULL(COUNT(DISTINCT "bricktracker_minifigures"."id"), 0) AS "total_sets"
|
||||
IFNULL(COUNT(DISTINCT "combined"."id"), 0) AS "total_sets",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_individual %}
|
||||
IFNULL(COUNT(DISTINCT "combined"."id"), 0) AS "total_individual"
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
-- LEFT JOIN + SELECT to avoid messing the total
|
||||
-- Combine parts from both set-based and individual minifigures
|
||||
LEFT JOIN (
|
||||
-- Set-based minifigure parts
|
||||
SELECT
|
||||
"bricktracker_parts"."figure",
|
||||
SUM("bricktracker_parts"."missing") AS "total_missing",
|
||||
@@ -26,15 +32,27 @@ LEFT JOIN (
|
||||
FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."figure" IS NOT DISTINCT FROM :figure
|
||||
GROUP BY "bricktracker_parts"."figure"
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Individual minifigure parts
|
||||
SELECT
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
SUM("bricktracker_individual_minifigure_parts"."missing") AS "total_missing",
|
||||
SUM("bricktracker_individual_minifigure_parts"."damaged") AS "total_damaged"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures" ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
WHERE "bricktracker_individual_minifigures"."figure" IS NOT DISTINCT FROM :figure
|
||||
GROUP BY "bricktracker_individual_minifigures"."figure"
|
||||
) "problem_join"
|
||||
ON "rebrickable_minifigures"."figure" IS NOT DISTINCT FROM "problem_join"."figure"
|
||||
ON "combined"."figure" IS NOT DISTINCT FROM "problem_join"."figure"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
WHERE "rebrickable_minifigures"."figure" IS NOT DISTINCT FROM :figure
|
||||
WHERE "combined"."figure" IS NOT DISTINCT FROM :figure
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"rebrickable_minifigures"."figure"
|
||||
"combined"."figure"
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{% extends 'minifigure/base/base.sql' %}
|
||||
|
||||
{% block where %}
|
||||
WHERE "bricktracker_minifigures"."id" IS NOT DISTINCT FROM :id
|
||||
AND "rebrickable_minifigures"."figure" IS NOT DISTINCT FROM :figure
|
||||
WHERE "combined"."id" IS NOT DISTINCT FROM :id
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM :figure
|
||||
AND "combined"."source_type" = 'set'
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
-- Get distinct themes from minifigures' sets
|
||||
SELECT DISTINCT
|
||||
"rebrickable_sets"."theme_id",
|
||||
COUNT(DISTINCT "bricktracker_minifigures"."figure") as "minifigure_count"
|
||||
FROM "bricktracker_minifigures"
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
INNER JOIN "rebrickable_sets"
|
||||
ON "bricktracker_sets"."set" IS NOT DISTINCT FROM "rebrickable_sets"."set"
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
INNER JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
WHERE "bricktracker_set_owners"."owner_{{ owner_id }}" = 1
|
||||
{% endif %}
|
||||
GROUP BY "rebrickable_sets"."theme_id"
|
||||
ORDER BY "rebrickable_sets"."theme_id" ASC
|
||||
@@ -1,16 +0,0 @@
|
||||
-- Get distinct years from minifigures' sets
|
||||
SELECT DISTINCT
|
||||
"rebrickable_sets"."year",
|
||||
COUNT(DISTINCT "bricktracker_minifigures"."figure") as "minifigure_count"
|
||||
FROM "bricktracker_minifigures"
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
INNER JOIN "rebrickable_sets"
|
||||
ON "bricktracker_sets"."set" IS NOT DISTINCT FROM "rebrickable_sets"."set"
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
INNER JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
WHERE "bricktracker_set_owners"."owner_{{ owner_id }}" = 1
|
||||
{% endif %}
|
||||
GROUP BY "rebrickable_sets"."year"
|
||||
ORDER BY "rebrickable_sets"."year" DESC
|
||||
@@ -1,17 +1,14 @@
|
||||
SELECT
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure",
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color",
|
||||
"bricktracker_parts"."spare",
|
||||
"bricktracker_parts"."quantity",
|
||||
"bricktracker_parts"."element",
|
||||
--"bricktracker_parts"."rebrickable_inventory",
|
||||
"bricktracker_parts"."missing",
|
||||
"bricktracker_parts"."damaged",
|
||||
"bricktracker_parts"."checked",
|
||||
--"rebrickable_parts"."part",
|
||||
--"rebrickable_parts"."color_id",
|
||||
"combined"."id",
|
||||
"combined"."figure",
|
||||
"combined"."part",
|
||||
"combined"."color",
|
||||
"combined"."spare",
|
||||
"combined"."quantity",
|
||||
"combined"."element",
|
||||
"combined"."missing",
|
||||
"combined"."damaged",
|
||||
"combined"."checked",
|
||||
"rebrickable_parts"."color_name",
|
||||
"rebrickable_parts"."color_rgb",
|
||||
"rebrickable_parts"."color_transparent",
|
||||
@@ -19,7 +16,6 @@ SELECT
|
||||
"rebrickable_parts"."bricklink_color_name",
|
||||
"rebrickable_parts"."bricklink_part_num",
|
||||
"rebrickable_parts"."name",
|
||||
--"rebrickable_parts"."category",
|
||||
"rebrickable_parts"."image",
|
||||
"rebrickable_parts"."image_id",
|
||||
"rebrickable_parts"."url",
|
||||
@@ -42,11 +38,45 @@ SELECT
|
||||
{% block total_minifigures %}
|
||||
NULL AS "total_minifigures" -- dummy for order: total_minifigures
|
||||
{% endblock %}
|
||||
FROM "bricktracker_parts"
|
||||
FROM (
|
||||
-- Parts from set-based minifigures
|
||||
SELECT
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure",
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color",
|
||||
"bricktracker_parts"."spare",
|
||||
"bricktracker_parts"."quantity",
|
||||
"bricktracker_parts"."element",
|
||||
"bricktracker_parts"."missing",
|
||||
"bricktracker_parts"."damaged",
|
||||
"bricktracker_parts"."checked",
|
||||
'set' AS "source_type"
|
||||
FROM "bricktracker_parts"
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Parts from individual minifigures
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigure_parts"."part",
|
||||
"bricktracker_individual_minifigure_parts"."color",
|
||||
"bricktracker_individual_minifigure_parts"."spare",
|
||||
"bricktracker_individual_minifigure_parts"."quantity",
|
||||
"bricktracker_individual_minifigure_parts"."element",
|
||||
"bricktracker_individual_minifigure_parts"."missing",
|
||||
"bricktracker_individual_minifigure_parts"."damaged",
|
||||
"bricktracker_individual_minifigure_parts"."checked",
|
||||
'individual' AS "source_type"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
) AS "combined"
|
||||
|
||||
INNER JOIN "rebrickable_parts"
|
||||
ON "bricktracker_parts"."part" IS NOT DISTINCT FROM "rebrickable_parts"."part"
|
||||
AND "bricktracker_parts"."color" IS NOT DISTINCT FROM "rebrickable_parts"."color_id"
|
||||
ON "combined"."part" IS NOT DISTINCT FROM "rebrickable_parts"."part"
|
||||
AND "combined"."color" IS NOT DISTINCT FROM "rebrickable_parts"."color_id"
|
||||
|
||||
{% block join %}{% endblock %}
|
||||
|
||||
|
||||
@@ -1,55 +1,57 @@
|
||||
{% extends 'part/base/base.sql' %}
|
||||
|
||||
{% block total_missing %}
|
||||
SUM("bricktracker_parts"."missing") AS "total_missing",
|
||||
SUM("combined"."missing") AS "total_missing",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_damaged %}
|
||||
SUM("bricktracker_parts"."damaged") AS "total_damaged",
|
||||
SUM("combined"."damaged") AS "total_damaged",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_quantity %}
|
||||
SUM("bricktracker_parts"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)) AS "total_quantity",
|
||||
SUM("combined"."quantity" * IFNULL("minifigure_quantities"."quantity", 1)) AS "total_quantity",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_sets %}
|
||||
IFNULL(COUNT(DISTINCT "bricktracker_parts"."id"), 0) AS "total_sets",
|
||||
IFNULL(COUNT(DISTINCT "combined"."id"), 0) AS "total_sets",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_minifigures %}
|
||||
SUM(IFNULL("bricktracker_minifigures"."quantity", 0)) AS "total_minifigures"
|
||||
SUM(IFNULL("minifigure_quantities"."quantity", 0)) AS "total_minifigures"
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
LEFT JOIN "bricktracker_minifigures"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_minifigures"."id"
|
||||
AND "bricktracker_parts"."figure" IS NOT DISTINCT FROM "bricktracker_minifigures"."figure"
|
||||
-- Join to get minifigure quantities from both set-based and individual minifigures
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
"bricktracker_minifigures"."id",
|
||||
"bricktracker_minifigures"."figure",
|
||||
"bricktracker_minifigures"."quantity"
|
||||
FROM "bricktracker_minifigures"
|
||||
|
||||
{% if theme_id or year %}
|
||||
INNER JOIN "bricktracker_sets" AS "filter_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "filter_sets"."id"
|
||||
INNER JOIN "rebrickable_sets" AS "filter_rs"
|
||||
ON "filter_sets"."set" IS NOT DISTINCT FROM "filter_rs"."set"
|
||||
{% endif %}
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
"bricktracker_individual_minifigures"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigures"."quantity"
|
||||
FROM "bricktracker_individual_minifigures"
|
||||
) AS "minifigure_quantities"
|
||||
ON "combined"."id" IS NOT DISTINCT FROM "minifigure_quantities"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "minifigure_quantities"."figure"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
{% set conditions = [] %}
|
||||
{% if color_id and color_id != 'all' %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."color" = ' ~ color_id) %}
|
||||
{% endif %}
|
||||
{% if theme_id and theme_id != 'all' %}
|
||||
{% set _ = conditions.append('"filter_rs"."theme_id" = ' ~ theme_id) %}
|
||||
{% endif %}
|
||||
{% if year and year != 'all' %}
|
||||
{% set _ = conditions.append('"filter_rs"."year" = ' ~ year) %}
|
||||
{% set _ = conditions.append('"combined"."color" = ' ~ color_id) %}
|
||||
{% endif %}
|
||||
{% if search_query %}
|
||||
{% set search_condition = '(LOWER("rebrickable_parts"."name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("rebrickable_parts"."color_name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("bricktracker_parts"."part") LIKE LOWER(\'%' ~ search_query ~ '%\'))' %}
|
||||
{% set search_condition = '(LOWER("rebrickable_parts"."name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("rebrickable_parts"."color_name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("combined"."part") LIKE LOWER(\'%' ~ search_query ~ '%\'))' %}
|
||||
{% set _ = conditions.append(search_condition) %}
|
||||
{% endif %}
|
||||
{% if skip_spare_parts %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."spare" = 0') %}
|
||||
{% set _ = conditions.append('"combined"."spare" = 0') %}
|
||||
{% endif %}
|
||||
{% if conditions %}
|
||||
WHERE {{ conditions | join(' AND ') }}
|
||||
@@ -58,7 +60,7 @@ WHERE {{ conditions | join(' AND ') }}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color",
|
||||
"bricktracker_parts"."spare"
|
||||
"combined"."part",
|
||||
"combined"."color",
|
||||
"combined"."spare"
|
||||
{% endblock %}
|
||||
|
||||
@@ -2,73 +2,113 @@
|
||||
|
||||
{% block total_missing %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "bricktracker_parts"."missing" ELSE 0 END) AS "total_missing",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."missing"
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."missing"
|
||||
ELSE 0
|
||||
END) AS "total_missing",
|
||||
{% else %}
|
||||
SUM("bricktracker_parts"."missing") AS "total_missing",
|
||||
SUM("combined"."missing") AS "total_missing",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_damaged %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "bricktracker_parts"."damaged" ELSE 0 END) AS "total_damaged",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."damaged"
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."damaged"
|
||||
ELSE 0
|
||||
END) AS "total_damaged",
|
||||
{% else %}
|
||||
SUM("bricktracker_parts"."damaged") AS "total_damaged",
|
||||
SUM("combined"."damaged") AS "total_damaged",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_quantity %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "bricktracker_parts"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1) ELSE 0 END) AS "total_quantity",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."quantity"
|
||||
ELSE 0
|
||||
END) AS "total_quantity",
|
||||
{% else %}
|
||||
SUM("bricktracker_parts"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)) AS "total_quantity",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' THEN "combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)
|
||||
ELSE "combined"."quantity"
|
||||
END) AS "total_quantity",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_sets %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
COUNT(DISTINCT CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "bricktracker_parts"."id" ELSE NULL END) AS "total_sets",
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."id"
|
||||
ELSE NULL
|
||||
END) AS "total_sets",
|
||||
{% else %}
|
||||
COUNT(DISTINCT "bricktracker_parts"."id") AS "total_sets",
|
||||
COUNT(DISTINCT CASE WHEN "combined"."source_type" = 'set' THEN "combined"."id" ELSE NULL END) AS "total_sets",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_minifigures %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN IFNULL("bricktracker_minifigures"."quantity", 0) ELSE 0 END) AS "total_minifigures"
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN IFNULL("bricktracker_minifigures"."quantity", 0)
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN 1
|
||||
ELSE 0
|
||||
END) AS "total_minifigures"
|
||||
{% else %}
|
||||
SUM(IFNULL("bricktracker_minifigures"."quantity", 0)) AS "total_minifigures"
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' THEN IFNULL("bricktracker_minifigures"."quantity", 0)
|
||||
WHEN "combined"."source_type" = 'individual' THEN 1
|
||||
ELSE 0
|
||||
END) AS "total_minifigures"
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
-- Join with sets to get owner information
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
-- Left join with sets (for set-based parts)
|
||||
LEFT JOIN "bricktracker_sets"
|
||||
ON "combined"."source_type" = 'set'
|
||||
AND "combined"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
|
||||
-- Left join with set owners (using dynamic columns)
|
||||
LEFT JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
ON "combined"."source_type" = 'set'
|
||||
AND "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
|
||||
-- Left join with minifigures
|
||||
-- Left join with set-based minifigures
|
||||
LEFT JOIN "bricktracker_minifigures"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_minifigures"."id"
|
||||
AND "bricktracker_parts"."figure" IS NOT DISTINCT FROM "bricktracker_minifigures"."figure"
|
||||
ON "combined"."source_type" = 'set'
|
||||
AND "combined"."id" IS NOT DISTINCT FROM "bricktracker_minifigures"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "bricktracker_minifigures"."figure"
|
||||
|
||||
-- Left join with individual minifigures (for individual parts)
|
||||
LEFT JOIN "bricktracker_individual_minifigures"
|
||||
ON "combined"."source_type" = 'individual'
|
||||
AND "combined"."id" IS NOT DISTINCT FROM "bricktracker_individual_minifigures"."id"
|
||||
|
||||
-- Left join with individual minifigure owners (using dynamic columns)
|
||||
LEFT JOIN "bricktracker_individual_minifigure_owners"
|
||||
ON "combined"."source_type" = 'individual'
|
||||
AND "bricktracker_individual_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_individual_minifigure_owners"."id"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
{% set conditions = [] %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
{% set _ = conditions.append('"bricktracker_set_owners"."owner_' ~ owner_id ~ '" = 1') %}
|
||||
{% set owner_condition = '(("combined"."source_type" = \'set\' AND "bricktracker_set_owners"."owner_' ~ owner_id ~ '" = 1) OR ("combined"."source_type" = \'individual\' AND "bricktracker_individual_minifigure_owners"."owner_' ~ owner_id ~ '" = 1))' %}
|
||||
{% set _ = conditions.append(owner_condition) %}
|
||||
{% endif %}
|
||||
{% if color_id and color_id != 'all' %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."color" = ' ~ color_id) %}
|
||||
{% set _ = conditions.append('"combined"."color" = ' ~ color_id) %}
|
||||
{% endif %}
|
||||
{% if search_query %}
|
||||
{% set search_condition = '(LOWER("rebrickable_parts"."name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("rebrickable_parts"."color_name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("bricktracker_parts"."part") LIKE LOWER(\'%' ~ search_query ~ '%\'))' %}
|
||||
{% set search_condition = '(LOWER("rebrickable_parts"."name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("rebrickable_parts"."color_name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("combined"."part") LIKE LOWER(\'%' ~ search_query ~ '%\'))' %}
|
||||
{% set _ = conditions.append(search_condition) %}
|
||||
{% endif %}
|
||||
{% if skip_spare_parts %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."spare" = 0') %}
|
||||
{% set _ = conditions.append('"combined"."spare" = 0') %}
|
||||
{% endif %}
|
||||
{% if conditions %}
|
||||
WHERE {{ conditions | join(' AND ') }}
|
||||
@@ -77,7 +117,7 @@ WHERE {{ conditions | join(' AND ') }}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color",
|
||||
"bricktracker_parts"."spare"
|
||||
"combined"."part",
|
||||
"combined"."color",
|
||||
"combined"."spare"
|
||||
{% endblock %}
|
||||
@@ -1,26 +1,88 @@
|
||||
-- Query parts from both set-based and individual minifigures
|
||||
SELECT
|
||||
"parts_combined"."id",
|
||||
"parts_combined"."figure",
|
||||
"parts_combined"."part",
|
||||
"parts_combined"."color",
|
||||
"parts_combined"."spare",
|
||||
SUM("parts_combined"."quantity") AS "quantity",
|
||||
"parts_combined"."element",
|
||||
SUM("parts_combined"."missing") AS "total_missing",
|
||||
SUM("parts_combined"."damaged") AS "total_damaged",
|
||||
MAX("parts_combined"."checked") AS "checked",
|
||||
"rebrickable_parts"."color_name",
|
||||
"rebrickable_parts"."color_rgb",
|
||||
"rebrickable_parts"."color_transparent",
|
||||
"rebrickable_parts"."bricklink_color_id",
|
||||
"rebrickable_parts"."bricklink_color_name",
|
||||
"rebrickable_parts"."bricklink_part_num",
|
||||
"rebrickable_parts"."name",
|
||||
"rebrickable_parts"."image",
|
||||
"rebrickable_parts"."image_id",
|
||||
"rebrickable_parts"."url",
|
||||
"rebrickable_parts"."print",
|
||||
NULL AS "total_quantity",
|
||||
NULL AS "total_spare",
|
||||
NULL AS "total_sets",
|
||||
NULL AS "total_minifigures"
|
||||
FROM (
|
||||
-- Set-based minifigure parts
|
||||
SELECT
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure",
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color",
|
||||
"bricktracker_parts"."spare",
|
||||
"bricktracker_parts"."quantity",
|
||||
"bricktracker_parts"."element",
|
||||
"bricktracker_parts"."missing",
|
||||
"bricktracker_parts"."damaged",
|
||||
"bricktracker_parts"."checked"
|
||||
FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."figure" IS NOT DISTINCT FROM :figure
|
||||
|
||||
{% extends 'part/base/base.sql' %}
|
||||
UNION ALL
|
||||
|
||||
{% block total_missing %}
|
||||
SUM("bricktracker_parts"."missing") AS "total_missing",
|
||||
{% endblock %}
|
||||
-- Individual minifigure parts
|
||||
SELECT
|
||||
"bricktracker_individual_minifigure_parts"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigure_parts"."part",
|
||||
"bricktracker_individual_minifigure_parts"."color",
|
||||
"bricktracker_individual_minifigure_parts"."spare",
|
||||
"bricktracker_individual_minifigure_parts"."quantity",
|
||||
"bricktracker_individual_minifigure_parts"."element",
|
||||
"bricktracker_individual_minifigure_parts"."missing",
|
||||
"bricktracker_individual_minifigure_parts"."damaged",
|
||||
"bricktracker_individual_minifigure_parts"."checked"
|
||||
FROM "bricktracker_individual_minifigure_parts"
|
||||
INNER JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_individual_minifigure_parts"."id" = "bricktracker_individual_minifigures"."id"
|
||||
WHERE "bricktracker_individual_minifigures"."figure" IS NOT DISTINCT FROM :figure
|
||||
) AS "parts_combined"
|
||||
|
||||
{% block total_damaged %}
|
||||
SUM("bricktracker_parts"."damaged") AS "total_damaged",
|
||||
{% endblock %}
|
||||
INNER JOIN "rebrickable_parts"
|
||||
ON "parts_combined"."part" = "rebrickable_parts"."part"
|
||||
AND "parts_combined"."color" = "rebrickable_parts"."color_id"
|
||||
|
||||
{% block where %}
|
||||
{% set conditions = [] %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."figure" IS NOT DISTINCT FROM :figure') %}
|
||||
{% if skip_spare_parts %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."spare" = 0') %}
|
||||
{% endif %}
|
||||
WHERE {{ conditions | join(' AND ') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color",
|
||||
"bricktracker_parts"."spare"
|
||||
{% endblock %}
|
||||
"parts_combined"."part",
|
||||
"parts_combined"."color",
|
||||
"parts_combined"."spare",
|
||||
"parts_combined"."element",
|
||||
"rebrickable_parts"."color_name",
|
||||
"rebrickable_parts"."color_rgb",
|
||||
"rebrickable_parts"."color_transparent",
|
||||
"rebrickable_parts"."bricklink_color_id",
|
||||
"rebrickable_parts"."bricklink_color_name",
|
||||
"rebrickable_parts"."bricklink_part_num",
|
||||
"rebrickable_parts"."name",
|
||||
"rebrickable_parts"."image",
|
||||
"rebrickable_parts"."image_id",
|
||||
"rebrickable_parts"."url",
|
||||
"rebrickable_parts"."print"
|
||||
|
||||
{% if order %}
|
||||
-- Replace combined/bricktracker_parts references with parts_combined for this query
|
||||
ORDER BY {{ order | replace('"combined"', '"parts_combined"') | replace('"bricktracker_parts"', '"parts_combined"') }}
|
||||
{% endif %}
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
{% block where %}
|
||||
WHERE "rebrickable_parts"."print" IS NOT DISTINCT FROM :print
|
||||
AND "bricktracker_parts"."color" IS NOT DISTINCT FROM :color
|
||||
AND "bricktracker_parts"."part" IS DISTINCT FROM :part
|
||||
AND "combined"."color" IS NOT DISTINCT FROM :color
|
||||
AND "combined"."part" IS DISTINCT FROM :part
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color"
|
||||
"combined"."part",
|
||||
"combined"."color"
|
||||
{% endblock %}
|
||||
|
||||
@@ -2,104 +2,121 @@
|
||||
|
||||
{% block total_missing %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "bricktracker_parts"."missing" ELSE 0 END) AS "total_missing",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."missing"
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."missing"
|
||||
ELSE 0
|
||||
END) AS "total_missing",
|
||||
{% else %}
|
||||
SUM("bricktracker_parts"."missing") AS "total_missing",
|
||||
SUM("combined"."missing") AS "total_missing",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_damaged %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "bricktracker_parts"."damaged" ELSE 0 END) AS "total_damaged",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."damaged"
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."damaged"
|
||||
ELSE 0
|
||||
END) AS "total_damaged",
|
||||
{% else %}
|
||||
SUM("bricktracker_parts"."damaged") AS "total_damaged",
|
||||
SUM("combined"."damaged") AS "total_damaged",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_quantity %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "bricktracker_parts"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1) ELSE 0 END) AS "total_quantity",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."quantity" * IFNULL("bricktracker_individual_minifigures"."quantity", 1)
|
||||
ELSE 0
|
||||
END) AS "total_quantity",
|
||||
{% else %}
|
||||
SUM("bricktracker_parts"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)) AS "total_quantity",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' THEN "combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)
|
||||
WHEN "combined"."source_type" = 'individual' THEN "combined"."quantity" * IFNULL("bricktracker_individual_minifigures"."quantity", 1)
|
||||
ELSE "combined"."quantity"
|
||||
END) AS "total_quantity",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_sets %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
COUNT(DISTINCT CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "bricktracker_parts"."id" ELSE NULL END) AS "total_sets",
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."id"
|
||||
ELSE NULL
|
||||
END) AS "total_sets",
|
||||
{% else %}
|
||||
COUNT(DISTINCT "bricktracker_parts"."id") AS "total_sets",
|
||||
COUNT(DISTINCT CASE WHEN "combined"."source_type" = 'set' THEN "combined"."id" ELSE NULL END) AS "total_sets",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_minifigures %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN IFNULL("bricktracker_minifigures"."quantity", 0) ELSE 0 END) AS "total_minifigures"
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN IFNULL("bricktracker_minifigures"."quantity", 0)
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN IFNULL("bricktracker_individual_minifigures"."quantity", 0)
|
||||
ELSE 0
|
||||
END) AS "total_minifigures"
|
||||
{% else %}
|
||||
SUM(IFNULL("bricktracker_minifigures"."quantity", 0)) AS "total_minifigures"
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' THEN IFNULL("bricktracker_minifigures"."quantity", 0)
|
||||
WHEN "combined"."source_type" = 'individual' THEN IFNULL("bricktracker_individual_minifigures"."quantity", 0)
|
||||
ELSE 0
|
||||
END) AS "total_minifigures"
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
-- Join with sets to get owner information
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
|
||||
-- Join with rebrickable sets for theme/year filtering
|
||||
INNER JOIN "rebrickable_sets"
|
||||
ON "bricktracker_sets"."set" IS NOT DISTINCT FROM "rebrickable_sets"."set"
|
||||
-- Left join with sets for set-based parts
|
||||
LEFT JOIN "bricktracker_sets"
|
||||
ON "combined"."source_type" = 'set'
|
||||
AND "combined"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
|
||||
-- Left join with set owners (using dynamic columns)
|
||||
LEFT JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
|
||||
-- Left join with set tags (for tag filtering)
|
||||
{% if tag_id and tag_id != 'all' %}
|
||||
LEFT JOIN "bricktracker_set_tags"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_tags"."id"
|
||||
{% endif %}
|
||||
|
||||
-- Left join with minifigures
|
||||
-- Left join with set-based minifigures
|
||||
LEFT JOIN "bricktracker_minifigures"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_minifigures"."id"
|
||||
AND "bricktracker_parts"."figure" IS NOT DISTINCT FROM "bricktracker_minifigures"."figure"
|
||||
ON "combined"."source_type" = 'set'
|
||||
AND "combined"."id" IS NOT DISTINCT FROM "bricktracker_minifigures"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "bricktracker_minifigures"."figure"
|
||||
|
||||
-- Left join with individual minifigures
|
||||
LEFT JOIN "bricktracker_individual_minifigures"
|
||||
ON "combined"."source_type" = 'individual'
|
||||
AND "combined"."id" IS NOT DISTINCT FROM "bricktracker_individual_minifigures"."id"
|
||||
|
||||
-- Left join with individual minifigure owners
|
||||
LEFT JOIN "bricktracker_individual_minifigure_owners"
|
||||
ON "bricktracker_individual_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_individual_minifigure_owners"."id"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
{% set conditions = [] %}
|
||||
-- Always filter for problematic parts
|
||||
{% set _ = conditions.append('("bricktracker_parts"."missing" > 0 OR "bricktracker_parts"."damaged" > 0)') %}
|
||||
{% set _ = conditions.append('("combined"."missing" > 0 OR "combined"."damaged" > 0)') %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
{% set _ = conditions.append('"bricktracker_set_owners"."owner_' ~ owner_id ~ '" = 1') %}
|
||||
{% set owner_condition = '(("combined"."source_type" = \'set\' AND "bricktracker_set_owners"."owner_' ~ owner_id ~ '" = 1) OR ("combined"."source_type" = \'individual\' AND "bricktracker_individual_minifigure_owners"."owner_' ~ owner_id ~ '" = 1))' %}
|
||||
{% set _ = conditions.append(owner_condition) %}
|
||||
{% endif %}
|
||||
{% if color_id and color_id != 'all' %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."color" = ' ~ color_id) %}
|
||||
{% endif %}
|
||||
{% if theme_id and theme_id != 'all' %}
|
||||
{% set _ = conditions.append('"rebrickable_sets"."theme_id" = ' ~ theme_id) %}
|
||||
{% endif %}
|
||||
{% if year and year != 'all' %}
|
||||
{% set _ = conditions.append('"rebrickable_sets"."year" = ' ~ year) %}
|
||||
{% endif %}
|
||||
{% if storage_id and storage_id != 'all' %}
|
||||
{% set _ = conditions.append('"bricktracker_sets"."storage" = \'' ~ storage_id ~ '\'') %}
|
||||
{% endif %}
|
||||
{% if tag_id and tag_id != 'all' %}
|
||||
{% set _ = conditions.append('"bricktracker_set_tags"."tag_' ~ tag_id ~ '" = 1') %}
|
||||
{% set _ = conditions.append('"combined"."color" = ' ~ color_id) %}
|
||||
{% endif %}
|
||||
{% if search_query %}
|
||||
{% set search_condition = '(LOWER("rebrickable_parts"."name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("rebrickable_parts"."color_name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("bricktracker_parts"."part") LIKE LOWER(\'%' ~ search_query ~ '%\'))' %}
|
||||
{% set search_condition = '(LOWER("rebrickable_parts"."name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("rebrickable_parts"."color_name") LIKE LOWER(\'%' ~ search_query ~ '%\') OR LOWER("combined"."part") LIKE LOWER(\'%' ~ search_query ~ '%\'))' %}
|
||||
{% set _ = conditions.append(search_condition) %}
|
||||
{% endif %}
|
||||
{% if skip_spare_parts %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."spare" = 0') %}
|
||||
{% set _ = conditions.append('"combined"."spare" = 0') %}
|
||||
{% endif %}
|
||||
WHERE {{ conditions | join(' AND ') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color",
|
||||
"bricktracker_parts"."spare"
|
||||
"combined"."part",
|
||||
"combined"."color",
|
||||
"combined"."spare"
|
||||
{% endblock %}
|
||||
|
||||
@@ -2,19 +2,14 @@
|
||||
{% extends 'part/base/base.sql' %}
|
||||
|
||||
{% block total_missing %}
|
||||
IFNULL("bricktracker_parts"."missing", 0) AS "total_missing",
|
||||
IFNULL("combined"."missing", 0) AS "total_missing",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_damaged %}
|
||||
IFNULL("bricktracker_parts"."damaged", 0) AS "total_damaged",
|
||||
IFNULL("combined"."damaged", 0) AS "total_damaged",
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
{% set conditions = [] %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."id" IS NOT DISTINCT FROM :id') %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."figure" IS NOT DISTINCT FROM :figure') %}
|
||||
{% if skip_spare_parts %}
|
||||
{% set _ = conditions.append('"bricktracker_parts"."spare" = 0') %}
|
||||
{% endif %}
|
||||
WHERE {{ conditions | join(' AND ') }}
|
||||
WHERE "combined"."id" IS NOT DISTINCT FROM :id
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM :figure
|
||||
{% endblock %}
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
{% block total_damaged %}{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
WHERE "bricktracker_parts"."color" IS DISTINCT FROM :color
|
||||
AND "bricktracker_parts"."part" IS NOT DISTINCT FROM :part
|
||||
WHERE "combined"."color" IS DISTINCT FROM :color
|
||||
AND "combined"."part" IS NOT DISTINCT FROM :part
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color"
|
||||
"combined"."part",
|
||||
"combined"."color"
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,34 +1,51 @@
|
||||
{% extends 'part/base/base.sql' %}
|
||||
|
||||
{% block total_missing %}
|
||||
SUM("bricktracker_parts"."missing") AS "total_missing",
|
||||
SUM("combined"."missing") AS "total_missing",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_damaged %}
|
||||
SUM("bricktracker_parts"."damaged") AS "total_damaged",
|
||||
SUM("combined"."damaged") AS "total_damaged",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_quantity %}
|
||||
SUM((NOT "bricktracker_parts"."spare") * "bricktracker_parts"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)) AS "total_quantity",
|
||||
SUM((NOT "combined"."spare") * "combined"."quantity" * IFNULL("minifigure_quantities"."quantity", 1)) AS "total_quantity",
|
||||
{% endblock %}
|
||||
|
||||
{% block total_spare %}
|
||||
SUM("bricktracker_parts"."spare" * "bricktracker_parts"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)) AS "total_spare",
|
||||
SUM("combined"."spare" * "combined"."quantity" * IFNULL("minifigure_quantities"."quantity", 1)) AS "total_spare",
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
LEFT JOIN "bricktracker_minifigures"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_minifigures"."id"
|
||||
AND "bricktracker_parts"."figure" IS NOT DISTINCT FROM "bricktracker_minifigures"."figure"
|
||||
-- Join to get minifigure quantities from both set-based and individual minifigures
|
||||
LEFT JOIN (
|
||||
-- Set-based minifigure quantities
|
||||
SELECT
|
||||
"bricktracker_minifigures"."id",
|
||||
"bricktracker_minifigures"."figure",
|
||||
"bricktracker_minifigures"."quantity"
|
||||
FROM "bricktracker_minifigures"
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Individual minifigure quantities
|
||||
SELECT
|
||||
"bricktracker_individual_minifigures"."id",
|
||||
"bricktracker_individual_minifigures"."figure",
|
||||
"bricktracker_individual_minifigures"."quantity"
|
||||
FROM "bricktracker_individual_minifigures"
|
||||
) AS "minifigure_quantities"
|
||||
ON "combined"."id" IS NOT DISTINCT FROM "minifigure_quantities"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "minifigure_quantities"."figure"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
WHERE "bricktracker_parts"."part" IS NOT DISTINCT FROM :part
|
||||
AND "bricktracker_parts"."color" IS NOT DISTINCT FROM :color
|
||||
WHERE "combined"."part" IS NOT DISTINCT FROM :part
|
||||
AND "combined"."color" IS NOT DISTINCT FROM :color
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color"
|
||||
"combined"."part",
|
||||
"combined"."color"
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
{% extends 'part/base/base.sql' %}
|
||||
|
||||
{% block where %}
|
||||
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
|
||||
WHERE "combined"."id" IS NOT DISTINCT FROM :id
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM :figure
|
||||
AND "combined"."part" IS NOT DISTINCT FROM :part
|
||||
AND "combined"."color" IS NOT DISTINCT FROM :color
|
||||
AND "combined"."spare" IS NOT DISTINCT FROM :spare
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"bricktracker_parts"."id",
|
||||
"bricktracker_parts"."figure",
|
||||
"bricktracker_parts"."part",
|
||||
"bricktracker_parts"."color",
|
||||
"bricktracker_parts"."spare"
|
||||
"combined"."id",
|
||||
"combined"."figure",
|
||||
"combined"."part",
|
||||
"combined"."color",
|
||||
"combined"."spare"
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
-- Get distinct storages from problem parts' sets
|
||||
SELECT DISTINCT
|
||||
"bricktracker_sets"."storage" AS "storage_id",
|
||||
"bricktracker_metadata_storages"."name" AS "storage_name",
|
||||
COUNT(DISTINCT "bricktracker_parts"."part") as "part_count"
|
||||
FROM "bricktracker_parts"
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
LEFT JOIN "bricktracker_metadata_storages"
|
||||
ON "bricktracker_sets"."storage" IS NOT DISTINCT FROM "bricktracker_metadata_storages"."id"
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
INNER JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
{% endif %}
|
||||
WHERE ("bricktracker_parts"."missing" > 0 OR "bricktracker_parts"."damaged" > 0)
|
||||
AND "bricktracker_sets"."storage" IS NOT NULL
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1
|
||||
{% endif %}
|
||||
GROUP BY "bricktracker_sets"."storage", "bricktracker_metadata_storages"."name"
|
||||
ORDER BY "bricktracker_metadata_storages"."name" ASC
|
||||
@@ -1,7 +0,0 @@
|
||||
-- Get list of all tags (simplified - filtering happens at application level)
|
||||
-- Tags use dynamic columns in bricktracker_set_tags, making direct SQL filtering complex
|
||||
SELECT
|
||||
"bricktracker_metadata_tags"."id" AS "tag_id",
|
||||
"bricktracker_metadata_tags"."name" AS "tag_name"
|
||||
FROM "bricktracker_metadata_tags"
|
||||
ORDER BY "bricktracker_metadata_tags"."name" ASC
|
||||
@@ -1,16 +0,0 @@
|
||||
-- Get distinct themes from parts' sets
|
||||
SELECT DISTINCT
|
||||
"rebrickable_sets"."theme_id",
|
||||
COUNT(DISTINCT "bricktracker_parts"."part") as "part_count"
|
||||
FROM "bricktracker_parts"
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
INNER JOIN "rebrickable_sets"
|
||||
ON "bricktracker_sets"."set" IS NOT DISTINCT FROM "rebrickable_sets"."set"
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
INNER JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
WHERE "bricktracker_set_owners"."owner_{{ owner_id }}" = 1
|
||||
{% endif %}
|
||||
GROUP BY "rebrickable_sets"."theme_id"
|
||||
ORDER BY "rebrickable_sets"."theme_id" ASC
|
||||
@@ -1,19 +0,0 @@
|
||||
-- Get distinct themes from problem parts' sets
|
||||
SELECT DISTINCT
|
||||
"rebrickable_sets"."theme_id",
|
||||
COUNT(DISTINCT "bricktracker_parts"."part") as "part_count"
|
||||
FROM "bricktracker_parts"
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
INNER JOIN "rebrickable_sets"
|
||||
ON "bricktracker_sets"."set" IS NOT DISTINCT FROM "rebrickable_sets"."set"
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
INNER JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
{% endif %}
|
||||
WHERE ("bricktracker_parts"."missing" > 0 OR "bricktracker_parts"."damaged" > 0)
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1
|
||||
{% endif %}
|
||||
GROUP BY "rebrickable_sets"."theme_id"
|
||||
ORDER BY "rebrickable_sets"."theme_id" ASC
|
||||
@@ -1,16 +0,0 @@
|
||||
-- Get distinct years from parts' sets
|
||||
SELECT DISTINCT
|
||||
"rebrickable_sets"."year",
|
||||
COUNT(DISTINCT "bricktracker_parts"."part") as "part_count"
|
||||
FROM "bricktracker_parts"
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
INNER JOIN "rebrickable_sets"
|
||||
ON "bricktracker_sets"."set" IS NOT DISTINCT FROM "rebrickable_sets"."set"
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
INNER JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
WHERE "bricktracker_set_owners"."owner_{{ owner_id }}" = 1
|
||||
{% endif %}
|
||||
GROUP BY "rebrickable_sets"."year"
|
||||
ORDER BY "rebrickable_sets"."year" DESC
|
||||
@@ -1,19 +0,0 @@
|
||||
-- Get distinct years from problem parts' sets
|
||||
SELECT DISTINCT
|
||||
"rebrickable_sets"."year",
|
||||
COUNT(DISTINCT "bricktracker_parts"."part") as "part_count"
|
||||
FROM "bricktracker_parts"
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
INNER JOIN "rebrickable_sets"
|
||||
ON "bricktracker_sets"."set" IS NOT DISTINCT FROM "rebrickable_sets"."set"
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
INNER JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
{% endif %}
|
||||
WHERE ("bricktracker_parts"."missing" > 0 OR "bricktracker_parts"."damaged" > 0)
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1
|
||||
{% endif %}
|
||||
GROUP BY "rebrickable_sets"."year"
|
||||
ORDER BY "rebrickable_sets"."year" DESC
|
||||
@@ -3,24 +3,22 @@
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
-- Delete child records first (those with foreign keys referencing bricktracker_sets)
|
||||
DELETE FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
|
||||
DELETE FROM "bricktracker_minifigures"
|
||||
WHERE "bricktracker_minifigures"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
|
||||
DELETE FROM "bricktracker_set_tags"
|
||||
WHERE "bricktracker_set_tags"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
|
||||
DELETE FROM "bricktracker_set_statuses"
|
||||
WHERE "bricktracker_set_statuses"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
DELETE FROM "bricktracker_sets"
|
||||
WHERE "bricktracker_sets"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
|
||||
DELETE FROM "bricktracker_set_owners"
|
||||
WHERE "bricktracker_set_owners"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
|
||||
-- Delete the parent record last
|
||||
DELETE FROM "bricktracker_sets"
|
||||
WHERE "bricktracker_sets"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
DELETE FROM "bricktracker_set_statuses"
|
||||
WHERE "bricktracker_set_statuses"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
|
||||
DELETE FROM "bricktracker_set_tags"
|
||||
WHERE "bricktracker_set_tags"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
|
||||
DELETE FROM "bricktracker_minifigures"
|
||||
WHERE "bricktracker_minifigures"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
|
||||
DELETE FROM "bricktracker_parts"
|
||||
WHERE "bricktracker_parts"."id" IS NOT DISTINCT FROM '{{ id }}';
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
{% extends 'set/base/full.sql' %}
|
||||
|
||||
{% block where %}
|
||||
WHERE "bricktracker_sets"."storage" IS NULL
|
||||
{% endblock %}
|
||||
@@ -7,6 +7,14 @@ ADD COLUMN "owner_{{ id }}" BOOLEAN NOT NULL DEFAULT 0;
|
||||
ALTER TABLE "bricktracker_wish_owners"
|
||||
ADD COLUMN "owner_{{ id }}" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
-- Also inject into individual minifigures
|
||||
ALTER TABLE "bricktracker_individual_minifigure_owners"
|
||||
ADD COLUMN "owner_{{ id }}" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
-- Also inject into individual parts
|
||||
ALTER TABLE "bricktracker_individual_part_owners"
|
||||
ADD COLUMN "owner_{{ id }}" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
INSERT INTO "bricktracker_metadata_owners" (
|
||||
"id",
|
||||
"name"
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
{% extends 'set/metadata/storage/base.sql' %}
|
||||
|
||||
{% block total_sets %}
|
||||
IFNULL(COUNT("bricktracker_sets"."id"), 0) AS "total_sets"
|
||||
IFNULL(COUNT(DISTINCT "bricktracker_sets"."id"), 0) AS "total_sets",
|
||||
IFNULL(COUNT(DISTINCT "bricktracker_individual_minifigures"."id"), 0) AS "total_individual_minifigures"
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
LEFT JOIN "bricktracker_sets"
|
||||
ON "bricktracker_metadata_storages"."id" IS NOT DISTINCT FROM "bricktracker_sets"."storage"
|
||||
|
||||
LEFT JOIN "bricktracker_individual_minifigures"
|
||||
ON "bricktracker_metadata_storages"."id" IS NOT DISTINCT FROM "bricktracker_individual_minifigures"."storage"
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
|
||||
@@ -3,6 +3,14 @@ BEGIN TRANSACTION;
|
||||
ALTER TABLE "bricktracker_set_tags"
|
||||
ADD COLUMN "tag_{{ id }}" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
-- Also inject into individual minifigures
|
||||
ALTER TABLE "bricktracker_individual_minifigure_tags"
|
||||
ADD COLUMN "tag_{{ id }}" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
-- Also inject into individual parts
|
||||
ALTER TABLE "bricktracker_individual_part_tags"
|
||||
ADD COLUMN "tag_{{ id }}" BOOLEAN NOT NULL DEFAULT 0;
|
||||
|
||||
INSERT INTO "bricktracker_metadata_tags" (
|
||||
"id",
|
||||
"name"
|
||||
|
||||
+23
-23
@@ -56,14 +56,14 @@ class BrickStatistics:
|
||||
"""Get financial summary from overview statistics"""
|
||||
overview = self.get_overview()
|
||||
return {
|
||||
'total_cost': overview.get('total_cost') or 0,
|
||||
'average_cost': overview.get('average_cost') or 0,
|
||||
'minimum_cost': overview.get('minimum_cost') or 0,
|
||||
'maximum_cost': overview.get('maximum_cost') or 0,
|
||||
'sets_with_price': overview.get('sets_with_price') or 0,
|
||||
'total_sets': overview.get('total_sets') or 0,
|
||||
'total_cost': overview.get('total_cost', 0),
|
||||
'average_cost': overview.get('average_cost', 0),
|
||||
'minimum_cost': overview.get('minimum_cost', 0),
|
||||
'maximum_cost': overview.get('maximum_cost', 0),
|
||||
'sets_with_price': overview.get('sets_with_price', 0),
|
||||
'total_sets': overview.get('total_sets', 0),
|
||||
'percentage_with_price': round(
|
||||
((overview.get('sets_with_price') or 0) / max((overview.get('total_sets') or 0), 1)) * 100, 1
|
||||
(overview.get('sets_with_price', 0) / max(overview.get('total_sets', 1), 1)) * 100, 1
|
||||
)
|
||||
}
|
||||
|
||||
@@ -71,16 +71,16 @@ class BrickStatistics:
|
||||
"""Get collection summary from overview statistics"""
|
||||
overview = self.get_overview()
|
||||
return {
|
||||
'total_sets': overview.get('total_sets') or 0,
|
||||
'unique_sets': overview.get('unique_sets') or 0,
|
||||
'total_parts_count': overview.get('total_parts_count') or 0,
|
||||
'unique_parts': overview.get('unique_parts') or 0,
|
||||
'total_minifigures_count': overview.get('total_minifigures_count') or 0,
|
||||
'unique_minifigures': overview.get('unique_minifigures') or 0,
|
||||
'total_missing_parts': overview.get('total_missing_parts') or 0,
|
||||
'total_damaged_parts': overview.get('total_damaged_parts') or 0,
|
||||
'storage_locations_used': overview.get('storage_locations_used') or 0,
|
||||
'purchase_locations_used': overview.get('purchase_locations_used') or 0
|
||||
'total_sets': overview.get('total_sets', 0),
|
||||
'unique_sets': overview.get('unique_sets', 0),
|
||||
'total_parts_count': overview.get('total_parts_count', 0),
|
||||
'unique_parts': overview.get('unique_parts', 0),
|
||||
'total_minifigures_count': overview.get('total_minifigures_count', 0),
|
||||
'unique_minifigures': overview.get('unique_minifigures', 0),
|
||||
'total_missing_parts': overview.get('total_missing_parts', 0),
|
||||
'total_damaged_parts': overview.get('total_damaged_parts', 0),
|
||||
'storage_locations_used': overview.get('storage_locations_used', 0),
|
||||
'purchase_locations_used': overview.get('purchase_locations_used', 0)
|
||||
}
|
||||
|
||||
def get_sets_by_year_statistics(self) -> list[dict[str, Any]]:
|
||||
@@ -106,9 +106,9 @@ class BrickStatistics:
|
||||
peak_collection_year = None
|
||||
max_sets_in_year = 0
|
||||
if sets_by_year:
|
||||
peak_year_data = max(sets_by_year, key=lambda x: x.get('total_sets') or 0)
|
||||
peak_collection_year = peak_year_data.get('year')
|
||||
max_sets_in_year = peak_year_data.get('total_sets') or 0
|
||||
peak_year_data = max(sets_by_year, key=lambda x: x['total_sets'])
|
||||
peak_collection_year = peak_year_data['year']
|
||||
max_sets_in_year = peak_year_data['total_sets']
|
||||
|
||||
# Find peak spending year
|
||||
peak_spending_year = None
|
||||
@@ -116,9 +116,9 @@ class BrickStatistics:
|
||||
if purchases_by_year:
|
||||
spending_years = [y for y in purchases_by_year if y.get('total_spent')]
|
||||
if spending_years:
|
||||
peak_spending_data = max(spending_years, key=lambda x: x.get('total_spent') or 0)
|
||||
peak_spending_year = peak_spending_data.get('purchase_year')
|
||||
max_spending = peak_spending_data.get('total_spent') or 0
|
||||
peak_spending_data = max(spending_years, key=lambda x: x['total_spent'] or 0)
|
||||
peak_spending_year = peak_spending_data['purchase_year']
|
||||
max_spending = peak_spending_data['total_spent']
|
||||
|
||||
return {
|
||||
'years_represented': years_represented,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Final
|
||||
|
||||
__version__: Final[str] = '1.3.0'
|
||||
__database_version__: Final[int] = 20
|
||||
__database_version__: Final[int] = 21
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from flask import Blueprint, request, render_template, current_app, jsonify
|
||||
from flask_login import login_required
|
||||
@@ -32,43 +31,22 @@ admin_page = Blueprint('admin', __name__, url_prefix='/admin')
|
||||
|
||||
def get_env_values():
|
||||
"""Get current environment values, using defaults from config when not set"""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
env_values = {}
|
||||
config_defaults = {}
|
||||
env_explicit_values = {} # Track which values are explicitly set
|
||||
env_locked_values = {} # Track which values are set via Docker environment (locked)
|
||||
|
||||
# Get list of variables that were set via Docker environment (before .env was loaded)
|
||||
# This was stored by load_env_file() in app.py
|
||||
docker_env_vars = set()
|
||||
if '_BK_DOCKER_ENV_VARS' in os.environ:
|
||||
try:
|
||||
docker_env_vars = set(json.loads(os.environ['_BK_DOCKER_ENV_VARS']))
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
pass
|
||||
|
||||
# Read .env file if it exists (check both locations)
|
||||
env_file = None
|
||||
if Path('data/.env').exists():
|
||||
env_file = Path('data/.env')
|
||||
elif Path('.env').exists():
|
||||
env_file = Path('.env')
|
||||
|
||||
# Read .env file if it exists
|
||||
env_file = Path('.env')
|
||||
env_from_file = {}
|
||||
if env_file:
|
||||
if env_file.exists():
|
||||
with open(env_file, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#') and '=' in line:
|
||||
key, value = line.split('=', 1)
|
||||
# Strip quotes from value when reading
|
||||
value = value.strip()
|
||||
if value.startswith('"') and value.endswith('"'):
|
||||
value = value[1:-1]
|
||||
elif value.startswith("'") and value.endswith("'"):
|
||||
value = value[1:-1]
|
||||
env_from_file[key] = value
|
||||
|
||||
# Process each config item
|
||||
@@ -86,11 +64,6 @@ def get_env_values():
|
||||
# For int/other types, keep the original default value
|
||||
config_defaults[env_name] = default_value
|
||||
|
||||
# Check if value is set via Docker environment directive
|
||||
# A variable is "locked" if it was in os.environ BEFORE our app loaded .env
|
||||
is_locked = env_name in docker_env_vars
|
||||
env_locked_values[env_name] = is_locked
|
||||
|
||||
# Check if value is explicitly set in .env file or environment
|
||||
is_explicitly_set = env_name in env_from_file or env_name in os.environ
|
||||
env_explicit_values[env_name] = is_explicitly_set
|
||||
@@ -115,7 +88,7 @@ def get_env_values():
|
||||
|
||||
env_values[env_name] = value
|
||||
|
||||
return env_values, config_defaults, env_explicit_values, env_locked_values
|
||||
return env_values, config_defaults, env_explicit_values
|
||||
|
||||
|
||||
# Admin
|
||||
@@ -229,36 +202,13 @@ def admin() -> str:
|
||||
open_tag
|
||||
)
|
||||
|
||||
env_values, config_defaults, env_explicit_values, env_locked_values = get_env_values()
|
||||
|
||||
# Check .env file location and set warnings
|
||||
env_file_location = None
|
||||
env_file_warning = False
|
||||
env_file_missing = False
|
||||
|
||||
if os.path.exists('data/.env'):
|
||||
env_file_location = 'data/.env'
|
||||
env_file_warning = False
|
||||
env_file_missing = False
|
||||
elif os.path.exists('.env'):
|
||||
env_file_location = '.env'
|
||||
env_file_warning = True # Warn: changes won't persist without volume mount
|
||||
env_file_missing = False
|
||||
else:
|
||||
env_file_location = None
|
||||
env_file_warning = False
|
||||
env_file_missing = True # Warn: no .env file found
|
||||
|
||||
env_values, config_defaults, env_explicit_values = get_env_values()
|
||||
return render_template(
|
||||
'admin.html',
|
||||
configuration=BrickConfigurationList.list(),
|
||||
env_values=env_values,
|
||||
config_defaults=config_defaults,
|
||||
env_explicit_values=env_explicit_values,
|
||||
env_locked_values=env_locked_values,
|
||||
env_file_location=env_file_location,
|
||||
env_file_warning=env_file_warning,
|
||||
env_file_missing=env_file_missing,
|
||||
database_counters=database_counters,
|
||||
database_error=request.args.get('database_error'),
|
||||
database_exception=database_exception,
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import os
|
||||
import logging
|
||||
from flask import Blueprint, current_app, send_from_directory, abort
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
data_page = Blueprint(
|
||||
'data',
|
||||
__name__,
|
||||
url_prefix='/data'
|
||||
)
|
||||
|
||||
|
||||
@data_page.route('/<path:folder>/<filename>')
|
||||
def serve_data_file(folder: str, filename: str):
|
||||
"""
|
||||
Serve files from the data folder (images, PDFs, etc.)
|
||||
This replaces serving these files from static/ folder.
|
||||
|
||||
Security:
|
||||
- Only allows serving files from configured data folders
|
||||
- Uses secure_filename to prevent path traversal
|
||||
- Returns 404 if file doesn't exist or folder not allowed
|
||||
"""
|
||||
# Secure the filename to prevent path traversal attacks
|
||||
safe_filename = secure_filename(filename)
|
||||
|
||||
# Get the configured data folders
|
||||
allowed_folders = {
|
||||
'sets': current_app.config.get('SETS_FOLDER', './data/sets'),
|
||||
'parts': current_app.config.get('PARTS_FOLDER', './data/parts'),
|
||||
'minifigures': current_app.config.get('MINIFIGURES_FOLDER', './data/minifigures'),
|
||||
'instructions': current_app.config.get('INSTRUCTIONS_FOLDER', './data/instructions'),
|
||||
}
|
||||
|
||||
# Check if the requested folder is allowed
|
||||
if folder not in allowed_folders:
|
||||
logger.warning(f"Attempt to access unauthorized folder: {folder}")
|
||||
abort(404)
|
||||
|
||||
# Get the actual folder path
|
||||
folder_path = allowed_folders[folder]
|
||||
|
||||
# If folder_path is relative (not absolute), make it relative to app root
|
||||
if not os.path.isabs(folder_path):
|
||||
folder_path = os.path.join(current_app.root_path, folder_path)
|
||||
|
||||
# Check if file exists
|
||||
file_path = os.path.join(folder_path, safe_filename)
|
||||
if not os.path.isfile(file_path):
|
||||
logger.debug(f"File not found: {file_path}")
|
||||
abort(404)
|
||||
|
||||
# Verify the resolved path is still within the allowed folder (security check)
|
||||
if not os.path.abspath(file_path).startswith(os.path.abspath(folder_path)):
|
||||
logger.warning(f"Path traversal attempt detected: {filename}")
|
||||
abort(404)
|
||||
|
||||
return send_from_directory(folder_path, safe_filename)
|
||||
@@ -2,7 +2,6 @@ from flask import Blueprint, render_template
|
||||
|
||||
from .exceptions import exception_handler
|
||||
from ..minifigure_list import BrickMinifigureList
|
||||
from ..set_status_list import BrickSetStatusList
|
||||
from ..set_list import BrickSetList, set_metadata_lists
|
||||
|
||||
index_page = Blueprint('index', __name__)
|
||||
@@ -15,7 +14,6 @@ def index() -> str:
|
||||
return render_template(
|
||||
'index.html',
|
||||
brickset_collection=BrickSetList().last(),
|
||||
brickset_statuses=BrickSetStatusList.list(),
|
||||
minifigure_collection=BrickMinifigureList().last(),
|
||||
**set_metadata_lists(as_class=True)
|
||||
)
|
||||
|
||||
@@ -0,0 +1,281 @@
|
||||
import logging
|
||||
|
||||
from flask import Blueprint, jsonify, redirect, render_template, request, url_for, Response
|
||||
from flask_login import login_required
|
||||
|
||||
from .exceptions import exception_handler
|
||||
from ..individual_minifigure import IndividualMinifigure
|
||||
from ..part import BrickPart
|
||||
from ..set_list import set_metadata_lists
|
||||
from ..set_owner_list import BrickSetOwnerList
|
||||
from ..set_tag_list import BrickSetTagList
|
||||
from ..set_storage_list import BrickSetStorageList
|
||||
from ..set_purchase_location_list import BrickSetPurchaseLocationList
|
||||
from ..sql import BrickSQL
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
individual_minifigure_page = Blueprint('individual_minifigure', __name__, url_prefix='/individual-minifigures')
|
||||
|
||||
|
||||
# Individual minifigure instance details/edit
|
||||
@individual_minifigure_page.route('/<id>')
|
||||
@exception_handler(__file__)
|
||||
def details(*, id: str) -> str:
|
||||
item = IndividualMinifigure().select_by_id(id)
|
||||
|
||||
return render_template(
|
||||
'individual_minifigure/details.html',
|
||||
item=item,
|
||||
**set_metadata_lists(as_class=True)
|
||||
)
|
||||
|
||||
|
||||
# Update individual minifigure instance
|
||||
@individual_minifigure_page.route('/<id>/update', methods=['POST'])
|
||||
@exception_handler(__file__)
|
||||
def update(*, id: str):
|
||||
item = IndividualMinifigure().select_by_id(id)
|
||||
|
||||
# Update basic fields
|
||||
item.fields.quantity = int(request.form.get('quantity', 1))
|
||||
item.fields.description = request.form.get('description', '')
|
||||
item.fields.storage = request.form.get('storage') or None
|
||||
item.fields.purchase_location = request.form.get('purchase_location') or None
|
||||
|
||||
# Update the individual minifigure
|
||||
from ..sql import BrickSQL
|
||||
BrickSQL().execute(
|
||||
'individual_minifigure/update',
|
||||
parameters={
|
||||
'id': item.fields.id,
|
||||
'quantity': item.fields.quantity,
|
||||
'description': item.fields.description,
|
||||
'storage': item.fields.storage,
|
||||
'purchase_location': item.fields.purchase_location,
|
||||
},
|
||||
commit=False,
|
||||
)
|
||||
|
||||
# Update owners
|
||||
owners = request.form.getlist('owners')
|
||||
for owner in BrickSetOwnerList.list():
|
||||
owner.update_individual_minifigure_state(item, state=(owner.fields.id in owners))
|
||||
|
||||
# Update tags
|
||||
tags = request.form.getlist('tags')
|
||||
for tag in BrickSetTagList.list():
|
||||
tag.update_individual_minifigure_state(item, state=(tag.fields.id in tags))
|
||||
|
||||
BrickSQL().commit()
|
||||
|
||||
return redirect(url_for('individual_minifigure.details', id=id))
|
||||
|
||||
|
||||
# Update quantity
|
||||
@individual_minifigure_page.route('/<id>/update/quantity', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def update_quantity(*, id: str):
|
||||
item = IndividualMinifigure().select_by_id(id)
|
||||
item.fields.quantity = int(request.json.get('value', 1))
|
||||
|
||||
BrickSQL().execute_and_commit(
|
||||
'individual_minifigure/update',
|
||||
parameters={
|
||||
'id': item.fields.id,
|
||||
'quantity': item.fields.quantity,
|
||||
'description': item.fields.description,
|
||||
'storage': item.fields.storage,
|
||||
'purchase_location': item.fields.purchase_location,
|
||||
}
|
||||
)
|
||||
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
# Update description
|
||||
@individual_minifigure_page.route('/<id>/update/description', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def update_description(*, id: str):
|
||||
item = IndividualMinifigure().select_by_id(id)
|
||||
item.fields.description = request.json.get('value', '')
|
||||
|
||||
BrickSQL().execute_and_commit(
|
||||
'individual_minifigure/update',
|
||||
parameters={
|
||||
'id': item.fields.id,
|
||||
'quantity': item.fields.quantity,
|
||||
'description': item.fields.description,
|
||||
'storage': item.fields.storage,
|
||||
'purchase_location': item.fields.purchase_location,
|
||||
}
|
||||
)
|
||||
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
# Update owner
|
||||
@individual_minifigure_page.route('/<id>/update/owner/<metadata_id>', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def update_owner(*, id: str, metadata_id: str):
|
||||
item = IndividualMinifigure().select_by_id(id)
|
||||
owner = BrickSetOwnerList.get(metadata_id)
|
||||
owner.update_individual_minifigure_state(item, json=request.json)
|
||||
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
# Update tag
|
||||
@individual_minifigure_page.route('/<id>/update/tag/<metadata_id>', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def update_tag(*, id: str, metadata_id: str):
|
||||
item = IndividualMinifigure().select_by_id(id)
|
||||
tag = BrickSetTagList.get(metadata_id)
|
||||
tag.update_individual_minifigure_state(item, json=request.json)
|
||||
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
# Update status
|
||||
@individual_minifigure_page.route('/<id>/update/status/<metadata_id>', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def update_status(*, id: str, metadata_id: str):
|
||||
item = IndividualMinifigure().select_by_id(id)
|
||||
from ..set_status_list import BrickSetStatusList
|
||||
status = BrickSetStatusList.get(metadata_id)
|
||||
status.update_individual_minifigure_state(item, json=request.json)
|
||||
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
# Update storage
|
||||
@individual_minifigure_page.route('/<id>/update/storage', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def update_storage(*, id: str):
|
||||
item = IndividualMinifigure().select_by_id(id)
|
||||
storage_id = request.json.get('value')
|
||||
|
||||
BrickSQL().execute_and_commit(
|
||||
'individual_minifigure/update',
|
||||
parameters={
|
||||
'id': item.fields.id,
|
||||
'quantity': item.fields.quantity,
|
||||
'description': item.fields.description,
|
||||
'storage': storage_id if storage_id else None,
|
||||
'purchase_location': item.fields.purchase_location,
|
||||
}
|
||||
)
|
||||
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
# Update purchase location
|
||||
@individual_minifigure_page.route('/<id>/update/purchase_location', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def update_purchase_location(*, id: str):
|
||||
item = IndividualMinifigure().select_by_id(id)
|
||||
location_id = request.json.get('value')
|
||||
|
||||
BrickSQL().execute_and_commit(
|
||||
'individual_minifigure/update',
|
||||
parameters={
|
||||
'id': item.fields.id,
|
||||
'quantity': item.fields.quantity,
|
||||
'description': item.fields.description,
|
||||
'storage': item.fields.storage,
|
||||
'purchase_location': location_id if location_id else None,
|
||||
}
|
||||
)
|
||||
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
# Update problematic pieces of an individual minifigure
|
||||
@individual_minifigure_page.route('/<id>/parts/<part>/<int:color>/<int:spare>/<problem>', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__, json=True)
|
||||
def problem_part(
|
||||
*,
|
||||
id: str,
|
||||
part: str,
|
||||
color: int,
|
||||
spare: int,
|
||||
problem: str,
|
||||
) -> Response:
|
||||
minifigure = IndividualMinifigure().select_by_id(id)
|
||||
|
||||
brickpart = BrickPart().select_specific_individual_minifigure(
|
||||
minifigure,
|
||||
part,
|
||||
color,
|
||||
spare,
|
||||
)
|
||||
|
||||
amount = brickpart.update_problem_individual_minifigure(problem, request.json)
|
||||
|
||||
# Info
|
||||
logger.info('Individual minifigure {figure} ({id}): updated part ({part} color: {color}, spare: {spare}) {problem} count to {amount}'.format(
|
||||
figure=minifigure.fields.figure,
|
||||
id=minifigure.fields.id,
|
||||
part=brickpart.fields.part,
|
||||
color=brickpart.fields.color,
|
||||
spare=brickpart.fields.spare,
|
||||
problem=problem,
|
||||
amount=amount
|
||||
))
|
||||
|
||||
return jsonify({problem: amount})
|
||||
|
||||
|
||||
# Update checked state of parts
|
||||
@individual_minifigure_page.route('/<id>/parts/<part>/<int:color>/<int:spare>/checked', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__, json=True)
|
||||
def checked_part(
|
||||
*,
|
||||
id: str,
|
||||
part: str,
|
||||
color: int,
|
||||
spare: int,
|
||||
) -> Response:
|
||||
minifigure = IndividualMinifigure().select_by_id(id)
|
||||
|
||||
brickpart = BrickPart().select_specific_individual_minifigure(
|
||||
minifigure,
|
||||
part,
|
||||
color,
|
||||
spare,
|
||||
)
|
||||
|
||||
checked = brickpart.update_checked_individual_minifigure(request.json)
|
||||
|
||||
# Info
|
||||
logger.info('Individual minifigure {figure} ({id}): updated part ({part} color: {color}, spare: {spare}) checked state to {checked}'.format(
|
||||
figure=minifigure.fields.figure,
|
||||
id=minifigure.fields.id,
|
||||
part=brickpart.fields.part,
|
||||
color=brickpart.fields.color,
|
||||
spare=brickpart.fields.spare,
|
||||
checked=checked
|
||||
))
|
||||
|
||||
return jsonify({'checked': checked})
|
||||
|
||||
|
||||
# Delete individual minifigure instance
|
||||
@individual_minifigure_page.route('/<id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def delete(*, id: str):
|
||||
item = IndividualMinifigure().select_by_id(id)
|
||||
figure = item.fields.figure
|
||||
item.delete()
|
||||
|
||||
return redirect(url_for('minifigure.details', figure=figure))
|
||||
@@ -3,6 +3,7 @@ from flask import Blueprint, current_app, render_template, request
|
||||
from .exceptions import exception_handler
|
||||
from ..minifigure import BrickMinifigure
|
||||
from ..minifigure_list import BrickMinifigureList
|
||||
from ..individual_minifigure_list import IndividualMinifigureList
|
||||
from ..pagination_helper import get_pagination_config, build_pagination_context, get_request_params
|
||||
from ..set_list import BrickSetList, set_metadata_lists
|
||||
from ..set_owner_list import BrickSetOwnerList
|
||||
@@ -16,9 +17,6 @@ minifigure_page = Blueprint('minifigure', __name__, url_prefix='/minifigures')
|
||||
def list() -> str:
|
||||
# Get filter parameters from request
|
||||
owner_id = request.args.get('owner', 'all')
|
||||
problems_filter = request.args.get('problems', 'all')
|
||||
theme_id = request.args.get('theme', 'all')
|
||||
year = request.args.get('year', 'all')
|
||||
search_query, sort_field, sort_order, page = get_request_params()
|
||||
|
||||
# Get pagination configuration
|
||||
@@ -29,9 +27,6 @@ def list() -> str:
|
||||
# PAGINATION MODE - Server-side pagination with search
|
||||
minifigures, total_count = BrickMinifigureList().all_filtered_paginated(
|
||||
owner_id=owner_id,
|
||||
problems_filter=problems_filter,
|
||||
theme_id=theme_id,
|
||||
year=year,
|
||||
search_query=search_query,
|
||||
page=page,
|
||||
per_page=per_page,
|
||||
@@ -43,45 +38,19 @@ def list() -> str:
|
||||
else:
|
||||
# ORIGINAL MODE - Single page with all data for client-side search
|
||||
if owner_id == 'all' or owner_id is None or owner_id == '':
|
||||
minifigures = BrickMinifigureList().all_filtered(problems_filter=problems_filter, theme_id=theme_id, year=year)
|
||||
minifigures = BrickMinifigureList().all()
|
||||
else:
|
||||
minifigures = BrickMinifigureList().all_by_owner_filtered(owner_id=owner_id, problems_filter=problems_filter, theme_id=theme_id, year=year)
|
||||
minifigures = BrickMinifigureList().all_by_owner(owner_id)
|
||||
|
||||
pagination_context = None
|
||||
|
||||
# Get list of owners for filter dropdown
|
||||
owners = BrickSetOwnerList.list()
|
||||
|
||||
# Prepare context for dependent filters
|
||||
filter_context = {}
|
||||
if owner_id != 'all' and owner_id:
|
||||
filter_context['owner_id'] = owner_id
|
||||
|
||||
# Get list of themes for filter dropdown
|
||||
from ..theme_list import BrickThemeList
|
||||
from ..sql import BrickSQL
|
||||
theme_list = BrickThemeList()
|
||||
themes_data = BrickSQL().fetchall('minifigure/themes/list', **filter_context)
|
||||
themes = []
|
||||
for theme_data in themes_data:
|
||||
theme = theme_list.get(theme_data['theme_id'])
|
||||
themes.append({
|
||||
'theme_id': theme_data['theme_id'],
|
||||
'theme_name': theme.name if theme else f"Theme {theme_data['theme_id']}"
|
||||
})
|
||||
|
||||
# Get list of years for filter dropdown
|
||||
years = BrickSQL().fetchall('minifigure/years/list', **filter_context)
|
||||
|
||||
template_context = {
|
||||
'table_collection': minifigures,
|
||||
'owners': owners,
|
||||
'selected_owner': owner_id,
|
||||
'selected_problems': problems_filter,
|
||||
'themes': themes,
|
||||
'selected_theme': theme_id,
|
||||
'years': years,
|
||||
'selected_year': year,
|
||||
'search_query': search_query,
|
||||
'use_pagination': use_pagination,
|
||||
'current_sort': sort_field,
|
||||
@@ -104,5 +73,6 @@ def details(*, figure: str) -> str:
|
||||
using=BrickSetList().using_minifigure(figure),
|
||||
missing=BrickSetList().missing_minifigure(figure),
|
||||
damaged=BrickSetList().damaged_minifigure(figure),
|
||||
individual_instances=IndividualMinifigureList().instances_by_figure(figure),
|
||||
**set_metadata_lists(as_class=True)
|
||||
)
|
||||
|
||||
+15
-74
@@ -19,8 +19,6 @@ def list() -> str:
|
||||
# Get filter parameters from request
|
||||
owner_id = request.args.get('owner', 'all')
|
||||
color_id = request.args.get('color', 'all')
|
||||
theme_id = request.args.get('theme', 'all')
|
||||
year = request.args.get('year', 'all')
|
||||
search_query, sort_field, sort_order, page = get_request_params()
|
||||
|
||||
# Get pagination configuration
|
||||
@@ -32,8 +30,6 @@ def list() -> str:
|
||||
parts, total_count = BrickPartList().all_filtered_paginated(
|
||||
owner_id=owner_id,
|
||||
color_id=color_id,
|
||||
theme_id=theme_id,
|
||||
year=year,
|
||||
search_query=search_query,
|
||||
page=page,
|
||||
per_page=per_page,
|
||||
@@ -44,34 +40,19 @@ def list() -> str:
|
||||
pagination_context = build_pagination_context(page, per_page, total_count, is_mobile)
|
||||
else:
|
||||
# ORIGINAL MODE - Single page with all data for client-side search
|
||||
parts = BrickPartList().all_filtered(owner_id, color_id, theme_id, year)
|
||||
parts = BrickPartList().all_filtered(owner_id, color_id)
|
||||
pagination_context = None
|
||||
|
||||
# Get list of owners for filter dropdown
|
||||
owners = BrickSetOwnerList.list()
|
||||
|
||||
# Prepare context for dependent filters
|
||||
filter_context = {}
|
||||
if owner_id != 'all' and owner_id:
|
||||
filter_context['owner_id'] = owner_id
|
||||
|
||||
# Get list of colors for filter dropdown
|
||||
colors = BrickSQL().fetchall('part/colors/list', **filter_context)
|
||||
# Prepare context for color query (filter by owner if selected)
|
||||
color_context = {}
|
||||
if owner_id != 'all' and owner_id:
|
||||
color_context['owner_id'] = owner_id
|
||||
|
||||
# Get list of themes for filter dropdown
|
||||
from ..theme_list import BrickThemeList
|
||||
theme_list = BrickThemeList()
|
||||
themes_data = BrickSQL().fetchall('part/themes/list', **filter_context)
|
||||
themes = []
|
||||
for theme_data in themes_data:
|
||||
theme = theme_list.get(theme_data['theme_id'])
|
||||
themes.append({
|
||||
'theme_id': theme_data['theme_id'],
|
||||
'theme_name': theme.name if theme else f"Theme {theme_data['theme_id']}"
|
||||
})
|
||||
|
||||
# Get list of years for filter dropdown
|
||||
years = BrickSQL().fetchall('part/years/list', **filter_context)
|
||||
colors = BrickSQL().fetchall('part/colors/list', **color_context)
|
||||
|
||||
template_context = {
|
||||
'table_collection': parts,
|
||||
@@ -79,10 +60,6 @@ def list() -> str:
|
||||
'selected_owner': owner_id,
|
||||
'colors': colors,
|
||||
'selected_color': color_id,
|
||||
'themes': themes,
|
||||
'selected_theme': theme_id,
|
||||
'years': years,
|
||||
'selected_year': year,
|
||||
'search_query': search_query,
|
||||
'use_pagination': use_pagination,
|
||||
'current_sort': sort_field,
|
||||
@@ -103,10 +80,6 @@ def problem() -> str:
|
||||
# Get filter parameters from request
|
||||
owner_id = request.args.get('owner', 'all')
|
||||
color_id = request.args.get('color', 'all')
|
||||
theme_id = request.args.get('theme', 'all')
|
||||
year = request.args.get('year', 'all')
|
||||
storage_id = request.args.get('storage', 'all')
|
||||
tag_id = request.args.get('tag', 'all')
|
||||
search_query, sort_field, sort_order, page = get_request_params()
|
||||
|
||||
# Get pagination configuration
|
||||
@@ -118,10 +91,6 @@ def problem() -> str:
|
||||
parts, total_count = BrickPartList().problem_paginated(
|
||||
owner_id=owner_id,
|
||||
color_id=color_id,
|
||||
theme_id=theme_id,
|
||||
year=year,
|
||||
storage_id=storage_id,
|
||||
tag_id=tag_id,
|
||||
search_query=search_query,
|
||||
page=page,
|
||||
per_page=per_page,
|
||||
@@ -132,40 +101,20 @@ def problem() -> str:
|
||||
pagination_context = build_pagination_context(page, per_page, total_count, is_mobile)
|
||||
else:
|
||||
# ORIGINAL MODE - Single page with all data for client-side search
|
||||
parts = BrickPartList().problem_filtered(owner_id, color_id, theme_id, year, storage_id, tag_id)
|
||||
parts = BrickPartList().problem_filtered(owner_id, color_id)
|
||||
pagination_context = None
|
||||
|
||||
# Get list of owners for filter dropdown
|
||||
owners = BrickSetOwnerList.list()
|
||||
|
||||
# Prepare context for dependent filters
|
||||
filter_context = {}
|
||||
if owner_id != 'all' and owner_id:
|
||||
filter_context['owner_id'] = owner_id
|
||||
# Get list of colors for filter dropdown
|
||||
# Prepare context for color query (filter by owner if selected)
|
||||
color_context = {}
|
||||
if owner_id != 'all':
|
||||
color_context['owner_id'] = owner_id
|
||||
|
||||
# Get list of colors for filter dropdown (problem parts only)
|
||||
colors = BrickSQL().fetchall('part/colors/list_problem', **filter_context)
|
||||
|
||||
# Get list of themes for filter dropdown (problem parts only)
|
||||
from ..theme_list import BrickThemeList
|
||||
theme_list = BrickThemeList()
|
||||
themes_data = BrickSQL().fetchall('part/themes/list_problem', **filter_context)
|
||||
themes = []
|
||||
for theme_data in themes_data:
|
||||
theme = theme_list.get(theme_data['theme_id'])
|
||||
themes.append({
|
||||
'theme_id': theme_data['theme_id'],
|
||||
'theme_name': theme.name if theme else f"Theme {theme_data['theme_id']}"
|
||||
})
|
||||
|
||||
# Get list of years for filter dropdown (problem parts only)
|
||||
years = BrickSQL().fetchall('part/years/list_problem', **filter_context)
|
||||
|
||||
# Get list of storages for filter dropdown (problem parts only)
|
||||
storages = BrickSQL().fetchall('part/storages/list_problem', **filter_context)
|
||||
|
||||
# Get list of tags for filter dropdown (problem parts only)
|
||||
tags = BrickSQL().fetchall('part/tags/list_problem', **filter_context)
|
||||
# Get colors from problem parts (following same pattern as parts page)
|
||||
colors = BrickSQL().fetchall('part/colors/list_problem', **color_context)
|
||||
|
||||
return render_template(
|
||||
'problem.html',
|
||||
@@ -178,15 +127,7 @@ def problem() -> str:
|
||||
owners=owners,
|
||||
colors=colors,
|
||||
selected_owner=owner_id,
|
||||
selected_color=color_id,
|
||||
themes=themes,
|
||||
selected_theme=theme_id,
|
||||
years=years,
|
||||
selected_year=year,
|
||||
storages=storages,
|
||||
selected_storage=storage_id,
|
||||
tags=tags,
|
||||
selected_tag=tag_id
|
||||
selected_color=color_id
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -285,7 +285,6 @@ def details(*, id: str) -> str:
|
||||
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:
|
||||
@@ -294,7 +293,6 @@ def details(*, id: str) -> str:
|
||||
'set.html',
|
||||
item=item,
|
||||
open_instructions=request.args.get('open_instructions'),
|
||||
brickset_statuses=BrickSetStatusList.list(all=True),
|
||||
**set_metadata_lists(as_class=True)
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ Provides statistics and analytics pages
|
||||
import logging
|
||||
|
||||
from flask import Blueprint, render_template, request, url_for, redirect, current_app
|
||||
from flask_login import login_required
|
||||
from werkzeug.wrappers.response import Response
|
||||
|
||||
from .exceptions import exception_handler
|
||||
@@ -18,7 +17,6 @@ statistics_page = Blueprint('statistics', __name__, url_prefix='/statistics')
|
||||
|
||||
|
||||
@statistics_page.route('/', methods=['GET'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def overview() -> str:
|
||||
"""Statistics overview page with metrics"""
|
||||
@@ -91,7 +89,6 @@ def redirect_to_filtered_sets(filter_type: str, filter_value: str) -> Response:
|
||||
|
||||
|
||||
@statistics_page.route('/themes', methods=['GET'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def themes() -> str:
|
||||
"""Detailed theme statistics page"""
|
||||
@@ -107,7 +104,6 @@ def themes() -> str:
|
||||
|
||||
|
||||
@statistics_page.route('/storage', methods=['GET'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def storage() -> str:
|
||||
"""Detailed storage statistics page"""
|
||||
@@ -123,7 +119,6 @@ def storage() -> str:
|
||||
|
||||
|
||||
@statistics_page.route('/purchase-locations', methods=['GET'])
|
||||
@login_required
|
||||
@exception_handler(__file__)
|
||||
def purchase_locations() -> str:
|
||||
"""Detailed purchase location statistics page"""
|
||||
@@ -177,10 +172,10 @@ def prepare_chart_data(sets_by_year_stats, purchases_by_year_stats):
|
||||
# Get sets and parts data from sets_by_year
|
||||
year_data = sets_by_year_lookup.get(year)
|
||||
if year_data:
|
||||
sets_data.append(year_data.get('total_sets') or 0)
|
||||
parts_data.append(year_data.get('total_parts') or 0)
|
||||
sets_data.append(year_data.get('total_sets', 0))
|
||||
parts_data.append(year_data.get('total_parts', 0))
|
||||
# Use actual minifigure count from the database
|
||||
minifigs_data.append(year_data.get('total_minifigures') or 0)
|
||||
minifigs_data.append(year_data.get('total_minifigures', 0))
|
||||
else:
|
||||
sets_data.append(0)
|
||||
parts_data.append(0)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
from .exceptions import exception_handler
|
||||
from ..individual_minifigure_list import IndividualMinifigureList
|
||||
from ..set_list import BrickSetList, set_metadata_lists
|
||||
from ..set_storage import BrickSetStorage
|
||||
from ..set_storage_list import BrickSetStorageList
|
||||
from ..sql import BrickSQL
|
||||
|
||||
storage_page = Blueprint('storage', __name__, url_prefix='/storages')
|
||||
|
||||
@@ -12,9 +14,48 @@ storage_page = Blueprint('storage', __name__, url_prefix='/storages')
|
||||
@storage_page.route('/', methods=['GET'])
|
||||
@exception_handler(__file__)
|
||||
def list() -> str:
|
||||
# Get counts of items with no storage
|
||||
sql = BrickSQL()
|
||||
|
||||
# Count sets with no storage
|
||||
sets_no_storage_query = 'SELECT COUNT(*) FROM "bricktracker_sets" WHERE "storage" IS NULL'
|
||||
sql.cursor.execute(sets_no_storage_query)
|
||||
sets_no_storage = sql.cursor.fetchone()[0]
|
||||
|
||||
# Count individual minifigures with no storage
|
||||
minifigs_no_storage_query = 'SELECT COUNT(*) FROM "bricktracker_individual_minifigures" WHERE "storage" IS NULL'
|
||||
sql.cursor.execute(minifigs_no_storage_query)
|
||||
minifigs_no_storage = sql.cursor.fetchone()[0]
|
||||
|
||||
return render_template(
|
||||
'storages.html',
|
||||
table_collection=BrickSetStorageList.all(),
|
||||
sets_no_storage=sets_no_storage,
|
||||
minifigs_no_storage=minifigs_no_storage,
|
||||
)
|
||||
|
||||
|
||||
# Storage details - no storage
|
||||
@storage_page.route('/no_storage/details')
|
||||
@exception_handler(__file__)
|
||||
def no_storage_details() -> str:
|
||||
# Create a mock storage object for "no storage"
|
||||
from ..record import BrickRecord
|
||||
|
||||
no_storage = BrickRecord()
|
||||
no_storage.fields.id = None
|
||||
no_storage.fields.name = 'Not in a storage location'
|
||||
|
||||
# Get sets and individual minifigures with no storage
|
||||
sets = BrickSetList().without_storage()
|
||||
individual_minifigures = IndividualMinifigureList().without_storage()
|
||||
|
||||
return render_template(
|
||||
'storage.html',
|
||||
item=no_storage,
|
||||
sets=sets,
|
||||
individual_minifigures=individual_minifigures,
|
||||
**set_metadata_lists(as_class=True)
|
||||
)
|
||||
|
||||
|
||||
@@ -28,5 +69,6 @@ def details(*, id: str) -> str:
|
||||
'storage.html',
|
||||
item=storage,
|
||||
sets=BrickSetList().using_storage(storage),
|
||||
individual_minifigures=IndividualMinifigureList().using_storage(storage),
|
||||
**set_metadata_lists(as_class=True)
|
||||
)
|
||||
|
||||
+14
-7
@@ -2,15 +2,22 @@ services:
|
||||
bricktracker:
|
||||
container_name: BrickTracker
|
||||
restart: unless-stopped
|
||||
# image: gitea.baerentsen.space/frederikbaerentsen/bricktracker:dev
|
||||
build: .
|
||||
ports:
|
||||
- "3334:3333"
|
||||
volumes:
|
||||
- ./local:/app/data # Changed from ./local to ./data for consistency
|
||||
- ./local:/local
|
||||
- ./local/instructions:/app/static/instructions/
|
||||
- ./local/minifigures:/app/static/minifigures/
|
||||
- ./local/parts:/app/static/parts/
|
||||
- ./local/sets:/app/static/sets/
|
||||
environment:
|
||||
- BK_DEBUG=true
|
||||
# For local development, place .env in data/ folder
|
||||
# The app automatically detects and uses data/.env (no env_file needed)
|
||||
# Uncomment below only if you keep .env in root for backward compatibility
|
||||
# env_file: .env
|
||||
BK_DEBUG: true
|
||||
BK_DATABASE_PATH: /local/app.db
|
||||
BK_INSTRUCTIONS_FOLDER: instructions
|
||||
BK_MINIFIGURES_FOLDER: minifigures
|
||||
BK_PARTS_FOLDER: parts
|
||||
BK_RETIRED_SETS_PATH: /local/retired_sets.csv
|
||||
BK_SETS_FOLDER: sets
|
||||
BK_THEMES_PATH: /local/themes.csv
|
||||
env_file: .env
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user