1
0
Fork 0
mirror of https://github.com/shouptech/tempgopher.git synced 2026-02-03 08:39:43 +00:00

Move append logic to separate function

Fixes #15
This commit is contained in:
Emma 2018-10-23 21:51:19 -06:00
parent f13c557b38
commit e3ec4803de
2 changed files with 116 additions and 112 deletions

View file

@ -60,15 +60,9 @@ function fahrenheitToCelsius(degree) {
return (degree - 32) * 5 / 9;
};
function renderThermostats() {
$.ajax({
url: jsconfig.baseurl + "/api/status/",
beforeSend: authHeaders
}).then(function(data) {
$("#thermostats").empty();
for (var key in data) {
function appendData(data) {
// Title of thermostat
var titleh = $("<h4></h4>").text(data[key].alias);
var titleh = $("<h4></h4>").text(data.alias);
var titlediv = $("<div></div>").addClass("row").append(titleh);
// Thermostat status
@ -77,18 +71,18 @@ function renderThermostats() {
// Display temperature
if (jsconfig.fahrenheit) {
var temp = celsiusToFahrenheit(parseFloat(data[key].temp)).toFixed(1) + "°F";
var temp = celsiusToFahrenheit(parseFloat(data.temp)).toFixed(1) + "°F";
} else {
var temp = parseFloat(data[key].temp).toFixed(1) + "°C";
var temp = parseFloat(data.temp).toFixed(1) + "°C";
}
var temph = $("<h2></h2>").text(temp);
var tempdiv = $("<div></div>").addClass("two columns").append(temph);
rowdiv.append(tempdiv);
// Display status
if (data[key].cooling) {
if (data.cooling) {
var statustext = "Cooling"
} else if (data[key].heating) {
} else if (data.heating) {
var statustext = "Heating"
} else {
var statustext = "Idle"
@ -99,7 +93,7 @@ function renderThermostats() {
// Display sensor config
$.ajax({
url: jsconfig.baseurl + "/api/config/sensors/" + data[key].alias,
url: jsconfig.baseurl + "/api/config/sensors/" + data.alias,
beforeSend: authHeaders
}).then(function(configData){
if (jsconfig.fahrenheit) {
@ -178,6 +172,16 @@ function renderThermostats() {
$("#thermostats").append(titlediv);
$("#thermostats").append(rowdiv);
});
}
function renderThermostats() {
$.ajax({
url: jsconfig.baseurl + "/api/status/",
beforeSend: authHeaders
}).then(function(data) {
$("#thermostats").empty();
for (var key in data) {
appendData(data[key])
};
});
};

View file

@ -8,7 +8,7 @@ import (
)
// Version is the current code version of tempgopher
const Version = "0.3.0"
const Version = "0.3.1-dev"
func main() {
var args struct {