From 284b86cf5d81383ee902398bbe4399dc86e2b5bd Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 10 Jul 2015 14:32:14 -0400 Subject: [PATCH] Refactor PostActionSummary a bit. - Remove `Discourse` constant. - Use `LikeCount` instead of `Likecount` --- .../discourse/components/post-menu.js.es6 | 21 ++++--------------- .../discourse/models/action-summary.js.es6 | 1 + .../javascripts/discourse/models/post.js.es6 | 5 ++++- app/assets/javascripts/main_include.js | 1 + 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/discourse/components/post-menu.js.es6 b/app/assets/javascripts/discourse/components/post-menu.js.es6 index e1cb7b00779..d50a6f3610e 100644 --- a/app/assets/javascripts/discourse/components/post-menu.js.es6 +++ b/app/assets/javascripts/discourse/components/post-menu.js.es6 @@ -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) + ""); }, - renderLikes(post, buffer) { - const likeCount = this.get('likeAction.count') || 0; - if (likeCount === 0) { return; } - - buffer.push(""); - }, - - 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(""); }, - 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'); diff --git a/app/assets/javascripts/discourse/models/action-summary.js.es6 b/app/assets/javascripts/discourse/models/action-summary.js.es6 index 0901dcb82c3..12a2c60ec98 100644 --- a/app/assets/javascripts/discourse/models/action-summary.js.es6 +++ b/app/assets/javascripts/discourse/models/action-summary.js.es6 @@ -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'); diff --git a/app/assets/javascripts/discourse/models/post.js.es6 b/app/assets/javascripts/discourse/models/post.js.es6 index c6840cad5db..67458bd4add 100644 --- a/app/assets/javascripts/discourse/models/post.js.es6 +++ b/app/assets/javascripts/discourse/models/post.js.es6 @@ -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; } diff --git a/app/assets/javascripts/main_include.js b/app/assets/javascripts/main_include.js index ddaf3d90c31..2e5e467ef7e 100644 --- a/app/assets/javascripts/main_include.js +++ b/app/assets/javascripts/main_include.js @@ -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