Commit 76f71df3 authored by Daniela Feitosa's avatar Daniela Feitosa

Merge branch 'master_processed_tasks' into 'master'

Improves listing of processed tasks

- Filters for processed tasks
Signed-off-by: Gustavo Jaruga Cruz's avatarGustavo Jaruga <[email protected]>
Signed-off-by: Marcos Ronaldo Pereira Junior's avatarMarcos Ronaldo <[email protected]>

See merge request !833
parents 075773a6 e6634cb3
Pipeline #2059000 failed with stage
......@@ -26,7 +26,11 @@ class TasksController < MyProfileController
end
def processed
@tasks = Task.to(profile).without_spam.closed.sort_by(&:created_at)
@tasks = Task.to(profile).without_spam.closed.order('tasks.created_at DESC')
@filter = params[:filter] || {}
@tasks = filter_tasks(@filter, @tasks)
@tasks = @tasks.paginate(:per_page => Task.per_page, :page => params[:page])
@task_types = Task.closed_types_for(profile)
end
def change_responsible
......@@ -102,4 +106,28 @@ class TasksController < MyProfileController
render :json => result.map { |task| {:label => task.data[:name], :value => task.data[:name]} }
end
protected
def filter_tasks(filter, tasks)
tasks = tasks.eager_load(:requestor, :closed_by)
tasks = tasks.of(filter[:type].presence)
tasks = tasks.where(:status => filter[:status]) unless filter[:status].blank?
filter[:created_from] = Date.parse(filter[:created_from]) unless filter[:created_from].blank?
filter[:created_until] = Date.parse(filter[:created_until]) unless filter[:created_until].blank?
filter[:closed_from] = Date.parse(filter[:closed_from]) unless filter[:closed_from].blank?
filter[:closed_until] = Date.parse(filter[:closed_until]) unless filter[:closed_until].blank?
tasks = tasks.from_creation_date filter[:created_from] unless filter[:created_from].blank?
tasks = tasks.until_creation_date filter[:created_until] unless filter[:created_until].blank?
tasks = tasks.from_closed_date filter[:closed_from] unless filter[:closed_from].blank?
tasks = tasks.until_closed_date filter[:closed_until] unless filter[:closed_until].blank?
tasks = tasks.where('profiles.name LIKE ?', filter[:requestor]) unless filter[:requestor].blank?
tasks = tasks.where('closed_bies_tasks.name LIKE ?', filter[:closed_by]) unless filter[:closed_by].blank?
tasks = tasks.where('tasks.data LIKE ?', "%#{filter[:text]}%") unless filter[:text].blank?
tasks
end
end
......@@ -324,11 +324,30 @@ class Task < ActiveRecord::Base
where [environment_condition, profile_condition].compact.join(' OR ')
}
scope :from_closed_date, -> closed_from {
where('tasks.end_date >= ?', closed_from.beginning_of_day) unless closed_from.blank?
}
scope :until_closed_date, -> closed_until {
where('tasks.end_date <= ?', closed_until.end_of_day) unless closed_until.blank?
}
scope :from_creation_date, -> created_from {
where('tasks.created_at >= ?', created_from.beginning_of_day) unless created_from.blank?
}
scope :until_creation_date, -> created_until {
where('tasks.created_at <= ?', created_until.end_of_day) unless created_until.blank?
}
def self.pending_types_for(profile)
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
......
<div class="title">
<%= task_information(task) %>
</div>
<div class="status">
<%= _(Task::Status.names[task.status]) %>
</div>
<div class="dates">
<span class="created">
<span class="label"><%= _('Created:') %></span>
<span class="value"><%= show_date(task.created_at) %></span>
</span>
&nbsp; &#151; &nbsp;
<span class="processed">
<span class="label"><%= _('Processed:') %></span>
<span class="value"><%= show_date(task.end_date) %></span>
</span>
</div>
<% if task.closed_by.present? %>
<div class="closed-by">
<span class="label"><%= _('Closed by:') %></span>
<span class="value"><%= link_to(task.closed_by.name, task.closed_by.url) %></span>
</div>
<% end %>
......@@ -57,7 +57,9 @@
<% end %>
<div class="task_boxes">
<%= render :partial => 'task', :collection => @tasks %>
<% @tasks.each do |task| %>
<%= render :partial => partial_for_class(task.class, nil, nil), :locals => {:task => task} %>
<% end %>
</div>
<% unless @view_only %>
......
<%= stylesheet_link_tag 'tasks' %>
<div class="task-processed">
<h1><%= _("%s's processed tasks") % profile.name %></h1>
<div class="task-processed-filter">
<%
type_collection = [[nil, _('All')]] + @task_types
type_collection.map!{|first,last| [last,first]}
%>
<%= form_tag '#', :method => 'get' do %>
<%= field_set_tag _('Filter'), :class => 'filter_fields' do %>
<div>
<%= labelled_form_field(_('Type of task')+': ', select_tag('filter[type]', options_for_select(type_collection, @filter[:type]), {:id => 'filter-type'})) %>
<%= labelled_form_field(_('Status')+': ', select_tag('filter[status]', options_for_select([[_('Any'), nil], [_(Task::Status.names[Task::Status::CANCELLED]), 2], [_(Task::Status.names[Task::Status::FINISHED]), 3] ], @filter[:status]))) %>
</div>
<div>
<%= labelled_form_field(_('Text Filter:'), text_field_tag('filter[text]', @filter[:text])) %>
</div>
<div>
<%= labelled_form_field(_('Requestor:'), text_field_tag('filter[requestor]', @filter[:requestor])) %>
<%= labelled_form_field(_('Closed by:'), text_field_tag('filter[closed_by]', @filter[:closed_by])) %>
</div>
<%= labelled_form_field(_('Creation date'), date_range_field('filter[created_from]', 'filter[created_until]', @filter[:created_from], @filter[:created_until], { :change_month => true, :change_year => true, :date_format => 'yy-mm-dd' }, { :size => 14, :from_id => 'filter_created_from', :to_id => 'filter_created_until' })) %>
<%= labelled_form_field(_('Processed date'), date_range_field('filter[closed_from]', 'filter[closed_until]', @filter[:closed_from], @filter[:closed_until], { :change_month => true, :change_year => true, :date_format => 'yy-mm-dd' }, { :size => 14, :from_id => 'filter_closed_from', :to_id => 'filter_closed_until' })) %>
<div class="actions">
<%= submit_button(:search, _('Search')) %>
</div>
<% end %>
<% end %>
</div>
<p>
<% if @tasks.empty? %>
<em><%= _('No processed tasks.') %></em>
<% else %>
<ul>
<ul class="task-list">
<% @tasks.each do |item| %>
<li>
<strong><%= task_information(item) %></strong> <br/>
<small>
<%= _('Created:') +' '+ show_date(item.created_at) %>
&nbsp; &#151; &nbsp;
<%= _('Processed:') +' '+ show_date(item.end_date) %>
</small>
<li class="task status-<%= item.status%>">
<%= render :partial => partial_for_class(item.class, nil, 'processed'), :locals => {:task => item} %>
</li>
<% end %>
</ul>
<%= pagination_links(@tasks)%>
<% end %>
</p>
<% button_bar do %>
<%= button(:back, _('Back'), :action => 'index') %>
<% end %>
</div>
......@@ -82,3 +82,47 @@ div.pending-tasks {
.task_responsible {
text-align: right;
}
.task-processed li {
background-color: rgb(240, 240, 240);
border-radius: 8px;
margin: 10px 0;
list-style-type: none;
padding: 12px;
}
.task-processed .task.status-3 {
background-color: rgb(205, 252, 218);
}
.task-processed .task.status-2 {
background-color: rgb(255, 203, 203);
}
.task-processed ul {
padding: 0;
}
.task-processed .task-list .task .title {
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
font-weight: bold;
color: rgb(44, 44, 44);
}
.task-processed .task .status {
float: right;
color: rgb(156, 156, 156);
font-weight: bold;
}
.task-processed .task .dates {
font-size: 11px;
}
.task-processed .task .closed-by {
font-size: 11px;
}
.task-processed .task .label {
font-weight: bold
}
......@@ -75,7 +75,8 @@ class TasksControllerTest < ActionController::TestCase
assert_response :success
assert_template 'processed'
assert_kind_of Array, assigns(:tasks)
assert !assigns(:tasks).nil?
assert_kind_of ActiveRecord::Relation, assigns(:tasks)
end
should 'display task created_at' do
......@@ -762,4 +763,30 @@ class TasksControllerTest < ActionController::TestCase
assert_equal [email_template], assigns(:rejection_email_templates)
end
should 'filter processed tasks by all filters' do
requestor = fast_create(Person)
closed_by = fast_create(Person)
class AnotherTask < Task; end
created_date = DateTime.now
processed_date = DateTime.now
task_params = {:status => Task::Status::FINISHED, :requestor => requestor, :target => profile, :created_at => created_date, :end_date => processed_date, :closed_by => closed_by, :data => {:field => 'some data field'}}
task = create(AnotherTask, task_params)
create(Task, task_params)
create(AnotherTask, task_params.clone.merge(:status => Task::Status::CANCELLED))
create(AnotherTask, task_params.clone.merge(:created_at => created_date - 1.day))
create(AnotherTask, task_params.clone.merge(:created_at => created_date + 1.day))
create(AnotherTask, task_params.clone.merge(:end_date => processed_date - 1.day))
create(AnotherTask, task_params.clone.merge(:end_date => processed_date + 1.day))
create(AnotherTask, task_params.clone.merge(:requestor => fast_create(Person, :name => 'another-requestor')))
create(AnotherTask, task_params.clone.merge(:closed_by => fast_create(Person, :name => 'another-closer')))
create(AnotherTask, task_params.clone.merge(:data => {:field => "other data field"}))
get :processed, :filter => {:type => AnotherTask, :status => Task::Status::FINISHED, :created_from => created_date, :created_until => created_date, :closed_from => processed_date, :closed_until => processed_date, :requestor => requestor.name, :closed_by => closed_by.name, :text => "some data field"}
assert_response :success
assert_equal [task], assigns(:tasks)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment