Merge branch 'master' of ssh://git.onelab.eu/git/myslice
authorLoic Baron <loic.baron@lip6.fr>
Fri, 6 Dec 2013 16:07:18 +0000 (17:07 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Fri, 6 Dec 2013 16:07:18 +0000 (17:07 +0100)
manifold/manifoldapi.py
manifold/static/js/record_generator.js [new file with mode: 0644]
plugins/maddash/static/css/maddash.css
portal/accountview.py
portal/templates/account-view.html
sandbox/urls.py
sandbox/views.py
ui/topmenu.py
unfold/page.py

index 664bb32..180807b 100644 (file)
@@ -113,6 +113,8 @@ def _execute_query(request, query, manifold_api_session_auth):
     print "-"*80
     result = manifold_api.forward(query.to_dict())
     if result['code'] == 2:
+        # XXX only if we know it is the issue
+        del request.session['manifold']
         raise Exception, 'Error running query: %r' % result
     
     if result['code'] == 1:
diff --git a/manifold/static/js/record_generator.js b/manifold/static/js/record_generator.js
new file mode 100644 (file)
index 0000000..f53c7ee
--- /dev/null
@@ -0,0 +1,71 @@
+/* Buffered DOM updates */
+var RecordGenerator = Class.extend({
+
+    init: function(query, generators, number)
+    {
+        this._query      = query;
+        this._generators = generators;
+        this._number     = number;
+    },
+
+    random_int: function(options)
+    {
+        var default_options = {
+            max: 1000
+        }
+
+        if (typeof options == 'object')
+            options = $.extend(default_options, options);
+        else
+            options = default_options;
+
+        return Math.floor(Math.random()*(options.max+1));
+    },
+
+    random_string: function()
+    {
+        var default_options = {
+            possible: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+            len:      this.random_int({max: 15})
+        }
+
+        if (typeof options == 'object')
+            options = $.extend(default_options, options);
+        else
+            options = default_options;
+
+        var text = "";
+
+        for( var i=0; i < options.len; i++ )
+            text += options.possible.charAt(Math.floor(Math.random() * options.possible.length));
+
+        return text;
+
+    },
+
+    generate_record: function()
+    {
+        var self = this;
+        var record = {};
+
+        $.each(this._query.fields, function(i, field) {
+            record[field] = self[self._generators[field]]();
+        });
+
+        // Publish records
+        manifold.raise_record_event(self._query.query_uuid, NEW_RECORD, record);
+        
+    },
+
+    run: function()
+    {
+        var record;
+        manifold.raise_record_event(this._query.query_uuid, CLEAR_RECORDS);
+        for (var i = 0; i < this._number; i++) {
+            record = this.generate_record();
+            /* XXX publish record */
+        }
+        manifold.raise_record_event(this._query.query_uuid, DONE);
+
+    }
+});
index 93ece29..9b8abbc 100644 (file)
@@ -1,5 +1,6 @@
-#maddash__maddash {
+.MadDash {
        height: 600px;
+       background: white;
 }
 
 .grid-container{float:left;overflow:hidden;margin-right:10px;}
index f7fa1b8..f0e7a4a 100644 (file)
@@ -60,12 +60,15 @@ class AccountView(LoginRequiredAutoLogoutView):
                     account_type_list.append(account_type)
                     usr_hrn_list.append(account_usr_hrn)
                     pub_key_list.append(account_pub_key)
+            
+                # to hide private key row if it doesn't exist    
+                if 'myslice' in platform_detail['platform']:
+                    account_config = json.loads(account_detail['config'])
+                    account_priv_key = account_config.get('user_private_key','N/A')
         
         # combining 4 lists into 1 [to render in the template] 
         lst = [{'platform_name': t[0], 'account_type': t[1], 'usr_hrn':t[2], 'usr_pubkey':t[3]} 
                for t in zip(platform_name_list, account_type_list, usr_hrn_list, pub_key_list)]
-        #print "test"
-        #print lst
 
         context = super(AccountView, self).get_context_data(**kwargs)
         context['data'] = lst
@@ -74,7 +77,7 @@ class AccountView(LoginRequiredAutoLogoutView):
         context ['lastname'] = config.get('lastname',"?")
         context ['fullname'] = context['firstname'] +' '+ context['lastname']
         context ['authority'] = config.get('authority',"Unknown Authority")
-        #context['users'] = userlist.render(self.request)
+        context['user_private_key'] = account_priv_key
         
         # XXX This is repeated in all pages
         # more general variables expected in the template
index 4b04246..1133452 100644 (file)
                                                <button id="upload_file" type="button" title="Upload a public key"> Upload </button>       
                                </td>
                        </tr>
-                       <tr class="even" id="pkey_row" display="none">
-                               <td class="key">Private Key </td>
+                       <tr class="even" id="pkey_row">
+                                {%if 'N/A' not in user_private_key%}
+                               <td class="key">Private Key </td> <!-- Hide if priv_key doesn't exist in myslice platform   -->
                                <td class="value">********<a href="#">
                                        <button type="submit" name="dl_pkey" class="download" title="Download your privaye key" id="dl_pkey"> Download </button>
                                        <button id="delete" name="delete" type="submit" title="Delete your private key">Delete </button>
                                </td>
+                                {%endif%}              
                                </tr>
                                <tr class="odd">
                                <td colspan="2">
index e5b210c..94e9463 100644 (file)
@@ -24,7 +24,9 @@ from django.views.generic.base   import TemplateView
 from django.conf.urls           import patterns, include, url
 
 from sandbox.views import MyPluginView
+from sandbox.views import MadDashView
 
 urlpatterns = patterns('', 
-    url(r'^myplugin/?$', MyPluginView.as_view(), name='myplugin')
+    url(r'^myplugin/?$', MyPluginView.as_view(), name='myplugin'),
+    url(r'^maddash/?$', MadDashView.as_view(), name='maddash')
 )
index dda1771..707e8f7 100644 (file)
@@ -26,14 +26,13 @@ import json
 from django.http                import HttpResponseRedirect, HttpResponse
 from django.shortcuts           import render
 from django.template.loader     import render_to_string
-
-from unfold.loginrequired       import FreeAccessView
+from manifold.core.query        import Query
+from plugins.myplugin           import MyPlugin
+from plugins.maddash            import MadDash
 from ui.topmenu                 import topmenu_items, the_user
-
+from unfold.loginrequired       import FreeAccessView
 from unfold.page                import Page
 
-from plugins.myplugin           import MyPlugin
-
 # NOTE
 # initially all the portal views were defined in this single file
 # all the other ones have now migrated into separate classes/files for more convenience
@@ -46,17 +45,14 @@ class MyPluginView(FreeAccessView):
 
         page = Page(self.request)
 
-#        pres_view = PresView(page = page)
-        plugin = MyPlugin(page = page, html="<h1>PresView needs to be integrated</h1>")
-
+        plugin = MyPlugin(page = page)
         context = super(MyPluginView, self).get_context_data(**kwargs)
-
         context['unfold_main'] = plugin.render(self.request)
 
         # more general variables expected in the template
         context['title'] = 'Sandbox for MyPlugin plugin'
         # the menu items on the top
-        context['topmenu_items'] = topmenu_items('PresView', self.request)
+        context['topmenu_items'] = topmenu_items('myplugin', self.request)
         # so we can sho who is logged
         context['username'] = the_user(self.request)
 
@@ -65,3 +61,35 @@ class MyPluginView(FreeAccessView):
 
         return context
 
+
+class MadDashView(FreeAccessView):
+    template_name = "view-unfold1.html"
+
+    def get_context_data(self, **kwargs):
+        page = Page(self.request)
+
+        # This will simulate fake records in order to test the plugin
+        fake_query = Query.get('ping').select('hrn', 'src_hostname', 'dst_hostname', 'delay')
+        fake_query_all = Query.get('ping').select('hrn', 'src_hostname', 'dst_hostname', 'delay')
+
+        generators = {
+            'hrn': 'random_string',
+            'src_hostname': 'random_string',
+            'dst_hostname': 'random_string',
+            'delay': 'random_int'
+        }
+        page.generate_records(fake_query, generators, 5)
+        page.generate_records(fake_query_all, generators, 20)
+
+        plugin = MadDash(query = fake_query, query_all = fake_query_all, page = page)
+        context = super(MadDashView, self).get_context_data(**kwargs)
+        context['unfold_main'] = plugin.render(self.request)
+        context['title'] = 'Sandbox for MadDash plugin'
+        context['topmenu_items'] = topmenu_items('maddash', self.request)
+        context['username'] = the_user(self.request)
+
+        prelude_env = page.prelude_env()
+        context.update(prelude_env)
+
+        return context
+
index de44555..860e180 100644 (file)
@@ -21,7 +21,10 @@ def topmenu_items (current,request=None):
         # ** Where am I a PI **
         # For this we need to ask SFA (of all authorities) = PI function
         pi_authorities_query = Query.get('ple:user').filter_by('user_hrn', '==', '$user_hrn').select('pi_authorities')
-        pi_authorities_tmp = execute_query(request, pi_authorities_query)
+        try:
+            pi_authorities_tmp = execute_query(request, pi_authorities_query)
+        except:
+            pi_authorities_tmp = set()
         pi_authorities = set()
         for pa in pi_authorities_tmp:
             pi_authorities |= set(pa['pi_authorities'])
index c61d159..0d3a81e 100644 (file)
@@ -69,6 +69,10 @@ class Page:
         # we only do this if run_it is set
         if run_it: self._queue.append ( (query.query_uuid,domid) )
 
+    def generate_records(self, query, generators, number):
+        self.add_js_files('js/record_generator.js');
+        self.add_js_chunks('$(document).ready(function() { new RecordGenerator(' + query.to_json() + ', ' + json.dumps(generators) + ', 10).run(); });')
+
     # return the javascript code for exposing queries
     # all queries are inserted in the global manifold object
     # in addition, the ones enqueued with 'run_it=True' are triggered