Commit 456e9347e1962ccfa6b5474d1293c83203082025
Committed by
Leandro Santos
1 parent
9db9c4b8
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Store task tags on database using acts_as_taggable gem
Showing
2 changed files
with
23 additions
and
7 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
| @@ -41,18 +41,33 @@ class TasksController < MyProfileController | @@ -41,18 +41,33 @@ class TasksController < MyProfileController | ||
| 41 | 41 | ||
| 42 | def close | 42 | def close |
| 43 | failed = {} | 43 | failed = {} |
| 44 | + save = false | ||
| 44 | 45 | ||
| 45 | if params[:tasks] | 46 | if params[:tasks] |
| 46 | params[:tasks].each do |id, value| | 47 | params[:tasks].each do |id, value| |
| 47 | decision = value[:decision] | 48 | decision = value[:decision] |
| 48 | - if request.post? && VALID_DECISIONS.include?(decision) && id && decision != 'skip' | 49 | + |
| 50 | + if value[:task].is_a?(Hash) && value[:task][:tag_list] | ||
| 51 | + | ||
| 49 | task = profile.find_in_all_tasks(id) | 52 | task = profile.find_in_all_tasks(id) |
| 50 | - begin | ||
| 51 | - task.update_attributes(value[:task]) | ||
| 52 | - task.send(decision) | ||
| 53 | - rescue Exception => ex | ||
| 54 | - message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" | ||
| 55 | - failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message] | 53 | + task.tag_list = value[:task][:tag_list] |
| 54 | + value[:task].delete('tag_list') | ||
| 55 | + | ||
| 56 | + save = true | ||
| 57 | + end | ||
| 58 | + | ||
| 59 | + if request.post? | ||
| 60 | + if VALID_DECISIONS.include?(decision) && id && decision != 'skip' | ||
| 61 | + task ||= profile.find_in_all_tasks(id) | ||
| 62 | + begin | ||
| 63 | + task.update_attributes(value[:task]) | ||
| 64 | + task.send(decision) | ||
| 65 | + rescue Exception => ex | ||
| 66 | + message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" | ||
| 67 | + failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message] | ||
| 68 | + end | ||
| 69 | + elsif save | ||
| 70 | + task.save! | ||
| 56 | end | 71 | end |
| 57 | end | 72 | end |
| 58 | end | 73 | 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 |