Commit a5b5066efab7d7c62093b3b346b002b8d48b497d
1 parent
ce1c8afe
Exists in
staging
and in
4 other branches
Store task tags on database using acts_as_taggable gem
Showing
2 changed files
with
24 additions
and
8 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
1 | class TasksController < MyProfileController | 1 | class TasksController < MyProfileController |
2 | 2 | ||
3 | protect 'perform_task', :profile | 3 | protect 'perform_task', :profile |
4 | - | 4 | + |
5 | def index | 5 | def index |
6 | @filter = params[:filter_type].blank? ? nil : params[:filter_type] | 6 | @filter = params[:filter_type].blank? ? nil : params[:filter_type] |
7 | @task_types = Task.pending_types_for(profile) | 7 | @task_types = Task.pending_types_for(profile) |
@@ -17,18 +17,33 @@ class TasksController < MyProfileController | @@ -17,18 +17,33 @@ class TasksController < MyProfileController | ||
17 | 17 | ||
18 | def close | 18 | def close |
19 | failed = {} | 19 | failed = {} |
20 | + save = false | ||
20 | 21 | ||
21 | if params[:tasks] | 22 | if params[:tasks] |
22 | params[:tasks].each do |id, value| | 23 | params[:tasks].each do |id, value| |
23 | decision = value[:decision] | 24 | decision = value[:decision] |
24 | - if request.post? && VALID_DECISIONS.include?(decision) && id && decision != 'skip' | 25 | + |
26 | + if value[:task].is_a?(Hash) && value[:task][:tag_list] | ||
27 | + | ||
25 | task = profile.find_in_all_tasks(id) | 28 | task = profile.find_in_all_tasks(id) |
26 | - begin | ||
27 | - task.update_attributes(value[:task]) | ||
28 | - task.send(decision) | ||
29 | - rescue Exception => ex | ||
30 | - message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" | ||
31 | - failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message] | 29 | + task.tag_list = value[:task][:tag_list] |
30 | + value[:task].delete('tag_list') | ||
31 | + | ||
32 | + save = true | ||
33 | + end | ||
34 | + | ||
35 | + if request.post? | ||
36 | + if VALID_DECISIONS.include?(decision) && id && decision != 'skip' | ||
37 | + task ||= profile.find_in_all_tasks(id) | ||
38 | + begin | ||
39 | + task.update_attributes(value[:task]) | ||
40 | + task.send(decision) | ||
41 | + rescue Exception => ex | ||
42 | + message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" | ||
43 | + failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message] | ||
44 | + end | ||
45 | + elsif save | ||
46 | + task.save! | ||
32 | end | 47 | end |
33 | end | 48 | end |
34 | end | 49 | end |
app/models/task.rb
@@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
12 | class Task < ActiveRecord::Base | 12 | class Task < ActiveRecord::Base |
13 | 13 | ||
14 | acts_as_having_settings :field => :data | 14 | acts_as_having_settings :field => :data |
15 | + acts_as_ordered_taggable | ||
15 | 16 | ||
16 | module Status | 17 | module Status |
17 | # the status of tasks just created | 18 | # the status of tasks just created |