Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add activity

  • Loading branch information...
commit f6d05b515da70fabd0e07ade7c59830ce3242944 1 parent b931304
@amesel amesel authored
Showing with 289 additions and 29 deletions.
  1. +3 −0  app/assets/javascripts/activities.js.coffee
  2. +3 −0  app/assets/stylesheets/activities.css.scss
  3. +76 −0 app/controllers/activities_controller.rb
  4. +0 −1  app/controllers/tasks_controller.rb
  5. +2 −0  app/helpers/activities_helper.rb
  6. +6 −0 app/models/activity.rb
  7. +1 −0  app/models/task.rb
  8. +1 −1  app/models/user.rb
  9. +7 −0 app/views/activities/_activity.html.haml
  10. +25 −0 app/views/activities/_form.html.erb
  11. +2 −0  app/views/activities/create.js.erb
  12. +1 −0  app/views/activities/destroy.js.erb
  13. +6 −0 app/views/activities/edit.html.erb
  14. +25 −0 app/views/activities/index.html.erb
  15. +5 −0 app/views/activities/new.html.erb
  16. +15 −0 app/views/activities/show.html.erb
  17. +4 −20 app/views/parties/show.html.haml
  18. +10 −0 app/views/tasks/_task.html.haml
  19. +1 −1  app/views/tasks/create.js.erb
  20. +1 −1  app/views/tasks/destroy.js.erb
  21. +1 −1  app/views/tasks/finish.js.erb
  22. +1 −1  app/views/tasks/hold.js.erb
  23. +1 −1  app/views/tasks/redo.js.erb
  24. +1 −1  app/views/tasks/start.js.erb
  25. +2 −0  config/routes.rb
  26. +11 −0 db/migrate/20120519100019_create_activities.rb
  27. +9 −1 db/schema.rb
  28. +9 −0 test/fixtures/activities.yml
  29. +49 −0 test/functional/activities_controller_test.rb
  30. +7 −0 test/unit/activity_test.rb
  31. +4 −0 test/unit/helpers/activities_helper_test.rb
View
3  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/
View
3  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/
View
76 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
View
1  app/controllers/tasks_controller.rb
@@ -70,7 +70,6 @@ def create
# # DELETE /tasks/1.json
def destroy
@task = current_user.tasks.find(params[:id])
- @party = @task.party
@task.destroy
respond_with @task
end
View
2  app/helpers/activities_helper.rb
@@ -0,0 +1,2 @@
+module ActivitiesHelper
+end
View
6 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
View
1  app/models/task.rb
@@ -2,6 +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
validates :content, :user_id, :presence => true
View
2  app/models/user.rb
@@ -6,6 +6,7 @@ class User < ActiveRecord::Base
# has_many :invited_parties, :through => :joins
has_many :invited_parties, :through => :joins, :source => :party
has_many :tasks
+ has_many :activities
validates :name, :presence => true
validates :uid, :uniqueness => {:scope => :provider}
@@ -18,5 +19,4 @@ def self.create_with_omniauth(auth)
user.image = auth["info"]["image"]
end
end
-
end
View
7 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
View
25 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 %>
View
2  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()
View
1  app/views/activities/destroy.js.erb
@@ -0,0 +1 @@
+$('#<%= dom_id(@activity) %>').remove().fadeOut()
View
6 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 %>
View
25 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 %>
View
5 app/views/activities/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New activity</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', activities_path %>
View
15 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 %>
View
24 app/views/parties/show.html.haml
@@ -50,42 +50,26 @@
.label
%h2 Current
.doing
- %ul
+ %ul.tasks
- task = member.tasks.current(@party.id).first
- if task
= render task
- else
%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
.label
%h2 Backlog
- if user_signed_in? && current_user == member
- .add.close
- %a{:href => ""} close
+ .add
= form_for [@party, member.tasks.build], :remote => true do |f|
= f.text_area :content, :rows => 3, :cols => 30
= f.submit
- .add
- %a{:href => ""} new task
- %ul
+ %ul.tasks
= render member.tasks.backlog(@party.id)
.done
.label
%h2 Done
-
- %ul
+ %ul.tasks
= render member.tasks.done(@party.id)
View
10 app/views/tasks/_task.html.haml
@@ -28,3 +28,13 @@
- when "done"
- if user_signed_in? && current_user == task.user
%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
View
2  app/views/tasks/create.js.erb
@@ -1,2 +1,2 @@
$('#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()
View
2  app/views/tasks/destroy.js.erb
@@ -1 +1 @@
-$('#<%= dom_id(@task) %>').remove().fadeOut()
+$('#<%= dom_id(@task) %>').remove().fadeOut()
View
2  app/views/tasks/finish.js.erb
@@ -1,2 +1,2 @@
$('#<%= 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()
View
2  app/views/tasks/hold.js.erb
@@ -1,2 +1,2 @@
$('#<%= 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()
View
2  app/views/tasks/redo.js.erb
@@ -1,2 +1,2 @@
$('#<%= 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()
View
2  app/views/tasks/start.js.erb
@@ -2,5 +2,5 @@
alert("You have a current task!")
<% else %>
$('#<%= 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 %>
View
2  config/routes.rb
@@ -1,5 +1,7 @@
Frontline::Application.routes.draw do
+ resources :activities
+
resources :joins
resources :parties do
View
11 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
View
10 db/schema.rb
@@ -11,7 +11,15 @@
#
# 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|
t.integer "user_id"
View
9 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
View
49 test/functional/activities_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class ActivitiesControllerTest < ActionController::TestCase
+ setup do
+ @activity = activities(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:activities)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create activity" do
+ assert_difference('Activity.count') do
+ post :create, activity: { content: @activity.content, user_id: @activity.user_id }
+ end
+
+ assert_redirected_to activity_path(assigns(:activity))
+ end
+
+ test "should show activity" do
+ get :show, id: @activity
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @activity
+ assert_response :success
+ end
+
+ test "should update activity" do
+ put :update, id: @activity, activity: { content: @activity.content, user_id: @activity.user_id }
+ assert_redirected_to activity_path(assigns(:activity))
+ end
+
+ test "should destroy activity" do
+ assert_difference('Activity.count', -1) do
+ delete :destroy, id: @activity
+ end
+
+ assert_redirected_to activities_path
+ end
+end
View
7 test/unit/activity_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ActivityTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/activities_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ActivitiesHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.