improved handling of plotting style for powersensors (fixes #89)

improved property handling in frontend
This commit is contained in:
Steffen Vogel 2011-08-01 01:59:34 +02:00
parent d510f7047d
commit 46c11577c1
11 changed files with 171 additions and 92 deletions

View file

@ -106,13 +106,6 @@
<td><label for="refresh"><img src="images/arrow_refresh.png" alt="" /> Automatisch aktualisieren</label></td>
<td><input type="checkbox" id="refresh" /> <span id="refresh-time"><span></td>
</tr>
<tr>
<td><img src="images/eye.png" alt="" /> Darstellung</td>
<td>
<label for="render-points"><input type="radio" id="render-points" name="render" value="points" /> Punkte</label>&nbsp;
<label for="render-lines"><input type="radio" id="render-lines" name="render" value="lines" /> Linien</label>
</td>
</tr>
</tbody>
</table>
<div><button name="options-save"><img src="images/save.png" alt="save" /> Einstellungen speichern</button></div>

View file

@ -97,9 +97,7 @@ vz.entities.showTable = function() {
vz.entities.sort(Entity.compare);
var c = 0; // for colors
this.each(function(entity, parent) {
entity.color = vz.options.plot.colors[c++ % vz.options.plot.colors.length];
$('#entity-list tbody').append(entity.getDOMRow(parent));
}, true); // recursive!

View file

@ -29,17 +29,14 @@
*/
var Entity = function(json) {
this.parseJSON(json);
if (this.active === undefined) {
this.active = true; // activate by default
}
};
Entity.colors = 0;
Entity.prototype.parseJSON = function(json) {
$.extend(true, this, json);
// parse children
if (this.children) {
for (var i = 0; i < this.children.length; i++) {
this.children[i].middleware = this.middleware; // children inherit parent middleware
@ -48,9 +45,27 @@ Entity.prototype.parseJSON = function(json) {
this.children.sort(Entity.compare);
}
// setting defaults
if (this.type !== undefined) {
this.definition = vz.capabilities.definitions.get('entities', this.type);
if (this.style === undefined) {
if (this.definition.style) {
this.style = this.definition.style;
}
else {
this.style = (this.definition.interpreter == 'Volkszaehler\\Interpreter\\SensorInterpreter') ? 'lines' : 'steps';
}
}
}
if (this.active === undefined) {
this.active = true; // activate by default
}
if (this.color === undefined) {
this.color = vz.options.plot.colors[Entity.colors++ % vz.options.plot.colors.length];
}
};
@ -143,14 +158,23 @@ Entity.prototype.getDOMDetails = function(edit) {
var data = $('<tbody>');
// general properties
var general = ['uuid', 'middleware', 'type', 'color', 'cookie'];
var general = ['title', 'type', 'uuid', 'middleware', 'color', 'style', 'active', 'cookie'];
var sections = ['required', 'optional'];
general.each(function(index, property) {
var definition = vz.capabilities.definitions.get('properties', property);
var title = (definition) ? definition.translation[vz.options.language] : property;
var value = this[property];
switch(property) {
case 'type':
var title = 'Typ';
var value = this.definition.translation[vz.options.language];
var icon = $('<img>').
attr('src', 'images/types/' + this.definition.icon)
.css('margin-right', 4);
var value = $('<span>')
.text(this.definition.translation[vz.options.language])
.prepend(icon);
break;
case 'middleware':
@ -164,8 +188,11 @@ Entity.prototype.getDOMDetails = function(edit) {
break;
case 'color':
var title = 'Farbe';
var value = '<span style="background-color: ' + this.color + '">' + this.color + '</span>';
var value = $('<span>')
.text(this.color)
.css('background-color', this.color)
.css('padding-left', 5)
.css('padding-right', 5);
break;
case 'cookie':
@ -173,9 +200,15 @@ Entity.prototype.getDOMDetails = function(edit) {
value = '<img src="images/' + ((this.cookie) ? 'tick' : 'cross') + '.png" alt="' + ((value) ? 'ja' : 'nein') + '" />';
break;
case 'active':
var title = 'Aktiv';
var value = '<img src="images/' + ((this.active) ? 'tick' : 'cross') + '.png" alt="' + ((this.active) ? 'ja' : 'nein') + '" />';
break;
case 'style':
switch (this.style) {
case 'lines': var value = 'Linien'; break;
case 'steps': var value = 'Stufen'; break;
case 'points': var value = 'Punkte'; break;
}
break;
}
data.append($('<tr>')
@ -191,10 +224,10 @@ Entity.prototype.getDOMDetails = function(edit) {
)
);
}, this);
sections.each(function(index, section) {
this.definition[section].each(function(index, property) {
if (this.hasOwnProperty(property)) {
if (this.hasOwnProperty(property) && !general.contains(property)) {
var definition = vz.capabilities.definitions.get('properties', property);
var title = definition.translation[vz.options.language];
var value = this[property];

View file

@ -29,7 +29,6 @@ vz.options = {
language: 'de',
precision: 2, // TODO update from middleware capabilities?
tuples: null, // automatically determined by plot size
render: 'lines',
refresh: false,
minTimeout: 3000, // minimum refresh time in ms
defaultInterval: 24*60*60*1000, // 1 day

View file

@ -458,10 +458,12 @@ vz.wui.drawPlot = function () {
data: entity.data.tuples,
color: entity.color,
lines: {
show: (vz.options.render == 'lines'),
steps: (entity.definition.interpreter == 'Volkszaehler\\Interpreter\\MeterInterpreter')
show: (entity.style == 'lines' || entity.style == 'steps'),
steps: (entity.style == 'steps')
},
points: { show: (vz.options.render == 'points') }
points: {
show: (entity.style == 'points')
}
};
series.push(serie);

View file

@ -26,6 +26,7 @@ namespace Volkszaehler\Controller;
use Volkszaehler\Model;
use Volkszaehler\Util;
use Volkszaehler\View;
use Volkszaehler\Definition;
/**
* Capabilities controller
@ -67,8 +68,8 @@ class CapabilitiesController extends Controller {
$this->view->setCaching('expires', time()+2*7*24*60*60); // cache for 2 weeks
}
$capabilities['definitions']['entities'] = \Volkszaehler\Definition\EntityDefinition::getJSON();
$capabilities['definitions']['properties'] = \Volkszaehler\Definition\PropertyDefinition::getJSON();
$capabilities['definitions']['entities'] = Definition\EntityDefinition::get();
$capabilities['definitions']['properties'] = Definition\PropertyDefinition::get();
}
if (count($capabilities) == 0) {

View file

@ -33,12 +33,12 @@ abstract class Definition {
/**
* @var string discriminator for database column
*/
protected $name;
public $name;
/**
* @var string title for UI
*/
protected $translation;
public $translation;
/**
* Hide default constructor
@ -69,7 +69,7 @@ abstract class Definition {
}
if (is_null($name)) {
return static::$definitions;
return array_values(static::$definitions);
}
elseif (static::exists($name)) {
return static::$definitions[$name];
@ -98,16 +98,14 @@ abstract class Definition {
*/
protected static function load() {
static::$definitions = array();
$json = Util\JSON::decode(file_get_contents(VZ_DIR . static::FILE));
foreach (self::getJSON() as $property) {
foreach ($json as $property) {
static::$definitions[$property->name] = new static($property);
}
}
public static function getJSON() {
return Util\JSON::decode(file_get_contents(VZ_DIR . static::FILE));
}
/*
* Setter & Getter
*/

View file

@ -28,8 +28,6 @@
[
{
"name" : "group",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "tolerance", "public"],
"icon" : "folder.png",
"interpreter" : "Volkszaehler\\Interpreter\\AggregatorInterpreter",
"model" : "Volkszaehler\\Model\\Aggregator",
@ -41,8 +39,6 @@
},
{
"name" : "user",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "tolerance", "public"],
"icon" : "user.png",
"interpreter" : "Volkszaehler\\Interpreter\\AggregatorInterpreter",
"model" : "Volkszaehler\\Model\\Aggregator",
@ -54,8 +50,6 @@
},
{
"name" : "building",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "tolerance", "public"],
"icon" : "house.png",
"interpreter" : "Volkszaehler\\Interpreter\\AggregatorInterpreter",
"model" : "Volkszaehler\\Model\\Aggregator",
@ -67,8 +61,8 @@
},
{
"name" : "power",
"required" : ["title", "resolution"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "cost", "public", "local"],
"required" : ["resolution"],
"optional" : ["tolerance", "cost", "local"],
"icon" : "bolt.png",
"unit" : "W",
"interpreter" : "Volkszaehler\\Interpreter\\MeterInterpreter",
@ -81,11 +75,11 @@
},
{
"name" : "powersensor",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "public", "local"],
"optional" : ["tolerance", "cost", "local"],
"icon" : "bolt.png",
"unit" : "W",
"interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter",
"style" : "steps",
"model" : "Volkszaehler\\Model\\Channel",
"translation" : {
"de" : "Stromsensor",
@ -95,8 +89,8 @@
},
{
"name" : "gas",
"required" : ["title", "resolution"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "cost", "public", "local"],
"required" : ["resolution"],
"optional" : ["tolerance", "cost", "local"],
"icon" : "flame.png",
"unit" : "m³/h",
"interpreter" : "Volkszaehler\\Interpreter\\MeterInterpreter",
@ -109,8 +103,8 @@
},
{
"name" : "water",
"required" : ["title", "resolution"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "cost", "public", "local"],
"required" : ["resolution"],
"optional" : ["tolerance", "cost", "local"],
"icon" : "waterdrop.png",
"unit" : "l/h",
"interpreter" : "Volkszaehler\\Interpreter\\MeterInterpreter",
@ -123,8 +117,7 @@
},
{
"name" : "temperature",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "public", "local"],
"optional" : ["tolerance", "local"],
"icon" : "thermometer.png",
"unit" : "°C",
"interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter",
@ -137,8 +130,7 @@
},
{
"name" : "pressure",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "public", "local"],
"optional" : ["tolerance", "local"],
"icon" : "cloud.png",
"unit" : "hPa",
"interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter",
@ -151,8 +143,7 @@
},
{
"name" : "humidity",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "public", "local"],
"optional" : ["tolerance", "local"],
"icon" : "rain.png",
"unit" : "%",
"interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter",
@ -165,8 +156,7 @@
},
{
"name" : "windspeed",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "public", "local"],
"optional" : ["tolerance", "local"],
"icon" : "propeller.png",
"unit" : "km/h",
"interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter",
@ -179,8 +169,7 @@
},
{
"name" : "radiation",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "resolution", "public", "local"],
"optional" : ["tolerance", "local", "resolution"],
"icon" : "radioactivity.png",
"unit" : "μSv",
"interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter",
@ -193,8 +182,7 @@
},
{
"name" : "luminosity",
"required" : ["title"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "public", "local"],
"optional" : ["tolerance", "local"],
"icon" : "sun.png",
"unit" : "cd",
"interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter",
@ -207,8 +195,8 @@
},
{
"name" : "workinghours",
"required" : ["title", "resolution"],
"optional" : ["description", "details:", "owner:", "address:", "tolerance", "public", "local"],
"required" : ["resolution"],
"optional" : ["tolerance", "local"],
"icon" : "clock.png",
"unit" : "h",
"interpreter" : "Volkszaehler\\Interpreter\\MeterInterpreter",

View file

@ -42,46 +42,72 @@ class EntityDefinition extends Definition {
*
* @var array
*/
protected $required = array();
public $required = array();
/**
* List of optional properties
*
* @var array
*/
protected $optional = array();
public $optional = array();
/**
* Classname of intepreter (see lib/Interpreter/)
*
* @var string
*/
protected $interpreter;
public $interpreter;
/**
* Style for plotting
*
* @var string (lines|points|steps)
*/
public $style;
/**
* Classname of model (see lib/Model/)
*
* @var string
*/
protected $model;
public $model;
/**
* Optional for Aggregator class entities
*
* @var string
*/
protected $unit;
public $unit;
/**
* Relative url to an icon
* @var string
*/
protected $icon;
public $icon;
/**
* @var array holds definitions
*/
protected static $definitions = NULL;
/**
* Properties required/optional by default for all Entity types
* @var array
*/
static protected $defaultRequired = array('title');
static protected $defaultOptional = array('description', 'public', 'color', 'active', 'style', 'details:', 'owner:', 'address:', 'link');
/**
* Constructor
*
* Adding default properties
*/
protected function __construct($object) {
parent::__construct($object);
$this->required = array_merge($this->required, self::$defaultRequired);
$this->optional = array_merge($this->optional, self::$defaultOptional);
}
/*
* Setter & Getter

View file

@ -52,22 +52,6 @@
"en" : "Public"
}
},
{
"name" : "active",
"type" : "boolean",
"translation" : {
"de" : "Aktiv",
"en" : "Active"
}
},
{
"name" : "local",
"type" : "string",
"translation" : {
"de" : "Lokale Adresse",
"en" : "Local Address"
}
},
{
"name" : "cost",
"type" : "float",
@ -366,5 +350,62 @@
"de" : "Hyperlink",
"en" : "Hyperlink"
}
},
{
"name" : "active",
"type" : "boolean",
"translation" : {
"de" : "Aktiv",
"en" : "Active"
}
},
{
"name" : "color",
"type" : "multiple",
"options" : [
"aqua",
"black",
"blue",
"fuchsia",
"gray",
"grey",
"green",
"lime",
"maroon",
"navy",
"olive",
"purple",
"red",
"silver",
"teal",
"white",
"yellow"
],
"translation" : {
"de" : "Farbe",
"en" : "color"
}
},
{
"name" : "style",
"type" : "multiple",
"options" : [
"lines",
"steps",
"points"
],
"translation" : {
"de" : "Style",
"en" : "Plotting style"
}
},
{
"name" : "local",
"type" : "string",
"pattern" : "\/^(http?|ftp):\/\/[a-z0-9-.]+\\.[a-z]{2,6}(\/\\S*)?$\/i", // url
"translation" : {
"de" : "Lokale Adresse",
"en" : "Local Address"
}
}
]

View file

@ -40,14 +40,14 @@ class PropertyDefinition extends Definition {
*
* @var string
*/
protected $type;
public $type;
/**
* Regex pattern to match if type == string
*
* @var string
*/
protected $pattern;
public $pattern;
/**
* Minimal value if type == integer or type == float
@ -55,7 +55,7 @@ class PropertyDefinition extends Definition {
*
* @var integer|float
*/
protected $min;
public $min;
/**
* Maximal value if type == integer or type == float
@ -63,7 +63,7 @@ class PropertyDefinition extends Definition {
*
* @var integer|float
*/
protected $max;
public $max;
/**
* List of possible choices if type == multiple
@ -71,7 +71,7 @@ class PropertyDefinition extends Definition {
*
* @var array
*/
protected $options = array();
public $options = array();
/**
* @var array holds definitions