diff --git a/debian/changelog b/debian/changelog index 62d9d372..d3894bc8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.405.67) stable; urgency=low +hedera-web (1.405.68) stable; urgency=low * Initial Release. diff --git a/package.json b/package.json index cd6acb2f..1e0bd2b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hedera-web", - "version": "1.405.67", + "version": "1.405.68", "description": "Verdnatura web page", "license": "GPL-3.0", "repository": { diff --git a/pages/production/main.js b/pages/production/main.js index 3cbb71b3..c872923e 100644 --- a/pages/production/main.js +++ b/pages/production/main.js @@ -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) diff --git a/pages/production/style.css b/pages/production/style.css index d5beb353..9bb6becd 100644 --- a/pages/production/style.css +++ b/pages/production/style.css @@ -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%; diff --git a/rest/misc/production.php b/rest/misc/production.php index 62ee72b4..91f7e0b6 100644 --- a/rest/misc/production.php +++ b/rest/misc/production.php @@ -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; } }