91 displaycols = range(len(self.rset.syntax_tree().children[0].selection)) |
91 displaycols = range(len(self.rset.syntax_tree().children[0].selection)) |
92 return displaycols |
92 return displaycols |
93 |
93 |
94 def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
94 def call(self, title=None, subvid=None, displayfilter=None, headers=None, |
95 displaycols=None, displayactions=None, actions=(), divid=None, |
95 displaycols=None, displayactions=None, actions=(), divid=None, |
96 cellvids=None, cellattrs=None): |
96 cellvids=None, cellattrs=None, mainindex=None): |
97 """Dumps a table displaying a composite query |
97 """Dumps a table displaying a composite query |
98 |
98 |
99 :param title: title added before table |
99 :param title: title added before table |
100 :param subvid: cell view |
100 :param subvid: cell view |
101 :param displayfilter: filter that selects rows to display |
101 :param displayfilter: filter that selects rows to display |
102 :param headers: columns' titles |
102 :param headers: columns' titles |
103 """ |
103 """ |
104 rset = self.rset |
|
105 req = self.req |
104 req = self.req |
106 req.add_js('jquery.tablesorter.js') |
105 req.add_js('jquery.tablesorter.js') |
107 req.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css')) |
106 req.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css')) |
108 rqlst = rset.syntax_tree() |
107 # compute label first since the filter form may remove some necessary |
109 # get rql description first since the filter form may remove some |
108 # information from the rql syntax tree |
110 # necessary information |
109 if mainindex is None: |
111 rqlstdescr = rqlst.get_description()[0] # XXX missing Union support |
110 mainindex = self.main_var_index() |
112 mainindex = self.main_var_index() |
111 computed_labels = self.columns_labels(mainindex) |
113 hidden = True |
112 hidden = True |
114 if not subvid and 'subvid' in req.form: |
113 if not subvid and 'subvid' in req.form: |
115 subvid = req.form.pop('subvid') |
114 subvid = req.form.pop('subvid') |
116 divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(rset)) |
115 divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.rset)) |
117 actions = list(actions) |
116 actions = list(actions) |
118 if mainindex is None: |
117 if mainindex is None: |
119 displayfilter, displayactions = False, False |
118 displayfilter, displayactions = False, False |
120 else: |
119 else: |
121 if displayfilter is None and 'displayfilter' in req.form: |
120 if displayfilter is None and 'displayfilter' in req.form: |
152 # render actions menu |
151 # render actions menu |
153 if actions: |
152 if actions: |
154 self.render_actions(divid, actions) |
153 self.render_actions(divid, actions) |
155 # render table |
154 # render table |
156 table = TableWidget(self) |
155 table = TableWidget(self) |
157 for column in self.get_columns(rqlstdescr, displaycols, headers, subvid, |
156 for column in self.get_columns(computed_labels, displaycols, headers, |
158 cellvids, cellattrs, mainindex): |
157 subvid, cellvids, cellattrs, mainindex): |
159 table.append_column(column) |
158 table.append_column(column) |
160 table.render(self.w) |
159 table.render(self.w) |
161 self.w(u'</div>\n') |
160 self.w(u'</div>\n') |
162 if not fromformfilter: |
161 if not fromformfilter: |
163 self.w(u'</div>\n') |
162 self.w(u'</div>\n') |
186 for url, label, klass, ident in actions: |
185 for url, label, klass, ident in actions: |
187 menu.append(BoxLink(url, label, klass, ident=ident, escape=True)) |
186 menu.append(BoxLink(url, label, klass, ident=ident, escape=True)) |
188 box.render(w=self.w) |
187 box.render(w=self.w) |
189 self.w(u'<div class="clear"/>') |
188 self.w(u'<div class="clear"/>') |
190 |
189 |
191 def get_columns(self, rqlstdescr, displaycols, headers, subvid, cellvids, |
190 def get_columns(self, computed_labels, displaycols, headers, subvid, |
192 cellattrs, mainindex): |
191 cellvids, cellattrs, mainindex): |
193 columns = [] |
192 columns = [] |
194 for colindex, attr in enumerate(rqlstdescr): |
193 for colindex, label in enumerate(computed_labels): |
195 if colindex not in displaycols: |
194 if colindex not in displaycols: |
196 continue |
195 continue |
197 # compute column header |
196 # compute column header |
198 if headers is not None: |
197 if headers is not None: |
199 label = headers[displaycols.index(colindex)] |
198 label = headers[displaycols.index(colindex)] |
200 elif colindex == 0 or attr == 'Any': # find a better label |
|
201 label = ','.join(display_name(self.req, et) |
|
202 for et in self.rset.column_types(colindex)) |
|
203 else: |
|
204 label = display_name(self.req, attr) |
|
205 if colindex == mainindex: |
199 if colindex == mainindex: |
206 label += ' (%s)' % self.rset.rowcount |
200 label += ' (%s)' % self.rset.rowcount |
207 column = TableColumn(label, colindex) |
201 column = TableColumn(label, colindex) |
208 coltype = self.rset.description[0][colindex] |
202 coltype = self.rset.description[0][colindex] |
209 # compute column cell view (if coltype is None, it's a left outer |
203 # compute column cell view (if coltype is None, it's a left outer |
212 column.append_renderer(cellvids[colindex], colindex) |
206 column.append_renderer(cellvids[colindex], colindex) |
213 elif coltype is not None and self.schema.eschema(coltype).is_final(): |
207 elif coltype is not None and self.schema.eschema(coltype).is_final(): |
214 column.append_renderer(self.finalview, colindex) |
208 column.append_renderer(self.finalview, colindex) |
215 else: |
209 else: |
216 column.append_renderer(subvid or 'incontext', colindex) |
210 column.append_renderer(subvid or 'incontext', colindex) |
217 |
|
218 if cellattrs and colindex in cellattrs: |
211 if cellattrs and colindex in cellattrs: |
219 for name, value in cellattrs[colindex].iteritems(): |
212 for name, value in cellattrs[colindex].iteritems(): |
220 column.add_attr(name, value) |
213 column.add_attr(name, value) |
221 # add column |
214 # add column |
222 columns.append(column) |
215 columns.append(column) |
295 # should not be displayed in possible view since it expects some specific |
288 # should not be displayed in possible view since it expects some specific |
296 # parameters |
289 # parameters |
297 title = None |
290 title = None |
298 |
291 |
299 def call(self, title=None, subvid=None, headers=None, divid=None, |
292 def call(self, title=None, subvid=None, headers=None, divid=None, |
300 displaycols=None, displayactions=None): |
293 displaycols=None, displayactions=None, mainindex=None): |
301 """Dumps a table displaying a composite query""" |
294 """Dumps a table displaying a composite query""" |
302 actrql = self.req.form['actualrql'] |
295 actrql = self.req.form['actualrql'] |
303 self.ensure_ro_rql(actrql) |
296 self.ensure_ro_rql(actrql) |
304 displaycols = self.displaycols(displaycols) |
297 displaycols = self.displaycols(displaycols) |
305 if displayactions is None and 'displayactions' in self.req.form: |
298 if displayactions is None and 'displayactions' in self.req.form: |
310 if not title and 'title' in self.req.form: |
303 if not title and 'title' in self.req.form: |
311 # pop title so it's not displayed by the table view as well |
304 # pop title so it's not displayed by the table view as well |
312 title = self.req.form.pop('title') |
305 title = self.req.form.pop('title') |
313 if title: |
306 if title: |
314 self.w(u'<h2>%s</h2>\n' % title) |
307 self.w(u'<h2>%s</h2>\n' % title) |
315 mainindex = self.main_var_index() |
308 if mainindex is None: |
|
309 mainindex = self.main_var_index() |
316 if mainindex is not None: |
310 if mainindex is not None: |
317 actions = self.form_filter(divid, displaycols, displayactions, True) |
311 actions = self.form_filter(divid, displaycols, displayactions, True) |
318 else: |
312 else: |
319 actions = () |
313 actions = () |
320 if not subvid and 'subvid' in self.req.form: |
314 if not subvid and 'subvid' in self.req.form: |