always use messages.* stuff
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 11 Apr 2013 14:02:02 +0000 (16:02 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 11 Apr 2013 14:02:02 +0000 (16:02 +0200)
16 files changed:
manifold/js/manifold.js
manifold/manifoldapi.py
manifold/manifoldproxy.py
plugins/hazelnut/hazelnut.js
plugins/lists/simplelist.css
plugins/lists/simplelist.js
plugins/messages/messages.js
plugins/querycode/querycode.js
plugins/quickfilter/quickfilter.js
plugins/updater/updater.js
trash/pluginview.py
trash/sliceview.py
unfold/js/messages-runtime.js
unfold/js/plugin.js
unfold/js/unfold-helper.js
unfold/templates/page-queries.js

index 4d005d0..4eb58fa 100644 (file)
@@ -2,19 +2,19 @@
 function debug_dict_keys (msg, o) {
     var keys=[];
     for (var k in o) keys.push(k);
-    console.log ("debug_dict_keys: " + msg + " keys= " + keys);
+    messages.debug ("debug_dict_keys: " + msg + " keys= " + keys);
 }
 function debug_dict (msg, o) {
-    for (var k in o) console.log ("debug_dict: " + msg + " [" + k + "]=" + o[k]);
+    for (var k in o) messages.debug ("debug_dict: " + msg + " [" + k + "]=" + o[k]);
 }
 function debug_value (msg, value) {
-    console.log ("debug_value: " + msg + " " + value);
+    messages.debug ("debug_value: " + msg + " " + value);
 }
 function debug_query (msg, query) {
-    if (query === undefined) console.log ("debug_query: " + msg + " -> undefined");
-    else if (query == null) console.log ("debug_query: " + msg + " -> null");
-    else if ('query_uuid' in query) console.log ("debug_query: " + msg + query.__repr());
-    else console.log ("debug_query: " + msg + " query= " + query);
+    if (query === undefined) messages.debug ("debug_query: " + msg + " -> undefined");
+    else if (query == null) messages.debug ("debug_query: " + msg + " -> null");
+    else if ('query_uuid' in query) messages.debug ("debug_query: " + msg + query.__repr());
+    else messages.debug ("debug_query: " + msg + " query= " + query);
 }
 
 /* ------------------------------------------------------------ */
@@ -31,7 +31,7 @@ var manifold = {
     },
     debug_all_queries : function (msg) {
        for (var query_uuid in manifold.all_queries) {
-           $.publish("/messages/debug","manifold.debug " + msg + " " + query_uuid + " -> " + manifold.all_queries[query_uuid]);
+           messages.debug("manifold.debug " + msg + " " + query_uuid + " -> " + manifold.all_queries[query_uuid]);
        }
     },
 
@@ -48,9 +48,9 @@ var manifold = {
        // in case the spin stuff was not loaded, let's make sure we proceed to the exit 
        try {
            if (manifold.asynchroneous_debug) 
-               $.publish("/messages/debug","Turning on spin with " + jQuery(".need-spin").length + " matches for .need-spin");
+               messages.debug("Turning on spin with " + jQuery(".need-spin").length + " matches for .need-spin");
            jQuery('.need-spin').spin(spin_presets);
-       } catch (err) { console.log("Cannot turn on spins " + err); }
+       } catch (err) { messages.debug("Cannot turn on spins " + err); }
        
        // We use js function closure to be able to pass the query (array) to the
        // callback function used when data is received
@@ -65,8 +65,8 @@ var manifold = {
            // by default we publish using the same uuid of course
            if (publish_uuid==undefined) publish_uuid=query.query_uuid;
            if (manifold.asynchroneous_debug) {
-               $.publish("/messages/debug","sending POST on " + manifold.proxy_url + " to be published on " + publish_uuid);
-               $.publish("/messages/debug","... ctd... with actual query= " + query.__repr());
+               messages.debug("sending POST on " + manifold.proxy_url + " to be published on " + publish_uuid);
+               messages.debug("... ctd... with actual query= " + query.__repr());
            }
            // not quite sure what happens if we send a string directly, as POST data is named..
            // this gets reconstructed on the proxy side with ManifoldQuery.fill_from_POST
@@ -80,7 +80,7 @@ var manifold = {
     // e.g. an updater wants to publish its results as if from the original (get) query
     asynchroneous_success : function (data, query, publish_uuid, domid) {
        if (manifold.asynchroneous_debug) 
-           $.publish("/messages/debug","received manifold result with code " + data.code);
+           messages.debug("received manifold result with code " + data.code);
        // xxx should have a nicer declaration of that enum in sync with the python code somehow
        if (data.code == 1) {
            alert("Your session has expired, please log in again");
@@ -95,11 +95,11 @@ var manifold = {
        if (data) {
             if (!!domid) {
                /* Directly inform the requestor */
-               if (manifold.asynchroneous_debug) $.publish("/messages/debug","directing results to " + domid);
+               if (manifold.asynchroneous_debug) messages.debug("directing results to " + domid);
                jQuery('#' + domid).trigger('results', [data]);
             } else {
                /* Publish an update announce */
-               if (manifold.asynchroneous_debug) $.publish("/messages/debug","publishing results on " + publish_uuid);
+               if (manifold.asynchroneous_debug) messages.debug("publishing results on " + publish_uuid);
                jQuery.publish("/results/" + publish_uuid + "/changed", [data, query]);
             }
 
index 5f79452..ef7e457 100644 (file)
@@ -48,7 +48,7 @@ class ManifoldAPI:
             except xmlrpclib.Fault, error:
                 ### xxx this is very rough for now
                 # until we have some agreement about how the API calls should return error conditions
-                # in some less unpolite way than this anoanymous exception, we assume it's a problem with the session
+                # in some less unpolite way than this anonymous exception, we assume it's a problem with the session
                 # that needs to be refreshed
                 if debug: print "Session Expired"
                 if error.faultCode == 8002:
index d0636c8..7a6235c 100644 (file)
@@ -66,9 +66,11 @@ with the query passed using POST"""
         answer=manifold_api.send_manifold_query (manifold_query)
         if debug: print 'manifoldproxy.proxy: received from backend with code', answer['code']
         json_answer=json.dumps(answer)
+        # if in debug mode we save this so we can use offline mode later
         if (debug):
             with (file(offline_filename,"w")) as f:
                 f.write(json_answer)
+        # this is an artificial delay added for debugging purposes only
         if debug_spin:
             import time
             time.sleep(debug_spin)
index 7afc726..3a9335f 100644 (file)
@@ -53,7 +53,7 @@
                 $.subscribe(query_channel,  function(e, query) { hazelnut.set_query(query); });
                 $.subscribe(update_channel, function(e, resources, instance) { hazelnut.set_resources(resources, instance); });
                 $.subscribe(results_channel, $this, function(e, rows) { hazelnut.update_plugin(e,rows); });
-               if (debug) console.log("hazelnut '" + this.id + "' subscribed to e.g." + results_channel);
+               if (debug) messages.debug("hazelnut '" + this.id + "' subscribed to e.g." + results_channel);
 
             }); // this.each
         }, // init
@@ -75,7 +75,7 @@
         show : function( ) {
            var $this=$(this);
            // xxx wtf. why [1] ? would expect 0...
-           if (debug) console.log("Hitting suspicious line in hazelnut.show");
+           if (debug) messages.debug("Hitting suspicious line in hazelnut.show");
             var oTable = $($('.dataTable', $this)[1]).dataTable();
             oTable.fnAdjustColumnSizing()
     
        // xxx thierry : initialize this here - it was not, I expect this relied on set_query somehow..
         //this.current_query = null;
        this.current_query=manifold.find_query(this.options.query_uuid);
-       if (debug) console.log("Hazelnut constructor: have set current_query -> " + this.current_query);
+       if (debug) messages.debug("Hazelnut constructor: have set current_query -> " + this.current_query);
        this.query_update = null;
         this.current_resources = Array();
 
             previous_query = this.current_query;
             /* Save the query as the current query */
             this.current_query = query;
-           if (debug) console.log("hazelnut.set_query, current_query is now -> " + this.current_query);
+           if (debug) messages.debug("hazelnut.set_query, current_query is now -> " + this.current_query);
             /* We check all necessary fields : in column editor I presume XXX */
             // XXX ID naming has no plugin_uuid
             if (typeof(query.fields) != 'undefined') {        
         }
 
         this.set_resources = function(resources, instance) {
-           if (debug) console.log("entering hazelnut.set_resources");
+           if (debug) messages.debug("entering hazelnut.set_resources");
             var options = this.options;
             var previous_resources = this.current_resources;
             this.current_resources = resources;
          * XXX will be removed/replaced
          */
         this.selected_changed = function(e, change) {
-           if (debug) console.log("entering hazelnut.selected_changed");
+           if (debug) messages.debug("entering hazelnut.selected_changed");
             var actions = change.split("/");
             if (actions.length > 1) {
                 var oNodes = this.table.fnGetNodes();
            // e.data is what we passed in second argument to subscribe
            // so here it is the jquery object attached to the plugin <div>
            var $plugindiv=e.data;
-           if (debug) console.log("entering hazelnut.update_plugin on id '" + $plugindiv.attr('id') + "'");
+           if (debug) messages.debug("entering hazelnut.update_plugin on id '" + $plugindiv.attr('id') + "'");
            // clear the spinning wheel: look up an ancestor that has the need-spin class
            // do this before we might return
            $plugindiv.closest('.need-spin').spin(false);
                 this.table.html(unfold.errorDisplay("No Result"));   
                 return;
             } else if (typeof(rows[0].error) != 'undefined') {
-               if (debug) console.log ("undefined result");
+               if (debug) messages.debug ("undefined result");
                 this.table.html(unfold.errorDisplay(rows[0].error));
                 return;
             }
             });
     
            this.table.fnClearTable();
-           if (debug) console.log("hazelnut.update_plugin: total of " + newlines.length + " rows");
+           if (debug) messages.debug("hazelnut.update_plugin: total of " + newlines.length + " rows");
             this.table.fnAddData(newlines);
     
         };
index 2a579fc..bbf537e 100644 (file)
@@ -1,10 +1,10 @@
 /* font size for regular (non datatable'd) simplelists */
 tbody.simplelist {
-    font-size: 80%;
+    font-size: 120%;
 }
 /* datatable'd tables behave differently */
 table.with-datatables>tbody.simplelist {
-    font-size: 100%;
+    font-size: 80%;
 }
 /* larger headers */
 thead.simplelist>tr>th {
index 172cd34..11f812b 100644 (file)
                var channel='/results/' + options.query_uuid + '/changed';
                /* passing $this as 2nd arg: callbacks will retrieve $this as e.data */
                $.subscribe(channel, $this, update_plugin);
-               if (debug) window.console.log('subscribing to ' + channel);
+               if (debug) window.messages.debug('subscribing to ' + channel);
                $this.data('SimpleList', options);
            });
        },
        destroy : function( ) {
-           if (debug) console.log("SimpleList.destroy...");
+           if (debug) messages.debug("SimpleList.destroy...");
             return this.each(function(){
                var $this = $(this), data = $this.data('SimpleList');
                // xxx not too sure what this is about
@@ -42,7 +42,7 @@
             });
        },
        update : function( content ) { 
-           if (debug) console.log("SimpleList.update...");
+           if (debug) messages.debug("SimpleList.update...");
        },
     }; // methods
 
@@ -59,7 +59,7 @@
        // also we may or may not have a header
        var $tbody=$table.find("tbody.simplelist").first();
        var use_datatables = $table.hasClass("with-datatables");
-       if (debug) console.log($plugindiv.attr('id') + " udt= " + use_datatables);
+       if (debug) messages.debug($plugindiv.attr('id') + " udt= " + use_datatables);
        
        // clear the spinning wheel: look up an ancestor that has the need-spin class
        // do this before we might return
@@ -98,7 +98,7 @@
     }
 
     function regular_update_table ($table, $tbody, rows, key) {
-       if (debug) console.log('regular_update_table ' + rows.length + " rows");
+       if (debug) messages.debug('regular_update_table ' + rows.length + " rows");
        var html=$.map(rows, function (row) { return html_row ( cell (key, row[key])); }).join();
        $tbody.html(html);
     }
     }
 
     function datatables_update_table ($table, $tbody, rows, key) {
-       if (debug) console.log('datatables_update_table ' + rows.length + " rows");
+       if (debug) messages.debug('datatables_update_table ' + rows.length + " rows");
        $table.dataTable().fnClearTable();
        // the lambda here returns a [[]] because $.map is kind of broken; as per the doc:
        // The function can return any value to add to the array. A returned array will be flattened into the resulting array.
index 76f1fb3..47c2ba1 100644 (file)
                        $.subscribe("/messages/"+level, function (e, msg){ instance.display_message (msg,level)});
                    }) (instance,level);
                }
+               // kind of patchy, notify the convenience functions that somebody is listening...
+               try {messages.ready=true;}
+               catch (err) { console.log("Could not set messages.ready");}
                // this happens very early - even before the document is loaded
                // so it won't show right away; no big deal though
-                $.publish  ("/messages/info", 'Subscribed to all 5 message channels');
+                $.publish ("/messages/info", 'Subscribed to all 5 message channels');
             });
         },
         destroy : function( ) {
index 8670afa..6dc00c4 100644 (file)
@@ -22,7 +22,7 @@
 
     var methods = {
        init : function (options) {
-           if (debug) console.log("SyntaxHighlighter.all ...");
+           if (debug) messages.debug("SyntaxHighlighter.all ...");
             SyntaxHighlighter.all();
            return this.each(function() {
                var $this=$(this);
@@ -32,7 +32,7 @@
                    var channel='/results/' + options.query_uuid + '/updated';
                    /* passing $this as 2nd arg: callbacks will retrieve $this as e.data */
                    $.subscribe(channel, $this, update_plugin);
-                   if (debug) console.log('subscribing to ' + channel);
+                   if (debug) messages.debug('subscribing to ' + channel);
                    $this.data('QueryCode', {options: options});
                    // react to changes to the language selector
                    $this.find(".querycode-lang").change(change_language);
        }, 
 
 //     destroy : function( ) {
-//         if (debug) console.log("QueryCode.destroy...");
+//         if (debug) messages.debug("QueryCode.destroy...");
 //     },
 //     update : function( content ) { 
-//         if (debug) console.log("QueryCode.update...");
+//         if (debug) messages.debug("QueryCode.update...");
 //     },
        
     } // methods
        funname="translate_query_as_" + lang;
        fun=eval(funname);
        if (! fun) {
-           console.log("Cannot find translator function for lang " + lang);
+           messages.debug("Cannot find translator function for lang " + lang);
            return;
        }
        html_code=fun(query);
        dom.html(html_code);
-       if (debug) console.log("SyntaxHighlighter.highlight");
+       if (debug) messages.debug("SyntaxHighlighter.highlight");
        SyntaxHighlighter.highlight()
     }
 
index 419fb07..455a2c3 100644 (file)
                 // Remove first to clean up select boxes
                 var removed_filters = tmp.removed;
                 $.each(removed_filters, function(i,filter){
-                    console.log(filter[0]);
+                    messages.debug(filter[0]);
                     allowedValues=metadata.property('resource', filter[0], 'allowed_values');
                     if (allowedValues!='' && allowedValues!="N/A") {
                        //if(MANIFOLD_METADATA[filter[0]]['allowed_values']!=''){
 
         $('#QuickFilter_select_field').change( function () {
             var field = $(this).val();
-            console.log(field);
+            messages.debug(field);
             $('input[id^="QuickFilter-string-"]').hide();
             $('#QuickFilter_int_value_div').hide();
             if(field=="#"){
         });
         
         $('.QuickFilter_select').change( function() {
-            console.log(this.id);
+            messages.debug(this.id);
             var query = data.current_query;
            var f_value = $(this).val();
             
                          f_value = "";
            */
             if(typeof(key[1])!="undefined"){
-                console.log(key[1]+'='+f_value);
+                messages.debug(key[1]+'='+f_value);
                 if(f_value==""){
                     query.remove_filter(key[1],"","");
                 }else{
index ae349f7..b28a05b 100644 (file)
@@ -71,7 +71,7 @@
            messages.debug("submit_update_request");
            var query_uuid = e.data.options.query_uuid;
            var update_query = e.data.update_query;
-           $.publish("/messages/debug","Updater.submit_update_request " + update_query.__repr());
+           messages.debug("Updater.submit_update_request " + update_query.__repr());
            // actually send the Update query, but publish results as if coming from the original query
            manifold.asynchroneous_exec ( [ {'query_uuid': update_query.query_uuid, 'publish_uuid' : query_uuid} ]);
            // looks like a previous attempt to disable the button while the query is flying
index f9c9663..e75c82e 100644 (file)
@@ -37,6 +37,7 @@ def test_plugin_view (request):
                                 fields=['network','type','hrn','hostname'],
                                 filters= [ [ 'slice_hrn', '=', slicename, ] ],
                                 )
+    # don't run this one as nothing listens to this
     page.enqueue_query (main_query, run_it=False)
 
     main_plugin = \
@@ -45,21 +46,19 @@ def test_plugin_view (request):
         title='thestack',
         togglable=False,
         sons=[ \
-#            Hazelnut (page=page, 
-#                      query=main_query,
-#                      ),
-            Messages (
-                page=page,
-                title="Runtime messages",
-                domid="msgs-pre",
-                levels='ALL',
-                ),
             Updater (
                     page=page,
                     title="Update me",
                     query=main_query,
                     label="Update me",
+                    domid="the-updater",
                     ),
+            Messages (
+                page=page,
+                title="Runtime messages",
+                domid="msgs-pre",
+                levels='ALL',
+                ),
             ])
 
     # define 'unfold1_main' to the template engine
index 456d635..ec43a44 100644 (file)
@@ -48,6 +48,7 @@ def slice_view (request, slicename=tmp_default_slice):
                 page=page,
                 title="Runtime messages",
                 domid="msgs-pre",
+                levels="ALL",
                 ),
             Tabs (
                 page=page,
index fa4d552..7bf3ef5 100644 (file)
@@ -1,15 +1,20 @@
-// messages runtime -- convenience functions messages.fatal and the like
+// messages runtime -- convenience functions messages.debug and the like
 // in addition, messages can get lost if the UI is not ready to accept them
 // so we use console.log in this case
 var messages = {
     ready : false,
     levels : ['fatal','error','warning','info','debug'],
     handler : function (level,msg) {
-       if (messages.ready) $.publish("/messages/"+level+"/",msg);
+       if (messages.ready) $.publish("/messages/"+level,msg);
        else console.log("/messages/"+level+"/: "+msg);
     },
 };
-for (var i in messages.levels) { var level=messages.levels[i]; messages[level]=function (msg) {messages.handler (level,msg)};}
-$(function(){messages.ready=true;})
+for (var i in messages.levels) { 
+    var level=messages.levels[i]; 
+    (function (level) { messages[level]=function (msg) {messages.handler (level,msg)};})(level);
+}
+// messages.ready is set by the messages plugin once it is ready to listen on the 5 channels
+// this way messages don't get lost if the view does not have a messages instance
+//$(function(){messages.ready=true;})
     
 
index 8efe77c..65d4d20 100644 (file)
@@ -8,7 +8,7 @@ var plugin = {
     ////////// use local storage to remember open/closed toggles
     store_status : function (domid,status) {
        var key='toggle.'+domid;
-       if (plugin.debug) console.log("storing toggle status " + status + " for " + domid + " key=" + key);
+       if (plugin.debug) messages.debug("storing toggle status " + status + " for " + domid + " key=" + key);
        $.localStorage.setItem(key,status);
     },
     // restore last status
@@ -18,7 +18,7 @@ var plugin = {
        var retrieved=$.localStorage.getItem(key);
        // set default to true
        if (retrieved==null) retrieved="true";
-       if (plugin.debug) console.log ("retrieved toggle status for " + domid + " (key=" + key + ") -> " + retrieved);
+       if (plugin.debug) messages.debug ("retrieved toggle status for " + domid + " (key=" + key + ") -> " + retrieved);
        return retrieved;
     },
     set_toggle_status : function (domid,status) {
@@ -31,7 +31,7 @@ var plugin = {
     },
     set_from_saved_status : function (domid) {
        var previous_status=plugin.retrieve_last_status (domid);
-       if (plugin.debug) console.log("restoring initial status for domid " + domid + " -> " + previous_status);
+       if (plugin.debug) messages.debug("restoring initial status for domid " + domid + " -> " + previous_status);
        plugin.set_toggle_status (domid,previous_status);
     },
     // triggered upon $(document).ready
index 0d3a54d..67db643 100644 (file)
@@ -4,11 +4,11 @@ var unfold = {
        if (maxdepth===undefined) maxdepth=5;
        var up=null, counter=0;
        while (true) {
-           console.log(counter+" "+msg+" id='"+dom.id+"' ["+dom.classList+"]");
+           messages.debug(counter+" "+msg+" id='"+dom.id+"' ["+dom.classList+"]");
            up=dom.parentNode;
            counter += 1;
            if ( (up == null) || (up === dom)) break;
-           if (counter >= maxdepth) { console.log(counter+" "+msg+" -> ..."); break; }
+           if (counter >= maxdepth) { messages.debug(counter+" "+msg+" -> ..."); break; }
            dom=up;
        }
     },
index 1df8d9b..a6ab97f 100644 (file)
@@ -3,7 +3,7 @@
 $(document).ready(function () {
 var query_publish_dom_tuples = new Array();
 {% for d in query_publish_dom_tuples %}try {query_publish_dom_tuples.push({'query_uuid':"{{ d.query_uuid }}"{%if d.domid %},'domid':"{{ d.domid }}"{% endif %}}) } 
-catch(err){console.log ("Could not expose query {{ d.query_uuid }}")}
+catch(err){messages.debug ("Could not expose query {{ d.query_uuid }}")}
 {% endfor %}
 manifold.asynchroneous_exec(query_publish_dom_tuples);
 })