simplified manifold config (one url will do just fine)
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 14 Mar 2013 07:53:59 +0000 (08:53 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 14 Mar 2013 07:53:59 +0000 (08:53 +0100)
expose it to js for querycode

auth/views.py
engine/manifoldapi.py
engine/page.py
myslice/config.py
plugins/querycode.py
plugins/static/js/querycode.js
plugins/static/js/simplelist.js
trash/dashboard.py

index 5237a64..6490ef5 100644 (file)
@@ -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:
index 111241c..1001f1b 100644 (file)
@@ -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):
index 850aa7c..dfbb5a9 100644 (file)
@@ -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
index 3293f1d..b8aabba 100644 (file)
@@ -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;
index cdc2929..637c66b 100644 (file)
@@ -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"
index a8e1e89..2c91244 100644 (file)
@@ -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 = '<pre class="brush: ruby; toolbar: false;">' + output + "</pre>";
        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 = '<pre class="brush: python; toolbar: false;">' + output + "</pre>";
        return output;
     }
+
+    function title_case (txt){ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}
     
 })(jQuery); // end closure wrapper
 
index 3d166a7..ab320e5 100644 (file)
@@ -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()
index ef8639f..62a0618 100644 (file)
@@ -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