X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fquerytable%2F__init__.py;h=dfd84f4a9c81e5bb40559582606c9144d63ed36d;hb=fcbcb07e40441b9396d2fa75d189e9e32fc464fa;hp=96456f5602f7b2fb014804ec885975db278a9789;hpb=d1197c134b70bda643a752bdaf891190cb5a15e7;p=myslice.git diff --git a/plugins/querytable/__init__.py b/plugins/querytable/__init__.py index 96456f56..dfd84f4a 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,9 @@ class QueryTable (Plugin): else: self.columns = [] self.hidden_columns = [] + # needs to be json-serializable, and sets are not + self.columns=list(self.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) @@ -56,20 +86,44 @@ class QueryTable (Plugin): def requirements (self): reqs = { - 'js_files' : [ "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js", - "js/dataTables.js", "js/dataTables.bootstrap.js", "js/with-datatables.js", - "js/manifold.js", "js/manifold-query.js", - "js/unfold-helper.js", - # querytable.js needs to be loaded after dataTables.js as it extends - # dataTableExt.afnSortData - "js/querytable.js", - ] , - 'css_files': [ "css/dataTables.bootstrap.css", - # hopefully temporary, when/if datatables supports sPaginationType=bootstrap3 - # for now we use full_numbers, with our own ad hoc css - "css/dataTables.full_numbers.css", - "css/querytable.css" , - ], + 'js_files' : [ + "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js", +# this one was in the slickgrid demo +# http://mleibman.github.io/SlickGrid/examples/example-checkbox-row-select.html +# but triggers js errors when included - probably/maybe because of the jquery version ? +# it might be responsible for not being able to select a row by clicking anywhere in it ? +# "http://mleibman.github.io/SlickGrid/lib/jquery-ui-1.8.16.custom.min.js", + "js/jquery.event.drag-2.2.js", # from slickgrid/lib + "js/slick.core.js", + "js/slick.autotooltips.js", # from slickgrid/plugins/ + "js/slick.cellrangedecorator.js", # from slickgrid/plugins/ + "js/slick.cellrangeselector.js", # from slickgrid/plugins/ + "js/slick.cellcopymanager.js", # from slickgrid/plugins/ + "js/slick.cellselectionmodel.js", # from slickgrid/plugins/ + "js/slick.rowselectionmodel.js", # from slickgrid/plugins/ + "js/slick.checkboxselectcolumn.js", # from slickgrid/plugins/ + "js/slick.columnpicker.js", # from slickgrid/controls/ + "js/slick.formatters.js", + "js/slick.editors.js", + "js/slick.grid.js", + +# "js/dataTables.js", "js/dataTables.bootstrap.js", "js/with-datatables.js", + "js/manifold.js", "js/manifold-query.js", + "js/unfold-helper.js", + # querytable.js needs to be loaded after dataTables.js as it extends + # dataTableExt.afnSortData + "js/querytable.js", + ] , + 'css_files': [ +# "css/dataTables.bootstrap.css", + # hopefully temporary, when/if datatables supports sPaginationType=bootstrap3 + # for now we use full_numbers, with our own ad hoc css +# "css/dataTables.full_numbers.css", + "css/querytable.css" , + "http://mleibman.github.io/SlickGrid/slick.grid.css", +# "http://mleibman.github.io/SlickGrid/css/smoothness/jquery-ui-1.8.16.custom.css", +# "http://mleibman.github.io/SlickGrid/examples/examples.css", + ], } return reqs @@ -78,4 +132,5 @@ class QueryTable (Plugin): return ['plugin_uuid', 'domid', 'query_uuid', 'query_all_uuid', 'checkboxes', 'datatables_options', - 'hidden_columns'] + 'columns','hidden_columns', + 'id_key',]