Browse Source

alterações nas request

pull/3/head
Lucas Awade 2 years ago
parent
commit
e29c650a67
  1. 7
      index.php
  2. 4
      public/js/config.js
  3. 4
      public/js/cronometro.js
  4. 30
      public/js/main.js
  5. 69
      public/js/requests.js
  6. 24
      public/js/util.js

7
index.php

@ -39,18 +39,11 @@ if ($geturl['t'] == 'gerar' && $post['passwd'] == 'S1MPL3S1P_CH4T') {
if ($geturl['t']) {
$json = json_decode($crypt->decrypt(str_replace(' ', '+', $geturl['t'])), true);
$objs = [
<<<<<<< HEAD
'id_empresa' => $json['id_empresa'],
'obj_server' => $json['servidor'],
'my_uniqueid' => $json['matricula'],
'obj_queue' => $json['fila'],
=======
'id_number' => $json['id_number'],
'id_empresa' => $json['id_empresa'],
'obj_server' => $json['servidor'],
'my_uniqueid' => $json['matricula'],
'obj_queue' => $json['fila'],
>>>>>>> 1e181ff (ajustes de funcionalidades)
'obj_ws' => $json['websocket'],
'session_uniqueid' => null,
'obj_notification' => null,

4
public/js/config.js

@ -1,10 +1,6 @@
const ws = localStorage.getItem('obj_ws')
<<<<<<< HEAD
const server_api = localStorage.getItem('obj_server')
=======
const server_api = `http://${localStorage.getItem('obj_server')}`
const supervisor_api = localStorage.getItem('supervisor_api') ? localStorage.getItem('supervisor_api') : localStorage.getItem('obj_server')
>>>>>>> 1e181ff (ajustes de funcionalidades)
let mediaRecorder
const icontypes = ['csv', 'doc', 'pdf', 'txt', 'xls', 'zip', 'ppt']
const path = 'public'

4
public/js/cronometro.js

@ -47,8 +47,8 @@ function converdata(timestamp, horario_server = false){
}
let date = new Date(timestamp);
let day = addZero(date.getDay())
let month = addZero(date.getMonth())
let day = addZero(date.getDate())
let month = addZero(date.getMonth() + 1)
let hours = date.getHours();
let minutes = date.getMinutes();
let formattedTime = `${day}/${month} ` + addZero(hours) + ':' + addZero(minutes)

30
public/js/main.js

@ -82,7 +82,7 @@ $(function(){
const selectNotification = (id) => {
marcarMensagemVista(id)
listaMensagem(id).then(() => {
listaMensagem(id).then(async () => {
let uniqueid
let number
let name
@ -90,15 +90,9 @@ const selectNotification = (id) => {
let protocolo
const dataRequest = JSON.parse(localStorage.getItem('obj_contact'))
<<<<<<< HEAD
listarAtendimentoAgente(localStorage.getItem('my_uniqueid'))
=======
listarAtendimentoAgente(localStorage.getItem('id_empresa'), localStorage.getItem('my_uniqueid'))
>>>>>>> 1e181ff (ajustes de funcionalidades)
const allNotifications = JSON.parse(localStorage.getItem('obj_notification'))
console.log(allNotifications)
const atendimentos = await buscarAtendimento(id);
hideButtons(false)
allNotifications.data.forEach(e => {
@ -146,13 +140,9 @@ const selectNotification = (id) => {
$('.chat-window .events').remove()
alertNotification(localStorage.getItem('session_uniqueid'), 'remove')
dataContact.forEach(e => {
dataContact.forEach((e) => {
const datesend = e.msg_date ? converdata(new Date(e.msg_date).getTime()) : 'algumas horas';
<<<<<<< HEAD
let typesend = localStorage.getItem('my_uniqueid') == e.src ? 'sender': 'receiver'
=======
let typesend = localStorage.getItem('my_uniqueid') == e.dst ? 'receiver' : 'sender'
>>>>>>> 1e181ff (ajustes de funcionalidades)
let typesend = atendimentos.data[0].cliente_id == e.dst ? 'sender' : 'receiver'
if (e.type == 'text') {
$('.chat-window').append(`
@ -164,6 +154,13 @@ const selectNotification = (id) => {
)
}
if (e.type == 'transfer') {
$('.chat-window').append(`
<div class="events">
<span class="events-message">${e.content} por ${e.profile_name}, ${datesend}.</span>
</div>`)
}
if (e.type == 'finish' || e.type == 're_start') {
$('.chat-window').append(`
<div class="events">
@ -193,9 +190,7 @@ const selectNotification = (id) => {
<span class="message-time">${datereceived}</span>
</div>`)
} else if (e.type == 'audio' || e.type == 'voice') {
const audio = `<audio controls>
<source src="data:audio/mpeg;base64,${e.msg}"></source>
</audio>`
const audio = `<audio controls><source src="data:audio/mpeg;base64,${e.msg}"></source></audio>`
$('.chat-window').append(`
<div class="${typesend}">
<span class="${typesend}-message">${audio}</span>
@ -379,6 +374,7 @@ const receiveNotification = (data) => {
context: data.event?.mensagem.media,
profile_name: data.event?.contact.name,
data_reg: data.event?.mensagem.datetime,
media: data.event?.mensagem.media,
status: 1,
action: 'mensagem',
}

69
public/js/requests.js

@ -16,12 +16,6 @@ const listaMensagem = (uniqueid) => new Promise((resolve) => {
$.ajax({
url: `${server_api}/messages/${uniqueid}`,
type: "GET",
<<<<<<< HEAD
data: {
uniqueid
},
=======
>>>>>>> 1e181ff (ajustes de funcionalidades)
success: function (res) {
localStorage.removeItem('obj_contact')
localStorage.setItem('obj_contact', JSON.stringify(res))
@ -37,13 +31,6 @@ const listarAgentesDisponivel = (id_empresa) => new Promise((resolve) => {
$.ajax({
url: `${server_api}/supervisor/agentes/status/${id_empresa}/livre`,
type: "GET",
<<<<<<< HEAD
data: {
id_empresa,
agente_livre: "true"
},
=======
>>>>>>> 1e181ff (ajustes de funcionalidades)
success: function (res) {
resolve(res)
},
@ -57,12 +44,6 @@ const listarAtendimentoAgente = (id_empresa, matricula) => new Promise((resolve)
$.ajax({
url: `${server_api}/atendimentos/${id_empresa}/${matricula}`,
type: "GET",
<<<<<<< HEAD
data: {
matricula
},
=======
>>>>>>> 1e181ff (ajustes de funcionalidades)
success: function (res) {
localStorage.removeItem('obj_notification')
localStorage.setItem('obj_notification', JSON.stringify(res))
@ -78,12 +59,6 @@ const listarPausasAgente = (id_empresa) => new Promise((resolve) => {
$.ajax({
url: `${server_api}/pausas/${id_empresa}`,
type: "GET",
<<<<<<< HEAD
data: {
id_empresa
},
=======
>>>>>>> 1e181ff (ajustes de funcionalidades)
success: function (res) {
resolve(res)
},
@ -205,13 +180,6 @@ const statusAgente = (id_empresa, matricula) => new Promise((resolve) => {
$.ajax({
url: `${server_api}/supervisor/agentes/${id_empresa}/${matricula}`,
type: "GET",
<<<<<<< HEAD
data: {
matricula,
id_empresa: empresa
},
=======
>>>>>>> 1e181ff (ajustes de funcionalidades)
success: function (res) {
localStorage.removeItem('obj_status')
localStorage.setItem('obj_status', JSON.stringify(res))
@ -246,9 +214,8 @@ const transferirAtendimento = (origem, destino, uniqueid) => new Promise((resolv
},
error: function (res) {
alertModal(
`<h2>OPS... HOUVE UM PROBLEMA &nbsp</h2><img id="imgReconnect" width="25px" src="${path}/images/alert.png">
<p>Não foi possível carregar as infoemacoes do agente!</p>
<p>Error: ${res}</p>`,
`<h3>OPS... HOUVE UM PROBLEMA &nbsp</h3><img id="imgReconnect" width="25px" src="${path}/images/alerta.png">
<p>Não foi possível carregar as infomacçõs do agente!</p>`,
'OPS!!!'
)
}
@ -270,3 +237,35 @@ const marcarMensagemVista = (uniqueid) => {
}
});
}
const buscarAtendimento = async (uniqueid) => {
return $.ajax({
url: `${server_api}/atendimentos/buscar`,
type: "POST",
data: JSON.stringify({
uniqueid
}),
success: function (res) {
return res
},
error: function (res) {
alert('Nao foi possivel carregar as informacoes do atendimento.')
}
});
}
const buscarUsuario = (matricula) => new Promise((resolve) =>{
$.ajax({
url: `${server_api}/usuario/buscar`,
type: "POST",
data: JSON.stringify({
matricula
}),
success: function (res) {
resolve(res)
},
error: function (res) {
alert('Nao foi possivel carregar as informacoes do usuario.')
}
});
})

24
public/js/util.js

@ -358,12 +358,13 @@ function recorderVoice () {
* @returns
*/
const buildNotification = (data = {}) => {
if(data.length == 'undefined'){
if(data.length == 'undefined' || (data.media == undefined && data.media == undefined) ){
return
}
const datesend = converdata(data.datetime)
const status = data.status == 0 ? 'opacity-3' : ''
return `<div class="chat ${status}" id="${data.uniqueid}" onclick="selectNotification(this.id)">
<div class="chat-left">
<img src="${path}/images/${data.media}.png"/>
@ -460,8 +461,13 @@ const notifications = (obj = {}) => {
}
}
notification.data.sort((a, b) => b.status - a.status)
notification.data.forEach(e => {
let chat = notification.data.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,
@ -479,11 +485,11 @@ const notifications = (obj = {}) => {
const monitorPausaAgente = () => {
statusAgente(localStorage.getItem('id_empresa'), localStorage.getItem('my_uniqueid')).then((agente) => {
let statusagent = agente.data[0].status
let statusagent = agente.data[0]?.status
const status = [
{ status: "LIVRE", class: "status-connect", html: `id="entrePause" src="${path}/images/pause.svg" title="Atribuir uma pausa"`, descricao: statusagent },
{ status: "PAUSA", class: "status-desconnect", html: `id="exitPause" src="${path}/images/play.svg" title="Remover a pausa"`, descricao: `${statusagent} - ${agente.data[0].motivo_pausa}` },
{ status: "PAUSA", class: "status-desconnect", html: `id="exitPause" src="${path}/images/play.svg" title="Remover a pausa"`, descricao: `${statusagent} - ${agente.data[0]?.motivo_pausa}` },
{ status: "OCUPADO", class: "status-reconnect", html: `id="entrePause" src="${path}/images/pause.svg" title="Atribuir uma pausa"`, descricao: statusagent },
{ status: "INDISPONIVEL", class: "status-reconnect", html: `id="exitPause" src="${path}/images/play.svg" title="Remover a pausa"`, descricao: statusagent },
]
@ -531,7 +537,7 @@ const connect = (wsserver) => {
ws.onerror = function(err) {
alertModal(
`<h2>CONECTANDO NO SISTEMA! POR FAVOR AGUARDE.</h2>`,
`<h3>CONECTANDO NO SISTEMA! POR FAVOR AGUARDE.</h3>`,
`<img id="imgReconnect" width="20px" src="${path}/images/loading.gif">`
)
$("#status_agent").addClass("status-desconnect").text('DESCONECTADO');
@ -541,6 +547,7 @@ const connect = (wsserver) => {
ws.onopen = function wsconnect() {
$("#status_agent").addClass("status-reconnect").text('RECONECTANDO ...');
entrar(localStorage.getItem('my_uniqueid'), localStorage.getItem('obj_queue')).then((login) => {
console.log(login)
if(login.status == 'success' || login.message.indexOf('autenticado') >= 0){
$('#modalselect').css({display: 'none'})
monitorPausaAgente()
@ -548,7 +555,7 @@ const connect = (wsserver) => {
notifications()
} else if(login.status == 'error'){
alertModal(
`<h2>OPSS!! ${login.message} &nbsp</h2>`,
`<h3>OPSS!! ${login.message} &nbsp</h3>`,
`<img width="20px" src="${path}/images/alerta.png">`
)
$("#status_agent").addClass("status-desconnect").text('OFF');
@ -559,9 +566,8 @@ const connect = (wsserver) => {
};
ws.addEventListener("open", () => {
const storage = ['my_uniqueid', 'keep_msg', 'obj_contact', 'session_uniqueid', 'session_window']
ws.addEventListener("message", e => {
/** att: atualizacao do websocket */
if(e.data != 'att'){
const data = JSON.parse(e?.data)

Loading…
Cancel
Save