Skip to content

Commit

Permalink
Add activity
Browse files Browse the repository at this point in the history
  • Loading branch information
amesel committed May 19, 2012
1 parent b931304 commit f6d05b5
Show file tree
Hide file tree
Showing 31 changed files with 289 additions and 29 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/activities.js.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/activities.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the activities controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
76 changes: 76 additions & 0 deletions app/controllers/activities_controller.rb
@@ -0,0 +1,76 @@
class ActivitiesController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show]
respond_to :html, :json, :js

# GET /activities
# GET /activities.json
def index
@activities = Activity.all

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

# GET /activities/1
# GET /activities/1.json
def show
@activity = Activity.find(params[:id])

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

# GET /activities/new
# GET /activities/new.json
def new
@activity = Activity.new

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

# GET /activities/1/edit
def edit
@activity = Activity.find(params[:id])
end

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

# PUT /activities/1
# PUT /activities/1.json
def update
@activity = Activity.find(params[:id])

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

# DELETE /activities/1
# DELETE /activities/1.json
def destroy
@activity = Activity.find(params[:id])
@activity.destroy
respond_with @activity
end
end
1 change: 0 additions & 1 deletion app/controllers/tasks_controller.rb
Expand Up @@ -70,7 +70,6 @@ def create
# # DELETE /tasks/1.json # # DELETE /tasks/1.json
def destroy def destroy
@task = current_user.tasks.find(params[:id]) @task = current_user.tasks.find(params[:id])
@party = @task.party
@task.destroy @task.destroy
respond_with @task respond_with @task
end end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/activities_helper.rb
@@ -0,0 +1,2 @@
module ActivitiesHelper
end
6 changes: 6 additions & 0 deletions app/models/activity.rb
@@ -0,0 +1,6 @@
class Activity < ActiveRecord::Base
attr_accessible :content, :task_id, :user_id

belongs_to :task
belongs_to :user
end
1 change: 1 addition & 0 deletions app/models/task.rb
Expand Up @@ -2,6 +2,7 @@ class Task < ActiveRecord::Base
attr_accessible :content, :finished_at, :started_at, :state, :user_id attr_accessible :content, :finished_at, :started_at, :state, :user_id
belongs_to :user belongs_to :user
belongs_to :party belongs_to :party
has_many :activities


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


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


validates :name, :presence => true validates :name, :presence => true
validates :uid, :uniqueness => {:scope => :provider} validates :uid, :uniqueness => {:scope => :provider}
Expand All @@ -18,5 +19,4 @@ def self.create_with_omniauth(auth)
user.image = auth["info"]["image"] user.image = auth["info"]["image"]
end end
end end

end end
7 changes: 7 additions & 0 deletions app/views/activities/_activity.html.haml
@@ -0,0 +1,7 @@
= content_tag_for :li, activity, :class => "activity" do
.icon
%a{:href => ""}
= image_tag activity.user.image ? activity.user.image : "dummy.png", alt: activity.user.name, class: "avatar size128"
%p= nl2br activity.content
- if user_signed_in? && current_user == activity.user
%p= link_to "delete", activity_path(activity), :method => :delete, :remote => true
25 changes: 25 additions & 0 deletions app/views/activities/_form.html.erb
@@ -0,0 +1,25 @@
<%= form_for(@activity) do |f| %>
<% if @activity.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@activity.errors.count, "error") %> prohibited this activity from being saved:</h2>

<ul>
<% @activity.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :user_id %><br />
<%= f.number_field :user_id %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/activities/create.js.erb
@@ -0,0 +1,2 @@
$('#<%= dom_id(@activity.task) %> textarea').val("")
$('#<%= dom_id(@activity.task) %> .activities ul').prepend("<%= j(render @activity) %>").fadeIn()
1 change: 1 addition & 0 deletions app/views/activities/destroy.js.erb
@@ -0,0 +1 @@
$('#<%= dom_id(@activity) %>').remove().fadeOut()
6 changes: 6 additions & 0 deletions app/views/activities/edit.html.erb
@@ -0,0 +1,6 @@
<h1>Editing activity</h1>

<%= render 'form' %>
<%= link_to 'Show', @activity %> |
<%= link_to 'Back', activities_path %>
25 changes: 25 additions & 0 deletions app/views/activities/index.html.erb
@@ -0,0 +1,25 @@
<h1>Listing activities</h1>

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

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

<br />

<%= link_to 'New Activity', new_activity_path %>
5 changes: 5 additions & 0 deletions app/views/activities/new.html.erb
@@ -0,0 +1,5 @@
<h1>New activity</h1>

<%= render 'form' %>
<%= link_to 'Back', activities_path %>
15 changes: 15 additions & 0 deletions app/views/activities/show.html.erb
@@ -0,0 +1,15 @@
<p id="notice"><%= notice %></p>

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

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


<%= link_to 'Edit', edit_activity_path(@activity) %> |
<%= link_to 'Back', activities_path %>
24 changes: 4 additions & 20 deletions app/views/parties/show.html.haml
Expand Up @@ -50,42 +50,26 @@
.label .label
%h2 Current %h2 Current
.doing .doing
%ul %ul.tasks
- task = member.tasks.current(@party.id).first - task = member.tasks.current(@party.id).first
- if task - if task
= render task = render task
- else - else
%li.empty %li.empty
未選択 未選択
/
.activities
.add
%form{:name => "form1"}
%textarea#content.mceEditor{:cols => "15", :name => "content", :rows => "3", :tabindex => "2"}
%input#publish{:name => "publish", :type => "submit", :value => "POST"}
%ul
%li
.icon
%a{:href => ""}
%img.avatar.size128{:alt => "machida", :src => "https://si0.twimg.com/profile_images/525575524/14424182_2338889845_reasonably_small.jpg"}/
%p お仕事がんばってます。
.backlog .backlog
.label .label
%h2 Backlog %h2 Backlog
- if user_signed_in? && current_user == member - if user_signed_in? && current_user == member
.add.close .add
%a{:href => ""} close
= form_for [@party, member.tasks.build], :remote => true do |f| = form_for [@party, member.tasks.build], :remote => true do |f|
= f.text_area :content, :rows => 3, :cols => 30 = f.text_area :content, :rows => 3, :cols => 30
= f.submit = f.submit
.add %ul.tasks
%a{:href => ""} new task
%ul
= render member.tasks.backlog(@party.id) = render member.tasks.backlog(@party.id)


.done .done
.label .label
%h2 Done %h2 Done

%ul.tasks
%ul
= render member.tasks.done(@party.id) = render member.tasks.done(@party.id)
10 changes: 10 additions & 0 deletions app/views/tasks/_task.html.haml
Expand Up @@ -28,3 +28,13 @@
- when "done" - when "done"
- if user_signed_in? && current_user == task.user - if user_signed_in? && current_user == task.user
%p= link_to "redo", redo_party_task_path(@party, task), :remote => true %p= link_to "redo", redo_party_task_path(@party, task), :remote => true

- if user_signed_in?
.add
= form_tag "/activities", :remote => true do
= hidden_field_tag :task_id, task.id
= text_area_tag :content, nil, :rows => 3, :cols => 15
= submit_tag "new activity"
.activities
%ul
= render task.activities
2 changes: 1 addition & 1 deletion app/views/tasks/create.js.erb
@@ -1,2 +1,2 @@
$('#task_content').val("") $('#task_content').val("")
$('#<%= dom_id(current_user) %> .backlog ul').prepend("<%= j(render @task) %>").fadeIn() $('#<%= dom_id(current_user) %> .backlog ul.tasks').prepend("<%= j(render @task) %>").fadeIn()
2 changes: 1 addition & 1 deletion app/views/tasks/destroy.js.erb
@@ -1 +1 @@
$('#<%= dom_id(@task) %>').remove().fadeOut() $('#<%= dom_id(@task) %>').remove().fadeOut()
2 changes: 1 addition & 1 deletion app/views/tasks/finish.js.erb
@@ -1,2 +1,2 @@
$('#<%= dom_id(@task) %>').remove().fadeOut() $('#<%= dom_id(@task) %>').remove().fadeOut()
$('#<%= dom_id(current_user) %> .done ul').prepend("<%= j(render @task) %>").fadeIn() $('#<%= dom_id(current_user) %> .done ul.tasks').prepend("<%= j(render @task) %>").fadeIn()
2 changes: 1 addition & 1 deletion app/views/tasks/hold.js.erb
@@ -1,2 +1,2 @@
$('#<%= dom_id(@task) %>').remove().fadeOut() $('#<%= dom_id(@task) %>').remove().fadeOut()
$('#<%= dom_id(current_user) %> .backlog ul').prepend("<%= j(render @task) %>").fadeIn() $('#<%= dom_id(current_user) %> .backlog ul.tasks').prepend("<%= j(render @task) %>").fadeIn()
2 changes: 1 addition & 1 deletion app/views/tasks/redo.js.erb
@@ -1,2 +1,2 @@
$('#<%= dom_id(@task) %>').remove().fadeOut() $('#<%= dom_id(@task) %>').remove().fadeOut()
$('#<%= dom_id(current_user) %> .backlog ul').prepend("<%= j(render @task) %>").fadeIn() $('#<%= dom_id(current_user) %> .backlog ul.tasks').prepend("<%= j(render @task) %>").fadeIn()
2 changes: 1 addition & 1 deletion app/views/tasks/start.js.erb
Expand Up @@ -2,5 +2,5 @@
alert("You have a current task!") alert("You have a current task!")
<% else %> <% else %>
$('#<%= dom_id(@task) %>').remove().fadeOut() $('#<%= dom_id(@task) %>').remove().fadeOut()
$('#<%= dom_id(current_user) %> .current .doing ul').prepend("<%= j(render @task) %>").fadeIn() $('#<%= dom_id(current_user) %> .current .doing ul.tasks').prepend("<%= j(render @task) %>").fadeIn()
<% end %> <% end %>
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,5 +1,7 @@
Frontline::Application.routes.draw do Frontline::Application.routes.draw do


resources :activities

resources :joins resources :joins


resources :parties do resources :parties do
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20120519100019_create_activities.rb
@@ -0,0 +1,11 @@
class CreateActivities < ActiveRecord::Migration
def change
create_table :activities do |t|
t.integer :task_id
t.integer :user_id
t.text :content

t.timestamps
end
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,15 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.


ActiveRecord::Schema.define(:version => 20120429045006) do ActiveRecord::Schema.define(:version => 20120519100019) do

create_table "activities", :force => true do |t|
t.integer "task_id"
t.integer "user_id"
t.text "content"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end


create_table "joins", :force => true do |t| create_table "joins", :force => true do |t|
t.integer "user_id" t.integer "user_id"
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/activities.yml
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
user_id: 1
content: MyText

two:
user_id: 1
content: MyText

0 comments on commit f6d05b5

Please sign in to comment.