mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-19 03:52:25 -05:00
a737090442
- 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
22 lines
688 B
JavaScript
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"),
|
|
|
|
});
|