From 3032850d58bb3a1ba67f6ba5096e89b973b07972 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 4 Dec 2017 19:22:58 +0100 Subject: [PATCH] Page to display production routes, bugs solved --- debian/changelog | 2 +- package.json | 2 +- pages/production/main.js | 120 ++++++++++++++++++++++++++++++++++++ pages/production/style.css | 61 ++++++++++++++++++ pages/production/ui.php | 30 +++++++++ pages/update-browser/ui.php | 4 +- pages/version-menu/ui.php | 2 +- rest/core/account.php | 1 - rest/misc/production.php | 19 ++++++ web/html-service.php | 3 +- web/html.php | 6 +- 11 files changed, 240 insertions(+), 10 deletions(-) create mode 100644 pages/production/main.js create mode 100644 pages/production/style.css create mode 100644 rest/misc/production.php diff --git a/debian/changelog b/debian/changelog index e8be1eef..fee3a56f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.405.25) stable; urgency=low +hedera-web (1.405.26) stable; urgency=low * Initial Release. diff --git a/package.json b/package.json index c009cd4b..6fd0f08e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hedera-web", - "version": "1.405.25", + "version": "1.405.26", "description": "Verdnatura web page", "license": "GPL-3.0", "repository": { diff --git a/pages/production/main.js b/pages/production/main.js new file mode 100644 index 00000000..d48c53e0 --- /dev/null +++ b/pages/production/main.js @@ -0,0 +1,120 @@ + +/** + * Time in seconds between every request. + */ +var INTERVAL = 5; + +var requestInterval = INTERVAL; +var timeoutId = null; +var request = null; + +function onSettingsClick () +{ + var deviceId = localStorage.getItem ('hederaDeviceId'); + + if (deviceId == null) + deviceId = ''; + + deviceId = prompt ('Enter the device identifier', deviceId); + + if (deviceId) + localStorage.setItem ('hederaDeviceId', deviceId); + else if (deviceId === '') + localStorage.removeItem ('hederaDeviceId'); + + if (timeoutId != null) + { + clearTimeout (timeoutId); + timeoutId = null; + } + if (request) + { + request.abort (); + request = null; + } + + updateText (); +} + +function onBodyLoad () +{ + updateText (); +} + +function updateText () +{ + var deviceId = localStorage.getItem ('hederaDeviceId'); + + if (!deviceId) + { + display ('Device id not set', true); + return; + } + + var formData = new FormData (); + formData.append ('srv', 'json:misc/production'); + formData.append ('deviceId', deviceId); + + request = new XMLHttpRequest(); + request.open ('post', '', true); + request.onreadystatechange = + onRequestChange.bind (null, request); + request.send (formData); +} + +function onRequestChange (request) +{ + if (request.readyState !== 4) + return; + + try { + switch (request.status) + { + case 200: + var json = JSON.parse (request.responseText); + display (json.data); + requestInterval = INTERVAL; + break; + case 400: + var json = JSON.parse (request.responseText); + throw new Error (json.data.message); + default: + throw new Error ('HTTP '+ request.status +': '+ request.statusText); + } + } + catch (e) + { + display (e.message, true); + console.error (e.message); + + if (requestInterval < 60) + { + requestInterval += parseInt (Math.random() * 10) + 1; + console.warn ('Request interval increased to %d seconds.', requestInterval); + } + } + + timeoutId = setTimeout (updateText, requestInterval * 1000); + request = null; +} + +function display (text, error) +{ + if (!error) + { + $('text').textContent = text; + $('error').textContent = ''; + $('error').style.display = 'none'; + } + else + { + $('text').textContent = 'Er'; + $('error').textContent = text; + $('error').style.display = 'block'; + } +} + +function $ (elementId) +{ + return document.getElementById (elementId); +} diff --git a/pages/production/style.css b/pages/production/style.css new file mode 100644 index 00000000..2c424c77 --- /dev/null +++ b/pages/production/style.css @@ -0,0 +1,61 @@ +body +{ + background-color: #333; + position: absolute; + height: 100%; + width: 100%; + margin: 0; + font-family: Sans; +} +#container +{ + width: 100%; + height: 100%; + display: flex; + justify-content: center; + align-items: center; +} +#child +{ + max-width: 90%; + text-align: center; +} +#text +{ + color: white; + font-size: 20em; + text-align: center; + font-weight: bold; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; +} +#error +{ + color: red; + font-size: 3em; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; +} +button +{ + position: fixed; + margin: 1em; + padding: 1em; + top: 0; + right: 0; + background-color: transparent; + border: none; + cursor: pointer; +} +button:hover +{ + background-color: rgba(0, 0, 0, 0.4); + border-radius: .2em; +} +button > img +{ + height: 3em; + display: block; +} \ No newline at end of file diff --git a/pages/production/ui.php b/pages/production/ui.php index e69de29b..3a0c8897 100644 --- a/pages/production/ui.php +++ b/pages/production/ui.php @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + Production + + + +
+
+
Hi!
+
+
+
+ + \ No newline at end of file diff --git a/pages/update-browser/ui.php b/pages/update-browser/ui.php index 62f59301..cdf53f03 100755 --- a/pages/update-browser/ui.php +++ b/pages/update-browser/ui.php @@ -3,8 +3,8 @@ - - + + Verdnatura diff --git a/pages/version-menu/ui.php b/pages/version-menu/ui.php index 2e8c5a41..9e7665ca 100755 --- a/pages/version-menu/ui.php +++ b/pages/version-menu/ui.php @@ -4,7 +4,7 @@ - + Verdnatura diff --git a/rest/core/account.php b/rest/core/account.php index c924b823..f902bcc3 100755 --- a/rest/core/account.php +++ b/rest/core/account.php @@ -233,7 +233,6 @@ class SshConnection $args[$i] = self::escape ($args[$i]); $command = call_user_func_array ('sprintf', $args); - error_log ($command); return ssh2_exec ($this->connection, $command); } diff --git a/rest/misc/production.php b/rest/misc/production.php new file mode 100644 index 00000000..18bf548d --- /dev/null +++ b/rest/misc/production.php @@ -0,0 +1,19 @@ +getObject ( + 'SELECT displayText FROM production WHERE deviceId = #', + [$_REQUEST['deviceId']] + ); + + if (!isset($row)) + throw new Vn\Lib\UserException ('Device not found'); + + return $row->displayText; + } +} diff --git a/web/html-service.php b/web/html-service.php index 1600ee7d..1497e8b0 100644 --- a/web/html-service.php +++ b/web/html-service.php @@ -2,8 +2,6 @@ namespace Vn\Web; -require_once __DIR__.'/html.php'; - use Vn\Lib\Locale; /** @@ -92,6 +90,7 @@ class HtmlService extends Service $this->printHeader (); $dir = $basePath; + include_once __DIR__.'/html.php'; include ("./$basePath/ui.php"); } else diff --git a/web/html.php b/web/html.php index 5f1df6dc..39414add 100644 --- a/web/html.php +++ b/web/html.php @@ -1,11 +1,13 @@ getVersion(); + function getUrl ($fileName) { if (file_exists ($fileName)) - $mTime = '?'. strftime ('%G%m%d%H%M%S', filemtime ($fileName)); + $mTime = '?'. strftime ('%G%m%d%H%M%S', filemtime ($fileName)); else - $mTime = '?'. $this->getVersion (); + $mTime = '?'. $this->getVersion (); return $fileName.$mTime; }