mirror of
https://gitea.baerentsen.space/FrederikBaerentsen/BrickTracker.git
synced 2025-12-30 13:19:59 -06:00
feat(minifigures): fixed owner filter on parts page
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
|
||||
{% block total_missing %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."missing" ELSE 0 END) AS "total_missing",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."missing"
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."missing"
|
||||
ELSE 0
|
||||
END) AS "total_missing",
|
||||
{% else %}
|
||||
SUM("combined"."missing") AS "total_missing",
|
||||
{% endif %}
|
||||
@@ -10,7 +14,11 @@ SUM("combined"."missing") AS "total_missing",
|
||||
|
||||
{% block total_damaged %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."damaged" ELSE 0 END) AS "total_damaged",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."damaged"
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."damaged"
|
||||
ELSE 0
|
||||
END) AS "total_damaged",
|
||||
{% else %}
|
||||
SUM("combined"."damaged") AS "total_damaged",
|
||||
{% endif %}
|
||||
@@ -18,47 +26,79 @@ SUM("combined"."damaged") AS "total_damaged",
|
||||
|
||||
{% block total_quantity %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1) ELSE 0 END) AS "total_quantity",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."quantity"
|
||||
ELSE 0
|
||||
END) AS "total_quantity",
|
||||
{% else %}
|
||||
SUM("combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)) AS "total_quantity",
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' THEN "combined"."quantity" * IFNULL("bricktracker_minifigures"."quantity", 1)
|
||||
ELSE "combined"."quantity"
|
||||
END) AS "total_quantity",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_sets %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
COUNT(DISTINCT CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."id" ELSE NULL END) AS "total_sets",
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN "combined"."id"
|
||||
ELSE NULL
|
||||
END) AS "total_sets",
|
||||
{% else %}
|
||||
COUNT(DISTINCT "combined"."id") AS "total_sets",
|
||||
COUNT(DISTINCT CASE WHEN "combined"."source_type" = 'set' THEN "combined"."id" ELSE NULL END) AS "total_sets",
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block total_minifigures %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
SUM(CASE WHEN "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN IFNULL("bricktracker_minifigures"."quantity", 0) ELSE 0 END) AS "total_minifigures"
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' AND "bricktracker_set_owners"."owner_{{ owner_id }}" = 1 THEN IFNULL("bricktracker_minifigures"."quantity", 0)
|
||||
WHEN "combined"."source_type" = 'individual' AND "bricktracker_individual_minifigure_owners"."owner_{{ owner_id }}" = 1 THEN 1
|
||||
ELSE 0
|
||||
END) AS "total_minifigures"
|
||||
{% else %}
|
||||
SUM(IFNULL("bricktracker_minifigures"."quantity", 0)) AS "total_minifigures"
|
||||
SUM(CASE
|
||||
WHEN "combined"."source_type" = 'set' THEN IFNULL("bricktracker_minifigures"."quantity", 0)
|
||||
WHEN "combined"."source_type" = 'individual' THEN 1
|
||||
ELSE 0
|
||||
END) AS "total_minifigures"
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block join %}
|
||||
-- Join with sets to get owner information
|
||||
INNER JOIN "bricktracker_sets"
|
||||
ON "combined"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
-- Left join with sets (for set-based parts)
|
||||
LEFT JOIN "bricktracker_sets"
|
||||
ON "combined"."source_type" = 'set'
|
||||
AND "combined"."id" IS NOT DISTINCT FROM "bricktracker_sets"."id"
|
||||
|
||||
-- Left join with set owners (using dynamic columns)
|
||||
LEFT JOIN "bricktracker_set_owners"
|
||||
ON "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
ON "combined"."source_type" = 'set'
|
||||
AND "bricktracker_sets"."id" IS NOT DISTINCT FROM "bricktracker_set_owners"."id"
|
||||
|
||||
-- Left join with minifigures
|
||||
-- Left join with set-based minifigures
|
||||
LEFT JOIN "bricktracker_minifigures"
|
||||
ON "combined"."id" IS NOT DISTINCT FROM "bricktracker_minifigures"."id"
|
||||
ON "combined"."source_type" = 'set'
|
||||
AND "combined"."id" IS NOT DISTINCT FROM "bricktracker_minifigures"."id"
|
||||
AND "combined"."figure" IS NOT DISTINCT FROM "bricktracker_minifigures"."figure"
|
||||
|
||||
-- Left join with individual minifigures (for individual parts)
|
||||
LEFT JOIN "bricktracker_individual_minifigures"
|
||||
ON "combined"."source_type" = 'individual'
|
||||
AND "combined"."id" IS NOT DISTINCT FROM "bricktracker_individual_minifigures"."id"
|
||||
|
||||
-- Left join with individual minifigure owners (using dynamic columns)
|
||||
LEFT JOIN "bricktracker_individual_minifigure_owners"
|
||||
ON "combined"."source_type" = 'individual'
|
||||
AND "bricktracker_individual_minifigures"."id" IS NOT DISTINCT FROM "bricktracker_individual_minifigure_owners"."id"
|
||||
{% endblock %}
|
||||
|
||||
{% block where %}
|
||||
{% set conditions = [] %}
|
||||
{% if owner_id and owner_id != 'all' %}
|
||||
{% set _ = conditions.append('"bricktracker_set_owners"."owner_' ~ owner_id ~ '" = 1') %}
|
||||
{% set owner_condition = '(("combined"."source_type" = \'set\' AND "bricktracker_set_owners"."owner_' ~ owner_id ~ '" = 1) OR ("combined"."source_type" = \'individual\' AND "bricktracker_individual_minifigure_owners"."owner_' ~ owner_id ~ '" = 1))' %}
|
||||
{% set _ = conditions.append(owner_condition) %}
|
||||
{% endif %}
|
||||
{% if color_id and color_id != 'all' %}
|
||||
{% set _ = conditions.append('"combined"."color" = ' ~ color_id) %}
|
||||
|
||||
Reference in New Issue
Block a user