Using URNs instead of HRNs = this works for the checkboxes in querytable & googlemap...
authorLoic Baron <loic.baron@lip6.fr>
Fri, 6 Dec 2013 16:04:13 +0000 (17:04 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Fri, 6 Dec 2013 16:04:13 +0000 (17:04 +0100)
plugins/googlemap/static/js/googlemap.js
plugins/querytable/static/js/querytable.js
portal/registrationview.py
portal/slicerequestview.py
portal/sliceview.py
portal/static/js/common.functions.js

index 00410ea..c288830 100644 (file)
@@ -27,10 +27,10 @@ googlemap_debug_detailed=false;
             this.in_set_backlog = [];
 
             // we keep a couple of global hashes
-           // lat_lon --> { marker, <ul> }
-           // id --> { <li>, <input> }
-           this.by_lat_lon = {};
-           this.by_id = {};
+               // lat_lon --> { marker, <ul> }
+               // id --> { <li>, <input> }
+               this.by_lat_lon = {};
+               this.by_id = {};
 
             /* XXX Events */
             this.elmt().on('show', this, this.on_show);
@@ -40,9 +40,9 @@ googlemap_debug_detailed=false;
             var query = manifold.query_store.find_analyzed_query(this.options.query_uuid);
             this.object = query.object;
 
-            var keys = manifold.metadata.get_key(this.object);
+        //    var keys = manifold.metadata.get_key(this.object);
            // 
-            this.key = (keys && keys.length == 1) ? keys[0] : null;
+        //    this.key = (keys && keys.length == 1) ? keys[0] : null;
 
            // xxx temporary hack
            // as of nov. 28 2013 we have here this.key='urn', but in any place where
@@ -51,7 +51,13 @@ googlemap_debug_detailed=false;
            // so for now we force using hrn instead
            // as soon as record have their primary key set this line can be removed
            // see also same hack in querytable
-           this.key= (this.key == 'urn') ? 'hrn' : this.key;
+           //this.key= (this.key == 'urn') ? 'hrn' : this.key;
+        this.key = (this.options.id_key);
+        if (typeof(this.key)=='undefined' || (this.key).startsWith("unknown")) {
+            // if not specified by caller, decide from metadata
+            var keys = manifold.metadata.get_key(this.object);
+            this.key = (keys && keys.length == 1) ? keys[0] : null;
+        }
 
             //// Setup query and record handlers 
            // this query is the one about the slice itself 
@@ -141,7 +147,8 @@ googlemap_debug_detailed=false;
            var checkbox = $("<input>", {type:'checkbox', checked:checked, class:'geo'});
            var id=this.record_id(record);
            // use hrn as far as possible for displaying
-           var label= ('hrn' in record) ? record.hrn : id;
+           // var label= ('hrn' in record) ? record.hrn : id;
+           var label= (this.key in record) ? record[this.key] : id;
            ul.append($("<li>").addClass("geo").append(checkbox).
                      append($("<span>").addClass("geo").append(label)));
            var googlemap=this;
@@ -154,12 +161,12 @@ googlemap_debug_detailed=false;
        },
            
        warning: function (record,message) {
-           try {messages.warning (message+" -- hostname="+record.hostname); }
+           try {messages.warning (message+" -- "+this.key+"="+record[this.key]); }
            catch (err) {messages.warning (message); }
        },
            
        // retrieve DOM checkbox and make sure it is checked/unchecked
-        set_checkbox: function(record, checked) {
+    set_checkbox: function(record, checked) {
            var id=this.record_id (record);
            if (! id) { 
                this.warning (record, "googlemap.set_checkbox: record has no id");
@@ -171,7 +178,7 @@ googlemap_debug_detailed=false;
                return; 
            }
            checkbox.prop('checked',checked);
-        }, // set_checkbox
+     }, // set_checkbox
 
        // this record is *in* the slice
         new_record: function(record) {
index 9d7bced..39e5049 100644 (file)
             // $(window).unbind('QueryTable');
 
             var query = manifold.query_store.find_analyzed_query(this.options.query_uuid);
-            this.method = query.object;
+            this.object = query.object;
 
            // xxx beware that this.key needs to contain a key that all records will have
            // in general query_all will return well populated records, but query
            // returns records with only the fields displayed on startup. 
            this.key = (this.options.id_key);
-           if (! this.key) {
-               // if not specified by caller, decide from metadata
-               var keys = manifold.metadata.get_key(this.method);
-               this.key = (keys && keys.length == 1) ? keys[0] : null;
+           if (typeof(this.key)=='undefined' || (this.key).startsWith("unknown")) {
+                   // if not specified by caller, decide from metadata
+                   var keys = manifold.metadata.get_key(this.object);
+                   this.key = (keys && keys.length == 1) ? keys[0] : null;
            }
            if (! this.key) messages.warning("querytable.init could not kind valid key");
-
            messages.debug("querytable: key="+this.key);
 
             /* Setup query and record handlers */
             }
 
 
-           if (id === undefined) {
-               messages.warning("querytable.set_checkbox record has no id to figure which line to tick");
-               return;
-           }
+               if (id === undefined) {
+                       messages.warning("querytable.set_checkbox record has no id to figure which line to tick");
+                       return;
+               }
+            // PB TO CHECK THE RIGHT CHECKBOXES IS HERE... flat_id using \ in the key
+            // need to use escape_id when creating the id of the checkboxes
             var checkbox_id = this.flat_id(this.id('checkbox', id));
             // function escape_id(myid) is defined in portal/static/js/common.functions.js
             checkbox_id = escape_id(checkbox_id);
+            // As we are using [id="x"] syntax, we need to remove the # in the checkbox_id
+            checkbox_id = checkbox_id.replace("#","");
             // using dataTables's $ to search also in nodes that are not currently displayed
-            var element = this.table.$(checkbox_id);
+            var element = this.table.$('[id="' + checkbox_id + '"]');
             if (debug) 
                 messages.debug("set_checkbox checked=" + checked
                                + " id=" + checkbox_id + " matches=" + element.length);
             var self = e.data;
 
             // XXX this.value = key of object to be added... what about multiple keys ?
-           if (debug) messages.debug("querytable click handler checked=" + this.checked + " hrn=" + this.value);
+           if (debug) messages.debug("querytable click handler checked=" + this.checked + " "+this.key+"=" + this.value);
             manifold.raise_event(self.options.query_uuid, this.checked?SET_ADD:SET_REMOVED, this.value);
             //return false; // prevent checkbox to be checked, waiting response from manifold plugin api
             
index 8f7032b..8f91de7 100644 (file)
@@ -31,15 +31,16 @@ class RegistrationView (FreeAccessView):
     def get_or_post  (self, request, method):
         errors = []
 
-        #authorities_query = Query.get('authority').\
-        #    select('name', 'authority_hrn')
+        # Using cache manifold-tables to get the list of authorities faster
+        authorities_query = Query.get('authority').select('name', 'authority_hrn')
         
         #onelab_enabled_query = Query.get('local:platform').filter_by('platform', '==', 'ple').filter_by('disabled', '==', 'False')
         #onelab_enabled = not not execute_admin_query(request, onelab_enabled_query)
         #if onelab_enabled:
         if True:
             print "ONELAB ENABLED"
-            authorities_query = Query.get('ple:authority').select('name', 'authority_hrn').filter_by('authority_hrn', 'included', ['ple.inria', 'ple.upmc', 'ple.ibbtple', 'ple.nitos'])
+            #authorities_query = Query.get('ple:authority').select('name', 'authority_hrn').filter_by('authority_hrn', 'included', ['ple.inria', 'ple.upmc', 'ple.ibbtple', 'ple.nitos'])
+            # Now using Cache 
         else:
             print "FIREXP ENABLED"
 
index c34a903..0c4a5be 100644 (file)
@@ -14,13 +14,15 @@ from ui.topmenu                  import topmenu_items, the_user
 class SliceRequestView (LoginRequiredAutoLogoutView):
 
     def authority_hrn_initial (self, request):
-        #authorities_query = Query.get('authority').\
-        #    select('name', 'authority_hrn')
+        # Using cache manifold-tables to get the list of authorities
+        authorities_query = Query.get('authority').\
+            select('name', 'authority_hrn')
         
         #onelab_enabled_query = Query.get('local:platform').filter_by('platform', '==', 'ple-onelab').filter_by('disabled', '==', 'False')
         #onelab_enabled = not not execute_admin_query(request, onelab_enabled_query)
         #if onelab_enabled:
-        authorities_query = Query.get('ple:authority').select('name', 'authority_hrn').filter_by('authority_hrn', 'included', ['ple.inria', 'ple.upmc', 'ple.ibbtple','ple.nitos'])
+        #authorities_query = Query.get('ple:authority').select('name', 'authority_hrn').filter_by('authority_hrn', 'included', ['ple.inria', 'ple.upmc', 'ple.ibbtple','ple.nitos'])
+        # Now using Cache
 
         authorities = execute_admin_query(request, authorities_query)
         authorities = sorted(authorities)
index 0c32b40..4d23bbb 100644 (file)
@@ -62,7 +62,7 @@ class SliceView (LoginRequiredAutoLogoutView):
         main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
         main_query.select(
                 'slice_hrn',
-                'resource.hrn', 'resource.hostname', 'resource.type', 
+                'resource.hrn', 'resource.urn', 'resource.hostname', 'resource.type', 
                 'resource.network_hrn',
                 'lease.urn',
                 'user.user_hrn',
@@ -70,7 +70,7 @@ class SliceView (LoginRequiredAutoLogoutView):
         )
         # for internal use in the querytable plugin;
         # needs to be a unique column present for each returned record
-        main_query_key = 'hrn'
+        #main_query_key = 'hrn'
     
         query_resource_all = Query.get('resource').select(resource_fields)
         if do_query_users:
@@ -188,7 +188,7 @@ class SliceView (LoginRequiredAutoLogoutView):
             query      = sq_resource,
             query_all  = query_resource_all,
             # safer to use 'hrn' as the internal unique key for this plugin
-            id_key     = main_query_key,
+            #id_key     = main_query_key,
             checkboxes = True,
             datatables_options = { 
                 'iDisplayLength': 25,
index d6f3f99..481e947 100644 (file)
@@ -15,6 +15,20 @@ function getKeySplitId(id,separator){
     return key;
 }
 
+// Adding startsWith & endsWith to the string prototype
+if ( typeof String.prototype.startsWith != 'function' ) {
+  String.prototype.startsWith = function( str ) {
+    return this.substring( 0, str.length ) === str;
+  }
+};
+
+if ( typeof String.prototype.endsWith != 'function' ) {
+  String.prototype.endsWith = function( str ) {
+    return this.substring( this.length - str.length, this.length ) === str;
+  }
+};
+// http://stackoverflow.com/questions/646628/javascript-startswith
+
 function arrays_equal(a,b) { return !(a<b || b<a); }
 
 function arrayInArray(elt,tab){