This commit is contained in:
2025-03-06 11:00:28 -03:00
parent 9599b31d69
commit 6d9693bc26
8 changed files with 25 additions and 96 deletions

View File

@@ -1,3 +1,4 @@
from datetime import date
from decimal import Decimal from decimal import Decimal
from django.http import JsonResponse from django.http import JsonResponse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
@@ -69,10 +70,10 @@ def addProduct(request, product_id, comanda_id):
'message': f""" 'message': f"""
<div class="m-card" id="m-card-{order.id}"> <div class="m-card" id="m-card-{order.id}">
<h4>{product.name}</h4> <h4>{product.name}</h4>
<h4 id="obs-{order.id}"> {order.obs}</h4>
<h4>{comanda.name} - {comanda.mesa.name}</h4> <h4>{comanda.name} - {comanda.mesa.name}</h4>
<h4> {order.queue.strftime("%d/%m/%Y - %H:%M")}</h4>
<h4> Atendente: {comanda.user.first_name}</h4> <h4> Atendente: {comanda.user.first_name}</h4>
<h4> {order.queue}</h4>
<button class="btn-primary" onclick="delayTab('Fila')" <button class="btn-primary" onclick="delayTab('Fila')"
hx-get="/pedidos/preparing/{order.id}/" hx-trigger="click" hx-target="#etapas" hx-get="/pedidos/preparing/{order.id}/" hx-trigger="click" hx-target="#etapas"
>Preparar</button></div> >Preparar</button></div>

Binary file not shown.

View File

@@ -70,6 +70,7 @@ websocket.addEventListener('message', (event) => {
case 'cozinha': case 'cozinha':
if (document.getElementById('Fila') !== null && data.tipo === 'add'){ if (document.getElementById('Fila') !== null && data.tipo === 'add'){
const novoElemento = document.createElement('div'); const novoElemento = document.createElement('div');
// const novoElemento = document.getElementById('Fila');
novoElemento.innerHTML = data.message; novoElemento.innerHTML = data.message;
var fila = document.getElementById('Fila').appendChild(novoElemento); var fila = document.getElementById('Fila').appendChild(novoElemento);
let valorAtual = document.cookie.replace(/(?:(?:^|.*;\s*)notificacao\s*\=\s*([^;]*).*$)|^.*$/, "$1"); let valorAtual = document.cookie.replace(/(?:(?:^|.*;\s*)notificacao\s*\=\s*([^;]*).*$)|^.*$/, "$1");

View File

@@ -1,7 +1,4 @@
document.cookie = `pronto=0`;
function openModal() { function openModal() {
document.getElementById('Modal-create-comanda').style.display = 'block'; document.getElementById('Modal-create-comanda').style.display = 'block';
@@ -49,36 +46,3 @@ function mostrarNotificacao(titulo,corpo,grupo) {
} }
} }
function notificacao(){
var resposta = fetch(`/comandas/notificacao/`, {method: 'GET',
headers: {'Content-Type': 'application/json',
},})
.then(response => response.json())
.then(data => {
if (data['notificacao'] == 'true'){
console.log('verdadeiro')
document.cookie = `pronto=${data['pronto']}`;
mostrarNotificacao(data['titulo'], data['corpo'],'Garçom')
texto = new SpeechSynthesisUtterance(data['corpo']+', para '+data['titulo']+' tá pronto.');
window.speechSynthesis.speak(texto);
console.log(data['notificacao'])
}else{
document.cookie = `pronto=${data['pronto']}`;
console.log('falso')
console.log(data['notificacao'])
}
})
.catch(error => {
alert('Erro verificar notificação:', error,data['notificacao'])
});
}
setInterval(()=> {
notificacao()
}, 10000)

View File

@@ -187,7 +187,6 @@ function addOrder(){
headers: { headers: {
'Content-Type': 'application/json'} 'Content-Type': 'application/json'}
}) })
.then(function(response) { .then(function(response) {
if(response.status == 200){ if(response.status == 200){
closeModalObs() closeModalObs()
@@ -195,7 +194,6 @@ function addOrder(){
}else{ }else{
showToast('❌Ocorreu um erro!😢','error') showToast('❌Ocorreu um erro!😢','error')
} }
}) })
} }
function showToastAdd(message, type ,duration = 3000) { function showToastAdd(message, type ,duration = 3000) {
@@ -208,10 +206,7 @@ function showToastAdd(message, type ,duration = 3000) {
} else if (type === 'info') { } else if (type === 'info') {
toast.style.backgroundColor = '#ffc107'; toast.style.backgroundColor = '#ffc107';
} }
const toastMessage = document.getElementById('toast-message-add'); const toastMessage = document.getElementById('toast-message-add');
toastMessage.textContent = message; toastMessage.textContent = message;
toast.classList.add('show'); toast.classList.add('show');
@@ -221,28 +216,20 @@ function showToastAdd(message, type ,duration = 3000) {
} }
function addProductComanda(productId,comandaId, cuisine) { function addProductComanda(productId,comandaId, cuisine) {
obs = document.getElementById('obs'); obs = document.getElementById('obs');
// console.log(obs.value);
// console.log(cuisine);
if(cuisine == 'ggg'){ if(cuisine == 'ggg'){
var obs = openModalObs(); var obs = openModalObs();
}else{ }else{
fetch(`/comandas/addProduct${productId}/${comandaId}`, { fetch(`/comandas/addProduct${productId}/${comandaId}`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json'} 'Content-Type': 'application/json'}
}) })
.then(function(response) { .then(function(response) {
return response.text(); return response.text();
}).then(function(text) { }).then(function(text) {
var listProductsBalcaoElement = document.getElementById("list-products-comanda"); var listProductsBalcaoElement = document.getElementById("list-products-comanda");
listProductsBalcaoElement.innerHTML = text; listProductsBalcaoElement.innerHTML = text;
}) })
// websocket.send(JSON.stringify({ type: 'broadcast', message: '<div class="m-card" style="background-color: rgb(253, 69, 69);"><h4>Tapioca de ovo</h4><h4>sem ovo </h4><h4>Joao - mesa 07</h4><h4> Atendente: Lucas </h4><h4> 25/02/2025 20:03</h4><button class="btn-primary" >Preparar</button></div>'
//}));
showToastAdd('Produto adicionado com sucesso!😁','success'); showToastAdd('Produto adicionado com sucesso!😁','success');
} }
@@ -267,15 +254,3 @@ function taxa(){
// event.preventDefault(); // event.preventDefault();
// }); // });
// Enviar uma mensagem (exemplo - broadcast):
// websocket.send(JSON.stringify({ type: 'broadcast', message: 'Olá do cliente!' }));
//enviar uma mensagem (exemplo - echo):
// websocket.send(JSON.stringify({"type": "echo", "message": "Olá Mundo!"}))
//enviar uma mensagem (exemplo - test):
// websocket.send(JSON.stringify({"type": "test"}))

View File

@@ -49,25 +49,25 @@ function openTab(evt, etapa) {
displayBlock('Fila'); displayBlock('Fila');
function mostrarNotificacao(titulo,corpo,grupo) { // function mostrarNotificacao(titulo,corpo,grupo) {
if (Notification.permission != 'granted') { // if (Notification.permission != 'granted') {
Notification.requestPermission().then(function(permission) { // Notification.requestPermission().then(function(permission) {
if (permission == 'granted') { // if (permission == 'granted') {
var notification = new Notification(titulo, { // var notification = new Notification(titulo, {
body: corpo, // body: corpo,
icon: 'https://example.com/icon.png' // icon: 'https://example.com/icon.png'
}); // });
} // }
}); // });
} else { // } else {
var notification = new Notification(titulo, { // var notification = new Notification(titulo, {
body: corpo, // body: corpo,
icon: 'https://imagecolorpicker.com/imagecolorpicker-preview_b.avif', // icon: 'https://imagecolorpicker.com/imagecolorpicker-preview_b.avif',
image: 'https://imagecolorpicker.com/imagecolorpicker-preview_b.avif', // image: 'https://imagecolorpicker.com/imagecolorpicker-preview_b.avif',
}); // });
} // }
} // }
// function notificacao(){ // function notificacao(){
@@ -95,17 +95,3 @@ function openTab(evt, etapa) {
// } // }
// setInterval(()=> {
// notificacao()
// }, 10000)
// setTimeout(function() {
// mostrarNotificacao();}, 2000);
// mostrarNotificacao()
// notificacao()

View File

@@ -56,7 +56,9 @@ async def process_message(data, websocket):
async def broadcast_message(data): async def broadcast_message(data):
if connected_clients: if connected_clients:
logging.info(f"Enviando mensagem por broadcast: {data}") logging.info(f"Enviando mensagem por broadcast: {data}")
await asyncio.wait([client.send(json.dumps(data)) for client in connected_clients]) # await asyncio.wait([client.send(json.dumps(data)) for client in connected_clients])
tasks = [asyncio.create_task(client.send(json.dumps(data))) for client in connected_clients]
await asyncio.wait(tasks)
else: else:
logging.info("Nenhum cliente conectado.") logging.info("Nenhum cliente conectado.")