From: Jordan Augé Date: Tue, 3 Dec 2013 16:27:42 +0000 (+0100) Subject: Merge branch 'master' of ssh://git.onelab.eu/git/myslice X-Git-Tag: myslice-0.3-0~96^2~2 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=f7ed6e816b00fabaf57d2946638a988a3043c3f5;hp=c5b4da52191579b5762f2571e6511c4a6f5abd22;p=unfold.git Merge branch 'master' of ssh://git.onelab.eu/git/myslice --- diff --git a/plugins/querytable/__init__.py b/plugins/querytable/__init__.py index 96456f56..b7b92f44 100644 --- a/plugins/querytable/__init__.py +++ b/plugins/querytable/__init__.py @@ -2,13 +2,40 @@ from unfold.plugin import Plugin class QueryTable (Plugin): - # set checkboxes if a final column with checkboxes is desired - # pass columns as the initial set of columns - # if None then this is taken from the query's fields - # also please refrain from passing an 'aoColumns' as datatables_options - # as we use 'aoColumnDefs' instead + """A plugin for displaying a query as a list + +More accurately, we consider a subject entity (say, a slice) +that can be linked to any number of related entities (say, resources, or users) +The 'query' argument will correspond to the subject, while +'query_all' will fetch the complete list of +possible candidates for the relationship. + +Current implementation makes the following assumptions +* query will only retrieve for the related items a list of fields + that corresponds to the initial set of fields displayed in the table +* query_all on the contrary is expected to return the complete set of + available attributes that may be of interest, so that using a QueryEditor + one can easily extend this table without having to query the backend +* checkboxes is a boolean flag, set to true if a rightmost column + with checkboxes is desired +* optionally pass columns as the initial set of columns + if None then this is taken from the query's fields +* id_key is the name of a column used internally in the plugin + for checkboxes management. Caller should specify a column that is present + in the fields returned by 'query' and that has unique values. + If not specified, metadata will be used to find out a primary key. + However in the case of nodes & slice for example, the default key + as returned by the metadata would be 'urn', but it is not necessarily + a good idea to show urn's initially - if at all. + This is why a slice view would use 'hrn' here instead. +* datatables_options are passed to dataTables as-is; + however please refrain from passing an 'aoColumns' + as we use 'aoColumnDefs' instead. +""" + def __init__ (self, query=None, query_all=None, checkboxes=False, columns=None, + id_key=None, datatables_options={}, **settings): Plugin.__init__ (self, **settings) self.query = query @@ -30,6 +57,7 @@ class QueryTable (Plugin): else: self.columns = [] self.hidden_columns = [] + self.id_key=id_key self.datatables_options=datatables_options # if checkboxes were required, we tell datatables about this column's type # so that sorting can take place on a selected-first basis (or -last of course) @@ -78,4 +106,4 @@ class QueryTable (Plugin): return ['plugin_uuid', 'domid', 'query_uuid', 'query_all_uuid', 'checkboxes', 'datatables_options', - 'hidden_columns'] + 'hidden_columns', 'id_key',] diff --git a/plugins/querytable/static/js/querytable.js b/plugins/querytable/static/js/querytable.js index 12232c8e..9d7bced0 100644 --- a/plugins/querytable/static/js/querytable.js +++ b/plugins/querytable/static/js/querytable.js @@ -41,17 +41,18 @@ var query = manifold.query_store.find_analyzed_query(this.options.query_uuid); this.method = query.object; - var keys = manifold.metadata.get_key(this.method); - 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 - // the code tries to access record[this.key] the records only have - // keys=type,hrn,network_hrn,hostname - // 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 googlemap - this.key= (this.key == 'urn') ? 'hrn' : this.key; + // 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 (! this.key) messages.warning("querytable.init could not kind valid key"); + + messages.debug("querytable: key="+this.key); /* Setup query and record handlers */ this.listen_query(options.query_uuid); diff --git a/plugins/tabs/static/js/tabs.js b/plugins/tabs/static/js/tabs.js index bfd568a9..4612dd25 100644 --- a/plugins/tabs/static/js/tabs.js +++ b/plugins/tabs/static/js/tabs.js @@ -58,7 +58,6 @@ var tabs_helper = { // persistent-active var domid=$(e.target).closest(".persistent-active").attr('id'); tabs_helper.store_active_domid(domid,active_domid); - console.log("CLICKED domid="+domid+" active_domid="+active_domid); }); }, diff --git a/portal/sliceview.py b/portal/sliceview.py index 6c9b46c7..0c32b401 100644 --- a/portal/sliceview.py +++ b/portal/sliceview.py @@ -31,6 +31,9 @@ tmp_default_slice='ple.upmc.myslicedemo' #do_query_users=True do_query_users=False +#do_query_leases=True +do_query_leases=False + insert_messages=False #insert_messages=True @@ -43,6 +46,7 @@ class SliceView (LoginRequiredAutoLogoutView): page.add_js_files ( [ "js/common.functions.js" ] ) page.add_js_chunks ('$(function() { messages.debug("sliceview: jQuery version " + $.fn.jquery); });') page.add_js_chunks ('$(function() { messages.debug("sliceview: users turned %s"); });'%("on" if do_query_users else "off")) + page.add_js_chunks ('$(function() { messages.debug("sliceview: leases turned %s"); });'%("on" if do_query_leases else "off")) config=Config() page.add_js_chunks ('$(function() { messages.debug("manifold URL %s"); });'%(config.manifold_url())) page.expose_js_metadata() @@ -64,6 +68,9 @@ class SliceView (LoginRequiredAutoLogoutView): 'user.user_hrn', #'application.measurement_point.counter' ) + # for internal use in the querytable plugin; + # needs to be a unique column present for each returned record + main_query_key = 'hrn' query_resource_all = Query.get('resource').select(resource_fields) if do_query_users: @@ -180,6 +187,8 @@ class SliceView (LoginRequiredAutoLogoutView): # this is the query at the core of the slice list 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, checkboxes = True, datatables_options = { 'iDisplayLength': 25, @@ -188,28 +197,36 @@ class SliceView (LoginRequiredAutoLogoutView): }, ) - resources_as_scheduler = Scheduler( - page = page, - title = 'Scheduler', - domid = 'scheduler', - query = sq_resource, - query_all_resources = query_resource_all, - query_lease = sq_lease, - ) + if do_query_leases: + resources_as_scheduler = Scheduler( + page = page, + title = 'Scheduler', + domid = 'scheduler', + query = sq_resource, + query_all_resources = query_resource_all, + query_lease = sq_lease, + ) # with the new 'Filter' stuff on top, no need for anything but the querytable resources_as_list_area = resources_as_list + resources_sons = [ + resources_as_gmap, + resources_as_3dmap, + resources_as_scheduler, + resources_as_list_area, + ] if do_query_leases else [ + resources_as_gmap, + resources_as_3dmap, + resources_as_list_area, + ] + resources_area = Tabs ( page=page, domid="resources", togglable=True, title="Resources", outline_complete=True, - sons=[ - resources_as_gmap, - resources_as_3dmap, - resources_as_scheduler, - resources_as_list_area, ], + sons= resources_sons, active_domid = 'resources-map', persistent_active=True, ) diff --git a/ui/templates/base.html b/ui/templates/base.html index f7787353..908f0f40 100644 --- a/ui/templates/base.html +++ b/ui/templates/base.html @@ -5,7 +5,6 @@ {# This is where insert_str will end up #}{% media_container prelude %} {% include 'messages-transient-header.html' %} - {{ header_prelude }} diff --git a/unfold/page.py b/unfold/page.py index a6ca83cd..c61d1593 100644 --- a/unfold/page.py +++ b/unfold/page.py @@ -33,7 +33,8 @@ class Page: # queue of queries with maybe a domid, see enqueue_query self._queue=[] # global prelude object - self.prelude=Prelude(css_files=['css/plugin.css','css/onelab_marko.css',]) + # global requirements should go in base.html + self.prelude=Prelude() # record known plugins hashed on their domid def record_plugin (self, plugin):