Testbeds list plugin with filters: key, included, [x,y,z]
authorLoic Baron <loic.baron@lip6.fr>
Thu, 20 Mar 2014 17:30:15 +0000 (18:30 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Thu, 20 Mar 2014 17:30:15 +0000 (18:30 +0100)
manifoldapi/static/js/manifold.js
plugins/querytable/static/js/querytable.js
plugins/testbeds/__init__.py
plugins/testbeds/static/js/testbeds.js
portal/static/css/fed4fire.css
portal/static/css/onelab.css

index 3d526a6..bbdbded 100644 (file)
@@ -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
index e162ffb..8637e72 100644 (file)
         {
             // Remove corresponding filters
             this.filters = $.grep(this.filters, function(x) {
-                return x != filter;
+                return x == filter;
             });
             this.redraw_table();
         },
                 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;
index 14f4a7c..6b2b89d 100644 (file)
@@ -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
index e424c24..dfe8855 100644 (file)
          *     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]);
+            }
+        }
 
     });
 
index 7522355..9d3ce4c 100644 (file)
@@ -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 {
index a643755..df675b1 100644 (file)
@@ -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 {