forked from verdnatura/hedera-web
Production adjustments and bugs
This commit is contained in:
parent
66644104de
commit
7d484fcb7e
|
@ -1,4 +1,4 @@
|
||||||
hedera-web (1.405.67) stable; urgency=low
|
hedera-web (1.405.68) stable; urgency=low
|
||||||
|
|
||||||
* Initial Release.
|
* Initial Release.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "hedera-web",
|
"name": "hedera-web",
|
||||||
"version": "1.405.67",
|
"version": "1.405.68",
|
||||||
"description": "Verdnatura web page",
|
"description": "Verdnatura web page",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -2,17 +2,26 @@
|
||||||
/**
|
/**
|
||||||
* Time in seconds between every request.
|
* Time in seconds between every request.
|
||||||
*/
|
*/
|
||||||
var INTERVAL = 10;
|
var INTERVAL = 15;
|
||||||
|
|
||||||
var requestInterval = INTERVAL;
|
var requestInterval = INTERVAL;
|
||||||
var failedRequests = 0;
|
var failedRequests = 0;
|
||||||
var timeoutId = null;
|
var timeoutId = null;
|
||||||
var request = null;
|
var request = null;
|
||||||
var lastText = null;
|
var lastText;
|
||||||
var lastError = null;
|
var lastStatus;
|
||||||
|
var lastError;
|
||||||
|
|
||||||
function onBodyLoad ()
|
function onBodyLoad ()
|
||||||
{
|
{
|
||||||
|
setText ();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setText ()
|
||||||
|
{
|
||||||
|
lastText = null;
|
||||||
|
lastStatus = null;
|
||||||
|
lastError = null;
|
||||||
updateText ();
|
updateText ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +34,9 @@ function onSettingsClick ()
|
||||||
|
|
||||||
deviceId = prompt ('Enter the device identifier', deviceId);
|
deviceId = prompt ('Enter the device identifier', deviceId);
|
||||||
|
|
||||||
|
if (deviceId == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (deviceId)
|
if (deviceId)
|
||||||
localStorage.setItem ('hederaDeviceId', deviceId);
|
localStorage.setItem ('hederaDeviceId', deviceId);
|
||||||
else if (deviceId === '')
|
else if (deviceId === '')
|
||||||
|
@ -41,7 +53,7 @@ function onSettingsClick ()
|
||||||
request = null;
|
request = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateText ();
|
setText ();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateText ()
|
function updateText ()
|
||||||
|
@ -50,7 +62,7 @@ function updateText ()
|
||||||
|
|
||||||
if (!deviceId)
|
if (!deviceId)
|
||||||
{
|
{
|
||||||
display ('Device id not set', true);
|
display (null, null, 'Device id not set');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,27 +86,29 @@ function onRequestChange (request)
|
||||||
switch (request.status)
|
switch (request.status)
|
||||||
{
|
{
|
||||||
case 200:
|
case 200:
|
||||||
var json = JSON.parse (request.responseText);
|
var data = JSON.parse (request.responseText).data;
|
||||||
display (json.data);
|
display (data.displayText, data.status, null);
|
||||||
requestInterval = INTERVAL;
|
requestInterval = INTERVAL;
|
||||||
failedRequests = 0;
|
failedRequests = 0;
|
||||||
break;
|
break;
|
||||||
case 400:
|
case 400:
|
||||||
var json = JSON.parse (request.responseText);
|
var json = JSON.parse (request.responseText);
|
||||||
throw new Error (json.data.message);
|
throw new Error (json.data.message);
|
||||||
|
case 0:
|
||||||
|
throw new Error ('Connection lost');
|
||||||
default:
|
default:
|
||||||
throw new Error ('HTTP '+ request.status +': '+ request.statusText);
|
throw new Error ('HTTP '+ request.status +': '+ request.statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
display (e.message, true);
|
display (null, null, e.message);
|
||||||
console.error (e.message);
|
console.error (e.message);
|
||||||
failedRequests++;
|
failedRequests++;
|
||||||
|
|
||||||
if (failedRequests > 10 && requestInterval < 60)
|
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);
|
console.warn ('Request interval increased to %d seconds.', requestInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,33 +117,39 @@ function onRequestChange (request)
|
||||||
request = null;
|
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').textContent = '';
|
||||||
$('error').style.display = 'none';
|
$('error').style.display = 'none';
|
||||||
bgColor = 'green';
|
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);
|
||||||
var body = document.body;
|
body.style.backgroundColor = bgColor;
|
||||||
body.addEventListener ('transitionend', onTransitionEnd);
|
|
||||||
body.style.backgroundColor = bgColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastText = text;
|
lastText = text;
|
||||||
|
lastStatus = status;
|
||||||
lastError = error;
|
lastError = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +158,7 @@ function onTransitionEnd ()
|
||||||
var body = document.body;
|
var body = document.body;
|
||||||
body.removeEventListener ('transitionend', onTransitionEnd);
|
body.removeEventListener ('transitionend', onTransitionEnd);
|
||||||
body.style.backgroundColor = '';
|
body.style.backgroundColor = '';
|
||||||
|
body.className = lastStatus ? lastStatus : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function $ (elementId)
|
function $ (elementId)
|
||||||
|
|
|
@ -8,6 +8,18 @@ body
|
||||||
font-family: Sans;
|
font-family: Sans;
|
||||||
transition: background-color 500ms ease-in;
|
transition: background-color 500ms ease-in;
|
||||||
}
|
}
|
||||||
|
body.idle
|
||||||
|
{
|
||||||
|
background-color: #08d;
|
||||||
|
}
|
||||||
|
body.doing
|
||||||
|
{
|
||||||
|
background-color: #333;
|
||||||
|
}
|
||||||
|
body.done
|
||||||
|
{
|
||||||
|
background-color: #4a0;
|
||||||
|
}
|
||||||
#container
|
#container
|
||||||
{
|
{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
|
@ -6,14 +6,15 @@ class Production extends Vn\Web\JsonRequest
|
||||||
|
|
||||||
function run ($db)
|
function run ($db)
|
||||||
{
|
{
|
||||||
$row = $db->getObject (
|
$row = $db->getObject (
|
||||||
'SELECT displayText FROM vn.routeGate WHERE deviceId = #',
|
'SELECT displayText, status
|
||||||
[$_REQUEST['deviceId']]
|
FROM vn.routeGate WHERE deviceId = #',
|
||||||
);
|
[$_REQUEST['deviceId']]
|
||||||
|
);
|
||||||
|
|
||||||
if (!isset($row))
|
if (!isset($row))
|
||||||
throw new Vn\Lib\UserException ('Device not found');
|
throw new Vn\Lib\UserException ('Device not found');
|
||||||
|
|
||||||
return $row->displayText;
|
return $row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue