Commit 5d64374acc79901fa151cba1b443b3c064123306
1 parent
bb88fa4d
Exists in
master
and in
8 other branches
Added interface to add a category to tasks. Added to model validation that deny …
…approve/reprove tasks without at least one category
Showing
6 changed files
with
93 additions
and
17 deletions
Show diff stats
controllers/myprofile/proposals_discussion_plugin_confirm_tasks_controller.rb
| ... | ... | @@ -27,7 +27,7 @@ private |
| 27 | 27 | if params[:task_id] and request.post? |
| 28 | 28 | begin |
| 29 | 29 | task = profile.find_in_all_tasks(params[:task_id]) |
| 30 | - task.tag_list = params[:tag_list] | |
| 30 | + task.tag_list = params[:tag_list] if params[:tag_list].presence | |
| 31 | 31 | task.article_parent_id = params[:article_parent_id] if decision.to_s == 'finish' |
| 32 | 32 | task.email_template_id = params[:email_template_id] |
| 33 | 33 | task.send(decision, current_person) | ... | ... |
controllers/myprofile/proposals_discussion_plugin_evaluate_tasks_controller.rb
| ... | ... | @@ -11,10 +11,19 @@ class ProposalsDiscussionPluginEvaluateTasksController < MyProfileController |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | task = Task.to(profile).find_by_id params[:task_id] |
| 14 | - save = task.flag_accept_proposal(current_person) | |
| 15 | 14 | |
| 16 | - if save | |
| 17 | - result = {:success => true } | |
| 15 | + begin | |
| 16 | + | |
| 17 | + save = task.flag_accept_proposal(current_person) | |
| 18 | + | |
| 19 | + if save | |
| 20 | + result = {:success => true } | |
| 21 | + end | |
| 22 | + rescue ActiveRecord::RecordInvalid => e | |
| 23 | + result = { | |
| 24 | + :success => false, | |
| 25 | + :message => e.message | |
| 26 | + } | |
| 18 | 27 | end |
| 19 | 28 | end |
| 20 | 29 | |
| ... | ... | @@ -30,10 +39,18 @@ class ProposalsDiscussionPluginEvaluateTasksController < MyProfileController |
| 30 | 39 | } |
| 31 | 40 | |
| 32 | 41 | task = Task.to(profile).find_by_id params[:task_id] |
| 33 | - save = task.flag_reject_proposal(current_person) | |
| 34 | 42 | |
| 35 | - if save | |
| 36 | - result = {:success => true } | |
| 43 | + begin | |
| 44 | + save = task.flag_reject_proposal(current_person) | |
| 45 | + | |
| 46 | + if save | |
| 47 | + result = {:success => true } | |
| 48 | + end | |
| 49 | + rescue ActiveRecord::RecordInvalid => e | |
| 50 | + result = { | |
| 51 | + :success => false, | |
| 52 | + :message => e.message | |
| 53 | + } | |
| 37 | 54 | end |
| 38 | 55 | end |
| 39 | 56 | ... | ... |
controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb
| ... | ... | @@ -6,13 +6,13 @@ class ProposalsDiscussionPluginTasksController < TasksController |
| 6 | 6 | @filter_type = params[:filter_type].presence |
| 7 | 7 | @filter_text = params[:filter_text].presence |
| 8 | 8 | @filter_responsible = params[:filter_responsible] |
| 9 | - @filter_tags = params[:filter_tags] | |
| 9 | + @filter_categories = params[:filter_categories] | |
| 10 | 10 | |
| 11 | 11 | @filter_status = params[:filter_status] |
| 12 | 12 | |
| 13 | 13 | @view_only = !current_person.has_permission?(:perform_task, profile) || params[:view_only] |
| 14 | 14 | |
| 15 | - @task_tags = [OpenStruct.new(:name => _('All'), :id => nil) ] + Task.all_tags | |
| 15 | + @task_categories = [OpenStruct.new(:name => _('All'), :id => nil) ] + ProposalsDiscussionPlugin::TaskCategory.all | |
| 16 | 16 | @task_types = Task.pending_types_for(profile) |
| 17 | 17 | |
| 18 | 18 | # maps statuses which would be used in status filter |
| ... | ... | @@ -33,8 +33,6 @@ class ProposalsDiscussionPluginTasksController < TasksController |
| 33 | 33 | |
| 34 | 34 | @tasks = @tasks.where(:responsible_id => @filter_responsible.to_i != -1 ? @filter_responsible : nil) if @filter_responsible.present? |
| 35 | 35 | |
| 36 | - @tasks = @tasks.tagged_with(@filter_tags, any: true) if @filter_tags.present? | |
| 37 | - | |
| 38 | 36 | end |
| 39 | 37 | |
| 40 | 38 | @tasks = @tasks.paginate(:per_page => Task.per_page, :page => params[:page]) |
| ... | ... | @@ -44,4 +42,35 @@ class ProposalsDiscussionPluginTasksController < TasksController |
| 44 | 42 | @responsible_candidates = profile.members.by_role(profile.roles.reject {|r| !r.has_permission?('perform_task')}) if profile.organization? |
| 45 | 43 | end |
| 46 | 44 | |
| 45 | + def save_categories | |
| 46 | + | |
| 47 | + if request.post? && params[:tag_list].presence | |
| 48 | + result = { | |
| 49 | + success: false, | |
| 50 | + message: _('Error to save categories. Please, contact the system admin') | |
| 51 | + } | |
| 52 | + | |
| 53 | + categories_list = params[:tag_list].split(',') | |
| 54 | + task = Task.to(profile).find_by_id params[:task_id] | |
| 55 | + | |
| 56 | + categories_data = [] | |
| 57 | + categories_list.each do |category_name| | |
| 58 | + category = ProposalsDiscussionPlugin::TaskCategory.find_by_name(category_name) | |
| 59 | + categories_data << category | |
| 60 | + end | |
| 61 | + task.categories = categories_data | |
| 62 | + save = task.save! | |
| 63 | + | |
| 64 | + if save | |
| 65 | + result = { | |
| 66 | + success: true, | |
| 67 | + message: _('Saved with success!') | |
| 68 | + } | |
| 69 | + end | |
| 70 | + end | |
| 71 | + | |
| 72 | + render json: result | |
| 73 | + | |
| 74 | + end | |
| 75 | + | |
| 47 | 76 | end | ... | ... |
lib/proposals_discussion_plugin/proposal_task.rb
| ... | ... | @@ -285,11 +285,15 @@ class ProposalsDiscussionPlugin::ProposalTask < Task |
| 285 | 285 | self.delay.marked_as_ham |
| 286 | 286 | end |
| 287 | 287 | |
| 288 | + def categories_list(field = :name) | |
| 289 | + categories.pluck(field).join(',') if categories.count > 0 | |
| 290 | + end | |
| 291 | + | |
| 288 | 292 | protected |
| 289 | 293 | |
| 290 | 294 | def require_category |
| 291 | 295 | if categories.count == 0 && flagged? |
| 292 | - errors.add :categories, _( 'Please, select at least one') | |
| 296 | + errors.add :categories, _('Please, select at least one') | |
| 293 | 297 | end |
| 294 | 298 | end |
| 295 | 299 | end | ... | ... |
views/proposals_discussion_plugin_tasks/_task.html.erb
| ... | ... | @@ -61,7 +61,10 @@ |
| 61 | 61 | |
| 62 | 62 | <div class="formfieldline"> |
| 63 | 63 | <div class="formfield tag-list-fields"> |
| 64 | - <%= labelled_text_field(_('Tags'),"tasks[#{task.id}][task][tag_list]", task.tags_from(nil).to_s, :size => 36, :class => 'tag-list','data-submit-values'=>"{'task_id':'#{task.id}'}") %> | |
| 64 | + <p> | |
| 65 | + <%= labelled_select(_('Categories')+': ', :select_category, :id, :name, @filter_categories, @task_categories, {:class => 'add-category'}) %> | |
| 66 | + <%= text_field_tag( :categories_list, task.categories_list, :size => 36,:id => '', :class => 'task-categories', 'data-submit-values'=>"{'task_id':'#{task.id}'}") %> | |
| 67 | + </p> | |
| 65 | 68 | </div> |
| 66 | 69 | </div> |
| 67 | 70 | ... | ... |
views/proposals_discussion_plugin_tasks/index.html.erb
| ... | ... | @@ -38,10 +38,6 @@ |
| 38 | 38 | <p> |
| 39 | 39 | <%= labelled_select(_('Status')+': ', :filter_status, :id, :name, @filter_status, @task_statuses, {:id => 'filter-statuses'}) %> |
| 40 | 40 | </p> |
| 41 | - <p> | |
| 42 | - <%= labelled_select(_('Tags')+': ', :filter_tags, :id, :name, @filter_tags, @task_tags, {:id => 'filter-add-tag'}) %> | |
| 43 | - <%= text_field_tag( :filter_tags, @filter_tags, :size => 36, :class => 'filter-tags' ) %> | |
| 44 | - </p> | |
| 45 | 41 | |
| 46 | 42 | <p> |
| 47 | 43 | <%= submit_button(:search, _('Search')) %> |
| ... | ... | @@ -197,4 +193,31 @@ |
| 197 | 193 | } |
| 198 | 194 | }); |
| 199 | 195 | } |
| 196 | + | |
| 197 | + jQuery('.task-categories').inputosaurus({ | |
| 198 | + hideInput: true, | |
| 199 | + submitTags: { | |
| 200 | + url: '/myprofile/'+<%= "'#{profile.identifier}'" %>+'/plugin/proposals_discussion/tasks/save_categories', | |
| 201 | + beforeSend: function(){ | |
| 202 | + | |
| 203 | + $('.ok').parent().remove(); | |
| 204 | + | |
| 205 | + this.element.parents('.task_box') | |
| 206 | + .prev('.fg-state-error') | |
| 207 | + .remove(); | |
| 208 | + | |
| 209 | + Task.addIcon(this,'loading'); | |
| 210 | + | |
| 211 | + //Add loading here! | |
| 212 | + }, | |
| 213 | + success: Task.onAddTag | |
| 214 | + } | |
| 215 | + }); | |
| 216 | + | |
| 217 | + $('.add-category').change(function(){ | |
| 218 | + | |
| 219 | + if($(this).val() != ''){ | |
| 220 | + $(this).next('ul').find('.task-categories').inputosaurus('addTags',$(this).children(':selected').text()); | |
| 221 | + } | |
| 222 | + }); | |
| 200 | 223 | </script> | ... | ... |