Commit ad80b504db359d01d309783ac77fc14d7b775856

Authored by Antonio Terceiro
1 parent f2305c51

Tasks: fix filtering by task type

app/controllers/my_profile/tasks_controller.rb
@@ -4,6 +4,7 @@ class TasksController < MyProfileController @@ -4,6 +4,7 @@ class TasksController < MyProfileController
4 4
5 def index 5 def index
6 @filter = params[:filter_type].blank? ? nil : params[:filter_type] 6 @filter = params[:filter_type].blank? ? nil : params[:filter_type]
  7 + @task_types = Task.pending_types_for(profile)
7 @tasks = Task.to(profile).without_spam.pending.of(@filter).order_by('created_at', 'asc').paginate(:per_page => Task.per_page, :page => params[:page]) 8 @tasks = Task.to(profile).without_spam.pending.of(@filter).order_by('created_at', 'asc').paginate(:per_page => Task.per_page, :page => params[:page])
8 @failed = params ? params[:failed] : {} 9 @failed = params ? params[:failed] : {}
9 end 10 end
app/models/task.rb
@@ -250,6 +250,10 @@ class Task < ActiveRecord::Base @@ -250,6 +250,10 @@ class Task < ActiveRecord::Base
250 { :conditions => [environment_condition, profile_condition].compact.join(' OR ') } 250 { :conditions => [environment_condition, profile_condition].compact.join(' OR ') }
251 } 251 }
252 252
  253 + def self.pending_types_for(profile)
  254 + Task.to(profile).pending.select('distinct type').map { |t| [t.class.name, t.title] }
  255 + end
  256 +
253 def opened? 257 def opened?
254 status == Task::Status::ACTIVE || status == Task::Status::HIDDEN 258 status == Task::Status::ACTIVE || status == Task::Status::HIDDEN
255 end 259 end
app/views/tasks/index.html.erb
@@ -4,11 +4,9 @@ @@ -4,11 +4,9 @@
4 <p> 4 <p>
5 5
6 <% 6 <%
7 - type_collection = [[nil, _('All')]]  
8 - type_collection += @tasks.map { |t| [t.name, t.title] }.uniq 7 + type_collection = [[nil, _('All')]] + @task_types
9 %> 8 %>
10 9
11 -  
12 <% if !@failed.blank? %> 10 <% if !@failed.blank? %>
13 <div id="errorExplanation"> 11 <div id="errorExplanation">
14 <% @failed.each do |error, tasks_descriptions|%> 12 <% @failed.each do |error, tasks_descriptions|%>
@@ -40,7 +38,7 @@ @@ -40,7 +38,7 @@
40 38
41 <ul class='task-list'> 39 <ul class='task-list'>
42 <p> 40 <p>
43 - <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => 'document.location.href = "?filter_type="+this.value')%> 41 + <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :onchange => "document.location.href = '?filter_type='+this.value") %>
44 </p> 42 </p>
45 <p> 43 <p>
46 <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "up-set-all-tasks-to") %> 44 <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "up-set-all-tasks-to") %>