diff --git a/src/usr/local/www/widgets/javascript/thermal_sensors.js b/src/usr/local/www/widgets/javascript/thermal_sensors.js index 5193c9c0ed9..7eaee679295 100644 --- a/src/usr/local/www/widgets/javascript/thermal_sensors.js +++ b/src/usr/local/www/widgets/javascript/thermal_sensors.js @@ -18,8 +18,9 @@ * limitations under the License. */ -warningTemp = 9999; -criticalTemp = 100; +var warningTemp = 9999; +var criticalTemp = 100; +var widgetUnit = 'C'; ajaxBusy = false; function buildThermalSensorsData(thermalSensorsData, widgetKey, tsParams, firstTime) { @@ -86,14 +87,19 @@ function buildThermalSensorsDataGraph(thermalSensorsData, tsParams, widgetKey) { sensorName = getSensorFriendlyName(sensorName); } + if (tsParams.showFahrenheit) { + widgetUnit = 'F'; + thermalSensorValue = getFahrenheitValue(thermalSensorValue); + } + //build temperature item/row for a sensor var thermalSensorRow = '
' + - '
' + - '
' + - '
' + - '
' + - '' + sensorName + ': ' + '' + thermalSensorValue + ' °C'; + '
' + + '
' + + '
' + + '' + + '' + sensorName + ': ' + '' + thermalSensorValue + ' °' + widgetUnit; thermalSensorsHTMLContent = thermalSensorsHTMLContent + thermalSensorRow; @@ -134,7 +140,7 @@ function updateThermalSensorsDataGraph(thermalSensorsData, tsParams, widgetKey) sensorName = getSensorFriendlyName(sensorName); } - setTempProgress(i, thermalSensorValue, widgetKey); + setTempProgress(i, thermalSensorValue, widgetKey); } } @@ -157,6 +163,14 @@ function getThermalSensorValue(stringValue) { return (+parseFloat(stringValue) || 0).toFixed(1); } +function getFahrenheitValue(cels) { + return Math.ceil((cels * 1.8) + 32); +} + +function getCelsiusValue(fahr) { + return Math.floor((fahr - 32) / 1.8); +} + // Update the progress indicator // transition = true allows the bar to move at default speed, false = instantaneous function setTempProgress(bar, percent, widgetKey) { @@ -176,10 +190,9 @@ function setTempProgress(bar, percent, widgetKey) { barTempH = percent - criticalTemp; } - $('#' + 'temperaturebarL' + bar + widgetKey).css('width', barTempL + '%').attr('aria-valuenow', barTempL); $('#' + 'temperaturebarM' + bar + widgetKey).css('width', barTempM + '%').attr('aria-valuenow', barTempM); $('#' + 'temperaturebarH' + bar + widgetKey).css('width', barTempH + '%').attr('aria-valuenow', barTempH); - $('#' + 'temperaturemsg' + bar + widgetKey).html(percent + ' °C'); + $('#' + 'temperaturemsg' + bar + widgetKey).html(widgetUnit === 'F' ? getFahrenheitValue(percent) : percent); } diff --git a/src/usr/local/www/widgets/widgets/system_information.widget.php b/src/usr/local/www/widgets/widgets/system_information.widget.php index 858236efb43..dd5526cd677 100644 --- a/src/usr/local/www/widgets/widgets/system_information.widget.php +++ b/src/usr/local/www/widgets/widgets/system_information.widget.php @@ -138,6 +138,8 @@ $skipsysinfoitems = explode(",", $user_settings['widgets'][$widgetkey]['filter']); $rows_displayed = false; +// use the preference of the first thermal sensor widget, if it's available (false == empty) +$temp_use_f = (isset($user_settings['widgets']['thermal_sensors-0']) && !empty($user_settings['widgets']['thermal_sensors-0']['thermal_sensors_widget_show_fahrenheit'])); ?>
@@ -354,16 +356,16 @@ if (!in_array('temperature', $skipsysinfoitems)): $rows_displayed = true; ?> - + - +
-
+
- + ° @@ -608,12 +610,10 @@ function updateCPU(total, used) { } function updateTemp(x) { - if ($("#tempmeter")) { - $('[id="tempmeter"]').html(x + '°' + 'C'); - } - if ($('#tempPB')) { - setProgress('tempPB', parseInt(x)); - } + $("#tempmeter").html(function() { + return this.dataset.units === "F" ? parseInt(x * 1.8 + 32, 10) : x; + }); + setProgress('tempPB', parseInt(x)); } function updateDateTime(x) { diff --git a/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php b/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php index df3ed418c4f..e3b509df948 100644 --- a/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php +++ b/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php @@ -110,6 +110,14 @@ function getBoolValueFromConfig(&$configArray, $valueKey, $defaultValue, $widget //========================================================================= //save widget config settings on POST if ($_POST['widgetkey']) { + if (isset($_POST["thermal_sensors_widget_show_fahrenheit"])) { + // convert back to celcius + $_POST["thermal_sensors_widget_zone_warning_threshold"] = floor(($_POST["thermal_sensors_widget_zone_warning_threshold"] - 32) / 1.8); + $_POST["thermal_sensors_widget_zone_critical_threshold"] = floor(($_POST["thermal_sensors_widget_zone_critical_threshold"] - 32) / 1.8); + $_POST["thermal_sensors_widget_core_warning_threshold"] = floor(($_POST["thermal_sensors_widget_core_warning_threshold"] - 32) / 1.8); + $_POST["thermal_sensors_widget_core_critical_threshold"] = floor(($_POST["thermal_sensors_widget_core_critical_threshold"] - 32) / 1.8); + } + set_customwidgettitle($user_settings); saveThresholdSettings($user_settings, $_POST, "thermal_sensors_widget_zone_warning_threshold", "thermal_sensors_widget_zone_critical_threshold"); saveThresholdSettings($user_settings, $_POST, "thermal_sensors_widget_core_warning_threshold", "thermal_sensors_widget_core_critical_threshold"); @@ -119,6 +127,7 @@ function getBoolValueFromConfig(&$configArray, $valueKey, $defaultValue, $widget saveGraphDisplaySettings($user_settings, $_POST, "thermal_sensors_widget_show_full_sensor_name"); saveGraphDisplaySettings($user_settings, $_POST, "thermal_sensors_widget_pulsate_warning"); saveGraphDisplaySettings($user_settings, $_POST, "thermal_sensors_widget_pulsate_critical"); + saveGraphDisplaySettings($user_settings, $_POST, "thermal_sensors_widget_show_fahrenheit"); //write settings to config file save_widget_settings($_SESSION['Username'], $user_settings["widgets"], gettext("Saved thermal_sensors_widget settings via Dashboard.")); @@ -139,6 +148,7 @@ function getBoolValueFromConfig(&$configArray, $valueKey, $defaultValue, $widget $thermal_sensors_widget_showFullSensorName = getBoolValueFromConfig($user_settings, "thermal_sensors_widget_show_full_sensor_name", false, $widgetkey); $thermal_sensors_widget_pulsateWarning = getBoolValueFromConfig($user_settings, "thermal_sensors_widget_pulsate_warning", true, $widgetkey); $thermal_sensors_widget_pulsateCritical = getBoolValueFromConfig($user_settings, "thermal_sensors_widget_pulsate_critical", true, $widgetkey); +$thermal_sensors_widget_showFahrenheit = getBoolValueFromConfig($user_settings, "thermal_sensors_widget_show_fahrenheit", false, $widgetkey); //========================================================================= ?> @@ -156,40 +166,67 @@ function getBoolValueFromConfig(&$configArray, $valueKey, $defaultValue, $widget showRawOutput:, showFullSensorName:, pulsateWarning:, - pulsateCritical: + pulsateCritical:, + showFahrenheit: + }; - // --------------------- Centralized widget refresh system ------------------------------ - - // Callback function called by refresh system when data is retrieved - function ts_callback(s) { + $("#thermal_sensors_widget_show_fahrenheit").on("change", function(e) { + if (this.checked) { + $(".thermal_sensors_widget_unit").html(''); + $(".thermal_sensors_widget_range").html(''); + $("#thermal_sensors_widget_zone_warning_threshold").val(function(){return getFahrenheitValue(this.value);}); + $("#thermal_sensors_widget_zone_critical_threshold").val(function(){return getFahrenheitValue(this.value);}); + $("#thermal_sensors_widget_core_warning_threshold").val(function(){return getFahrenheitValue(this.value);}); + $("#thermal_sensors_widget_core_critical_threshold").val(function(){return getFahrenheitValue(this.value);}); + } else { + $(".thermal_sensors_widget_unit").html(''); + $(".thermal_sensors_widget_range").html(''); + $("#thermal_sensors_widget_zone_warning_threshold").val(function(){return getCelsiusValue(this.value);}); + $("#thermal_sensors_widget_zone_critical_threshold").val(function(){return getCelsiusValue(this.value);}); + $("#thermal_sensors_widget_core_warning_threshold").val(function(){return getCelsiusValue(this.value);}); + $("#thermal_sensors_widget_core_critical_threshold").val(function(){return getCelsiusValue(this.value);}); + } + }); + // --------------------- Centralized widget refresh system ------------------------------ + + // Callback function called by refresh system when data is retrieved + function ts_callback(s) { var thermalSensorsData = s || ""; buildThermalSensorsData(thermalSensorsData, "", tsParams, true); firstTime = false; - } - - // POST data to send via AJAX - var postdata = { - ajax: "ajax", - getThermalSensorsData : "1" - }; + } - // Create an object defining the widget refresh AJAX call - var tsObject = new Object(); - tsObject.name = "Gateways"; - tsObject.url = "/widgets/widgets/thermal_sensors.widget.php"; - tsObject.callback = ts_callback; - tsObject.parms = postdata; - tsObject.freq = 1; + // POST data to send via AJAX + var postdata = { + ajax: "ajax", + getThermalSensorsData : "1" + }; - // Register the AJAX object - register_ajax(tsObject); + // Create an object defining the widget refresh AJAX call + var tsObject = new Object(); + tsObject.name = "thermal-sensors"; + tsObject.url = "/widgets/widgets/thermal_sensors.widget.php"; + tsObject.callback = ts_callback; + tsObject.parms = postdata; + tsObject.freq = 5; - // --------------------------------------------------------------------------------------------------- + // Register the AJAX object + register_ajax(tsObject); + // --------------------------------------------------------------------------------------------------- }); //]]> +


@@ -203,33 +240,35 @@ function ts_callback(s) {
- +
-
+
-
+
-
+
-
+
@@ -257,6 +296,15 @@ function ts_callback(s) {
+
+ +
+ +
+
+