Class: TasksController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TasksController
- Defined in:
- app/controllers/tasks_controller.rb
Overview
Copyright © 2008-2013 Michael Dvorkin and contributors.
Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php
Instance Method Summary collapse
-
#complete ⇒ Object
PUT /tasks/1/complete —————————————————————————-.
-
#create ⇒ Object
POST /tasks —————————————————————————-.
-
#destroy ⇒ Object
DELETE /tasks/1 —————————————————————————-.
-
#edit ⇒ Object
GET /tasks/1/edit AJAX —————————————————————————-.
-
#filter ⇒ Object
Ajax request to filter out a list of tasks.
-
#index ⇒ Object
GET /tasks —————————————————————————-.
-
#new ⇒ Object
GET /tasks/new —————————————————————————-.
-
#show ⇒ Object
GET /tasks/1 —————————————————————————-.
-
#uncomplete ⇒ Object
PUT /tasks/1/uncomplete —————————————————————————-.
-
#update ⇒ Object
PUT /tasks/1 —————————————————————————-.
Methods inherited from ApplicationController
Instance Method Details
#complete ⇒ Object
PUT /tasks/1/complete
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/tasks_controller.rb', line 126 def complete @task = Task.tracked_by(current_user).find(params[:id]) @task&.update_attributes(completed_at: Time.now, completed_by: current_user.id) # Make sure bucket's div gets hidden if it's the last completed task in the bucket. if Task.bucket_empty?(params[:bucket], current_user) @empty_bucket = params[:bucket] end unless params[:bucket].blank? respond_with(@task) end |
#create ⇒ Object
POST /tasks
71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/tasks_controller.rb', line 71 def create @view = view @task = Task.new(task_params) # NOTE: we don't display validation messages for tasks. respond_with(@task) do |_format| if @task.save if called_from_index_page? end end end |
#destroy ⇒ Object
DELETE /tasks/1
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/tasks_controller.rb', line 110 def destroy @view = view @task = Task.tracked_by(current_user).find(params[:id]) @task.destroy # Make sure bucket's div gets hidden if we're deleting last task in the bucket. if Task.bucket_empty?(params[:bucket], current_user, @view) @empty_bucket = params[:bucket] end if called_from_index_page? respond_with(@task) end |
#edit ⇒ Object
GET /tasks/1/edit AJAX
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/tasks_controller.rb', line 55 def edit @view = view @task = Task.tracked_by(current_user).find(params[:id]) @bucket = Setting.unroll(:task_bucket)[1..-1] << [t(:due_specific_date, default: 'On Specific Date...'), :specific_time] @category = Setting.unroll(:task_category) @asset = @task.asset if @task.asset_id? if params[:previous].to_s =~ /(\d+)\z/ @previous = Task.tracked_by(current_user).find_by_id(Regexp.last_match[1]) || Regexp.last_match[1].to_i end respond_with(@task) end |
#filter ⇒ Object
Ajax request to filter out a list of tasks. AJAX
160 161 162 163 164 165 166 167 168 169 170 |
# File 'app/controllers/tasks_controller.rb', line 160 def filter @view = view update_session do |filters| if params[:checked].true? filters << params[:filter] else filters.delete(params[:filter]) end end end |
#index ⇒ Object
GET /tasks
15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/tasks_controller.rb', line 15 def index @view = view @tasks = Task.find_all_grouped(current_user, @view) respond_with @tasks do |format| format.xls { render layout: 'header' } format.csv { render csv: @tasks.map(&:second).flatten } format.xml { render xml: @tasks, except: [:subscribed_users] } end end |
#new ⇒ Object
GET /tasks/new
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/tasks_controller.rb', line 35 def new @view = view @task = Task.new @bucket = Setting.unroll(:task_bucket)[1..-1] << [t(:due_specific_date, default: 'On Specific Date...'), :specific_time] @category = Setting.unroll(:task_category) if params[:related] model, id = params[:related].split(/_(\d+)/) if = model.classify.constantize.my(current_user).find_by_id(id) instance_variable_set("@asset", ) else (model) && return end end respond_with(@task) end |
#show ⇒ Object
GET /tasks/1
28 29 30 31 |
# File 'app/controllers/tasks_controller.rb', line 28 def show @task = Task.tracked_by(current_user).find(params[:id]) respond_with(@task) end |
#uncomplete ⇒ Object
PUT /tasks/1/uncomplete
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/controllers/tasks_controller.rb', line 141 def uncomplete @task = Task.tracked_by(current_user).find(params[:id]) @task&.update_attributes(completed_at: nil, completed_by: nil) # Make sure bucket's div gets hidden if we're deleting last task in the bucket. if Task.bucket_empty?(params[:bucket], current_user, @view) @empty_bucket = params[:bucket] end respond_with(@task) end |
#update ⇒ Object
PUT /tasks/1
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/controllers/tasks_controller.rb', line 84 def update @view = view @task = Task.tracked_by(current_user).find(params[:id]) @task_before_update = @task.dup @task_before_update.bucket = if @task.due_at && (@task.due_at < Date.today.to_time) "overdue" else @task.computed_bucket end respond_with(@task) do |_format| if @task.update_attributes(task_params) @task.bucket = @task.computed_bucket if called_from_index_page? if Task.bucket_empty?(@task_before_update.bucket, current_user, @view) @empty_bucket = @task_before_update.bucket end end end end end |