MDC DC New Profile shows users info

Profile show json
Profile backbone model
This commit is contained in:
Dennis Collinson 2012-04-18 16:50:00 -07:00
parent f62b9f9698
commit 062de4c269
15 changed files with 128 additions and 49 deletions

View file

@ -0,0 +1,10 @@
app.models.Profile = Backbone.Model.extend({
urlRoot : "/profiles"
}, {
findByGuid : function(personId){
var person = new app.models.Profile({ id : personId})
person.fetch()
return person
}
});

View file

@ -8,25 +8,26 @@ app.pages.Profile = app.views.Base.extend(_.extend(app.views.infiniteScrollMixin
// "#canvas" : "canvasView" // "#canvas" : "canvasView"
// }, // },
initialize : function() { initialize : function(options) {
this.stream = this.model = this.model || new app.models.Stream() this.model = new app.models.Profile.findByGuid(options.personId)
this.collection = this.model.posts this.stream = options && options.stream || new app.models.Stream()
this.model.fetch(); this.collection = this.stream.posts
this.stream.fetch();
this.stream.bind("fetched", this.mason, this) this.model.bind("change", this.render, this)
// this.initViews() // this.initViews()
this.setupInfiniteScroll() // this.setupInfiniteScroll()
}, },
postClass : app.views.SmallFrame, postClass : app.views.SmallFrame,
mason : function() { // mason : function() {
this.$el.isotope({ // this.$el.isotope({
itemSelector : '.canvas-frame' // itemSelector : '.canvas-frame'
}) // })
} // }
// initViews : function() { // initViews : function() {
// this.canvasView = new app.views.Canvas({model : this.model}) // this.canvasView = new app.views.Canvas({model : this.model})

View file

@ -13,6 +13,7 @@ app.Router = Backbone.Router.extend({
"liked": "stream", "liked": "stream",
"mentions": "stream", "mentions": "stream",
"people/:id?ex=true": "newProfile",
"people/:id": "profile", "people/:id": "profile",
"u/:name": "profile", "u/:name": "profile",
@ -26,13 +27,25 @@ app.Router = Backbone.Router.extend({
"framer": "framer" "framer": "framer"
}, },
profile : function(page) {
this.isExperimental(page) ? this.newProfile() : this.stream() newProfile : function(personId) {
this.renderPage(new app.pages.Profile({ personId : personId }));
}, },
newProfile : function() { composer : function(){
app.page = new app.pages.Profile(); this.renderPage(new app.pages.Composer());
$("#container").html(app.page.render().el) },
framer : function(){
this.renderPage(new app.pages.Framer());
},
singlePost : function(id) {
this.renderPage(new app.pages.PostViewer({ id: id }));
},
profile : function(page) {
this.stream()
}, },
stream : function(page) { stream : function(page) {
@ -55,23 +68,13 @@ app.Router = Backbone.Router.extend({
$("#main_stream").html(app.page.render().el); $("#main_stream").html(app.page.render().el);
}, },
composer : function(){
var page = new app.pages.Composer();
$("#container").html(page.render().el)
},
framer : function(){
var page = new app.pages.Framer();
$("#container").html(page.render().el)
},
singlePost : function(id) {
var page = new app.pages.PostViewer({ id: id });
$("#container").html(page.el);
},
isExperimental : function(query) { isExperimental : function(query) {
return query.search("ex=true") != -1 return query.search("ex=true") != -1
},
renderPage : function(page){
app.page = page
$("#container").html(app.page.render().el)
} }
}); });

View file

@ -95,7 +95,7 @@ app.views.infiniteScrollMixin = {
$(window).scroll(throttledScroll); $(window).scroll(throttledScroll);
}, },
renderTemplate : function() { postRenderTemplate : function() {
if(this.stream.isFetching()) { this.showLoader() } if(this.stream.isFetching()) { this.showLoader() }
}, },

View file

@ -1,4 +1,4 @@
app.views.Stream = Backbone.View.extend(_.extend({ app.views.Stream = Backbone.View.extend(_.extend( app.views.infiniteScrollMixin, {
initialize: function(options) { initialize: function(options) {
this.stream = this.model this.stream = this.model
this.collection = this.stream.items this.collection = this.stream.items
@ -24,4 +24,4 @@ app.views.Stream = Backbone.View.extend(_.extend({
_.map(this.postViews, function(view){ view.render() }) _.map(this.postViews, function(view){ view.render() })
} }
} }
}, app.views.infiniteScrollMixin)); }));

View file

@ -1,8 +1,11 @@
<div class="container"> <h1>{{full_name}}</h1>
<h2> <div>
Daniel Grippi Gender: {{gender}}
</h2> </div>
<div>
<div id="canvas"></div> Bio: {{bio}}
</div>
<div>
Birthday: {{birthday}}
</div> </div>

View file

@ -5,8 +5,17 @@
class ProfilesController < ApplicationController class ProfilesController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html respond_to :html, :except => [:show]
respond_to :js, :only => :update respond_to :js, :only => :update
def show
@profile = Person.find_by_guid!(params[:id]).profile
respond_to do |format|
format.json { render :json => @profile }
end
end
def edit def edit
@person = current_user.person @person = current_user.person
@aspect = :person_edit @aspect = :person_edit

View file

@ -3,11 +3,12 @@
# the COPYRIGHT file. # the COPYRIGHT file.
class Profile < ActiveRecord::Base class Profile < ActiveRecord::Base
self.include_root_in_json = false
include Diaspora::Federated::Base include Diaspora::Federated::Base
include Diaspora::Taggable include Diaspora::Taggable
attr_accessor :tag_string attr_accessor :tag_string
acts_as_taggable_on :tags acts_as_taggable_on :tags
extract_tags_from :tag_string extract_tags_from :tag_string
validates :tag_list, :length => { :maximum => 5 } validates :tag_list, :length => { :maximum => 5 }

View file

@ -33,7 +33,7 @@ class User < ActiveRecord::Base
serialize :hidden_shareables, Hash serialize :hidden_shareables, Hash
has_one :person, :foreign_key => :owner_id has_one :person, :foreign_key => :owner_id
delegate :public_key, :posts, :photos, :owns?, :diaspora_handle, :name, :public_url, :profile, :first_name, :last_name, :participations, :to => :person delegate :guid, :public_key, :posts, :photos, :owns?, :diaspora_handle, :name, :public_url, :profile, :first_name, :last_name, :participations, :to => :person
has_many :invitations_from_me, :class_name => 'Invitation', :foreign_key => :sender_id has_many :invitations_from_me, :class_name => 'Invitation', :foreign_key => :sender_id
has_many :invitations_to_me, :class_name => 'Invitation', :foreign_key => :recipient_id has_many :invitations_to_me, :class_name => 'Invitation', :foreign_key => :recipient_id

View file

@ -123,6 +123,8 @@ Diaspora::Application.routes.draw do
end end
resource :profile, :only => [:edit, :update] resource :profile, :only => [:edit, :update]
resources :profiles, :only => [:show]
resources :contacts, :except => [:update, :create] do resources :contacts, :except => [:update, :create] do
get :sharing, :on => :collection get :sharing, :on => :collection

View file

@ -13,6 +13,7 @@ Feature: editing your profile
And I select "30" from "profile_date_day" And I select "30" from "profile_date_day"
And I press "Update Profile" And I press "Update Profile"
Then I should be on my edit profile page Then I should be on my edit profile page
And I should see "Profile updated" And I should see "Profile updated"
And the "profile_gender" field should contain "Fearless" And the "profile_gender" field should contain "Fearless"
@ -22,3 +23,9 @@ Feature: editing your profile
And the "profile_date_year" field should be filled with "1986" And the "profile_date_year" field should be filled with "1986"
And the "profile_date_month" field should be filled with "11" And the "profile_date_month" field should be filled with "11"
And the "profile_date_day" field should be filled with "30" And the "profile_date_day" field should be filled with "30"
When I go to my new profile page
Then I should see "Gender: Fearless"
And I should see "Boba Fett"
And I should see "Bio: This is a bio"
And I should see "Birthday: 1986-11-30"

View file

@ -27,6 +27,8 @@ module NavigationHelpers
person_path(User.find_by_email($1).person) person_path(User.find_by_email($1).person)
when /^my account settings page$/ when /^my account settings page$/
edit_user_path edit_user_path
when /^my new profile page$/
person_path(@me.person, :ex => true)
when /^"(\/.*)"/ when /^"(\/.*)"/
$1 $1
else else

View file

@ -10,6 +10,13 @@ describe ProfilesController do
sign_in :user, @user sign_in :user, @user
end end
describe '#show' do
it "returns the user as json" do
get :show, :id => @user.person.guid, :format => :json
response.body.should == @user.person.profile.to_json
end
end
describe '#edit' do describe '#edit' do
it 'succeeds' do it 'succeeds' do
get :edit get :edit

View file

@ -1,17 +1,26 @@
describe("app.pages.Profile", function(){ describe("app.pages.Profile", function(){
beforeEach(function(){ beforeEach(function(){
this.page = new app.pages.Profile(); this.guid = 'abcdefg123'
this.page = new app.pages.Profile({personId :this.guid });
this.stream = this.page.stream this.stream = this.page.stream
}); });
it("passes the model down to the post view", function(){ // xit("passes the model down to the post view", function(){
expect(this.page.canvasView.model).toBeDefined() // expect(this.page.canvasView.model).toBeDefined()
expect(this.page.canvasView.model).toBe(this.stream) // expect(this.page.canvasView.model).toBe(this.stream)
}); // });
it("fetches the profile of the user with the params from the router", function(){
profile = new factory.profile()
spyOn(app.models.Profile, 'findByGuid').andReturn(profile)
var page = new app.pages.Profile({personId : 'jarjabinkisthebest' })
expect(app.models.Profile.findByGuid).toHaveBeenCalledWith('jarjabinkisthebest')
expect(page.model).toBe(profile)
})
it("fetches the stream for the user", function(){ it("fetches the stream for the user", function(){
spyOn(this.stream, "fetch") spyOn(this.stream, "fetch")
new app.pages.Profile({model : this.stream}) new app.pages.Profile({stream : this.stream})
expect(this.stream.fetch).toHaveBeenCalled() expect(this.stream.fetch).toHaveBeenCalled()
}) })

View file

@ -74,6 +74,31 @@ factory = {
} }
}, },
profile : function(overrides) {
var id = overrides && overrides.id || factory.id.next()
var defaults = {
"bio": "I am a cat lover and I love to run",
"birthday": "2012-04-17",
"created_at": "2012-04-17T23:48:35Z",
"diaspora_handle": "bob@localhost:3000",
"first_name": "Bob",
"full_name": "bob grimm",
"gender": "robot",
"id": id,
"image_url": "http:\/\/localhost:3000\/assets\/user\/wolf.jpg",
"image_url_medium": "http:\/\/localhost:3000\/assets\/user\/wolf.jpg",
"image_url_small": "http:\/\/localhost:3000\/assets\/user\/wolf.jpg",
"last_name": "Grimm",
"location": "Earth",
"nsfw": false,
"person_id": "person" + id,
"searchable": true,
"updated_at": "2012-04-17T23:48:36Z"
}
return new app.models.Profile(_.extend(defaults, overrides))
},
photoAttrs : function(overrides){ photoAttrs : function(overrides){
var id = this.id.next(); var id = this.id.next();
return _.extend({ return _.extend({