From dcc65257573225bcb6c97038268397745a5e3e6c Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Thu, 20 Mar 2014 18:30:15 +0100 Subject: [PATCH] Testbeds list plugin with filters: key, included, [x,y,z] --- manifoldapi/static/js/manifold.js | 10 +- plugins/querytable/static/js/querytable.js | 11 ++- plugins/testbeds/__init__.py | 7 +- plugins/testbeds/static/js/testbeds.js | 101 ++++++++++++++++++++- portal/static/css/fed4fire.css | 13 ++- portal/static/css/onelab.css | 13 ++- 6 files changed, 141 insertions(+), 14 deletions(-) diff --git a/manifoldapi/static/js/manifold.js b/manifoldapi/static/js/manifold.js index 3d526a67..bbdbdedf 100644 --- a/manifoldapi/static/js/manifold.js +++ b/manifoldapi/static/js/manifold.js @@ -908,9 +908,7 @@ var manifold = { 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); @@ -945,7 +943,11 @@ var manifold = { } // 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 diff --git a/plugins/querytable/static/js/querytable.js b/plugins/querytable/static/js/querytable.js index e162ffb3..8637e728 100644 --- a/plugins/querytable/static/js/querytable.js +++ b/plugins/querytable/static/js/querytable.js @@ -300,7 +300,7 @@ { // Remove corresponding filters this.filters = $.grep(this.filters, function(x) { - return x != filter; + return x == filter; }); this.redraw_table(); }, @@ -490,6 +490,15 @@ if (op == '=' || op == '==') { if ( col_value != value || col_value==null || col_value=="" || col_value=="n/a") ret = false; + }else if (op == 'included') { + $.each(value, function(i,x) { + if(x == col_value){ + ret = true; + return false; + }else{ + ret = false; + } + }); }else if (op == '!=') { if ( col_value == value || col_value==null || col_value=="" || col_value=="n/a") ret = false; diff --git a/plugins/testbeds/__init__.py b/plugins/testbeds/__init__.py index 14f4a7c8..6b2b89d9 100644 --- a/plugins/testbeds/__init__.py +++ b/plugins/testbeds/__init__.py @@ -2,7 +2,7 @@ from unfold.plugin import Plugin 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 @@ -10,6 +10,9 @@ class TestbedsPlugin(Plugin): 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" @@ -28,7 +31,7 @@ class TestbedsPlugin(Plugin): # 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 diff --git a/plugins/testbeds/static/js/testbeds.js b/plugins/testbeds/static/js/testbeds.js index e424c248..dfe88553 100644 --- a/plugins/testbeds/static/js/testbeds.js +++ b/plugins/testbeds/static/js/testbeds.js @@ -22,12 +22,13 @@ * 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 */ @@ -80,9 +81,34 @@ // 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 @@ -90,18 +116,83 @@ /* RECORD HANDLERS */ on_network_new_record: function(record) { - console.log(record); - row = ''; + row = ''; row += ''+record["platform"]+''; //row += ''+record["network_hrn"]+''; row += '

'+record["network_hrn"]+'

'; $('#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]); + } + } }); diff --git a/portal/static/css/fed4fire.css b/portal/static/css/fed4fire.css index 75223550..9d3ce4ce 100644 --- a/portal/static/css/fed4fire.css +++ b/portal/static/css/fed4fire.css @@ -371,12 +371,23 @@ a.list-group-item { padding:3px 0 3px 10px; border-left:2pt white solid; } -a.list-group-item.active, a.list-group-item:hover { +a.list-group-item.active, a.list-group-item.active:hover { + font-weight: bold; + color:black; + background-color:transparent; + border-left:2pt blue solid; +} +a.list-group-item.active:hover { + background-color:#dddddd; +} +a.list-group-item:hover { border-left:2pt blue solid; } a.list-group-item p.list-group-item-text { font-size:9pt; font-style:italic; + font-weight: normal; + color: black !important; } div#slice-info { diff --git a/portal/static/css/onelab.css b/portal/static/css/onelab.css index a643755d..df675b1a 100644 --- a/portal/static/css/onelab.css +++ b/portal/static/css/onelab.css @@ -371,12 +371,23 @@ a.list-group-item { padding:3px 0 3px 10px; border-left:2pt white solid; } -a.list-group-item.active, a.list-group-item:hover { +a.list-group-item.active, a.list-group-item.active:hover { + font-weight: bold; + color:black; + background-color:transparent; + border-left:2pt blue solid; +} +a.list-group-item.active:hover { + background-color:#dddddd; +} +a.list-group-item:hover { border-left:2pt blue solid; } a.list-group-item p.list-group-item-text { font-size:9pt; font-style:italic; + font-weight: normal; + color: black !important; } div#slice-info { -- 2.43.0