[REF] moves utility functions to pivot.js file and remove utility.js in addon web_graph
bzr revid: ged@openerp.com-20131123105925-edix9lyw9k6tjlmw
This commit is contained in:
parent
ebf46e668d
commit
0f995a25d5
|
@ -18,7 +18,6 @@ Graph Views for Web Client.
|
|||
'static/lib/nvd3/d3.v3.js',
|
||||
'static/lib/nvd3/nv.d3.js',
|
||||
'static/lib/bootstrap/bootstrap.js',
|
||||
'static/src/js/utility.js',
|
||||
'static/src/js/pivot.js',
|
||||
'static/src/js/charts.js',
|
||||
'static/src/js/graph.js',
|
||||
|
|
|
@ -201,3 +201,62 @@ var PivotTable = openerp.web.Class.extend({
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
function removeFromArray(array, element) {
|
||||
var index = array.indexOf(element);
|
||||
if (index > -1) {
|
||||
array.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function insertAfter(array, after, elem) {
|
||||
array.splice(array.indexOf(after) + 1, 0, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the server and return a deferred which will return the data
|
||||
* with all the groupbys applied (this is done for now, but the goal
|
||||
* is to modify read_group in order to allow eager and lazy groupbys
|
||||
*/
|
||||
function query_groups (model, fields, domain, groupbys) {
|
||||
return model.query(fields)
|
||||
.filter(domain)
|
||||
.group_by(groupbys)
|
||||
.then(function (results) {
|
||||
var non_empty_results = _.filter(results, function (group) {
|
||||
return group.attributes.length > 0;
|
||||
});
|
||||
if (groupbys.length <= 1) {
|
||||
return non_empty_results;
|
||||
} else {
|
||||
var get_subgroups = $.when.apply(null, _.map(non_empty_results, function (result) {
|
||||
var new_domain = result.model._domain;
|
||||
var new_groupings = groupbys.slice(1);
|
||||
return query_groups(model, fields,new_domain, new_groupings).then(function (subgroups) {
|
||||
result.subgroups_data = subgroups;
|
||||
});
|
||||
}));
|
||||
return get_subgroups.then(function () {
|
||||
return non_empty_results;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function query_groups_data(model, fields, domain, row_groupbys, col_groupby) {
|
||||
return query_groups(model, fields, domain, [col_groupby].concat(row_groupbys)).then(function (groups) {
|
||||
return _.map(groups, function (group) {
|
||||
return format_group(group, []);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function format_group (group, path) {
|
||||
group.path = path.concat(group.attributes.value[1]);
|
||||
result = [group];
|
||||
_.each(group.subgroups_data, function (subgroup) {
|
||||
result = result.concat(format_group (subgroup, group.path));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
|
||||
function removeFromArray(array, element) {
|
||||
var index = array.indexOf(element);
|
||||
if (index > -1) {
|
||||
array.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function insertAfter(array, after, elem) {
|
||||
array.splice(array.indexOf(after) + 1, 0, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the server and return a deferred which will return the data
|
||||
* with all the groupbys applied (this is done for now, but the goal
|
||||
* is to modify read_group in order to allow eager and lazy groupbys
|
||||
*/
|
||||
function query_groups (model, fields, domain, groupbys) {
|
||||
return model.query(fields)
|
||||
.filter(domain)
|
||||
.group_by(groupbys)
|
||||
.then(function (results) {
|
||||
var non_empty_results = _.filter(results, function (group) {
|
||||
return group.attributes.length > 0;
|
||||
});
|
||||
if (groupbys.length <= 1) {
|
||||
return non_empty_results;
|
||||
} else {
|
||||
var get_subgroups = $.when.apply(null, _.map(non_empty_results, function (result) {
|
||||
var new_domain = result.model._domain;
|
||||
var new_groupings = groupbys.slice(1);
|
||||
return query_groups(model, fields,new_domain, new_groupings).then(function (subgroups) {
|
||||
result.subgroups_data = subgroups;
|
||||
});
|
||||
}));
|
||||
return get_subgroups.then(function () {
|
||||
return non_empty_results;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function query_groups_data(model, fields, domain, row_groupbys, col_groupby) {
|
||||
return query_groups(model, fields, domain, [col_groupby].concat(row_groupbys)).then(function (groups) {
|
||||
return _.map(groups, function (group) {
|
||||
return format_group(group, []);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function format_group (group, path) {
|
||||
group.path = path.concat(group.attributes.value[1]);
|
||||
result = [group];
|
||||
_.each(group.subgroups_data, function (subgroup) {
|
||||
result = result.concat(format_group (subgroup, group.path));
|
||||
});
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue