2011-04-15 06:42:41 +00:00
|
|
|
/*---------------------------------------------------------
|
2011-09-05 12:28:15 +00:00
|
|
|
* OpenERP web_graph
|
2011-04-15 06:42:41 +00:00
|
|
|
*---------------------------------------------------------*/
|
2013-11-08 15:41:14 +00:00
|
|
|
|
2013-11-12 08:38:27 +00:00
|
|
|
/* jshint undef: false */
|
|
|
|
|
2011-04-15 06:42:41 +00:00
|
|
|
|
2012-04-17 12:48:30 +00:00
|
|
|
openerp.web_graph = function (instance) {
|
2013-11-13 10:50:59 +00:00
|
|
|
'use strict';
|
2011-06-17 13:25:50 +00:00
|
|
|
|
2012-06-07 14:17:12 +00:00
|
|
|
var _lt = instance.web._lt;
|
2013-01-25 07:02:40 +00:00
|
|
|
var _t = instance.web._t;
|
2013-11-12 13:53:44 +00:00
|
|
|
var QWeb = instance.web.qweb;
|
2012-05-07 08:19:08 +00:00
|
|
|
|
2012-04-17 12:48:30 +00:00
|
|
|
instance.web.views.add('graph', 'instance.web_graph.GraphView');
|
2013-11-08 13:08:06 +00:00
|
|
|
|
2013-11-08 15:20:48 +00:00
|
|
|
/**
|
|
|
|
* GraphView view. It mostly contains two widgets (PivotTable and ChartView)
|
|
|
|
* and some data.
|
|
|
|
*/
|
2012-04-17 12:48:30 +00:00
|
|
|
instance.web_graph.GraphView = instance.web.View.extend({
|
2013-11-08 13:08:06 +00:00
|
|
|
template: 'GraphView',
|
2011-12-16 13:00:00 +00:00
|
|
|
display_name: _lt('Graph'),
|
2013-11-08 13:08:06 +00:00
|
|
|
view_type: 'graph',
|
2013-11-15 16:32:09 +00:00
|
|
|
mode: 'pivot', // pivot, bar_chart, line_chart or pie_chart
|
2013-11-12 11:31:34 +00:00
|
|
|
|
2013-11-08 13:08:06 +00:00
|
|
|
events: {
|
|
|
|
'click .graph_mode_selection li' : function (event) {
|
|
|
|
event.preventDefault();
|
2013-11-15 16:32:09 +00:00
|
|
|
this.mode = event.target.attributes['data-mode'].nodeValue;
|
2013-11-12 16:10:34 +00:00
|
|
|
this.display_data();
|
2013-11-08 13:08:06 +00:00
|
|
|
},
|
2013-11-14 15:33:48 +00:00
|
|
|
'click .graph_clear_groups' : function (event) {
|
|
|
|
this.pivot_table.clear_groups();
|
|
|
|
},
|
2013-11-08 13:08:06 +00:00
|
|
|
},
|
2011-04-15 06:42:41 +00:00
|
|
|
|
2013-11-08 13:08:06 +00:00
|
|
|
view_loading: function (fields_view_get) {
|
2013-11-08 15:20:48 +00:00
|
|
|
var self = this;
|
2013-11-13 10:50:59 +00:00
|
|
|
var model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true});
|
2013-11-13 15:47:31 +00:00
|
|
|
var options = {};
|
|
|
|
options.domain = [];
|
|
|
|
options.col_groupby = [];
|
2013-11-08 15:20:48 +00:00
|
|
|
|
|
|
|
// get the default groupbys and measure defined in the field view
|
2013-11-13 15:47:31 +00:00
|
|
|
options.measure = null;
|
|
|
|
options.row_groupby = [];
|
2013-11-08 15:20:48 +00:00
|
|
|
_.each(fields_view_get.arch.children, function (field) {
|
|
|
|
if ('name' in field.attrs) {
|
|
|
|
if ('operator' in field.attrs) {
|
2013-11-13 15:47:31 +00:00
|
|
|
options.measure = field.attrs.name;
|
2013-11-08 15:20:48 +00:00
|
|
|
} else {
|
2013-11-13 15:47:31 +00:00
|
|
|
options.row_groupby.push(field.attrs.name);
|
2013-11-08 15:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-11-13 15:47:31 +00:00
|
|
|
// get the most important fields (of the model) by looking at the
|
|
|
|
// groupby filters defined in the search view
|
2013-11-14 10:34:46 +00:00
|
|
|
options.important_fields = [];
|
2013-11-13 15:47:31 +00:00
|
|
|
var load_view = instance.web.fields_view_get({
|
|
|
|
model: model,
|
|
|
|
view_type: 'search',
|
2013-11-12 08:38:27 +00:00
|
|
|
});
|
2013-11-08 15:20:48 +00:00
|
|
|
|
2013-11-13 15:47:31 +00:00
|
|
|
var important_fields_def = $.when(load_view).then(function (search_view) {
|
|
|
|
var groups = _.select(search_view.arch.children, function (c) {
|
|
|
|
return (c.tag == 'group') && (c.attrs.string != 'Display');
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(groups, function(g) {
|
|
|
|
_.each(g.children, function (g) {
|
|
|
|
if (g.attrs.context) {
|
|
|
|
var field_id = py.eval(g.attrs.context).group_by;
|
|
|
|
options.important_fields.push(field_id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2013-11-14 10:34:46 +00:00
|
|
|
});
|
2013-11-13 15:47:31 +00:00
|
|
|
|
|
|
|
// get the fields descriptions from the model
|
|
|
|
var field_descr_def = model.call('fields_get', [])
|
|
|
|
.then(function (fields) { options.fields = fields; });
|
|
|
|
|
|
|
|
|
|
|
|
return $.when(important_fields_def, field_descr_def)
|
|
|
|
.then(function () {
|
2013-11-15 16:32:09 +00:00
|
|
|
|
|
|
|
self.data = {
|
|
|
|
model: model,
|
|
|
|
domain: options.domain,
|
|
|
|
fields: options.fields,
|
|
|
|
important_fields: options.important_fields,
|
|
|
|
measure: options.measure,
|
|
|
|
measure_label: options.fields[options.measure].string,
|
|
|
|
col_groupby: [],
|
|
|
|
row_groupby: options.row_groupby,
|
|
|
|
groups: [],
|
|
|
|
total: null,
|
|
|
|
};
|
2013-11-13 15:47:31 +00:00
|
|
|
self.pivot_table = new PivotTable(model, options);
|
|
|
|
})
|
|
|
|
.then(function () {
|
2013-11-14 10:34:46 +00:00
|
|
|
return self.pivot_table.appendTo('.graph_main_content');
|
2013-11-13 15:47:31 +00:00
|
|
|
});
|
2013-11-15 16:32:09 +00:00
|
|
|
|
2013-11-12 16:10:34 +00:00
|
|
|
},
|
|
|
|
|
2013-11-13 09:18:07 +00:00
|
|
|
display_data : function () {
|
2013-11-15 16:32:09 +00:00
|
|
|
var content = this.$el.filter('.graph_main_content');
|
|
|
|
content.find('svg').remove();
|
|
|
|
var self = this;
|
2013-11-13 09:18:07 +00:00
|
|
|
if (this.mode === 'pivot') {
|
|
|
|
this.pivot_table.show();
|
2013-11-15 16:32:09 +00:00
|
|
|
|
2013-11-13 09:18:07 +00:00
|
|
|
} else {
|
|
|
|
this.pivot_table.hide();
|
2013-11-15 16:32:09 +00:00
|
|
|
content.append('<svg></svg>');
|
|
|
|
var view_fields = this.data.row_groupby.concat(this.data.measure, this.data.col_groupby);
|
|
|
|
query_groups(this.data.model, view_fields, this.data.domain, this.data.row_groupby).then(function (groups) {
|
|
|
|
Charts[self.mode](groups, self.data.measure, self.data.measure_label);
|
|
|
|
});
|
|
|
|
|
2013-11-13 09:18:07 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-08 15:20:48 +00:00
|
|
|
do_search: function (domain, context, group_by) {
|
2013-11-15 16:32:09 +00:00
|
|
|
this.data.domain = new instance.web.CompoundDomain(domain);
|
2013-11-13 10:50:59 +00:00
|
|
|
this.pivot_table.set_domain(domain);
|
|
|
|
this.display_data();
|
2011-05-06 12:41:08 +00:00
|
|
|
},
|
2012-05-07 09:40:59 +00:00
|
|
|
|
2013-11-08 11:32:10 +00:00
|
|
|
do_show: function () {
|
2012-01-03 16:06:50 +00:00
|
|
|
this.do_push_state({});
|
|
|
|
return this._super();
|
2012-05-07 08:19:08 +00:00
|
|
|
},
|
2013-11-08 15:20:48 +00:00
|
|
|
|
2013-11-08 13:08:06 +00:00
|
|
|
});
|
|
|
|
|
2013-11-15 15:16:59 +00:00
|
|
|
|
2013-11-08 15:20:48 +00:00
|
|
|
/**
|
2013-11-15 16:32:09 +00:00
|
|
|
* PivotTable widget. It displays the data in tabular data and allows the
|
|
|
|
* user to drill down and up in the table
|
2013-11-08 15:20:48 +00:00
|
|
|
*/
|
2013-11-15 16:32:09 +00:00
|
|
|
var PivotTable = instance.web.Widget.extend({
|
|
|
|
template: 'pivot_table',
|
|
|
|
rows: [],
|
|
|
|
cols: [],
|
|
|
|
current_row_id : 0,
|
2013-11-13 09:26:46 +00:00
|
|
|
need_redraw: false,
|
|
|
|
|
2013-11-13 10:50:59 +00:00
|
|
|
// Input parameters:
|
|
|
|
// model: model to display
|
|
|
|
// fields: dictionary returned by field_get on model (desc of model)
|
|
|
|
// domain: constraints on model records
|
|
|
|
// row_groupby: groubys on rows (so, row headers in the pivot table)
|
|
|
|
// col_groupby: idem, but on col
|
|
|
|
// measure: quantity to display. either a field from the model, or
|
|
|
|
// null, in which case we use the "count" measure
|
2013-11-13 15:47:31 +00:00
|
|
|
init: function (model, options) {
|
2013-11-15 11:19:32 +00:00
|
|
|
var self = this;
|
2013-11-13 10:50:59 +00:00
|
|
|
this.model = model;
|
2013-11-13 15:47:31 +00:00
|
|
|
this.fields = options.fields;
|
|
|
|
this.domain = options.domain;
|
2013-11-15 11:19:32 +00:00
|
|
|
this.groupby = {
|
|
|
|
row: options.row_groupby,
|
|
|
|
col: options.col_groupby,
|
|
|
|
};
|
|
|
|
|
2013-11-13 15:47:31 +00:00
|
|
|
this.measure = options.measure;
|
|
|
|
this.measure_label = options.measure ? options.fields[options.measure].string : 'Quantity';
|
2013-11-12 16:10:34 +00:00
|
|
|
this.data = [];
|
2013-11-13 10:50:59 +00:00
|
|
|
this.need_redraw = true;
|
2013-11-13 15:47:31 +00:00
|
|
|
this.important_fields = options.important_fields;
|
2013-11-12 16:10:34 +00:00
|
|
|
},
|
|
|
|
|
2013-11-14 10:34:46 +00:00
|
|
|
get_descr: function (field_id) {
|
|
|
|
return this.fields[field_id].string;
|
|
|
|
},
|
|
|
|
|
2013-11-13 10:50:59 +00:00
|
|
|
set_domain: function (domain) {
|
|
|
|
this.domain = domain;
|
|
|
|
this.need_redraw = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
set_row_groupby: function (row_groupby) {
|
2013-11-15 11:19:32 +00:00
|
|
|
this.groupby.row = row_groupby;
|
2013-11-13 10:50:59 +00:00
|
|
|
this.need_redraw = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
set_col_groupby: function (col_groupby) {
|
2013-11-15 11:19:32 +00:00
|
|
|
this.groupby.col = col_groupby;
|
2013-11-13 10:50:59 +00:00
|
|
|
this.need_redraw = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
set_measure: function (measure) {
|
|
|
|
this.measure = measure;
|
2013-11-13 09:26:46 +00:00
|
|
|
this.need_redraw = true;
|
2013-11-12 11:31:34 +00:00
|
|
|
},
|
2013-11-08 13:08:06 +00:00
|
|
|
|
|
|
|
show: function () {
|
2013-11-13 09:26:46 +00:00
|
|
|
if (this.need_redraw) {
|
|
|
|
this.draw();
|
|
|
|
this.need_redraw = false;
|
|
|
|
}
|
2013-11-08 13:08:06 +00:00
|
|
|
this.$el.css('display', 'block');
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function () {
|
|
|
|
this.$el.css('display', 'none');
|
|
|
|
},
|
2013-11-12 16:10:34 +00:00
|
|
|
|
2013-11-13 10:50:59 +00:00
|
|
|
|
|
|
|
get_data: function (groupby) {
|
2013-11-15 11:19:32 +00:00
|
|
|
var view_fields = this.groupby.row.concat(this.measure, this.groupby.col);
|
2013-11-13 10:50:59 +00:00
|
|
|
return query_groups(this.model, view_fields, this.domain, groupby);
|
|
|
|
},
|
|
|
|
|
2013-11-13 15:47:31 +00:00
|
|
|
|
|
|
|
events: {
|
2013-11-15 12:13:15 +00:00
|
|
|
'click .web_graph_click' : function (event) {
|
2013-11-14 10:34:46 +00:00
|
|
|
var self = this;
|
2013-11-13 15:47:31 +00:00
|
|
|
event.preventDefault();
|
2013-11-14 16:31:07 +00:00
|
|
|
var row_id = event.target.attributes['data-row-id'].nodeValue;
|
2013-11-14 10:34:46 +00:00
|
|
|
|
2013-11-14 16:31:07 +00:00
|
|
|
var row = this.get_row(row_id);
|
|
|
|
if (row.expanded) {
|
2013-11-15 08:50:37 +00:00
|
|
|
this.fold_row(row_id);
|
2013-11-14 16:31:07 +00:00
|
|
|
} else {
|
2013-11-15 11:19:32 +00:00
|
|
|
if (row.path.length < this.groupby.row.length) {
|
|
|
|
var field_to_expand = this.groupby.row[row.path.length];
|
2013-11-15 09:24:11 +00:00
|
|
|
this.expand_row(row_id, field_to_expand);
|
|
|
|
} else {
|
2013-11-15 11:19:32 +00:00
|
|
|
var already_grouped = self.groupby.row.concat(self.groupby.col);
|
2013-11-15 09:24:11 +00:00
|
|
|
var possible_groups = _.difference(self.important_fields, already_grouped);
|
|
|
|
var dropdown_options = {
|
|
|
|
fields: _.map(possible_groups, function (field) {
|
|
|
|
return {id: field, value: self.get_descr(field)};
|
|
|
|
}),
|
|
|
|
row_id: row_id,
|
|
|
|
};
|
|
|
|
this.dropdown = $(QWeb.render('field_selection', dropdown_options));
|
|
|
|
$(event.target).after(this.dropdown);
|
2013-11-15 12:13:15 +00:00
|
|
|
this.dropdown.css({position:"absolute",
|
|
|
|
left:event.pageX,
|
|
|
|
top:event.pageY});
|
2013-11-15 09:24:11 +00:00
|
|
|
$('.field-selection').next('.dropdown-menu').toggle();
|
|
|
|
}
|
2013-11-14 16:31:07 +00:00
|
|
|
}
|
2013-11-14 10:34:46 +00:00
|
|
|
|
2013-11-14 16:31:07 +00:00
|
|
|
|
2013-11-14 10:34:46 +00:00
|
|
|
},
|
|
|
|
'click a.field-selection' : function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.dropdown.remove();
|
2013-11-13 15:47:31 +00:00
|
|
|
var row_id = event.target.attributes['data-row-id'].nodeValue;
|
2013-11-14 10:34:46 +00:00
|
|
|
var field_id = event.target.attributes['data-field-id'].nodeValue;
|
|
|
|
this.expand_row(row_id, field_id);
|
2013-11-13 15:47:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2013-11-14 15:33:48 +00:00
|
|
|
clear_groups: function () {
|
2013-11-15 11:19:32 +00:00
|
|
|
this.groupby.row = [];
|
|
|
|
this.groupby.col = [];
|
2013-11-14 15:33:48 +00:00
|
|
|
this.rows = [];
|
|
|
|
this.cols = [];
|
|
|
|
this.draw();
|
|
|
|
},
|
|
|
|
|
2013-11-13 15:47:31 +00:00
|
|
|
generate_id: function () {
|
|
|
|
this.current_row_id += 1;
|
|
|
|
return this.current_row_id - 1;
|
|
|
|
},
|
2013-11-12 11:31:34 +00:00
|
|
|
|
2013-11-14 10:34:46 +00:00
|
|
|
get_row: function (id) {
|
|
|
|
return _.find(this.rows, function(row) {
|
|
|
|
return (row.id == id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-11-14 13:17:47 +00:00
|
|
|
make_cell: function (content, options) {
|
|
|
|
var attrs = ['<td'];
|
|
|
|
if (options && options.is_border) {
|
|
|
|
attrs.push('class="graph_border"');
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs.push('>');
|
|
|
|
if (options && options.indent) {
|
|
|
|
_.each(_.range(options.indent), function () {
|
|
|
|
attrs.push('<span class="web_graph_indent"></span>');
|
|
|
|
});
|
|
|
|
}
|
2013-11-14 14:00:15 +00:00
|
|
|
if (options && options.foldable) {
|
2013-11-15 12:13:15 +00:00
|
|
|
attrs.push('<span data-row-id="'+ options.row_id + '" href="#" class="icon-plus-sign web_graph_click">');
|
2013-11-14 14:00:15 +00:00
|
|
|
}
|
2013-11-15 12:13:15 +00:00
|
|
|
if (content) {
|
|
|
|
attrs.push(content);
|
|
|
|
} else {
|
|
|
|
attrs.push('Undefined');
|
|
|
|
}
|
|
|
|
if (options && options.foldable) {
|
|
|
|
attrs.push('</span>');
|
|
|
|
}
|
|
|
|
attrs.push('</td>');
|
|
|
|
return attrs.join(' ');
|
2013-11-14 13:17:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
make_row: function (data, parent_id) {
|
|
|
|
var has_parent = (parent_id !== undefined);
|
|
|
|
var parent = has_parent ? this.get_row(parent_id) : null;
|
2013-11-14 15:33:48 +00:00
|
|
|
var path;
|
|
|
|
if (has_parent) {
|
|
|
|
path = parent.path.concat(data.attributes.grouped_on);
|
|
|
|
} else if (data.attributes.grouped_on !== undefined) {
|
|
|
|
path = [data.attributes.grouped_on];
|
|
|
|
} else {
|
|
|
|
path = [];
|
|
|
|
}
|
2013-11-14 13:17:47 +00:00
|
|
|
|
|
|
|
var indent_level = has_parent ? parent.path.length : 0;
|
2013-11-15 11:19:32 +00:00
|
|
|
var value = (this.groupby.row.length > 0) ? data.attributes.value[1] : 'Total';
|
2013-11-14 13:17:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
var jquery_row = $('<tr></tr>');
|
|
|
|
var row_id = this.generate_id();
|
|
|
|
|
2013-11-14 15:33:48 +00:00
|
|
|
var header = $(this.make_cell(value, {is_border:true, indent: indent_level, foldable:true, row_id: row_id}));
|
2013-11-14 13:17:47 +00:00
|
|
|
jquery_row.html(header);
|
|
|
|
jquery_row.append(this.make_cell(data.attributes.aggregates[this.measure]));
|
|
|
|
|
|
|
|
var row = {
|
|
|
|
id: row_id,
|
|
|
|
path: path,
|
2013-11-14 15:33:48 +00:00
|
|
|
value: value,
|
2013-11-14 13:17:47 +00:00
|
|
|
expanded: false,
|
|
|
|
parent: parent_id,
|
|
|
|
children: [],
|
|
|
|
html_tr: jquery_row,
|
|
|
|
domain: data.model._domain,
|
|
|
|
};
|
2013-11-14 16:31:07 +00:00
|
|
|
// rows.splice(index of parent if any,0,row);
|
2013-11-14 13:17:47 +00:00
|
|
|
this.rows.push(row); // to do, insert it properly
|
|
|
|
|
2013-11-15 11:19:32 +00:00
|
|
|
if (this.groupby.row.length === 0) {
|
2013-11-14 15:33:48 +00:00
|
|
|
row.remove_when_expanded = true;
|
2013-11-14 16:31:07 +00:00
|
|
|
row.domain = this.domain;
|
2013-11-14 15:33:48 +00:00
|
|
|
}
|
2013-11-14 13:17:47 +00:00
|
|
|
if (has_parent) {
|
2013-11-15 08:50:37 +00:00
|
|
|
parent.children.push(row.id);
|
2013-11-14 13:17:47 +00:00
|
|
|
}
|
|
|
|
return row;
|
2013-11-14 10:34:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
expand_row: function (row_id, field_id) {
|
2013-11-14 13:17:47 +00:00
|
|
|
var self = this;
|
2013-11-14 10:34:46 +00:00
|
|
|
var row = this.get_row(row_id);
|
2013-11-15 09:24:11 +00:00
|
|
|
|
2013-11-15 11:19:32 +00:00
|
|
|
if (row.path.length == this.groupby.row.length) {
|
|
|
|
this.groupby.row.push(field_id);
|
2013-11-15 09:24:11 +00:00
|
|
|
}
|
2013-11-14 15:33:48 +00:00
|
|
|
|
2013-11-15 11:19:32 +00:00
|
|
|
var visible_fields = this.groupby.row.concat(this.groupby.col, this.measure);
|
2013-11-14 10:34:46 +00:00
|
|
|
|
2013-11-14 15:33:48 +00:00
|
|
|
if (row.remove_when_expanded) {
|
|
|
|
this.rows = [];
|
|
|
|
} else {
|
|
|
|
row.expanded = true;
|
|
|
|
row.html_tr.find('.icon-plus-sign')
|
|
|
|
.removeClass('icon-plus-sign')
|
|
|
|
.addClass('icon-minus-sign');
|
|
|
|
}
|
|
|
|
|
2013-11-14 10:34:46 +00:00
|
|
|
query_groups(this.model, visible_fields, row.domain, [field_id])
|
|
|
|
.then(function (data) {
|
2013-11-14 16:31:07 +00:00
|
|
|
_.each(data.reverse(), function (datapt) {
|
2013-11-14 15:33:48 +00:00
|
|
|
var new_row;
|
|
|
|
if (row.remove_when_expanded) {
|
|
|
|
new_row = self.make_row(datapt);
|
|
|
|
self.$('tr.graph_table_header').after(new_row.html_tr);
|
|
|
|
} else {
|
|
|
|
new_row = self.make_row(datapt, row_id);
|
|
|
|
row.html_tr.after(new_row.html_tr);
|
|
|
|
}
|
2013-11-14 13:17:47 +00:00
|
|
|
});
|
2013-11-14 16:31:07 +00:00
|
|
|
if (row.remove_when_expanded) {
|
2013-11-15 08:50:37 +00:00
|
|
|
row.html_tr.remove();
|
2013-11-14 16:31:07 +00:00
|
|
|
}
|
2013-11-14 10:34:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-14 16:31:07 +00:00
|
|
|
fold_row: function (row_id) {
|
2013-11-15 08:50:37 +00:00
|
|
|
var self = this;
|
|
|
|
var row = this.get_row(row_id);
|
|
|
|
|
|
|
|
_.each(row.children, function (child_row) {
|
2013-11-15 11:19:32 +00:00
|
|
|
self.remove_row(child_row);
|
2013-11-15 08:50:37 +00:00
|
|
|
});
|
|
|
|
row.children = [];
|
|
|
|
|
|
|
|
row.expanded = false;
|
|
|
|
row.html_tr.find('.icon-minus-sign')
|
|
|
|
.removeClass('icon-minus-sign')
|
2013-11-15 11:19:32 +00:00
|
|
|
.addClass('icon-plus-sign');
|
2013-11-15 08:50:37 +00:00
|
|
|
|
2013-11-15 11:19:32 +00:00
|
|
|
var fold_levels = _.map(self.rows, function(g) {return g.path.length;});
|
|
|
|
var new_groupby_length = _.reduce(fold_levels, function (x, y) {
|
|
|
|
return Math.max(x,y);
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
this.groupby.row.splice(new_groupby_length);
|
2013-11-15 08:50:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
remove_row: function (row_id) {
|
|
|
|
var self = this;
|
|
|
|
var row = this.get_row(row_id);
|
|
|
|
|
|
|
|
_.each(row.children, function (child_row) {
|
|
|
|
self.remove_row(child_row);
|
|
|
|
});
|
2013-11-14 16:31:07 +00:00
|
|
|
|
2013-11-15 08:50:37 +00:00
|
|
|
row.html_tr.remove();
|
2013-11-15 11:19:32 +00:00
|
|
|
removeFromArray(this.rows, row);
|
2013-11-14 16:31:07 +00:00
|
|
|
},
|
|
|
|
|
2013-11-12 11:31:34 +00:00
|
|
|
draw: function () {
|
2013-11-15 11:19:32 +00:00
|
|
|
this.get_data(this.groupby.row)
|
2013-11-13 14:44:24 +00:00
|
|
|
.then(this.proxy('build_table'))
|
|
|
|
.done(this.proxy('_draw'));
|
2013-11-13 10:50:59 +00:00
|
|
|
},
|
|
|
|
|
2013-11-13 14:44:24 +00:00
|
|
|
build_table: function (data) {
|
|
|
|
var self = this;
|
2013-11-15 11:26:59 +00:00
|
|
|
this.rows = [];
|
2013-11-14 10:34:46 +00:00
|
|
|
|
2013-11-13 14:44:24 +00:00
|
|
|
this.cols = [{
|
|
|
|
path: [],
|
|
|
|
value: this.measure_label,
|
|
|
|
expanded: false,
|
|
|
|
parent: null,
|
|
|
|
children: [],
|
|
|
|
html_tds: [],
|
|
|
|
domain: this.domain,
|
2013-11-14 13:17:47 +00:00
|
|
|
header: $(this.make_cell(this.measure_label, {is_border:true})),
|
2013-11-13 14:44:24 +00:00
|
|
|
}];
|
|
|
|
|
2013-11-14 13:17:47 +00:00
|
|
|
_.each(data, function (datapt) {
|
|
|
|
self.make_row(datapt);
|
2013-11-13 14:44:24 +00:00
|
|
|
});
|
2013-11-14 13:17:47 +00:00
|
|
|
},
|
2013-11-13 14:44:24 +00:00
|
|
|
|
|
|
|
_draw: function () {
|
|
|
|
|
2013-11-12 16:10:34 +00:00
|
|
|
this.$el.empty();
|
2013-11-12 13:53:44 +00:00
|
|
|
var self = this;
|
2013-11-14 15:33:48 +00:00
|
|
|
var header;
|
2013-11-12 13:53:44 +00:00
|
|
|
|
2013-11-15 11:19:32 +00:00
|
|
|
if (this.groupby.row.length > 0) {
|
2013-11-14 15:33:48 +00:00
|
|
|
header = '<tr><td class="graph_border">' +
|
2013-11-15 11:19:32 +00:00
|
|
|
this.fields[this.groupby.row[0]].string +
|
2013-11-12 16:10:34 +00:00
|
|
|
'</td><td class="graph_border">' +
|
2013-11-12 13:53:44 +00:00
|
|
|
this.measure_label +
|
|
|
|
'</td></tr>';
|
2013-11-14 15:33:48 +00:00
|
|
|
} else {
|
|
|
|
header = '<tr class="graph_table_header"><td class="graph_border">' +
|
|
|
|
'</td><td class="graph_border">' +
|
|
|
|
this.measure_label +
|
|
|
|
'</td></tr>';
|
|
|
|
}
|
2013-11-13 14:44:24 +00:00
|
|
|
this.$el.append(header);
|
2013-11-13 10:50:59 +00:00
|
|
|
|
2013-11-13 14:44:24 +00:00
|
|
|
_.each(this.rows, function (row) {
|
|
|
|
self.$el.append(row.html_tr);
|
2013-11-12 13:53:44 +00:00
|
|
|
});
|
2013-11-13 14:44:24 +00:00
|
|
|
|
2013-11-13 10:50:59 +00:00
|
|
|
}
|
2013-11-08 13:08:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2011-04-15 06:42:41 +00:00
|
|
|
};
|
2013-11-12 08:38:27 +00:00
|
|
|
|