Commit 7ee82799 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the StoreForMetric1DView.

parent 87726cc0
......@@ -13,7 +13,7 @@ from datetime import date, timedelta
from gluon.dal import smart_query
from gluon.storage import Storage
from plugin_dbui import Store
from reporting_tools import Report, StoreForListView
from reporting_tools import Report, StoreForListView, StoreForMetric1DView
def list():
......@@ -82,24 +82,14 @@ def metric1D():
# group condition for the vertical axis
groupfield = metric.field_vertical
label = groupfield.split('.')[-1]
# configure the Ext.data.ArrayStore
cfg = dict()
cfg['data'] = []
cfg['fields'] = [{'name': 'group', 'type': 'string'},
{'name': 'count', 'type': 'float'},
{'name': 'sum_fte', 'type': 'float'},
{'name': 'avg_age', 'type': 'float'}]
cfg['sorters'] = ['group']
tablename, fieldname = groupfield.split('.')
# fill the data block
for di in report.get_metric(groupfield):
cfg['data'].append([di['group'], di['count'], di['sum_fte'], di['avg_age']])
# configure the Ext.data.Store
store = StoreForMetric1DView(report.get_metric(groupfield))
# customize the standard view (Ext.grid.Panel)
view = Storage(columns=[], features=[], title=metric.title)
view.columns = [{'text': T(label.title()),
view.columns = [{'text': T(fieldname.title()),
'dataIndex': 'group',
'flex': 0.8},
{'text': '∑ person',
......@@ -129,7 +119,7 @@ def metric1D():
# delegate to standard view
response.view = 'report/grid.html'
return dict(cfg_store=cfg, view=view)
return dict(cfg_store=store.as_json(), view=view)
def metric2D():
......
......@@ -365,7 +365,8 @@ class StoreForListView(StoreFactory):
def _get_fields(self, list):
""" Generate the Ext.data.Store.fields property.
It is a list of Ext.data.Field configuration.
@type list: gluon.dal.Row
@param list: parameters defining the list.
......@@ -378,9 +379,6 @@ class StoreForListView(StoreFactory):
Therefore, the name of the database dbfield is converted by
removing dots.
@rtype: list of Ext.data.Field configuration
@return: list of dictionaries configuring Ext.data.Field.
"""
db = current.globalenv['db']
......@@ -441,15 +439,13 @@ class StoreForListView(StoreFactory):
def _get_data(self, rows):
""" Generate the Ext.data.Store.data property.
It is a list of dictionaries. Each of them contains the data
for one row. One key, value pair for each Ext.data.Field.
The key is equal to the Ext.data.Field name.
@type rows: gluon.dal.Rows
@param rows: data block to be loaded on the store.
@rtype: list of dictionary
@return: each dictionary contains the data for a row.
One key, value pair for each Ext.data.Field. The key is
equal to the Ext.data.Field name.
"""
for row in rows:
......@@ -480,3 +476,51 @@ class StoreForListView(StoreFactory):
di[field.name] = value
self.cfg_store.data.append(di)
class StoreForMetric1DView(StoreFactory):
"""Generate the Ext.data.Store configuration for the metric1D view.
"""
def __init__(self, rows):
"""
@type rows: list of dictionary
@param rows: dictionary containing the data for the store.
It should have the key: group, count, sum_fte, avg_age.
"""
StoreFactory.__init__(self)
self._get_fields()
self._get_data(rows)
def _get_fields(self):
""" Generate the Ext.data.Store.fields property.
The store contains four fields: group, count, sum_fte and avg_age
and data are grouped per the group field values.
"""
self.cfg_store.fields = [dict(name='group', type='string'),
dict(name='count', type='float'),
dict(name='sum_fte', type='float'),
dict(name='avg_age', type='float')]
self.cfg_store.sorters = ['group']
def _get_data(self, rows):
""" Generate the Ext.data.Store.data property.
It is a list of dictionaries. Each of them contains the data
for one row. One key, value pair for each Ext.data.Field.
The key is equal to the Ext.data.Field name.
@type rows: list of dictionary
@param rows: dictionary containing the data for the store.
It should have the key: group, count, sum_fte, avg_age.
"""
self.cfg_store.data.extend(rows)
\ No newline at end of file
......@@ -2,8 +2,8 @@
#--------------------------------------------------------------------------
#
# The python controller return the variables:
# - cfg_store
# - view
# - cfg_store (string)
# - view (Storage)
#
#--------------------------------------------------------------------------
# Prepare the data
......
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