Refactor PostActionSummary a bit.

- Remove `Discourse` constant.
- Use `LikeCount` instead of `Likecount`
This commit is contained in:
Robin Ward 2015-07-10 14:32:14 -04:00
parent ce86c9956e
commit 284b86cf5d
4 changed files with 10 additions and 18 deletions

View File

@ -91,7 +91,7 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, {
action = $target.data('action') || $target.parent().data('action');
if (!action) return;
const handler = this["click" + action.replace(/[\+-]/, "").capitalize()];
const handler = this["click" + action.classify()];
if (!handler) return;
handler.call(this, this.get('post'));
@ -109,19 +109,6 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, {
return buffer.push(iconHTML(icon) + "</button>");
},
renderLikes(post, buffer) {
const likeCount = this.get('likeAction.count') || 0;
if (likeCount === 0) { return; }
buffer.push("<button class='show-likes' data-action='likes'>");
buffer.push("<span class='badge-posts'>" + Discourse.Formatter.number(likeCount) + "</span>");
buffer.push(I18n.t("post.has_likes", { count: likeCount }));
const icon = (this.get('likeAction.users.length') > 0) ? 'chevron-up' : 'chevron-down';
return buffer.push(iconHTML(icon) + "</button>");
},
renderButtons(post, buffer) {
const self = this;
const allButtons = [];
@ -141,7 +128,7 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, {
const yours = post.get('yours');
this.siteSettings.post_menu.split("|").forEach(function(i) {
const creator = self["buttonFor" + i.replace(/[\+-]/, '').capitalize()];
const creator = self["buttonFor" + i.classify()];
if (creator) {
const button = creator.call(self, post);
if (button) {
@ -177,7 +164,7 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, {
buffer.push("</div>");
},
clickLikecount() {
clickLikeCount() {
const likeAction = this.get('post.actionByName.like');
if (likeAction) {
const users = likeAction.get('users');
@ -259,7 +246,7 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, {
}
},
buttonForLikecount() {
buttonForLikeCount() {
var likeCount = this.get('post.like_count') || 0;
if (likeCount > 0) {
const likedPost = !!this.get('likeAction.acted');

View File

@ -56,6 +56,7 @@ export default RestModel.extend({
// Perform this action
act: function(post, opts) {
if (!opts) opts = {};
const action = this.get('actionType.name_key');

View File

@ -1,5 +1,6 @@
import RestModel from 'discourse/models/rest';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import ActionSummary from 'discourse/models/action-summary';
const Post = RestModel.extend({
@ -359,13 +360,15 @@ Post.reopenClass({
munge(json) {
if (json.actions_summary) {
const lookup = Em.Object.create();
// this area should be optimized, it is creating way too many objects per post
json.actions_summary = json.actions_summary.map(function(a) {
a.actionType = Discourse.Site.current().postActionTypeById(a.id);
const actionSummary = Discourse.ActionSummary.create(a);
const actionSummary = ActionSummary.create(a);
lookup[a.actionType.name_key] = actionSummary;
return actionSummary;
});
json.actionByName = lookup;
}

View File

@ -28,6 +28,7 @@
//= require ./discourse/models/rest
//= require ./discourse/models/model
//= require ./discourse/models/post-action-type
//= require ./discourse/models/action-summary
//= require ./discourse/models/post
//= require ./discourse/models/post-stream
//= require ./discourse/models/topic-details