From eac9fc179345925ec795b9da782281e861aca777 Mon Sep 17 00:00:00 2001
From: Gregoo <versatile.mailbox@gmail.com>
Date: Mon, 3 Feb 2025 09:52:33 +0100
Subject: [PATCH] Allow hiding the damaged and missing columns from the parts
 table

---
 .env.sample                | 10 +++++++++-
 CHANGELOG.md               |  8 +++++++-
 bricktracker/config.py     |  4 +++-
 bricktracker/navbar.py     |  2 +-
 templates/macro/table.html |  6 +++++-
 templates/part/table.html  | 16 ++++++++++------
 6 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/.env.sample b/.env.sample
index fb52132..0bfc3f0 100644
--- a/.env.sample
+++ b/.env.sample
@@ -110,12 +110,20 @@
 # Optional: Hide the 'Problems' entry from the menu. Does not disable the route.
 # Default: false
 # Legacy name: BK_HIDE_MISSING_PARTS
-# BK_HIDE_PROBLEMS_PARTS=true
+# BK_HIDE_ALL_PROBLEMS_PARTS=true
 
 # Optional: Hide the 'Instructions' entry in a Set card
 # Default: false
 # BK_HIDE_SET_INSTRUCTIONS=true
 
+# Optional: Hide the 'Damaged' column from the parts table.
+# Default: false
+# BK_HIDE_TABLE_DAMAGED_PARTS=true
+
+# Optional: Hide the 'Missing' column from the parts table.
+# Default: false
+# BK_HIDE_TABLE_MISSING_PARTS=true
+
 # Optional: Hide the 'Wishlist' entry from the menu. Does not disable the route.
 # Default: false
 # BK_HIDE_WISHES=true
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6a7379e..28a7f0f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,13 @@
 > "Missing" part has been renamed to "Problems" to accomodate for missing and damaged parts.
 > The associated environment variables have changed named (the old names are still valid)
 
-## Code
+### Environment
+
+- Renamed: `BK_HIDE_MISSING_PARTS` -> `BK_HIDE_ALL_PROBLEMS_PARTS`
+- Added: `BK_HIDE_TABLE_MISSING_PARTS`, hide the Missing column in all tables
+- Added: `BK_HIDE_TABLE_DAMAGED_PARTS`, hide the Damaged column in all tables
+
+### Code
 
 - Form
     - Migrate missing input fields to BrickChanger
diff --git a/bricktracker/config.py b/bricktracker/config.py
index 8ab193a..62e23a1 100644
--- a/bricktracker/config.py
+++ b/bricktracker/config.py
@@ -29,8 +29,10 @@ CONFIG: Final[list[dict[str, Any]]] = [
     {'n': 'HIDE_ALL_MINIFIGURES', 'c': bool},
     {'n': 'HIDE_ALL_PARTS', 'c': bool},
     {'n': 'HIDE_ALL_SETS', 'c': bool},
-    {'n': 'HIDE_PROBLEMS_PARTS', 'e': 'BK_HIDE_MISSING_PARTS', 'c': bool},
+    {'n': 'HIDE_ALL_PROBLEMS_PARTS', 'e': 'BK_HIDE_MISSING_PARTS', 'c': bool},
     {'n': 'HIDE_SET_INSTRUCTIONS', 'c': bool},
+    {'n': 'HIDE_TABLE_DAMAGED_PARTS', 'c': bool},
+    {'n': 'HIDE_TABLE_MISSING_PARTS', 'c': bool},
     {'n': 'HIDE_WISHES', 'c': bool},
     {'n': 'MINIFIGURES_DEFAULT_ORDER', 'd': '"rebrickable_minifigures"."name" ASC'},  # noqa: E501
     {'n': 'MINIFIGURES_FOLDER', 'd': 'minifigs', 's': True},
diff --git a/bricktracker/navbar.py b/bricktracker/navbar.py
index 04b7053..30007de 100644
--- a/bricktracker/navbar.py
+++ b/bricktracker/navbar.py
@@ -11,7 +11,7 @@ NAVBAR: Final[list[dict[str, Any]]] = [
     {'e': 'set.list', 't': 'Sets', 'i': 'grid-line', 'f': 'HIDE_ALL_SETS'},  # noqa: E501
     {'e': 'add.add', 't': 'Add', 'i': 'add-circle-line', 'f': 'HIDE_ADD_SET'},  # noqa: E501
     {'e': 'part.list', 't': 'Parts', 'i': 'shapes-line', 'f': 'HIDE_ALL_PARTS'},  # noqa: E501
-    {'e': 'part.problem', 't': 'Problems', 'i': 'error-warning-line', 'f': 'HIDE_PROBLEMS_PARTS'},  # noqa: E501
+    {'e': 'part.problem', 't': 'Problems', 'i': 'error-warning-line', 'f': 'HIDE_ALL_PROBLEMS_PARTS'},  # noqa: E501
     {'e': 'minifigure.list', 't': 'Minifigures', 'i': 'group-line', 'f': 'HIDE_ALL_MINIFIGURES'},  # noqa: E501
     {'e': 'instructions.list', 't': 'Instructions', 'i': 'file-line', 'f': 'HIDE_ALL_INSTRUCTIONS'},  # noqa: E501
     {'e': 'wish.list', 't': 'Wishlist', 'i': 'gift-line', 'f': 'HIDE_WISHES'},
diff --git a/templates/macro/table.html b/templates/macro/table.html
index 8db1dda..d31e1c2 100644
--- a/templates/macro/table.html
+++ b/templates/macro/table.html
@@ -9,8 +9,12 @@
       {% if quantity %}
         <th data-table-number="true" scope="col"><i class="ri-functions fw-normal"></i> Quantity</th>
       {% endif %}
-      <th data-table-number="true" scope="col"><i class="ri-question-line fw-normal"></i> Missing{% if missing_parts %} parts{% endif %}</th>
+      {% if not config['HIDE_TABLE_MISSING_PARTS'] %}
+        <th data-table-number="true" scope="col"><i class="ri-question-line fw-normal"></i> Missing{% if missing_parts %} parts{% endif %}</th>
+      {% endif %}
+      {% if not config['HIDE_TABLE_DAMAGED_PARTS'] %}
       <th data-table-number="true" scope="col"><i class="ri-error-warning-line fw-normal"></i> Damaged{% if damaged_parts %} parts{% endif %}</th>
+      {% endif %}
       {% if sets %}
         <th data-table-number="true" scope="col"><i class="ri-hashtag fw-normal"></i> Sets</th>
       {% endif %}
diff --git a/templates/part/table.html b/templates/part/table.html
index ac96af5..d2f6569 100644
--- a/templates/part/table.html
+++ b/templates/part/table.html
@@ -27,12 +27,16 @@
             <td>{% if quantity %}{{ item.fields.quantity * quantity }}{% else %}{{ item.fields.quantity }}{% endif %}</td>
           {% endif %}
         {% endif %}
-        <td data-sort="{{ item.fields.total_missing }}" class="table-td-input">
-          {{ form.input('Missing', item.fields.id, item.html_id('missing'), item.url_for_problem('missing'), item.fields.total_missing, all=all, read_only=read_only) }}
-        </td>
-        <td data-sort="{{ item.fields.total_damaged }}" class="table-td-input">
-          {{ form.input('Damaged', item.fields.id, item.html_id('damaged'), item.url_for_problem('damaged'), item.fields.total_damaged, all=all, read_only=read_only) }}
-        </td>
+        {% if not config['HIDE_TABLE_MISSING_PARTS'] %}
+          <td data-sort="{{ item.fields.total_missing }}" class="table-td-input">
+            {{ form.input('Missing', item.fields.id, item.html_id('missing'), item.url_for_problem('missing'), item.fields.total_missing, all=all, read_only=read_only) }}
+          </td>
+        {% endif %}
+        {% if not config['HIDE_TABLE_DAMAGED_PARTS'] %}
+          <td data-sort="{{ item.fields.total_damaged }}" class="table-td-input">
+            {{ form.input('Damaged', item.fields.id, item.html_id('damaged'), item.url_for_problem('damaged'), item.fields.total_damaged, all=all, read_only=read_only) }}
+          </td>
+        {% endif %}
         {% if all %}
           <td>{{ item.fields.total_sets }}</td>
           <td>{{ item.fields.total_minifigures }}</td>