added darft of controller webinterface

This commit is contained in:
Steffen Vogel 2010-09-25 01:37:04 +02:00
parent b2c16229f7
commit f0ac7ce068
8 changed files with 258 additions and 29 deletions

View file

@ -31,14 +31,16 @@
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "tolerance"],
"interpreter" : "AggregatorInterpreter",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Gruppe"
},
{
"name" : "user",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "tolerance"],
"interpreter" : "AggregatorInterpreter",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Nutzer"
},
{
"name" : "power",
@ -46,7 +48,8 @@
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "MeterInterpreter",
"unit" : "kW/h",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Strom"
},
{
"name" : "gas",
@ -54,7 +57,8 @@
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "MeterInterpreter",
"unit" : "m³/h",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Gas"
},
{
"name" : "water",
@ -62,7 +66,8 @@
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "MeterInterpreter",
"unit" : "m³/h",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Wasser"
},
{
"name" : "temperature",
@ -70,7 +75,8 @@
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"unit" : "°C",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Temperatur"
},
{
"name" : "pressure",
@ -78,7 +84,8 @@
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"unit" : "hPa",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Luftdruck"
},
{
"name" : "humidity",
@ -86,7 +93,8 @@
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"unit" : "%",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Luftfeuchtigkeit"
},
{
"name" : "windspeed",
@ -94,20 +102,23 @@
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"unit" : "km/h",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Windgeschwindigkeit"
},
{
"name" : "radition",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Strahlung"
},
{
"name" : "luminosity",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance"],
"interpreter" : "SensorInterpreter",
"icon" : "" // TODO look for an icon
"icon" : "", // TODO look for an icon
"de_name" : "Lichtstärke"
}
]

View file

@ -31,54 +31,64 @@
"type" : "string",
"pattern" : "/[a-z0-9 ]/",
"min": 3,
"max" : 255
"max" : 255,
"de_name" : "Titel"
},
{
"name" : "description",
"type" : "string",
"type" : "text",
"pattern" : "/[a-z0-9 ]/", // TODO add whitespaces as \t \n \r
"max" : 255 // TODO allowed column size in database?
"max" : 255, // TODO allowed column size in database?
"de_name" : "Beschreibung"
},
{
"name" : "cost",
"type" : "float",
"min" : 0
"min" : 0,
"de_name" : "Kosten"
},
{
"name" : "resolution",
"type" : "integer",
"min" : 1
"min" : 1,
"de_name" : "Auflösung"
},
{
"name" : "tolerance",
"type" : "float",
"min" : 0,
"max" : 1
"max" : 1,
"de_name" : "Toleranz"
},
{
"name" : "address:lat",
"type" : "float",
"min" : -90,
"max" : 90
"max" : 90,
"de_name" : "Latitude"
},
{
"name" : "address:lon",
"type" : "float",
"min" : -90,
"max" : 90
"max" : 90,
"de_name" : "Longitude"
},
{
"name" : "address:city",
"type" : "string",
"pattern" : "" // TODO add pattern
"pattern" : "", // TODO add pattern
"de_name" : "Stadt"
},
{
"name" : "address:houseno",
"type" : "string"
"type" : "string",
"de_name" : "Hausnummer"
},
{
"name" : "address:postal",
"type" : "string"
"type" : "string",
"de_name" : "Postleitzahl"
},
{
"name" : "address:state",
@ -273,29 +283,35 @@
"Wallis and Futuna Islands",
"Yemen",
"Zambia"
]
],
"de_name" : "Land"
},
{
"name" : "address:country",
"type" : "string"
"type" : "string",
"de_name" : "Staat"
},
{
"name" : "photo:url",
"type" : "string",
"pattern" : "" // TODO add pattern
"pattern" : "", // TODO add pattern
"de_name" : "Foto (URL)"
},
{
"name" : "cuuid",
"type" : "string",
"max" : 37
"max" : 37,
"de_name" : "Cotroller UUID"
},
{
"name" : "port",
"type" : "string",
"max" : 6
"max" : 6,
"de_name" : "Controller Pin"
},
{
"name" : "active",
"type" : "boolean"
"type" : "boolean",
"de_name" : "Aktiv?"
}
]

View file

@ -36,7 +36,7 @@ class PropertyDefinition extends Definition {
const FILE = '/lib/Definition/PropertyDefinition.json';
/**
* One of: string, integer, float, boolean, multiple
* One of: string, integer, float, boolean, multiple, text
*
* @var string
*/
@ -84,6 +84,7 @@ class PropertyDefinition extends Definition {
public function validateValue($value) {
switch ($this->type) {
case 'string':
case 'text':
$invalid = !is_string($value);
$invalid |= isset($this->pattern) && !preg_match($this->pattern, $value);
$invalid |= isset($this->min) && strlen($value) < $this->min;

1
controller/README Normal file
View file

@ -0,0 +1 @@
Dieses Verzeichnis enthällt den Sourcecode für die Messcontroller und deren Webfrontend.

42
controller/index.html Normal file
View file

@ -0,0 +1,42 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>volkszaehler.org - controller setup</title>
<script src="http://code.jquery.com/jquery-1.4.2.js"
type="text/javascript"></script>
<script src="script.js" type="text/javascript"></script>
</head>
<body>
<h1>volkszaehler.org - controller setup</h1>
<p>Hier können Sie ihren Stromzähler einrichten.</p>
<h2>Kanäle</h2>
<p>Derzeit sind folgende Zähler/Sensoren konfiguriert:</p>
<table id="channels">
<tr><th>#</th><th>UUID</th><th>Typ</th><th>Port</th><th>Value</th></tr>
</table>
<h2>Kanal hinzufügen</h2>
<p>Hier können sie einen neuen Kanal hinzufügen:</p>
<fieldset><legend>Allgemeine Eigenschaften</legend>
<table>
<tr>
<td><label for="type">Typ:</label></td>
<td><select name="type"></select></td>
</tr>
</table>
</fieldset>
<fieldset><legend>Spezifische Eigenschaften</legend>
<table id="properties">
</table>
</fieldset>
<hr />
<h5>Debug</h5>
<div style="border: 1px dashed grey; padding: 5px" id="debug"></div>
</body>
</html>

View file

@ -0,0 +1,51 @@
<?php
header('Content-type: application/json');
$filename = 'channels.csv';
$channels = array();
$methodMapping = array(
'POST' => 'add',
'DELETE' => 'delete',
'GET' => 'get'
);
$operation = (isset($_GET['operation'])) ? $_GET['operation'] : $methodMapping[$_SERVER['REQUEST_METHOD']];
// read channels
$fd = fopen($filename, 'r') or die('cant open file');
while (($data = fgetcsv($fd, 100, ';')) !== FALSE) {
$channels[] = array(
'uuid' => $data[0],
'type' => $data[1],
'port' => $data[2],
'last_value' => $data[3],
'last_timestamp' => $data[4]
);
}
fclose($fd);
if ($operation == 'add') {
$channels[] = array(
'uuid' => $_GET['uuid'],
'type' => $_GET['type'],
'port' => $_GET['port']
);
}
elseif ($operation == 'delete') {
$channels = array_filter($channels, function($channel) {
return $channel['uuid'] != $_GET['uuid'];
});
}
if (in_array($operation, array('delete', 'add'))) {
$fd = fopen($filename, 'w') or die('cant open file');
foreach ($channels as $channel) {
fputcsv($fd, $channel, ';');
}
fclose($fd);
}
// return all channels as JSON
echo json_encode($channels);
?>

View file

@ -0,0 +1,2 @@
1234;power;PD0;;
12345;power;PD0
1 1234;power;PD0;;
2 12345;power;PD0

105
controller/script.js Normal file
View file

@ -0,0 +1,105 @@
var backend = '../backend';
var controller = 'php/channel.php';
var entities;
var properties;
var channels;
$(document).ready(function() {
// get entities from backend
$.getJSON(backend + '/capabilities/definition/entity.json', function(data) {
entities = data.definition.entity;
for (var i in entities) {
$('select, [name=type]').append('<option value="' + entities[i].name + '">' + entities[i].de_name + '</option>');
}
});
// get properties from backend
$.getJSON(backend + '/capabilities/definition/property.json', function(data) {
properties = data.definition.property;
});
// get channels from controller
$.getJSON(controller, showChannels);
$('select').change(function(event) { showEntityForm(event.target.value); });
});
function showEntityForm(type) {
$('#properties').empty();
var type = getDefinition(entities, type);
for (var i in type.optional) {
var property = getDefinition(properties, type.optional[i]);
if (property) {
var input = getPropertyForm(property);
$('#properties').append('<tr><td><label for="' + property.name + '">' + property.de_name + ':</label></td><td>' + input + '</td></tr>')
}
}
}
function deleteChannel(uuid) {
$.get(controller, {operation: 'delete', uuid: uuid}, function(data) {
})
}
function addChannel() {
}
function addChannelBackend(channel, backendUrl) {
}
function addChannelController(uuid) {
}
function getDefinition(definition, type) {
for (var i in definition) {
if (definition[i].name == type) {
return definition[i];
}
}
}
function getPropertyForm(property) {
var input;
switch (property.type) {
case 'string':
case 'float':
case 'integer':
input = '<input type="text" name="' + property.name + '" maxlength="' + property.max + '" />';
break;
case 'text':
input = '<textarea name="' + property.name + '"></textarea>';
break;
case 'boolean':
input = '<input type="checkbox" name="' + property.name + '" value="true" />';
case 'multiple':
for (var k in property.options) {
options.push('<option>' + property.options[k] + '<\option>');
}
input = '<select name="' + property.name + '">' + options.join() + '</select>';
break;
default:
input = 'Error: unknown property type!';
}
return input;
}
function showChannels(data) {
channels = data;
for (var i in channels) {
$('#channels').append('<tr><td>' + i + '</td><td>' + channels[i].uuid + '</td><td>' + channels[i].type + '</td><td>' + channels[i].port + '</td><td>' + channels[i].value + '</td><td><input type="button" value="löschen" /></td></tr>');
}
}