From 7b7331537c7a0178700e5ccc40803f42723f3616 Mon Sep 17 00:00:00 2001
From: Ábner Silva de Oliveira
Date: Fri, 19 Jun 2015 10:21:35 -0300
Subject: [PATCH] added filter for task status
---
controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb | 16 +++++++++++++++-
lib/proposals_discussion_plugin/proposal_task.rb | 9 +++++++++
views/proposals_discussion_plugin_tasks/index.html.erb | 3 +++
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb b/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb
index ce4daf9..5020ee8 100644
--- a/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb
+++ b/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb
@@ -8,19 +8,33 @@ class ProposalsDiscussionPluginTasksController < TasksController
@filter_responsible = params[:filter_responsible]
@filter_tags = params[:filter_tags]
+ @filter_status = params[:filter_status]
+
@view_only = !current_person.has_permission?(:perform_task, profile) || params[:view_only]
@task_tags = [OpenStruct.new(:name => _('All'), :id => nil) ] + Task.all_tags
@task_types = Task.pending_types_for(profile)
+ # maps statuses which would be used in status filter
+ @task_statuses = ProposalsDiscussionPlugin::ProposalTask::Status.names.each_with_index.map { |x,i| OpenStruct.new(:id => i, :name =>x) }
+ @task_statuses.reject! {|status| [2,3,4].include? status.id}
+
+ # filter for evaluator profile
if @view_only
@tasks = Task.pending_all(profile, false, false).order_by('created_at', 'asc')
@tasks = @tasks.where(:responsible_id => current_person.id)
else
+ # filter for moderator
+ if @filter_status.present? && ! "0".eql?(@filter_status) && !["2","3","4"].include?(@filter_status)
+ @tasks = ProposalsDiscussionPlugin::ProposalTask.filter_by_status(profile, @filter_type, @filter_text, @filter_status ).order_by('created_at', 'asc')
+ else
+ @tasks = ProposalsDiscussionPlugin::ProposalTask.pending_evaluated(profile, @filter_type, @filter_text).order_by('created_at', 'asc')
+ end
- @tasks = ProposalsDiscussionPlugin::ProposalTask.pending_evaluated(profile, @filter_type, @filter_text).order_by('created_at', 'asc')
@tasks = @tasks.where(:responsible_id => @filter_responsible.to_i != -1 ? @filter_responsible : nil) if @filter_responsible.present?
+
@tasks = @tasks.tagged_with(@filter_tags, any: true) if @filter_tags.present?
+
end
@tasks = @tasks.paginate(:per_page => Task.per_page, :page => params[:page])
diff --git a/lib/proposals_discussion_plugin/proposal_task.rb b/lib/proposals_discussion_plugin/proposal_task.rb
index bfbe558..80dd76a 100644
--- a/lib/proposals_discussion_plugin/proposal_task.rb
+++ b/lib/proposals_discussion_plugin/proposal_task.rb
@@ -20,6 +20,15 @@ class ProposalsDiscussionPlugin::ProposalTask < Task
.where(:status => ProposalsDiscussionPlugin::ProposalTask::Status.evaluated_statuses)
}
+ scope :filter_by_status, lambda { |profile, filter_type, filter_text, status_id|
+ self
+ .to(profile)
+ .without_spam.pending
+ .of(filter_type)
+ .like('data', filter_text)
+ .where(:status => status_id)
+ }
+
before_create do |task|
if !task.target.nil?
organization = task.target
diff --git a/views/proposals_discussion_plugin_tasks/index.html.erb b/views/proposals_discussion_plugin_tasks/index.html.erb
index e46b2f0..fbdb0de 100644
--- a/views/proposals_discussion_plugin_tasks/index.html.erb
+++ b/views/proposals_discussion_plugin_tasks/index.html.erb
@@ -36,6 +36,9 @@
<% end %>
+ <%= labelled_select(_('Status')+': ', :filter_status, :id, :name, @filter_status, @task_statuses, {:id => 'filter-statuses'}) %>
+
+
<%= labelled_select(_('Tags')+': ', :filter_tags, :id, :name, @filter_tags, @task_tags, {:id => 'filter-add-tag'}) %>
<%= text_field_tag( :filter_tags, @filter_tags, :size => 36, :class => 'filter-tags' ) %>
--
libgit2 0.21.2