[noosfero/noosfero][master] 2 commits: Filter tasks by text on task list
Victor Costa
gitlab at gitlab.com
Tue May 26 12:42:44 BRT 2015
Victor Costa pushed to branch master at Noosfero / noosfero
Commits:
7bcd1c31 by Michel Felipe at 2015-05-26T11:54:59Z
Filter tasks by text on task list
- - - - -
78331cae by Victor Costa at 2015-05-26T15:42:33Z
Merge branch 'tasks_text_filter' into 'master'
Filter tasks by text content
Change tasks filter to a fieldset with two fields: Type and text content autocomplete. To perform a filter, needs click a **search button**.
The screen below shows the interface modification:
![tasks_filter](https://gitlab.com/noosfero/noosfero/uploads/291b184f4c22310af97433914eb029d5/tasks_filter.png)
See merge request !445
- - - - -
4 changed files:
- app/controllers/my_profile/tasks_controller.rb
- app/models/task.rb
- app/views/tasks/index.html.erb
- test/functional/tasks_controller_test.rb
Changes:
=====================================
app/controllers/my_profile/tasks_controller.rb
=====================================
--- a/app/controllers/my_profile/tasks_controller.rb
+++ b/app/controllers/my_profile/tasks_controller.rb
@@ -1,11 +1,12 @@
class TasksController < MyProfileController
protect 'perform_task', :profile
-
+
def index
- @filter = params[:filter_type].blank? ? nil : params[:filter_type]
+ @filter_type = params[:filter_type].presence
+ @filter_text = params[:filter_text].presence
@task_types = Task.pending_types_for(profile)
- @tasks = Task.to(profile).without_spam.pending.of(@filter).order_by('created_at', 'asc').paginate(:per_page => Task.per_page, :page => params[:page])
+ @tasks = Task.pending_all(profile, @filter_type, @filter_text).order_by('created_at', 'asc').paginate(:per_page => Task.per_page, :page => params[:page])
@failed = params ? params[:failed] : {}
end
=====================================
app/models/task.rb
=====================================
--- a/app/models/task.rb
+++ b/app/models/task.rb
@@ -239,6 +239,10 @@ class Task < ActiveRecord::Base
scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] }
scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} }
scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} }
+ scope :like, lambda { |field, value| where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value}
+ scope :pending_all, lambda { |profile, filter_type, filter_text|
+ self.to(profile).without_spam.pending.of(filter_type).like('data', filter_text)
+ }
scope :to, lambda { |profile|
environment_condition = nil
=====================================
app/views/tasks/index.html.erb
=====================================
--- a/app/views/tasks/index.html.erb
+++ b/app/views/tasks/index.html.erb
@@ -21,11 +21,24 @@
</div>
<% end %>
+<%= form_tag '#', :method => 'get' do %>
+ <%= field_set_tag _('Filter'), :class => 'filter_fields' do %>
+ <p>
+ <%= labelled_select(_('Type of task')+': ', :filter_type, :first, :last, @filter_type, type_collection, {:id => 'filter-type'}) %>
+ </p>
+ <p>
+ <%= labelled_text_field(_("Text filter")+': ', :filter_text, nil, {:id => 'filter-text',:value => @filter_text}) %>
+ </p>
+ <p>
+ <%= submit_button(:search, _('Search')) %>
+ </p>
+ <% end %>
+<% end %>
+
<% if @tasks.empty? %>
<p>
- <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => "document.location.href = '?filter_type='+this.value")%>
+ <em><%= _('No pending tasks for %s') % profile.name %></em>
</p>
- <em><%= _('No pending tasks for %s') % profile.name %></em>
<% else %>
<%= form_tag :action => 'close' do%>
<% button_bar do %>
@@ -38,14 +51,12 @@
<ul class='task-list'>
<p>
- <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => "document.location.href = '?filter_type='+this.value") %>
- </p>
- <p>
<%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "up-set-all-tasks-to") %>
</p>
- <% @tasks.each do |task| %>
- <%= render :partial => 'task', :locals => { :task => task } %>
- <% end %>
+
+ <div class="task_boxes">
+ <%= render :partial => 'task', :collection => @tasks %>
+ </div>
<p>
<%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "down-set-all-tasks-to") %>
</p>
=====================================
test/functional/tasks_controller_test.rb
=====================================
--- a/test/functional/tasks_controller_test.rb
+++ b/test/functional/tasks_controller_test.rb
@@ -5,7 +5,7 @@ class TasksController; def rescue_action(e) raise e end; end
class TasksControllerTest < ActionController::TestCase
- noosfero_test :profile => 'testuser'
+ noosfero_test :profile => 'testuser'
def setup
@controller = TasksController.new
@@ -388,6 +388,28 @@ class TasksControllerTest < ActionController::TestCase
assert_includes assigns(:tasks), t3
end
+ should 'filter tasks by type and data content' do
+ class CleanHouse < Task; end
+ class FeedDog < Task; end
+ Task.stubs(:per_page).returns(3)
+ requestor = fast_create(Person)
+ t1 = CleanHouse.create!(:requestor => requestor, :target => profile, :data => {:name => 'Task Test'})
+ t2 = CleanHouse.create!(:requestor => requestor, :target => profile)
+ t3 = FeedDog.create!(:requestor => requestor, :target => profile)
+
+ get :index, :filter_type => t1.type, :filter_text => 'test'
+
+ assert_includes assigns(:tasks), t1
+ assert_not_includes assigns(:tasks), t2
+ assert_not_includes assigns(:tasks), t3
+
+ get :index
+
+ assert_includes assigns(:tasks), t1
+ assert_includes assigns(:tasks), t2
+ assert_includes assigns(:tasks), t3
+ end
+
should 'return tasks ordered accordingly and limited by pages' do
time = Time.now
person = fast_create(Person)
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/5087582d1e3f60ac0119927d86d64c2ad71c8f77...78331cae3493f00a17b9bebb39b7d01a4ba06bd3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150526/ebaab7d2/attachment.html>
More information about the Noosfero-dev
mailing list