Saving multiple sets works

This commit is contained in:
FrederikBaerentsen 2024-02-29 13:30:25 -05:00
parent 88898e0361
commit 2e2eab7d6f
3 changed files with 92 additions and 19 deletions

3
app.py
View File

@ -22,6 +22,7 @@ def index():
def save_number():
data1 = request.form.get('brick.part.part_num')
data2 = request.form.get('brick.color.name')
data3 = request.form.get('index')
number = request.form.get('numberInput')
if number is not None:
@ -36,7 +37,7 @@ def save_number():
data = '{"brick" : {"ID":"' + data1 + '","color_name": "' + data2 + '","amount":"' + number + '"}}'
json_file['unit'][0]['bricks']['missing'].append(json.loads(data))
json_file['unit'][int(data3)]['bricks']['missing'].append(json.loads(data))
with open('./info/'+tmp+'.json', 'w') as dump_file:
json.dump(json_file,dump_file)

View File

@ -1,6 +1,6 @@
body {
font-family: Arial, sans-serif;
margin: 20px;
margin: 10px;
}
h1 {
@ -32,3 +32,72 @@ button:hover {
background-color: #0056b3;
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}
/* Add Animation */
@-webkit-keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
@keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal-header {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
}
.modal-body {padding: 2px 16px;}
.modal-footer {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
}

View File

@ -13,7 +13,7 @@
<th>qty</th>
<th>is_spare</th>
{% for i in json_file['unit'] %}
<th>Missing?</th>
<th>Missing ({{ loop.index }})</th>
{% endfor %}
</tr>
</thead>
@ -28,24 +28,27 @@
<td>{{ brick.color.name }}</td>
<td>{{ brick.quantity }}</td>
<td>{{ brick.is_spare }}</td>
{% for i in json_file['unit'] %}
<td>
{% set ns = namespace(count='') %}
<form action="/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="brick.color.name" value="{{ brick.color.name }}">
{% for j in i['bricks']['missing'] %}
{% if j['brick']['ID'] == brick.part.part_num and j['brick']['color_name'] == brick.color.name %}
{% set ns.count = j['brick']['amount'] %}
{% endif %}
{% endfor %}
<input type="text" style="height:auto;width:20px" id="numberInput" name="numberInput" value={{ ns.count }}><button type="submit"><i class="fa fa-save"></i></button>
</form>
</td>
{% endfor %}
{% for i in json_file['unit'] %}
<td>
{% set ns = namespace(count='') %}
<form action="/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="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 %}
{% 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>
{% endfor %}
</tbody>
</table>
{% endblock %}