Skip to content

Commit

Permalink
Added support for multiple remote middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Dec 14, 2013
1 parent 4e4a782 commit f117a19
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
1 change: 0 additions & 1 deletion htdocs/frontend/javascripts/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ vz.entities.loadData = function() {
queue.push(entity.loadData());
}
}, true); // recursive!

return $.when.apply($, queue);
};

Expand Down
11 changes: 11 additions & 0 deletions htdocs/frontend/javascripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,20 @@ $(document).ready(function() {
// initialize variables
vz.middleware.push({ // default middleware
url: vz.options.localMiddleware,
title: 'Local (default)',
public: [ ] // public entities
/* capabilities: { } */
});

// remote middleware(s)
vz.options.remoteMiddleware.forEach(function(middleware) {
vz.middleware.push({
url: middleware.url,
title: middleware.title,
public: [ ] // public entities
/* capabilities: { } */
});
});

// TODO make language/translation dependent (vz.options.language)
vz.options.plot.xaxis.monthNames = vz.options.monthNames;
Expand Down
4 changes: 4 additions & 0 deletions htdocs/frontend/javascripts/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ vz.options = {
minTimeout: 2000, // minimum refresh time in ms
interval: 24*60*60*1000, // 1 day
localMiddleware: '../middleware.php',
remoteMiddleware: [{
title: 'Volkszaehler Demo',
url: 'http://demo.volkszaehler.org/middleware.php'
}],
monthNames: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
dayNames: ['Son', 'Mon', 'Di', 'Mi', 'Do', 'Fr', 'Sam'],
lineWidthDefault: 2,
Expand Down
65 changes: 44 additions & 21 deletions htdocs/frontend/javascripts/wui.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,25 @@ vz.wui.dialogs.init = function() {
$('#entity-add.dialog > div').tabs({
activate: function(event, ui) { // lazy loading public entities
if (ui.newTab.attr('aria-controls') == 'entity-public') {
vz.load({
controller: 'entity',
success: function(json) {
var public = new Array;
json.entities.each(function(index, json) {
public.push(new Entity(json));
});

public.sort(Entity.compare);
vz.middleware[0].public = public;

$('#entity-public-entity').empty();
public.each(function(index, entity) {
$('#entity-public-entity').append(
$('<option>').html(entity.title).val(entity.uuid).data('entity', entity)
);
});
}
// populate MW entities (vz.middleware[0] is the default local)
vz.middleware.forEach(function(middleware, idx) {
vz.load({
controller: 'entity',
url: middleware.url,
success: function(json) {
var public = new Array;
json.entities.each(function(index, json) {
public.push(new Entity(json));
});

public.sort(Entity.compare);
vz.middleware[idx].public = public;

if (idx == 0) {
populateEntities(vz.middleware[idx]);
}
}
});
});
}
}
Expand All @@ -144,12 +145,25 @@ vz.wui.dialogs.init = function() {

// set defaults
$('#entity-subscribe-middleware').val(vz.options.localMiddleware);
$('#entity-public-middleware').append($('<option>').val(vz.options.localMiddleware).text('Local (default)'));
// add middlewares
vz.middleware.forEach(function(middleware, idx) {
$('#entity-public-middleware').append($('<option>').val(middleware.url).text(middleware.title));
});
$('#entity-create-middleware').val(vz.options.localMiddleware);
$('#entity-subscribe-cookie').attr('checked', 'checked');
$('#entity-public-cookie').attr('checked', 'checked');

// actions
$('#entity-public-middleware').change(function() {
var title = $('#entity-public-middleware option:selected').text();
vz.middleware.forEach(function(middleware) {
// populate entities for selected middleware
if (middleware.title == title) {
populateEntities(middleware);
}
});
});

$('#entity-subscribe input[type=button]').click(function() {
try {
var entity = new Entity({
Expand Down Expand Up @@ -196,6 +210,17 @@ vz.wui.dialogs.init = function() {
}
});

function populateEntities(middleware) {
var public = middleware.public;

$('#entity-public-entity').empty();
public.each(function(index, entity) {
$('#entity-public-entity').append(
$('<option>').html(entity.title).val(entity.uuid).data('entity', entity)
);
});
}

// show available properties for selected type
function addProperties(proplist, className) {
proplist.each(function(index, def) {
Expand Down Expand Up @@ -253,7 +278,6 @@ vz.wui.dialogs.init = function() {
});
$('#entity-create select').change();


$('#entity-create form').submit(function() {
var def = $('select[name=type] option:selected', this).data('definition');
var properties = {};
Expand Down Expand Up @@ -319,7 +343,6 @@ vz.wui.zoom = function(from, to) {
vz.options.plot.xaxis.min = 0;
}


vz.options.plot.yaxes.each(function(i) {
vz.options.plot.yaxes[i].max = null; // autoscaling
vz.options.plot.yaxes[i].min = 0; // fixed to 0
Expand Down

0 comments on commit f117a19

Please sign in to comment.