From d8f20800f3709f4958493d2e1e1f8a8a98b0e29a Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 11 Apr 2013 16:02:02 +0200 Subject: [PATCH] always use messages.* stuff --- manifold/js/manifold.js | 30 +++++++++++++++--------------- manifold/manifoldapi.py | 2 +- manifold/manifoldproxy.py | 2 ++ plugins/hazelnut/hazelnut.js | 18 +++++++++--------- plugins/lists/simplelist.css | 4 ++-- plugins/lists/simplelist.js | 12 ++++++------ plugins/messages/messages.js | 5 ++++- plugins/querycode/querycode.js | 12 ++++++------ plugins/quickfilter/quickfilter.js | 8 ++++---- plugins/updater/updater.js | 2 +- trash/pluginview.py | 17 ++++++++--------- trash/sliceview.py | 1 + unfold/js/messages-runtime.js | 13 +++++++++---- unfold/js/plugin.js | 6 +++--- unfold/js/unfold-helper.js | 4 ++-- unfold/templates/page-queries.js | 2 +- 16 files changed, 74 insertions(+), 64 deletions(-) diff --git a/manifold/js/manifold.js b/manifold/js/manifold.js index 4d005d09..4eb58fac 100644 --- a/manifold/js/manifold.js +++ b/manifold/js/manifold.js @@ -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]); } diff --git a/manifold/manifoldapi.py b/manifold/manifoldapi.py index 5f79452d..ef7e4572 100644 --- a/manifold/manifoldapi.py +++ b/manifold/manifoldapi.py @@ -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: diff --git a/manifold/manifoldproxy.py b/manifold/manifoldproxy.py index d0636c88..7a6235c4 100644 --- a/manifold/manifoldproxy.py +++ b/manifold/manifoldproxy.py @@ -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) diff --git a/plugins/hazelnut/hazelnut.js b/plugins/hazelnut/hazelnut.js index 7afc726b..3a9335fa 100644 --- a/plugins/hazelnut/hazelnut.js +++ b/plugins/hazelnut/hazelnut.js @@ -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() @@ -103,7 +103,7 @@ // 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(); @@ -157,7 +157,7 @@ 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') { @@ -205,7 +205,7 @@ } 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; @@ -234,7 +234,7 @@ * 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(); @@ -258,7 +258,7 @@ // e.data is what we passed in second argument to subscribe // so here it is the jquery object attached to the plugin
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); @@ -271,7 +271,7 @@ 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; } @@ -322,7 +322,7 @@ }); 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); }; diff --git a/plugins/lists/simplelist.css b/plugins/lists/simplelist.css index 2a579fc6..bbf537e7 100644 --- a/plugins/lists/simplelist.css +++ b/plugins/lists/simplelist.css @@ -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 { diff --git a/plugins/lists/simplelist.js b/plugins/lists/simplelist.js index 172cd34e..11f812b9 100644 --- a/plugins/lists/simplelist.js +++ b/plugins/lists/simplelist.js @@ -28,12 +28,12 @@ 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); } @@ -110,7 +110,7 @@ } 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. diff --git a/plugins/messages/messages.js b/plugins/messages/messages.js index 76f1fb39..47c2ba17 100644 --- a/plugins/messages/messages.js +++ b/plugins/messages/messages.js @@ -29,9 +29,12 @@ $.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( ) { diff --git a/plugins/querycode/querycode.js b/plugins/querycode/querycode.js index 8670afa1..6dc00c4c 100644 --- a/plugins/querycode/querycode.js +++ b/plugins/querycode/querycode.js @@ -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); @@ -45,10 +45,10 @@ }, // 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 @@ -75,12 +75,12 @@ 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() } diff --git a/plugins/quickfilter/quickfilter.js b/plugins/quickfilter/quickfilter.js index 419fb070..455a2c3d 100644 --- a/plugins/quickfilter/quickfilter.js +++ b/plugins/quickfilter/quickfilter.js @@ -137,7 +137,7 @@ // 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']!=''){ @@ -198,7 +198,7 @@ $('#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=="#"){ @@ -249,7 +249,7 @@ }); $('.QuickFilter_select').change( function() { - console.log(this.id); + messages.debug(this.id); var query = data.current_query; var f_value = $(this).val(); @@ -261,7 +261,7 @@ 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{ diff --git a/plugins/updater/updater.js b/plugins/updater/updater.js index ae349f7c..b28a05bf 100644 --- a/plugins/updater/updater.js +++ b/plugins/updater/updater.js @@ -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 diff --git a/trash/pluginview.py b/trash/pluginview.py index f9c96635..e75c82e7 100644 --- a/trash/pluginview.py +++ b/trash/pluginview.py @@ -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 diff --git a/trash/sliceview.py b/trash/sliceview.py index 456d635d..ec43a442 100644 --- a/trash/sliceview.py +++ b/trash/sliceview.py @@ -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, diff --git a/unfold/js/messages-runtime.js b/unfold/js/messages-runtime.js index fa4d552d..7bf3ef54 100644 --- a/unfold/js/messages-runtime.js +++ b/unfold/js/messages-runtime.js @@ -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;}) diff --git a/unfold/js/plugin.js b/unfold/js/plugin.js index 8efe77ca..65d4d202 100644 --- a/unfold/js/plugin.js +++ b/unfold/js/plugin.js @@ -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 diff --git a/unfold/js/unfold-helper.js b/unfold/js/unfold-helper.js index 0d3a54d8..67db643e 100644 --- a/unfold/js/unfold-helper.js +++ b/unfold/js/unfold-helper.js @@ -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; } }, diff --git a/unfold/templates/page-queries.js b/unfold/templates/page-queries.js index 1df8d9bd..a6ab97f4 100644 --- a/unfold/templates/page-queries.js +++ b/unfold/templates/page-queries.js @@ -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); }) -- 2.43.0