backbone all the streams, besides user. don't use the acts_as_api way for now.

This commit is contained in:
danielgrippi 2011-11-29 14:19:56 -08:00 committed by Dennis Collinson
parent 91ba6447d0
commit 42ce3b277b
14 changed files with 80 additions and 39 deletions

View file

@ -146,12 +146,13 @@ class ApplicationController < ActionController::Base
end end
def stream(stream_klass) def stream(stream_klass)
authenticate_user!
save_sort_order
stream_klass.new(current_user, :max_time => max_time, :order => sort_order) stream_klass.new(current_user, :max_time => max_time, :order => sort_order)
end end
def default_stream_action(stream_klass) def default_stream_action(stream_klass)
authenticate_user!
save_sort_order
@stream = stream(stream_klass) @stream = stream(stream_klass)
if params[:only_posts] if params[:only_posts]

View file

@ -11,16 +11,23 @@ class AspectsController < ApplicationController
before_filter :ensure_page, :only => :index before_filter :ensure_page, :only => :index
respond_to :html, :js respond_to :html, :js
respond_to :json, :only => [:show, :create] respond_to :json, :only => [:show, :create, :index]
def index def index
#@backbone = true
aspect_ids = (session[:a_ids] ? session[:a_ids] : []) aspect_ids = (session[:a_ids] ? session[:a_ids] : [])
@stream = Stream::Aspect.new(current_user, aspect_ids, @stream = Stream::Aspect.new(current_user, aspect_ids,
:order => sort_order, :order => sort_order,
:max_time => params[:max_time].to_i) :max_time => params[:max_time].to_i)
if params[:only_posts] respond_with do |format|
render :partial => 'shared/stream', :locals => {:posts => @stream.stream_posts} format.html do
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.stream_posts}
end
end
format.json{ render :json => @stream.stream_posts.to_json(:include => {:author => {:include => :profile}}) }
end end
end end

View file

@ -5,7 +5,15 @@
require File.join(Rails.root, 'lib','stream', 'comments') require File.join(Rails.root, 'lib','stream', 'comments')
class CommentStreamController < ApplicationController class CommentStreamController < ApplicationController
respond_to :html, :json
def index def index
default_stream_action(Stream::Comments) @backbone = true
respond_with do |format|
format.html{ default_stream_action(Stream::Comments) }
format.json{ render :json => stream(Stream::Comments).stream_posts.to_json(:include => {:author => {:include => :profile}}) }
end
end end
end end

View file

@ -5,7 +5,15 @@
require File.join(Rails.root, 'lib','stream', 'mention') require File.join(Rails.root, 'lib','stream', 'mention')
class MentionsController < ApplicationController class MentionsController < ApplicationController
respond_to :html, :json
def index def index
default_stream_action(Stream::Mention) @backbone = true
respond_with do |format|
format.html{ default_stream_action(Stream::Mention) }
format.json{ render :json => stream(Stream::Mention).stream_posts.to_json(:include => {:author => {:include => :profile}}) }
end
end end
end end

View file

@ -13,8 +13,8 @@ class MultisController < ApplicationController
respond_with do |format| respond_with do |format|
format.html{ default_stream_action(Stream::Multi) } format.html{ default_stream_action(Stream::Multi) }
#format.json{ render :json => stream(Stream::Multi).stream_posts.to_json(:include => {:author => {:include => :profile}}) } format.json{ render :json => stream(Stream::Multi).stream_posts.to_json(:include => {:author => {:include => :profile}}) }
format.json{ render_for_api :backbone, :json => stream(Stream::Multi).stream_posts } #format.json{ render_for_api :backbone, :json => stream(Stream::Multi).stream_posts }
end end
end end
end end

View file

@ -133,7 +133,6 @@ class PeopleController < ApplicationController
} }
end end
end end
end end
def retrieve_remote def retrieve_remote

View file

@ -7,8 +7,15 @@ require File.join(Rails.root, 'lib', 'stream', 'followed_tag')
class TagFollowingsController < ApplicationController class TagFollowingsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html, :json
def index def index
default_stream_action(Stream::FollowedTag) @backbone = true
respond_with do |format|
format.html{ default_stream_action(Stream::FollowedTag) }
format.json{ render :json => stream(Stream::FollowedTag).stream_posts.to_json(:include => {:author => {:include => :profile}}) }
end
end end
# POST /tag_followings # POST /tag_followings

View file

@ -12,7 +12,7 @@ class TagsController < ApplicationController
helper_method :tag_followed? helper_method :tag_followed?
respond_to :html, :only => [:show] respond_to :html, :only => [:show]
respond_to :json, :only => [:index] respond_to :json, :only => [:index, :show]
def index def index
if params[:q] && params[:q].length > 1 && request.format.json? if params[:q] && params[:q].length > 1 && request.format.json?
@ -35,11 +35,18 @@ class TagsController < ApplicationController
end end
def show def show
@backbone = true
@stream = Stream::Tag.new(current_user, params[:name], :max_time => max_time, :page => params[:page]) @stream = Stream::Tag.new(current_user, params[:name], :max_time => max_time, :page => params[:page])
if params[:only_posts] respond_with do |format|
render :partial => 'shared/stream', :locals => {:posts => @stream.stream_posts} format.html do
return if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.stream_posts}
return
end
end
format.json{ render :json => @stream.stream_posts.to_json(:include => {:author => {:include => :profile}}) }
end end
end end

View file

@ -6,11 +6,6 @@
- content_for :head do - content_for :head do
= include_javascripts :home = include_javascripts :home
- if @backbone
:javascript
window.useBackbone = true;
- if current_user.getting_started? - if current_user.getting_started?
#welcome-to-diaspora #welcome-to-diaspora
.container{:style => "position: relative;"} .container{:style => "position: relative;"}
@ -68,6 +63,6 @@
= render 'aspects/aspect_stream', :stream => @stream = render 'aspects/aspect_stream', :stream => @stream
.span-5.rightBar.last .span-5.rightBar.last
= render 'aspects/selected_contacts', :stream => @stream /= render 'aspects/selected_contacts', :stream => @stream
= render 'shared/right_sections' = render 'shared/right_sections'

View file

@ -44,6 +44,10 @@
Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}"); Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}");
Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}"; Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}";
- if @backbone
:javascript
window.useBackbone = true;
= yield(:head) = yield(:head)
-unless Rails.env == "production" -unless Rails.env == "production"

View file

@ -1,4 +1,6 @@
<div id="<%= guid %>" class="stream_element"> <% var post = typeof(status_message) === "undefined" ? (typeof(reshare) === "undefined" ? photo : reshare) : status_message; %>
<div id="<%= post.guid %>" class="stream_element">
<div class="right controls"> <div class="right controls">
<a href="#" class="block_user control_icon"> <a href="#" class="block_user control_icon">
<img src="/images/icons/ignoreuser.png"> <img src="/images/icons/ignoreuser.png">
@ -13,32 +15,32 @@
<div class="sm_body"> <div class="sm_body">
<a href="/people/<%= author.id %>"> <a href="/people/<%= post.author.id %>">
<img src="<%= author.profile.image_url_small %>" class="avatar" data-person-id="<%= post.author.id %>"/> <img src="<%= post.author.profile.image_url_small %>" class="avatar" data-person-id="<%= post.author.id %>"/>
</a> </a>
<div class="content"> <div class="content">
<div class="post_initial_info"> <div class="post_initial_info">
<span class="from"> <span class="from">
<a href="/people/<%= author.id %>"> <a href="/people/<%= post.author.id %>">
<%= author.profile.full_name %> <%= post.author.profile.full_name %>
</a> </a>
</span> </span>
<span class="details"> <span class="details">
- -
<a href="/posts/<%= id %>"> <a href="/posts/<%= post.id %>">
<time class="timeago" datetime="<%= created_at %>"/> <time class="timeago" datetime="<%= post.created_at %>"/>
</a> </a>
</span> </span>
<p> <p>
<%= text %> <%= post.text %>
</p> </p>
<div class="info"> <div class="info">
<span class="via"> <span class="via">
via <%= provider_display_name %> via <%= post.provider_display_name %>
</span> </span>
</div> </div>

View file

@ -67,10 +67,11 @@
%hr %hr
#main_stream.stream #main_stream.stream
- if @stream.stream_posts.length > 0 - if !@backbone
= render 'shared/stream', :posts => @stream.stream_posts - if @stream.stream_posts.length > 0
#pagination = render 'shared/stream', :posts => @stream.stream_posts
=link_to(t('more'), next_page_path, :class => 'paginate') #pagination
- else =link_to(t('more'), next_page_path, :class => 'paginate')
= t('.nobody_talking', :tag => @stream.display_tag_name) - else
= t('.nobody_talking', :tag => @stream.display_tag_name)

View file

@ -1,10 +1,12 @@
var BackboneStream = Backbone.Collection.extend({ var BackboneStream = Backbone.Collection.extend({
url: function() { url: function() {
var path = document.location.pathname;
if(this.models.length) { if(this.models.length) {
return "stream.json?max_time=" + _.last(this.models).intTime() / 1000; return path + ".json?max_time=" + _.last(this.models).intTime();
} }
else { else {
return "stream.json"; return path + ".json";
} }
}, },

View file

@ -1,7 +1,7 @@
var Post = Backbone.Model.extend({ var Post = Backbone.Model.extend({
url: "/posts/:id", url: "/posts/:id",
intTime: function(){ intTime: function(){
return +new Date(this.postAttributes().created_at); return +new Date(this.postAttributes().created_at) / 1000;
}, },
postAttributes: function() { postAttributes: function() {