Skip to content

Commit

Permalink
Associate actions with people and notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Karim Husseiny committed May 13, 2012
1 parent d8e8f53 commit d9c7e95
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 63 deletions.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/dinobot.css
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@ info List
background-color: rgba(0, 0, 0, 0.1);
background-color: transparent;
}
.post-actions ul{
width:360px;
}
.post-actions ul li{
float:right;
}
.post-actions .nav-pills .active > a, .post-actions .nav-pills .active > a:hover{
color: #344;
}
Expand Down
16 changes: 14 additions & 2 deletions app/controllers/actions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ class ActionsController < ApplicationController
before_filter :authenticate_user


def update
def like
@action = Action.find(params[:id])
@action.upvote_count = @action.upvote_count + 1
@action.people << @current_person
if @action.save && params[:target_person_id] != @current_person.id.to_s
Notification.create(:target_type => 'Action',
:target_url => "",
:person_id => params[:target_person_id],
:notifier_id => @current_person.id)
end
redirect_to :back
end

def unlike
@action = Action.find(params[:id])
@action.people.delete(@current_person)
@action.save
redirect_to :back
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create
@album= Album.create params[:album]
@album.person = @current_person
if @album.save
Action.create(:target_type => 'Album', :target_id => @album.id, :upvote_count => 0)
Action.create(:target_type => 'Album', :target_id => @album.id)
redirect_to albums_path
else
render text: "Something worng happen while Creating New Album"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def create
@comment = Comment.new({:content => params[:content] ,:commentary_id => params[:commentary_id], :commentary_type => params[:commentary_type] })
@comment.person_id = User.find(session[:user_id]).person.id
if @comment.save
Action.create(:target_type => 'comment', :target_id => @comment.id, :upvote_count => 0)
Action.create(:target_type => 'comment', :target_id => @comment.id)
if params[:person_id] != @comment.person_id.to_s
Notification.create(:target_type => 'Comment',
:target_url => "/#{@comment.commentary_type}s/show/#{@comment.commentary_id}/##{@comment.id}",
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create
@album.cover_url = @image.image.url
end
if @image.save
Action.create(:target_type => 'Image', :target_id => @image.id, :upvote_count => 0)
Action.create(:target_type => 'Image', :target_id => @image.id)
redirect_to album_path(@image.album_id)
else
render text: "Something worng happen while Uploading"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def create
@post.post_type= "status"
@post.person_id = @current_user.person.id
if @post.save
Action.create(:target_type => 'Post', :target_id => @post.id, :upvote_count => 0)
Action.create(:target_type => 'Post', :target_id => @post.id)
redirect_to :back
else
render text: "Something worng happen while posting"
Expand Down
5 changes: 2 additions & 3 deletions app/models/action.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Action < ActiveRecord::Base
belongs_to :target, :polymorphic => true
has_many :action_items
has_many :people, :through => :action_items

has_many :actors
has_many :people, :through => :actors
end
2 changes: 1 addition & 1 deletion app/models/action_item.rb → app/models/actor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ActionItem < ActiveRecord::Base
class Actor < ActiveRecord::Base
belongs_to :person
belongs_to :action
end
4 changes: 2 additions & 2 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Person < ActiveRecord::Base
has_many :groups, :through => :group_memberships
has_many :group_admins
has_many :groups, :through => :group_admins
has_many :action_items
has_many :actions, :through => :action_items
has_many :actors
has_many :actions, :through => :actors
has_many :comments
has_many :aspect_memberships
has_many :aspects, :through => :aspect_memberships
Expand Down
46 changes: 31 additions & 15 deletions app/views/actions/_new.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
<%if target.class.name == "Comment"%>
<ul class="nav nav-pills pull-left">
<li>
<a href= "<%=upvote_path(target.action.id)%>">
<i class="icon-ok"></i>
Like
<sup class="comment-counts"><%=target.action.upvote_count%></sup>
</a>
<%if target.action.people.include?(@current_person)%>
<%=link_to({:controller => 'actions', :action => 'unlike', :id=>target.action.id, :target_person_id => target.person_id}) do %>
<i class="icon-ok"></i>
UnLike
<sup class="post-counts"><%=target.action.people.count%></sup>
<%end%>
<%else%>
<%=link_to({:controller => 'actions', :action => 'like', :id=>target.action.id, :target_person_id => target.person_id}) do %>
<i class="icon-ok"></i>
Like
<sup class="post-counts"><%=target.action.people.count%></sup>
<%end%>
<%end%>
</li>
</ul>
<%else%>
<ul class="nav nav-pills pull-right">
<li >
<a href= "<%=upvote_path(target.action.id)%>">
<i class="icon-ok"></i>
Like
<sup class="post-counts"><%=target.action.upvote_count%></sup>
<li>
<a href="#">
<i class="icon-share"></i>
Share
<sup class="post-counts">10</sup>
</a>
</li>
<li class="active">
Expand All @@ -26,11 +34,19 @@
</a>
</li>
<li>
<a href="#">
<i class="icon-share"></i>
Share
<sup class="post-counts">10</sup>
</a>
<%if target.action.people.include?(@current_person)%>
<%=link_to({:controller => 'actions', :action => 'unlike', :id=>target.action.id, :target_person_id => target.person_id}) do %>
<i class="icon-ok"></i>
UnLike
<sup class="post-counts"><%=target.action.people.count%></sup>
<%end%>
<%else%>
<%=link_to({:controller => 'actions', :action => 'like', :id=>target.action.id, :target_person_id => target.person_id}) do %>
<i class="icon-ok"></i>
Like
<sup class="post-counts"><%=target.action.people.count%></sup>
<%end%>
<%end%>
</li>
</ul>
<%end%>
2 changes: 1 addition & 1 deletion app/views/albums/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>

<div id="album-action" class="well post-actions">
<%= render({:partial => new_action_path, :locals => {:target => @album}})%>
<%= render({:partial => 'actions/new', :locals => {:target => @album}})%>
</div>
<div class ="album-comments">
<%= render({:partial => new_comment_path, :locals => {:commentary => @album}})%>
Expand Down
2 changes: 1 addition & 1 deletion app/views/comments/_new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<div class="row header-bottom">
<div class="span8 comment-actions pull-left ">
<%= render({:partial => new_action_path, :locals => {:target => comment}})%>
<%= render({:partial => 'actions/new', :locals => {:target => comment}})%>
</div> <!-- /comment-actions -->

<div class="span4 pull-right ">
Expand Down
2 changes: 1 addition & 1 deletion app/views/images/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
</div>
<div id="album-action" class="well post-actions">
<%= render({:partial => new_action_path, :locals => {:target => @image}})%>
<%= render({:partial => 'actions/new', :locals => {:target => @image}})%>
</div>
<div class ="album-comments">
<%= render({:partial => new_comment_path, :locals => {:commentary => @image}})%>
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/_new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</div>

<div class="span8 post-actions pull-right ">
<%= render({:partial => new_action_path, :locals => {:target => post}})%>
<%= render({:partial => 'actions/new', :locals => {:target => post}})%>
</div> <!-- /post-actions -->
</div><!-- / -->

Expand Down
4 changes: 1 addition & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
get "login" => "sessions#new", :as => "login"
get "signup" => "users#new", :as => "signup"

resources :users, :sessions, :posts, :comments, :actions, :people, :aspects, :conversations, :messages, :albums, :images
resources :users, :sessions, :posts, :comments, :people, :aspects, :conversations, :messages, :albums, :images

match ':controller/:action/:id/:person_id'

Expand All @@ -20,8 +20,6 @@
end

match ':username' => "profiles#show", :as => 'profile'

put 'actions/update/:id' => 'actions#update', :as => 'upvote'

match ':controller(/:action(/:id))(.:format)'

Expand Down
2 changes: 0 additions & 2 deletions db/migrate/20120306153617_create_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ class CreateActions < ActiveRecord::Migration
def change
create_table :actions do |t|
t.references :target, :polymorphic => true
t.integer :upvote_count
t.integer :downvote_count
t.timestamps
end
add_index :actions,:target_id
Expand Down
12 changes: 0 additions & 12 deletions db/migrate/20120306203229_create_action_items.rb

This file was deleted.

10 changes: 10 additions & 0 deletions db/migrate/20120306203229_create_actors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateActors < ActiveRecord::Migration
def change
create_table :actors do |t|
t.integer :action_id
t.integer :person_id
t.timestamps
end
add_index :actors, [:action_id,:person_id]
end
end
26 changes: 11 additions & 15 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,24 @@

ActiveRecord::Schema.define(:version => 20120510213303) do

create_table "action_items", :force => true do |t|
t.integer "action_id"
t.integer "person_id"
t.string "opinion"
t.string "vote"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "action_items", ["action_id", "person_id"], :name => "index_action_items_on_action_id_and_person_id"

create_table "actions", :force => true do |t|
t.integer "target_id"
t.string "target_type"
t.integer "upvote_count"
t.integer "downvote_count"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "actions", ["target_id"], :name => "index_actions_on_target_id"

create_table "actors", :force => true do |t|
t.integer "action_id"
t.integer "person_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "actors", ["action_id", "person_id"], :name => "index_actors_on_action_id_and_person_id"

create_table "albums", :force => true do |t|
t.string "title"
t.text "description"
Expand Down

0 comments on commit d9c7e95

Please sign in to comment.