diff options
| author | Gery Debongnie <ged@openerp.com> | 2013-11-23 11:59:25 +0100 |
|---|---|---|
| committer | Gery Debongnie <ged@openerp.com> | 2013-11-23 11:59:25 +0100 |
| commit | 0f995a25d5bb467dfb309a9f197a1f7e962b2445 (patch) | |
| tree | 5f8dc7bb1d4632c1e5584bd158d5287e628152fd /addons/web_graph/static/src/js | |
| parent | ebf46e668d6f0ae9695eb693b8ffb6b1498ba6c4 (diff) | |
[REF] moves utility functions to pivot.js file and remove utility.js in addon web_graph
bzr revid: ged@openerp.com-20131123105925-edix9lyw9k6tjlmw
Diffstat (limited to 'addons/web_graph/static/src/js')
| -rw-r--r-- | addons/web_graph/static/src/js/pivot.js | 59 | ||||
| -rw-r--r-- | addons/web_graph/static/src/js/utility.js | 58 |
2 files changed, 59 insertions, 58 deletions
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 |
