Commit 45641950 authored by Tomáš Peterka's avatar Tomáš Peterka

Functional stats line in ListBox

parent a26aa2dd
...@@ -676,8 +676,8 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key ...@@ -676,8 +676,8 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
"lines": field.get_value('lines'), "lines": field.get_value('lines'),
"default_params": ensure_serializable(default_params), "default_params": ensure_serializable(default_params),
"list_method": list_method_name, "list_method": list_method_name,
"stat_method": field.get_value('stat_method').getMethodName() if field.get_value('stat_method') != "" else "", "show_stat": field.get_value('stat_method') != "" or len(field.get_value('stat_columns')) > 0,
"count_method": field.get_value('count_method').getMethodName() if field.get_value('count_method') != "" else "", "show_count": field.get_value('count_method') != "",
"query": url_template_dict["jio_search_template"] % { "query": url_template_dict["jio_search_template"] % {
"query": make_query({ "query": make_query({
"query": sql_catalog.buildQuery( "query": sql_catalog.buildQuery(
...@@ -1430,8 +1430,11 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1430,8 +1430,11 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
editable_field_dict = {} editable_field_dict = {}
listbox_form = None listbox_form = None
listbox_field_id = None listbox_field_id = None
source_field_meta_type = source_field.meta_type if source_field is not None else ""
if source_field_meta_type == "ProxyField":
source_field_meta_type = source_field.getRecursiveTemplateField().meta_type
if source_field is not None and source_field.meta_type == "ListBox": if source_field is not None and source_field_meta_type == "ListBox":
listbox_field_id = source_field.id listbox_field_id = source_field.id
# XXX Proxy field are not correctly handled in traversed_document of web site # XXX Proxy field are not correctly handled in traversed_document of web site
listbox_form = getattr(traversed_document, source_field.aq_parent.id) listbox_form = getattr(traversed_document, source_field.aq_parent.id)
...@@ -1454,7 +1457,13 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1454,7 +1457,13 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
start, num_items = 0, len(search_result_iterable) start, num_items = 0, len(search_result_iterable)
contents_list = [] # resolved fields from the search result contents_list = [] # resolved fields from the search result
result_dict.update({
'_query': query,
'_local_roles': local_roles,
'_limit': limit,
'_select_list': select_list,
'_embedded': {}
})
# now fill in `contents_list` with actual information # now fill in `contents_list` with actual information
# beware that search_result_iterable can hide anything inside! # beware that search_result_iterable can hide anything inside!
for result_index, search_result in enumerate(search_result_iterable): for result_index, search_result in enumerate(search_result_iterable):
...@@ -1514,45 +1523,60 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1514,45 +1523,60 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# given search_result. This name can unfortunately mean almost anything from # given search_result. This name can unfortunately mean almost anything from
# a key name to Python Script with variable number of input parameters. # a key name to Python Script with variable number of input parameters.
contents_item[select] = resolve_field(search_result, select, property_getter, property_hasser) contents_item[select] = resolve_field(search_result, select, property_getter, property_hasser)
# endfor select # endfor select
contents_list.append(contents_item) contents_list.append(contents_item)
result_dict.update({ result_dict['_embedded'].update({
'_query': query, 'contents': contents_list
'_local_roles': local_roles,
'_limit': limit,
'_select_list': select_list,
'_embedded': {
'contents': contents_list
}
}) })
# Compute statistics if the search issuer was ListBox # Compute statistics if the search issuer was ListBox
# or in future if the stats (SUM) are required by JIO call # or in future if the stats (SUM) are required by JIO call
contents_stat_list = [] source_field_meta_type = source_field.meta_type if source_field is not None else ""
if source_field is not None and source_field.meta_type == "ListBox": if source_field_meta_type == "ProxyField":
source_field_meta_type = source_field.getRecursiveTemplateField().meta_type
context.log('source_field "{!s}", source_field_meta_type {!s}'.format(source_field, source_field_meta_type))
if source_field is not None and source_field_meta_type == "ListBox":
contents_stat_list = []
# in case the search was issued by listbox we can provide results of # in case the search was issued by listbox we can provide results of
# stat_method and count_method back to the caller # stat_method and count_method back to the caller
# XXX: we should check whether they asked for it # XXX: we should check whether they asked for it
stat_method = source_field.get_value('stat_method') stat_method = source_field.get_value('stat_method')
stat_columns = source_field.get_value('stat_columns') stat_columns = source_field.get_value('stat_columns')
context.log('stat_method "{!s}", stat_columns {!s}'.format(stat_method, stat_columns))
# Selection is unfortunatelly required fot stat methods
selection_name = source_field.get_value('selection_name')
selection = None
if selection_name:
selection_tool = context.getPortalObject().portal_selections
selection = selection_tool.getSelectionFor(selection_name, REQUEST)
contents_stat = {} contents_stat = {}
if len(stat_columns) > 0: if len(stat_columns) > 0:
# prefer stat per columns as it is in ListBox # prefer stat per columns as it is in ListBox
# always called on current context # always called on current context
for stat_name, stat_script in stat_columns: for stat_name, stat_script in stat_columns:
contents_stat[stat_name] = getattr(traversed_document, stat_script)(**catalog_kw) contents_stat[stat_name] = getattr(traversed_document, stat_script)(
selection=selection,
selection_name=selection_name,
**catalog_kw)
contents_stat_list.append(contents_stat) contents_stat_list.append(contents_stat)
elif stat_method != "" and stat_method.getMethodName() != list_method_name: elif stat_method != "" and stat_method.getMethodName() != list_method:
# global stat_method is second - should return dictionary or list of dictionaries # general stat_method is second - should return dictionary or list of dictionaries
# where all "fields" should be accessible by its "select" name # where all "fields" should be accessible by their "select" name
contents_stat_list = getattr(traversed_document, stat_method.getMethodName())(**catalog_kw) contents_stat_list = getattr(traversed_document, stat_method.getMethodName())(**catalog_kw)
if len(contents_stat_list) > 0: for contents_stat in contents_stat_list:
result_dict['_embedded'].update({ for key, value in contents_stat.items():
'contents': contents_list if key in editable_field_dict:
}) contents_stat[key] = renderField(
traversed_document, editable_field_dict[key], listbox_form, value, key=editable_field_dict[key].id + '__sum')
context.log('contents_stat_list {!s}'.format(contents_stat_list))
if len(contents_stat_list) > 0:
result_dict['_embedded'].update({
'sum': contents_stat_list
})
# We should cleanup the selection if it exists in catalog params BUT # We should cleanup the selection if it exists in catalog params BUT
# we cannot because it requires escalated Permission.'modifyPortal' so # we cannot because it requires escalated Permission.'modifyPortal' so
......
...@@ -179,12 +179,14 @@ ...@@ -179,12 +179,14 @@
) )
.push(function (catalog_json) { .push(function (catalog_json) {
var data = catalog_json._embedded.contents, var data = catalog_json._embedded.contents,
count = data.length, summary = catalog_json._embedded.sum,
count = catalog_json._embedded.count,
length = data.length,
k, k,
uri, uri,
item, item,
result = []; result = [];
for (k = 0; k < count; k += 1) { for (k = 0; k < length; k += 1) {
item = data[k]; item = data[k];
uri = new URI(item._links.self.href); uri = new URI(item._links.self.href);
delete item._links; delete item._links;
...@@ -198,7 +200,9 @@ ...@@ -198,7 +200,9 @@
data: { data: {
rows: result, rows: result,
total_rows: result.length total_rows: result.length
} },
sum: summary,
count: count
}; };
}); });
}) })
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>947.45414.13002.10052</string> </value> <value> <string>963.50499.50100.12458</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1449753994.81</float> <float>1511939345.58</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -118,55 +118,37 @@ ...@@ -118,55 +118,37 @@
</table> </table>
</script> </script>
<script id="listbox-tfoot-sum-template" type="text/x-handlebars-template"> <script id="listbox-tfoot-template" type="text/x-handlebars-template">
<table> <table>
<tfoot class="ui-bar-inherit tfoot summary"> <tfoot class="ui-bar-inherit tfoot">
{{#each row_list}} {{#each row_list}}
<tr> <tr>
{{#each cell_list}} {{#if ../show_anchor}}
<td> <td></td>
{{#if type}} {{/if}}
{{#if editable}} {{#each cell_list}}
<div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div> <td>
{{else}} {{#if type}}
<a href="{{href}}" class="ui-link"> <div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div>
<div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div> {{else}}
</a> {{text}}
{{/if}} {{/if}}
{{else}} </td>
<a href="{{href}}" class="ui-link">{{text}}</a> {{/each}}
{{/if}} </tr>
</td> {{/each}}
{{/each}}
</tr>
{{/each}}
<th colspan="{{colspan}}">
<div class="ui-controlgroup ui-controlgroup-horizontal ui-corner-all ui-paging-menu">
<div class="ui-controlgroup-controls">
<a class="{{previous_classname}}" data-i18n="Previous" href="{{previous_url}}">Previous</a>
<a class="{{next_classname}}" data-i18n="Next" href="{{next_url}}">Next</a>
<span class="ui-btn ui-disabled" data-i18n="{{record}}">{{record}}</span>
</div>
</div>
</th>
</tfoot> </tfoot>
</table> </table>
</script> </script>
<script id="listbox-tfoot-count-template" type="text/x-handlebars-template"> <script id="listbox-nav-template" type="text/x-handlebars-template">
<table> <nav class="ui-bar-inherit ui-controlgroup ui-controlgroup-horizontal ui-corner-all ui-paging-menu">
<tfoot class="ui-bar-inherit tfoot"> <div class="ui-controlgroup-controls">
<th colspan="{{colspan}}"> <a class="{{previous_classname}}" data-i18n="Previous" href="{{previous_url}}">Previous</a>
<div class="ui-controlgroup ui-controlgroup-horizontal ui-corner-all ui-paging-menu"> <a class="{{next_classname}}" data-i18n="Next" href="{{next_url}}">Next</a>
<div class="ui-controlgroup-controls"> <span class="ui-btn ui-disabled" data-i18n="{{record}}">{{record}}</span>
<a class="{{previous_classname}}" data-i18n="Previous" href="{{previous_url}}">Previous</a> </div>
<a class="{{next_classname}}" data-i18n="Next" href="{{next_url}}">Next</a> </nav>
<span class="ui-btn ui-disabled" data-i18n="{{record}}">{{record}}</span>
</div>
</div>
</th>
</tfoot>
</table>
</script> </script>
<script id="listbox-template" type="text/x-handlebars-template"> <script id="listbox-template" type="text/x-handlebars-template">
...@@ -188,6 +170,7 @@ ...@@ -188,6 +170,7 @@
<tbody></tbody> <tbody></tbody>
<tfoot class="ui-bar-inherit tfoot"></tfoot> <tfoot class="ui-bar-inherit tfoot"></tfoot>
</table> </table>
<nav></nav>
</div> </div>
</script> </script>
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.47536.5989.57173</string> </value> <value> <string>963.50750.47688.32426</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1511764805.38</float> <float>1511952124.83</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.47634.31999.4898</string> </value> <value> <string>963.50757.35572.58794</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1511765129.91</float> <float>1511952430.52</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment