From 0f995a25d5bb467dfb309a9f197a1f7e962b2445 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Sat, 23 Nov 2013 11:59:25 +0100 Subject: [PATCH] [REF] moves utility functions to pivot.js file and remove utility.js in addon web_graph bzr revid: ged@openerp.com-20131123105925-edix9lyw9k6tjlmw --- addons/web_graph/__openerp__.py | 1 - addons/web_graph/static/src/js/pivot.js | 59 +++++++++++++++++++++++ addons/web_graph/static/src/js/utility.js | 58 ---------------------- 3 files changed, 59 insertions(+), 59 deletions(-) delete mode 100644 addons/web_graph/static/src/js/utility.js diff --git a/addons/web_graph/__openerp__.py b/addons/web_graph/__openerp__.py index 5468c894b7d..8d8a267baf1 100644 --- a/addons/web_graph/__openerp__.py +++ b/addons/web_graph/__openerp__.py @@ -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', diff --git a/addons/web_graph/static/src/js/pivot.js b/addons/web_graph/static/src/js/pivot.js index a5a3af78ae9..e42f8f272ff 100644 --- a/addons/web_graph/static/src/js/pivot.js +++ b/addons/web_graph/static/src/js/pivot.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; +} + diff --git a/addons/web_graph/static/src/js/utility.js b/addons/web_graph/static/src/js/utility.js deleted file mode 100644 index bb0f6a9835d..00000000000 --- a/addons/web_graph/static/src/js/utility.js +++ /dev/null @@ -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; -} \ No newline at end of file