Commit 62a74f33b947814c8c2de916c8a61c2866b22946

Authored by Victor Costa
1 parent 556c20c3

Improve listing of processed tasks

app/controllers/my_profile/tasks_controller.rb
@@ -21,7 +21,26 @@ class TasksController < MyProfileController @@ -21,7 +21,26 @@ class TasksController < MyProfileController
21 end 21 end
22 22
23 def processed 23 def processed
24 - @tasks = Task.to(profile).without_spam.closed.sort_by(&:created_at) 24 + @filter_requestor = params[:filter_requestor].presence
  25 + @filter_type = params[:filter_type].presence
  26 + @filter_text = params[:filter_text].presence
  27 + @filter_status = params[:filter_status].presence
  28 + @filter_created_from = Date.parse(params[:filter_created_from]) unless params[:filter_created_from].blank?
  29 + @filter_created_until = Date.parse(params[:filter_created_until]) unless params[:filter_created_until].blank?
  30 + @filter_closed_from = Date.parse(params[:filter_closed_from]) unless params[:filter_closed_from].blank?
  31 + @filter_closed_until = Date.parse(params[:filter_closed_until]) unless params[:filter_closed_until].blank?
  32 +
  33 + @tasks = Task.to(profile).without_spam.closed.order('tasks.created_at DESC')
  34 + @tasks = @tasks.of(@filter_type)
  35 + @tasks = @tasks.where(:status => params[:filter_status]) unless @filter_status.blank?
  36 + @tasks = @tasks.where('tasks.created_at >= ?', @filter_created_from.beginning_of_day) unless @filter_created_from.blank?
  37 + @tasks = @tasks.where('tasks.created_at <= ?', @filter_created_until.end_of_day) unless @filter_created_until.blank?
  38 + @tasks = @tasks.joins(:requestor).like('profiles.name', @filter_requestor) unless @filter_requestor.blank?
  39 + @tasks = @tasks.like('tasks.data', @filter_text) unless @filter_text.blank?
  40 +
  41 + @tasks = @tasks.paginate(:per_page => Task.per_page, :page => params[:page])
  42 +
  43 + @task_types = Task.closed_types_for(profile)
25 end 44 end
26 45
27 def change_responsible 46 def change_responsible
app/models/task.rb
@@ -242,7 +242,7 @@ class Task &lt; ActiveRecord::Base @@ -242,7 +242,7 @@ class Task &lt; ActiveRecord::Base
242 scope :canceled, :conditions => { :status => Task::Status::CANCELLED } 242 scope :canceled, :conditions => { :status => Task::Status::CANCELLED }
243 scope :closed, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] } 243 scope :closed, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] }
244 scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } 244 scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] }
245 - scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } 245 + scope :of, lambda { |type| conditions = type ? "tasks.type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} }
246 scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } 246 scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} }
247 scope :like, lambda { |field, value| where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value} 247 scope :like, lambda { |field, value| where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value}
248 scope :pending_all, lambda { |profile, filter_type, filter_text| 248 scope :pending_all, lambda { |profile, filter_type, filter_text|
@@ -263,6 +263,10 @@ class Task &lt; ActiveRecord::Base @@ -263,6 +263,10 @@ class Task &lt; ActiveRecord::Base
263 Task.to(profile).pending.select('distinct type').map { |t| [t.class.name, t.title] } 263 Task.to(profile).pending.select('distinct type').map { |t| [t.class.name, t.title] }
264 end 264 end
265 265
  266 + def self.closed_types_for(profile)
  267 + Task.to(profile).closed.select('distinct type').map { |t| [t.class.name, t.title] }
  268 + end
  269 +
266 def opened? 270 def opened?
267 status == Task::Status::ACTIVE || status == Task::Status::HIDDEN 271 status == Task::Status::ACTIVE || status == Task::Status::HIDDEN
268 end 272 end
app/views/tasks/processed.html.erb
  1 +<%= stylesheet_link_tag 'tasks' %>
  2 +
  3 +<div class="task-processed">
1 <h1><%= _("%s's processed tasks") % profile.name %></h1> 4 <h1><%= _("%s's processed tasks") % profile.name %></h1>
2 5
  6 +<div class="task-processed-filter">
  7 +<%
  8 + type_collection = [[nil, _('All')]] + @task_types
  9 +%>
  10 + <%= form_tag '#', :method => 'get' do %>
  11 + <%= field_set_tag _('Filter'), :class => 'filter_fields' do %>
  12 + <div>
  13 + <%= labelled_select(_('Type of task')+': ', :filter_type, :first, :last, @filter_type, type_collection, {:id => 'filter-type'}) %>
  14 + <%= labelled_select(_('Status:'), :filter_status, :last, :first, @filter_status, [[_('Any'), nil], [_(Task::Status.names[Task::Status::CANCELLED]), 2], [_(Task::Status.names[Task::Status::FINISHED]), 3] ]) %>
  15 + </div>
  16 +
  17 + <div>
  18 + <%= labelled_text_field(_('Text Filter:'), :filter_text, @filter_text) %>
  19 + <%= labelled_text_field(_('Requestor Name:'), :filter_requestor, @filter_requestor) %>
  20 + </div>
  21 +
  22 + <%= labelled_form_field(_('Creation date'), date_range_field(:filter_created_from, :filter_created_until, @filter_created_from, @filter_created_until, '%Y-%m-%d', { :change_month => true, :change_year => true, :date_format => 'yy-mm-dd' }, { :size => 14, :from_id => 'filter_created_from', :to_id => 'filter_created_until' })) %>
  23 + <%= labelled_form_field(_('Processed date'), date_range_field(:filter_closed_from, :filter_closed_until, @filter_closed_from, @filter_closed_until, '%Y-%m-%d', { :change_month => true, :change_year => true, :date_format => 'yy-mm-dd' }, { :size => 14, :from_id => 'filter_closed_from', :to_id => 'filter_closed_until' })) %>
  24 +
  25 + <div class="actions">
  26 + <%= submit_button(:search, _('Search')) %>
  27 + </div>
  28 + <% end %>
  29 + <% end %>
  30 +</div>
  31 +
3 <p> 32 <p>
4 <% if @tasks.empty? %> 33 <% if @tasks.empty? %>
5 <em><%= _('No processed tasks.') %></em> 34 <em><%= _('No processed tasks.') %></em>
6 <% else %> 35 <% else %>
7 - <ul> 36 + <ul class="task-list">
8 <% @tasks.each do |item| %> 37 <% @tasks.each do |item| %>
9 - <li>  
10 - <strong><%= task_information(item) %></strong> <br/>  
11 - <small>  
12 - <%= _('Created:') +' '+ show_date(item.created_at) %> 38 + <li class="task status-<%= item.status%>">
  39 + <div class="title">
  40 + <%= task_information(item) %>
  41 + </div>
  42 + <div class="status">
  43 + <%= _(Task::Status.names[item.status]) %>
  44 + </div>
  45 + <div class="dates">
  46 + <span class="created">
  47 + <span class="label"><%= _('Created:') %></span>
  48 + <span class="value"><%= show_date(item.created_at) %></span>
  49 + </span>
13 &nbsp; &#151; &nbsp; 50 &nbsp; &#151; &nbsp;
14 - <%= _('Processed:') +' '+ show_date(item.end_date) %>  
15 - </small> 51 + <span class="processed">
  52 + <span class="label"><%= _('Processed:') %></span>
  53 + <span class="value"><%= show_date(item.end_date) %></span>
  54 + </span>
  55 + </div>
  56 + <% if item.closed_by.present? %>
  57 + <div class="closed-by">
  58 + <span class="label"><%= _('Closed by: ') %></span>
  59 + <span class="value"><%= link_to(item.closed_by.name, item.closed_by.url) %></span>
  60 + </div>
  61 + <% end %>
16 </li> 62 </li>
17 <% end %> 63 <% end %>
18 </ul> 64 </ul>
  65 + <%= pagination_links(@tasks)%>
19 <% end %> 66 <% end %>
20 </p> 67 </p>
21 68
22 <% button_bar do %> 69 <% button_bar do %>
23 <%= button(:back, _('Back'), :action => 'index') %> 70 <%= button(:back, _('Back'), :action => 'index') %>
24 <% end %> 71 <% end %>
  72 +
  73 +</div>
public/stylesheets/tasks.css
@@ -53,3 +53,46 @@ @@ -53,3 +53,46 @@
53 .task_responsible { 53 .task_responsible {
54 text-align: right; 54 text-align: right;
55 } 55 }
  56 +
  57 +.task-processed li {
  58 + background-color: rgb(240, 240, 240);
  59 + border-radius: 8px;
  60 + margin: 10px 0;
  61 + list-style-type: none;
  62 + padding: 12px;
  63 +}
  64 +
  65 +.task-processed .task.status-3 {
  66 + background-color: rgb(205, 252, 218);
  67 +}
  68 +
  69 +.task-processed .task.status-2 {
  70 + background-color: rgb(255, 203, 203);
  71 +}
  72 +
  73 +
  74 +.task-processed ul {
  75 + padding: 0;
  76 +}
  77 +
  78 +.task-processed .task-list .task .title {
  79 + border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  80 + font-weight: bold;
  81 + color: rgb(44, 44, 44);
  82 +}
  83 +
  84 +.task-processed .task .status {
  85 + float: right;
  86 + color: rgb(156, 156, 156);
  87 + font-weight: bold;
  88 +}
  89 +
  90 +.task-processed .task .dates {
  91 + font-size: 11px;
  92 +}
  93 +.task-processed .task .closed-by {
  94 + font-size: 11px;
  95 +}
  96 +.task-processed .task .label {
  97 + font-weight: bold
  98 +}
test/functional/tasks_controller_test.rb
@@ -46,7 +46,7 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -46,7 +46,7 @@ class TasksControllerTest &lt; ActionController::TestCase
46 46
47 assert_response :success 47 assert_response :success
48 assert_template 'processed' 48 assert_template 'processed'
49 - assert_kind_of Array, assigns(:tasks) 49 + assert !assigns(:tasks).nil?
50 end 50 end
51 51
52 should 'display task created_at' do 52 should 'display task created_at' do