diff --git a/core/class/Monitoring.class.php b/core/class/Monitoring.class.php index 9909f35e..3d3f2ef7 100644 --- a/core/class/Monitoring.class.php +++ b/core/class/Monitoring.class.php @@ -2627,7 +2627,11 @@ public function getCmdReplace(string $cmdName, array $cmdOptions, &$replace) { $replace[$cmdNamePrefix . '_averageHistory#'] = $isCmdObject ? $cmd->getConfiguration($cmdName . '_averageHistory') : '-'; $replace[$cmdNamePrefix . '_minHistory#'] = $isCmdObject ? $cmd->getConfiguration($cmdName . '_minHistory') : '-'; $replace[$cmdNamePrefix . '_maxHistory#'] = $isCmdObject ? $cmd->getConfiguration($cmdName . '_maxHistory') : '-'; - $replace[$cmdNamePrefix . '_tendance#'] = ($isCmdObject && $cmd->getConfiguration($cmdName . '_tendance', '') !== '') ? ' ' : ''; + // Utiliser htmlspecialchars pour échapper les attributs HTML afin d'éviter les conflits avec les guillemets + $tendanceIcon = ($isCmdObject && $cmd->getConfiguration($cmdName . '_tendance', '') !== '') + ? ' getConfiguration($cmdName . '_tendance') . '">' + : ''; + $replace[$cmdNamePrefix . '_tendance#'] = $tendanceIcon; } ]; diff --git a/desktop/js/Monitoring.js b/desktop/js/Monitoring.js index 88b4f41b..0e64252e 100644 --- a/desktop/js/Monitoring.js +++ b/desktop/js/Monitoring.js @@ -396,33 +396,61 @@ function printEqLogic(_eqLogic) { } } - buildSelectHost(_eqLogic.configuration.SSHHostId) + // Build SSH host select + const buildPromise = buildSelectHost(_eqLogic.configuration.SSHHostId) // Toggle add/edit button based on SSH host selection const sshHostSelect = document.querySelector('.sshmanagerHelper[data-helper="list"]') if (sshHostSelect) { + // Remove existing listener to avoid duplicates + sshHostSelect.removeEventListener('change', toggleSSHButtons) + // Attach listener sshHostSelect.addEventListener('change', toggleSSHButtons) - // Initialize button display - toggleSSHButtons({ currentTarget: sshHostSelect }) + + // Initialize button display - pass the value directly instead of waiting + if (buildPromise && buildPromise.then) { + buildPromise.then(() => { + toggleSSHButtons(_eqLogic.configuration.SSHHostId) + }) + } else { + // Fallback if buildSelectHost didn't return a promise + toggleSSHButtons(_eqLogic.configuration.SSHHostId) + } } } /** * Toggle between add and edit SSH buttons based on selection + * @param {Event|string|number} eventOrValue - Either a change event or a direct value (SSHHostId) */ -function toggleSSHButtons(event) { - const selectedValue = event.currentTarget.value +function toggleSSHButtons(eventOrValue) { + let selectedValue + + // Check if it's a direct value (string/number) or an event object + if (typeof eventOrValue === 'string' || typeof eventOrValue === 'number') { + selectedValue = eventOrValue + } else if (eventOrValue?.target || eventOrValue?.currentTarget) { + // It's an event, extract value from it + selectedValue = eventOrValue.target?.value ?? eventOrValue.currentTarget?.value ?? eventOrValue.value + } + + // If still no value, read directly from the select element as fallback + if (!selectedValue) { + const sshHostSelect = document.querySelector('.sshmanagerHelper[data-helper="list"]') + selectedValue = sshHostSelect?.value + } + const addBtn = document.querySelector('.sshmanagerHelper[data-helper="add"]') const editBtn = document.querySelector('.sshmanagerHelper[data-helper="edit"]') if (selectedValue && selectedValue !== '') { // Host selected → show edit, hide add - addBtn?.unseen() - editBtn?.seen() + if (addBtn) addBtn.style.display = 'none' + if (editBtn) editBtn.style.display = 'block' } else { // No host selected → show add, hide edit - addBtn?.seen() - editBtn?.unseen() + if (addBtn) addBtn.style.display = 'block' + if (editBtn) editBtn.style.display = 'none' } } diff --git a/plugin_info/info.json b/plugin_info/info.json index f68d7c2d..202af5de 100644 --- a/plugin_info/info.json +++ b/plugin_info/info.json @@ -1,7 +1,7 @@ { "id": "Monitoring", "name": "Monitoring", - "pluginVersion": "3.4.2", + "pluginVersion": "3.4.3", "description": { "fr_FR": "Plugin permettant le monitoring des équipements locaux et distants (via SSH). Le plugin affichera les informations systèmes d'équipements sous Linux ou Synology (Distribution, CPU, Mémoire, Disques, Swap).", "en_US": "Plugin to monitor local and remote equipments (through SSH). The plugin will display system informations from Linux or Synology (Distribution, CPU, Memory, Disks, Swap).",