Commit 7bcd1c3138b3b3f16987e6b2daa17a19ae13bba4
Committed by
Victor Costa
1 parent
9984b8c2
Exists in
master
and in
29 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 | 1 | class TasksController < MyProfileController |
| 2 | 2 | |
| 3 | 3 | protect 'perform_task', :profile |
| 4 | - | |
| 4 | + | |
| 5 | 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 | 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 | 10 | @failed = params ? params[:failed] : {} |
| 10 | 11 | end |
| 11 | 12 | ... | ... |
app/models/task.rb
| ... | ... | @@ -239,6 +239,10 @@ class Task < ActiveRecord::Base |
| 239 | 239 | scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } |
| 240 | 240 | scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } |
| 241 | 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 | 247 | scope :to, lambda { |profile| |
| 244 | 248 | environment_condition = nil | ... | ... |
app/views/tasks/index.html.erb
| ... | ... | @@ -21,11 +21,24 @@ |
| 21 | 21 | </div> |
| 22 | 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 | 38 | <% if @tasks.empty? %> |
| 25 | 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 | 41 | </p> |
| 28 | - <em><%= _('No pending tasks for %s') % profile.name %></em> | |
| 29 | 42 | <% else %> |
| 30 | 43 | <%= form_tag :action => 'close' do%> |
| 31 | 44 | <% button_bar do %> |
| ... | ... | @@ -38,14 +51,12 @@ |
| 38 | 51 | |
| 39 | 52 | <ul class='task-list'> |
| 40 | 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 | 54 | <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "up-set-all-tasks-to") %> |
| 45 | 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 | 60 | <p> |
| 50 | 61 | <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "down-set-all-tasks-to") %> |
| 51 | 62 | </p> | ... | ... |
test/functional/tasks_controller_test.rb
| ... | ... | @@ -5,7 +5,7 @@ class TasksController; def rescue_action(e) raise e end; end |
| 5 | 5 | |
| 6 | 6 | class TasksControllerTest < ActionController::TestCase |
| 7 | 7 | |
| 8 | - noosfero_test :profile => 'testuser' | |
| 8 | + noosfero_test :profile => 'testuser' | |
| 9 | 9 | |
| 10 | 10 | def setup |
| 11 | 11 | @controller = TasksController.new |
| ... | ... | @@ -388,6 +388,28 @@ class TasksControllerTest < ActionController::TestCase |
| 388 | 388 | assert_includes assigns(:tasks), t3 |
| 389 | 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 | 413 | should 'return tasks ordered accordingly and limited by pages' do |
| 392 | 414 | time = Time.now |
| 393 | 415 | person = fast_create(Person) | ... | ... |