Rename photos[:count] to photos_count in gon

This commit is contained in:
cmrd Senya 2016-08-08 13:38:37 +03:00
parent d8687ccb3a
commit 15e0f88758
No known key found for this signature in database
GPG key ID: 5FCC5BA680E67BFE
7 changed files with 15 additions and 21 deletions

View file

@ -21,8 +21,8 @@ app.pages.Profile = app.views.Base.extend({
this._populateModel(opts);
}
if(app.hasPreload("photos")){
this.photos = app.parsePreload("photos");
if (app.hasPreload("photos_count")) {
this.photos = app.parsePreload("photos_count");
}
if (app.hasPreload("contacts_count")) {
this.contacts = app.parsePreload("contacts_count");

View file

@ -38,7 +38,7 @@ app.views.ProfileHeader = app.views.Base.extend({
},
_shouldShowPhotos: function() {
return (this.photos && this.photos.count > 0);
return (this.photos && this.photos > 0);
},
_shouldShowContacts: function() {

View file

@ -78,7 +78,7 @@
<a href="{{urlTo 'personPhotos' guid}}" id="photos_link">
<i class="entypo-picture"></i>
{{t 'profile.photos'}}
<div class="badge badge-default">{{photos.count}}</div>
<div class="badge badge-default">{{photos}}</div>
</a>
</li>
{{/if}}

View file

@ -75,9 +75,7 @@ class PeopleController < ApplicationController
@contact = current_user.contact_for(@person)
end
gon.preloads[:person] = @person_json
gon.preloads[:photos] = {
count: Photo.visible(current_user, @person).count(:all)
}
gon.preloads[:photos_count] = Photo.visible(current_user, @person).count(:all)
gon.preloads[:contacts_count] = Contact.contact_contacts_for(current_user, @person).count(:all)
respond_with @person, layout: "with_header"
end
@ -135,9 +133,7 @@ class PeopleController < ApplicationController
@contact = current_user.contact_for(@person)
@contacts_of_contact = Contact.contact_contacts_for(current_user, @person)
gon.preloads[:person] = PersonPresenter.new(@person, current_user).as_json
gon.preloads[:photos] = {
count: Photo.visible(current_user, @person).count(:all)
}
gon.preloads[:photos_count] = Photo.visible(current_user, @person).count(:all)
gon.preloads[:contacts_count] = @contacts_of_contact.count(:all)
@contacts_of_contact = @contacts_of_contact.paginate(page: params[:page], per_page: (params[:limit] || 15))
@hashes = hashes_for_people @contacts_of_contact, @aspects

View file

@ -27,9 +27,7 @@ class PhotosController < ApplicationController
respond_to do |format|
format.all do
gon.preloads[:person] = PersonPresenter.new(@person, current_user).as_json
gon.preloads[:photos] = {
count: Photo.visible(current_user, @person).count(:all)
}
gon.preloads[:photos_count] = Photo.visible(current_user, @person).count(:all)
gon.preloads[:contacts_count] = Contact.contact_contacts_for(current_user, @person).count(:all)
render "people/show", layout: "with_header"
end

View file

@ -195,11 +195,11 @@ describe PeopleController, :type => :controller do
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true)
end
get :show, :id => eve.person.to_param
expect(response.body).to include '"photos":{"count":16}'
expect(response.body).to include ',"photos_count":16'
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => false)
get :show, :id => eve.person.to_param
expect(response.body).to include '"photos":{"count":16}' # eve is not sharing with alice
expect(response.body).to include ',"photos_count":16' # eve is not sharing with alice
end
context "when the person is the current user" do
@ -491,11 +491,11 @@ describe PeopleController, :type => :controller do
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true)
end
get :contacts, :person_id => eve.person.to_param
expect(response.body).to include '"photos":{"count":16}'
expect(response.body).to include ',"photos_count":16'
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => false)
get :contacts, :person_id => eve.person.to_param
expect(response.body).to include '"photos":{"count":16}' # eve is not sharing with alice
expect(response.body).to include ',"photos_count":16' # eve is not sharing with alice
end
it "returns a 406 for json format" do

View file

@ -109,11 +109,11 @@ describe PhotosController, :type => :controller do
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true)
end
get :index, :person_id => eve.person.to_param
expect(response.body).to include '"photos":{"count":16}'
expect(response.body).to include ',"photos_count":16'
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => false)
get :index, :person_id => eve.person.to_param
expect(response.body).to include '"photos":{"count":16}' # eve is not sharing with alice
expect(response.body).to include ',"photos_count":16' # eve is not sharing with alice
end
it "returns json when requested" do
@ -160,11 +160,11 @@ describe PhotosController, :type => :controller do
eve.post(:photo, user_file: uploaded_photo, to: eve.aspects.first.id, public: true)
end
get :index, person_id: eve.person.to_param
expect(response.body).to include '"photos":{"count":16}'
expect(response.body).to include ',"photos_count":16'
eve.post(:photo, user_file: uploaded_photo, to: eve.aspects.first.id, public: false)
get :index, person_id: eve.person.to_param
expect(response.body).to include '"photos":{"count":16}'
expect(response.body).to include ',"photos_count":16'
end
it "displays a person's pictures" do