FEATURE: Can click to expand hidden posts to see the good stuff!

This commit is contained in:
Robin Ward 2014-06-20 17:06:44 -04:00
parent 14c1752474
commit 8a4e96645c
8 changed files with 54 additions and 5 deletions

View File

@ -294,6 +294,10 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
});
},
expandHidden: function(post) {
post.expandHidden();
},
toggleVisibility: function() {
this.get('content').toggleStatus('visible');
},

View File

@ -396,7 +396,17 @@ Discourse.Post = Discourse.Model.extend({
var topic = this.get('topic');
return !topic.isReplyDirectlyBelow(this);
}.property('reply_count')
}.property('reply_count'),
expandHidden: function() {
var self = this;
return Discourse.ajax("/posts/" + this.get('id') + "/cooked.json").then(function (result) {
self.setProperties({
cooked: result.cooked,
cooked_hidden: false
});
});
}
});
Discourse.Post.reopenClass({

View File

@ -63,7 +63,12 @@
</div>
<div {{bind-attr class="showUserReplyTab:avoid-tab view.repliesShown::bottom-round :contents :regular view.extraClass"}}>
<div class='cooked'>{{{cooked}}}</div>
<div class='cooked'>
{{{cooked}}}
</div>
{{#if cooked_hidden}}
<a href {{action expandHidden this}}>{{i18n post.show_hidden}}</a>
{{/if}}
{{#if view.showExpandButton}}
{{#if controller.loadingExpanded}}
<button class="btn expand-post" disabled>{{i18n loading}}</button>

View File

@ -5,7 +5,7 @@ require_dependency 'distributed_memoizer'
class PostsController < ApplicationController
# Need to be logged in for all actions here
before_filter :ensure_logged_in, except: [:show, :replies, :by_number, :short_link, :reply_history, :revisions, :expand_embed, :markdown]
before_filter :ensure_logged_in, except: [:show, :replies, :by_number, :short_link, :reply_history, :revisions, :expand_embed, :markdown, :raw, :cooked]
skip_before_filter :store_incoming_links, only: [:short_link]
skip_before_filter :check_xhr, only: [:markdown,:short_link]
@ -19,6 +19,11 @@ class PostsController < ApplicationController
end
end
def cooked
post = find_post_from_params
render json: {cooked: post.cooked}
end
def short_link
post = Post.find(params[:post_id].to_i)
IncomingLink.add(request,current_user)

View File

@ -6,7 +6,8 @@ class BasicPostSerializer < ApplicationSerializer
:avatar_template,
:uploaded_avatar_id,
:created_at,
:cooked
:cooked,
:cooked_hidden
def name
object.user.try(:name)
@ -24,8 +25,15 @@ class BasicPostSerializer < ApplicationSerializer
object.user.try(:uploaded_avatar_id)
end
def cooked_hidden
object.hidden && !scope.is_staff?
end
def include_cooked_hidden?
cooked_hidden
end
def cooked
if object.hidden && !scope.is_staff?
if cooked_hidden
if scope.current_user && object.user_id == scope.current_user.id
I18n.t('flagging.you_must_edit')
else

View File

@ -953,6 +953,7 @@ en:
continue_discussion: "Continuing the discussion from {{postLink}}:"
follow_quote: "go to the quoted post"
show_full: "Show Full Post"
show_hidden: 'View hidden content.'
deleted_by_author:
one: "(post withdrawn by author, will be automatically deleted in %{count} hour unless flagged)"
other: "(post withdrawn by author, will be automatically deleted in %{count} hours unless flagged)"

View File

@ -361,6 +361,7 @@ Discourse::Application.routes.draw do
post "t/:topic_id/notifications" => "topics#set_notifications" , constraints: {topic_id: /\d+/}
get "/posts/:id/cooked" => "posts#cooked"
get "/posts/:id/expand-embed" => "posts#expand_embed"
get "raw/:topic_id(/:post_number)" => "posts#markdown"

View File

@ -57,6 +57,21 @@ describe PostsController do
end
end
describe 'cooked' do
before do
post = Post.new(cooked: 'wat')
PostsController.any_instance.expects(:find_post_from_params).returns(post)
end
it 'returns the cooked conent' do
xhr :get, :cooked, id: 1234
response.should be_success
json = ::JSON.parse(response.body)
json.should be_present
json['cooked'].should == 'wat'
end
end
describe 'show' do
include_examples 'finding and showing post' do
let(:action) { :show }