diff --git a/app.py b/app.py index 11588c4..4aa3b78 100644 --- a/app.py +++ b/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 from pprint import pprint as pp 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 + '"}}' - for i in 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: - print(i) + if len(json_file['unit'][int(index)]['bricks']['missing']) == 0: + json_file['unit'][int(index)]['bricks']['missing'].append(json.loads(data)) + 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 == '': with open('./info/'+tmp+'.json', 'w') as dump_file: json.dump(json_file,dump_file) - return ('', 204) + return redirect('/{}'.format(tmp)) if __name__ == '__main__': app.run(host='192.168.10.109', debug=True, port=3333) diff --git a/set_template.json b/set_template.json index 07139b3..69f1698 100644 --- a/set_template.json +++ b/set_template.json @@ -9,4 +9,4 @@ } } ] -} \ No newline at end of file +} diff --git a/templates/base.html b/templates/base.html index 80dcc45..70cc741 100644 --- a/templates/base.html +++ b/templates/base.html @@ -193,6 +193,17 @@ td img{ 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; +} diff --git a/templates/bootstrap_table.html b/templates/bootstrap_table.html index 2e9843e..ffd6a0f 100644 --- a/templates/bootstrap_table.html +++ b/templates/bootstrap_table.html @@ -21,7 +21,7 @@ {% if brick.is_spare == False %} {% if brick.element_id == None %} - + {% else %} {% endif %} @@ -34,7 +34,7 @@
{% set ns = namespace(count='') %} -
+ @@ -50,7 +50,7 @@ {% endif %} {% endfor %}
- + @@ -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'); +}); + {% endblock %}