MDC DC New Profile shows users info
Profile show json Profile backbone model
This commit is contained in:
parent
f62b9f9698
commit
062de4c269
15 changed files with 128 additions and 49 deletions
10
app/assets/javascripts/app/models/profile.js
Normal file
10
app/assets/javascripts/app/models/profile.js
Normal 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
|
||||
}
|
||||
});
|
||||
|
|
@ -8,25 +8,26 @@ app.pages.Profile = app.views.Base.extend(_.extend(app.views.infiniteScrollMixin
|
|||
// "#canvas" : "canvasView"
|
||||
// },
|
||||
|
||||
initialize : function() {
|
||||
this.stream = this.model = this.model || new app.models.Stream()
|
||||
this.collection = this.model.posts
|
||||
this.model.fetch();
|
||||
initialize : function(options) {
|
||||
this.model = new app.models.Profile.findByGuid(options.personId)
|
||||
this.stream = options && options.stream || new app.models.Stream()
|
||||
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.setupInfiniteScroll()
|
||||
// this.setupInfiniteScroll()
|
||||
},
|
||||
|
||||
postClass : app.views.SmallFrame,
|
||||
|
||||
mason : function() {
|
||||
this.$el.isotope({
|
||||
itemSelector : '.canvas-frame'
|
||||
})
|
||||
}
|
||||
// mason : function() {
|
||||
// this.$el.isotope({
|
||||
// itemSelector : '.canvas-frame'
|
||||
// })
|
||||
// }
|
||||
|
||||
// initViews : function() {
|
||||
// this.canvasView = new app.views.Canvas({model : this.model})
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ app.Router = Backbone.Router.extend({
|
|||
"liked": "stream",
|
||||
"mentions": "stream",
|
||||
|
||||
"people/:id?ex=true": "newProfile",
|
||||
"people/:id": "profile",
|
||||
"u/:name": "profile",
|
||||
|
||||
|
|
@ -26,13 +27,25 @@ app.Router = Backbone.Router.extend({
|
|||
"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() {
|
||||
app.page = new app.pages.Profile();
|
||||
$("#container").html(app.page.render().el)
|
||||
composer : function(){
|
||||
this.renderPage(new app.pages.Composer());
|
||||
},
|
||||
|
||||
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) {
|
||||
|
|
@ -55,23 +68,13 @@ app.Router = Backbone.Router.extend({
|
|||
$("#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) {
|
||||
return query.search("ex=true") != -1
|
||||
},
|
||||
|
||||
renderPage : function(page){
|
||||
app.page = page
|
||||
$("#container").html(app.page.render().el)
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ app.views.infiniteScrollMixin = {
|
|||
$(window).scroll(throttledScroll);
|
||||
},
|
||||
|
||||
renderTemplate : function() {
|
||||
postRenderTemplate : function() {
|
||||
if(this.stream.isFetching()) { this.showLoader() }
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
app.views.Stream = Backbone.View.extend(_.extend({
|
||||
app.views.Stream = Backbone.View.extend(_.extend( app.views.infiniteScrollMixin, {
|
||||
initialize: function(options) {
|
||||
this.stream = this.model
|
||||
this.collection = this.stream.items
|
||||
|
|
@ -24,4 +24,4 @@ app.views.Stream = Backbone.View.extend(_.extend({
|
|||
_.map(this.postViews, function(view){ view.render() })
|
||||
}
|
||||
}
|
||||
}, app.views.infiniteScrollMixin));
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
<div class="container">
|
||||
<h2>
|
||||
Daniel Grippi
|
||||
</h2>
|
||||
|
||||
<div id="canvas"></div>
|
||||
<h1>{{full_name}}</h1>
|
||||
<div>
|
||||
Gender: {{gender}}
|
||||
</div>
|
||||
<div>
|
||||
Bio: {{bio}}
|
||||
</div>
|
||||
<div>
|
||||
Birthday: {{birthday}}
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,17 @@
|
|||
class ProfilesController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
|
||||
respond_to :html
|
||||
respond_to :html, :except => [:show]
|
||||
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
|
||||
@person = current_user.person
|
||||
@aspect = :person_edit
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
class Profile < ActiveRecord::Base
|
||||
self.include_root_in_json = false
|
||||
|
||||
include Diaspora::Federated::Base
|
||||
include Diaspora::Taggable
|
||||
|
||||
attr_accessor :tag_string
|
||||
|
||||
acts_as_taggable_on :tags
|
||||
extract_tags_from :tag_string
|
||||
validates :tag_list, :length => { :maximum => 5 }
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class User < ActiveRecord::Base
|
|||
serialize :hidden_shareables, Hash
|
||||
|
||||
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_to_me, :class_name => 'Invitation', :foreign_key => :recipient_id
|
||||
|
|
|
|||
|
|
@ -123,6 +123,8 @@ Diaspora::Application.routes.draw do
|
|||
end
|
||||
|
||||
resource :profile, :only => [:edit, :update]
|
||||
resources :profiles, :only => [:show]
|
||||
|
||||
|
||||
resources :contacts, :except => [:update, :create] do
|
||||
get :sharing, :on => :collection
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ Feature: editing your profile
|
|||
And I select "30" from "profile_date_day"
|
||||
|
||||
And I press "Update Profile"
|
||||
|
||||
Then I should be on my edit profile page
|
||||
And I should see "Profile updated"
|
||||
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_month" field should be filled with "11"
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ module NavigationHelpers
|
|||
person_path(User.find_by_email($1).person)
|
||||
when /^my account settings page$/
|
||||
edit_user_path
|
||||
when /^my new profile page$/
|
||||
person_path(@me.person, :ex => true)
|
||||
when /^"(\/.*)"/
|
||||
$1
|
||||
else
|
||||
|
|
|
|||
|
|
@ -10,6 +10,13 @@ describe ProfilesController do
|
|||
sign_in :user, @user
|
||||
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
|
||||
it 'succeeds' do
|
||||
get :edit
|
||||
|
|
|
|||
|
|
@ -1,17 +1,26 @@
|
|||
describe("app.pages.Profile", 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
|
||||
});
|
||||
|
||||
it("passes the model down to the post view", function(){
|
||||
expect(this.page.canvasView.model).toBeDefined()
|
||||
expect(this.page.canvasView.model).toBe(this.stream)
|
||||
});
|
||||
// xit("passes the model down to the post view", function(){
|
||||
// expect(this.page.canvasView.model).toBeDefined()
|
||||
// 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(){
|
||||
spyOn(this.stream, "fetch")
|
||||
new app.pages.Profile({model : this.stream})
|
||||
new app.pages.Profile({stream : this.stream})
|
||||
expect(this.stream.fetch).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
var id = this.id.next();
|
||||
return _.extend({
|
||||
|
|
|
|||
Loading…
Reference in a new issue