From 66c059dff484c0a33dc33e2f8098efe194f4df28 Mon Sep 17 00:00:00 2001 From: rmm Date: Fri, 17 May 2024 15:05:17 +0200 Subject: [PATCH] Add temperature unit getter to the helper class --- pve-mod-gui-sensors.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pve-mod-gui-sensors.sh b/pve-mod-gui-sensors.sh index fcc8844..153e15a 100644 --- a/pve-mod-gui-sensors.sh +++ b/pve-mod-gui-sensors.sh @@ -227,7 +227,6 @@ function install_mod { msg "Backup of \"$pvemanagerlibjs\" saved to \"$BACKUP_DIR/pvemanagerlib.js.$timestamp\"." local tempHelperCtorParams=$([[ "$TEMP_UNIT" = "F" ]] && echo '{srcUnit: PVE.mod.TempHelper.CELSIUS, dstUnit: PVE.mod.TempHelper.FAHRENHEIT}' || echo '{srcUnit: PVE.mod.TempHelper.CELSIUS, dstUnit: PVE.mod.TempHelper.CELSIUS}') - local tempUnitSuffix=$([[ "$TEMP_UNIT" = "F" ]] && echo "°F" || echo "°C") # Expand space in StatusView sed -i "/Ext.define('PVE\.node\.StatusView'/,/\},/ { s/\(bodyPadding:\) '[^']*'/\1 '20 15 20 15'/ @@ -307,6 +306,21 @@ Ext.define('PVE.mod.TempHelper', {\n\ return value;\n\ }\n\ },\n\ +\n\ + getUnit: function(plainText) {\n\ + switch (this.dstUnit) {\n\ + case this.self.CELSIUS:\n\ + return plainText !== true ? '\°C' : '\\\'C';\n\ +\n\ + case this.self.FAHRENHEIT:\n\\n\ + return plainText !== true ? '\°F' : '\\\'F';\n\ +\n\ + default:\n\ + Ext.raise({\n\ + msg: 'Unsupported destination temperature unit: ' + this.srcUnit,\n\ + });\n\ + }\n\ + },\n\ });\n" "$pvemanagerlibjs" sed -i "/^Ext.define('PVE.node.StatusView',/ { @@ -369,9 +383,9 @@ Ext.define('PVE.mod.TempHelper', {\n\ let tempIndex = coreKey.match(/\\\S+\\\s*(\\\d+)/);\n\ if (tempIndex !== null && tempIndex.length > 1) {\n\ tempIndex = tempIndex[1];\n\ - tempStr = \`\${cpuTempCaption} \${tempIndex}: \${Ext.util.Format.number(tempVal, '0.#')}$tempUnitSuffix\`;\n\ + tempStr = \`\${cpuTempCaption} \${tempIndex}: \${Ext.util.Format.number(tempVal, '0.#')}\${cpuTempHelper.getUnit()}\`;\n\ } else {\n\ - tempStr = \`\${cpuTempCaption}: \${Ext.util.Format.number(tempVal, '0.#')}$tempUnitSuffix\`;\n\ + tempStr = \`\${cpuTempCaption}: \${Ext.util.Format.number(tempVal, '0.#')}\${cpuTempHelper.getUnit()}\`;\n\ }\n\ cpuTemps.push(tempStr);\n\ }\n\ @@ -447,7 +461,7 @@ Ext.define('PVE.mod.TempHelper', {\n\ if (!isNaN(tempCrit) && tempVal >= tempCrit) {\n\ tempStyle = 'color: red; font-weight: bold;';\n\ }\n\ - const tempStr = \`Drive \${index + 1}: \${Ext.util.Format.number(tempVal, '0.#')}$tempUnitSuffix\`;\n\ + const tempStr = \`Drive \${index + 1}: \${Ext.util.Format.number(tempVal, '0.#')}\${tempHelper.getUnit()}\`;\n\ temps.push(tempStr);\n\ }\n\ } catch(e) { /*_*/ }\n\ @@ -510,7 +524,7 @@ Ext.define('PVE.mod.TempHelper', {\n\ if (!isNaN(tempCrit) && tempVal >= tempCrit) {\n\ tempStyle = 'color: red; font-weight: bold;';\n\ }\n\ - const tempStr = \`Drive \${index + 1}: \${Ext.util.Format.number(tempVal, '0.#')}$tempUnitSuffix\`;\n\ + const tempStr = \`Drive \${index + 1}: \${Ext.util.Format.number(tempVal, '0.#')}\${tempHelper.getUnit()}\`;\n\ temps.push(tempStr);\n\ }\n\ } catch(e) { /*_*/ }\n\