From a22344d664e2e425476959403958a8e8bba01aca Mon Sep 17 00:00:00 2001 From: Pierre Marx Date: Thu, 4 Sep 2025 13:06:17 -0400 Subject: [PATCH] =?UTF-8?q?liste=20d=C3=A9roulante=20postes=20t=C3=A9l?= =?UTF-8?q?=C3=A9phoniques?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 12 ++++--- index.html | 5 ++- main.js | 37 +++++++++++++++++++++ renderer.js | 93 +++++++++++++++++++++++++++++++++++++++++++++++++---- styles.css | 15 +++++++++ 5 files changed, 151 insertions(+), 11 deletions(-) diff --git a/config.json b/config.json index e15bea0..fd0b49c 100644 --- a/config.json +++ b/config.json @@ -2,22 +2,25 @@ "agents": [ { "id": "agent1", + "accessCode": "AGENT001", "name": "Marie DUPONT", - "email": "marie.dupont@callcenter.fr", + "email": "AGENT001@callcenter.fr", "password": "demo123", "centresAssignes": ["centre1", "centre2", "centre3"] }, { "id": "agent2", + "accessCode": "AGENT002", "name": "Jean MARTIN", - "email": "jean.martin@callcenter.fr", + "email": "AGENT002@callcenter.fr", "password": "demo456", "centresAssignes": ["centre2", "centre4", "centre5"] }, { "id": "agent3", + "accessCode": "AGENT003", "name": "Sophie BERNARD", - "email": "sophie.bernard@callcenter.fr", + "email": "AGENT003@callcenter.fr", "password": "demo789", "centresAssignes": ["centre1", "centre3", "centre4", "centre5"] } @@ -109,6 +112,7 @@ "signalR": { "serverUrl": "http://10.90.20.201:8002/signalR", "serviceProvider": "RDVPREM", - "enabled": true + "enabled": true, + "terminalsSimulation": ["3001", "3002", "3003", "3004", "3005"] } } \ No newline at end of file diff --git a/index.html b/index.html index e1291d8..a47013e 100644 --- a/index.html +++ b/index.html @@ -17,8 +17,11 @@

Connexion Agent

- + + + +
diff --git a/main.js b/main.js index d8cf92a..6ccdeef 100644 --- a/main.js +++ b/main.js @@ -81,6 +81,9 @@ function initializeSignalR() { sendSignalRStatus(); }); + // Configurer les méthodes SignalR + setupSignalRMethods(); + // Démarrer la connexion startSignalRConnection(); @@ -91,6 +94,16 @@ function initializeSignalR() { } } +function setupSignalRMethods() { + // Écouter les événements IPBX + signalRConnection.on('IpbxEvent', (name, args) => { + if (!args) return; + const event = args[0]; + console.log('Événement IPBX reçu:', event); + // TODO: Gérer les événements d'appel + }); +} + async function startSignalRConnection() { try { signalRStatus = 'connecting'; @@ -171,6 +184,30 @@ ipcMain.handle('get-signalr-status', () => { return signalRStatus; }); +// Récupérer la liste des terminaux téléphoniques +ipcMain.handle('get-terminal-list', async () => { + // Mode simulation si SignalR non connecté + if (!signalRConnection || signalRStatus !== 'connected') { + console.log('SignalR non connecté, utilisation des terminaux de simulation'); + return config.signalR.terminalsSimulation || ['3001', '3002', '3003']; + } + + try { + console.log('Récupération des terminaux pour:', config.signalR.serviceProvider); + const terminals = await signalRConnection.invoke( + 'GetTerminalListByServiceProvider', + config.signalR.serviceProvider + ); + + console.log('Terminaux disponibles:', terminals); + return terminals || []; + } catch (error) { + console.error('Erreur récupération terminaux:', error); + // Retourner les terminaux de simulation en cas d'erreur + return config.signalR.terminalsSimulation || ['3001', '3002', '3003']; + } +}); + // Connexion agent ipcMain.handle('login-agent', (event, credentials) => { const agent = config.agents.find(a => diff --git a/renderer.js b/renderer.js index 60928d8..7c0561e 100644 --- a/renderer.js +++ b/renderer.js @@ -18,12 +18,17 @@ document.addEventListener('DOMContentLoaded', async () => { // Écouter les changements de statut SignalR ipcRenderer.on('signalr-status', (event, status) => { updateSignalRIndicator(status); + // Recharger les terminaux à chaque changement de statut + loadTerminals(); }); // Obtenir le statut initial SignalR const initialStatus = await ipcRenderer.invoke('get-signalr-status'); updateSignalRIndicator(initialStatus); + // Toujours charger les terminaux (simulation ou réels) + loadTerminals(); + // Vérifier si un agent est déjà connecté const agentData = await ipcRenderer.invoke('get-current-agent'); if (agentData) { @@ -66,19 +71,44 @@ document.addEventListener('DOMContentLoaded', async () => { async function handleLogin(e) { e.preventDefault(); - const email = document.getElementById('email').value; + const accessCode = document.getElementById('accessCode').value; const password = document.getElementById('password').value; + const terminal = document.getElementById('terminal').value; const errorDiv = document.getElementById('loginError'); - const result = await ipcRenderer.invoke('login-agent', { email, password }); + // Vérifier que le terminal est sélectionné et valide + if (!terminal) { + errorDiv.textContent = 'Veuillez sélectionner un poste téléphonique'; + return; + } - if (result.success) { - currentAgent = result.agent; - currentCentres = result.centres; + // Valider que le terminal existe dans la liste + if (!validateTerminal(terminal)) { + errorDiv.textContent = 'Poste téléphonique invalide. Veuillez choisir un poste de la liste.'; + return; + } + + // Sauvegarder le terminal sélectionné pour la prochaine fois + localStorage.setItem('last-terminal', terminal); + + // Pour l'instant, utiliser l'authentification locale (simulation) + // TODO: Intégrer l'authentification SignalR + const config = await ipcRenderer.invoke('get-config'); + const agent = config.agents.find(a => + a.email === `${accessCode}@callcenter.fr` && + a.password === password + ); + + if (agent) { + currentAgent = agent; + currentAgent.terminal = terminal; // Ajouter le terminal sélectionné + currentCentres = config.centres.filter(c => + agent.centresAssignes.includes(c.id) + ); errorDiv.textContent = ''; showMainPage(); } else { - errorDiv.textContent = result.message; + errorDiv.textContent = 'Code d\'accès ou mot de passe incorrect'; } } @@ -406,6 +436,57 @@ async function saveNotes() { } } +// === GESTION DES TERMINAUX === +let availableTerminals = []; // Stocker les terminaux disponibles + +async function loadTerminals() { + const terminalInput = document.getElementById('terminal'); + const terminalDatalist = document.getElementById('terminalList'); + if (!terminalInput || !terminalDatalist) return; + + try { + // Récupérer les terminaux depuis le serveur SignalR + const terminals = await ipcRenderer.invoke('get-terminal-list'); + availableTerminals = terminals || []; + + if (terminals && terminals.length > 0) { + // Vider la datalist + terminalDatalist.innerHTML = ''; + + // Ajouter chaque terminal comme option + terminals.forEach(terminal => { + const option = document.createElement('option'); + option.value = terminal; + terminalDatalist.appendChild(option); + }); + + // Restaurer la dernière sélection si disponible + const lastTerminal = localStorage.getItem('last-terminal'); + if (lastTerminal && terminals.includes(lastTerminal)) { + terminalInput.value = lastTerminal; + } + + // Activer l'input + terminalInput.disabled = false; + terminalInput.placeholder = 'Poste téléphonique (tapez pour filtrer)'; + } else { + terminalDatalist.innerHTML = ''; + terminalInput.placeholder = 'Aucun poste disponible'; + terminalInput.disabled = true; + } + } catch (error) { + console.error('Erreur chargement des terminaux:', error); + terminalDatalist.innerHTML = ''; + terminalInput.placeholder = 'Erreur de chargement'; + terminalInput.disabled = true; + } +} + +// Valider que le terminal saisi existe dans la liste +function validateTerminal(terminal) { + return availableTerminals.includes(terminal); +} + // === GESTION INDICATEUR SIGNALR === function updateSignalRStatus() { // Fonction appelée au chargement pour initialiser l'interface diff --git a/styles.css b/styles.css index 7737327..ade6485 100644 --- a/styles.css +++ b/styles.css @@ -120,6 +120,21 @@ body { border: 1px solid #ddd; border-radius: 5px; font-size: 14px; + background-color: white; +} + +#loginForm input:disabled { + background-color: #f5f5f5; + cursor: not-allowed; +} + +/* Style pour l'input avec datalist */ +#loginForm input[list] { + cursor: text; +} + +#loginForm input[list]::-webkit-calendar-picker-indicator { + display: none; } #loginForm button {