discourse/plugins/poll/assets/javascripts/components/poll-results-standard.js.es6
Régis Hanol 86d7412f30 REFACTOR: rename "total_votes" poll field to the more accurate "voters"
FEATURE: automagically load plugin's migrations
2015-05-04 16:01:57 +02:00

25 lines
773 B
JavaScript

export default Em.Component.extend({
tagName: "table",
classNames: ["results"],
options: function() {
const totalVotes = this.get("poll.voters"),
backgroundColor = this.get("poll.background");
this.get("poll.options").forEach(option => {
const percentage = totalVotes == 0 ? 0 : Math.floor(100 * option.get("votes") / totalVotes),
styles = ["width: " + percentage + "%"];
if (backgroundColor) { styles.push("background: " + backgroundColor); }
option.setProperties({
percentage: percentage,
title: I18n.t("poll.option_title", { count: option.get("votes") }),
style: styles.join(";")
});
});
return this.get("poll.options");
}.property("poll.voters", "poll.options.[]")
});