From df482c9a6212b2b7134e8130358d213562b9df44 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 14 Mar 2013 08:53:59 +0100 Subject: [PATCH] simplified manifold config (one url will do just fine) expose it to js for querycode --- auth/views.py | 2 +- engine/manifoldapi.py | 8 +++---- engine/page.py | 16 ++++++++++---- myslice/config.py | 11 +++++----- plugins/querycode.py | 2 ++ plugins/static/js/querycode.js | 39 ++++++++++++++++----------------- plugins/static/js/simplelist.js | 23 +++++++++---------- trash/dashboard.py | 12 +++++----- 8 files changed, 61 insertions(+), 52 deletions(-) diff --git a/auth/views.py b/auth/views.py index 5237a645..6490ef59 100644 --- a/auth/views.py +++ b/auth/views.py @@ -14,7 +14,7 @@ def login_user(request): state = "Please log in below..." username = password = '' env={'hard_wired_users':MyCustomBackend.hard_wired_users, - 'manifold_url':Config.manifold_url(), + 'manifold_url':Config.manifold_url, } if request.POST: diff --git a/engine/manifoldapi.py b/engine/manifoldapi.py index 111241c5..1001f1b9 100644 --- a/engine/manifoldapi.py +++ b/engine/manifoldapi.py @@ -11,15 +11,15 @@ class ManifoldAPI: config = Config() self.auth = auth - self.server = config.manifold_server - self.port = config.manifold_port - self.path = config.manifold_path +# self.server = config.manifold_server +# self.port = config.manifold_port +# self.path = config.manifold_path self.cainfo = cainfo self.errors = [] self.trace = [] self.calls = {} self.multicall = False - self.url = config.manifold_url() + self.url = config.manifold_url self.proxy = xmlrpclib.Server(self.url, verbose=False, allow_none=True) def __getattr__(self, methodName): diff --git a/engine/page.py b/engine/page.py index 850aa7cf..dfbb5a95 100644 --- a/engine/page.py +++ b/engine/page.py @@ -3,8 +3,10 @@ # it is expected to exist one such object for a given page import json + from engine.prelude import Prelude from engine.manifoldapi import ManifoldAPI +from myslice.config import Config # decorator to deflect calls on this Page to its prelude def to_prelude (method): @@ -16,15 +18,17 @@ def to_prelude (method): class Page: def __init__ (self, request): + self.request=request + # all plugins mentioned in this page self._plugins = {} # queue of queries self._queue=[] + # global prelude object self.prelude=Prelude(css_files='css/plugin.css') - # no queries yet, needed ? # load metadata self._metadata={} self._metadata_javascript='' - self.load_metadata(request) + self.expose_js_metadata() # record known plugins hashed on their domid def record_plugin (self, plugin): @@ -38,7 +42,8 @@ class Page: # the js async methods (see manifold_async_success) # offer the option to deliver the result to a specific DOM elt - # otherwise it goes through the pubsub using query's uuid + # otherwise (i.e. if domid not provided) + # it goes through the pubsub using query's uuid def enqueue_query (self, query, domid=None): self._queue.append ( (query,domid,) ) @@ -57,7 +62,8 @@ class Page: self.add_js_chunks (js) - def load_metadata(self, request): + def expose_js_metadata(self): + request=self.request if 'metadata' not in request.session.keys(): manifold_api_session_auth = request.session['manifold']['auth'] manifold_api = ManifoldAPI(auth=manifold_api_session_auth) @@ -87,6 +93,8 @@ class Page: def metadata_get_fields(self, method): return self._metadata[method]['column'].sort() + def expose_js_manifold_config (self): + self.add_js_chunks(Config.manifold_js_export()) #################### requirements/prelude management # just forward to self.prelude - see decorator above diff --git a/myslice/config.py b/myslice/config.py index 3293f1d1..b8aabba9 100644 --- a/myslice/config.py +++ b/myslice/config.py @@ -1,10 +1,9 @@ class Config: - manifold_server = 'manifold.pl.sophia.inria.fr' -# manifold_server = 'demo.myslice.info' - manifold_port = '7080' - manifold_path = '/' + # production should use https of course + manifold_url = "http://manifold.pl.sophia.inria.fr:7080/" + # exporting these details to js @staticmethod - def manifold_url (): - return "http://%s:%s%s"%(Config.manifold_server,Config.manifold_port,Config.manifold_path) + def manifold_js_export (): + return "var MANIFOLD_URL = '%s';"%Config.manifold_url; diff --git a/plugins/querycode.py b/plugins/querycode.py index cdc2929c..637c66b0 100644 --- a/plugins/querycode.py +++ b/plugins/querycode.py @@ -5,6 +5,8 @@ class QueryCode (Plugin): def __init__ (self, query, **settings): Plugin.__init__ (self, **settings) self.query=query + # our javascript requires the details of the manifold server + self.page.expose_js_manifold_config() def template_file (self): return "querycode.html" diff --git a/plugins/static/js/querycode.js b/plugins/static/js/querycode.js index a8e1e890..2c912449 100644 --- a/plugins/static/js/querycode.js +++ b/plugins/static/js/querycode.js @@ -21,6 +21,17 @@ function debug_object (msg, o) { (function($) { + $.fn.QueryCode = function( method ) { + /* Method calling logic */ + if ( methods[method] ) { + return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( typeof method === 'object' || ! method ) { + return methods.init.apply( this, arguments ); + } else { + $.error( 'Method ' + method + ' does not exist on jQuery.QueryCode' ); + } + }; + var methods = { init : function (options) { console.log("temporarily turned off SyntaxHighlighter ..."); @@ -54,19 +65,9 @@ function debug_object (msg, o) { } // methods - $.fn.QueryCode = function( method ) { - /* Method calling logic */ - if ( methods[method] ) { - return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); - } else if ( typeof method === 'object' || ! method ) { - return methods.init.apply( this, arguments ); - } else { - $.error( 'Method ' + method + ' does not exist on jQuery.QueryCode' ); - } - }; - // we retrieve the plugindiv as e.data - cf the 2nd arg to subscribe - function update_plugin (e) { + // in fact we don't really read the published message + function update_plugin (e, _) { var $plugindiv=e.data; do_update ($plugindiv); } @@ -107,8 +108,7 @@ function debug_object (msg, o) { output += ' remove_const :ENABLE_NIL_PARSER\n'; output += ' const_set :ENABLE_NIL_PARSER, true\n'; output += 'end\n'; - output += 'srv = XMLRPC::Client.new2("https://www.top-hat.info/API/")\n'; - //output += 'tophat = xmlrpclib.ServerProxy("' . (TOPHAT_API_PORT == 443 ? 'http' : 'https') . '://' . TOPHAT_API_HOST . ':' . TOPHAT_API_PORT . TOPHAT_API_PATH . '", allow_none=True)\n\n'; + output += 'srv = XMLRPC::Client.new2("' + MANIFOLD_URL + '")\n'; output += '\n'; output += '# Authentication token\n'; output += 'auth = {"AuthMethod" => "password", "Username" => "guest", "AuthString" => "guest"}\n'; @@ -132,7 +132,7 @@ function debug_object (msg, o) { }); ofs = '[' + ofs + ']'; - output += 'pp srv.call("' + query.action +'", auth, "' + query.method + '", "' + query.timestamp + '", ' + ifs + ', ' + ofs + ')'; + output += 'pp srv.call("' + title_case(query.action) +'", auth, "' + query.method + '", "' + query.timestamp + '", ' + ifs + ', ' + ofs + ')'; var output = '
' + output + "
"; return output; @@ -140,12 +140,9 @@ function debug_object (msg, o) { } function translate_query_as_python (query) { - // xxx tmp - var TOPHAT_API_HOST="hostname", TOPHAT_API_PORT=443, TOPHAT_API_PATH="/path"; - var proto = (TOPHAT_API_PORT == 443 ? 'https' : 'http'); var output = '# Connection to XMLRPC server\n'; output += 'import xmlrpclib\n'; - output += 'srv = xmlrpclib.ServerProxy("' + proto + '://' + TOPHAT_API_HOST + ':' + TOPHAT_API_PORT + TOPHAT_API_PATH + '", allow_none=True)\n\n'; + output += 'srv = xmlrpclib.ServerProxy("' + MANIFOLD_URL + '", allow_none=True)\n\n'; output += '# Authentication token\n'; output += 'auth = {"AuthMethod": "password", "Username": "name.surname@domain.name", "AuthString": "mypassword"}\n\n'; @@ -168,10 +165,12 @@ function debug_object (msg, o) { }); ofs = '[' + ofs + ']'; - output += 'srv.' + query.action + '(auth, "' + query.method + '", ' + ifs + ', {}, ' + ofs + ')'; + output += 'srv.' + title_case(query.action) + '(auth, "' + query.method + '", ' + ifs + ', {}, ' + ofs + ')'; var output = '
' + output + "
"; return output; } + + function title_case (txt){ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();} })(jQuery); // end closure wrapper diff --git a/plugins/static/js/simplelist.js b/plugins/static/js/simplelist.js index 3d166a7c..ab320e5e 100644 --- a/plugins/static/js/simplelist.js +++ b/plugins/static/js/simplelist.js @@ -11,6 +11,18 @@ simplelist_debug=false; //simplelist_debug=true; (function($){ + + $.fn.SimpleList = function( method ) { + /* Method calling logic */ + if ( methods[method] ) { + return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( typeof method === 'object' || ! method ) { + return methods.init.apply( this, arguments ); + } else { + $.error( 'Method ' + method + ' does not exist on jQuery.SimpleList' ); + } + }; + var methods = { init : function( options ) { return this.each(function(){ @@ -40,17 +52,6 @@ simplelist_debug=false; }, }; // methods - $.fn.SimpleList = function( method ) { - /* Method calling logic */ - if ( methods[method] ) { - return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); - } else if ( typeof method === 'object' || ! method ) { - return methods.init.apply( this, arguments ); - } else { - $.error( 'Method ' + method + ' does not exist on jQuery.SimpleList' ); - } - }; - /* Private methods */ // complexity here is mostly because a datatables-enabled table cannot // be updated in a "normal" way using .html() diff --git a/trash/dashboard.py b/trash/dashboard.py index ef8639fe..62a0618f 100644 --- a/trash/dashboard.py +++ b/trash/dashboard.py @@ -37,20 +37,20 @@ def dashboard_view (request): page=page, title="Putting stuff together", sons=[ + QueryCode ( + page=page, + title="Vizualize your query (no syntax highlight for now)", + query=slices_query, + toggled=False, + ), SliceList ( # setting visible attributes first page=page, title='Asynchroneous SliceList', header='slices list', with_datatables=False, - toggled=False, # this is the query at the core of the slice list query=slices_query, ), - QueryCode ( - page=page, - title="Vizualize your query", - query=slices_query, - ), ]) # variables that will get passed to the view-plugin.html template -- 2.43.0