From 9d7611f8d8258d22c4dc793b4140c5d45e1c5510 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Wed, 2 Mar 2011 12:22:08 -0800 Subject: [PATCH] addedthe controllers and the views for the message and the conversation inbox, going to pull in some left nav styling --- app/controllers/conversations_controller.rb | 8 ++-- app/controllers/messages_controller.rb | 6 +-- app/views/conversations/_conversation.haml | 20 +++++++++ app/views/conversations/_show.haml | 22 ++++++++++ app/views/conversations/index.haml | 45 +++++++++++--------- app/views/conversations/new.haml | 9 ++-- app/views/conversations/show.haml | 29 +------------ app/views/messages/_message.haml | 17 ++++++++ lib/tasks/db.rake | 13 +----- public/stylesheets/sass/application.sass | 29 ++++++++++++- spec/controllers/messages_controller_spec.rb | 20 ++++----- 11 files changed, 138 insertions(+), 80 deletions(-) create mode 100644 app/views/conversations/_conversation.haml create mode 100644 app/views/conversations/_show.haml create mode 100644 app/views/messages/_message.haml diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index 2718e12f1..b49333446 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -1,11 +1,13 @@ class ConversationsController < ApplicationController before_filter :authenticate_user! - respond_to :html + respond_to :html, :json def index @conversations = Conversation.joins(:conversation_visibilities).where( :conversation_visibilities => {:person_id => current_user.person.id}).all + @conversation = Conversation.joins(:conversation_visibilities).where( + :conversation_visibilities => {:person_id => current_user.person.id, :conversation_id => params[:conversation_id]}).first end def create @@ -18,7 +20,7 @@ class ConversationsController < ApplicationController @conversation = Conversation.create(params[:conversation]) - respond_with @conversation + redirect_to conversations_path(:conversation_id => @conversation.id) end def show @@ -26,7 +28,7 @@ class ConversationsController < ApplicationController :conversation_visibilities => {:person_id => current_user.person.id}).first if @conversation - respond_with @conversation + render :layout => false else redirect_to conversations_path end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 148032fc9..2dac50dda 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -14,13 +14,13 @@ class MessagesController < ApplicationController :conversation_visibilities => {:person_id => current_user.person.id}).first if cnv - message = Message.new(:conversation_id => cnv.id, :text => params[:text], :author => current_user.person) + message = Message.new(:conversation_id => cnv.id, :text => params[:message][:text], :author => current_user.person) if message.save - Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:text].length}") + Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:message][:text].length}") Postzord::Dispatch.new(current_user, message).post - respond_with cnv + redirect_to conversations_path(:conversation_id => cnv.id) else render :nothing => true, :status => 406 end diff --git a/app/views/conversations/_conversation.haml b/app/views/conversations/_conversation.haml new file mode 100644 index 000000000..cac2ddf08 --- /dev/null +++ b/app/views/conversations/_conversation.haml @@ -0,0 +1,20 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +.stream_element.conversation{:data=>{:guid=>conversation.id}} + - if conversation.author.owner_id == current_user.id + .right.hidden.controls + /= link_to image_tag('deletelabel.png'), status_message_path(conversation), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete", :title => t('delete') + + %strong + = person_link(conversation.author) + + .subject + = conversation.subject + .message + = "#{conversation.messages.first.text[0..20]}..." + + .info + /%span.timeago= link_to(how_long_ago(conversation), status_message_path(conversation)) + diff --git a/app/views/conversations/_show.haml b/app/views/conversations/_show.haml new file mode 100644 index 000000000..66c59b195 --- /dev/null +++ b/app/views/conversations/_show.haml @@ -0,0 +1,22 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +.conversation_participants + .right + = link_to t('delete'), conversation_conversation_visibility_path(conversation), :method => 'delete', :confirm => t('are_you_sure') + - for participant in conversation.participants + = person_image_link(participant) + +.stream + = render :partial => 'messages/message', :collection => conversation.messages + + .stream_element.new_message + = owner_image_tag + + .content + = form_for [conversation, Message.new] do |message| + = message.text_area :text, :rows => 5 + .right + = message.submit 'Reply' + = link_to 'Cancel', '#' diff --git a/app/views/conversations/index.haml b/app/views/conversations/index.haml index 71a8167be..8ea7f5d71 100644 --- a/app/views/conversations/index.haml +++ b/app/views/conversations/index.haml @@ -2,29 +2,36 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. +:javascript + $(document).ready(function(){ + $('.conversation', '.stream').click(function(){ + var conversationGuid = $(this).attr('data-guid'); + $.get("conversations/"+conversationGuid, function(data){ + $('#conversation_show').html(data); + }); + }); + }); -.span-12.last - - %h2 - .right - = link_to 'new message', new_conversation_path, :class => 'button' - Inbox - +.span-24.last{:style => 'position:relative;'} + .right + = link_to 'New Message', new_conversation_path, :class => 'button' + = link_to 'Inbox', conversations_path, :class => 'button' + = link_to 'Sent', conversations_path, :class => 'button' + %br + %br + %br +.span-6.append-1 - if @conversations.count > 0 .stream - - for conversation in @conversations - .stream_element - .right - = link_to image_tag('deletelabel.png'), conversation_conversation_visibility_path(conversation), :method => 'delete', :confirm => t('are_you_sure') - - .from - = conversation.messages.last.author.name - %p - = link_to conversation.subject, conversation - %p - = link_to conversation.messages.last, conversation - + = render :partial => 'conversations/conversation', :collection => @conversations - else %i You have no messages + +#conversation_show.span-17.last + - if @conversation + = render 'conversations/show', :conversation => @conversation + - else + %i + no conversation selected diff --git a/app/views/conversations/new.haml b/app/views/conversations/new.haml index 5d13de323..e61d21678 100644 --- a/app/views/conversations/new.haml +++ b/app/views/conversations/new.haml @@ -9,16 +9,15 @@ = form_for Conversation.new do |conversation| %h4 to - = text_field_tag "private_message[contact_ids]" + = text_field_tag "conversation[contact_ids]" %h4 subject = conversation.text_field :subject - = fields_for :message do |message| - %h4 - message - = message.text_area :text, :rows => 5 + %h4 + message + = text_area_tag "conversation[text]", '', :rows => 5 = conversation.submit :send = link_to 'cancel', conversations_path diff --git a/app/views/conversations/show.haml b/app/views/conversations/show.haml index 99a8989fa..b5d871dfc 100644 --- a/app/views/conversations/show.haml +++ b/app/views/conversations/show.haml @@ -2,31 +2,4 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -= link_to 'back', conversations_path - -%br -%br -%br -%br - - -- for participant in @conversation.participants - = participant.name - -- for message in @conversation.messages - %h4 - from - = message.author.name - - %br - %br - - %h4 - message - = message.text - - %hr - -= link_to t('delete'), conversation_conversation_visibility_path(@conversation), :method => 'delete', :confirm => t('are_you_sure') - - += render 'show', :conversation => @conversation diff --git a/app/views/messages/_message.haml b/app/views/messages/_message.haml new file mode 100644 index 000000000..bfcf56a4c --- /dev/null +++ b/app/views/messages/_message.haml @@ -0,0 +1,17 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +.stream_element{:data=>{:guid=>message.id}} + = person_image_link(message.author, :size => :thumb_small) + + .right + %span.timeago= link_to(how_long_ago(message), status_message_path(message)) + + .content + %strong + = person_link(message.author) + + .message + = message.text + diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 4da04ce86..77e4b4022 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -38,9 +38,7 @@ namespace :db do puts "Purging the database for #{Rails.env}..." - # Specifiy what models to remove - # No! Drop the fucking database. - MongoMapper::connection.drop_database(MongoMapper::database.name) + Rake::Task['db:rebuild'].invoke puts 'Deleting tmp folder...' `rm -rf #{File.dirname(__FILE__)}/../../public/uploads/*` @@ -51,17 +49,10 @@ namespace :db do puts "Resetting the database for #{Rails.env}".upcase Rake::Task['db:purge'].invoke - Rake::Task['db:seed:dev'].invoke + Rake::Task['db:seed'].invoke puts "Success!" end - task :reset_dev do - puts "making a new base user" - Rake::Task['db:purge'].invoke - Rake::Task['db:seed:dev'].invoke - puts "you did it!" - end - desc "Purge database and then add the first user" task :first_user, :username, :password, :email do |t, args| Rake::Task['db:purge'].invoke diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 2af5d5534..59eb806d9 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -2480,4 +2480,31 @@ ul.show_comments :position static .public_icon, .service_icon - :cursor pointer \ No newline at end of file + :cursor pointer + +.stream_element + .subject + :font + :weight bold + +.conversation_participants + :background + :color #eee + :border + :bottom 1px solid #999 + :padding 1em + +.stream_element.new_message + :border + :top 1px solid #999 + :bottom none + &:hover + :border + :bottom none + textarea + :margin 0 + :bottom 0.5em + :width 100% + .right + :right -11px + diff --git a/spec/controllers/messages_controller_spec.rb b/spec/controllers/messages_controller_spec.rb index 45f7d31e7..8c9b777bb 100644 --- a/spec/controllers/messages_controller_spec.rb +++ b/spec/controllers/messages_controller_spec.rb @@ -21,19 +21,18 @@ describe MessagesController do before do @create_hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], :subject => "cool stuff", :text => "stuff"} - end context "on my own post" do before do @cnv = Conversation.create(@create_hash) - @message_hash = {:conversation_id => @cnv.id, :text => "here is something else"} + @message_hash = {:conversation_id => @cnv.id, :message => {:text => "here is something else"}} end - it 'responds to format js' do + it 'redirects to conversation' do lambda{ post :create, @message_hash }.should change(Message, :count).by(1) - response.code.should == '201' - response.should redirect_to(@cnv) + response.code.should == '302' + response.should redirect_to(conversations_path(:conversation_id => @cnv)) end end @@ -41,17 +40,18 @@ describe MessagesController do before do @create_hash[:author] = @user2.person @cnv = Conversation.create(@create_hash) - @message_hash = {:conversation_id => @cnv.id, :text => "here is something else"} + @message_hash = {:conversation_id => @cnv.id, :message => {:text => "here is something else"}} end it 'comments' do post :create, @message_hash - response.code.should == '201' + response.code.should == '302' + response.should redirect_to(conversations_path(:conversation_id => @cnv)) end it "doesn't overwrite author_id" do new_user = Factory.create(:user) @message_hash[:author_id] = new_user.person.id.to_s post :create, @message_hash - Message.find_by_text(@message_hash[:text]).author_id.should == @user1.person.id + Message.find_by_text(@message_hash[:message][:text]).author_id.should == @user1.person.id end it "doesn't overwrite id" do old_message = Message.create(:text => "hello", :author_id => @user1.person.id, :conversation_id => @cnv.id) @@ -63,11 +63,11 @@ describe MessagesController do context 'on a post from a stranger' do before do @create_hash[:author] = eve.person + @create_hash[:participant_ids] = [eve.person.id, bob.person.id] @cnv = Conversation.create(@create_hash) - @message_hash = {:conversation_id => @cnv.id, :text => "here is something else"} + @message_hash = {:conversation_id => @cnv.id, :message => {:text => "here is something else"}} end it 'posts no comment' do - Message.should_not_receive(:new) post :create, @message_hash response.code.should == '406' end