FIX: closed polls with no votes showed NaN as percentage and average
This commit is contained in:
parent
2ead293098
commit
c9e4fd578d
|
@ -12,7 +12,8 @@ export default Em.Component.extend({
|
||||||
}.property("poll.options.@each.{html,votes}"),
|
}.property("poll.options.@each.{html,votes}"),
|
||||||
|
|
||||||
average: function() {
|
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"),
|
}.property("totalScore", "poll.total_votes"),
|
||||||
|
|
||||||
averageRating: function() {
|
averageRating: function() {
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default Em.Component.extend({
|
||||||
backgroundColor = this.get("poll.background");
|
backgroundColor = this.get("poll.background");
|
||||||
|
|
||||||
this.get("poll.options").forEach(option => {
|
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 + "%"];
|
styles = ["width: " + percentage + "%"];
|
||||||
|
|
||||||
if (backgroundColor) { styles.push("background: " + backgroundColor); }
|
if (backgroundColor) { styles.push("background: " + backgroundColor); }
|
||||||
|
|
Loading…
Reference in New Issue