forked from verdnatura/hedera-web
Page to display production routes, bugs solved
This commit is contained in:
parent
fa4dd86862
commit
3032850d58
|
@ -1,4 +1,4 @@
|
|||
hedera-web (1.405.25) stable; urgency=low
|
||||
hedera-web (1.405.26) stable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "hedera-web",
|
||||
"version": "1.405.25",
|
||||
"version": "1.405.26",
|
||||
"description": "Verdnatura web page",
|
||||
"license": "GPL-3.0",
|
||||
"repository": {
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=no"/>
|
||||
<meta name="mobile-web-app-capable" content="yes"/>
|
||||
<link rel="shortcut icon" href="image/favicon/favicon.ico"/>
|
||||
<link rel="icon" type="image/png" href="image/favicon/favicon.png"/>
|
||||
<link rel="icon" type="image/svg+xml" href="image/icon.svg" sizes="any"/>
|
||||
<link rel="manifest" href="manifest.json"/>
|
||||
<meta name="theme-color" content="#009688"/>
|
||||
<meta name="content-language" content="<?=$lang?>"/>
|
||||
|
||||
<script type="text/javascript" src="<?=$dir?>/main.js?<?=$version?>"></script>
|
||||
<link rel="stylesheet" type="text/css" href="<?=$dir?>/style.css?<?=$version?>"/>
|
||||
|
||||
<title>Production</title>
|
||||
</head>
|
||||
<body onload="onBodyLoad()">
|
||||
<button onclick="onSettingsClick()">
|
||||
<img src="image/icon/dark/preferences.svg" alt="Config"/>
|
||||
</button>
|
||||
<div id="container">
|
||||
<div id="child">
|
||||
<div id="text">Hi!</div>
|
||||
<div id="error"></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -3,8 +3,8 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<meta name="viewport" content="user-scalable=no"/>
|
||||
<link href="http://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css"/>
|
||||
<link rel="stylesheet" type="text/css" href="<?=$dir?>/style.css"/>
|
||||
<link href="//fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css"/>
|
||||
<link rel="stylesheet" type="text/css" href="<?=$dir?>/style.css?<?=$version?>"/>
|
||||
<title>Verdnatura</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<meta name="viewport" content="user-scalable=no"/>
|
||||
<link href="//fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css"/>
|
||||
<link rel="stylesheet" type="text/css" href="<?=$dir?>/style.css?version"/>
|
||||
<link rel="stylesheet" type="text/css" href="<?=$dir?>/style.css?<?=$version?>"/>
|
||||
<title>Verdnatura</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
class Production extends Vn\Web\JsonRequest
|
||||
{
|
||||
const PARAMS = ['deviceId'];
|
||||
|
||||
function run ($db)
|
||||
{
|
||||
$row = $db->getObject (
|
||||
'SELECT displayText FROM production WHERE deviceId = #',
|
||||
[$_REQUEST['deviceId']]
|
||||
);
|
||||
|
||||
if (!isset($row))
|
||||
throw new Vn\Lib\UserException ('Device not found');
|
||||
|
||||
return $row->displayText;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
$version = $this->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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue