diff --git a/frontend/index.html b/frontend/index.html
index 928da25..7cb7a24 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -85,6 +85,13 @@
')
- .addClass((parent) ? 'child-of-entity-' + parent.uuid : '')
- .attr('id', 'entity-' + entity.uuid)
- .append($('')
- .css('background-color', entity.color)
- .css('width', 19)
- .append($('')
- .attr('type', 'checkbox')
- .attr('checked', entity.active)
- .bind('change', entity, function(event) {
- event.data.active = $(this).attr('checked');
- vz.plot.data.load();
- })
- )
- )
- .append($(' | ')
- .css('width', 20)
- )
- .append($(' | ')
- .append($('')
- .text(entity.title)
- .addClass('indicator')
- .addClass((entity.type == 'group') ? 'group' : 'channel')
- )
- )
- .append($(' | ').text(entity.type))
- .append($(' | ')) // min
- .append($(' | ')) // max
- .append($(' | ')) // avg
- .append($(' | ') // operations
- .addClass('ops')
- /*.append($('')
- .attr('type', 'image')
- .attr('src', 'images/information.png')
- .attr('alt', 'details')
- .bind('click', entity, function(event) { event.data.showDetails(); })
- )*/
- );
-
- if (parent == null) {
- $('td.ops', row).prepend($('')
- .attr('type', 'image')
- .attr('src', 'images/delete.png')
- .attr('alt', 'delete')
- .bind('click', entity, function(event) {
- vz.uuids.remove(event.data.uuid);
- vz.entities.load();
+ var row = $(' |
')
+ .addClass((parent) ? 'child-of-entity-' + parent.uuid : '')
+ .attr('id', 'entity-' + entity.uuid)
+ .append($('')
+ .css('background-color', entity.color)
+ .css('width', 19)
+ .append($('')
+ .attr('type', 'checkbox')
+ .attr('checked', entity.active)
+ .bind('change', entity, function(event) {
+ event.data.active = $(this).attr('checked');
+ vz.plot.data.load();
})
- );
- }
+ )
+ )
+ .append($(' | ')
+ .css('width', 20)
+ )
+ .append($(' | ')
+ .append($('')
+ .text(entity.title)
+ .addClass('indicator')
+ .addClass((entity.type == 'group') ? 'group' : 'channel')
+ )
+ )
+ .append($(' | ').text(entity.type))
+ .append($(' | ')) // min
+ .append($(' | ')) // max
+ .append($(' | ')) // avg
+ .append($(' | ') // operations
+ .addClass('ops')
+ /*.append($('')
+ .attr('type', 'image')
+ .attr('src', 'images/information.png')
+ .attr('alt', 'details')
+ .bind('click', entity, function(event) { event.data.showDetails(); })
+ )*/
+ );
+
+ if (parent == null) {
+ $('td.ops', row).prepend($('')
+ .attr('type', 'image')
+ .attr('src', 'images/delete.png')
+ .attr('alt', 'delete')
+ .bind('click', entity, function(event) {
+ vz.uuids.remove(event.data.uuid);
+ vz.entities.load();
+ })
+ );
+ }
- $('#entities tbody').append(row);
- });
+ $('#entities tbody').append(row);
});
// http://ludo.cubicphuse.nl/jquery-plugins/treeTable/doc/index.html
@@ -281,22 +310,30 @@ vz.entities.show = function() {
vz.plot.data.load();
};
+/**
+ * Overwritten each iterator for entity array
+ */
+vz.entities.each = function(cb) {
+ for (var i = 0; i < vz.entities.length; i++) {
+ vz.entities[i].each(cb);
+ }
+}
+
/**
* Load json data from the backend
*/
vz.plot.data.load = function() {
vz.plot.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: Math.floor(vz.from), to: Math.ceil(vz.to), tuples: vz.options.tuples }, ajaxWait(function(json) {
- vz.plot.data.push({
- data: json.data[0].tuples, // TODO check uuid
- color: entity.color
- });
- }, vz.plot.draw, 'data'));
- }
- });
+ $('#plot').html(' loading... '); // TODO insert loading animation
+ vz.entities.each(function(entity, parent) {
+ if (entity.active && entity.type != 'group') {
+ $.getJSON(vz.options.backendUrl + '/data/' + entity.uuid + '.json', { from: Math.floor(vz.from), to: Math.ceil(vz.to), tuples: vz.options.tuples }, waitAsync(function(json) {
+ vz.plot.data.push({
+ data: json.data[0].tuples, // TODO check uuid
+ color: entity.color
+ });
+ }, vz.plot.draw, 'data'));
+ }
});
};
@@ -306,6 +343,6 @@ vz.plot.data.load = function() {
vz.plot.draw = function () {
vz.options.plot.xaxis.min = vz.from;
vz.options.plot.xaxis.max = vz.to;
-
+
vz.plot.flot = $.plot($('#plot'), vz.plot.data, vz.options.plot);
};
diff --git a/frontend/javascripts/helper.js b/frontend/javascripts/helper.js
index 00f7656..b20f706 100644
--- a/frontend/javascripts/helper.js
+++ b/frontend/javascripts/helper.js
@@ -24,21 +24,25 @@
* volkszaehler.org. If not, see .
*/
-function ajaxWait(callback, finished, identifier) {
- if (!ajaxWait.counter) { ajaxWait.counter = new Array(); }
- if (!ajaxWait.counter[identifier]) { ajaxWait.counter[identifier] = 0; }
+function waitAsync(callback, finished, identifier) {
+ if (!waitAsync.counter) { waitAsync.counter = new Array(); }
+ if (!waitAsync.counter[identifier]) { waitAsync.counter[identifier] = 0; }
- ajaxWait.counter[identifier]++;
+ waitAsync.counter[identifier]++;
return function (data, textStatus) {
callback(data, textStatus);
- if (!--ajaxWait.counter[identifier]) {
+ if (!--waitAsync.counter[identifier]) {
finished();
}
};
}
+/*
+ * Array extensions
+ * according to js language specification ECMA 1.6
+ */
Array.prototype.indexOf = function(n) {
for (var i = 0, l = this.length; i < l; i++)
if (n == this[i]) return i;
diff --git a/frontend/javascripts/init.js b/frontend/javascripts/init.js
index dad09ab..b24053b 100644
--- a/frontend/javascripts/init.js
+++ b/frontend/javascripts/init.js
@@ -48,10 +48,7 @@ var vz = {
// definitions of entities & properties
// for validation, translation etc..
- definitions: {
- properties: {},
- entities: {}
- },
+ definitions: { },
// timeinterval to request
to: new Date().getTime(),
@@ -63,9 +60,9 @@ var vz = {
plot: {
colors: ['#83CAFF', '#7E0021', '#579D1C', '#FFD320', '#FF420E', '#004586', '#0084D1', '#C5000B', '#FF950E', '#4B1F6F', '#AECF00', '#314004'],
series: {
- lines: { show: false },
+ lines: { show: true },
points: {
- show: true,
+ show: false,
radius: 1,
//symbol: 'square'
symbol: function(ctx, x, y, radius, shadow) {
@@ -100,6 +97,8 @@ var vz = {
$(document).ready(function() {
// initialize user interface
vz.initInterface();
+ vz.initDialogs();
+ vz.bindEvents();
// parse uuids from cookie
vz.uuids.parseCookie();
@@ -110,16 +109,12 @@ $(document).ready(function() {
}
if (vz.uuids.length == 0) {
- $('#addUUID').dialog({
- title: 'UUID hinzufügen',
- width: 400
- });
+ $('#addUUID').dialog('open');
}
// start auto refresh timer
window.setInterval(vz.refresh, 5000);
- vz.bindEvents();
-
+ vz.definitions.load();
vz.entities.load();
});
diff --git a/frontend/javascripts/uuid.js b/frontend/javascripts/uuid.js
index 7b73834..63fe718 100644
--- a/frontend/javascripts/uuid.js
+++ b/frontend/javascripts/uuid.js
@@ -28,8 +28,8 @@
* Read UUIDs from cookie and add them to the array
*/
vz.uuids.parseCookie = function() {
- if ($.getCookie('uuids')) {
- $.each(JSON.parse($.getCookie('uuids')), function(index, uuid) {
+ if ($.getCookie('vz_uuids')) {
+ $.each(JSON.parse($.getCookie('vz_uuids')), function(index, uuid) {
vz.uuids.push(uuid);
});
}
@@ -42,7 +42,7 @@ vz.uuids.add = function(uuid) {
if (vz.uuids.validate(uuid)) {
if (!vz.uuids.contains(uuid)) {
vz.uuids.push(uuid);
- $.setCookie('uuids', JSON.stringify(vz.uuids));
+ $.setCookie('vz_uuids', JSON.stringify(vz.uuids));
}
else {
throw 'UUID already added';
@@ -60,7 +60,7 @@ vz.uuids.remove = function(uuid) {
console.log(vz.uuids.contains(uuid));
if (vz.uuids.contains(uuid)) {
vz.uuids.splice(this.indexOf(uuid), 1); // remove uuid from array
- $.setCookie('uuids', JSON.stringify(vz.uuids));
+ $.setCookie('vz_uuids', JSON.stringify(vz.uuids));
}
else {
throw 'UUID unkown: ' + uuid;
@@ -71,5 +71,5 @@ 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}$/));
+ return new 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}$/) > 0;
};
\ No newline at end of file
|