0
1
Fork 0

Production adjustments and bugs

This commit is contained in:
Juan Ferrer Toribio 2018-01-17 12:49:09 +01:00
parent 66644104de
commit 7d484fcb7e
5 changed files with 70 additions and 36 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
hedera-web (1.405.67) stable; urgency=low
hedera-web (1.405.68) stable; urgency=low
* Initial Release.

View File

@ -1,6 +1,6 @@
{
"name": "hedera-web",
"version": "1.405.67",
"version": "1.405.68",
"description": "Verdnatura web page",
"license": "GPL-3.0",
"repository": {

View File

@ -2,17 +2,26 @@
/**
* Time in seconds between every request.
*/
var INTERVAL = 10;
var INTERVAL = 15;
var requestInterval = INTERVAL;
var failedRequests = 0;
var timeoutId = null;
var request = null;
var lastText = null;
var lastError = null;
var lastText;
var lastStatus;
var lastError;
function onBodyLoad ()
{
setText ();
}
function setText ()
{
lastText = null;
lastStatus = null;
lastError = null;
updateText ();
}
@ -25,6 +34,9 @@ function onSettingsClick ()
deviceId = prompt ('Enter the device identifier', deviceId);
if (deviceId == null)
return;
if (deviceId)
localStorage.setItem ('hederaDeviceId', deviceId);
else if (deviceId === '')
@ -41,7 +53,7 @@ function onSettingsClick ()
request = null;
}
updateText ();
setText ();
}
function updateText ()
@ -50,7 +62,7 @@ function updateText ()
if (!deviceId)
{
display ('Device id not set', true);
display (null, null, 'Device id not set');
return;
}
@ -74,27 +86,29 @@ function onRequestChange (request)
switch (request.status)
{
case 200:
var json = JSON.parse (request.responseText);
display (json.data);
var data = JSON.parse (request.responseText).data;
display (data.displayText, data.status, null);
requestInterval = INTERVAL;
failedRequests = 0;
break;
case 400:
var json = JSON.parse (request.responseText);
throw new Error (json.data.message);
case 0:
throw new Error ('Connection lost');
default:
throw new Error ('HTTP '+ request.status +': '+ request.statusText);
}
}
catch (e)
{
display (e.message, true);
display (null, null, e.message);
console.error (e.message);
failedRequests++;
if (failedRequests > 10 && requestInterval < 60)
{
requestInterval += parseInt (Math.random() * 10) + 1;
requestInterval += parseInt (Math.random() * INTERVAL) + 1;
console.warn ('Request interval increased to %d seconds.', requestInterval);
}
}
@ -103,33 +117,39 @@ function onRequestChange (request)
request = null;
}
function display (text, error)
function display (text, status, error)
{
var bgColor;
if (!error)
if (error)
{
text = lastText;
status = lastStatus;
}
if (text === lastText && status === lastStatus && error === lastError)
return;
var bgColor;
$('text').textContent = text;
if (error)
{
$('error').textContent = error;
$('error').style.display = 'block';
bgColor = 'red';
}
else
{
$('text').textContent = text;
$('error').textContent = '';
$('error').style.display = 'none';
bgColor = 'green';
}
else
{
$('text').textContent = 'Er';
$('error').textContent = text;
$('error').style.display = 'block';
bgColor = 'red';
}
if (text != lastText || lastError != error)
{
var body = document.body;
body.addEventListener ('transitionend', onTransitionEnd);
body.style.backgroundColor = bgColor;
}
var body = document.body;
body.addEventListener ('transitionend', onTransitionEnd);
body.style.backgroundColor = bgColor;
lastText = text;
lastStatus = status;
lastError = error;
}
@ -138,6 +158,7 @@ function onTransitionEnd ()
var body = document.body;
body.removeEventListener ('transitionend', onTransitionEnd);
body.style.backgroundColor = '';
body.className = lastStatus ? lastStatus : '';
}
function $ (elementId)

View File

@ -8,6 +8,18 @@ body
font-family: Sans;
transition: background-color 500ms ease-in;
}
body.idle
{
background-color: #08d;
}
body.doing
{
background-color: #333;
}
body.done
{
background-color: #4a0;
}
#container
{
width: 100%;

View File

@ -6,14 +6,15 @@ class Production extends Vn\Web\JsonRequest
function run ($db)
{
$row = $db->getObject (
'SELECT displayText FROM vn.routeGate WHERE deviceId = #',
[$_REQUEST['deviceId']]
);
$row = $db->getObject (
'SELECT displayText, status
FROM vn.routeGate WHERE deviceId = #',
[$_REQUEST['deviceId']]
);
if (!isset($row))
throw new Vn\Lib\UserException ('Device not found');
if (!isset($row))
throw new Vn\Lib\UserException ('Device not found');
return $row->displayText;
return $row;
}
}