Fixed removing entry if missing is 0
This commit is contained in:
parent
a8cc82f7cb
commit
172e371656
28
app.py
28
app.py
@ -1,4 +1,4 @@
|
|||||||
from flask import Flask, request, jsonify, render_template
|
from flask import Flask, request, redirect, jsonify, render_template
|
||||||
import json
|
import json
|
||||||
from pprint import pprint as pp
|
from pprint import pprint as pp
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -54,17 +54,33 @@ def save_number(tmp):
|
|||||||
|
|
||||||
data = '{"brick" : {"ID":"' + part_num + '","is_spare": "' + is_spare + '","color_name": "' + color + '","amount":"' + number + '"}}'
|
data = '{"brick" : {"ID":"' + part_num + '","is_spare": "' + is_spare + '","color_name": "' + color + '","amount":"' + number + '"}}'
|
||||||
|
|
||||||
for i in json_file['unit'][int(index)]['bricks']['missing']:
|
if len(json_file['unit'][int(index)]['bricks']['missing']) == 0:
|
||||||
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'].append(json.loads(data))
|
||||||
print(i)
|
print(json_file)
|
||||||
|
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)
|
||||||
|
else:
|
||||||
|
found = False
|
||||||
|
|
||||||
|
for idx,i in enumerate(json_file['unit'][int(index)]['bricks']['missing']):
|
||||||
|
if not found and i['brick']['ID'] == part_num and i['brick']['is_spare'] == is_spare and i['brick']['color_name'] == color:
|
||||||
|
print('found one ')
|
||||||
|
print(part_num,i['brick']['ID'])
|
||||||
|
print(is_spare,i['brick']['is_spare'])
|
||||||
|
print(color,i['brick']['color_name'])
|
||||||
|
|
||||||
json_file['unit'][int(index)]['bricks']['missing'].append(json.loads(data))
|
json_file['unit'][int(index)]['bricks']['missing'][idx]['brick']['amount'] = number
|
||||||
|
found = True
|
||||||
|
if not found:
|
||||||
|
json_file['unit'][int(index)]['bricks']['missing'].append(json.loads(data))
|
||||||
|
|
||||||
if not number == '':
|
if not number == '':
|
||||||
with open('./info/'+tmp+'.json', 'w') as dump_file:
|
with open('./info/'+tmp+'.json', 'w') as dump_file:
|
||||||
json.dump(json_file,dump_file)
|
json.dump(json_file,dump_file)
|
||||||
|
|
||||||
return ('', 204)
|
return redirect('/{}'.format(tmp))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='192.168.10.109', debug=True, port=3333)
|
app.run(host='192.168.10.109', debug=True, port=3333)
|
||||||
|
@ -9,4 +9,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -193,6 +193,17 @@ td img{
|
|||||||
max-height: 90%;
|
max-height: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Chrome, Safari, Edge, Opera */
|
||||||
|
input::-webkit-outer-spin-button,
|
||||||
|
input::-webkit-inner-spin-button {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Firefox */
|
||||||
|
input[type=number] {
|
||||||
|
-moz-appearance: textfield;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
{% if brick.is_spare == False %}
|
{% if brick.is_spare == False %}
|
||||||
<tr>
|
<tr>
|
||||||
{% if brick.element_id == None %}
|
{% if brick.element_id == None %}
|
||||||
<td><img src="{{ '/static/none.jpg' }}" style="height: 50px; width: auto;"></td>
|
<td><img src="{{ '/static/none.jpg' }}" class="lightbox-trigger" style="height: 50px; width: auto;"></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><img src="{{ '/static/parts/' + brick.element_id + '.jpg' }}" class="lightbox-trigger" style="height: 50px; width: auto;"></td>
|
<td><img src="{{ '/static/parts/' + brick.element_id + '.jpg' }}" class="lightbox-trigger" style="height: 50px; width: auto;"></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -34,7 +34,7 @@
|
|||||||
<td class="centered-cell">
|
<td class="centered-cell">
|
||||||
<div class="inputContainer">
|
<div class="inputContainer">
|
||||||
{% set ns = namespace(count='') %}
|
{% set ns = namespace(count='') %}
|
||||||
<form action="/{{ tmp }}/saveNumber" method="post">
|
<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="brick.part.part_num" value="{{ brick.part.part_num }}">
|
||||||
<input type="hidden" name="count" value="{{ i }}">
|
<input type="hidden" name="count" value="{{ i }}">
|
||||||
<input type="hidden" name="index" value="{{ loop.index0 }}">
|
<input type="hidden" name="index" value="{{ loop.index0 }}">
|
||||||
@ -50,7 +50,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<div class='inputField'>
|
<div class='inputField'>
|
||||||
<input type="text" id="numberInput" name="numberInput" value={{ ns.count }}>
|
<input type="number" style="text-align:center;" id="numberInput" name="numberInput" value="{{ ns.count }}" pattern="\d+" required>
|
||||||
<button class="square-button" type="submit">
|
<button class="square-button" type="submit">
|
||||||
<img src="/static/save.svg" alt="Save Icon">
|
<img src="/static/save.svg" alt="Save Icon">
|
||||||
</button>
|
</button>
|
||||||
@ -196,6 +196,19 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
const numberInput = document.getElementById('numberInput');
|
||||||
|
|
||||||
|
// Add event listener to input to prevent non-numeric input
|
||||||
|
numberInput.addEventListener('input', function () {
|
||||||
|
// Remove non-numeric characters
|
||||||
|
this.value = this.value.replace(/\D/g, '');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Force numeric keyboard on mobile devices
|
||||||
|
numberInput.setAttribute('inputmode', 'numeric');
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user