1 from unfold.plugin import Plugin
3 class UnivbrisFv (Plugin):
7 ////////////////////////////////////////
9 modified querytable for univbris foam
10 ///////////////////////////////////////
12 A plugin for displaying a query as a list
14 More accurately, we consider a subject entity (say, a slice)
15 that can be linked to any number of related entities (say, resources, or users)
16 The 'query' argument will correspond to the subject, while
17 'query_all' will fetch the complete list of
18 possible candidates for the relationship.
20 Current implementation makes the following assumptions
21 * query will only retrieve for the related items a list of fields
22 that corresponds to the initial set of fields displayed in the table
23 * query_all on the contrary is expected to return the complete set of
24 available attributes that may be of interest, so that using a QueryEditor
25 one can easily extend this table without having to query the backend
26 * checkboxes is a boolean flag, set to true if a rightmost column
27 with checkboxes is desired
28 * optionally pass columns as the initial set of columns
29 if None then this is taken from the query's fields
30 * init_key is the name of a column that should appear in both queries
31 and used internally in the plugin for checkboxes initialization.
32 If not specified, metadata will be used to find out a primary key.
33 However in the case of nodes & slice for example, the default key
34 as returned by the metadata would be 'urn', but 'urn' could only
35 be used for this purpose if it gets displayed initially, which is
36 not necessarily a good idea.
37 This is why a slice view would use 'hrn' here instead.
38 * datatables_options are passed to dataTables as-is;
39 however please refrain from passing an 'aoColumns'
40 as we use 'aoColumnDefs' instead.
43 def __init__ (self, query=None, query_all=None,
44 checkboxes=False, columns=None,
46 datatables_options={}, **settings):
47 Plugin.__init__ (self, **settings)
49 # Until we have a proper way to access queries in Python
50 self.query_all = query_all
51 self.query_all_uuid = query_all.query_uuid if query_all else None
52 self.checkboxes = checkboxes
53 # XXX We need to have some hidden columns until we properly handle dynamic queries
54 if columns is not None:
56 self.hidden_columns = []
58 self.columns = list (['Flowspace Name', 'Edit', 'Delete'])
60 #self.columns = self.query.fields
63 self.hidden_columns = []
64 # We need a list because sets are not JSON-serializable
65 #self.hidden_columns = #list(self.query_all.fields - self.query.fields)
67 self.hidden_columns = []
70 self.hidden_columns = []
72 self.columns = list (['Flowspace Name', 'Edit', 'Delete'])
73 self.init_key=init_key
74 self.datatables_options=datatables_options
75 # if checkboxes were required, we tell datatables about this column's type
76 # so that sorting can take place on a selected-first basis (or -last of course)
77 # this relies on the template exposing the checkboxes 'th' with class 'checkbox'
79 # we use aoColumnDefs rather than aoColumns -- ignore user-provided aoColumns
80 if 'aoColumns' in self.datatables_options:
81 print 'WARNING: querytable uses aoColumnDefs, your aoColumns spec. is discarded'
82 del self.datatables_options['aoColumns']
83 # set aoColumnDefs in datatables_options - might already have stuff in there
84 aoColumnDefs = self.datatables_options.setdefault ('aoColumnDefs',[])
85 # here 'checkbox' is the class that we give to the <th> dom elem
86 # dom-checkbox is a sorting type that we define in querytable.js
87 aoColumnDefs.append ( {'aTargets': ['checkbox'], 'sSortDataType': 'dom-checkbox' } )
89 def template_file (self):
90 return "univbrisfv.html"
92 def template_env (self, request):
94 env.update(self.__dict__)
95 env['columns']=self.columns
98 def requirements (self):
100 'js_files' : [ "js/spin-presets.js", "js/spin.min.js", "js/jquery.spin.js",
101 "js/dataTables.js", "js/dataTables.bootstrap.js", "js/with-datatables.js", "js/jquery.jeditable.js",
102 "js/manifold.js", "js/manifold-query.js",
103 "js/unfold-helper.js",
104 # querytable.js needs to be loaded after dataTables.js as it extends
105 # dataTableExt.afnSortData
106 # "js/jquery-ui.min.js" "js/jquery.dataTables.editable.js", "js/jquery.validate.js",
107 "js/univbrisfv.js",#"js/univbrisfv.js",
109 'css_files': [ "css/dataTables.bootstrap.css",
110 # hopefully temporary, when/if datatables supports sPaginationType=bootstrap3
111 # for now we use full_numbers, with our own ad hoc css
112 "css/dataTables.full_numbers.css",
113 "css/univbrisfv.css" , #"css/univbrisfv.css"
118 # the list of things passed to the js plugin
119 def json_settings_list (self):
120 return ['plugin_uuid', 'domid',
121 'query_uuid', 'query_all_uuid',
122 'checkboxes', 'datatables_options',
123 'hidden_columns', 'init_key',]