Minor JS refactoring

MAX31855-EH
chrono 2013-11-30 00:08:04 +01:00
rodzic 30b450c9d3
commit 8f5967479d
3 zmienionych plików z 118 dodań i 134 usunięć

Wyświetl plik

@ -33,6 +33,7 @@ border-color: #000000;
.ds-num { .ds-num {
font-family: "LCDN"; font-family: "LCDN";
line-height: 38px;
} }
#main_status { #main_status {

Wyświetl plik

@ -1,4 +1,5 @@
var state = "IDLE"; var state = "IDLE";
var state_last = "";
var graph = [ 'profile', 'live']; var graph = [ 'profile', 'live'];
var points = []; var points = [];
var profiles = []; var profiles = [];
@ -257,8 +258,8 @@ $(document).ready(function()
}); });
}; };
ws_status.onclose = function() ws_status.onclose = function()
{ {
$.bootstrapGrowl("<span class=\"glyphicon glyphicon-exclamation-sign\"></span> <b>ERROR 1:</b><br/>Status Websocket not available", { $.bootstrapGrowl("<span class=\"glyphicon glyphicon-exclamation-sign\"></span> <b>ERROR 1:</b><br/>Status Websocket not available", {
ele: 'body', // which element to append to ele: 'body', // which element to append to
type: 'error', // (null, 'info', 'error', 'success') type: 'error', // (null, 'info', 'error', 'success')
@ -269,11 +270,7 @@ ws_status.onclose = function()
allow_dismiss: true, allow_dismiss: true,
stackup_spacing: 10 // spacing between consecutively stacked growls. stackup_spacing: 10 // spacing between consecutively stacked growls.
}); });
}; };
eta=0;
ws_status.onmessage = function(e) ws_status.onmessage = function(e)
{ {
@ -298,6 +295,7 @@ ws_status.onclose = function()
updateProgress(parseFloat(x.runtime)/parseFloat(x.totaltime)*100); updateProgress(parseFloat(x.runtime)/parseFloat(x.totaltime)*100);
$('#state').html(parseInt(parseFloat(x.runtime)/parseFloat(x.totaltime)*100) + '% ' + eta); $('#state').html(parseInt(parseFloat(x.runtime)/parseFloat(x.totaltime)*100) + '% ' + eta);
$('#target_temp').html(parseInt(x.target) + ' \xB0C');
} }
else else
@ -307,47 +305,36 @@ ws_status.onclose = function()
$('#state').html(state); $('#state').html(state);
} }
}
$('#act_temp').html(parseInt(x.temperature) + ' \xB0C'); $('#act_temp').html(parseInt(x.temperature) + ' \xB0C');
$('#heat').css("background-color", (x.heat > 0.5 ? "rgba(233, 28, 0, 0.84)" : "rgba(46, 12, 12, 0.62") ); $('#heat').css("background-color", (x.heat > 0.5 ? "rgba(233, 28, 0, 0.84)" : "rgba(46, 12, 12, 0.62") );
$('#air').css("background-color", (x.air > 0.5 ? "rgba(240, 199, 67, 0.84)" : "rgba(46, 38, 12, 0.62)") ); $('#air').css("background-color", (x.air > 0.5 ? "rgba(240, 199, 67, 0.84)" : "rgba(46, 38, 12, 0.62)") );
$('#cool').css("background-color", (x.cool > 0.5 ? "rgba(74, 159, 255, 0.84)" : "rgba(12, 28, 46, 0.62)") ); $('#cool').css("background-color", (x.cool > 0.5 ? "rgba(74, 159, 255, 0.84)" : "rgba(12, 28, 46, 0.62)") );
}
};
if (x.target == 0)
// Control Socket ////////////////////////////////
ws_control.onopen = function()
{ {
$('#target_temp').html('OFF');
}
else
{
$('#target_temp').html(parseInt(x.target) + ' \xB0C');
}
}
// Control Socket ////////////////////////////////
ws_control.onopen = function()
{
ws_control.onmessage = function(e) ws_control.onmessage = function(e)
{ {
console.log (e.data); console.log (e.data);
} }
console.log("Control Socket has been opened"); };
}
// Storage Socket /////////////////////////////// // Storage Socket ///////////////////////////////
ws_storage.onopen = function()
{
ws_storage.send('GET');
};
ws_storage.onopen = function()
{
console.log("Storage Socket has been opened");
ws_storage.onmessage = function(e) ws_storage.onmessage = function(e)
{ {
@ -357,24 +344,26 @@ ws_storage.onopen = function()
{ {
if(message.resp == "FAIL") if(message.resp == "FAIL")
{ {
if (confirm('Overwrite?')) { if (confirm('Overwrite?'))
{
message.force=true; message.force=true;
console.log("Sending: " + JSON.stringify(message)); console.log("Sending: " + JSON.stringify(message));
ws_storage.send(JSON.stringify(message)); ws_storage.send(JSON.stringify(message));
} else { }
else
{
//do nothing //do nothing
} }
} }
return; return;
} }
//the message is an array of profiles //the message is an array of profiles
//FIXME: this should be better, maybe a {"profiles": ...} container? //FIXME: this should be better, maybe a {"profiles": ...} container?
profiles = message; profiles = message;
//delete old options in select //delete old options in select
$('#e2') $('#e2').find('option').remove().end();
.find('option')
.remove()
.end();
// fill select with new options from websocket // fill select with new options from websocket
for (var i=0; i<profiles.length; i++) for (var i=0; i<profiles.length; i++)
@ -392,25 +381,19 @@ ws_storage.onopen = function()
} }
} };
console.log('Requesting stored profiles');
ws_storage.send('GET');
}
$("#e2").select2(
$("#e2").select2({ {
placeholder: "Select Profile", placeholder: "Select Profile",
allowClear: false allowClear: false
}); });
$("#e2").on("change", function(e) { $("#e2").on("change", function(e)
{
update_profile(e.val); update_profile(e.val);
}); });
} }
}); });

Wyświetl plik

@ -29,7 +29,7 @@
<div class="pull-left" style="margin: 14px"> <div class="pull-left" style="margin: 14px">
<span id="act_temp" class="display ds-num" style="color: #75890c">25 &deg;C</span> <span id="act_temp" class="display ds-num" style="color: #75890c">25 &deg;C</span>
<span id="target_temp" class="display ds-num">OFF</span> <span id="target_temp" class="display ds-num">OFF</span>
<span id="state" class="display" style="font-size: 14px; text-align: center; padding-right:0">Idle</span> <span id="state" class="display ds-num" style="text-align: center; padding-right:0">Idle</span>
<span id="heat" class="display" style="width: 35px; background: rgba(46, 12, 12, 0.62)">&nbsp;</span> <span id="heat" class="display" style="width: 35px; background: rgba(46, 12, 12, 0.62)">&nbsp;</span>
<span id="air" class="display" style="width: 35px; background: rgba(46, 38, 12, 0.62)">&nbsp;</span> <span id="air" class="display" style="width: 35px; background: rgba(46, 38, 12, 0.62)">&nbsp;</span>
<span id="cool" class="display" style="width: 35px; background: rgba(12, 28, 46, 0.62)">&nbsp;</span> <span id="cool" class="display" style="width: 35px; background: rgba(12, 28, 46, 0.62)">&nbsp;</span>