From f2bb9bc061435fbbd91d05e9fa7dbb7e737ce503 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 27 Sep 2016 09:29:43 -0700 Subject: [PATCH] When summing points on a workboard, display sum with same precision as most-precise value Summary: Fixes T11703. This mostly avoids rounding errors. If point values include "0.001", we also get three digits of precision: 1.000. Maybe useful if your point field is called "bitcoins" or something. Test Plan: Before: {F1851404} After: {F1851405} Reviewers: chad Reviewed By: chad Maniphest Tasks: T11703 Differential Revision: https://secure.phabricator.com/D16601 --- resources/celerity/map.php | 12 ++++++------ .../rsrc/js/application/projects/WorkboardColumn.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 802fe48b7f..eb9f2b9797 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -495,7 +495,7 @@ return array( 'rsrc/js/application/policy/behavior-policy-rule-editor.js' => '5e9f347c', 'rsrc/js/application/projects/WorkboardBoard.js' => 'fe7cb52a', 'rsrc/js/application/projects/WorkboardCard.js' => 'c587b80f', - 'rsrc/js/application/projects/WorkboardColumn.js' => 'bae58312', + 'rsrc/js/application/projects/WorkboardColumn.js' => '21df4ff5', 'rsrc/js/application/projects/WorkboardController.js' => '55baf5ed', 'rsrc/js/application/projects/behavior-project-boards.js' => '14a1faae', 'rsrc/js/application/projects/behavior-project-create.js' => '065227cc', @@ -825,7 +825,7 @@ return array( 'javelin-websocket' => 'e292eaf4', 'javelin-workboard-board' => 'fe7cb52a', 'javelin-workboard-card' => 'c587b80f', - 'javelin-workboard-column' => 'bae58312', + 'javelin-workboard-column' => '21df4ff5', 'javelin-workboard-controller' => '55baf5ed', 'javelin-workflow' => '1e911d0f', 'lightbox-attachment-css' => '7acac05d', @@ -1162,6 +1162,10 @@ return array( 'javelin-stratcom', 'conpherence-thread-manager', ), + '21df4ff5' => array( + 'javelin-install', + 'javelin-workboard-card', + ), '2290aeef' => array( 'javelin-install', 'javelin-dom', @@ -1922,10 +1926,6 @@ return array( 'javelin-uri', 'phabricator-notification', ), - 'bae58312' => array( - 'javelin-install', - 'javelin-workboard-card', - ), 'bb1dd507' => array( 'javelin-behavior', 'javelin-stratcom', diff --git a/webroot/rsrc/js/application/projects/WorkboardColumn.js b/webroot/rsrc/js/application/projects/WorkboardColumn.js index ced39dcd73..81fba84077 100644 --- a/webroot/rsrc/js/application/projects/WorkboardColumn.js +++ b/webroot/rsrc/js/application/projects/WorkboardColumn.js @@ -222,6 +222,7 @@ JX.install('WorkboardColumn', { var points = {}; var count = 0; + var decimal_places = 0; for (var phid in cards) { var card = cards[phid]; @@ -238,6 +239,15 @@ JX.install('WorkboardColumn', { points[status] = 0; } points[status] += card_points; + + // Count the number of decimal places in the point value with the + // most decimal digits. We'll use the same precision when rendering + // the point sum. This avoids rounding errors and makes the display + // a little more consistent. + var parts = card_points.toString().split('.'); + if (parts[1]) { + decimal_places = Math.max(decimal_places, parts[1].length); + } } count++; @@ -247,6 +257,7 @@ JX.install('WorkboardColumn', { for (var k in points) { total_points += points[k]; } + total_points = total_points.toFixed(decimal_places); var limit = this.getPointLimit();