mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-12 08:41:23 -05:00
30 lines
867 B
JavaScript
30 lines
867 B
JavaScript
import evenRound from "discourse/plugins/poll/lib/even-round";
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
export default Em.Component.extend({
|
|
tagName: "ul",
|
|
classNames: ["results"],
|
|
|
|
@computed("poll.voters", "poll.options.[]")
|
|
options() {
|
|
const options = this.get("poll.options");
|
|
const voters = this.get("poll.voters");
|
|
const percentages = voters === 0 ?
|
|
Array(options.length).fill(0) :
|
|
evenRound(_.map(options, o => 100 * o.get("votes") / voters));
|
|
|
|
options.forEach((option, i) => {
|
|
const percentage = percentages[i];
|
|
const style = new Ember.Handlebars.SafeString(`width: ${percentage}%`);
|
|
|
|
option.setProperties({
|
|
percentage,
|
|
style,
|
|
title: I18n.t("poll.option_title", { count: option.get("votes") })
|
|
});
|
|
});
|
|
|
|
return this.get("poll.options");
|
|
}
|
|
|
|
});
|