added documentation

This commit is contained in:
Steffen Vogel 2010-10-04 22:37:29 +02:00
parent 767ad23145
commit 18213a1cfa
6 changed files with 59 additions and 21 deletions

View file

@ -32,7 +32,6 @@
<div id="content">
<div id="plot"></div>
<table id="move">
<tr>
<td>

View file

@ -25,7 +25,8 @@
*/
/**
* Entity
* Entity constructor
* @todo add validation
*/
var Entity = function(json) {
for (var i in json) {
@ -48,9 +49,8 @@ var Entity = function(json) {
/**
* Show and edit entity details
* @param entity
*/
Entity.prototype.showDetails = function(entity) {
Entity.prototype.showDetails = function() {
$('<div>')
.addClass('details')
.append(this.getDOM())
@ -63,10 +63,9 @@ Entity.prototype.showDetails = function(entity) {
/**
* Show from for new Channel
*
* @param type
* @todo
* @todo implement/test
*/
Entity.prototype.getDOM = function(type) {
Entity.prototype.getDOM = function() {
var properties = $('<table><thead><th>Key</th><th>Value</th></thead></table');
$.each(entity, function(key, value) {
@ -106,7 +105,12 @@ Entity.prototype.getDOM = function(type) {
// TODO optional properties
};
Entity.prototype.validate = function(entity) {
/**
* Validate Entity for required and optional properties and their values
* @return boolean
* @todo implement/test
*/
Entity.prototype.validate = function() {
var def = getDefinition(vz.definitions.entities, entity.type);
def.required.each(function(index, property) {
@ -123,6 +127,11 @@ Entity.prototype.validate = function(entity) {
return true;
};
/**
* Calls the callback function for the entity and all nested children
*
* @param cb callback function
*/
Entity.prototype.each = function(cb, parent) {
cb(this, parent);

View file

@ -119,7 +119,7 @@ vz.refresh = function() {
*/
vz.handleControls = function () {
var delta = vz.to - vz.from;
var middle = Math.round(vz.from + delta/2);
var middle = vz.from + delta/2;
switch(this.value) {
case 'move_last':
@ -137,13 +137,13 @@ vz.handleControls = function () {
break;
case 'zoom_reset':
vz.from = middle - Math.floor(defaultInterval/2);
vz.to = middle + Math.ceil(defaultInterval/2);
vz.from = middle - efaultInterval/2;
vz.to = middle + defaultInterval/2;
break;
case 'zoom_in':
vz.from += Math.floor(delta/4);
vz.to -= Math.ceil(delta/4);
vz.from += delta/4;
vz.to -= delta/4;
break;
case 'zoom_out':
@ -215,12 +215,12 @@ vz.entities.show = function() {
.append($('<td>')) // avg
.append($('<td>') // operations
.addClass('ops')
.append($('<input>')
/*.append($('<input>')
.attr('type', 'image')
.attr('src', 'images/information.png')
.attr('alt', 'details')
.bind('click', entity, function(event) { event.data.showDetails(); })
)
)*/
);
if (parent == null) {
@ -250,14 +250,14 @@ vz.entities.show = function() {
};
/**
* Load json data with given time window
* Load json data from the backend
*/
vz.data.load = function() {
vz.data.clear();
vz.entities.each(function(index, entity) {
entity.each(function(entity, parent) {
if (entity.active && entity.type != 'group') {
$.getJSON(vz.options.backendUrl + '/data/' + entity.uuid + '.json', { from: vz.from, to: vz.to, tuples: vz.options.tuples }, ajaxWait(function(json) {
$.getJSON(vz.options.backendUrl + '/data/' + entity.uuid + '.json', { from: Math.floor(vz.from), to: Math.ceil(vz.to), tuples: vz.options.tuples }, ajaxWait(function(json) {
vz.data.push({
data: json.data[0].tuples, // TODO check uuid
color: entity.color
@ -268,6 +268,9 @@ vz.data.load = function() {
});
};
/**
* Draws plot to container
*/
vz.drawPlot = function () {
vz.options.plot.xaxis.min = vz.from;
vz.options.plot.xaxis.max = vz.to;

View file

@ -107,6 +107,13 @@ $(document).ready(function() {
vz.uuids.add($.getUrlVar('uuid'));
}
if (vz.uuids.length == 0) {
$('#addUUID').dialog({
title: 'UUID hinzufügen',
width: 400
});
}
// start auto refresh timer
window.setInterval(vz.refresh, 5000);

View file

@ -25,12 +25,18 @@
*/
/**
* Property
* Property constructor
*/
var Property = function(key, value) {
};
/**
* Validate value
* @param value
* @return boolean
* @todo implement/test
*/
Property.prototype.validate = function(value) {
switch (property.type) {
case 'string':
@ -60,6 +66,10 @@ Property.prototype.validate = function(value) {
}
};
/**
*
* @todo implement/test
*/
Property.prototype.getDOM = function() {
switch (property.type) {
case 'string':

View file

@ -24,8 +24,8 @@
* volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Cookie & UUID related functions
/**
* Read UUIDs from cookie and add them to the array
*/
vz.uuids.parseCookie = function() {
if ($.getCookie('uuids')) {
@ -35,6 +35,9 @@ vz.uuids.parseCookie = function() {
}
};
/**
* Add given UUID and update cookie
*/
vz.uuids.add = function(uuid) {
if (vz.uuids.validate(uuid)) {
if (!vz.uuids.contains(uuid)) {
@ -50,9 +53,13 @@ vz.uuids.add = function(uuid) {
}
};
/**
* Remove UUID and update cookie
*/
vz.uuids.remove = function(uuid) {
console.log(vz.uuids.contains(uuid));
if (vz.uuids.contains(uuid)) {
vz.uuids.remove(uuid);
vz.uuids.splice(this.indexOf(uuid), 1); // remove uuid from array
$.setCookie('uuids', JSON.stringify(vz.uuids));
}
else {
@ -60,6 +67,9 @@ vz.uuids.remove = function(uuid) {
}
};
/**
* Validate UUID
*/
vz.uuids.validate = function(uuid) {
return new Boolean(uuid.match(/^[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}$/));
};