mirror of
https://github.com/pi-hole/web.git
synced 2025-12-25 05:05:33 +00:00
Use and set the unit on setupVars.conf option TEMPERATUREUNIT
New behavior!!! The temperature unit will be set GLOBALLY and not per browser. - if a TEMPERATUREUNIT is set in setupVars.conf file, the value will be used. - if there is no unit set in setupVars.conf, "C" will be used; - changing the value on the web interface WILL CHANGE setupVars.conf. - if the browser has an old value set on locastorage, this will be ingnored. Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
11
api.php
11
api.php
@@ -75,6 +75,17 @@ if (isset($_GET['enable']) && $auth) {
|
||||
$data = array_merge($data, $current);
|
||||
$data = array_merge($data, $latest);
|
||||
$data = array_merge($data, $branches);
|
||||
} elseif (isset($_GET['setTempUnit'])) {
|
||||
$unit = strtolower($_GET['setTempUnit']);
|
||||
if ($unit == 'c' || $unit == 'f' || $unit == 'k') {
|
||||
pihole_execute('-a -'.$unit);
|
||||
$result = 'success';
|
||||
} else {
|
||||
// invalid unit
|
||||
$result = 'error';
|
||||
}
|
||||
|
||||
$data = array_merge($data, array('result' => $result));
|
||||
} elseif (isset($_GET['list'])) {
|
||||
if (!$auth) {
|
||||
exit('Not authorized!');
|
||||
|
||||
@@ -160,10 +160,6 @@ function initCheckboxRadioStyle() {
|
||||
|
||||
function initCPUtemp() {
|
||||
function setCPUtemp(unit) {
|
||||
if (localStorage) {
|
||||
localStorage.setItem("tempunit", tempunit);
|
||||
}
|
||||
|
||||
var temperature = parseFloat($("#rawtemp").text());
|
||||
var displaytemp = $("#tempdisplay");
|
||||
if (!isNaN(temperature)) {
|
||||
@@ -185,11 +181,8 @@ function initCPUtemp() {
|
||||
}
|
||||
}
|
||||
|
||||
// Read from local storage, initialize if needed
|
||||
var tempunit = localStorage ? localStorage.getItem("tempunit") : null;
|
||||
if (tempunit === null) {
|
||||
tempunit = "C";
|
||||
}
|
||||
// Read the temperature unit from HTML code
|
||||
var tempunit = $("#tempunit").text();
|
||||
|
||||
setCPUtemp(tempunit);
|
||||
|
||||
@@ -200,6 +193,15 @@ function initCPUtemp() {
|
||||
tempunitSelector.on("change", function () {
|
||||
tempunit = $(this).val();
|
||||
setCPUtemp(tempunit);
|
||||
|
||||
// store the selected value on setupVars.conf
|
||||
$.getJSON("api.php?setTempUnit=" + tempunit + "&token=" + token, function (data) {
|
||||
if ("result" in data && data.result == "success") {
|
||||
utils.showAlert("success", "", "Temperature unit set to " + tempunit, "");
|
||||
} else {
|
||||
utils.showAlert("error", "", "", "Temperature unit not set");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,22 @@ function getTemperature()
|
||||
$limit = null;
|
||||
}
|
||||
|
||||
return array($celsius, $limit);
|
||||
// Get user-defined temperature limit if set
|
||||
if (isset($setupVars['TEMPERATUREUNIT'])) {
|
||||
switch (strtoupper($setupVars['TEMPERATUREUNIT'])) {
|
||||
case 'F':
|
||||
case 'K':
|
||||
$unit = strtoupper($setupVars['TEMPERATUREUNIT']);
|
||||
break;
|
||||
|
||||
default:
|
||||
$unit = 'C';
|
||||
}
|
||||
} else {
|
||||
$unit = 'C';
|
||||
}
|
||||
|
||||
return array($celsius, $limit, $unit);
|
||||
}
|
||||
|
||||
check_cors();
|
||||
@@ -113,7 +128,7 @@ $token = $_SESSION['token'];
|
||||
$maxlifetime = ini_get('session.gc_maxlifetime');
|
||||
|
||||
// Get temperature
|
||||
list($celsius, $temperaturelimit) = getTemperature();
|
||||
list($celsius, $temperaturelimit, $temperatureunit) = getTemperature();
|
||||
|
||||
// Get CPU load
|
||||
$loaddata = sys_getloadavg();
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
}
|
||||
echo '<span id="temperature"><i class="fa fa-w fa-fire '.$tempcolor.'" style="width: 1em !important"></i> ';
|
||||
echo 'Temp: <span id="rawtemp" hidden>'.$celsius.'</span>';
|
||||
echo '<span id="tempunit" hidden>'.$temperatureunit.'</span>';
|
||||
echo '<span id="tempdisplay"></span></span>';
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user