Browse Source

Add fields selection for tree view

pull/59/head
Andrea 8 years ago
parent
commit
69e615bb17
  1. 25
      bi_view_editor/models/bve_view.py
  2. 15
      bi_view_editor/static/src/js/bve.js
  3. 1
      bi_view_editor/templates/qweb_template.xml
  4. 3
      bi_view_editor/tests/test_bi_view.py

25
bi_view_editor/models/bve_view.py

@ -124,6 +124,29 @@ class BveView(models.Model):
view_fields.append(field_def)
return view_fields
@api.multi
def _create_tree_view_arch(self):
self.ensure_one()
def _get_field_def(name):
return """<field name="x_{}" />""".format(
name
)
def _get_field_list(fields_info):
view_fields = []
for field_info in fields_info:
field_name = field_info['name']
if field_info['list'] and 'join_node' not in field_info:
field_def = _get_field_def(field_name)
view_fields.append(field_def)
return view_fields
fields_info = json.loads(self._get_format_data(self.data))
view_fields = _get_field_list(fields_info)
return view_fields
@api.model
def _get_format_data(self, data):
data = data.replace('\'', '"')
@ -177,7 +200,7 @@ class BveView(models.Model):
'priority': 16,
'arch': """<?xml version="1.0"?>
<tree string="List Analysis" create="false"> {} </tree>
""".format("".join(self._create_view_arch()))
""".format("".join(self._create_tree_view_arch()))
})
# set the Tree view as the default one

15
bi_view_editor/static/src/js/bve.js

@ -68,6 +68,8 @@ openerp.bi_view_editor = function (instance, local) {
icons += "<span class='fa fa-bars' title='Row'></span> ";
if(field.measure)
icons += "<span class='fa fa-bar-chart-o' title='Measure'></span> ";
if(field.list)
icons += "<span class='fa fa-list' title='List'></span> ";
return icons;
},
@ -165,15 +167,19 @@ openerp.bi_view_editor = function (instance, local) {
_contextMenu.find(identifier).attr('checked', false);
},
_false_if_undefined: function(to_check) {
if (typeof check === 'undefined') return false;
return check;
if (typeof to_check === 'undefined') return false;
return to_check;
},
_true_if_undefined: function(to_check) {
if (typeof to_check === 'undefined') return true;
return to_check;
},
add_field_to_table: function(data, options) {
var self = this;
data.row = self._false_if_undefined(data.row);
data.column = self._false_if_undefined(data.column);
data.measure = self._false_if_undefined(data.measure);
data.list = self._true_if_undefined(data.list);
var n = 1;
var name = data.name;
@ -220,10 +226,11 @@ openerp.bi_view_editor = function (instance, local) {
self.set_checkbox(currentFieldData.column, '#column-checkbox', contextMenu);
self.set_checkbox(currentFieldData.row, '#row-checkbox', contextMenu);
self.set_checkbox(currentFieldData.measure, '#measure-checkbox', contextMenu);
self.set_checkbox(currentFieldData.list, '#list-checkbox', contextMenu);
var to_disable = false;
if(currentFieldData.type === "float" || currentFieldData.type === "integer" || currentFieldData.type === "monetary") to_disable = true;
var identifiers = [['#column-checkbox', 'column', to_disable], ['#row-checkbox', 'row', to_disable], ['#measure-checkbox', 'measure', !to_disable]];
var identifiers = [['#column-checkbox', 'column', to_disable], ['#row-checkbox', 'row', to_disable], ['#measure-checkbox', 'measure', !to_disable], ['#list-checkbox', 'list', false]];
identifiers.forEach(function (element) {
contextMenu.find(element[0]).attr('disabled', element[2]);
});

1
bi_view_editor/templates/qweb_template.xml

@ -47,6 +47,7 @@
<li><input type="checkbox" id="column-checkbox"/> Column</li>
<li><input type="checkbox" id="row-checkbox"/> Row</li>
<li><input type="checkbox" id="measure-checkbox"/> Measure</li>
<li><input type="checkbox" id="list-checkbox"/> List</li>
</ul>
</div>

3
bi_view_editor/tests/test_bi_view.py

@ -66,6 +66,7 @@ class TestBiViewEditor(TransactionCase):
'table_alias': 't0',
'row': 0,
'column': 1,
'list': 1,
'measure': 0
},
{'model_id': self.partner_model.id,
@ -81,6 +82,7 @@ class TestBiViewEditor(TransactionCase):
'description': self.partner_company_field.field_description,
'row': 0,
'column': 0,
'list': 1,
'measure': 0
},
{'model_id': self.company_model.id,
@ -94,6 +96,7 @@ class TestBiViewEditor(TransactionCase):
'table_alias': 't1',
'row': 1,
'column': 0,
'list': 0,
'measure': 0
}
]

Loading…
Cancel
Save