discourse/plugins/poll/assets/javascripts/components/poll-results-standard.js.es6

26 lines
762 B
Text
Raw Normal View History

export default Em.Component.extend({
tagName: "table",
classNames: ["results"],
options: function() {
2015-05-04 10:20:13 -04:00
const voters = this.get("poll.voters"),
backgroundColor = this.get("poll.background");
this.get("poll.options").forEach(option => {
2015-05-04 10:20:13 -04:00
const percentage = voters === 0 ? 0 : Math.floor(100 * option.get("votes") / voters),
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.[]")
});