Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
authorLoic Baron <loic.baron@lip6.fr>
Thu, 5 Jun 2014 13:09:54 +0000 (15:09 +0200)
committerLoic Baron <loic.baron@lip6.fr>
Thu, 5 Jun 2014 13:09:54 +0000 (15:09 +0200)
manifoldapi/static/js/manifold.js
plugins/queryupdater/static/js/queryupdater.js
portal/sliceresourceview.py
portal/templates/account-view.html
portal/templates/slice-resource-view.html
portal/templates/slice-tab-users-view.html
rest/__init__.py

index f0bbc8a..fa5415a 100644 (file)
@@ -475,15 +475,18 @@ var manifold = {
                 var key = manifold.metadata.get_key(method);
                 if (!key)
                     continue;
-                if (key.length > 1)
-                    continue;
-                key = key[0];
                 var sq_keys = [];
                 var subrecords = record[method];
                 if (!subrecords)
                     continue
                 $.each(subrecords, function (i, subrecord) {
-                    sq_keys.push(subrecord[key]);
+                    if (key.length == 1){
+                        key = key[0];
+                        sq_keys.push(subrecord[key]);
+                    }else{
+                        // more than what's necessary, but should work
+                        sq_keys.push(subrecord);
+                    }
                 });
                 update_query.params[method] = sq_keys;
                 update_query_orig.params[method] = sq_keys.slice();
index 5a7f7ba..774392b 100644 (file)
     var QueryUpdater = Plugin.extend({
 
         init: function(options, element) {
-           this.classname="queryupdater";
+               this.classname="queryupdater";
             this._super(options, element);
 
             var self = this;
+
+            this.initial = Array();
+
             this.table = this.elmt('table').dataTable({
 // the original querytable layout was
 //                sDom: "<'row'<'col-xs-5'l><'col-xs-1'r><'col-xs-6'f>>t<'row'<'col-xs-5'i><'col-xs-7'p>>",
 
         do_update: function(e) {
             var self = e.data;
+
+            self.spin();
+            console.log("do_update");
+
             // XXX check that the query is not disabled
             manifold.raise_event(self.options.query_uuid, RUN_UPDATE);
+
+            // how to stop the spinning after the event? 
+            // this should be triggered by some on_updatequery_done ?
         },
 
        // related buttons are also disabled in the html template
 
         set_state: function(data)
         {
+            console.log("function set_state");
             var action;
             var msg;
             var button = '';
 
         on_new_record: function(record)
         {
+            console.log("query_updater on_new_record");
+            console.log(record);
+
             // if (not and update) {
 
                 // initial['resource'], initial['lease'] ?
-                this.initial.push(record.urn);
+                this.initial.push(record);
 
+            //this.set_record_state(record, RECORD_STATE_ATTACHED);
                 // We simply add to the table
             // } else {
                 //                 \ this.initial_resources
 
         on_query_in_progress: function()
         {
-           messages.debug("queryupdater.on_query_in_progress");
+               messages.debug("queryupdater.on_query_in_progress");
             this.spin();
         },
 
             this.clear();
         },
 
-        on_new_record: function(record)
-        {
-        },
-
         on_query_done: function()
         {
+            console.log("on_query_done");
             this.unspin();
         },
 
         // NOTE: record_key could be sufficient 
         on_added_record: function(record)
         {
+            console.log("on_added_record = ",record);
             this.set_record_state(record, RECORD_STATE_ADDED);
             // update pending number
         },
 
         on_removed_record: function(record_key)
         {
+            console.log("on_removed_record = ",record_key);
             this.set_record_state(RECORD_STATE_REMOVED);
         },
 
 
         on_field_state_changed: function(result)
         {
+            console.log("on_field_state_changed");
+            console.log(result);
             messages.debug(result)
             /* this.set_state(result.request, result.key, result.value, result.status); */
             this.set_state(result);
              if (!change)
                 return;
              // ioi: Refubrished
-             var initial = this.initial_resources;
+             var initial = this.initial;
              //var r_removed  = []; //
              /*-----------------------------------------------------------------------
                 TODO: remove this dirty hack !!!
index 2034eac..f99c7d9 100644 (file)
@@ -19,6 +19,7 @@ from plugins.queryupdater            import QueryUpdater
 from plugins.testbeds                import TestbedsPlugin
 from plugins.scheduler2              import Scheduler2
 from plugins.columns_editor          import ColumnsEditor
+from plugins.lists.simplelist        import SimpleList
 
 from myslice.theme import ThemeView
 
@@ -43,13 +44,16 @@ class SliceResourceView (LoginRequiredView, ThemeView):
         user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
 
         # TODO The query to run is embedded in the URL
+        # Example: select slice_hrn, resource.urn, lease.resource, lease.start_time, lease.end_time from slice where slice_hrn == "ple.upmc.myslicedemo"
         main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
         main_query.select(
                 'slice_hrn',
                 'resource.urn', 
                 'resource.hostname', 'resource.type',
                 'resource.network_hrn',
-                'lease.urn',
+                'lease.resource',
+                'lease.start_time',
+                'lease.end_time',
                 #'user.user_hrn',
                 #'application.measurement_point.counter'
         )
@@ -95,21 +99,35 @@ class SliceResourceView (LoginRequiredView, ThemeView):
         # RESERVED RESOURCES LIST
         # resources as a list using datatable plugin
  
-        list_reserved_resources = QueryTable(
-            page       = page,
-            domid      = 'resources-reserved-list',
-            title      = 'List view',
-            query      = sq_resource,
-            query_all  = sq_resource,
-            init_key   = "urn",
-            checkboxes = True,
-            datatables_options = {
-                'iDisplayLength': 25,
-                'bLengthChange' : True,
-                'bAutoWidth'    : True,
-                },
+        list_reserved_resources = SimpleList(
+            title = None,
+            page  = page,
+            key   = 'urn',
+            query = sq_resource,
         )
 
+        list_reserved_leases = SimpleList(
+            title = None,
+            page  = page,
+            key   = 'resource',
+            query = sq_lease,
+        )
+
+#        list_reserved_resources = QueryTable(
+#            page       = page,
+#            domid      = 'resources-reserved-list',
+#            title      = 'List view',
+#            query      = sq_resource,
+#            query_all  = sq_resource,
+#            init_key   = "urn",
+#            checkboxes = True,
+#            datatables_options = {
+#                'iDisplayLength': 25,
+#                'bLengthChange' : True,
+#                'bAutoWidth'    : True,
+#                },
+#        )
+
         # --------------------------------------------------------------------------
         # COLUMNS EDITOR
         # list of fields to be applied on the query 
@@ -203,7 +221,8 @@ class SliceResourceView (LoginRequiredView, ThemeView):
 
         template_env = {}
         template_env['list_resources'] = list_resources.render(self.request)
-#         template_env['list_reserved_resources'] = list_reserved_resources.render(self.request)
+        template_env['list_reserved_resources'] = list_reserved_resources.render(self.request)
+        template_env['list_reserved_leases'] = list_reserved_leases.render(self.request)
 
         template_env['columns_editor'] = filter_column_editor.render(self.request)
 
index 353a83c..c60efb9 100644 (file)
                                        <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="#">
+                                               <td class="value">********<a href="#"></a>
                                                        <button type="submit" name="dl_pkey" class="btn btn-default btn-xs" title="Download your privaye key" id="dl_pkey">
                                                                        <span class="glyphicon glyphicon-download"></span> Download     
                                                                </button>
                                                </td>
                                                  {%else%}
                                                        <td class="key">Private Key </td> <!-- Hide if priv_key doesn't exist in myslice platform   -->
-                                                       <td class="value">********<a href="#">
+                                                       <td class="value">********<a href="#"></a>
                                                        <button type="submit" name="dl_pkey" class="btn btn-default btn-xs disabled" title="Download your privaye key" id="dl_pkey">
                                                                <span class="glyphicon glyphicon-download"></span> Download 
                                                        </button>
index 707fa36..27ac3c5 100644 (file)
                                <!-- <table cellpadding="0" cellspacing="0" border="0" class="table" id="objectList"></table> -->
                        </div>
                        <div id="reserved" class="panel" style="height:370px;display:none;">
-                {{list_reserved_resources}}
+                <table width="80%">
+                    <tr><th width="50%" style="text-align:center;">resources</th><th width="50%" style="text-align:center;">leases</th></tr>
+                    <tr>
+                        <td style="text-align:center">{{list_reserved_resources}}</td>
+                        <td style="text-align:center">{{list_reserved_leases}}</td>
+                    </tr>
+                </table>
                        </div>
                        <div id="pending" class="panel" style="height:370px;display:none;">
                 {{pending_resources}}
index 50806ac..6942861 100644 (file)
                </div>
 <script>
     $(document).ready(function() {
+            // TODO: Add a filter based on the list of authorities
+               $.post("/rest/authority/",{'fields':['authority_hrn']}, function( data ) {
+                console.log(data);
+            }); // post rest/authority
+
                        var slice_users = [];
                $.post("/rest/user/",{'filters':{'parent_authority': "{{user_details.parent_authority}}"}}, function( data ) {
                var list_users = [];
                        table_users.push(user_row);
                 
                });
-                                console.log("slice users before");
-                                console.log(slice_users);
             
                                $("table#user-tab tr:last").after(table_users.join( "" ));
                $("div#user-tab-loaded").css("display","block");
                $("div#user-tab-loading").css("display","none");
                 $("input:checkbox.user").click(function() {
-                    console.log("user_hrn");
                     user_hrn = $(this).closest('tr').find('td:eq(2)').html();
-                    console.log(user_hrn);
-                    console.log(this.checked);
                     if(this.checked){
                         var record_id = this.id;
                         slice_users.push (user_hrn);
                     }else{
-                        console.log("not checked");
-                        slice_users = $.grep(slice_users, function( user, i ) {
-                            return user != user_hrn;
-                        });
+                        console.log(slice_users);
                     }
-                    console.log(slice_users);
                 });
            
                }); // post rest/user
                $('button#addusers').click(function() {
                 $.post("/update/slice/",{'filters':{'slice_hrn':'{{slice}}'},'params':{'users':slice_users}}, function(data) {
-                    console.log(data);
                        if(data.success){
                        // TODO: highlight row after success
                        //$('tr[id="'+record_id+'"]').highlight();
index 1ca3797..a856596 100644 (file)
@@ -40,21 +40,33 @@ class ObjectRequest(object):
             self.filters['disabled'] = '0'
             self.filters['gateway_type'] = 'sfa'
             self.filters['platform'] = '!myslice'
-        elif(self.type.startswith('local:')):
-            # XXX TODO: find a generic Query to get the fields like 
-            # select column.name from local:object where table == local:user
+        #elif(self.type.startswith('local:')):
+        elif ':' in self.type:
             table = self.type.split(':')
+            prefix = table[0]
             table = table[1]
-            if table == "user":
-                self.id = table + '_id'
-                self.fields = ['user_id', 'email', 'password', 'config','status'];
-            elif table == "account":
-                # XXX TODO: Multiple key for account = (platform_id, user_id)
-                self.id = "platform_id, user_id"
-                self.fields = ['platform_id', 'user_id', 'auth_type', 'config'];
-            elif table == "platform":
-                self.id = 'platform'
-                self.fields = ['platform', 'platform_longname', 'platform_url', 'platform_description','gateway_type'];
+
+            if prefix is 'local':
+                # XXX TODO: find a generic Query to get the fields like 
+                # select column.name from local:object where table == local:user
+                table = self.type.split(':')
+                table = table[1]
+                if table == "user":
+                    self.id = table + '_id'
+                    self.fields = ['user_id', 'email', 'password', 'config','status'];
+                elif table == "account":
+                    # XXX TODO: Multiple key for account = (platform_id, user_id)
+                    self.id = "platform_id, user_id"
+                    self.fields = ['platform_id', 'user_id', 'auth_type', 'config'];
+                elif table == "platform":
+                    self.id = 'platform'
+                    self.fields = ['platform', 'platform_longname', 'platform_url', 'platform_description','gateway_type'];
+            else:
+                # If we use prefix, set the key without the prefix then add it again
+                self.type = table
+                self.setKey()
+                self.setLocalFields()
+                self.type = prefix + ':' + table
         else :
             self.setKey()
             self.setLocalFields()