Commit 7b7331537c7a0178700e5ccc40803f42723f3616
1 parent
dbeeb306
Exists in
master
and in
9 other branches
added filter for task status
Showing
3 changed files
with
27 additions
and
1 deletions
Show diff stats
controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb
... | ... | @@ -8,19 +8,33 @@ class ProposalsDiscussionPluginTasksController < TasksController |
8 | 8 | @filter_responsible = params[:filter_responsible] |
9 | 9 | @filter_tags = params[:filter_tags] |
10 | 10 | |
11 | + @filter_status = params[:filter_status] | |
12 | + | |
11 | 13 | @view_only = !current_person.has_permission?(:perform_task, profile) || params[:view_only] |
12 | 14 | |
13 | 15 | @task_tags = [OpenStruct.new(:name => _('All'), :id => nil) ] + Task.all_tags |
14 | 16 | @task_types = Task.pending_types_for(profile) |
15 | 17 | |
18 | + # maps statuses which would be used in status filter | |
19 | + @task_statuses = ProposalsDiscussionPlugin::ProposalTask::Status.names.each_with_index.map { |x,i| OpenStruct.new(:id => i, :name =>x) } | |
20 | + @task_statuses.reject! {|status| [2,3,4].include? status.id} | |
21 | + | |
22 | + # filter for evaluator profile | |
16 | 23 | if @view_only |
17 | 24 | @tasks = Task.pending_all(profile, false, false).order_by('created_at', 'asc') |
18 | 25 | @tasks = @tasks.where(:responsible_id => current_person.id) |
19 | 26 | else |
27 | + # filter for moderator | |
28 | + if @filter_status.present? && ! "0".eql?(@filter_status) && !["2","3","4"].include?(@filter_status) | |
29 | + @tasks = ProposalsDiscussionPlugin::ProposalTask.filter_by_status(profile, @filter_type, @filter_text, @filter_status ).order_by('created_at', 'asc') | |
30 | + else | |
31 | + @tasks = ProposalsDiscussionPlugin::ProposalTask.pending_evaluated(profile, @filter_type, @filter_text).order_by('created_at', 'asc') | |
32 | + end | |
20 | 33 | |
21 | - @tasks = ProposalsDiscussionPlugin::ProposalTask.pending_evaluated(profile, @filter_type, @filter_text).order_by('created_at', 'asc') | |
22 | 34 | @tasks = @tasks.where(:responsible_id => @filter_responsible.to_i != -1 ? @filter_responsible : nil) if @filter_responsible.present? |
35 | + | |
23 | 36 | @tasks = @tasks.tagged_with(@filter_tags, any: true) if @filter_tags.present? |
37 | + | |
24 | 38 | end |
25 | 39 | |
26 | 40 | @tasks = @tasks.paginate(:per_page => Task.per_page, :page => params[:page]) | ... | ... |
lib/proposals_discussion_plugin/proposal_task.rb
... | ... | @@ -20,6 +20,15 @@ class ProposalsDiscussionPlugin::ProposalTask < Task |
20 | 20 | .where(:status => ProposalsDiscussionPlugin::ProposalTask::Status.evaluated_statuses) |
21 | 21 | } |
22 | 22 | |
23 | + scope :filter_by_status, lambda { |profile, filter_type, filter_text, status_id| | |
24 | + self | |
25 | + .to(profile) | |
26 | + .without_spam.pending | |
27 | + .of(filter_type) | |
28 | + .like('data', filter_text) | |
29 | + .where(:status => status_id) | |
30 | + } | |
31 | + | |
23 | 32 | before_create do |task| |
24 | 33 | if !task.target.nil? |
25 | 34 | organization = task.target | ... | ... |
views/proposals_discussion_plugin_tasks/index.html.erb
... | ... | @@ -36,6 +36,9 @@ |
36 | 36 | </p> |
37 | 37 | <% end %> |
38 | 38 | <p> |
39 | + <%= labelled_select(_('Status')+': ', :filter_status, :id, :name, @filter_status, @task_statuses, {:id => 'filter-statuses'}) %> | |
40 | + </p> | |
41 | + <p> | |
39 | 42 | <%= labelled_select(_('Tags')+': ', :filter_tags, :id, :name, @filter_tags, @task_tags, {:id => 'filter-add-tag'}) %> |
40 | 43 | <%= text_field_tag( :filter_tags, @filter_tags, :size => 36, :class => 'filter-tags' ) %> |
41 | 44 | </p> | ... | ... |