diff --git a/app/view/content.php b/app/view/content.php index ae6fbfe..cb99c7f 100644 --- a/app/view/content.php +++ b/app/view/content.php @@ -31,7 +31,7 @@
diff --git a/public/js/main.js b/public/js/main.js index 6f50dba..3e597fc 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -4,6 +4,7 @@ $(function () { connect(localStorage.getItem('obj_ws')); notifications(); + startSearch(); changeColors(darkMode, html); localStorage.removeItem('session_status'); localStorage.setItem('session_status', 0); @@ -192,7 +193,7 @@ const selectNotification = (id, status, datetime) => { localStorage.getItem("my_uniqueid") ); const allNotifications = JSON.parse( - localStorage.getItem("obj_notification") + localStorage.getItem("obj_search") ); const atendimentos = await buscarAtendimento(id); @@ -464,7 +465,6 @@ const viewMessage = (ev) => { $(".chat-window").append(`
${ev.event.mensagem.content}
`); break; case "alert": - console.log("eae eae peixe"); break; case "recover": $(".chat-window").append(`
${ev.event.mensagem.content}
`); diff --git a/public/js/requests.js b/public/js/requests.js index 763d2e4..b55729d 100644 --- a/public/js/requests.js +++ b/public/js/requests.js @@ -108,6 +108,18 @@ const listarAtendimentoAgente = (matricula) => new Promise((resolve) => { }); }) +const listarTodosAtendimentoAgente = (matricula) => new Promise((resolve) => { + $.ajax({ + url: `${server_api}${version_api}atendimentos/listar/${matricula}`, + type: "GET", + success: function (res) { + resolve(res) + }, + error: function (res) { + } + }); +}) + const listarPausasAgente = (id_empresa) => new Promise((resolve) => { $.ajax({ url: `${server_api}${version_api}pausas`, diff --git a/public/js/util.js b/public/js/util.js index 0071d19..85f0b9c 100644 --- a/public/js/util.js +++ b/public/js/util.js @@ -4,12 +4,10 @@ const scrollDown = () => { }; const responsivoButtonsHeader = () => { let chat_windown = document.querySelector(".chat-window-header-right"); - chat_windown.classList.toggle("ativo"); }; function formatedNumber(telefone) { const numeros = telefone.replace(/\D/g, ''); - if (numeros.length < 10) { return telefone; } @@ -19,18 +17,35 @@ function formatedNumber(telefone) { const search = (input) => { let inputValue = input.value.trim(); $("#chats").empty(); - let pesquisa = chatsArray.filter((item) => - item.nome.toLowerCase().includes(inputValue.toLowerCase()) - ); - + const atendimentos = JSON.parse(localStorage.getItem('obj_search')).data; + let pesquisa; let chatList = ""; - pesquisa.sort((a, b) => b.status - a.status); - pesquisa.forEach((e) => { + + if (!inputValue) { + notifications(); + return; + } + + pesquisa = atendimentos.filter((atendimento) => { + return ( + atendimento.nome.toLowerCase().includes(inputValue.toLowerCase()) || + atendimento.protocolo.toString().includes(inputValue.toLowerCase()) || + atendimento.cliente_id.toString().includes(inputValue.toLowerCase()) + ) + }); + + let chat = pesquisa.filter(function (a) { + return ( + !this[JSON.stringify(a.uniqueid)] && (this[JSON.stringify(a.uniqueid)] = true) + ); + }, Object.create(null)); + chat.sort((a, b) => b.status - a.status); + chat.forEach((e) => { chatList += buildNotification({ uniqueid: e.uniqueid, number: e.cliente_id, media: e.context, - name: e.nome, + name: e.profile_name, datetime: e.data_reg, status: e.status, protocolo: e.protocolo, @@ -431,9 +446,6 @@ const monitoraStatusRecuperacaoAtendimento = (date) => { const start = new Date(formatedTransferDate); const end = new Date(formatedDate); const diffInTime = Math.abs(end - start) / 1000 / 60 / 60 - console.log(start); - console.log(end); - console.log(diffInTime); if (diffInTime > RecuperacaoAtendimentoLimite) { return; } @@ -967,6 +979,20 @@ const notifyMe = (title, content) => { }); } }; + +const startSearch = () => { + let matricula = localStorage.getItem("token") + if (typeof matricula == "undefined") { + return; + } + + listarTodosAtendimentoAgente( + localStorage.getItem("my_uniqueid") + ).then(res => { + localStorage.removeItem('obj_search'); + localStorage.setItem('obj_search', JSON.stringify(res)); + }) +} /** * CRIA AS NOTIFICACOES DE TODOS OS ATENDIMENTOS NA INICIALIZACAO DO SISTEMA OU ATUALIZACAO */ @@ -1029,7 +1055,6 @@ const notifications = (obj = {}) => { }); }; - /** * CRIA AS NOTIFICACOES DE TODOS OS ATENDIMENTOS QUE ESTÃO NA FILA */ @@ -1131,6 +1156,7 @@ const supervisorAgente = () => { if (agente.status == "error" && agente.message == "Agente não encontrado") { window.close(); } + startSearch(); }); }, 30000); }; @@ -1211,7 +1237,6 @@ const connect = (wsserver) => { } /** RECEBE AS NOTIFICAÇÕES E RENDERIZA NA TELA)*/ - // console.log(data); if (data.event?.mensagem.type === 'alert') { renderNotification(data); }