Skip to content

Commit

Permalink
Modify activity to comment
Browse files Browse the repository at this point in the history
  • Loading branch information
amesel committed Jun 9, 2012
1 parent 3826a28 commit 067ce2f
Show file tree
Hide file tree
Showing 34 changed files with 197 additions and 197 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions app/assets/javascripts/parties.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ ->
$(".member .header .selectstate").toggle()
$(".doing").click ->
$(".current .actions").toggle()
$(".activities .label").click ->
$(".activities ul").toggle()
$(".comments .label").click ->
$(".comments ul").toggle()
$("#notice").css "left", $(window).width() / 2 - $("#notice").width() / 2
$("#notice").delay(2000).fadeOut "slow"
2 changes: 1 addition & 1 deletion app/assets/stylesheets/sass/parties.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ body.parties_show
+border-radius(0 4px 4px 0)
border-left: $label_text_shadow 1px solid

.activities
.comments
clear: both
+clearfix
.add
Expand Down
76 changes: 0 additions & 76 deletions app/controllers/activities_controller.rb

This file was deleted.

76 changes: 76 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
class CommentsController < ApplicationController
before_filter :authenticate_user!
respond_to :html, :json, :js

# GET /comments
# GET /comments.json
def index
@comments = Comment.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @comments }
end
end

# GET /comments/1
# GET /comments/1.json
def show
@comment = Comment.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @comment }
end
end

# GET /comments/new
# GET /comments/new.json
def new
@comment = Comment.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @comment }
end
end

# GET /comments/1/edit
def edit
@comment = Comment.find(params[:id])
end

# POST /comments
# POST /comments.json
def create
@comment = current_user.comments.build
@comment.task_id = params[:task_id]
@comment.content = params[:content]
@comment.save
respond_with @comment
end

# PUT /comments/1
# PUT /comments/1.json
def update
@comment = Comment.find(params[:id])

respond_to do |format|
if @comment.update_attributes(params[:comment])
format.html { redirect_to @comment, notice: 'Comment was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end

# DELETE /comments/1
# DELETE /comments/1.json
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
respond_with @comment
end
end
2 changes: 0 additions & 2 deletions app/helpers/activities_helper.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/helpers/comments_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CommentsHelper
end
2 changes: 1 addition & 1 deletion app/models/activity.rb → app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Activity < ActiveRecord::Base
class Comment < ActiveRecord::Base
attr_accessible :content, :task_id, :user_id

belongs_to :task
Expand Down
2 changes: 1 addition & 1 deletion app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Task < ActiveRecord::Base
attr_accessible :content, :finished_at, :started_at, :state, :user_id
belongs_to :user
belongs_to :party
has_many :activities
has_many :comments

validates :content, :user_id, :presence => true

Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class User < ActiveRecord::Base
has_many :joins
has_many :invited_parties, :through => :joins, :source => :party
has_many :tasks
has_many :activities
has_many :comments

validates :name, :presence => true
validates :password, :presence => true, :on => :create
Expand Down
7 changes: 0 additions & 7 deletions app/views/activities/_activity.html.haml

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/activities/create.js.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/activities/destroy.js.erb

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/activities/edit.html.erb

This file was deleted.

25 changes: 0 additions & 25 deletions app/views/activities/index.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/activities/new.html.erb

This file was deleted.

15 changes: 0 additions & 15 deletions app/views/activities/show.html.erb

This file was deleted.

7 changes: 7 additions & 0 deletions app/views/comments/_comment.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= content_tag_for :li, comment, :class => "comment" do
.icon
%a{:href => ""}
= image_tag comment.user.image_url(:thumb), alt: comment.user.name, class: "avatar size128"
%p= nl2br comment.content
- if user_signed_in? && current_user == comment.user
%p= link_to "delete", comment_path(comment), :method => :delete, :remote => true
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%= form_for(@activity) do |f| %>
<% if @activity.errors.any? %>
<%= form_for(@comment) do |f| %>
<% if @comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@activity.errors.count, "error") %> prohibited this activity from being saved:</h2>
<h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>

<ul>
<% @activity.errors.full_messages.each do |msg| %>
<% @comment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
Expand Down
2 changes: 2 additions & 0 deletions app/views/comments/create.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$('#<%= dom_id(@comment.task) %> textarea').val("")
$('#<%= dom_id(@comment.task) %> .comments ul').prepend("<%= j(render @comment) %>").fadeIn()
1 change: 1 addition & 0 deletions app/views/comments/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$('#<%= dom_id(@comment) %>').remove().fadeOut()
6 changes: 6 additions & 0 deletions app/views/comments/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing comment</h1>

<%= render 'form' %>
<%= link_to 'Show', @comment %> |
<%= link_to 'Back', comments_path %>
25 changes: 25 additions & 0 deletions app/views/comments/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h1>Listing comments</h1>

<table>
<tr>
<th>User</th>
<th>Content</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @comments.each do |comment| %>
<tr>
<td><%= comment.user_id %></td>
<td><%= comment.content %></td>
<td><%= link_to 'Show', comment %></td>
<td><%= link_to 'Edit', edit_comment_path(comment) %></td>
<td><%= link_to 'Destroy', comment, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Comment', new_comment_path %>
5 changes: 5 additions & 0 deletions app/views/comments/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New comment</h1>

<%= render 'form' %>
<%= link_to 'Back', comments_path %>
15 changes: 15 additions & 0 deletions app/views/comments/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p id="notice"><%= notice %></p>

<p>
<b>User:</b>
<%= @comment.user_id %>
</p>

<p>
<b>Content:</b>
<%= @comment.content %>
</p>


<%= link_to 'Edit', edit_comment_path(@comment) %> |
<%= link_to 'Back', comments_path %>
10 changes: 5 additions & 5 deletions app/views/tasks/_task.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

- if user_signed_in?
.add
= form_tag "/activities", :remote => true do
= form_tag "/comments", :remote => true do
= hidden_field_tag :task_id, task.id
= text_area_tag :content, nil, :rows => 3, :cols => 15, :id => "new_activity_#{dom_id(task)}"
= submit_tag "new activity"
.activities
= text_area_tag :content, nil, :rows => 3, :cols => 15, :id => "new_comment_#{dom_id(task)}"
= submit_tag "new comment"
.comments
%ul
= render task.activities
= render task.comments
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
# config.email_regexp = /\A[^@]+@[^@]+\z/

# ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this
# The time you want to timeout the user session without comment. After this
# time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes

Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
get "settings/edit" => "settings#edit"
put "settings/update" => "settings#update"

resources :activities
resources :comments

resources :joins

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CreateActivities < ActiveRecord::Migration
class CreateComments < ActiveRecord::Migration
def change
create_table :activities do |t|
create_table :comments do |t|
t.integer :task_id
t.integer :user_id
t.text :content
Expand Down
Loading

0 comments on commit 067ce2f

Please sign in to comment.