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 —————————————————————————-.
-
#versions ⇒ Object
GET /tasks/1/versions AJAX —————————————————————————-.
Methods inherited from ApplicationController
Instance Method Details
#complete ⇒ Object
PUT /tasks/1/complete
132 133 134 135 136 137 138 139 140 141 |
# File 'app/controllers/tasks_controller.rb', line 132 def complete @task = Task.tracked_by(current_user).find(params[:id]) @task&.update(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. @empty_bucket = params[:bucket] if Task.bucket_empty?(params[:bucket], current_user) unless params[:bucket].blank? respond_with(@task) end |
#create ⇒ Object
POST /tasks
78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/tasks_controller.rb', line 78 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
118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/tasks_controller.rb', line 118 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. @empty_bucket = params[:bucket] if Task.bucket_empty?(params[:bucket], current_user, @view) if called_from_index_page? respond_with(@task) end |
#edit ⇒ Object
GET /tasks/1/edit AJAX
64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/tasks_controller.rb', line 64 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? @previous = Task.tracked_by(current_user).find_by_id(detect_previous_id) || detect_previous_id if detect_previous_id respond_with(@task) end |
#filter ⇒ Object
Ajax request to filter out a list of tasks. AJAX
162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/controllers/tasks_controller.rb', line 162 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
14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/tasks_controller.rb', line 14 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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/tasks_controller.rb', line 44 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
27 28 29 30 31 32 |
# File 'app/controllers/tasks_controller.rb', line 27 def show @task = Task.tracked_by(current_user).find(params[:id]) @comment = Comment.new @timeline = timeline(@task) respond_with(@task) end |
#uncomplete ⇒ Object
PUT /tasks/1/uncomplete
145 146 147 148 149 150 151 152 153 154 |
# File 'app/controllers/tasks_controller.rb', line 145 def uncomplete @task = Task.tracked_by(current_user).find(params[:id]) @task&.update(completed_at: nil, completed_by: nil) # Make sure bucket's div gets hidden if we're deleting last task in the bucket. @empty_bucket = params[:bucket] if Task.bucket_empty?(params[:bucket], current_user, @view) respond_with(@task) end |
#update ⇒ Object
PUT /tasks/1
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/tasks_controller.rb', line 91 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(task_params) @task.bucket = @task.computed_bucket if called_from_index_page? @empty_bucket = @task_before_update.bucket if Task.bucket_empty?(@task_before_update.bucket, current_user, @view) end else @bucket = Setting.unroll(:task_bucket)[1..-1] << [t(:due_specific_date, default: 'On Specific Date...'), :specific_time] @category = Setting.unroll(:task_category) end end end |
#versions ⇒ Object
GET /tasks/1/versions AJAX
36 37 38 39 40 |
# File 'app/controllers/tasks_controller.rb', line 36 def versions @task = Task.tracked_by(current_user).find(params[:id]) @versions = @task.versions.order('created_at DESC') respond_with(@versions) end |