Add temperature unit getter to the helper class

This commit is contained in:
rmm 2024-05-17 15:05:17 +02:00
parent ee3692de4a
commit 66c059dff4

View File

@ -227,7 +227,6 @@ function install_mod {
msg "Backup of \"$pvemanagerlibjs\" saved to \"$BACKUP_DIR/pvemanagerlib.js.$timestamp\"." 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 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 # Expand space in StatusView
sed -i "/Ext.define('PVE\.node\.StatusView'/,/\},/ { sed -i "/Ext.define('PVE\.node\.StatusView'/,/\},/ {
s/\(bodyPadding:\) '[^']*'/\1 '20 15 20 15'/ s/\(bodyPadding:\) '[^']*'/\1 '20 15 20 15'/
@ -307,6 +306,21 @@ Ext.define('PVE.mod.TempHelper', {\n\
return value;\n\ return value;\n\
}\n\ }\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" });\n" "$pvemanagerlibjs"
sed -i "/^Ext.define('PVE.node.StatusView',/ { 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\ let tempIndex = coreKey.match(/\\\S+\\\s*(\\\d+)/);\n\
if (tempIndex !== null && tempIndex.length > 1) {\n\ if (tempIndex !== null && tempIndex.length > 1) {\n\
tempIndex = tempIndex[1];\n\ tempIndex = tempIndex[1];\n\
tempStr = \`\${cpuTempCaption}&nbsp;\${tempIndex}:&nbsp;<span style=\"\${tempStyle}\">\${Ext.util.Format.number(tempVal, '0.#')}$tempUnitSuffix</span>\`;\n\ tempStr = \`\${cpuTempCaption}&nbsp;\${tempIndex}:&nbsp;<span style=\"\${tempStyle}\">\${Ext.util.Format.number(tempVal, '0.#')}\${cpuTempHelper.getUnit()}</span>\`;\n\
} else {\n\ } else {\n\
tempStr = \`\${cpuTempCaption}:&nbsp;\${Ext.util.Format.number(tempVal, '0.#')}$tempUnitSuffix\`;\n\ tempStr = \`\${cpuTempCaption}:&nbsp;\${Ext.util.Format.number(tempVal, '0.#')}\${cpuTempHelper.getUnit()}\`;\n\
}\n\ }\n\
cpuTemps.push(tempStr);\n\ cpuTemps.push(tempStr);\n\
}\n\ }\n\
@ -447,7 +461,7 @@ Ext.define('PVE.mod.TempHelper', {\n\
if (!isNaN(tempCrit) && tempVal >= tempCrit) {\n\ if (!isNaN(tempCrit) && tempVal >= tempCrit) {\n\
tempStyle = 'color: red; font-weight: bold;';\n\ tempStyle = 'color: red; font-weight: bold;';\n\
}\n\ }\n\
const tempStr = \`Drive&nbsp;\${index + 1}:&nbsp;<span style=\"\${tempStyle}\">\${Ext.util.Format.number(tempVal, '0.#')}$tempUnitSuffix</span>\`;\n\ const tempStr = \`Drive&nbsp;\${index + 1}:&nbsp;<span style=\"\${tempStyle}\">\${Ext.util.Format.number(tempVal, '0.#')}\${tempHelper.getUnit()}</span>\`;\n\
temps.push(tempStr);\n\ temps.push(tempStr);\n\
}\n\ }\n\
} catch(e) { /*_*/ }\n\ } catch(e) { /*_*/ }\n\
@ -510,7 +524,7 @@ Ext.define('PVE.mod.TempHelper', {\n\
if (!isNaN(tempCrit) && tempVal >= tempCrit) {\n\ if (!isNaN(tempCrit) && tempVal >= tempCrit) {\n\
tempStyle = 'color: red; font-weight: bold;';\n\ tempStyle = 'color: red; font-weight: bold;';\n\
}\n\ }\n\
const tempStr = \`Drive&nbsp;\${index + 1}:&nbsp;<span style=\"\${tempStyle}\">\${Ext.util.Format.number(tempVal, '0.#')}$tempUnitSuffix</span>\`;\n\ const tempStr = \`Drive&nbsp;\${index + 1}:&nbsp;<span style=\"\${tempStyle}\">\${Ext.util.Format.number(tempVal, '0.#')}\${tempHelper.getUnit()}</span>\`;\n\
temps.push(tempStr);\n\ temps.push(tempStr);\n\
}\n\ }\n\
} catch(e) { /*_*/ }\n\ } catch(e) { /*_*/ }\n\