break;
case FILTER_ADDED:
-// Thierry - this is probably wrong but intended as a hotfix
-// http://trac.myslice.info/ticket/32
-// manifold.raise_query_event(query_uuid, event_type, value);
+ manifold.raise_query_event(query_uuid, event_type, value);
break;
case FILTER_REMOVED:
manifold.raise_query_event(query_uuid, event_type, value);
}
// We need to inform about changes in these queries to the respective plugins
// Note: query, main_query & update_query have the same UUID
- manifold.raise_query_event(query_uuid, event_type, value);
+
+ // http://trac.myslice.info/ticket/32
+ // Avoid multiple calls to the same event
+ //manifold.raise_query_event(query_uuid, event_type, value);
+
// We are targeting the same object with get and update
// The notion of query is bad, we should have a notion of destination, and issue queries on the destination
// NOTE: Editing a subquery == editing a local view on the destination
class TestbedsPlugin(Plugin):
- def __init__ (self, query=None, query_network=None, **settings):
+ def __init__ (self, query=None, query_all=None, query_network=None, **settings):
Plugin.__init__ (self, **settings)
# Until we have a proper way to access queries in Python
self.query_network = query_network
self.query_network_uuid = query_network.query_uuid if query_network else None
+ self.query_all = query_all
+ self.query_all_uuid = query_all.query_uuid if query_all else None
+
def template_file (self):
return "testbeds.html"
# query_uuid will pass self.query results to the javascript
# and will be available as "record" in :
# on_new_record: function(record)
- return ['plugin_uuid', 'domid', 'query_uuid', 'query_network_uuid']
+ return ['plugin_uuid', 'domid', 'query_uuid', 'query_all_uuid', 'query_network_uuid']
def export_json_settings (self):
return True
* applied, which allows to maintain chainability of calls
*/
init: function(options, element) {
- // for debugging tools
- this.classname="testbedsplugin";
+ // for debugging tools
+ this.classname="testbedsplugin";
// Call the parent constructor, see FAQ when forgotten
this._super(options, element);
/* Member variables */
+ this.filters = Array();
/* Plugin events */
// no prefix
+ /* When a filter is added/removed, update the list of filters local to the plugin */
on_filter_added: function(filter)
{
-
+ this.filters.push(filter);
+ if(filter[0]=='network_hrn'){
+ if(filter[1]=='included'){
+ $.each(filter[2], function(value){
+ $("#testbeds-filter_"+value).addClass("active");
+ });
+ }else if(filter[1]=='=' || filter[1]=='=='){
+ $("#testbeds-filter_"+filter[2]).addClass("active");
+ }
+ }
+ },
+ on_filter_removed: function(filter)
+ {
+ this.filters = $.grep(this.filters, function(x) {
+ return x == filter;
+ });
+ if(filter[0]=='network_hrn'){
+ if(filter[1]=='included'){
+ $.each(filter[2], function(value){
+ $("#testbeds-filter_"+value).removeClass("active");
+ });
+ }else if(filter[1]=='=' || filter[1]=='=='){
+ $("#testbeds-filter_"+filter[2]).removeClass("active");
+ }
+ }
},
// ... be sure to list all events here
/* RECORD HANDLERS */
on_network_new_record: function(record)
{
- console.log(record);
- row = '<a href="#" class="list-group-item sl-platform" data-platform="'+record["network_hrn"]+'">';
+ row = '<a href="#" class="list-group-item sl-platform" id="testbeds-filter_'+record["network_hrn"]+'" data-platform="'+record["network_hrn"]+'">';
row += '<span class="list-group-item-heading">'+record["platform"]+'</span>';
//row += '<span class="list-group-item-heading">'+record["network_hrn"]+'</span></a>';
row += '<p class="list-group-item-text">'+record["network_hrn"]+'</p></a>';
$('#testbeds-filter').append(row);
},
+ /* When the network query is done, add the click event to the elements */
+ on_network_query_done: function() {
+ var self = this;
+ console.log('query network DONE');
+ $("[id^='testbeds-filter_']").on('click',function(e) {
+ $(this).toggleClass("active");
+
+ // avoid multiple calls when an event is raised to manifold.js
+ e.stopPropagation();
+
+ value = this.dataset['platform'];
+ key = "network_hrn";
+ op = "included";
+ return $(this).hasClass('active') ? self._addFilter(key, op, value) : self._removeFilter(key, op, value);
+ });
+
+ },
+
/* INTERNAL FUNCTIONS */
_dummy: function() {
// only convention, not strictly enforced at the moment
},
+ _addFilter: function(key, op, value)
+ {
+ console.log("add "+value);
+ var self = this;
+ values = Array();
+ // get the previous list of values for this key, ex: [ple,nitos]
+ // remove the previous filter
+ network_filter = $.grep(this.filters, function(x) {
+ return x[0] == "network_hrn";
+ });
+ if(network_filter.length > 0){
+ $.each(network_filter, function(i,f){
+ values = f[2];
+ manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, [key, op, values]);
+ });
+ }
+ // Add the new value to list of values, ex: wilab
+ values.push(value);
+
+ // Update the filter with the new list of values, ex: [ple,nitos,wilab]
+ manifold.raise_event(this.options.query_uuid, FILTER_ADDED, [key, op, values]);
+ },
+ _removeFilter: function(key, op, value)
+ {
+ console.log("remove "+value);
+ var self = this;
+ values = Array();
+ // get the previous list of values for this key, ex: [ple,nitos,wilab]
+ // remove the previous filter
+ network_filter = $.grep(this.filters, function(x) {
+ return x[0] == "network_hrn";
+ });
+ if(network_filter.length > 0){
+ $.each(network_filter, function(i,f){
+ values = f[2];
+ manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, [key, op, values]);
+ });
+ }
+
+ // remove the value from the list of values, ex: wilab
+ values = $.grep(values, function(x) {
+ return x != value;
+ });
+ if(values.length>0){
+ // Update the filter with the new list of values, ex: [ple,nitos]
+ manifold.raise_event(this.options.query_uuid, FILTER_ADDED, [key, op, values]);
+ }
+ }
});