From 9aadc2007ac6ca4913885cb2a1e3561e2dae7364 Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Sun, 7 Oct 2018 19:42:01 -0600 Subject: [PATCH 1/4] Add form to UI --- html/js/thermostat.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/html/js/thermostat.js b/html/js/thermostat.js index 9f7c85b..9220ff2 100644 --- a/html/js/thermostat.js +++ b/html/js/thermostat.js @@ -35,7 +35,7 @@ function renderThermostats() { var statustext = "Idle" } var statusp = $("

").html(statustext); - var statusdiv = $("
").addClass("three columns").append(statusp); + var statusdiv = $("
").addClass("two columns").append(statusp); rowdiv.append(statusdiv); // Display sensor config @@ -43,23 +43,37 @@ function renderThermostats() { url: jsconfig.baseurl + "/api/config/sensors/" + data[key].alias }).then(function(configData){ if (jsconfig.fahrenheit) { - var hightemp = celsiusToFahrenheit(parseFloat(configData.hightemp)).toFixed(1) + "°F"; - var lowtemp = celsiusToFahrenheit(parseFloat(configData.lowtemp)).toFixed(1) + "°F"; + var degUnit = "°F"; + var hightemp = celsiusToFahrenheit(parseFloat(configData.hightemp)).toFixed(1); + var lowtemp = celsiusToFahrenheit(parseFloat(configData.lowtemp)).toFixed(1); } else { - var hightemp = parseFloat(configData.hightemp).toFixed(1) + "°C"; - var lowtemp = parseFloat(configData.lowtemp).toFixed(1) + "°C"; + var hightemp = parseFloat(configData.hightemp).toFixed(1); + var lowtemp = parseFloat(configData.lowtemp).toFixed(1); } - configText = "Chills for " + configData.coolminutes + " minutes when > " + hightemp + ".
"; - configText += "Heats for " + configData.heatminutes + " minutes when < " + lowtemp + "."; + + rp = '[0-9]+(\.[0-9]+)?' + + configText = "Chills for " + + " minutes when > " + + "" + degUnit + ".
"; + + configText += "Heats for " + + " minutes when < " + + "" + degUnit + ".
"; var configp = $("

").html(configText); - var configdiv = $("
").addClass("seven columns").append(configp); + var configdiv = $("
").addClass("five columns").append(configp); rowdiv.append(configdiv); + + var yesButton = $("").attr("type", "submit").addClass("button button-primary").text("✔").css("margin-right", "5px"); + var noButton = $("").addClass("button").text("✘"); + var buttonDiv = $("
").addClass("three columns").append(yesButton).append(noButton); + rowdiv.append(buttonDiv); }); // Add things back to the thermostat list $("#thermostats").append(titlediv); - $("#thermostats").append(rowdiv); + $("#thermostats").append($("
").append(rowdiv)); }; }); }; From cfb14d490d2d3ad1335434188f16e85b36520c1a Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Sun, 7 Oct 2018 21:30:34 -0600 Subject: [PATCH 2/4] Add ability to stop reloading whent yping in form --- html/js/thermostat.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/html/js/thermostat.js b/html/js/thermostat.js index 9220ff2..a9bc1a2 100644 --- a/html/js/thermostat.js +++ b/html/js/thermostat.js @@ -53,27 +53,32 @@ function renderThermostats() { rp = '[0-9]+(\.[0-9]+)?' - configText = "Chills for " + - " minutes when > " + - "" + degUnit + ".
"; + var cmIn = $("").attr("id", "cm" + configData.alias).val(configData.coolminutes).attr("size", "2").attr("pattern", rp).on('input', function(){window.clearInterval(rtHandle)}); + var htIn = $("").attr("id", "ht" + configData.alias).val(hightemp).attr("size", "4").attr("pattern", rp).on('input', function(){window.clearInterval(rtHandle)}); + var hmIn = $("").attr("id", "hm" + configData.alias).val(configData.heatminutes).attr("size", "2").attr("pattern", rp).on('input', function(){window.clearInterval(rtHandle)}); + var ltIn = $("").attr("id", "lt" + configData.alias).val(lowtemp).attr("size", "4").attr("pattern", rp).on('input', function(){window.clearInterval(rtHandle)}); - configText += "Heats for " + - " minutes when < " + - "" + degUnit + ".
"; + var configp = $("

").text("Chills for ").append(cmIn).append(" minutes when > ").append(htIn).append(degUnit).append($("
")); + configp.append("Heats for ").append(hmIn).append(" minutes when < ").append(ltIn).append(degUnit); - var configp = $("

").html(configText); var configdiv = $("
").addClass("five columns").append(configp); rowdiv.append(configdiv); var yesButton = $("").attr("type", "submit").addClass("button button-primary").text("✔").css("margin-right", "5px"); - var noButton = $("").addClass("button").text("✘"); + var noButton = $("").attr("id", "no" + configData.alias).addClass("button").text("✘"); var buttonDiv = $("
").addClass("three columns").append(yesButton).append(noButton); rowdiv.append(buttonDiv); - }); - // Add things back to the thermostat list - $("#thermostats").append(titlediv); - $("#thermostats").append($("
").append(rowdiv)); + // Add things back to the thermostat list + $("#thermostats").append(titlediv); + $("#thermostats").append($("
").append(rowdiv)); + + // Re-engage reload, and re-render the thermostat on clear + $("#no" + configData.alias).click(function() { + window.setInterval(renderThermostats, 60000); + renderThermostats(); + }); + }); }; }); }; @@ -89,4 +94,4 @@ function renderVersion() { $(document).ready(renderVersion); $(document).ready(renderThermostats); -setInterval(renderThermostats, 60000) +var rtHandle = window.setInterval(renderThermostats, 60000); From b18a11ecb38f88084ac176990f5ff145251dbb51 Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Sun, 7 Oct 2018 22:04:31 -0600 Subject: [PATCH 3/4] Add POST that doesn't work --- html/js/thermostat.js | 38 ++++++++++++++++++++++++++++---------- html/jsconfig.js | 2 +- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/html/js/thermostat.js b/html/js/thermostat.js index a9bc1a2..f0005dd 100644 --- a/html/js/thermostat.js +++ b/html/js/thermostat.js @@ -64,20 +64,38 @@ function renderThermostats() { var configdiv = $("
").addClass("five columns").append(configp); rowdiv.append(configdiv); - var yesButton = $("").attr("type", "submit").addClass("button button-primary").text("✔").css("margin-right", "5px"); - var noButton = $("").attr("id", "no" + configData.alias).addClass("button").text("✘"); - var buttonDiv = $("
").addClass("three columns").append(yesButton).append(noButton); - rowdiv.append(buttonDiv); + var yesButton = $("").addClass("button button-primary").text("✔").css("margin-right", "5px").click(function() { + $.ajax({ + type: "POST", + url: jsconfig.baseurl + "/api/config/sensors/", + data: JSON.stringify([{ + "id": configData.id, + "alias": configData.alias, + "hightemp": htIn.val(), + "lowtemp": ltIn.val(), + "heatgpio": configData.heatgpio, + "heatinvert": configData.heatInvert, + "heatminutes": hmIn.val(), + "coolgpio": configData.coolgpio, + "coolinvert": configData.coolinvert, + "coolminutes": cmIn.val(), + "verbose": configData.verbose + }]) + }) + }); - // Add things back to the thermostat list - $("#thermostats").append(titlediv); - $("#thermostats").append($("
").append(rowdiv)); - - // Re-engage reload, and re-render the thermostat on clear - $("#no" + configData.alias).click(function() { + var noButton = $("").addClass("button").text("✘").click(function() { window.setInterval(renderThermostats, 60000); renderThermostats(); }); + + var buttonDiv = $("
").addClass("three columns").append(yesButton).append(noButton); + rowdiv.append(buttonDiv); + var confForm = $("
").append(rowdiv); + + // Add things back to the thermostat list + $("#thermostats").append(titlediv); + $("#thermostats").append(confForm); }); }; }); diff --git a/html/jsconfig.js b/html/jsconfig.js index d435468..ca5fbc6 100644 --- a/html/jsconfig.js +++ b/html/jsconfig.js @@ -1,4 +1,4 @@ var jsconfig = { - baseurl: "http://foo.bar", + baseurl: "http://beerpi.home.shoup.io:8080", fahrenheit: true }; From a2f734ca444cae519f451961501c956101cdc4c4 Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Mon, 8 Oct 2018 06:00:52 -0600 Subject: [PATCH 4/4] It works I think --- html/js/thermostat.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/html/js/thermostat.js b/html/js/thermostat.js index f0005dd..136b9ff 100644 --- a/html/js/thermostat.js +++ b/html/js/thermostat.js @@ -2,6 +2,10 @@ function celsiusToFahrenheit(degree) { return degree * 1.8 + 32; } +function fahrenheitToCelsius(degree) { + return (degree - 32) * 5 / 9; +} + function renderThermostats() { $.ajax({ url: jsconfig.baseurl + "/api/status/" @@ -65,23 +69,32 @@ function renderThermostats() { rowdiv.append(configdiv); var yesButton = $("").addClass("button button-primary").text("✔").css("margin-right", "5px").click(function() { + if (jsconfig.fahrenheit) { + var newHT = fahrenheitToCelsius(parseFloat(htIn.val())); + var newLT = fahrenheitToCelsius(parseFloat(ltIn.val())); + } else { + var newHT = parseFloat(htIn.val()); + var newLT = parseFloat(ltIn.val()); + } $.ajax({ type: "POST", - url: jsconfig.baseurl + "/api/config/sensors/", + url: jsconfig.baseurl + "/api/config/sensors", data: JSON.stringify([{ "id": configData.id, "alias": configData.alias, - "hightemp": htIn.val(), - "lowtemp": ltIn.val(), + "hightemp": newHT, + "lowtemp": newLT, "heatgpio": configData.heatgpio, "heatinvert": configData.heatInvert, - "heatminutes": hmIn.val(), + "heatminutes": parseFloat(hmIn.val()), "coolgpio": configData.coolgpio, "coolinvert": configData.coolinvert, - "coolminutes": cmIn.val(), + "coolminutes": parseFloat(cmIn.val()), "verbose": configData.verbose }]) }) + window.setInterval(renderThermostats, 60000); + renderThermostats(); }); var noButton = $("").addClass("button").text("✘").click(function() { @@ -91,11 +104,11 @@ function renderThermostats() { var buttonDiv = $("
").addClass("three columns").append(yesButton).append(noButton); rowdiv.append(buttonDiv); - var confForm = $("
").append(rowdiv); + //var confForm = $("
").append(rowdiv); // Add things back to the thermostat list $("#thermostats").append(titlediv); - $("#thermostats").append(confForm); + $("#thermostats").append(rowdiv); }); }; });