adding some tracability into the plugins code
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 20 Dec 2013 11:19:24 +0000 (12:19 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 20 Dec 2013 11:19:24 +0000 (12:19 +0100)
we can now get some events traced right into plugins.js instead of having to instrument all callbacks

14 files changed:
manifold/static/js/plugin.js
plugins/active_filters/static/js/active_filters.js
plugins/googlemap/static/js/googlemap.js
plugins/lists/static/js/simplelist.js
plugins/maddash/static/js/maddash.js
plugins/messages/static/js/messages.js
plugins/myplugin/static/js/myplugin.js
plugins/querygrid/static/js/querygrid.js
plugins/querytable/static/js/querytable.js
plugins/queryupdater/static/js/queryupdater.js
plugins/scheduler/static/js/scheduler.js
plugins/senslabmap/static/js/senslabmap.js
plugins/slicestat/static/js/slicestat.js
plugins/topmenuvalidation/static/js/topmenuvalidation.js

index 4530b51..24d4112 100644 (file)
@@ -20,6 +20,13 @@ $.plugin = function(name, object) {
     };
 };
 
+// set to either
+// * false or undefined or none : no debug
+// * true : trace all event calls
+// * [ 'in_progress', 'query_done' ] : would only trace to these events
+var plugin_debug=false;
+plugin_debug = [ 'in_progress', 'query_done' ];
+
 var Plugin = Class.extend({
 
     init: function(options, element) {
@@ -42,35 +49,52 @@ var Plugin = Class.extend({
         return (typeof this.on_filter_added === 'function');
     },
 
+    // do we need to log API calls ?
+    _is_in : function (obj, arr) {
+       for(var i=0; i<arr.length; i++) {
+            if (arr[i] == obj) return true;
+       }
+    },
+    _deserves_logging: function (event) {
+       if ( ! plugin_debug )                           return false;
+       else if ( plugin_debug === true)                return true;
+       else if (this._is_in (event, plugin_debug))     return true;
+       return false;
+    },
+
     _query_handler: function(prefix, event_type, data) {
         // We suppose this.query_handler_prefix has been defined if this
         // callback is triggered    
-        var fn;
+        var event, fn;
         switch(event_type) {
         case FILTER_ADDED:
-            fn = 'filter_added';
+            event = 'filter_added';
             break;
         case FILTER_REMOVED:
-            fn = 'filter_removed';
+            event = 'filter_removed';
             break;
         case CLEAR_FILTERS:
-            fn = 'filter_clear';
+            event = 'filter_clear';
             break;
         case FIELD_ADDED:
-            fn = 'field_added';
+            event = 'field_added';
             break;
         case FIELD_REMOVED:
-            fn = 'field_removed';
+            event = 'field_removed';
             break;
         case CLEAR_FIELDS:
-            fn = 'field_clear';
+            event = 'field_clear';
             break;
         default:
             return;
         } // switch
         
-        fn = 'on_' + prefix + fn;
+        fn = 'on_' + prefix + event;
         if (typeof this[fn] === 'function') {
+           if (this._deserves_logging (event)) {
+               var classname=this.classname;
+               messages.debug("Plugin._query_handler: calling "+fn+" on "+classname);
+           }
             // call with data as parameter
             // XXX implement anti loop
             this[fn](data);
@@ -80,29 +104,33 @@ var Plugin = Class.extend({
     _record_handler: function(prefix, event_type, record) {
         // We suppose this.query_handler_prefix has been defined if this
         // callback is triggered    
-        var fn;
+        var event, fn;
         switch(event_type) {
         case NEW_RECORD:
-            fn = 'new_record';
+            event = 'new_record';
             break;
         case CLEAR_RECORDS:
-            fn = 'clear_records';
+            event = 'clear_records';
             break;
         case IN_PROGRESS:
-            fn = 'query_in_progress';
+            event = 'query_in_progress';
             break;
         case DONE:
-            fn = 'query_done';
+            event = 'query_done';
             break;
         case FIELD_STATE_CHANGED:
-            fn = 'field_state_changed';
+            event = 'field_state_changed';
             break;
         default:
             return;
         } // switch
         
-        fn = 'on_' + prefix + fn;
+        fn = 'on_' + prefix + event;
         if (typeof this[fn] === 'function') {
+           if (this._deserves_logging (event)) {
+               var classname=this.classname;
+               messages.debug("Plugin._record_handler: calling "+fn+" on "+classname);
+           }
             // call with data as parameter
             // XXX implement anti loop
             this[fn](record);
index e9548be..538157e 100644 (file)
@@ -11,6 +11,7 @@
     var ActiveFilters = Plugin.extend({
 
         init: function(options, element) {
+           this.classname="active_filters";
             this._super(options, element);
 
             this.elts('closeButton').click(function() {
index 91ece99..9cde18c 100644 (file)
@@ -14,6 +14,7 @@
     var debug=false;
     debug=true;
 
+    // this now should be obsolete, rather use plugin_debug in plugin.js
     // more on a on-per-record basis
     var debug_deep=false;
     // debug_deep=true;
@@ -21,6 +22,7 @@
     var GoogleMap = Plugin.extend({
 
         init: function(options, element) {
+           this.classname="googlemap";
             this._super(options, element);
 
             /* Member variables */
index 2bed5b4..254fb22 100644 (file)
@@ -12,6 +12,7 @@
     var SimpleList = Plugin.extend ({
 
        init: function (options, element) {
+           this.classname=options.classname;
            this._super (options, element);
            this.buffered_records=[];
             this.listen_query(options.query_uuid);
            var self=this;
             var $plugindiv = this.elmt();
             var options = this.options;
-           var classname=options.classname;
             // locate the <table> element; with datatables in the way,
             // this might not be a direct son of the div-plugin
-            var $table = $plugindiv.find("table."+classname).first();
+            var $table = $plugindiv.find("table."+this.classname).first();
             // also we may or may not have a header
-            var $tbody = $table.find("tbody."+classname).first();
+            var $tbody = $table.find("tbody."+this.classname).first();
             var use_datatables = $table.hasClass("with-datatables");
            var rows=self.buffered_records;
            self.buffered_records=[];
@@ -69,7 +69,7 @@
            if (use_datatables) 
                this._datatables_update_table($table, $tbody, rows, options.key);
            else
-               this._regular_update_table($table, $tbody, rows, options.key, classname);
+               this._regular_update_table($table, $tbody, rows, options.key, this.classname);
        },
 
        _regular_set_message: function ($table, $tbody, message) {
@@ -78,7 +78,8 @@
 
        _regular_update_table: function ($table, $tbody, rows, key, classname) {
             if (debug)
-               messages.debug('regular_update_table ' + rows.length + " rows" + " key=" + key + " classname=" + classname);
+               messages.debug('regular_update_table ' + rows.length + " rows" + 
+                              " key=" + key + " classname=" + this.classname);
            var self=this;
            var html=$.map(rows, function (row) {
                var value = row;
                });
                if ($.isArray(value)) {
                     return $.map(value, function(val, i) { 
-                       return self._html_row ( self._cell (key, val), classname); 
+                       return self._html_row ( self._cell (key, val), this.classname); 
                    });
                } else {
-                    return self._html_row ( self._cell (key, value), classname);
+                    return self._html_row ( self._cell (key, value), this.classname);
                }
             }).join();
            $tbody.html(html);
index 110eec1..ab5a7a5 100644 (file)
@@ -37,6 +37,7 @@ var colorscale = d3.scale.category10().range(["green", "yellow", "red", "orange"
          */
         init: function(options, element) {
             // Call the parent constructor, see FAQ when forgotten
+           this.classname="maddash";
             this._super(options, element);
 
 
index a90a745..07265e6 100644 (file)
@@ -9,6 +9,7 @@
     var Messages = Plugin.extend ({
 
        init: function (options, element) {
+           classname="messages";
            this._super (options, element);
            // subscribe to the various messages channels
            var self=this;
index 26a2992..a885ddf 100644 (file)
@@ -23,6 +23,8 @@
          *     applied, which allows to maintain chainability of calls
          */
         init: function(options, element) {
+           // for debugging tools
+           this.classname="myplugin";
             // Call the parent constructor, see FAQ when forgotten
             this._super(options, element);
 
index 8f77eaa..a5758e8 100644 (file)
@@ -38,6 +38,7 @@
     var QueryGrid = Plugin.extend({
 
         init: function(options, element) {
+           this.classname="querygrid";
             this._super(options, element);
 
             /* Member variables */
index ca2c5da..19ecd6c 100644 (file)
@@ -11,8 +11,8 @@
 
     var QueryTable = Plugin.extend({
 
-        init: function(options, element) 
-        {
+        init: function(options, element) {
+           this.classname="querytable";
             this._super(options, element);
 
             /* Member variables */
index abcd2d7..b00f04f 100644 (file)
@@ -11,6 +11,9 @@
 
 (function( $ ){
 
+    var debug=false;
+    debug=true;
+
     // XXX record selected (multiple selection ?)
     // XXX record disabled ?
     // XXX out of sync plugin ?
@@ -25,8 +28,8 @@
 
     var QueryUpdater = Plugin.extend({
 
-        init: function(options, element)
-        {
+        init: function(options, element) {
+           this.classname="queryupdater";
             this._super(options, element);
 
             var self = this;
@@ -65,8 +68,7 @@
 
         /***************************** GUI EVENTS *****************************/
 
-        do_update: function(e) 
-        {
+        do_update: function(e) {
             var self = e.data;
             // XXX check that the query is not disabled
             manifold.raise_event(self.options.query_uuid, RUN_UPDATE);
 
         on_query_in_progress: function()
         {
+           messages.debug("queryupdater.on_query_in_progress");
             this.spin();
         },
 
index 0929157..c9b2096 100644 (file)
@@ -45,6 +45,7 @@ var txt_otherslice = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-s
 
         init: function(options, element) 
         {
+           this.classname="scheduler";
             this._super(options, element);
 
             /* Member variables */
index 519a5af..e6a64b5 100644 (file)
@@ -1,6 +1,7 @@
 (function($){
   var SensLabMap = Plugin.extend({
     init: function(options, element) {
+       this.classname="senslabmap";
       this._super(options, element);
       
       this.elmt().on('show', this, this.on_show);
index da17722..a55a797 100644 (file)
@@ -23,6 +23,7 @@
          *     applied, which allows to maintain chainability of calls
          */
         init: function(options, element) {
+           this.classname="slicestat";
             // Call the parent constructor, see FAQ when forgotten
             this._super(options, element);                      
                        
index 6cfc383..c29592b 100644 (file)
@@ -10,6 +10,7 @@
     var TopmenuValidation = Plugin.extend({
 
         init: function(options, element) {
+           this.classname="topmenuvalidation";
             this._super(options, element);
             this.listen_query(options.query_uuid);
            this.triggered=false;