add current user to body tag data field (hackity hack). add comment links to posts

This commit is contained in:
Daniel Grippi 2011-12-01 13:56:57 -08:00 committed by Dennis Collinson
parent 176963fdad
commit d504bf4591
9 changed files with 52 additions and 15 deletions

View file

@ -23,6 +23,7 @@ class Comment < ActiveRecord::Base
t.add :guid t.add :guid
t.add :text t.add :text
t.add :author t.add :author
t.add :created_at
end end

View file

@ -15,6 +15,7 @@ class Post < ActiveRecord::Base
t.add :id t.add :id
t.add :guid t.add :guid
t.add :text t.add :text
t.add :public
t.add :created_at t.add :created_at
t.add :comments_count t.add :comments_count
t.add :last_three_comments t.add :last_three_comments

View file

@ -42,6 +42,7 @@ class Services::Facebook < Service
end end
def save_friends def save_friends
return
url = "https://graph.facebook.com/me/friends?fields[]=name&fields[]=picture&access_token=#{URI.escape(self.access_token)}" url = "https://graph.facebook.com/me/friends?fields[]=name&fields[]=picture&access_token=#{URI.escape(self.access_token)}"
response = Faraday.get(url) response = Faraday.get(url)
data = JSON.parse(response.body)['data'] data = JSON.parse(response.body)['data']

View file

@ -60,7 +60,8 @@
- if @person - if @person
%link{:rel => "alternate", :href => "#{@person.public_url}.atom", :type => "application/atom+xml", :title => "#{t('.public_feed', :name => @person.name)}"} %link{:rel => "alternate", :href => "#{@person.public_url}.atom", :type => "application/atom+xml", :title => "#{t('.public_feed', :name => @person.name)}"}
%body{:class => "#{yield(:body_class)}", 'data-current-user-metadata' => CGI::escape(current_user.person.as_api_response(:backbone).to_json) } - metadata = user_signed_in? ? CGI::escape({:current_user => current_user.person.as_api_response(:backbone)}.to_json) : ""
%body{:class => "#{yield(:body_class)}", 'data-current-user-metadata' => metadata }
- unless @page == :logged_out - unless @page == :logged_out
- flash.each do |name, msg| - flash.each do |name, msg|

View file

@ -1,8 +1,11 @@
<div id="<%= guid %>" class="stream_element"> <div id="<%= guid %>" class="stream_element">
<div class="right controls"> <div class="right controls">
<a href="#" class="block_user control_icon">
<img src="/images/icons/ignoreuser.png"> <% if(author.id != current_user.id) { %>
</a> <a href="#" class="block_user control_icon">
<img src="/images/icons/ignoreuser.png">
</a>
<% } %>
<a href="#" class="delete control_icon remove_post"> <a href="#" class="delete control_icon remove_post">
<img src="/images/deletelabel.png"/> <img src="/images/deletelabel.png"/>
@ -37,14 +40,33 @@
</p> </p>
<div class="info"> <div class="info">
<span class="via"> <% if(provider_display_name != null) { %>
via <%= provider_display_name %> <span class="via">
via <%= provider_display_name %>
-
</span>
<% } %>
<span class="post_scope">
<%= public === true ? "Public" : "Limited" %>
-
</span> </span>
<a href="#" class="focus_comment_textarea">
Comment
</a>
</div> </div>
<div class="comments"> <div class="comments">
<div class="comment_stream"> <div class="comment_stream">
<ul class="comments" >
<ul class="show_comments <%= comments_count <= 3 ? 'hidden' : '' %>">
<li>
<a href="/posts/<%= id %>/comments" class="toggle_post_comments">
Show <%= comments_count - 3 %> more comments
</a>
</li>
</ul>
<ul class="comments">
<% _.each(last_three_comments, function(comment) { %> <% _.each(last_three_comments, function(comment) { %>
<li id="<%= comment.guid %>" class="comment"> <li id="<%= comment.guid %>" class="comment">
@ -74,9 +96,11 @@
</ul> </ul>
<div class="new_comment_form_wrapper"> <div class="new_comment_form_wrapper <%= comments_count > 0 ? '' : 'hidden' %>">
<form accept-charset="UTF-8" action="/posts/<%= id %>/comments" class="new_comment" data-remote="true" id="new_comment_on_<%= id %>" method="post"> <form accept-charset="UTF-8" action="/posts/<%= id %>/comments" class="new_comment" data-remote="true" id="new_comment_on_<%= id %>" method="post">
<!-- <img alt="Bob Grimm" class="avatar" data-person_id="2" src="http://localhost:3000/images/user/wolf.jpg" title="Bob Grimm"> --> <a href="/people/<%= current_user.id %>">
<img src="<%= current_user.avatar.small %>" class="avatar" data-person-id="<%= current_user.id %>"/>
</a>
<p> <p>
<label for="comment_text_on_<%= id %>">Comment</label> <label for="comment_text_on_<%= id %>">Comment</label>

View file

@ -15,6 +15,7 @@ javascripts:
- public/javascripts/vendor/underscore.js - public/javascripts/vendor/underscore.js
- public/javascripts/vendor/backbone.js - public/javascripts/vendor/backbone.js
- public/javascripts/app.js
- public/javascripts/models/* - public/javascripts/models/*
- public/javascripts/collections/* - public/javascripts/collections/*
- public/javascripts/views/* - public/javascripts/views/*

View file

@ -0,0 +1,9 @@
var App = {
Collections: {},
Models: {},
Views: {},
currentUser: function() {
return $.parseJSON(unescape($("body").data("current-user-metadata")));
}
};

View file

@ -2,10 +2,5 @@ var Post = Backbone.Model.extend({
url: "/posts/:id", url: "/posts/:id",
intTime: function(){ intTime: function(){
return +new Date(this.get("created_at")) / 1000; return +new Date(this.get("created_at")) / 1000;
},
// should be moved into the view or something?
currentUserJSON: function(){
return $.parseJSON(unescape($("body").data("current-user-metadata")));
} }
}); });

View file

@ -18,13 +18,17 @@ $(function() {
}, },
appendPost: function(model) { appendPost: function(model) {
var post = $(this.template(model.toJSON())); var post = $(this.template($.extend(
model.toJSON(),
App.currentUser()
)));
$(this.el).append(post); $(this.el).append(post);
Diaspora.BaseWidget.instantiate("StreamElement", post); Diaspora.BaseWidget.instantiate("StreamElement", post);
}, },
collectionFetched: function() { collectionFetched: function() {
this.$(".details time").timeago(); this.$(".details time").timeago();
this.$("label").inFieldLabels();
this.$("#paginate").remove(); this.$("#paginate").remove();
$(this.el).append($("<a>", { $(this.el).append($("<a>", {