Compare commits
No commits in common. "main" and "1.0.3" have entirely different histories.
|
|
@ -5,13 +5,14 @@
|
||||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; connect-src https://autoatend.linco.work">
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; connect-src https://autoatend.linco.work">
|
||||||
<title>Floating Button</title>
|
<title>Floating Button</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<script src="res/js/jquery/jquery.js"></script>
|
<script src="js/jquery/jquery.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body id="floating">
|
<body id="floating">
|
||||||
<button id="float-button">
|
<button id="float-button">
|
||||||
<span id="icon"><img src="res/img/client.png" width="22px"></span> <!-- Ícone de exemplo -->
|
<span id="icon">🧑🦰</span> <!-- Ícone de exemplo -->
|
||||||
<span id="count">0</span>
|
<span id="count">0</span>
|
||||||
</button>
|
</button>
|
||||||
<script src="floating.js"></script>
|
<script src="floating.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
45
floating.js
45
floating.js
|
|
@ -3,11 +3,6 @@ const countSpan = document.getElementById('count');
|
||||||
|
|
||||||
// Atualiza a contagem e a cor do botão quando recebe do main process
|
// Atualiza a contagem e a cor do botão quando recebe do main process
|
||||||
window.electronAPI.onUpdateCount((value) => {
|
window.electronAPI.onUpdateCount((value) => {
|
||||||
// Se estiver em atendimento, ignora qualquer atualização de contagem
|
|
||||||
if (floatButton.classList.contains('em-atendimento')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
countSpan.innerHTML = value ?? 0;
|
countSpan.innerHTML = value ?? 0;
|
||||||
// Verifica a contagem para mudar a cor
|
// Verifica a contagem para mudar a cor
|
||||||
if (value > 0) {
|
if (value > 0) {
|
||||||
|
|
@ -17,50 +12,10 @@ window.electronAPI.onUpdateCount((value) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Altera a cor do botão com base no status do atendimento
|
|
||||||
window.electronAPI.onAtendimentoStatusChanged((status) => {
|
|
||||||
if (status === 'iniciado') {
|
|
||||||
const nomeAtendimento = localStorage.getItem('atendimentoAtualNome');
|
|
||||||
floatButton.classList.remove('has-items');
|
|
||||||
floatButton.classList.add('em-atendimento');
|
|
||||||
countSpan.innerHTML = '-'; // Mostra o hífen
|
|
||||||
if (nomeAtendimento) {
|
|
||||||
floatButton.setAttribute('title', `Atendendo: ${nomeAtendimento}`);
|
|
||||||
}
|
|
||||||
} else { // 'finalizado'
|
|
||||||
floatButton.classList.remove('em-atendimento');
|
|
||||||
floatButton.setAttribute('title', 'Chamar próximo da fila');
|
|
||||||
// Solicita uma atualização imediata da contagem para refletir o estado atual da fila
|
|
||||||
window.electronAPI.refreshCount();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Ao carregar, verifica se já existe um atendimento em andamento
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
const atendimentoAtual = localStorage.getItem('atendimentoAtual');
|
|
||||||
if (atendimentoAtual) {
|
|
||||||
const nomeAtendimento = localStorage.getItem('atendimentoAtualNome');
|
|
||||||
floatButton.classList.remove('has-items');
|
|
||||||
floatButton.classList.add('em-atendimento');
|
|
||||||
countSpan.innerHTML = '-'; // Mostra o hífen
|
|
||||||
if (nomeAtendimento) {
|
|
||||||
floatButton.setAttribute('title', `Atendendo: ${nomeAtendimento}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
floatButton.setAttribute('title', 'Chamar próximo da fila');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mostra a janela principal ao clicar
|
// Mostra a janela principal ao clicar
|
||||||
floatButton.addEventListener('click', () => {
|
floatButton.addEventListener('click', () => {
|
||||||
window.electronAPI.showMainWindow();
|
window.electronAPI.showMainWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Adiciona um listener para o evento de clique com o botão direito
|
|
||||||
floatButton.addEventListener('contextmenu', (e) => {
|
|
||||||
e.preventDefault(); // Impede o menu padrão do navegador
|
|
||||||
window.electronAPI.showMenu(); // Chama a função para mostrar o menu no processo principal
|
|
||||||
});
|
|
||||||
|
|
||||||
// Ajuste inicial do cursor
|
// Ajuste inicial do cursor
|
||||||
floatButton.style.cursor = 'pointer';
|
floatButton.style.cursor = 'pointer';
|
||||||
|
|
@ -2,8 +2,7 @@ const { contextBridge, ipcRenderer } = require('electron');
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld('electronAPI', {
|
contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
onUpdateCount: (callback) => ipcRenderer.on('update-count', (_event, value) => callback(value)),
|
onUpdateCount: (callback) => ipcRenderer.on('update-count', (_event, value) => callback(value)),
|
||||||
onAtendimentoStatusChanged: (callback) => ipcRenderer.on('atendimento-status-changed', (_event, status) => callback(status)),
|
showMainWindow: () => ipcRenderer.send('chamar-fila')
|
||||||
refreshCount: () => ipcRenderer.send('refresh-count'),
|
// Remova a linha abaixo:
|
||||||
showMainWindow: () => ipcRenderer.send('chamar-fila'),
|
// startDrag: (offset) => ipcRenderer.send('drag-float-window', offset)
|
||||||
showMenu: () => ipcRenderer.send('show-context-menu')
|
|
||||||
});
|
});
|
||||||
18
index.html
18
index.html
|
|
@ -1,19 +1,12 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta http-equiv="Content-Security-Policy" content="
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; connect-src https://autoatend.linco.work">
|
||||||
default-src 'self';
|
|
||||||
script-src 'self' 'unsafe-inline';
|
|
||||||
style-src 'self' 'unsafe-inline';
|
|
||||||
connect-src 'self' ws://autoatend.linco.work:6001 ws://localhost:6001 wss://aa.linco.work:443;
|
|
||||||
">
|
|
||||||
<title>Tela de Atendimento</title>
|
<title>Tela de Atendimento</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<script src="res/js/jquery/jquery.js"></script>
|
<script src="js/jquery/jquery.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="list-view">
|
<div id="list-view">
|
||||||
<h1>Fila</h1>
|
<h1>Fila</h1>
|
||||||
|
|
@ -21,10 +14,7 @@
|
||||||
<ul id="item-list">
|
<ul id="item-list">
|
||||||
<!-- Itens serão carregados aqui -->
|
<!-- Itens serão carregados aqui -->
|
||||||
</ul>
|
</ul>
|
||||||
<button id="next-button" disabled>
|
<button id="next-button" disabled><span id="counter-start"></span> Iniciar atendimento</button>
|
||||||
<span id="counter-start"></span>
|
|
||||||
Iniciar atendimento
|
|
||||||
</button>
|
|
||||||
<!-- <button id="sendto-button" disabled>Encaminhar</button> -->
|
<!-- <button id="sendto-button" disabled>Encaminhar</button> -->
|
||||||
<button id="logout-button">Trocar Colaborador</button>
|
<button id="logout-button">Trocar Colaborador</button>
|
||||||
|
|
||||||
|
|
@ -45,9 +35,7 @@
|
||||||
<button id="save-button">Salvar</button>
|
<button id="save-button">Salvar</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="res/js/pusher.min.js"></script>
|
|
||||||
<script src="renderer.js"></script>
|
<script src="renderer.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'">
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'">
|
||||||
<title>Login</title>
|
<title>Login</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<script src="res/js/jquery/jquery.js"></script>
|
<script src="js/jquery/jquery.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="login-page">
|
<body class="login-page">
|
||||||
<div class="login-container">
|
<div class="login-container">
|
||||||
|
|
|
||||||
312
main.js
312
main.js
|
|
@ -1,10 +1,9 @@
|
||||||
const { app, BrowserWindow, ipcMain, screen, net, dialog, Menu } = require('electron');
|
const { app, BrowserWindow, ipcMain, screen, net } = require('electron');
|
||||||
// const { app: singleInstanceLock } = require('electron-single-instance');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const { autoUpdater, AppUpdater } = require('electron-updater');
|
const { autoUpdater, AppUpdater } = require('electron-updater');
|
||||||
const pjson = require(path.join(__dirname, '', 'package.json'));
|
const pjson = require(path.join(__dirname,'','package.json'));
|
||||||
|
|
||||||
let floatingWin;
|
let floatingWin;
|
||||||
let mainWin;
|
let mainWin;
|
||||||
|
|
@ -14,17 +13,18 @@ let updateWin;
|
||||||
|
|
||||||
const dataPath = path.join(__dirname, 'data.json'); // Caminho para o JSON (backup local)
|
const dataPath = path.join(__dirname, 'data.json'); // Caminho para o JSON (backup local)
|
||||||
const apiUrl = 'https://autoatend.linco.work/api/v1/';
|
const apiUrl = 'https://autoatend.linco.work/api/v1/';
|
||||||
// const apiUrl = 'http://_lara10-autoatend.devel/api/v1/';
|
|
||||||
|
|
||||||
const pusherUrl = 'aa.linco.work';
|
|
||||||
// const pusherUrl = 'localhost';
|
|
||||||
|
|
||||||
|
|
||||||
autoUpdater.autoDownload = false;
|
autoUpdater.autoDownload = false;
|
||||||
autoUpdater.autoInstallOnAppQuit = true;
|
autoUpdater.autoInstallOnAppQuit = true;
|
||||||
|
|
||||||
//impede que o app seja executado mais de uma vez
|
|
||||||
const gotTheLock = app.requestSingleInstanceLock();
|
//// carrega o electron-reload, buga ao salvar o main.js por conta do fetchDataFromAPI
|
||||||
|
// if(!pjson.isBuildNow){
|
||||||
|
// require('electron-reload')(__dirname,{
|
||||||
|
// electron: require(`${__dirname}/node_modules/electron`)
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
// Função modificada para buscar dados da API
|
// Função modificada para buscar dados da API
|
||||||
async function readData() {
|
async function readData() {
|
||||||
|
|
@ -50,31 +50,33 @@ async function readData() {
|
||||||
async function fetchDataFromAPI() {
|
async function fetchDataFromAPI() {
|
||||||
//executa uma vez e a cada 30 segundos
|
//executa uma vez e a cada 30 segundos
|
||||||
|
|
||||||
//!primeira requisição é feita para API
|
//TODO propicio para fazer um webhook nessas funções que repetem a chamada de requisições em busca de alterações
|
||||||
getFirstData();
|
getAndUpdateDataStorage();
|
||||||
|
|
||||||
//! as outras é o websockt que solicita a chamada de requisições em busca de alterações
|
const updData = setInterval(()=>{
|
||||||
const updData = setInterval(() => {
|
getAndUpdateDataStorage();
|
||||||
getDataAndUpdateFloatingBtn();
|
},10000);
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
const updVersion = setTimeout(() => {
|
const updVersion = setTimeout(()=>{
|
||||||
if (pjson.isBuildNow) {
|
if(pjson.isBuildNow){
|
||||||
autoUpdater.checkForUpdates();
|
autoUpdater.checkForUpdates();
|
||||||
}
|
}
|
||||||
}, 300000);
|
},300000);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFirstData() {
|
// Função para coletar a lista de atendimentos do servidor, vai ser chamada uma vez e a cada 30s
|
||||||
|
async function getAndUpdateDataStorage (){
|
||||||
|
|
||||||
const token = await getAuthToken();
|
const token = await getAuthToken();
|
||||||
const colabId = await floatingWin.webContents.executeJavaScript("localStorage.getItem('idOperator')")
|
const colabId = await floatingWin.webContents.executeJavaScript("localStorage.getItem('idOperator')")
|
||||||
const url = apiUrl + 'get-proximos/' + colabId;
|
|
||||||
|
|
||||||
//! checa se o token e o colabId existem
|
const url = apiUrl + 'get-proximos/'+colabId; // URL de exemplo para enviar a solicitação
|
||||||
if (!token && !colabId) { console.warn("Token or colabId not found in localStorage. API requests will not be made."); return; }
|
|
||||||
|
if (!token && !colabId) {
|
||||||
|
console.warn("Token or colabId not found in localStorage. API requests will not be made.");
|
||||||
|
return; // Stop the function if token or colabId is missing
|
||||||
|
}
|
||||||
|
|
||||||
//! faz o request
|
|
||||||
const request = net.request({
|
const request = net.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: url,
|
url: url,
|
||||||
|
|
@ -84,20 +86,35 @@ async function getFirstData() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//! busca pela resposta
|
|
||||||
request.on('response', (response) => {
|
request.on('response', (response) => {
|
||||||
let rawData = '';
|
let rawData = '';
|
||||||
response.on('data', (chunk) => { rawData += chunk; });
|
|
||||||
|
response.on('data', (chunk) => {
|
||||||
|
rawData += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
response.on('end', () => {
|
response.on('end', () => {
|
||||||
try {
|
try {
|
||||||
const parsedData = JSON.parse(rawData);
|
const parsedData = JSON.parse(rawData);
|
||||||
let proximos = parsedData;
|
let proximos = parsedData;
|
||||||
|
|
||||||
if (response.statusCode === 200) {
|
if (response.statusCode === 200) {
|
||||||
floatingWin.webContents.executeJavaScript("localStorage.setItem('proximos','" + JSON.stringify(proximos) + "')");
|
if(!mainWin.isVisible){
|
||||||
|
//envia os dados para o loadData atualiza a tela somente se não estiver sendo exibida
|
||||||
|
mainWin.webContents.send('load-data', proximos);
|
||||||
|
}
|
||||||
|
//grava os registros no localstorage
|
||||||
|
floatingWin.webContents.executeJavaScript("localStorage.setItem('proximos','"+JSON.stringify(proximos)+"')");
|
||||||
let count = proximos.length;
|
let count = proximos.length;
|
||||||
|
//lista a contagem no botão flutuante
|
||||||
floatingWin.webContents.send('update-count', count);
|
floatingWin.webContents.send('update-count', count);
|
||||||
|
console.log(`Dados carregados com sucesso!`);
|
||||||
} else {
|
} else {
|
||||||
console.error(`Erro na requisição: Status code ${response.statusCode}`, parsedData);
|
console.error(`Erro na requisição: Status code ${response.statusCode}`, parsedData);
|
||||||
|
// Lidar com o erro adequadamente, talvez enviando uma mensagem para a janela principal
|
||||||
|
mainWin.webContents.send('api-error', {
|
||||||
|
message: `Erro ao chamar atendimentos: ${parsedData.message || 'Erro desconhecido'}`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erro ao analisar a resposta JSON:", error);
|
console.error("Erro ao analisar a resposta JSON:", error);
|
||||||
|
|
@ -107,24 +124,16 @@ async function getFirstData() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
request.on('error', (error) => {
|
request.on('error', (error) => {
|
||||||
console.error("Erro na requisição:", error);
|
console.error("Erro na requisição:", error);
|
||||||
|
mainWin.webContents.send('api-error', {
|
||||||
|
message: `Erro ao chamar atendimento: ${error.message}`
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
request.end();
|
request.end();
|
||||||
|
|
||||||
return JSON.parse(await floatingWin.webContents.executeJavaScript("localStorage.getItem('proximos')"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Função para coletar a lista de atendimentos do servidor, vai ser chamada uma vez e a cada 30s
|
|
||||||
async function getDataAndUpdateFloatingBtn() {
|
|
||||||
|
|
||||||
const proximos = JSON.parse(await floatingWin.webContents.executeJavaScript("localStorage.getItem('proximos')")) ?? [];
|
|
||||||
let count = proximos.length;
|
|
||||||
|
|
||||||
//lista a contagem no botão flutuante
|
|
||||||
floatingWin.webContents.send('update-count', count);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Função para verificar se o token existe no localStorage
|
// Função para verificar se o token existe no localStorage
|
||||||
|
|
@ -256,7 +265,7 @@ function createFloatingWindow() {
|
||||||
|
|
||||||
floatingWin.loadFile('floating.html');
|
floatingWin.loadFile('floating.html');
|
||||||
|
|
||||||
floatingWin.webContents.executeJavaScript('localStorage.setItem("version","' + app.getVersion() + '")');
|
floatingWin.webContents.executeJavaScript('localStorage.setItem("version","'+app.getVersion()+'")');
|
||||||
|
|
||||||
// Envia a contagem inicial para a janela flutuante
|
// Envia a contagem inicial para a janela flutuante
|
||||||
const data = readData();
|
const data = readData();
|
||||||
|
|
@ -267,6 +276,7 @@ function createFloatingWindow() {
|
||||||
floatingWin.on('closed', () => {
|
floatingWin.on('closed', () => {
|
||||||
floatingWin = null;
|
floatingWin = null;
|
||||||
});
|
});
|
||||||
|
// floatingWin.webContents.openDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMainWindow() {
|
function createMainWindow() {
|
||||||
|
|
@ -307,42 +317,31 @@ function createMainWindow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (pjson.isBuildNow) {
|
if(pjson.isBuildNow){
|
||||||
autoUpdater.on('update-available', () => {
|
autoUpdater.on('update-available', () => {
|
||||||
let pth = autoUpdater.downloadUpdate();
|
let pth = autoUpdater.downloadUpdate();
|
||||||
updateWin.show(); updateWin.focus();
|
updateWin.show(); updateWin.focus();
|
||||||
updateWin.webContents.send('update_message', `Uma nova versão está dispinível.`);
|
updateWin.webContents.send('update_message',`Uma nova versão está dispinível.`);
|
||||||
updateWin.webContents.send('update_percent', pth);
|
updateWin.webContents.send('update_percent',pth);
|
||||||
})
|
})
|
||||||
autoUpdater.on('download-progress', (obj) => {
|
autoUpdater.on('download-progress',(obj) => {
|
||||||
updateWin.webContents.send('update_message', `Estamos baixando uma nova atualização.`);
|
updateWin.webContents.send('update_message',`Estamos baixando uma nova atualização.`);
|
||||||
});
|
});
|
||||||
autoUpdater.on('update-downloaded', (obj) => {
|
autoUpdater.on('update-downloaded',(obj) => {
|
||||||
updateWin.webContents.send('update_message', `Download concluído. Aguarde, vamos reiniciar para instalar!`);
|
updateWin.webContents.send('update_message',`Download concluído. Aguarde, vamos reiniciar para instalar!`);
|
||||||
setTimeout(() => {
|
setTimeout(()=>{
|
||||||
autoUpdater.quitAndInstall();
|
autoUpdater.quitAndInstall();
|
||||||
}, 5000);
|
},5000);
|
||||||
});
|
});
|
||||||
autoUpdater.on('error', err => {
|
autoUpdater.on('error',err => {
|
||||||
updateWin.webContents.send('update_message', err);
|
updateWin.webContents.send('update_message',err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!gotTheLock) {
|
|
||||||
app.quit();
|
|
||||||
} else {
|
|
||||||
app.on('second-instance', () => {
|
|
||||||
if (mainWin) {
|
|
||||||
if (mainWin.isMinimized()) {
|
|
||||||
mainWin.restore();
|
|
||||||
}
|
|
||||||
mainWin.focus();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Inicialização do aplicativo modificada para verificar autenticação
|
// Inicialização do aplicativo modificada para verificar autenticação
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
|
|
||||||
// Verifica se o usuário já está autenticado
|
// Verifica se o usuário já está autenticado
|
||||||
const token = await getAuthToken();
|
const token = await getAuthToken();
|
||||||
|
|
@ -362,6 +361,7 @@ if (!gotTheLock) {
|
||||||
createFloatingWindow();
|
createFloatingWindow();
|
||||||
createMainWindow();
|
createMainWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
createUpdateWindow();
|
createUpdateWindow();
|
||||||
|
|
||||||
|
|
@ -377,15 +377,11 @@ if (!gotTheLock) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (pjson.isBuildNow) {
|
if(pjson.isBuildNow){
|
||||||
autoUpdater.checkForUpdates();
|
autoUpdater.checkForUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Função para verificar se já existe um operador selecionado
|
// Função para verificar se já existe um operador selecionado
|
||||||
async function getSelectedOperator() {
|
async function getSelectedOperator() {
|
||||||
|
|
@ -428,19 +424,13 @@ async function getSelectedOperatorId() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.handle('get-pusher-config', async () => {
|
|
||||||
// Obtenha sua chave e host de forma segura aqui (ambiente, .env, etc.)
|
|
||||||
const PUSHER_APP_KEY = process.env.PUSHER_APP_KEY || '1feb970af7708cb';
|
|
||||||
const PUSHER_HOST = process.env.PUSHER_HOST || pusherUrl;
|
|
||||||
return { appKey: PUSHER_APP_KEY, host: PUSHER_HOST };
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on('update_version', async (event, arg) => {
|
ipcMain.on('update_version', async (event, arg) => {
|
||||||
if (updateWin) {
|
if(updateWin){
|
||||||
if (!updateWin.isVisible()) {
|
if(!updateWin.isVisible()){
|
||||||
updateWin.show();
|
updateWin.show();
|
||||||
updateWin.focus();
|
updateWin.focus();
|
||||||
} else {
|
}else{
|
||||||
updateWin.focus();
|
updateWin.focus();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -462,10 +452,6 @@ ipcMain.handle('get-count', async () => {
|
||||||
// Ouvir pedido para mostrar a janela principal
|
// Ouvir pedido para mostrar a janela principal
|
||||||
ipcMain.on('chamar-fila', async () => {
|
ipcMain.on('chamar-fila', async () => {
|
||||||
|
|
||||||
// Primeiro, verifica se já existe um atendimento em andamento
|
|
||||||
const atendimentoAtualId = await floatingWin.webContents.executeJavaScript("localStorage.getItem('atendimentoAtual')");
|
|
||||||
|
|
||||||
const showMainWindow = () => {
|
|
||||||
if (mainWin) {
|
if (mainWin) {
|
||||||
if (!mainWin.isVisible()) {
|
if (!mainWin.isVisible()) {
|
||||||
mainWin.show();
|
mainWin.show();
|
||||||
|
|
@ -480,29 +466,10 @@ ipcMain.on('chamar-fila', async () => {
|
||||||
mainWin.focus();
|
mainWin.focus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Se um atendimento já estiver em andamento, apenas mostra a janela principal.
|
|
||||||
// A lógica em renderer.js cuidará de exibir a tela de observação.
|
|
||||||
if (atendimentoAtualId) {
|
|
||||||
showMainWindow();
|
|
||||||
return; // Interrompe a execução aqui
|
|
||||||
}
|
|
||||||
|
|
||||||
// Se não houver atendimento em andamento, continua com a lógica original.
|
|
||||||
const countFila = async () => {
|
|
||||||
const proximos = JSON.parse(await floatingWin.webContents.executeJavaScript("localStorage.getItem('proximos')")) ?? [];
|
|
||||||
return proximos.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestData = async () => {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const colabId = await getSelectedOperatorId();
|
const colabId = await getSelectedOperatorId();
|
||||||
const token = await getAuthToken('token');
|
const token = await getAuthToken('token');
|
||||||
const url = apiUrl + 'chama-fila-app-colab/' + colabId; // URL de exemplo para enviar a solicitação
|
const url = apiUrl + 'chama-fila-app-colab/'+colabId; // URL de exemplo para enviar a solicitação
|
||||||
|
|
||||||
const request = net.request({
|
const request = net.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|
@ -523,28 +490,10 @@ ipcMain.on('chamar-fila', async () => {
|
||||||
response.on('end', () => {
|
response.on('end', () => {
|
||||||
try {
|
try {
|
||||||
const parsedData = JSON.parse(rawData);
|
const parsedData = JSON.parse(rawData);
|
||||||
|
|
||||||
if (response.statusCode === 200) {
|
if (response.statusCode === 200) {
|
||||||
mainWin.webContents.send('select-atend-id', parsedData.data);
|
mainWin.webContents.send('select-atend-id', parsedData.data);
|
||||||
if (parsedData.data && (parsedData.data.Status === 'Fila' || parsedData.data.Status === 'Chamado')) { showMainWindow(); } else
|
console.log(parsedData);
|
||||||
if (parsedData.data && parsedData.data.Status === 'Atendendo') {
|
|
||||||
let options2 = {
|
|
||||||
'title': 'Precisa finalizar antes de chamar o próximo.',
|
|
||||||
'message': 'Em andamento',
|
|
||||||
'detail': 'Já possui um atendimento em andamento (Atendendo: ' + parsedData.data.clientName + '), continue e finalize por favor!',
|
|
||||||
'type': 'error',
|
|
||||||
'noLink': true,
|
|
||||||
'buttons': ['Depois', 'Continuar'],
|
|
||||||
};
|
|
||||||
dialog.showMessageBox(floatingWin, options2).then(result => {
|
|
||||||
if (result.response) {
|
|
||||||
mainWin.webContents.send('show-observation');
|
|
||||||
showMainWindow();
|
|
||||||
} else {
|
|
||||||
mainWin.hide();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// console.log(parsedData);
|
|
||||||
} else {
|
} else {
|
||||||
console.error(`Erro na requisição: Status code ${response.statusCode}`, parsedData);
|
console.error(`Erro na requisição: Status code ${response.statusCode}`, parsedData);
|
||||||
// Lidar com o erro adequadamente, talvez enviando uma mensagem para a janela principal
|
// Lidar com o erro adequadamente, talvez enviando uma mensagem para a janela principal
|
||||||
|
|
@ -569,40 +518,10 @@ ipcMain.on('chamar-fila', async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
request.end();
|
request.end();
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let options = {
|
|
||||||
'title': 'Incie o atendimento quando o cliente chegar na sala.',
|
|
||||||
'message': 'Chamar um cliente da fila?',
|
|
||||||
'type': 'warning',
|
|
||||||
'noLink': true,
|
|
||||||
'buttons': ['Não', 'Sim'],
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
if (await countFila()) {
|
|
||||||
dialog.showMessageBox(floatingWin, options).then(result => {
|
|
||||||
if (result.response) {
|
|
||||||
requestData();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
requestData();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Ouve um pedido da janela flutuante para forçar a atualização da contagem
|
ipcMain.on('select-atend-id',(itemId)=>{
|
||||||
ipcMain.on('refresh-count', async () => {
|
|
||||||
if (floatingWin) {
|
|
||||||
const proximos = JSON.parse(await floatingWin.webContents.executeJavaScript("localStorage.getItem('proximos')")) ?? [];
|
|
||||||
floatingWin.webContents.send('update-count', proximos.length);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.on('select-atend-id', (itemId) => {
|
|
||||||
selectedItemId = itemId;
|
selectedItemId = itemId;
|
||||||
console.log(selectedItemId);
|
console.log(selectedItemId);
|
||||||
});
|
});
|
||||||
|
|
@ -614,9 +533,9 @@ ipcMain.on('iniciar-atendimento', async (event, itemId) => {
|
||||||
const colabId = await floatingWin.webContents.executeJavaScript("localStorage.getItem('idOperator')")
|
const colabId = await floatingWin.webContents.executeJavaScript("localStorage.getItem('idOperator')")
|
||||||
//TODO inicia o atendimento o id do atendimento deve ser requisitado do backend
|
//TODO inicia o atendimento o id do atendimento deve ser requisitado do backend
|
||||||
|
|
||||||
const url = apiUrl + 'iniciar-atendimento/' + itemId; // URL para enviar a solicitação
|
const url = apiUrl + 'iniciar-atendimento/'+itemId; // URL de exemplo para enviar a solicitação
|
||||||
|
|
||||||
// envio de uma solicitação POST com o ID do item
|
// Simula o envio de uma solicitação POST com o ID do item
|
||||||
const request = net.request({
|
const request = net.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: url,
|
url: url,
|
||||||
|
|
@ -651,20 +570,6 @@ ipcMain.on('iniciar-atendimento', async (event, itemId) => {
|
||||||
// A janela principal já mudou a UI ao enviar o evento 'next-step'
|
// A janela principal já mudou a UI ao enviar o evento 'next-step'
|
||||||
});
|
});
|
||||||
|
|
||||||
// Ouve quando um atendimento é iniciado e notifica a janela flutuante
|
|
||||||
ipcMain.on('atendimento-iniciado', (event, itemId) => {
|
|
||||||
if (floatingWin) {
|
|
||||||
floatingWin.webContents.send('atendimento-status-changed', 'iniciado');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Ouve quando um atendimento é finalizado e notifica a janela flutuante
|
|
||||||
ipcMain.on('atendimento-finalizado', () => {
|
|
||||||
if (floatingWin) {
|
|
||||||
floatingWin.webContents.send('atendimento-status-changed', 'finalizado');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Ouvir clique no botão "Salvar"
|
// Ouvir clique no botão "Salvar"
|
||||||
ipcMain.on('save-observation', async (event, { itemId, observation }) => {
|
ipcMain.on('save-observation', async (event, { itemId, observation }) => {
|
||||||
|
|
||||||
|
|
@ -676,7 +581,7 @@ ipcMain.on('save-observation', async (event, { itemId, observation }) => {
|
||||||
const colabId = await floatingWin.webContents.executeJavaScript("localStorage.getItem('idOperator')")
|
const colabId = await floatingWin.webContents.executeJavaScript("localStorage.getItem('idOperator')")
|
||||||
//TODO inicia o atendimento o id do atendimento deve ser requisitado do backend
|
//TODO inicia o atendimento o id do atendimento deve ser requisitado do backend
|
||||||
|
|
||||||
const url = apiUrl + 'finalizar-atendimento/' + itemId; // URL de exemplo para enviar a solicitação
|
const url = apiUrl + 'finalizar-atendimento/'+itemId; // URL de exemplo para enviar a solicitação
|
||||||
|
|
||||||
const fmData = JSON.stringify({
|
const fmData = JSON.stringify({
|
||||||
"colabId": colabId,
|
"colabId": colabId,
|
||||||
|
|
@ -732,7 +637,7 @@ ipcMain.on('drag-float-window', (event, { offsetX, offsetY }) => {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
ipcMain.on('logout', () => {
|
ipcMain.on('logout', ()=>{
|
||||||
mainWin.webContents.executeJavaScript(`
|
mainWin.webContents.executeJavaScript(`
|
||||||
localStorage.removeItem("idOperator");
|
localStorage.removeItem("idOperator");
|
||||||
localStorage.removeItem("selectedOperator");
|
localStorage.removeItem("selectedOperator");
|
||||||
|
|
@ -778,7 +683,6 @@ ipcMain.on('login-attempt', async (event, credentials) => {
|
||||||
// Login bem-sucedido
|
// Login bem-sucedido
|
||||||
loginWin.webContents.executeJavaScript(`
|
loginWin.webContents.executeJavaScript(`
|
||||||
localStorage.setItem("authToken", "${data.api_key}");
|
localStorage.setItem("authToken", "${data.api_key}");
|
||||||
localStorage.setItem("channel", "${data.channel}");
|
|
||||||
`).then(() => {
|
`).then(() => {
|
||||||
// Fecha a janela de login e abre a de seleção de operador
|
// Fecha a janela de login e abre a de seleção de operador
|
||||||
event.reply('login-response', { success: true });
|
event.reply('login-response', { success: true });
|
||||||
|
|
@ -960,66 +864,6 @@ ipcMain.on('token-exists', async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
ipcMain.on('sair', () => {
|
ipcMain.on('sair', ()=>{
|
||||||
let exec = `
|
app.exit();
|
||||||
localStorage.removeItem("idOperator");
|
|
||||||
localStorage.removeItem("selectedOperator");
|
|
||||||
localStorage.removeItem("salaOperator");
|
|
||||||
localStorage.removeItem("servicosOperator");
|
|
||||||
`;
|
|
||||||
|
|
||||||
let options = {
|
|
||||||
'title': 'Deseja realmente sair?',
|
|
||||||
'message': 'Tem certeza que deseja fechar o Auto Atendimento?',
|
|
||||||
'type': 'question',
|
|
||||||
'buttons': ['Não', 'Sim'],
|
|
||||||
'defaultId': 0,
|
|
||||||
'cancelId': 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
dialog.showMessageBox(floatingWin, options).then(result => {
|
|
||||||
if (result.response === 1) { // Se o usuário clicou em "Sim" (índice 1)
|
|
||||||
if (floatingWin) {
|
|
||||||
floatingWin.webContents.executeJavaScript(exec).then(() => { app.exit(); });
|
|
||||||
} else if (operatorWin) {
|
|
||||||
operatorWin.webContents.executeJavaScript(exec).then(() => { app.exit(); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
ipcMain.on('show-context-menu', (event) => {
|
|
||||||
const template = [
|
|
||||||
{
|
|
||||||
label: 'Chamar Fila',
|
|
||||||
click: () => {
|
|
||||||
// Lógica para chamar atendimento
|
|
||||||
if (floatingWin) {
|
|
||||||
ipcMain.emit('chamar-fila');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Trocar Colab',
|
|
||||||
click: () => {
|
|
||||||
// Lógica para chamar atendimento
|
|
||||||
if (floatingWin) {
|
|
||||||
ipcMain.emit('logout');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Sair',
|
|
||||||
click: () => {
|
|
||||||
// Lógica para fechar o aplicativo
|
|
||||||
if (floatingWin) {
|
|
||||||
ipcMain.emit('sair');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const menu = Menu.buildFromTemplate(template);
|
|
||||||
menu.popup({ window: floatingWin });
|
|
||||||
});
|
});
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'">
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'">
|
||||||
<title>Selecionar Operador</title>
|
<title>Selecionar Operador</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<script src="res/js/jquery/jquery.js"></script>
|
<script src="js/jquery/jquery.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="operator-page">
|
<body class="operator-page">
|
||||||
<div class="operator-container">
|
<div class="operator-container">
|
||||||
|
|
@ -29,10 +29,8 @@
|
||||||
<script>
|
<script>
|
||||||
$(function(){
|
$(function(){
|
||||||
let opse = localStorage.getItem('selectedOperator');
|
let opse = localStorage.getItem('selectedOperator');
|
||||||
let vs = localStorage.getItem('version');
|
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
$('span.op').text(opse);
|
$('span.op').text(opse);
|
||||||
$('#version').text(vs);
|
|
||||||
},2000);
|
},2000);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ const operatorSelect = document.getElementById('operator-select');
|
||||||
const selectButton = document.getElementById('select-button');
|
const selectButton = document.getElementById('select-button');
|
||||||
const errorMessage = document.getElementById('error-message');
|
const errorMessage = document.getElementById('error-message');
|
||||||
const quitButton = document.getElementById('sair-button');
|
const quitButton = document.getElementById('sair-button');
|
||||||
const verionSpan = document.getElementById('version');
|
|
||||||
|
|
||||||
// Carrega a lista de operadores ao iniciar
|
// Carrega a lista de operadores ao iniciar
|
||||||
window.addEventListener('DOMContentLoaded', async () => {
|
window.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
|
@ -69,12 +68,6 @@ const selectedOperatorValue = operatorSelect.value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.electronAPI.showVersion((version) => {
|
|
||||||
verionSpan.textContent = `${version}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Recebe resposta do processo de seleção
|
// Recebe resposta do processo de seleção
|
||||||
window.electronAPI.onOperatorResponse((response) => {
|
window.electronAPI.onOperatorResponse((response) => {
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ const { contextBridge, ipcRenderer } = require('electron');
|
||||||
contextBridge.exposeInMainWorld('electronAPI', {
|
contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
getOperators: () => ipcRenderer.invoke('get-operators'),
|
getOperators: () => ipcRenderer.invoke('get-operators'),
|
||||||
selectOperator: (operatorName) => ipcRenderer.send('select-operator', operatorName),
|
selectOperator: (operatorName) => ipcRenderer.send('select-operator', operatorName),
|
||||||
showVersion: (version) => ipcRenderer.on('show-version', version),
|
|
||||||
onOperatorResponse: (callback) => ipcRenderer.on('operator-response', (_event, response) => callback(response)),
|
onOperatorResponse: (callback) => ipcRenderer.on('operator-response', (_event, response) => callback(response)),
|
||||||
quitApp : () => ipcRenderer.send('sair'),
|
quitApp : () => ipcRenderer.send('sair'),
|
||||||
});
|
});
|
||||||
|
|
@ -1,16 +1,15 @@
|
||||||
{
|
{
|
||||||
"name": "autoatendcolab",
|
"name": "electronjs",
|
||||||
"version": "1.0.7",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "autoatendcolab",
|
"name": "electronjs",
|
||||||
"version": "1.0.7",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron/remote": "^2.1.2",
|
"@electron/remote": "^2.1.2",
|
||||||
"electron-single-instance": "^0.0.2",
|
|
||||||
"electron-updater": "^6.6.2",
|
"electron-updater": "^6.6.2",
|
||||||
"jquery": "^3.7.1"
|
"jquery": "^3.7.1"
|
||||||
},
|
},
|
||||||
|
|
@ -2610,12 +2609,6 @@
|
||||||
"chokidar": "^3.5.2"
|
"chokidar": "^3.5.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/electron-single-instance": {
|
|
||||||
"version": "0.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/electron-single-instance/-/electron-single-instance-0.0.2.tgz",
|
|
||||||
"integrity": "sha512-HWZ0BsGpFRuUU+8Cpf0ecDHYOqptuUyjup62sYnkl19//DtysiTZzeIWO9YXdbow3JErti/Zyi2yHO2e0yn1ew==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/electron-updater": {
|
"node_modules/electron-updater": {
|
||||||
"version": "6.6.2",
|
"version": "6.6.2",
|
||||||
"resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-6.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-6.6.2.tgz",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "autoatendcolab",
|
"name": "autoatendcolab",
|
||||||
"version": "1.1.3",
|
"version": "1.0.3",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"isBuildNow": true,
|
"isBuildNow": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
@ -38,7 +38,6 @@
|
||||||
"description": "Sistema auxiliar para colaboradores de autoatendimento",
|
"description": "Sistema auxiliar para colaboradores de autoatendimento",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron/remote": "^2.1.2",
|
"@electron/remote": "^2.1.2",
|
||||||
"electron-single-instance": "^0.0.2",
|
|
||||||
"electron-updater": "^6.6.2",
|
"electron-updater": "^6.6.2",
|
||||||
"jquery": "^3.7.1"
|
"jquery": "^3.7.1"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,12 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
//carrega todos os atendimentos na fila
|
//carrega todos os atendimentos na fila
|
||||||
onLoadData: (callback) => ipcRenderer.on('load-data', (_event, data) => callback(data)),
|
onLoadData: (callback) => ipcRenderer.on('load-data', (_event, data) => callback(data)),
|
||||||
|
|
||||||
//carrega todos os atendimentoa via pusher
|
|
||||||
getPusherConfig: () => ipcRenderer.invoke('get-pusher-config'),
|
|
||||||
sendPusherEvent: (callback) => ipcRenderer.on('pusher-event-received', (_event, data) => callback(data)),
|
|
||||||
|
|
||||||
//seleciona o atendimento atual
|
//seleciona o atendimento atual
|
||||||
selectAtendID: (callback) => ipcRenderer.on('select-atend-id', (_event, data) => callback(data)),
|
selectAtendID: (callback) => ipcRenderer.on('select-atend-id', (_event, data) => callback(data)),
|
||||||
|
|
||||||
//inicia o atendimento atual
|
//inicia o atendimento atual
|
||||||
iniciaAtendimento: (itemId) => ipcRenderer.send('iniciar-atendimento', itemId),
|
iniciaAtendimento: (itemId) => ipcRenderer.send('iniciar-atendimento', itemId),
|
||||||
|
|
||||||
//notifica sobre o status do atendimento
|
|
||||||
atendimentoIniciado: (itemId) => ipcRenderer.send('atendimento-iniciado', itemId),
|
|
||||||
atendimentoFinalizado: () => ipcRenderer.send('atendimento-finalizado'),
|
|
||||||
|
|
||||||
showObservation: (callback) => ipcRenderer.on('show-observation', (_event) => callback() ),
|
|
||||||
//salva a observação do atendimento
|
//salva a observação do atendimento
|
||||||
saveObservation: (data) => ipcRenderer.send('save-observation', data),
|
saveObservation: (data) => ipcRenderer.send('save-observation', data),
|
||||||
|
|
||||||
|
|
|
||||||
148
renderer.js
148
renderer.js
|
|
@ -17,121 +17,61 @@ let selectedItemId = null;
|
||||||
let selectedItemName = '';
|
let selectedItemName = '';
|
||||||
|
|
||||||
window.electronAPI.onLoadData((data) => {
|
window.electronAPI.onLoadData((data) => {
|
||||||
nextButton.disabled = true;
|
if(!data){
|
||||||
if (!data) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Reseta a view para a lista sempre que os dados são carregados
|
// Reseta a view para a lista sempre que os dados são carregados
|
||||||
populateList(data[0]);
|
populateList(data[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function initializePusher() {
|
|
||||||
if (typeof window.electronAPI === 'undefined' || !window.electronAPI.getPusherConfig) {
|
|
||||||
console.error('electronAPI not available or getPusherConfig method missing.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pusherConfig = await window.electronAPI.getPusherConfig();
|
|
||||||
const PUSHER_APP_KEY = pusherConfig.appKey;
|
|
||||||
let host = pusherConfig.host;
|
|
||||||
|
|
||||||
const channelLocal = localStorage.getItem('channel');
|
|
||||||
const colabId = localStorage.getItem('idOperator');
|
|
||||||
|
|
||||||
//! checa se ja tem o colabId
|
|
||||||
if (channelLocal && colabId && PUSHER_APP_KEY) {
|
|
||||||
Pusher.logToConsole = true;
|
|
||||||
|
|
||||||
var pusher = new Pusher(PUSHER_APP_KEY, {
|
|
||||||
wsHost: host,
|
|
||||||
wsPort: 80,
|
|
||||||
wssPort: 443,
|
|
||||||
forceTLS: true,
|
|
||||||
enableStats: false,
|
|
||||||
enabledTransports: ['wss', 'ws'],
|
|
||||||
cluster: 'mt1'
|
|
||||||
});
|
|
||||||
|
|
||||||
let channel;
|
|
||||||
if (pusher.connection.state === 'connected') {
|
|
||||||
pusher.unsubscribe('chat.' + channelLocal + '_' + colabId);
|
|
||||||
}
|
|
||||||
|
|
||||||
channel = pusher.subscribe('chat.' + channelLocal + '_' + colabId);
|
|
||||||
|
|
||||||
channel.bind('message-sent', function (r) {
|
|
||||||
let data = r.data.fila.original;
|
|
||||||
let count = data.length;
|
|
||||||
console.log(data);
|
|
||||||
localStorage.setItem('proximos', JSON.stringify(data));
|
|
||||||
|
|
||||||
populateList(r.data.currentData.original);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
pusher.connection.bind('error', function (err) {
|
|
||||||
console.error('Pusher connection error: ', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Host de conexão: ', host);
|
|
||||||
} else {
|
|
||||||
console.warn('User not authenticated or Pusher APP_KEY not available. Private channel not subscribed.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
initializePusher();
|
|
||||||
|
|
||||||
//chama o proximo da fila ao abrir a janela de atendimentos
|
//chama o proximo da fila ao abrir a janela de atendimentos
|
||||||
window.electronAPI.selectAtendID((data) => {
|
window.electronAPI.selectAtendID((data)=>{
|
||||||
nextButton.disabled = true;
|
if(!data){
|
||||||
if (!data) {
|
|
||||||
queueNumber.innerHTML = 'Ninguem aguardando atendimento, fechando a janela em alguns segundos...';
|
queueNumber.innerHTML = 'Ninguem aguardando atendimento, fechando a janela em alguns segundos...';
|
||||||
|
setTimeout(() => {
|
||||||
|
window.close();
|
||||||
|
},5000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Reseta a view para a lista sempre que os dados são carregados ao clicar no botão para abrir a janela
|
// Reseta a view para a lista sempre que os dados são carregados ao clicar no botão para abrir a janela
|
||||||
populateList(data);
|
populateList(data);
|
||||||
showListView();
|
showListView();
|
||||||
|
|
||||||
// Garante que o item selecionado (ID e Nome) seja o que veio da chamada, sobrescrevendo o da lista.
|
|
||||||
selectedItemId = data.id ?? null;
|
selectedItemId = data.id ?? null;
|
||||||
selectedItemName = data.clientName ?? '';
|
|
||||||
|
|
||||||
//data.senhaGen
|
//data.senhaGen
|
||||||
queueNumber.innerHTML = data ? `NA VEZ: <u>${data.clientName.toUpperCase()}</u> - ${data.descricaoServico.toUpperCase()}` : 'Ninguem aguardando atendimento';
|
queueNumber.innerHTML = data ? `NA VEZ: <u>${data.clientName.toUpperCase()}</u> - ${data.descricaoServico.toUpperCase()}` : 'Ninguem aguardando atendimento';
|
||||||
selectedItemNameSpan.innerHTML = data ? `<u> ${data.clientName.toUpperCase()} </u> <i style="float:right;">[ ${data.senhaGen} ]</i>` : 'Ninguem aguardando atendimento';
|
selectedItemNameSpan.innerHTML = data ? `<u> ${data.clientName.toUpperCase()} </u> <i style="float:right;">[ ${data.senhaGen} ]</i>` : 'Ninguem aguardando atendimento';
|
||||||
});
|
|
||||||
|
|
||||||
window.electronAPI.showObservation(() => {
|
|
||||||
window.electronAPI.iniciaAtendimento(selectedItemId);
|
|
||||||
showObservationView(); // Muda para a tela de observação
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Função para popular a lista de itens
|
// Função para popular a lista de itens
|
||||||
function populateList(currentData) {
|
function populateList(currentData) {
|
||||||
const atendimentoEmAndamentoId = localStorage.getItem('atendimentoAtual');
|
|
||||||
const atendimentoEmAndamentoNome = localStorage.getItem('atendimentoAtualNome');
|
|
||||||
|
|
||||||
if (atendimentoEmAndamentoId) {
|
|
||||||
itemList.innerHTML = `<li>Atendimento com <strong>${(atendimentoEmAndamentoNome || '').toUpperCase()}</strong> em andamento.</li>`;
|
|
||||||
queueNumber.innerHTML = `EM ATENDIMENTO: <u>${(atendimentoEmAndamentoNome || '').toUpperCase()}</u>`;
|
|
||||||
nextButton.disabled = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let datastorage = localStorage.getItem('proximos');
|
let datastorage = localStorage.getItem('proximos');
|
||||||
|
nextButton.disabled = true;
|
||||||
|
|
||||||
// Adiciona os outros itens apenas para visualização (opcional)
|
// Adiciona os outros itens apenas para visualização (opcional)
|
||||||
const proximos = JSON.parse(datastorage);
|
const proximos = JSON.parse(datastorage);
|
||||||
itemList.innerHTML = '';
|
var count = 15;
|
||||||
|
|
||||||
setTimeout(() => {
|
itemList.innerHTML = ''; // Limpa a lista anterior
|
||||||
nextButton.disabled = !currentData;
|
if (!proximos || proximos.length === 0 || !currentData) {
|
||||||
}, 5000);
|
itemList.innerHTML = '<li>Fila vazia!</li>';
|
||||||
|
const dec_counter = setInterval(() => {
|
||||||
|
count = count -1;
|
||||||
|
counterStart.innerHTML = `[ ${count} ]`;
|
||||||
|
if (count <= 0 && currentData) {
|
||||||
|
counterStart.innerHTML = '';
|
||||||
|
nextButton.disabled = false;
|
||||||
|
clearInterval(dec_counter);
|
||||||
|
}
|
||||||
|
},1000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Seleciona o primeiro item por padrão (ou o próximo disponível)
|
// Seleciona o primeiro item por padrão (ou o próximo disponível)
|
||||||
// Aqui, vamos apenas pegar o primeiro da lista atual
|
// Aqui, vamos apenas pegar o primeiro da lista atual
|
||||||
const itemToProcess = proximos[0]; // Pega o primeiro item
|
const itemToProcess = proximos[0]; // Pega o primeiro item
|
||||||
if (itemToProcess) {
|
if (itemToProcess) {
|
||||||
|
|
||||||
selectedItemId = itemToProcess.id;
|
selectedItemId = itemToProcess.id;
|
||||||
selectedItemName = itemToProcess.clientName;
|
selectedItemName = itemToProcess.clientName;
|
||||||
const li = document.createElement('li');
|
const li = document.createElement('li');
|
||||||
|
|
@ -139,9 +79,20 @@ function populateList(currentData) {
|
||||||
li.dataset.id = itemToProcess.id; // Armazena o ID no elemento
|
li.dataset.id = itemToProcess.id; // Armazena o ID no elemento
|
||||||
li.classList.add('selected'); // Marca como selecionado visualmente (precisa de CSS)
|
li.classList.add('selected'); // Marca como selecionado visualmente (precisa de CSS)
|
||||||
itemList.appendChild(li);
|
itemList.appendChild(li);
|
||||||
|
|
||||||
|
const dec_counter = setInterval(() => {
|
||||||
|
count = count -1;
|
||||||
|
counterStart.innerHTML = `[ ${count} ]`;
|
||||||
|
if (count <= 0 && currentData) {
|
||||||
|
counterStart.innerHTML = '';
|
||||||
|
nextButton.disabled = false;
|
||||||
|
clearInterval(dec_counter);
|
||||||
|
}
|
||||||
|
},1000);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
itemList.innerHTML = '<li>Fila vazia!</li>';
|
itemList.innerHTML = '<li>Fila vazia!</li>';
|
||||||
nextButton.disabled = true;
|
nextButton.disabled = !currentData;
|
||||||
selectedItemId = null;
|
selectedItemId = null;
|
||||||
selectedItemName = '';
|
selectedItemName = '';
|
||||||
}
|
}
|
||||||
|
|
@ -156,25 +107,13 @@ function populateList(currentData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Verifica o estado ao carregar a janela
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
const atendimentoEmAndamentoId = localStorage.getItem('atendimentoAtual');
|
|
||||||
if (atendimentoEmAndamentoId) {
|
|
||||||
// Se um atendimento está em andamento, a tela de observação deve ser mostrada
|
|
||||||
selectedItemId = atendimentoEmAndamentoId;
|
|
||||||
selectedItemName = localStorage.getItem('atendimentoAtualNome');
|
|
||||||
selectedItemNameSpan.innerHTML = `<u> ${(selectedItemName || '').toUpperCase()} </u>`;
|
|
||||||
showObservationView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
//mostra a tela de listagem e permite iniciar o atendimento
|
//mostra a tela de listagem e permite iniciar o atendimento
|
||||||
function showListView() {
|
function showListView() {
|
||||||
listView.style.display = 'block';
|
listView.style.display = 'block';
|
||||||
encaminharView.style.display = 'none';
|
encaminharView.style.display = 'none';
|
||||||
observationView.style.display = 'none';
|
observationView.style.display = 'none';
|
||||||
observationText.value = ''; // Limpa a textarea
|
observationText.value = ''; // Limpa a textarea
|
||||||
|
// nextButton.disabled = !selectedItemId; // Habilita/desabilita baseado na seleção
|
||||||
}
|
}
|
||||||
|
|
||||||
showListView();
|
showListView();
|
||||||
|
|
@ -190,12 +129,6 @@ function showObservationView() {
|
||||||
// // Evento do botão "Iniciar atendimento"
|
// // Evento do botão "Iniciar atendimento"
|
||||||
nextButton.addEventListener('click', () => {
|
nextButton.addEventListener('click', () => {
|
||||||
if (selectedItemId !== null) {
|
if (selectedItemId !== null) {
|
||||||
// Salva o estado de atendimento no localStorage
|
|
||||||
localStorage.setItem('atendimentoAtual', selectedItemId);
|
|
||||||
localStorage.setItem('atendimentoAtualNome', selectedItemName);
|
|
||||||
|
|
||||||
// Notifica o main process e muda a view
|
|
||||||
window.electronAPI.atendimentoIniciado(selectedItemId);
|
|
||||||
window.electronAPI.iniciaAtendimento(selectedItemId);
|
window.electronAPI.iniciaAtendimento(selectedItemId);
|
||||||
showObservationView(); // Muda para a tela de observação
|
showObservationView(); // Muda para a tela de observação
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -205,7 +138,7 @@ nextButton.addEventListener('click', () => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logoutButton.addEventListener('click', () => {
|
logoutButton.addEventListener('click',()=>{
|
||||||
window.electronAPI.logoutApp();
|
window.electronAPI.logoutApp();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -214,13 +147,10 @@ logoutButton.addEventListener('click', () => {
|
||||||
saveButton.addEventListener('click', () => {
|
saveButton.addEventListener('click', () => {
|
||||||
const observation = observationText.value;
|
const observation = observationText.value;
|
||||||
if (selectedItemId !== null) {
|
if (selectedItemId !== null) {
|
||||||
// Limpa o estado de atendimento
|
|
||||||
localStorage.removeItem('atendimentoAtual');
|
|
||||||
localStorage.removeItem('atendimentoAtualNome');
|
|
||||||
window.electronAPI.atendimentoFinalizado();
|
|
||||||
|
|
||||||
window.electronAPI.saveObservation({ itemId: selectedItemId, observation: observation });
|
window.electronAPI.saveObservation({ itemId: selectedItemId, observation: observation });
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
// A janela será escondida pelo main process após salvar (conforme main.js)
|
||||||
|
// Se quiser resetar a view sem esconder, chame showListView() aqui.
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB |
File diff suppressed because one or more lines are too long
|
|
@ -78,13 +78,6 @@ body#floating{
|
||||||
animation: pulse-border .5s infinite;
|
animation: pulse-border .5s infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Nova classe para quando estiver em atendimento */
|
|
||||||
#float-button.em-atendimento {
|
|
||||||
background-color: var(--danger-color); /* Vermelho */
|
|
||||||
border: 4px solid var(--dark-danger-color);
|
|
||||||
animation: pulse-border .2s infinite; /* Pulso mais rápido */
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes pulse-border {
|
@keyframes pulse-border {
|
||||||
0% {
|
0% {
|
||||||
border-color: var(--medium-gold);
|
border-color: var(--medium-gold);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'">
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'">
|
||||||
<title>Update</title>
|
<title>Update</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<script src="res/js/jquery/jquery.js"></script>
|
<script src="js/jquery/jquery.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="login-page">
|
<body class="login-page">
|
||||||
<div class="login-container">
|
<div class="login-container">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue