mirror of
https://gitea.baerentsen.space/FrederikBaerentsen/BrickTracker.git
synced 2025-12-21 08:39:53 -06:00
feat(minifigures): initial upload.
This commit is contained in:
@@ -29,6 +29,7 @@ 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
|
||||
@@ -80,6 +81,7 @@ def setup_app(app: Flask) -> None:
|
||||
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)
|
||||
|
||||
@@ -39,7 +39,7 @@ 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_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},
|
||||
@@ -47,7 +47,7 @@ CONFIG: Final[list[dict[str, Any]]] = [
|
||||
{'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_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},
|
||||
|
||||
456
bricktracker/individual_minifigure.py
Normal file
456
bricktracker/individual_minifigure.py
Normal file
@@ -0,0 +1,456 @@
|
||||
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:
|
||||
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:
|
||||
socket.fail(
|
||||
message='Could not load the minifigure from Rebrickable: {error}. Data: {data}'.format(
|
||||
error=str(e),
|
||||
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.fields.image if self.fields.image else '',
|
||||
'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
|
||||
|
||||
if not self.select():
|
||||
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)
|
||||
|
||||
# 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)),
|
||||
}
|
||||
44
bricktracker/individual_minifigure_list.py
Normal file
44
bricktracker/individual_minifigure_list.py
Normal file
@@ -0,0 +1,44 @@
|
||||
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'
|
||||
|
||||
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
|
||||
|
||||
# Load the instances from the database
|
||||
self.list(override_query=self.instances_by_figure_query)
|
||||
|
||||
return self
|
||||
|
||||
# Base individual minifigure list
|
||||
def list(
|
||||
self,
|
||||
/,
|
||||
*,
|
||||
override_query: str | None = None,
|
||||
order: str | None = None,
|
||||
limit: int | None = None,
|
||||
) -> None:
|
||||
# Load the individual minifigures from the database
|
||||
for record in super().select(
|
||||
override_query=override_query,
|
||||
order=order,
|
||||
limit=limit,
|
||||
):
|
||||
individual_minifigure = IndividualMinifigure(record=record)
|
||||
self.records.append(individual_minifigure)
|
||||
@@ -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__)
|
||||
@@ -28,6 +29,7 @@ class BrickMetadata(BrickRecord):
|
||||
update_field_query: str
|
||||
update_set_state_query: str
|
||||
update_set_value_query: str
|
||||
update_individual_minifigure_state_query: str
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -216,6 +218,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,
|
||||
|
||||
@@ -76,12 +76,13 @@ class BrickMinifigureList(BrickRecordList[BrickMinifigure]):
|
||||
|
||||
# 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
|
||||
|
||||
@@ -35,3 +35,28 @@ def parse_set(set: str, /) -> str:
|
||||
))
|
||||
|
||||
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
|
||||
|
||||
@@ -14,3 +14,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'
|
||||
|
||||
@@ -11,3 +11,6 @@ class BrickSetPurchaseLocation(BrickMetadata):
|
||||
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_set_state_query: str = '' # Not used for purchase location
|
||||
update_individual_minifigure_state_query: str = '' # Not used for purchase location
|
||||
set_state_endpoint: str = '' # Not used for purchase location
|
||||
|
||||
@@ -16,6 +16,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 = '' # Not used for status
|
||||
|
||||
# Grab data from a form
|
||||
def from_form(self, form: dict[str, str], /) -> Self:
|
||||
|
||||
@@ -13,6 +13,9 @@ class BrickSetStorage(BrickMetadata):
|
||||
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_set_state_query: str = '' # Not used for storage
|
||||
update_individual_minifigure_state_query: str = '' # Not used for storage
|
||||
set_state_endpoint: str = '' # Not used for storage
|
||||
|
||||
# Self url
|
||||
def url(self, /) -> str:
|
||||
|
||||
@@ -14,3 +14,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'
|
||||
|
||||
@@ -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',
|
||||
}
|
||||
@@ -207,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,
|
||||
|
||||
@@ -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;
|
||||
15
bricktracker/sql/individual_minifigure/insert.sql
Normal file
15
bricktracker/sql/individual_minifigure/insert.sql
Normal file
@@ -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,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_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
|
||||
23
bricktracker/sql/individual_minifigure/part/insert.sql
Normal file
23
bricktracker/sql/individual_minifigure/part/insert.sql
Normal file
@@ -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
|
||||
)
|
||||
26
bricktracker/sql/individual_minifigure/select/by_id.sql
Normal file
26
bricktracker/sql/individual_minifigure/select/by_id.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
-- 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"
|
||||
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"
|
||||
|
||||
WHERE "bricktracker_individual_minifigures"."id" = :id
|
||||
@@ -0,0 +1,28 @@
|
||||
-- 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"
|
||||
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"
|
||||
|
||||
WHERE "bricktracker_individual_minifigures"."figure" = :figure
|
||||
|
||||
ORDER BY "bricktracker_individual_minifigures"."rowid" DESC
|
||||
7
bricktracker/sql/individual_minifigure/update.sql
Normal file
7
bricktracker/sql/individual_minifigure/update.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
UPDATE "bricktracker_individual_minifigures"
|
||||
SET
|
||||
"quantity" = :quantity,
|
||||
"description" = :description,
|
||||
"storage" = :storage,
|
||||
"purchase_location" = :purchase_location
|
||||
WHERE "id" = :id
|
||||
132
bricktracker/sql/migrations/0020.sql
Normal file
132
bricktracker/sql/migrations/0020.sql
Normal file
@@ -0,0 +1,132 @@
|
||||
-- Migration 0020: Add individual minifigures and individual parts tables
|
||||
|
||||
-- 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")
|
||||
);
|
||||
|
||||
-- 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")
|
||||
);
|
||||
|
||||
-- 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")
|
||||
);
|
||||
|
||||
-- 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")
|
||||
);
|
||||
|
||||
-- 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")
|
||||
);
|
||||
|
||||
-- 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")
|
||||
);
|
||||
|
||||
-- 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")
|
||||
);
|
||||
|
||||
-- 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);
|
||||
23
bricktracker/sql/migrations/0021.sql
Normal file
23
bricktracker/sql/migrations/0021.sql
Normal file
@@ -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,42 @@ 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",
|
||||
'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",
|
||||
'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 %}
|
||||
|
||||
|
||||
@@ -9,16 +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 %}
|
||||
-- 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",
|
||||
@@ -29,18 +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 %}
|
||||
{% if search_query %}
|
||||
WHERE (LOWER("rebrickable_minifigures"."name") LIKE LOWER('%{{ search_query }}%'))
|
||||
WHERE (LOWER("combined"."name") LIKE LOWER('%{{ search_query }}%'))
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"rebrickable_minifigures"."figure"
|
||||
"combined"."figure"
|
||||
{% endblock %}
|
||||
|
||||
@@ -10,31 +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'
|
||||
|
||||
-- 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 "bricktracker_set_owners" AS "set_owners"
|
||||
ON "bricktracker_sets"."id" = "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",
|
||||
@@ -47,25 +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') %}
|
||||
{% 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 ') }}
|
||||
@@ -74,5 +118,5 @@ WHERE {{ conditions | join(' AND ') }}
|
||||
|
||||
{% block group %}
|
||||
GROUP BY
|
||||
"rebrickable_minifigures"."figure"
|
||||
"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,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,42 +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"
|
||||
|
||||
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) %}
|
||||
{% 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 ') }}
|
||||
@@ -45,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,33 +2,33 @@
|
||||
|
||||
{% 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 "bricktracker_set_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 "bricktracker_set_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 "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1) ELSE 0 END) AS "total_quantity",
|
||||
{% else %}
|
||||
SUM("bricktracker_parts"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)) AS "total_quantity",
|
||||
SUM("combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)) 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 "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 "combined"."id") AS "total_sets",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -43,7 +43,7 @@ SUM(IFNULL("bricktracker_minifigures"."quantity", 0)) AS "total_minifigures"
|
||||
{% block join %}
|
||||
-- Join with sets to get owner information
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
ON "combined"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
|
||||
-- Left join with set owners (using dynamic columns)
|
||||
LEFT JOIN "bricktracker_set_owners"
|
||||
@@ -51,8 +51,8 @@ ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
|
||||
-- Left join with 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"."id" IS NOT DISTINCT FROM "bricktracker_minifigures"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "bricktracker_minifigures"."figure"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
@@ -61,14 +61,14 @@ AND "bricktracker_parts"."figure" IS NOT DISTINCT FROM "bricktracker_minifigures
|
||||
{% set _ = conditions.append('"bricktracker_set_owners"."owner_' ~ owner_id ~ '" = 1') %}
|
||||
{% 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 +77,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,21 +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 %}
|
||||
WHERE "bricktracker_parts"."figure" IS NOT DISTINCT FROM :figure
|
||||
{% 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,33 +2,33 @@
|
||||
|
||||
{% 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 "bricktracker_set_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 "bricktracker_set_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 "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1) ELSE 0 END) AS "total_quantity",
|
||||
{% else %}
|
||||
SUM("bricktracker_parts"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)) AS "total_quantity",
|
||||
SUM("combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)) 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 "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 "combined"."id") AS "total_sets",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -43,7 +43,7 @@ SUM(IFNULL("bricktracker_minifigures"."quantity", 0)) AS "total_minifigures"
|
||||
{% block join %}
|
||||
-- Join with sets to get owner information
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "bricktracker_parts"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
ON "combined"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
|
||||
-- Left join with set owners (using dynamic columns)
|
||||
LEFT JOIN "bricktracker_set_owners"
|
||||
@@ -51,33 +51,33 @@ ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
|
||||
-- Left join with 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"."id" IS NOT DISTINCT FROM "bricktracker_minifigures"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "bricktracker_minifigures"."figure"
|
||||
{% 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') %}
|
||||
{% 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 %}
|
||||
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,14 +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 %}
|
||||
WHERE "bricktracker_parts"."id" IS NOT DISTINCT FROM :id
|
||||
AND "bricktracker_parts"."figure" IS NOT DISTINCT FROM :figure
|
||||
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 %}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Final
|
||||
|
||||
__version__: Final[str] = '1.3.0'
|
||||
__database_version__: Final[int] = 19
|
||||
__database_version__: Final[int] = 21
|
||||
|
||||
74
bricktracker/views/individual_minifigure.py
Normal file
74
bricktracker/views/individual_minifigure.py
Normal file
@@ -0,0 +1,74 @@
|
||||
from flask import Blueprint, redirect, render_template, request, url_for
|
||||
|
||||
from .exceptions import exception_handler
|
||||
from ..individual_minifigure import IndividualMinifigure
|
||||
from ..set_list import set_metadata_lists
|
||||
from ..set_owner_list import BrickSetOwnerList
|
||||
from ..set_tag_list import BrickSetTagList
|
||||
|
||||
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))
|
||||
|
||||
|
||||
# Delete individual minifigure instance
|
||||
@individual_minifigure_page.route('/<id>/delete', methods=['POST'])
|
||||
@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
|
||||
@@ -72,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)
|
||||
)
|
||||
|
||||
71
static/scripts/add.js
Normal file
71
static/scripts/add.js
Normal file
@@ -0,0 +1,71 @@
|
||||
// Add page - handles both sets and individual minifigures
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Get template data from data attributes
|
||||
const addContainer = document.getElementById('add-set');
|
||||
if (!addContainer) return;
|
||||
|
||||
// Read data from data attributes
|
||||
const templateData = {
|
||||
path: addContainer.dataset.path,
|
||||
namespace: addContainer.dataset.namespace,
|
||||
messages: {
|
||||
COMPLETE: addContainer.dataset.msgComplete,
|
||||
FAIL: addContainer.dataset.msgFail,
|
||||
IMPORT_SET: addContainer.dataset.msgImportSet,
|
||||
LOAD_SET: addContainer.dataset.msgLoadSet,
|
||||
PROGRESS: addContainer.dataset.msgProgress,
|
||||
SET_LOADED: addContainer.dataset.msgSetLoaded,
|
||||
IMPORT_MINIFIGURE: addContainer.dataset.msgImportMinifigure,
|
||||
LOAD_MINIFIGURE: addContainer.dataset.msgLoadMinifigure,
|
||||
MINIFIGURE_LOADED: addContainer.dataset.msgMinifigureLoaded,
|
||||
}
|
||||
};
|
||||
|
||||
// Default: create set socket
|
||||
const setSocket = new BrickSetSocket(
|
||||
'add',
|
||||
templateData.path,
|
||||
templateData.namespace,
|
||||
{
|
||||
COMPLETE: templateData.messages.COMPLETE,
|
||||
FAIL: templateData.messages.FAIL,
|
||||
IMPORT_SET: templateData.messages.IMPORT_SET,
|
||||
LOAD_SET: templateData.messages.LOAD_SET,
|
||||
PROGRESS: templateData.messages.PROGRESS,
|
||||
SET_LOADED: templateData.messages.SET_LOADED,
|
||||
},
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
// Override the execute method to check for minifigures
|
||||
const originalExecute = setSocket.execute.bind(setSocket);
|
||||
let minifigSocket = null;
|
||||
|
||||
setSocket.execute = function() {
|
||||
const inputValue = document.getElementById('add-set').value.trim();
|
||||
|
||||
if (inputValue.startsWith('fig-') || inputValue.match(/^fig\d/i)) {
|
||||
// It's a minifigure - create minifig socket if needed
|
||||
if (!minifigSocket) {
|
||||
minifigSocket = new BrickMinifigureSocket(
|
||||
'add',
|
||||
templateData.path,
|
||||
templateData.namespace,
|
||||
{
|
||||
COMPLETE: templateData.messages.COMPLETE,
|
||||
FAIL: templateData.messages.FAIL,
|
||||
IMPORT_MINIFIGURE: templateData.messages.IMPORT_MINIFIGURE,
|
||||
LOAD_MINIFIGURE: templateData.messages.LOAD_MINIFIGURE,
|
||||
MINIFIGURE_LOADED: templateData.messages.MINIFIGURE_LOADED,
|
||||
PROGRESS: templateData.messages.PROGRESS,
|
||||
}
|
||||
);
|
||||
}
|
||||
minifigSocket.execute();
|
||||
} else {
|
||||
// It's a set - use original execute
|
||||
originalExecute();
|
||||
}
|
||||
};
|
||||
});
|
||||
258
static/scripts/socket/minifigure.js
Normal file
258
static/scripts/socket/minifigure.js
Normal file
@@ -0,0 +1,258 @@
|
||||
// Minifigure Socket class
|
||||
class BrickMinifigureSocket extends BrickSocket {
|
||||
constructor(id, path, namespace, messages) {
|
||||
super(id, path, namespace, messages, false);
|
||||
|
||||
// Listeners
|
||||
this.add_listener = undefined;
|
||||
this.input_listener = undefined;
|
||||
this.confirm_listener = undefined;
|
||||
|
||||
// Form elements (built based on the initial id)
|
||||
this.html_button = document.getElementById(id);
|
||||
this.html_input = document.getElementById(`${id}-set`);
|
||||
this.html_no_confim = document.getElementById(`${id}-no-confirm`);
|
||||
this.html_owners = document.getElementById(`${id}-owners`);
|
||||
this.html_purchase_location = document.getElementById(`${id}-purchase-location`);
|
||||
this.html_storage = document.getElementById(`${id}-storage`);
|
||||
this.html_tags = document.getElementById(`${id}-tags`);
|
||||
|
||||
// Card elements
|
||||
this.html_card = document.getElementById(`${id}-card`);
|
||||
this.html_card_set = document.getElementById(`${id}-card-set`);
|
||||
this.html_card_name = document.getElementById(`${id}-card-name`);
|
||||
this.html_card_image_container = document.getElementById(`${id}-card-image-container`);
|
||||
this.html_card_image = document.getElementById(`${id}-card-image`);
|
||||
this.html_card_footer = document.getElementById(`${id}-card-footer`);
|
||||
this.html_card_confirm = document.getElementById(`${id}-card-confirm`);
|
||||
this.html_card_dismiss = document.getElementById(`${id}-card-dismiss`);
|
||||
|
||||
if (this.html_button) {
|
||||
this.add_listener = this.html_button.addEventListener("click", ((bricksocket) => (e) => {
|
||||
bricksocket.execute();
|
||||
})(this));
|
||||
|
||||
this.input_listener = this.html_input.addEventListener("keyup", ((bricksocket) => (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
bricksocket.execute();
|
||||
}
|
||||
})(this))
|
||||
}
|
||||
|
||||
if (this.html_card_dismiss && this.html_card) {
|
||||
this.html_card_dismiss.addEventListener("click", ((card) => (e) => {
|
||||
card.classList.add("d-none");
|
||||
})(this.html_card));
|
||||
}
|
||||
|
||||
// Setup the socket
|
||||
this.setup();
|
||||
}
|
||||
|
||||
// Clear form
|
||||
clear() {
|
||||
super.clear();
|
||||
|
||||
if (this.html_card) {
|
||||
this.html_card.classList.add("d-none");
|
||||
}
|
||||
|
||||
if (this.html_card_footer) {
|
||||
this.html_card_footer.classList.add("d-none");
|
||||
|
||||
if (this.html_card_confirm) {
|
||||
this.html_card_footer.classList.add("d-none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute the action
|
||||
execute() {
|
||||
if (!this.disabled && this.socket !== undefined && this.socket.connected) {
|
||||
this.toggle(false);
|
||||
|
||||
if (this.html_no_confim && this.html_no_confim.checked) {
|
||||
this.import_minifigure(true);
|
||||
} else {
|
||||
this.load_minifigure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Import a minifigure
|
||||
import_minifigure(no_confirm, figure) {
|
||||
if (this.html_input) {
|
||||
if (no_confirm) {
|
||||
this.clear();
|
||||
} else {
|
||||
this.clear_status();
|
||||
}
|
||||
|
||||
// Grab the owners
|
||||
const owners = [];
|
||||
if (this.html_owners) {
|
||||
this.html_owners.querySelectorAll('input').forEach(input => {
|
||||
if (input.checked) {
|
||||
owners.push(input.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Grab the purchase location
|
||||
let purchase_location = null;
|
||||
if (this.html_purchase_location) {
|
||||
purchase_location = this.html_purchase_location.value;
|
||||
}
|
||||
|
||||
// Grab the storage
|
||||
let storage = null;
|
||||
if (this.html_storage) {
|
||||
storage = this.html_storage.value;
|
||||
}
|
||||
|
||||
// Grab the tags
|
||||
const tags = [];
|
||||
if (this.html_tags) {
|
||||
this.html_tags.querySelectorAll('input').forEach(input => {
|
||||
if (input.checked) {
|
||||
tags.push(input.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.spinner(true);
|
||||
|
||||
if (this.html_progress_bar) {
|
||||
this.html_progress_bar.scrollIntoView();
|
||||
}
|
||||
|
||||
this.socket.emit(this.messages.IMPORT_MINIFIGURE, {
|
||||
figure: (figure !== undefined) ? figure : this.html_input.value,
|
||||
owners: owners,
|
||||
purchase_location: purchase_location,
|
||||
storage: storage,
|
||||
tags: tags,
|
||||
quantity: 1
|
||||
});
|
||||
} else {
|
||||
this.fail("Could not find the input field for the minifigure number");
|
||||
}
|
||||
}
|
||||
|
||||
// Load a minifigure
|
||||
load_minifigure() {
|
||||
if (this.html_input) {
|
||||
// Reset the progress
|
||||
this.clear()
|
||||
this.spinner(true);
|
||||
|
||||
this.socket.emit(this.messages.LOAD_MINIFIGURE, {
|
||||
figure: this.html_input.value
|
||||
});
|
||||
} else {
|
||||
this.fail("Could not find the input field for the minifigure number");
|
||||
}
|
||||
}
|
||||
|
||||
// Minifigure is loaded
|
||||
minifigure_loaded(data) {
|
||||
if (this.html_card) {
|
||||
this.html_card.classList.remove("d-none");
|
||||
|
||||
if (this.html_card_set) {
|
||||
this.html_card_set.textContent = data["figure"];
|
||||
}
|
||||
|
||||
if (this.html_card_name) {
|
||||
this.html_card_name.textContent = data["name"];
|
||||
}
|
||||
|
||||
if (this.html_card_image_container) {
|
||||
this.html_card_image_container.setAttribute("style", `background-image: url(${data["image"]})`);
|
||||
}
|
||||
|
||||
if (this.html_card_image) {
|
||||
this.html_card_image.setAttribute("src", data["image"]);
|
||||
this.html_card_image.setAttribute("alt", data["figure"]);
|
||||
}
|
||||
|
||||
if (this.html_card_footer) {
|
||||
this.html_card_footer.classList.add("d-none");
|
||||
|
||||
if (!data.download) {
|
||||
this.html_card_footer.classList.remove("d-none");
|
||||
|
||||
if (this.html_card_confirm) {
|
||||
if (this.confirm_listener !== undefined) {
|
||||
this.html_card_confirm.removeEventListener("click", this.confirm_listener);
|
||||
}
|
||||
|
||||
this.confirm_listener = ((bricksocket, figure) => (e) => {
|
||||
if (!bricksocket.disabled) {
|
||||
bricksocket.toggle(false);
|
||||
bricksocket.import_minifigure(false, figure);
|
||||
}
|
||||
})(this, data["figure"]);
|
||||
|
||||
this.html_card_confirm.addEventListener("click", this.confirm_listener);
|
||||
|
||||
this.html_card_confirm.scrollIntoView();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup the actual socket
|
||||
setup() {
|
||||
super.setup();
|
||||
|
||||
if (this.socket !== undefined) {
|
||||
// Minifigure loaded
|
||||
this.socket.on(this.messages.MINIFIGURE_LOADED, ((bricksocket) => (data) => {
|
||||
bricksocket.minifigure_loaded(data);
|
||||
})(this));
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle clicking on the button, or sending events
|
||||
toggle(enabled) {
|
||||
super.toggle(enabled);
|
||||
|
||||
if (this.html_button) {
|
||||
this.html_button.disabled = !enabled;
|
||||
}
|
||||
|
||||
if (this.html_input) {
|
||||
this.html_input.disabled = !enabled;
|
||||
}
|
||||
|
||||
if (this.html_no_confim) {
|
||||
this.html_no_confim.disabled = !enabled;
|
||||
}
|
||||
|
||||
if (this.html_owners) {
|
||||
this.html_owners.querySelectorAll('input').forEach(input => input.disabled = !enabled);
|
||||
}
|
||||
|
||||
if (this.html_purchase_location) {
|
||||
this.html_purchase_location.disabled = !enabled;
|
||||
}
|
||||
|
||||
if (this.html_storage) {
|
||||
this.html_storage.disabled = !enabled;
|
||||
}
|
||||
|
||||
if (this.html_tags) {
|
||||
this.html_tags.querySelectorAll('input').forEach(input => input.disabled = !enabled);
|
||||
}
|
||||
|
||||
if (this.html_card_confirm) {
|
||||
this.html_card_confirm.disabled = !enabled;
|
||||
}
|
||||
|
||||
if (this.html_card_dismiss) {
|
||||
this.html_card_dismiss.disabled = !enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,20 @@
|
||||
<div id="add-complete"></div>
|
||||
{% endif %}
|
||||
<div class="mb-3">
|
||||
<label for="add-set" class="form-label">{% if not bulk %}Set number (only one){% else %}List of sets (separated by a comma){% endif %}</label>
|
||||
<input type="text" class="form-control" id="add-set" placeholder="{% if not bulk %}107-1 or 1642-1 or ...{% else %}107-1, 1642-1, ...{% endif %}">
|
||||
<label for="add-set" class="form-label">{% if not bulk %}Set or Minifigure number (only one){% else %}List of sets (separated by a comma){% endif %}</label>
|
||||
<input type="text" class="form-control" id="add-set" placeholder="{% if not bulk %}107-1 or fig-001234 or ...{% else %}107-1, 1642-1, ...{% endif %}"
|
||||
data-path="{{ path }}"
|
||||
data-namespace="{{ namespace }}"
|
||||
data-msg-complete="{{ messages['COMPLETE'] }}"
|
||||
data-msg-fail="{{ messages['FAIL'] }}"
|
||||
data-msg-import-set="{{ messages['IMPORT_SET'] }}"
|
||||
data-msg-load-set="{{ messages['LOAD_SET'] }}"
|
||||
data-msg-progress="{{ messages['PROGRESS'] }}"
|
||||
data-msg-set-loaded="{{ messages['SET_LOADED'] }}"
|
||||
data-msg-import-minifigure="{{ messages['IMPORT_MINIFIGURE'] }}"
|
||||
data-msg-load-minifigure="{{ messages['LOAD_MINIFIGURE'] }}"
|
||||
data-msg-minifigure-loaded="{{ messages['MINIFIGURE_LOADED'] }}">
|
||||
<div class="form-text">Sets: use format like 107-1. Minifigures: use format like fig-001234</div>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="add-no-confirm" {% if bulk %}checked disabled{% endif %}>
|
||||
@@ -141,7 +153,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if bulk %}
|
||||
{% with id='add', bulk=bulk %}
|
||||
{% include 'set/socket.html' %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -92,7 +92,11 @@
|
||||
<script src="{{ url_for('static', filename='scripts/socket/socket.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='scripts/socket/instructions.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='scripts/socket/set.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='scripts/socket/minifigure.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='scripts/table.js') }}"></script>
|
||||
{% if request.endpoint == 'add.add' %}
|
||||
<script src="{{ url_for('static', filename='scripts/add.js') }}"></script>
|
||||
{% endif %}
|
||||
{% if request.endpoint == 'minifigure.list' %}
|
||||
<script src="{{ url_for('static', filename='scripts/minifigures.js') }}"></script>
|
||||
{% endif %}
|
||||
|
||||
25
templates/individual_minifigure/card.html
Normal file
25
templates/individual_minifigure/card.html
Normal file
@@ -0,0 +1,25 @@
|
||||
{% import 'macro/badge.html' as badge %}
|
||||
{% import 'macro/card.html' as card %}
|
||||
|
||||
<div class="card mb-3 flex-fill">
|
||||
{{ card.header(item, item.fields.name, solo=false, identifier=item.fields.figure, icon='user-line') }}
|
||||
{{ card.image(item, solo=false, last=false, caption=item.fields.name, alt=item.fields.figure, medium=false) }}
|
||||
<div class="card-body border-bottom p-1">
|
||||
{{ badge.quantity(item.fields.quantity, solo=false, last=false) }}
|
||||
{% if item.fields.storage_name %}
|
||||
<span class="badge text-bg-info" data-bs-toggle="tooltip" title="Storage">
|
||||
<i class="ri-archive-2-line"></i> {{ item.fields.storage_name }}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if item.fields.purchase_location_name %}
|
||||
<span class="badge text-bg-secondary" data-bs-toggle="tooltip" title="Purchase Location">
|
||||
<i class="ri-building-line"></i> {{ item.fields.purchase_location_name }}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if item.fields.description %}
|
||||
<span class="badge text-bg-light text-dark" data-bs-toggle="tooltip" title="Description">
|
||||
<i class="ri-file-text-line"></i> {{ item.fields.description }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
123
templates/individual_minifigure/details.html
Normal file
123
templates/individual_minifigure/details.html
Normal file
@@ -0,0 +1,123 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %} - Individual Minifigure {{ item.fields.name }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h5 class="mb-0">
|
||||
<i class="ri-user-line"></i> {{ item.fields.name }}
|
||||
<span class="badge text-bg-secondary fw-normal"><i class="ri-hashtag"></i> {{ item.fields.figure }}</span>
|
||||
</h5>
|
||||
<div>
|
||||
<a href="{{ url_for('minifigure.details', figure=item.fields.figure) }}" class="btn btn-sm btn-secondary">
|
||||
<i class="ri-arrow-left-line"></i> Back to {{ item.fields.figure }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-img border-bottom" style="background-image: url({{ item.url_for_image() }})">
|
||||
<a data-lightbox data-caption="{{ item.fields.name }}" href="{{ item.url_for_image() }}" target="_blank">
|
||||
<img class="card-medium-img" src="{{ item.url_for_image() }}" alt="{{ item.fields.figure }}" loading="lazy">
|
||||
</a>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form id="individual-minifigure-form" method="POST" action="{{ url_for('individual_minifigure.update', id=item.fields.id) }}">
|
||||
<div class="mb-3">
|
||||
<label for="quantity" class="form-label">Quantity</label>
|
||||
<input type="number" class="form-control" id="quantity" name="quantity" value="{{ item.fields.quantity }}" min="1" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Description</label>
|
||||
<textarea class="form-control" id="description" name="description" rows="3">{{ item.fields.description or '' }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="storage" class="form-label">Storage</label>
|
||||
<select class="form-select" id="storage" name="storage">
|
||||
<option value="">None</option>
|
||||
{% for storage in brickset_storages %}
|
||||
<option value="{{ storage.fields.id }}" {% if item.fields.storage == storage.fields.id %}selected{% endif %}>
|
||||
{{ storage.fields.name }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="purchase_location" class="form-label">Purchase Location</label>
|
||||
<select class="form-select" id="purchase_location" name="purchase_location">
|
||||
<option value="">None</option>
|
||||
{% for location in brickset_purchase_locations %}
|
||||
<option value="{{ location.fields.id }}" {% if item.fields.purchase_location == location.fields.id %}selected{% endif %}>
|
||||
{{ location.fields.name }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Owners</label>
|
||||
{% for owner in brickset_owners %}
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="owners" value="{{ owner.fields.id }}" id="owner-{{ owner.fields.id }}"
|
||||
{% if owner.has_individual_minifigure(item) %}checked{% endif %}>
|
||||
<label class="form-check-label" for="owner-{{ owner.fields.id }}">
|
||||
{{ owner.fields.name }}
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Tags</label>
|
||||
{% for tag in brickset_tags %}
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="tags" value="{{ tag.fields.id }}" id="tag-{{ tag.fields.id }}"
|
||||
{% if tag.has_individual_minifigure(item) %}checked{% endif %}>
|
||||
<label class="form-check-label" for="tag-{{ tag.fields.id }}">
|
||||
{{ tag.fields.name }}
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="ri-save-line"></i> Save Changes
|
||||
</button>
|
||||
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal">
|
||||
<i class="ri-delete-bin-line"></i> Delete Instance
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete Confirmation Modal -->
|
||||
<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="deleteModalLabel">Confirm Delete</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Are you sure you want to delete this individual minifigure instance? This action cannot be undone.
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<form method="POST" action="{{ url_for('individual_minifigure.delete', id=item.fields.id) }}">
|
||||
<button type="submit" class="btn btn-danger">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,4 +1,4 @@
|
||||
{% macro header(image=true, color=false, parts=false, quantity=false, missing=true, missing_parts=false, damaged=true, damaged_parts=false, sets=false, minifigures=false, checked=false, hamburger_menu=false, accordion_id='') %}
|
||||
{% macro header(image=true, color=false, parts=false, quantity=false, missing=true, missing_parts=false, damaged=true, damaged_parts=false, sets=false, individual=false, minifigures=false, checked=false, hamburger_menu=false, accordion_id='') %}
|
||||
<thead>
|
||||
<tr>
|
||||
{% if image %}
|
||||
@@ -23,6 +23,9 @@
|
||||
{% if sets %}
|
||||
<th data-table-number="true" scope="col"><i class="ri-hashtag fw-normal"></i> Sets</th>
|
||||
{% endif %}
|
||||
{% if individual %}
|
||||
<th data-table-number="true" scope="col"><i class="ri-package-line fw-normal"></i> Individual</th>
|
||||
{% endif %}
|
||||
{% if minifigures %}
|
||||
<th data-table-number="true" scope="col"><i class="ri-group-line fw-normal"></i> Minifigures</th>
|
||||
{% endif %}
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
<div class="accordion accordion-flush" id="minifigure-details">
|
||||
{{ accordion.table(item.generic_parts(), 'Parts', item.fields.figure, 'minifigure-details', 'part/table.html', icon='shapes-line', alt=item.fields.figure, read_only=read_only)}}
|
||||
{{ accordion.cards(using, 'Sets using this minifigure', 'using-inventory', 'minifigure-details', 'set/card.html', icon='hashtag') }}
|
||||
{% if individual_instances is defined and individual_instances | length > 0 %}
|
||||
{{ accordion.cards(individual_instances, 'Individual minifigure instances', 'individual-instances', 'minifigure-details', 'individual_minifigure/card.html', icon='package-line') }}
|
||||
{% endif %}
|
||||
{{ accordion.cards(missing, 'Sets missing parts for this minifigure', 'missing-inventory', 'minifigure-details', 'set/card.html', icon='question-line') }}
|
||||
{{ accordion.cards(damaged, 'Sets with damaged parts for this minifigure', 'damaged-inventory', 'minifigure-details', 'set/card.html', icon='error-warning-line') }}
|
||||
</div>
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<td data-sort="{{ minifigure.fields.total_damaged }}">{{ minifigure.fields.total_damaged }}</td>
|
||||
{% endif %}
|
||||
<td data-sort="{{ minifigure.fields.total_sets }}">{{ minifigure.fields.total_sets }}</td>
|
||||
<td data-sort="{{ minifigure.fields.total_individual }}">{{ minifigure.fields.total_individual }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -33,7 +33,7 @@
|
||||
<!-- PAGINATION MODE -->
|
||||
<div class="table-responsive-sm">
|
||||
<table data-table="false" class="table table-striped align-middle mb-0" id="minifigures">
|
||||
{{ table.header(parts=true, quantity=true, missing=true, damaged=true, sets=true, minifigures=false) }}
|
||||
{{ table.header(parts=true, quantity=true, missing=true, damaged=true, sets=true, individual=true, minifigures=false) }}
|
||||
{% include 'minifigure/table_body.html' %}
|
||||
</table>
|
||||
</div>
|
||||
@@ -148,7 +148,7 @@
|
||||
<!-- ORIGINAL MODE - Single page with client-side search -->
|
||||
<div class="table-responsive-sm">
|
||||
<table data-table="true" class="table table-striped align-middle {% if not all %}sortable mb-0{% endif %}" id="minifigures">
|
||||
{{ table.header(parts=true, quantity=true, missing=true, damaged=true, sets=true, minifigures=false) }}
|
||||
{{ table.header(parts=true, quantity=true, missing=true, damaged=true, sets=true, individual=true, minifigures=false) }}
|
||||
<tbody>
|
||||
{% for minifigure in table_collection %}
|
||||
<tr>
|
||||
@@ -166,6 +166,7 @@
|
||||
<td data-sort="{{ minifigure.fields.total_damaged }}">{{ minifigure.fields.total_damaged }}</td>
|
||||
{% endif %}
|
||||
<td data-sort="{{ minifigure.fields.total_sets }}">{{ minifigure.fields.total_sets }}</td>
|
||||
<td data-sort="{{ minifigure.fields.total_individual }}">{{ minifigure.fields.total_individual }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user