display proper counts after feedback actions; modified destroy responses to return PostPresenter objects
This commit is contained in:
parent
37981b71fe
commit
899136d0e5
7 changed files with 30 additions and 12 deletions
|
|
@ -32,8 +32,7 @@ class LikesController < ApplicationController
|
||||||
if @like
|
if @like
|
||||||
current_user.retract(@like)
|
current_user.retract(@like)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.any { }
|
format.json { render :json => PostPresenter.new(@like.parent, current_user).to_json, :status => 202 }
|
||||||
format.json{ render :json => @like.parent.as_api_response(:backbone), :status => 202 }
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,7 @@ class ParticipationsController < ApplicationController
|
||||||
if @participation
|
if @participation
|
||||||
current_user.retract(@participation)
|
current_user.retract(@participation)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.any { }
|
format.json { render :json => PostPresenter.new(@participation.parent, current_user).to_json, :status => 202 }
|
||||||
format.json{ render :json => @participation.parent.as_api_response(:backbone), :status => 202 }
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ class PostPresenter
|
||||||
{
|
{
|
||||||
:user_like => self.user_like,
|
:user_like => self.user_like,
|
||||||
:user_participation => self.user_participation,
|
:user_participation => self.user_participation,
|
||||||
|
:likes_count => self.post.likes.count,
|
||||||
|
:participations_count => self.post.participations.count,
|
||||||
|
:reshares_count => self.post.reshares.count,
|
||||||
:user_reshare => self.user_reshare,
|
:user_reshare => self.user_reshare,
|
||||||
:next_post => self.next_post_url,
|
:next_post => self.next_post_url,
|
||||||
:previous_post => self.previous_post_url
|
:previous_post => self.previous_post_url
|
||||||
|
|
|
||||||
|
|
@ -46,13 +46,14 @@ app.models.Post = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
unfollow : function() {
|
unfollow : function() {
|
||||||
|
var self = this;
|
||||||
var participationModel = new app.models.Participation(this.get("user_participation"));
|
var participationModel = new app.models.Participation(this.get("user_participation"));
|
||||||
participationModel.url = this.participations.url + "/" + participationModel.id;
|
participationModel.url = this.participations.url + "/" + participationModel.id;
|
||||||
|
|
||||||
participationModel.destroy();
|
participationModel.destroy({success : function(model, resp){
|
||||||
this.set({ user_participation : null });
|
self.set(resp.post);
|
||||||
|
self.trigger('feedback', this)
|
||||||
this.trigger('feedback', this)
|
}});
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleLike : function() {
|
toggleLike : function() {
|
||||||
|
|
@ -67,17 +68,19 @@ app.models.Post = Backbone.Model.extend({
|
||||||
like : function() {
|
like : function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.likes.create({}, {success : function(resp){
|
this.likes.create({}, {success : function(resp){
|
||||||
self.set(resp.attributes.post)
|
self.set(resp.get("post"))
|
||||||
self.trigger('feedback', self)
|
self.trigger('feedback', self)
|
||||||
}});
|
}});
|
||||||
},
|
},
|
||||||
|
|
||||||
unlike : function() {
|
unlike : function() {
|
||||||
|
var self = this;
|
||||||
var likeModel = new app.models.Like(this.get("user_like"));
|
var likeModel = new app.models.Like(this.get("user_like"));
|
||||||
likeModel.url = this.likes.url + "/" + likeModel.id;
|
likeModel.url = this.likes.url + "/" + likeModel.id;
|
||||||
|
|
||||||
likeModel.destroy();
|
likeModel.destroy({success : function(model, resp) {
|
||||||
this.set({ user_like : null });
|
self.set(resp.post);
|
||||||
this.trigger('feedback', this)
|
self.trigger('feedback', this)
|
||||||
|
}});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<i class="icon-heart icon-white"></i>
|
<i class="icon-heart icon-white"></i>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{likes_count}}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="#" class="label follow" title="{{#if user_participation}} Stop Following {{else}} Follow {{/if}} Post">
|
<a href="#" class="label follow" title="{{#if user_participation}} Stop Following {{else}} Follow {{/if}} Post">
|
||||||
|
|
@ -18,6 +19,7 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<i class="icon-plus icon-white"></i>
|
<i class="icon-plus icon-white"></i>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{participations_count}}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
{{#if userCanReshare}}
|
{{#if userCanReshare}}
|
||||||
|
|
@ -27,9 +29,11 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<i class="icon-retweet icon-white"></i>
|
<i class="icon-retweet icon-white"></i>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{reshares_count}}
|
||||||
</a>
|
</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<a href="#" class="label comment" title="Comment">
|
<a href="#" class="label comment" title="Comment">
|
||||||
<i class="icon-comment icon-white"></i>
|
<i class="icon-comment icon-white"></i>
|
||||||
|
{{comments_count}}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,11 @@ describe LikesController do
|
||||||
|
|
||||||
response.status.should == 403
|
response.status.should == 403
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns the parent post presenter' do
|
||||||
|
delete :destroy, :format => :json, id_field => @like.target_id, :id => @like.id
|
||||||
|
response.body.should == PostPresenter.new(@like.parent, alice).to_json.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,11 @@ describe ParticipationsController do
|
||||||
|
|
||||||
response.status.should == 403
|
response.status.should == 403
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns the parent post presenter' do
|
||||||
|
delete :destroy, :format => :json, id_field => @participation.target_id, :id => @participation.id
|
||||||
|
response.body.should == PostPresenter.new(@participation.parent, alice).to_json.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue