diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index 78dcee3..4ca40d9 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -21,7 +21,26 @@ class TasksController < MyProfileController end def processed - @tasks = Task.to(profile).without_spam.closed.sort_by(&:created_at) + @filter_requestor = params[:filter_requestor].presence + @filter_type = params[:filter_type].presence + @filter_text = params[:filter_text].presence + @filter_status = params[:filter_status].presence + @filter_created_from = Date.parse(params[:filter_created_from]) unless params[:filter_created_from].blank? + @filter_created_until = Date.parse(params[:filter_created_until]) unless params[:filter_created_until].blank? + @filter_closed_from = Date.parse(params[:filter_closed_from]) unless params[:filter_closed_from].blank? + @filter_closed_until = Date.parse(params[:filter_closed_until]) unless params[:filter_closed_until].blank? + + @tasks = Task.to(profile).without_spam.closed.order('tasks.created_at DESC') + @tasks = @tasks.of(@filter_type) + @tasks = @tasks.where(:status => params[:filter_status]) unless @filter_status.blank? + @tasks = @tasks.where('tasks.created_at >= ?', @filter_created_from.beginning_of_day) unless @filter_created_from.blank? + @tasks = @tasks.where('tasks.created_at <= ?', @filter_created_until.end_of_day) unless @filter_created_until.blank? + @tasks = @tasks.joins(:requestor).like('profiles.name', @filter_requestor) unless @filter_requestor.blank? + @tasks = @tasks.like('tasks.data', @filter_text) unless @filter_text.blank? + + @tasks = @tasks.paginate(:per_page => Task.per_page, :page => params[:page]) + + @task_types = Task.closed_types_for(profile) end def change_responsible diff --git a/app/models/task.rb b/app/models/task.rb index 927031d..da6004e 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -242,7 +242,7 @@ class Task < ActiveRecord::Base scope :canceled, :conditions => { :status => Task::Status::CANCELLED } scope :closed, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] } scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } - scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } + scope :of, lambda { |type| conditions = type ? "tasks.type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } scope :like, lambda { |field, value| where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value} scope :pending_all, lambda { |profile, filter_type, filter_text| @@ -263,6 +263,10 @@ class Task < ActiveRecord::Base Task.to(profile).pending.select('distinct type').map { |t| [t.class.name, t.title] } end + def self.closed_types_for(profile) + Task.to(profile).closed.select('distinct type').map { |t| [t.class.name, t.title] } + end + def opened? status == Task::Status::ACTIVE || status == Task::Status::HIDDEN end diff --git a/app/views/tasks/processed.html.erb b/app/views/tasks/processed.html.erb index b76fac6..ade81e8 100644 --- a/app/views/tasks/processed.html.erb +++ b/app/views/tasks/processed.html.erb @@ -1,24 +1,73 @@ +<%= stylesheet_link_tag 'tasks' %> + +
<% if @tasks.empty? %> <%= _('No processed tasks.') %> <% else %> -