diff options
| author | Mathieu Duckerts-Antoine <dam@odoo.com> | 2019-04-02 15:00:53 +0000 |
|---|---|---|
| committer | Mathieu Duckerts-Antoine <dam@odoo.com> | 2019-08-02 18:34:18 +0000 |
| commit | 49a97305b1f214b7d27f3de3bd0a91b6c551f8cd (patch) | |
| tree | 7951ce91fb4d3798f351d88caa7427623079466f /addons/web/static/src/js/core | |
| parent | 1ef258f6cbb8214e765fee50100857dc2a237c19 (diff) | |
[REF] *: pivot view refactoring
The main aim of the present refactoring is twofold:
- simplify the code that was largely complexified at the time of the
introduction of comparisons in the pivot view (Time Ranges menu),
- factorize the method expandHeader and _loadData that were too much complex.
Along the way, the pivot model structure has been simplified
and many tests have been added.
Performances in mobile mode have been improved by avoiding
unecessary operations due to useless column groupbys in that
mode.
It should now be easier to understand and modify the pivot view in future.
Co-Authored-By: Aaron Bohy <aab@odoo.com>
closes odoo/odoo#33615
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Diffstat (limited to 'addons/web/static/src/js/core')
| -rw-r--r-- | addons/web/static/src/js/core/data_comparison_utils.js | 70 | ||||
| -rw-r--r-- | addons/web/static/src/js/core/math_utils.js | 2 |
2 files changed, 33 insertions, 39 deletions
diff --git a/addons/web/static/src/js/core/data_comparison_utils.js b/addons/web/static/src/js/core/data_comparison_utils.js index b55cc4b93d8..ad848824c3d 100644 --- a/addons/web/static/src/js/core/data_comparison_utils.js +++ b/addons/web/static/src/js/core/data_comparison_utils.js @@ -68,67 +68,60 @@ var DateClasses = Class.extend({ /** * @param {Number} value * @param {Number} comparisonValue - * @returns {Object} + * @returns {Number} */ -function computeVariation (value, comparisonValue) { - var magnitude; - var signClass; - - if (!isNaN(value) && !isNaN(comparisonValue)) { - if (comparisonValue === 0) { - if (value === 0) { - magnitude = 0; - } else if (value > 0){ - magnitude = 1; - } else { - magnitude = -1; - } +function computeVariation(value, comparisonValue) { + if (isNaN(value) || isNaN(comparisonValue)) { + return NaN; + } + if (comparisonValue === 0) { + if (value === 0) { + return 0; + } else if (value > 0) { + return 1; } else { - magnitude = (value - comparisonValue) / Math.abs(comparisonValue); + return -1; } - if (magnitude > 0) { - signClass = ' o_positive'; - } else if (magnitude < 0) { - signClass = ' o_negative'; - } else if (magnitude === 0) { - signClass = ' o_null'; - } - return {magnitude: magnitude, signClass: signClass}; - } else { - return {magnitude: NaN}; } + return (value - comparisonValue) / Math.abs(comparisonValue); } /** - * @param {Object} variation + * @param {Number} variation * @param {Object} field * @param {Object} options * @returns {Object} */ -function renderVariation (variation, field, options) { - var $variation; - if (!isNaN(variation.magnitude)) { - $variation = $('<div>', {class: 'o_variation' + variation.signClass}).html( - fieldUtils.format.percentage(variation.magnitude, field, options - )); +function renderVariation(variation, field, options) { + var className = 'o_variation'; + var value; + if (!isNaN(variation)) { + if (variation > 0) { + className += ' o_positive'; + } else if (variation < 0) { + className += ' o_negative'; + } else { + className += ' o_null'; + } + value = fieldUtils.format.percentage(variation, field, options); } else { - $variation = $('<div>', {class: 'o_variation'}).html('-'); + value = '-'; } - return $variation; + return $('<div>', {class: className, html: value}); } /** * @param {JQuery} $node * @param {Number} value * @param {Number} comparisonValue - * @param {Object} variation (with key 'magnitude' and 'signClass') + * @param {Number} variation * @param {function} formatter * @param {Object} field * @param {Object} options * @returns {Object} */ -function renderComparison ($node, value, comparisonValue, variation, formatter, field, options) { +function renderComparison($node, value, comparisonValue, variation, formatter, field, options) { var $variation = renderVariation(variation, field, options); $node.append($variation); - if (!isNaN(variation.magnitude)) { + if (!isNaN(variation)) { $node.append( $('<div>', {class: 'o_comparison'}) .html(formatter(value, field, options) + ' <span>vs</span> ' + formatter(comparisonValue, field, options)) @@ -139,7 +132,8 @@ function renderComparison ($node, value, comparisonValue, variation, formatter, return { computeVariation: computeVariation, DateClasses: DateClasses, - renderComparison: renderComparison + renderComparison: renderComparison, + renderVariation: renderVariation, }; }); diff --git a/addons/web/static/src/js/core/math_utils.js b/addons/web/static/src/js/core/math_utils.js index 0eeb631125b..6f560624ffc 100644 --- a/addons/web/static/src/js/core/math_utils.js +++ b/addons/web/static/src/js/core/math_utils.js @@ -34,7 +34,7 @@ function _cartesian() { * Returns the product of any number n of arrays. * The internal structures of their elements is preserved. * For n = 1, no brackets are put around the unique parameter elements - * For n = 0, the singleton [undefined] is returned since it is the unit + * For n = 0, [undefined] is returned since it is the unit * of the cartesian product (up to isomorphism). * * @returns {Array} |
