discourse/plugins/poll/assets/javascripts/components/poll-results-number.js.es6
Régis Hanol a737090442 - FEATURE: revamped poll plugin
- add User.staff scope
- inject MessageBus into Ember views (so it can be used by the poll plugin)
- REFACTOR: use more accurate is_first_post? method instead of post_number == 1
- FEATURE: add support for JSON-typed custom fields
- FEATURE: allow plugins to add validation
- FEATURE: add post_custom_fields to PostSerializer
- FEATURE: allow plugins to whitelist post_custom_fields
- FIX: don't bump when post did not save successfully
- FEATURE: polls are supported in any post
- FEATURE: allow for multiple polls in the same post
- FEATURE: multiple choice polls
- FEATURE: rating polls
- FEATURE: new dialect allowing users to preview polls in the composer
2015-04-23 19:33:29 +02:00

22 lines
688 B
JavaScript

import round from "discourse/plugins/poll/lib/round";
export default Em.Component.extend({
tagName: "span",
totalScore: function() {
return _.reduce(this.get("poll.options"), function(total, o) {
const value = parseInt(o.get("html"), 10),
votes = parseInt(o.get("votes"), 10);
return total + value * votes;
}, 0);
}.property("poll.options.@each.{html,votes}"),
average: function() {
return round(this.get("totalScore") / this.get("poll.total_votes"), -2);
}.property("totalScore", "poll.total_votes"),
averageRating: function() {
return I18n.t("poll.average_rating", { average: this.get("average") });
}.property("average"),
});