backbone all the streams, besides user. don't use the acts_as_api way for now.
This commit is contained in:
parent
91ba6447d0
commit
42ce3b277b
14 changed files with 80 additions and 39 deletions
|
|
@ -146,12 +146,13 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def stream(stream_klass)
|
||||
authenticate_user!
|
||||
save_sort_order
|
||||
|
||||
stream_klass.new(current_user, :max_time => max_time, :order => sort_order)
|
||||
end
|
||||
|
||||
def default_stream_action(stream_klass)
|
||||
authenticate_user!
|
||||
save_sort_order
|
||||
@stream = stream(stream_klass)
|
||||
|
||||
if params[:only_posts]
|
||||
|
|
|
|||
|
|
@ -11,18 +11,25 @@ class AspectsController < ApplicationController
|
|||
before_filter :ensure_page, :only => :index
|
||||
|
||||
respond_to :html, :js
|
||||
respond_to :json, :only => [:show, :create]
|
||||
respond_to :json, :only => [:show, :create, :index]
|
||||
|
||||
def index
|
||||
#@backbone = true
|
||||
|
||||
aspect_ids = (session[:a_ids] ? session[:a_ids] : [])
|
||||
@stream = Stream::Aspect.new(current_user, aspect_ids,
|
||||
:order => sort_order,
|
||||
:max_time => params[:max_time].to_i)
|
||||
|
||||
respond_with do |format|
|
||||
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
|
||||
|
||||
def create
|
||||
@aspect = current_user.aspects.create(params[:aspect])
|
||||
|
|
|
|||
|
|
@ -5,7 +5,15 @@
|
|||
require File.join(Rails.root, 'lib','stream', 'comments')
|
||||
|
||||
class CommentStreamController < ApplicationController
|
||||
|
||||
respond_to :html, :json
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -5,7 +5,15 @@
|
|||
require File.join(Rails.root, 'lib','stream', 'mention')
|
||||
|
||||
class MentionsController < ApplicationController
|
||||
|
||||
respond_to :html, :json
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ class MultisController < ApplicationController
|
|||
|
||||
respond_with do |format|
|
||||
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_for_api :backbone, :json => stream(Stream::Multi).stream_posts }
|
||||
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 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -133,7 +133,6 @@ class PeopleController < ApplicationController
|
|||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def retrieve_remote
|
||||
|
|
|
|||
|
|
@ -7,8 +7,15 @@ require File.join(Rails.root, 'lib', 'stream', 'followed_tag')
|
|||
class TagFollowingsController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
|
||||
respond_to :html, :json
|
||||
|
||||
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
|
||||
|
||||
# POST /tag_followings
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class TagsController < ApplicationController
|
|||
helper_method :tag_followed?
|
||||
|
||||
respond_to :html, :only => [:show]
|
||||
respond_to :json, :only => [:index]
|
||||
respond_to :json, :only => [:index, :show]
|
||||
|
||||
def index
|
||||
if params[:q] && params[:q].length > 1 && request.format.json?
|
||||
|
|
@ -35,13 +35,20 @@ class TagsController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@backbone = true
|
||||
|
||||
@stream = Stream::Tag.new(current_user, params[:name], :max_time => max_time, :page => params[:page])
|
||||
|
||||
respond_with do |format|
|
||||
format.html do
|
||||
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
|
||||
|
||||
def tag_followed?
|
||||
if @tag_followed.nil?
|
||||
|
|
|
|||
|
|
@ -6,11 +6,6 @@
|
|||
- content_for :head do
|
||||
= include_javascripts :home
|
||||
|
||||
- if @backbone
|
||||
:javascript
|
||||
window.useBackbone = true;
|
||||
|
||||
|
||||
- if current_user.getting_started?
|
||||
#welcome-to-diaspora
|
||||
.container{:style => "position: relative;"}
|
||||
|
|
@ -68,6 +63,6 @@
|
|||
= render 'aspects/aspect_stream', :stream => @stream
|
||||
|
||||
.span-5.rightBar.last
|
||||
= render 'aspects/selected_contacts', :stream => @stream
|
||||
/= render 'aspects/selected_contacts', :stream => @stream
|
||||
|
||||
= render 'shared/right_sections'
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@
|
|||
Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}");
|
||||
Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}";
|
||||
|
||||
- if @backbone
|
||||
:javascript
|
||||
window.useBackbone = true;
|
||||
|
||||
= yield(:head)
|
||||
|
||||
-unless Rails.env == "production"
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
<a href="#" class="block_user control_icon">
|
||||
<img src="/images/icons/ignoreuser.png">
|
||||
|
|
@ -13,32 +15,32 @@
|
|||
|
||||
<div class="sm_body">
|
||||
|
||||
<a href="/people/<%= author.id %>">
|
||||
<img src="<%= author.profile.image_url_small %>" class="avatar" data-person-id="<%= post.author.id %>"/>
|
||||
<a href="/people/<%= post.author.id %>">
|
||||
<img src="<%= post.author.profile.image_url_small %>" class="avatar" data-person-id="<%= post.author.id %>"/>
|
||||
</a>
|
||||
|
||||
<div class="content">
|
||||
<div class="post_initial_info">
|
||||
<span class="from">
|
||||
<a href="/people/<%= author.id %>">
|
||||
<%= author.profile.full_name %>
|
||||
<a href="/people/<%= post.author.id %>">
|
||||
<%= post.author.profile.full_name %>
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span class="details">
|
||||
-
|
||||
<a href="/posts/<%= id %>">
|
||||
<time class="timeago" datetime="<%= created_at %>"/>
|
||||
<a href="/posts/<%= post.id %>">
|
||||
<time class="timeago" datetime="<%= post.created_at %>"/>
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<p>
|
||||
<%= text %>
|
||||
<%= post.text %>
|
||||
</p>
|
||||
|
||||
<div class="info">
|
||||
<span class="via">
|
||||
via <%= provider_display_name %>
|
||||
via <%= post.provider_display_name %>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@
|
|||
%hr
|
||||
|
||||
#main_stream.stream
|
||||
- if !@backbone
|
||||
- if @stream.stream_posts.length > 0
|
||||
= render 'shared/stream', :posts => @stream.stream_posts
|
||||
#pagination
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
var BackboneStream = Backbone.Collection.extend({
|
||||
url: function() {
|
||||
var path = document.location.pathname;
|
||||
|
||||
if(this.models.length) {
|
||||
return "stream.json?max_time=" + _.last(this.models).intTime() / 1000;
|
||||
return path + ".json?max_time=" + _.last(this.models).intTime();
|
||||
}
|
||||
else {
|
||||
return "stream.json";
|
||||
return path + ".json";
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
var Post = Backbone.Model.extend({
|
||||
url: "/posts/:id",
|
||||
intTime: function(){
|
||||
return +new Date(this.postAttributes().created_at);
|
||||
return +new Date(this.postAttributes().created_at) / 1000;
|
||||
},
|
||||
|
||||
postAttributes: function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue