Permalink
Browse files

Add task help, destroy, redo

  • Loading branch information...
1 parent b22db12 commit 70b081e657aa3b3985a52bfaaea2749953be0243 @amesel amesel committed May 19, 2012
@@ -68,15 +68,12 @@ def create
#
# # DELETE /tasks/1
# # DELETE /tasks/1.json
- # def destroy
- # @task = Task.find(params[:id])
- # @task.destroy
- #
- # respond_to do |format|
- # format.html { redirect_to tasks_url }
- # format.json { head :no_content }
- # end
- # end
+ def destroy
+ @task = current_user.tasks.find(params[:id])
+ @party = @task.party
+ @task.destroy
+ respond_with @task
+ end
def start
@task = current_user.tasks.find(params[:id])
@@ -105,4 +102,20 @@ def finish
@party = @task.party
respond_with @task
end
+
+ def help
+ @task = current_user.tasks.find(params[:id])
+ @party = @task.party
+ @task.toggle!(:help)
+ respond_with @task
+ end
+
+ def redo
+ @task = current_user.tasks.find(params[:id])
+ @task.state = "backlog"
+ @task.finished_at = nil
+ @task.save
+ @party = @task.party
+ respond_with @task
+ end
end
@@ -1,2 +1,5 @@
module ApplicationHelper
+ def nl2br(str)
+ sanitize str.gsub(/\r\n|\r|\n/, "<br />"), tags: "br"
+ end
end
@@ -1,2 +1,5 @@
module TasksHelper
+ def help_message(task)
+ task.help ? "solve" : "help"
+ end
end
View
@@ -1,6 +1,6 @@
# encoding: utf-8
class Join < ActiveRecord::Base
- attr_accessible :party_id, :user_id, :state, :end_hour, :end_min
+ attr_accessible :party_id, :user_id, :state, :end_hour, :end_min, :help
belongs_to :party
belongs_to :user
View
@@ -1,14 +1,12 @@
class Party < ActiveRecord::Base
- attr_accessible :description, :end_at, :name, :user_id, :member_tokens
+ attr_accessible :description, :name, :user_id, :member_tokens
has_many :joins
has_many :members, :through => :joins, :source => :user
belongs_to :user
attr_reader :member_tokens
- validates :name, :end_at, :presence => true
-
def member_tokens=(ids)
self.member_ids = ids.split(",")
end
@@ -1,6 +1,8 @@
= content_tag_for :li, task do
%p
- = task.content
+ = nl2br task.content
+ .helpme
+ = "HELP ME!!!" if task.help
- if task.state == "done"
%p
working time
@@ -16,7 +18,11 @@
%li= link_to "hold", hold_party_task_path(@party, task), :remote => true
%li= link_to "finish", finish_party_task_path(@party, task), :remote => true
%p.help
- %a{:href => ""} HELP
+ = link_to help_message(task), help_party_task_path(@party, task), :remote => true
- when "backlog"
- if user_signed_in? && current_user == task.user
%p= link_to "start", start_party_task_path(@party, task), :remote => true
+ %p= link_to "delete", party_task_path(@party, task), :method => :delete, :remote => true
+ - when "done"
+ - if user_signed_in? && current_user == task.user
+ %p= link_to "redo", redo_party_task_path(@party, task), :remote => true
@@ -0,0 +1 @@
+$('#<%= dom_id(@task) %>').remove().fadeOut()
@@ -0,0 +1,6 @@
+<% if @task.help %>
+$('#<%= dom_id(@task) %> .helpme').html("HELP ME!!!")
+<% else %>
+$('#<%= dom_id(@task) %> .helpme').empty()
+<% end %>
+$('#<%= dom_id(@task) %> .help a').html("<%= help_message(@task) %>")
@@ -0,0 +1,2 @@
+$('#<%= dom_id(@task) %>').remove().fadeOut()
+$('#<%= dom_id(current_user) %> .backlog ul').prepend("<%= j(render @task) %>").fadeIn()
View
@@ -4,9 +4,11 @@
resources :parties do
resources :tasks do
- get "start", :on => :member
- get "hold", :on => :member
+ get "start", :on => :member
+ get "hold", :on => :member
get "finish", :on => :member
+ get "help", :on => :member
+ get "redo", :on => :member
end
end
@@ -3,7 +3,6 @@ def change
create_table :parties do |t|
t.string :name
t.text :description
- t.datetime :end_at
t.integer :user_id
t.timestamps
@@ -4,6 +4,10 @@ def change
t.integer :user_id
t.integer :party_id
t.string :state, default: "chore"
+ t.datetime :started_at
+ t.datetime :finished_at
+ t.integer :end_hour, :default => 0
+ t.integer :end_min, :default => 0
t.timestamps
end
@@ -5,6 +5,7 @@ def change
t.integer :party_id
t.text :content
t.string :state
+ t.boolean :help, dafault: false
t.datetime :started_at
t.datetime :finished_at
@@ -1,8 +0,0 @@
-class AddFinishedAtToJoins < ActiveRecord::Migration
- def change
- add_column :joins, :started_at, :datetime
- add_column :joins, :finished_at, :datetime
- add_column :joins, :end_hour, :integer, default: 0
- add_column :joins, :end_min, :integer, default: 0
- end
-end
View
@@ -11,24 +11,23 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120512083000) do
+ActiveRecord::Schema.define(:version => 20120429045006) do
create_table "joins", :force => true do |t|
t.integer "user_id"
t.integer "party_id"
t.string "state", :default => "chore"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
t.datetime "started_at"
t.datetime "finished_at"
t.integer "end_hour", :default => 0
t.integer "end_min", :default => 0
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
create_table "parties", :force => true do |t|
t.string "name"
t.text "description"
- t.datetime "end_at"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
@@ -39,6 +38,7 @@
t.integer "party_id"
t.text "content"
t.string "state"
+ t.boolean "help"
t.datetime "started_at"
t.datetime "finished_at"
t.datetime "created_at", :null => false
View
@@ -6,10 +6,10 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
-User.create(name: 'yoshida naoki')
+User.create(name: 'yoshida')
+User.create(name: 'machida')
User.create(name: 'yoshinao0330')
-User.create(name: 'frasel')
-Party.create(name: 'p4d hackason #1', end_at: Time.now.to_date.tomorrow)
-Party.create(name: 'p4d hackason #2', end_at: Time.now.to_date.tomorrow)
-Party.create(name: 'p4d hackason #3', end_at: Time.now.to_date.tomorrow)
+Party.create(name: 'p4d hackason #1')
+Party.create(name: 'p4d hackason #2')
+Party.create(name: 'p4d hackason #3')

0 comments on commit 70b081e

Please sign in to comment.