From 6262ac7889d7343b2d59f5a805c3c3860d1f4337 Mon Sep 17 00:00:00 2001 From: Gregoo Date: Fri, 31 Jan 2025 14:46:50 +0100 Subject: [PATCH] Use badge macros in the card header --- bricktracker/rebrickable_part.py | 13 ++++++++----- templates/macro/badge.html | 23 +++++++++++++++++++++-- templates/macro/card.html | 16 +++++----------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/bricktracker/rebrickable_part.py b/bricktracker/rebrickable_part.py index eea6d08..8fdd3cb 100644 --- a/bricktracker/rebrickable_part.py +++ b/bricktracker/rebrickable_part.py @@ -119,11 +119,14 @@ class RebrickablePart(BrickRecord): # Compute the url for the original of the printed part def url_for_print(self, /) -> str: - return url_for( - 'part.details', - part=self.fields.print, - color=self.fields.color, - ) + if self.fields.print is not None: + return url_for( + 'part.details', + part=self.fields.print, + color=self.fields.color, + ) + else: + return '' # Compute the url for the rebrickable page def url_for_rebrickable(self, /) -> str: diff --git a/templates/macro/badge.html b/templates/macro/badge.html index 70b10f1..722a357 100644 --- a/templates/macro/badge.html +++ b/templates/macro/badge.html @@ -1,14 +1,15 @@ -{% macro badge(check=none, url=none, solo=false, last=false, color='primary', blank=none, icon=none, alt=none, collapsible=none, text=none, tooltip=none) %} +{% macro badge(check=none, url=none, solo=false, last=false, header=false, color='primary', rgb=none, blank=none, icon=none, alt=none, collapsible=none, text=none, tooltip=none) %} {% if check or url %} {% if url %} {% if icon %}{% endif %} + {% if rgb %}{% endif %} {% if collapsible and not last %} {{ collapsible }} {% endif %} {% if text %}{{ text }}{% endif %} {% if url %} @@ -23,6 +24,20 @@ {{ badge(url=item.url_for_bricklink(), solo=solo, last=last, blank=true, color='light border', icon='external-link-line', collapsible='Bricklink', alt='Bricklink') }} {% endmacro %} +{% macro color(item, icon=none, solo=false, last=false, header=false) %} + {% if item.fields.color == 9999 %} + {% set rgb = 'any' %} + {% else %} + {% set rgb = item.fields.color_rgb %} + {% endif %} + {{ badge(check=item.fields.color_name, solo=solo, last=last, header=header, color=' bg-white text-black border', rgb=rgb, icon='palette-line', collapsible=item.fields.color_name) }} + {{ badge(check=item.fields.color_transparent, solo=solo, last=last, header=header, color='light border', icon='blur-off-line', collapsible='Transparent') }} +{% endmacro %} + +{% macro identifier(id, icon=none, solo=false, last=false, header=false) %} + {{ badge(check=id, solo=solo, last=last, header=header, color='secondary', icon=icon, text=id) }} +{% endmacro %} + {% macro instructions(item, solo=false, last=false) %} {{ badge(url=item.url_for_instructions(), solo=solo, last=last, blank=true, color='light border', icon='file-line', collapsible='Instructions:', text=item.instructions | length, alt='Instructions') }} {% endmacro %} @@ -35,6 +50,10 @@ {{ badge(check=quantity, solo=solo, last=last, color='success', icon='close-line', collapsible='Quantity:', text=quantity, alt='Quantity') }} {% endmacro %} +{% macro print(item, solo=false, last=false, header=false) %} + {{ badge(url=item.url_for_print(), solo=solo, last=last, color='light border', icon='paint-brush-line', collapsible='Print') }} +{% endmacro %} + {% macro set(set, solo=false, last=false, url=None, id=None) %} {% if id %} {% set url=url_for('set.details', id=id) %} diff --git a/templates/macro/card.html b/templates/macro/card.html index ae8bce0..be6ad74 100644 --- a/templates/macro/card.html +++ b/templates/macro/card.html @@ -1,21 +1,15 @@ +{% import 'macro/badge.html' as badge %} + {% macro header(item, name, solo=false, identifier=none, icon='hashtag') %}
{% if not solo %} {% endif %}
- {% if identifier %}{{ identifier }}{% endif %} + {{ badge.identifier(identifier, icon=icon, solo=solo, header=true) }} {% if solo %} - {% if item.fields.color_name %} - - {% if item.fields.color_rgb %} - - {% endif %} - {{ item.fields.color_name }} - - {% endif %} - {% if item.fields.color_transparent %} Transparent{% endif %} - {% if item.fields.print %} Print{% endif %} + {{ badge.color(item, header=true) }} + {{ badge.print(item, header=true) }} {% endif %} {{ name }}