Commit 7bcd1c3138b3b3f16987e6b2daa17a19ae13bba4
Committed by
Victor Costa
1 parent
9984b8c2
Exists in
master
and in
25 other branches
Filter tasks by text on task list
Showing
4 changed files
with
50 additions
and
12 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
1 | class TasksController < MyProfileController | 1 | class TasksController < MyProfileController |
2 | 2 | ||
3 | protect 'perform_task', :profile | 3 | protect 'perform_task', :profile |
4 | - | 4 | + |
5 | def index | 5 | def index |
6 | - @filter = params[:filter_type].blank? ? nil : params[:filter_type] | 6 | + @filter_type = params[:filter_type].presence |
7 | + @filter_text = params[:filter_text].presence | ||
7 | @task_types = Task.pending_types_for(profile) | 8 | @task_types = Task.pending_types_for(profile) |
8 | - @tasks = Task.to(profile).without_spam.pending.of(@filter).order_by('created_at', 'asc').paginate(:per_page => Task.per_page, :page => params[:page]) | 9 | + @tasks = Task.pending_all(profile, @filter_type, @filter_text).order_by('created_at', 'asc').paginate(:per_page => Task.per_page, :page => params[:page]) |
9 | @failed = params ? params[:failed] : {} | 10 | @failed = params ? params[:failed] : {} |
10 | end | 11 | end |
11 | 12 |
app/models/task.rb
@@ -239,6 +239,10 @@ class Task < ActiveRecord::Base | @@ -239,6 +239,10 @@ class Task < ActiveRecord::Base | ||
239 | scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } | 239 | scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } |
240 | scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } | 240 | scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } |
241 | scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } | 241 | scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } |
242 | + scope :like, lambda { |field, value| where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value} | ||
243 | + scope :pending_all, lambda { |profile, filter_type, filter_text| | ||
244 | + self.to(profile).without_spam.pending.of(filter_type).like('data', filter_text) | ||
245 | + } | ||
242 | 246 | ||
243 | scope :to, lambda { |profile| | 247 | scope :to, lambda { |profile| |
244 | environment_condition = nil | 248 | environment_condition = nil |
app/views/tasks/index.html.erb
@@ -21,11 +21,24 @@ | @@ -21,11 +21,24 @@ | ||
21 | </div> | 21 | </div> |
22 | <% end %> | 22 | <% end %> |
23 | 23 | ||
24 | +<%= form_tag '#', :method => 'get' do %> | ||
25 | + <%= field_set_tag _('Filter'), :class => 'filter_fields' do %> | ||
26 | + <p> | ||
27 | + <%= labelled_select(_('Type of task')+': ', :filter_type, :first, :last, @filter_type, type_collection, {:id => 'filter-type'}) %> | ||
28 | + </p> | ||
29 | + <p> | ||
30 | + <%= labelled_text_field(_("Text filter")+': ', :filter_text, nil, {:id => 'filter-text',:value => @filter_text}) %> | ||
31 | + </p> | ||
32 | + <p> | ||
33 | + <%= submit_button(:search, _('Search')) %> | ||
34 | + </p> | ||
35 | + <% end %> | ||
36 | +<% end %> | ||
37 | + | ||
24 | <% if @tasks.empty? %> | 38 | <% if @tasks.empty? %> |
25 | <p> | 39 | <p> |
26 | - <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => "document.location.href = '?filter_type='+this.value")%> | 40 | + <em><%= _('No pending tasks for %s') % profile.name %></em> |
27 | </p> | 41 | </p> |
28 | - <em><%= _('No pending tasks for %s') % profile.name %></em> | ||
29 | <% else %> | 42 | <% else %> |
30 | <%= form_tag :action => 'close' do%> | 43 | <%= form_tag :action => 'close' do%> |
31 | <% button_bar do %> | 44 | <% button_bar do %> |
@@ -38,14 +51,12 @@ | @@ -38,14 +51,12 @@ | ||
38 | 51 | ||
39 | <ul class='task-list'> | 52 | <ul class='task-list'> |
40 | <p> | 53 | <p> |
41 | - <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => "document.location.href = '?filter_type='+this.value") %> | ||
42 | - </p> | ||
43 | - <p> | ||
44 | <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "up-set-all-tasks-to") %> | 54 | <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "up-set-all-tasks-to") %> |
45 | </p> | 55 | </p> |
46 | - <% @tasks.each do |task| %> | ||
47 | - <%= render :partial => 'task', :locals => { :task => task } %> | ||
48 | - <% end %> | 56 | + |
57 | + <div class="task_boxes"> | ||
58 | + <%= render :partial => 'task', :collection => @tasks %> | ||
59 | + </div> | ||
49 | <p> | 60 | <p> |
50 | <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "down-set-all-tasks-to") %> | 61 | <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "down-set-all-tasks-to") %> |
51 | </p> | 62 | </p> |
test/functional/tasks_controller_test.rb
@@ -5,7 +5,7 @@ class TasksController; def rescue_action(e) raise e end; end | @@ -5,7 +5,7 @@ class TasksController; def rescue_action(e) raise e end; end | ||
5 | 5 | ||
6 | class TasksControllerTest < ActionController::TestCase | 6 | class TasksControllerTest < ActionController::TestCase |
7 | 7 | ||
8 | - noosfero_test :profile => 'testuser' | 8 | + noosfero_test :profile => 'testuser' |
9 | 9 | ||
10 | def setup | 10 | def setup |
11 | @controller = TasksController.new | 11 | @controller = TasksController.new |
@@ -388,6 +388,28 @@ class TasksControllerTest < ActionController::TestCase | @@ -388,6 +388,28 @@ class TasksControllerTest < ActionController::TestCase | ||
388 | assert_includes assigns(:tasks), t3 | 388 | assert_includes assigns(:tasks), t3 |
389 | end | 389 | end |
390 | 390 | ||
391 | + should 'filter tasks by type and data content' do | ||
392 | + class CleanHouse < Task; end | ||
393 | + class FeedDog < Task; end | ||
394 | + Task.stubs(:per_page).returns(3) | ||
395 | + requestor = fast_create(Person) | ||
396 | + t1 = CleanHouse.create!(:requestor => requestor, :target => profile, :data => {:name => 'Task Test'}) | ||
397 | + t2 = CleanHouse.create!(:requestor => requestor, :target => profile) | ||
398 | + t3 = FeedDog.create!(:requestor => requestor, :target => profile) | ||
399 | + | ||
400 | + get :index, :filter_type => t1.type, :filter_text => 'test' | ||
401 | + | ||
402 | + assert_includes assigns(:tasks), t1 | ||
403 | + assert_not_includes assigns(:tasks), t2 | ||
404 | + assert_not_includes assigns(:tasks), t3 | ||
405 | + | ||
406 | + get :index | ||
407 | + | ||
408 | + assert_includes assigns(:tasks), t1 | ||
409 | + assert_includes assigns(:tasks), t2 | ||
410 | + assert_includes assigns(:tasks), t3 | ||
411 | + end | ||
412 | + | ||
391 | should 'return tasks ordered accordingly and limited by pages' do | 413 | should 'return tasks ordered accordingly and limited by pages' do |
392 | time = Time.now | 414 | time = Time.now |
393 | person = fast_create(Person) | 415 | person = fast_create(Person) |