Skip to content

Commit

Permalink
Add per-browser temp unit selection
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <dl6er@dl6er.de>
  • Loading branch information
DL6ER authored and PromoFaux committed Jun 2, 2020
1 parent 6e52ee4 commit 3c79358
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 46 deletions.
41 changes: 40 additions & 1 deletion scripts/pi-hole/js/footer.js
Expand Up @@ -164,7 +164,6 @@ function initTheme() {

// The theme selector is only available on the settings page
var theme_selector = $('#theme-selector');
console.log(theme_selector);
if (theme_selector !== null) {
theme_selector.change(function(){
themename = $(this).val();
Expand All @@ -174,6 +173,45 @@ function initTheme() {
}
}

function initCPUtemp() {
function setCPUtemp(unit) {
var temperature = parseFloat($("#rawtemp").text());
var displaytemp = $("#tempdisplay");
if (temperature !== NaN) {
switch (unit) {
case "K":
temperature = temperature + 273.15;
displaytemp.html(temperature.toFixed(1) + "&nbsp;&deg;K");
break;

case "F":
temperature = (temperature * 9/5) + 32;
displaytemp.html(temperature.toFixed(1) + "&nbsp;&deg;F");
break;

default:
displaytemp.html(temperature.toFixed(1) + "&nbsp;&deg;C");
break;
}
}
}
var tempunit = localStorage.getItem("tempunit");
if (tempunit === null) {
tempunit = "C";
}
setCPUtemp(tempunit);

// The theme selector is only available on the settings page
var tempunit_selector = $('#tempunit-selector');
if (tempunit_selector !== null) {
tempunit_selector.change(function(){
tempunit = $(this).val();
localStorage.setItem("tempunit", tempunit);
setCPUtemp(tempunit);
});
}
}

$(function () {
var enaT = $("#enableTimer");
var target = new Date(parseInt(enaT.html()));
Expand All @@ -190,6 +228,7 @@ $(function () {
applyCheckboxRadioStyle();
applyBoxedLayout();
initTheme();
initCPUtemp();

// Run check immediately after page loading ...
checkMessages();
Expand Down
31 changes: 1 addition & 30 deletions scripts/pi-hole/php/header.php
Expand Up @@ -49,22 +49,6 @@
$celsius *= 1e-3;
}

$kelvin = $celsius + 273.15;
$fahrenheit = ($celsius*9./5)+32.0;

if(isset($setupVars['TEMPERATUREUNIT']))
{
$temperatureunit = $setupVars['TEMPERATUREUNIT'];
}
else
{
$temperatureunit = "C";
}
// Override temperature unit setting if it is changed via Settings page
if(isset($_POST["tempunit"]))
{
$temperatureunit = $_POST["tempunit"];
}
// Get user-defined temperature limit if set
if(isset($setupVars['TEMPERATURE_LIMIT']))
{
Expand Down Expand Up @@ -326,20 +310,7 @@ function pidofFTL()
{
echo "text-vivid-blue";
}
echo "\"></i> Temp:&nbsp;";
if($temperatureunit === "F")
{
echo round($fahrenheit,1) . "&nbsp;&deg;F";
}
elseif($temperatureunit === "K")
{
echo round($kelvin,1) . "&nbsp;K";
}
else
{
echo round($celsius,1) . "&nbsp;&deg;C";
}
echo "</span>";
?>"\"></i> Temp:&nbsp;<span id="rawtemp" hidden><?php echo $celsius;?></span><span id="tempdisplay"></span><?php
}
}
else
Expand Down
29 changes: 14 additions & 15 deletions settings.php
Expand Up @@ -1111,19 +1111,6 @@ function convertseconds($argument)
<div class="box-body">
<div class="row">
<div class="col-md-12">
<h4>CPU Temperature Unit</h4>
<div>
<input type="radio" name="tempunit" value="C" id="tempunit_C" <?php if ($temperatureunit === "C"){ ?>checked<?php } ?>>
<label for="tempunit_C"><strong>Celsius</strong></label>
</div>
<div>
<input type="radio" name="tempunit" value="K" id="tempunit_K" <?php if ($temperatureunit === "K"){ ?>checked<?php } ?>>
<label for="tempunit_K"><strong>Kelvin</strong></label>
</div>
<div>
<input type="radio" name="tempunit" value="F" id="tempunit_F" <?php if ($temperatureunit === "F"){ ?>checked<?php } ?>>
<label for="tempunit_F"><strong>Fahrenheit</strong></label>
</div>
<h4>Administrator Email Address</h4>
<input type="email" class="form-control" name="adminemail" value="<?php echo htmlspecialchars($adminemail); ?>">
<input type="hidden" name="field" value="webUI">
Expand Down Expand Up @@ -1152,7 +1139,7 @@ function convertseconds($argument)
<div class="col-md-4">
<p>Checkbox and radio buttons</p>
</div>
<div class="col-md-6">
<div class="col-md-8">
<select id="iCheckStyle">
<option>material-red</option>
<option>material-pink</option>
Expand Down Expand Up @@ -1180,13 +1167,25 @@ function convertseconds($argument)
<div class="col-md-4">
<p>Theme</p>
</div>
<div class="col-md-6">
<div class="col-md-8">
<select id="theme-selector">
<option value="default-light">Pi-hole default theme (light, default)</option>
<option value="default-dark">Pi-hole midnight theme (dark)</option>
</select>
</div>
</div>
<div class="row">
<div class="col-md-4">
<p>CPU Temperature Unit</p>
</div>
<div class="col-md-8">
<select id="tempunit-selector">
<option value="C">Celsius</option>
<option value="K">Kelvin</option>
<option value="F">Fahrenheit</option>
</select>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div>
Expand Down

1 comment on commit 3c79358

@pralor-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/possible-to-persist-temperature-setting/37438/6

Please sign in to comment.