diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index 82937f5..f5f28ff 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -4,8 +4,9 @@ class TasksController < MyProfileController def index @filter = params[:filter_type].blank? ? nil : params[:filter_type] + @filter_text = params[:filter_text].blank? ? nil : params[:filter_text] @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.to(profile).without_spam.pending.of(@filter).like('data',@filter_text).order_by('created_at', 'asc').paginate(:per_page => Task.per_page, :page => params[:page]) @failed = params ? params[:failed] : {} end diff --git a/app/models/task.rb b/app/models/task.rb index 12bd631..3e4103b 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -239,8 +239,7 @@ 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| {:conditions => ["LOWER(#{field}) LIKE ?", "%#{value}%"]}} - scope :like, ->(field,value) { where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%")} + scope :like, ->(field,value) { where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value} scope :to, lambda { |profile| environment_condition = nil diff --git a/app/views/tasks/index.html.erb b/app/views/tasks/index.html.erb index a654728..129014f 100644 --- a/app/views/tasks/index.html.erb +++ b/app/views/tasks/index.html.erb @@ -21,10 +21,27 @@ <% end %> +<%= form_tag '#', :method => 'get' do %> + + <%= field_set_tag _('Filter'), :class => 'filter_fields' do %> +

+ <%= labelled_select(_('Type of task')+': ', :filter_type, :first, :last, @filter, type_collection, {:id => 'filter-type'}) %> +

+

+ <%= labelled_text_field(_("Text filter")+': ', :filter_text, nil, {:id => 'filter-text-autocomplete',:value => @filter_text}) %> + +

+

+ <%= submit_button(:search, _('Search')) %> +

+ <% end %> +<% end %> <% if @tasks.empty? %> -

- <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => "document.location.href = '?filter_type='+this.value")%> -

<%= _('No pending tasks for %s') % profile.name %> <% else %> <%= form_tag :action => 'close' do%> @@ -38,27 +55,14 @@