|
From: <pe...@us...> - 2013-01-29 09:03:10
|
Revision: 1371
http://openautomation.svn.sourceforge.net/openautomation/?rev=1371&view=rev
Author: peuter
Date: 2013-01-29 09:03:03 +0000 (Tue, 29 Jan 2013)
Log Message:
-----------
- new possibility to enable a simple status-update-queue, which loads the startpage items status first and then all other items status, can be enabled via URL-Parameter ?enableQueue=1
Modified Paths:
--------------
CometVisu/trunk/visu/lib/cometvisu-client.js
CometVisu/trunk/visu/lib/templateengine.js
CometVisu/trunk/visu/plugins/clock/structure_plugin.js
CometVisu/trunk/visu/plugins/diagram/structure_plugin.js
CometVisu/trunk/visu/plugins/svg/structure_plugin.js
CometVisu/trunk/visu/structure/pure/_common.js
CometVisu/trunk/visu/structure/pure/page.js
Modified: CometVisu/trunk/visu/lib/cometvisu-client.js
===================================================================
--- CometVisu/trunk/visu/lib/cometvisu-client.js 2013-01-28 19:53:55 UTC (rev 1370)
+++ CometVisu/trunk/visu/lib/cometvisu-client.js 2013-01-29 09:03:03 UTC (rev 1371)
@@ -33,18 +33,23 @@
var thisCometVisu = this;
this.urlPrefix = (null == urlPrefix) ? '' : urlPrefix; // the address of the service
this.addresses = []; // the subscribed addresses
+ this.initialAddresses = []; // the addresses which should be loaded before the subscribed addresses
this.filters = []; // the subscribed filters
this.user = ''; // the current user
this.pass = ''; // the current password
this.device = ''; // the current device ID
this.running = false; // is the communication running at the moment?
- this.doRestart = false; // are we currently in a reastart, e.g. due to the watchdog
+ this.doRestart = false; // are we currently in a restart, e.g. due to the watchdog
this.xhr = false; // the ongoing AJAX request
- this.watchdogTimer = 5; // in Seconds - the alive check intervall of the watchdog
+ this.watchdogTimer = 5; // in Seconds - the alive check interval of the watchdog
this.maxConnectionAge = 60; // in Seconds - restart if last read is older
- this.maxDataAge = 3200; // in Seconds - reload all data when last successfull read is older
+ this.maxDataAge = 3200; // in Seconds - reload all data when last successful read is older
// (should be faster than the index overflow at max data rate, i.e. 2^16 @ 20 tps for KNX TP)
this.lastIndex = -1; // index returned by the last request
+
+ this.setInitialAddresses = function(addresses) {
+ this.initialAddresses = addresses;
+ }
/**
* This function gets called once the communication is established and session information is available
@@ -60,7 +65,13 @@
// send first request
this.running = true;
- this.xhr = $.ajax( {url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
+ if (this.initialAddresses.length) {
+ this.xhr = $.ajax({url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest(this.initialAddresses)+'&t=0', success:this.handleReadStart} );
+ }
+ else {
+ // old behaviour -> start full query
+ this.xhr = $.ajax({url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
+ }
};
/**
@@ -92,6 +103,28 @@
watchdog.ping();
}
};
+
+ this.handleReadStart = function( json )
+ {
+ if( !json && (-1 == this.lastIndex) )
+ {
+ if( this.running )
+ { // retry initial request
+ this.xhr = $.ajax({url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest(this.startPageAddresses)+'&t=0', success:this.handleReadStart} );
+ watchdog.ping();
+ }
+ return;
+ }
+ if( json && !this.doRestart )
+ {
+ this.update( json.d );
+ }
+ if( this.running )
+ { // keep the requests going
+ this.xhr = $.ajax({url:this.urlPrefix + 'r',dataType: 'json',context:this,data:this.buildRequest()+'&t=0', success:this.handleRead ,error:this.handleError/*,complete:this.handleComplete*/ } );
+ watchdog.ping();
+ }
+ };
/**
* This function gets called on an error
@@ -123,11 +156,12 @@
* Build the URL part that contains the addresses and filters
* @method buildRequest
*/
- this.buildRequest = function()
+ this.buildRequest = function(addresses)
{
- var requestAddresses = (this.addresses.length)?'a=' + this.addresses.join( '&a=' ):'';
+ addresses = addresses ? addresses : this.addresses;
+ var requestAddresses = (addresses.length)?'a=' + addresses.join( '&a=' ):'';
var requestFilters = (this.filters.length )?'f=' + this.filters.join( '&f=' ):'';
- return 's=' + this.session + '&' + requestAddresses + ( (this.addresses.length&&this.filters.length)?'&':'' ) + requestFilters;
+ return 's=' + this.session + '&' + requestAddresses + ( (addresses.length&&this.filters.length)?'&':'' ) + requestFilters;
}
/**
@@ -138,14 +172,7 @@
this.subscribe = function( addresses, filters )
{
var startCommunication = !this.addresses.length; // start when addresses were empty
- this.addresses=[];
- var obj={};
- for (var i=0;i<addresses.length;i++) {
- obj[addresses[i]]=0;
- }
- for (var i in obj) {
- this.addresses.push(i);
- }
+ this.addresses= addresses ? addresses : [];
this.filters = filters ? filters : [] ;
if( !addresses.length ) this.stop(); // stop when new addresses are empty
Modified: CometVisu/trunk/visu/lib/templateengine.js
===================================================================
--- CometVisu/trunk/visu/lib/templateengine.js 2013-01-28 19:53:55 UTC (rev 1370)
+++ CometVisu/trunk/visu/lib/templateengine.js 2013-01-29 09:03:03 UTC (rev 1371)
@@ -51,7 +51,7 @@
this.mappings = {}; // store the mappings
this.stylings = {}; // store the stylings
- this.ga_list = [];
+ var ga_list = {};
this.main_scroll;
this.old_scroll = '';
@@ -63,6 +63,9 @@
this.defaultColumns = 12;
this.minColumnWidth = 150;
this.enableColumnAdjustment = false;
+
+ this.enableAddressQueue = $.getUrlVar('enableQueue') ? true : false;
+
this.backend = 'cgi-bin'; // default path to backend
if ($.getUrlVar("backend")) {
this.backend = $.getUrlVar("backend");
@@ -132,6 +135,14 @@
.decode(value) : (basetrans in Transform ? Transform[basetrans]
.decode(value) : value);
};
+
+ this.addAddress = function(address) {
+ ga_list[address]=1;
+ };
+
+ this.getAddresses = function() {
+ return Object.keys(ga_list);
+ };
this.map = function(value, this_map) {
if (this_map && thisTemplateEngine.mappings[this_map]) {
@@ -520,14 +531,11 @@
if (thisTemplateEngine.scrollSpeed != undefined) {
thisTemplateEngine.main_scroll.getConf().speed = thisTemplateEngine.scrollSpeed;
}
-
+ var startpage = 'id_0';
if ($.getUrlVar('startpage')) {
- thisTemplateEngine.scrollToPage('id_' + $.getUrlVar('startpage'), 0);
- } else {
- thisTemplateEngine.scrollToPage('id_0', 0); // simple solution to show
- // page name on top at
- // start
+ startpage='id_' + $.getUrlVar('startpage');
}
+ thisTemplateEngine.scrollToPage(startpage,0);
$('.fast').bind('click', function() {
thisTemplateEngine.main_scroll.seekTo($(this).text());
@@ -662,8 +670,18 @@
$('svg', svg).prepend(s);
};
});
-
- thisTemplateEngine.visu.subscribe(thisTemplateEngine.ga_list);
+ if (thisTemplateEngine.enableAddressQueue) {
+ // identify addresses on startpage
+ var startPageAddresses = {};
+ $('.actor','#'+startpage).each(function() {
+ var address = $(this).data('address');
+ for (var ga in address) {
+ startPageAddresses[ga.substring(1)]=1;
+ }
+ });
+ thisTemplateEngine.visu.setInitialAddresses(Object.keys(startPageAddresses));
+ }
+ thisTemplateEngine.visu.subscribe(thisTemplateEngine.getAddresses());
$(window).trigger('resize');
$("#pages").triggerHandler("done");
};
Modified: CometVisu/trunk/visu/plugins/clock/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/clock/structure_plugin.js 2013-01-28 19:53:55 UTC (rev 1370)
+++ CometVisu/trunk/visu/plugins/clock/structure_plugin.js 2013-01-29 09:03:03 UTC (rev 1371)
@@ -35,7 +35,7 @@
var transform = this.getAttribute('transform');
var color = this.getAttribute('variant' );
var readonly = this.getAttribute('readonly' );
- templateEngine.ga_list.push( src );
+ templateEngine.addAddress( src );
address[ '_' + src ] = [ transform, color, readonly=='true' ];
});
Modified: CometVisu/trunk/visu/plugins/diagram/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/diagram/structure_plugin.js 2013-01-28 19:53:55 UTC (rev 1370)
+++ CometVisu/trunk/visu/plugins/diagram/structure_plugin.js 2013-01-29 09:03:03 UTC (rev 1371)
@@ -231,7 +231,7 @@
var address = {};
$p.find('address').each( function(){
var src = this.textContent;
- templateEngine.ga_list.push( src );
+ templateEngine.addAddress( src );
address[ '_' + src ] = [ this.getAttribute('transform') ];
});
Modified: CometVisu/trunk/visu/plugins/svg/structure_plugin.js
===================================================================
--- CometVisu/trunk/visu/plugins/svg/structure_plugin.js 2013-01-28 19:53:55 UTC (rev 1370)
+++ CometVisu/trunk/visu/plugins/svg/structure_plugin.js 2013-01-29 09:03:03 UTC (rev 1371)
@@ -35,7 +35,7 @@
var transform = this.getAttribute('transform');
var color = this.getAttribute('variant' );
var readonly = this.getAttribute('readonly' );
- templateEngine.ga_list.push( src );
+ templateEngine.addAddress( src );
address[ '_' + src ] = [ transform, color, readonly=='true' ];
});
Modified: CometVisu/trunk/visu/structure/pure/_common.js
===================================================================
--- CometVisu/trunk/visu/structure/pure/_common.js 2013-01-28 19:53:55 UTC (rev 1370)
+++ CometVisu/trunk/visu/structure/pure/_common.js 2013-01-29 09:03:03 UTC (rev 1371)
@@ -108,8 +108,8 @@
break;
}
var variantInfo = handleVariant ? handleVariant( src, transform, mode, this.getAttribute('variant') ) : [true, undefined];
- if( variantInfo[0] )
- templateEngine.ga_list.push( src );
+ if( variantInfo[0])
+ templateEngine.addAddress( src );
address[ '_' + src ] = [ transform, mode, variantInfo[1] ];
return; // end of each-func
});
Modified: CometVisu/trunk/visu/structure/pure/page.js
===================================================================
--- CometVisu/trunk/visu/structure/pure/page.js 2013-01-28 19:53:55 UTC (rev 1370)
+++ CometVisu/trunk/visu/structure/pure/page.js 2013-01-29 09:03:03 UTC (rev 1371)
@@ -22,7 +22,7 @@
var address = {};
if ($p.attr('ga')) {
src = $p.attr('ga');
- templateEngine.ga_list.push($p.attr('ga'));
+ templateEngine.addAddress($p.attr('ga'));
address[ '_' + $p.attr('ga') ] = [ 'DPT:1.001', 0 ];
}
@@ -80,17 +80,17 @@
}}, floorplan.translateMouseEvent );
$(window).bind( 'resize', function(){ floorplan.resize($('.page').width(), $('.page').height(), true);} );
if ($p.attr('azimut')) {
- templateEngine.ga_list.push($p.attr('azimut'));
+ templateEngine.addAddress($p.attr('azimut'));
address[ '_' + $p.attr('azimut') ] = [ 'DPT:9.001', 0, 'azimut' ];
container.bind( '_' + $p.attr('azimut'), this.update );
}
if ($p.attr('elevation')) {
- templateEngine.ga_list.push($p.attr('elevation'));
+ templateEngine.addAddress($p.attr('elevation'));
address[ '_' + $p.attr('elevation') ] = [ 'DPT:9.001', 0, 'elevation' ];
container.bind( '_' + $p.attr('elevation'), this.update );
};
if ($p.attr('floor')) {
- templateEngine.ga_list.push($p.attr('floor'));
+ templateEngine.addAddress($p.attr('floor'));
address[ '_' + $p.attr('floor') ] = [ 'DPT:5.004', 0, 'floor' ];
container.bind( '_' + $p.attr('floor'), this.update );
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|