From a23205060c515b4f358b445cff81d7ede94f8e41 Mon Sep 17 00:00:00 2001
From: FrederikBaerentsen <frederik+gitea@baerentsen.net>
Date: Mon, 4 Mar 2024 14:10:56 -0500
Subject: [PATCH] Fixed a bug where it was already index 0 that was popped from
 the missing bricks list

---
 app.py                         |  2 +-
 templates/bootstrap_table.html | 84 ++++++++++++++++++++--------------
 2 files changed, 50 insertions(+), 36 deletions(-)

diff --git a/app.py b/app.py
index 581ba32..ea24953 100644
--- a/app.py
+++ b/app.py
@@ -58,7 +58,7 @@ def save_number(tmp):
         elif number == '0':
             for idx,i in enumerate(json_file['unit'][int(index)]['bricks']['missing']):
                 if i['brick']['ID'] == part_num and i['brick']['is_spare'] == is_spare and i['brick']['color_name'] == color:
-                    json_file['unit'][int(index)]['bricks']['missing'].pop(0)
+                    json_file['unit'][int(index)]['bricks']['missing'].pop(idx)
         else:
             found = False
             
diff --git a/templates/bootstrap_table.html b/templates/bootstrap_table.html
index 4bce6d6..b190785 100644
--- a/templates/bootstrap_table.html
+++ b/templates/bootstrap_table.html
@@ -67,17 +67,17 @@
 </div>
 
   <h1>Spares</h1>
-  <table id="data" class="table table-striped">
+<div class="center-table">
+<table id="data" class="table">
     <thead>
       <tr>
-        <th>img</th>
-        <th>element_id</th>
-        <th>part_num</th>
-        <th>name</th>
-        <th>color</th>
-        <th>qty</th>
+        <th></th>
+        <th style="text-align:center;margin:0px;" class="fixed-width hidden-mobile">ID</th>
+        <th class="fixed-width hidden-mobile">Name</th>
+        <th class="fixed-width">Color</th>
+        <th style="text-align: center;" class="fixed-width">Qty</th>
         {% for i in json_file['unit'] %}
-	<th>Missing ({{ loop.index }})</th>
+    <th style="text-align: center;" class="fixed-width">Missing ({{ loop.index }})</th>
         {% endfor %}
       </tr>
     </thead>
@@ -85,41 +85,55 @@
       {% for brick in inventory_file.results %}
       {% if brick.is_spare == True %}
         <tr>
-	  {% if brick.element_id == None %}
-	  <td><img src="{{ '/static/none.jpg' }}" style="height: 50px; width: auto;"></td>
-	  {% else %}
-	  <td><img src="{{ '/static/parts/' + brick.element_id + '.jpg' }}" style="height: 50px; width: auto;"></td>
-	  {% endif %}
-          <td>{{ brick.element_id }}</td>
-          <td>{{ brick.part.part_num }}</td>
-          <td>{{ brick.part.name }}</td>
+    {% if brick.element_id == None %}
+    <td><img src="{{ '/static/none.jpg' }}" class="lightbox-trigger" style="height: 50px; width: auto;"></td>
+    {% else %}
+    <td><img src="{{ '/static/parts/' + brick.element_id + '.jpg' }}" class="lightbox-trigger" style="height: 50px; width: auto;"></td>
+    {% endif %}
+          <td  style="text-align:center;margin:0px;" class="hidden-mobile">{{ brick.part.part_num }}</td>
+          <td class="hidden-mobile">{{ brick.part.name }}</td>
           <td>{{ brick.color.name }}</td>
-          <td>{{ brick.quantity }}</td>
-    	  {% for i in json_file['unit'] %}
+          <td style="text-align:center;">{{ brick.quantity }}</td>
+        {% for i in json_file['unit'] %}
         
-    		  <td>
-    			{% set ns = namespace(count='') %}
-			<form action="/{{ tmp }}/saveNumber" method="post">
-    			<input type="hidden" name="brick.part.part_num" value="{{ brick.part.part_num }}">
-    			<input type="hidden" name="count" value="{{ i }}">
+          <td class="centered-cell">
+      <div class="inputContainer">
+          {% set ns = namespace(count='') %}
+      <form id="number-form" action="/{{ tmp }}/saveNumber" method="post">
+          <input type="hidden" name="brick.part.part_num" value="{{ brick.part.part_num }}">
+          <input type="hidden" name="count" value="{{ i }}">
           <input type="hidden" name="index" value="{{ loop.index0 }}">
           <input type="hidden" name="is_spare" value="{{ brick.is_spare }}">
-    			<input type="hidden" name="brick.color.name" value="{{ brick.color.name }}">
-    			{% for j in json_file['unit'][loop.index0]['bricks']['missing'] %}
-    			  {% if j['brick']['ID'] == brick.part.part_num and j['brick']['color_name'] == brick.color.name and j['brick']['is_spare']|lower == brick.is_spare|lower %}
-    			    {% set ns.count = j['brick']['amount'] %}
-    			  {% endif %}
-    			{% endfor %}
-    			<input type="text" style="height:auto;width:40px" id="numberInput" name="numberInput" value={{ ns.count }}><button type="submit"><i class="fa fa-save"></i></button>
-    		      </form>
-    		  </td>
-    	  {% endfor %}
-        </tr>
-	{% endif %}
+          <input type="hidden" name="brick.color.name" value="{{ brick.color.name }}">
+          {% for j in json_file['unit'][loop.index0]['bricks']['missing'] %}
+            {% if j['brick']['ID'] == brick.part.part_num and j['brick']['color_name'] == brick.color.name %}
 
+        {% if j['brick']['is_spare']|lower == brick.is_spare|lower %} 
+
+              {% set ns.count = j['brick']['amount'] %}
+          {% endif %} 
+            {% endif %}
+          {% endfor %}
+      <div class='inputField'>
+  <input type="number" style="text-align:center;" id="numberInput" name="numberInput" value="{{ ns.count }}" pattern="\d+" required>
+  <button class="square-button" type="submit">
+    <img src="/static/save.svg" alt="Save Icon">
+  </button>
+      </div>
+              </form>
+      </div>
+          </td>
+        {% endfor %}
+        </tr>
+  {% endif %}
       {% endfor %}
     </tbody>
   </table>
+</div>
+
+
+
+
 
 
 <div id="lightbox-modal">