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:
Tim Berchtold 2025-07-08 16:41:12 +02:00
parent a95e8a00b8
commit 35f20e4f63
10 changed files with 103 additions and 33 deletions

View file

@ -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>

View file

@ -20,4 +20,4 @@
</form>
</body>
</html>
</html>

View file

@ -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>

View 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>