From c9e4fd578dcd2b97444cbc05cbfd0ad6113b502a Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Sat, 2 May 2015 01:58:23 +0200 Subject: [PATCH] FIX: closed polls with no votes showed NaN as percentage and average --- .../assets/javascripts/components/poll-results-number.js.es6 | 3 ++- .../assets/javascripts/components/poll-results-standard.js.es6 | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/poll/assets/javascripts/components/poll-results-number.js.es6 b/plugins/poll/assets/javascripts/components/poll-results-number.js.es6 index 46a904f279b..4e7c6b35fa2 100644 --- a/plugins/poll/assets/javascripts/components/poll-results-number.js.es6 +++ b/plugins/poll/assets/javascripts/components/poll-results-number.js.es6 @@ -12,7 +12,8 @@ export default Em.Component.extend({ }.property("poll.options.@each.{html,votes}"), average: function() { - return round(this.get("totalScore") / this.get("poll.total_votes"), -2); + const total_votes = this.get("poll.total_votes"); + return total_votes == 0 ? 0 : round(this.get("totalScore") / total_votes, -2); }.property("totalScore", "poll.total_votes"), averageRating: function() { diff --git a/plugins/poll/assets/javascripts/components/poll-results-standard.js.es6 b/plugins/poll/assets/javascripts/components/poll-results-standard.js.es6 index 49fe8b88dfb..21f213d83eb 100644 --- a/plugins/poll/assets/javascripts/components/poll-results-standard.js.es6 +++ b/plugins/poll/assets/javascripts/components/poll-results-standard.js.es6 @@ -7,7 +7,7 @@ export default Em.Component.extend({ backgroundColor = this.get("poll.background"); this.get("poll.options").forEach(option => { - const percentage = Math.floor(100 * option.get("votes") / totalVotes), + const percentage = totalVotes == 0 ? 0 : Math.floor(100 * option.get("votes") / totalVotes), styles = ["width: " + percentage + "%"]; if (backgroundColor) { styles.push("background: " + backgroundColor); }