Commit a19f2635766a0c27887047db446dc5a0e9f1ed4a

Authored by Michel Felipe
Committed by Victor Costa
1 parent 23fcc9dd

Added a fieldset 'Filter' to Tasks list page, and perform a submit on search button to filter tasks

app/controllers/my_profile/tasks_controller.rb
... ... @@ -4,8 +4,9 @@ class TasksController < MyProfileController
4 4  
5 5 def index
6 6 @filter = params[:filter_type].blank? ? nil : params[:filter_type]
  7 + @filter_text = params[:filter_text].blank? ? nil : params[:filter_text]
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.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])
9 10 @failed = params ? params[:failed] : {}
10 11 end
11 12  
... ...
app/models/task.rb
... ... @@ -239,8 +239,7 @@ 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| {:conditions => ["LOWER(#{field}) LIKE ?", "%#{value}%"]}}
243   - scope :like, ->(field,value) { where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%")}
  242 + scope :like, ->(field,value) { where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value}
244 243  
245 244 scope :to, lambda { |profile|
246 245 environment_condition = nil
... ...
app/views/tasks/index.html.erb
... ... @@ -21,10 +21,27 @@
21 21 </div>
22 22 <% end %>
23 23  
  24 +<%= form_tag '#', :method => 'get' do %>
  25 +
  26 + <%= field_set_tag _('Filter'), :class => 'filter_fields' do %>
  27 + <p>
  28 + <%= labelled_select(_('Type of task')+': ', :filter_type, :first, :last, @filter, type_collection, {:id => 'filter-type'}) %>
  29 + </p>
  30 + <p>
  31 + <%= labelled_text_field(_("Text filter")+': ', :filter_text, nil, {:id => 'filter-text-autocomplete',:value => @filter_text}) %>
  32 + <script type="text/javascript">
  33 + jQuery('#filter-text-autocomplete').autocomplete({
  34 + source:<%= "'/myprofile/#{profile.identifier}/tasks/search_tasks'" %>+'?filter_type='+jQuery('#filter-type').val(),
  35 + minLength:2
  36 + });
  37 + </script>
  38 + </p>
  39 + <p>
  40 + <%= submit_button(:search, _('Search')) %>
  41 + </p>
  42 + <% end %>
  43 +<% end %>
24 44 <% if @tasks.empty? %>
25   - <p>
26   - <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => "document.location.href = '?filter_type='+this.value")%>
27   - </p>
28 45 <em><%= _('No pending tasks for %s') % profile.name %></em>
29 46 <% else %>
30 47 <%= form_tag :action => 'close' do%>
... ... @@ -38,27 +55,14 @@
38 55  
39 56 <ul class='task-list'>
40 57 <p>
41   - <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, {:onchange => "document.location.href = '?filter_type='+this.value", :id => 'filter-type'}) %>
42   - </p>
43   - <p>
44   - <%= labelled_text_field(_("Text filter")+': ', :text_filter, nil, {:id => 'text-filter-autocomplete'}) %>
45   - <script type="text/javascript">
46   - jQuery('#text-filter-autocomplete').autocomplete({
47   - source:<%= "'/myprofile/#{profile.identifier}/tasks/search_tasks'" %>+'?filter_type='+jQuery('#filter-type').val(),
48   - minLength:3,
49   - select:function(event,ui){
50   - document.location.href += '&term='+ui.item.value
51   - }
52   - });
53   - </script>
54   - </p>
55   - <p>
56 58 <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "up-set-all-tasks-to") %>
57 59 </p>
58 60  
59   - <% @tasks.each do |task| %>
60   - <%= render :partial => 'task', :locals => { :task => task } %>
61   - <% end %>
  61 + <div class="task_boxes">
  62 + <% @tasks.each do |task| %>
  63 + <%= render :partial => 'task', :locals => { :task => task } %>
  64 + <% end %>
  65 + </div>
62 66 <p>
63 67 <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "down-set-all-tasks-to") %>
64 68 </p>
... ...