added feature on new orderGet refresh orders list fixed bug if i order something from desk 2 as first after db entry 2 desk dont show its ordered items only if i add in desk 1 (querys.py)
This commit is contained in:
parent
a95e8a00b8
commit
35f20e4f63
10 changed files with 103 additions and 33 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
.venv
|
||||
|
|
@ -27,6 +27,10 @@ Execute in Terminal "python3 -m venv .venv", for the virtual enviroment activate
|
|||
|
||||
Note:
|
||||
This are early stages of this project listed are missing and planed.
|
||||
|
||||
### DB Delete
|
||||
|
||||
To delete db simple add first_startup = True in Options.ini and remove db.sqlite
|
||||
# To Does
|
||||
---
|
||||
Must have features / fixes
|
||||
|
|
|
|||
|
|
@ -126,11 +126,10 @@ class get:
|
|||
def all_orders():
|
||||
# All unfinished orders (finished is False or string "False")
|
||||
result = []
|
||||
desk = 1
|
||||
orders = session.query(Order).filter(Order.finished == 0).all()
|
||||
session.commit()
|
||||
for order in orders:
|
||||
products = session.query(Product).filter(Product.order_id == order.id , Order.desk_number == desk).all()
|
||||
products = session.query(Product).filter(Product.order_id == order.id).all()
|
||||
session.commit()
|
||||
list_products = []
|
||||
for p in products:
|
||||
|
|
|
|||
|
|
@ -95,16 +95,21 @@ def logout():
|
|||
def orders(): #TODO on new orderGet refresh orders list
|
||||
if request.method == 'POST':
|
||||
order_id = request.form.get('order_id')
|
||||
action = request.form.get('action') # 'finish' or 'undo'
|
||||
action = request.form.get('action') # 'refresh', 'finish' or 'undo'
|
||||
|
||||
order = session.get(Order, int(order_id))
|
||||
if order: #SQL error handeling just in case
|
||||
if action == 'finish':
|
||||
order.finished = True
|
||||
elif action == 'undo':
|
||||
order.finished = False
|
||||
if action == 'finish':
|
||||
order = session.get(Order, int(order_id))
|
||||
order.finished = True
|
||||
session.commit()
|
||||
return jsonify(success=True)
|
||||
elif action == 'undo':
|
||||
order = session.get(Order, int(order_id))
|
||||
order.finished = False
|
||||
session.commit()
|
||||
return jsonify(success=True)
|
||||
elif action == 'refresh':
|
||||
html = render_template('partials/_order_rows.html', orders=get.all_orders())
|
||||
return jsonify(success=True, html=html)
|
||||
return jsonify(success=False)
|
||||
|
||||
return render_template('orders.html', orders=get.all_orders())
|
||||
|
|
@ -137,11 +142,9 @@ def order_get():
|
|||
return render_template('index.html', desk=desk, MAX_DESKS=int(config['DEFAULT']['max_desks']), orderableItems = get.valid_products(get_json_=True))
|
||||
elif config['SETTINGS']['lockqrcode_whit_secret'] == 'False':
|
||||
return render_template('index.html', desk=desk, MAX_DESKS=int(config['DEFAULT']['max_desks']),orderableItems = get.valid_products(get_json_=True))
|
||||
else:
|
||||
return '<h1>Somethign went wrong try again.</h1>' #TODO Make the HTML prettier for all
|
||||
return '<h1>404 wrong Secret?</h1>' #TODO Make the HTML prettier for all
|
||||
elif config['SETTINGS']['lockqrcode_whit_secret'] == 'True':
|
||||
return '<h1>your LOCKQRCODE is invalid.</h1>'
|
||||
elif config['SETTINGS']['lockqrcode_whit_secret'] == 'True':
|
||||
return '<h1>your LOCKQRCODE is invalid.</h1>'
|
||||
return '<h1>Something went wrong went wrong, Try again.</h1>' #TODO Make the HTML prettier for all
|
||||
else:
|
||||
return render_template('index.html',desk=desk, MAX_DESKS=int(config['DEFAULT']['max_desks']),orderableItems = get.valid_products(get_json_=True))
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<form name="order" onsubmit="return validateForm()" action="{{ url_for('order_get') }}" method="POST" class="flex-container">
|
||||
<form name="order" onsubmit="return validateForm() && refresh()" action="{{ url_for('order_get') }}" method="POST" class="flex-container">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
||||
<li class="box desk-nr">Tisch Nummer
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -20,4 +20,4 @@
|
|||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -35,26 +35,31 @@
|
|||
<th>Action</th>
|
||||
<th>Order-Nr</th>
|
||||
</tr>
|
||||
<div id="refresh-timer" style="font-size: 0.9em; color: gray; margin-bottom: 10px;">
|
||||
Last refreshed: 0s ago
|
||||
</div>
|
||||
<tbody id="orders-container">
|
||||
{% for order in orders%}
|
||||
<tr id="order-{{ order[2] }}">
|
||||
<td>{{ order[0] }}</td>
|
||||
<td>
|
||||
<ul>
|
||||
{% for product in order[1] %}
|
||||
<li>{{ product }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<button class="finish-btn" onclick="markFinished({{ order[2] }})" id="btn-{{ order[2] }}">
|
||||
Finished
|
||||
</button>
|
||||
</td>
|
||||
<td>order {{ order[2] }} </td>
|
||||
</tr>
|
||||
<tr id="order-{{ order[2] }}">
|
||||
<td>{{ order[0] }}</td>
|
||||
<td>
|
||||
<ul>
|
||||
{% for product in order[1] %}
|
||||
<li>{{ product }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<button class="finish-btn" onclick="markFinished({{ order[2] }})" id="btn-{{ order[2] }}">
|
||||
Finished
|
||||
</button>
|
||||
</td>
|
||||
<td>order {{ order[2] }} </td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="3">No open orders.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<script>
|
||||
var csrfToken = "{{ csrf_token() }}";
|
||||
|
|
@ -120,6 +125,42 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
let secondsSinceRefresh = 0;
|
||||
setInterval(() => refreshInfo({ preventDefault: () => {} }), 1000);
|
||||
|
||||
function refreshInfo(e) {
|
||||
secondsSinceRefresh++
|
||||
e.preventDefault();
|
||||
|
||||
document.getElementById('refresh-timer').textContent = `Last refreshed: ${secondsSinceRefresh}s ago`;
|
||||
// Prevent refresh if any undo countdowns are active
|
||||
if (Object.keys(window.activeTimers).length > 0) {
|
||||
console.log('Refresh blocked: undo countdown in progress.');
|
||||
document.getElementsById('#output').text('Please wait for undo countdown to finish.').show();
|
||||
|
||||
return
|
||||
}
|
||||
fetch('/orders', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' ,
|
||||
'X-CSRFToken': csrfToken },
|
||||
body: `order_id=0&action=refresh`
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
document.getElementById('orders-container').innerHTML = data.html;
|
||||
secondsSinceRefresh = 0;
|
||||
document.getElementById('refresh-timer').textContent = `Last refreshed: 0s ago`
|
||||
} else {
|
||||
console.error('Failed to load orders');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching and rendering:', error);
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
22
Server/Host/templates/partials/_order_rows.html
Normal file
22
Server/Host/templates/partials/_order_rows.html
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
{% for order in orders%}
|
||||
<tr id="order-{{ order[2] }}">
|
||||
<td>{{ order[0] }}</td>
|
||||
<td>
|
||||
<ul>
|
||||
{% for product in order[1] %}
|
||||
<li>{{ product }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td>
|
||||
<button class="finish-btn" onclick="markFinished({{ order[2] }})" id="btn-{{ order[2] }}">
|
||||
Finished
|
||||
</button>
|
||||
</td>
|
||||
<td>order {{ order[2] }} </td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="3">No open orders.</td></tr>
|
||||
{% endfor %}
|
||||
</html>
|
||||
BIN
Tools/__pycache__/qrGenerator.cpython-312.pyc
Normal file
BIN
Tools/__pycache__/qrGenerator.cpython-312.pyc
Normal file
Binary file not shown.
2
app.py
2
app.py
|
|
@ -20,7 +20,7 @@ you want async logging.
|
|||
def run(): #TODO: sys.stderr back to a file log??
|
||||
logger.add(sys.stderr, format="{time} {level} {message}", filter="startup", level="INFO")
|
||||
logger.add(sys.stderr, backtrace=True, diagnose=config['OTHER']['log_diagnose'])
|
||||
app.run(debug=False)
|
||||
app.run(debug=False, host="0.0.0.0")
|
||||
|
||||
if __name__ == "__main__":
|
||||
#First startup is handled in DB/handler
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue