before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
before_filter :authorize, :only => [:show, :edit, :update, :bulk_edit, :bulk_update, :destroy]
- before_filter :find_optional_project, :only => [:new, :create, :index, :report]
+ before_filter :find_optional_issue, :only => [:new, :create]
+ before_filter :find_optional_project, :only => [:index, :report]
before_filter :authorize_global, :only => [:new, :create, :index, :report]
accept_rss_auth :index
end
end
- def find_optional_project
+ def find_optional_issue
if params[:issue_id].present?
@issue = Issue.find(params[:issue_id])
@project = @issue.project
- elsif params[:project_id].present?
+ else
+ find_optional_project
+ end
+ end
+
+ def find_optional_project
+ if params[:project_id].present?
@project = Project.find(params[:project_id])
end
rescue ActiveRecord::RecordNotFound
# Returns the TimeEntry scope for index and report actions
def time_entry_scope(options={})
- scope = @query.results_scope(options)
- if @issue
- scope = scope.on_issue(@issue)
- end
- scope
+ @query.results_scope(options)
end
def retrieve_time_entry_query
def issue_spent_hours_details(issue)
if issue.total_spent_hours > 0
+ path = project_time_entries_path(issue.project, :issue_id => "~#{issue.id}")
+
if issue.total_spent_hours == issue.spent_hours
- link_to(l_hours_short(issue.spent_hours), issue_time_entries_path(issue))
+ link_to(l_hours_short(issue.spent_hours), path)
else
s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : ""
- s << " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), issue_time_entries_path(issue)})"
+ s << " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), path})"
s.html_safe
end
end
ungrouped = []
grouped = {}
query.available_filters.map do |field, field_options|
- if [:tree, :relation].include?(field_options[:type])
+ if field_options[:type] == :relation
group = :label_relations
+ elsif field_options[:type] == :tree
+ group = query.is_a?(IssueQuery) ? :label_relations : nil
elsif field =~ /^(.+)\./
# association filters
group = "field_#{$1}"
end
def _time_entries_path(project, issue, *args)
- if issue
- issue_time_entries_path(issue, *args)
- elsif project
+ if project
project_time_entries_path(project, *args)
else
time_entries_path(*args)
end
def _report_time_entries_path(project, issue, *args)
- if issue
- report_issue_time_entries_path(issue, *args)
- elsif project
+ if project
report_project_time_entries_path(project, *args)
else
report_time_entries_path(*args)
module TimelogHelper
include ApplicationHelper
- def render_timelog_breadcrumb
- links = []
- links << link_to(l(:label_project_all), {:project_id => nil, :issue_id => nil})
- links << link_to(h(@project), {:project_id => @project, :issue_id => nil}) if @project
- if @issue
- if @issue.visible?
- links << link_to_issue(@issue, :subject => false)
- else
- links << "##{@issue.id}"
- end
- end
- breadcrumb links
- end
-
# Returns a collection of activities for a select field. time_entry
# is optional and will be used to check if the selected TimeEntryActivity
# is active.
next unless expression =~ /^#{Regexp.escape(operator)}(.*)$/
values = $1
add_filter field, operator, values.present? ? values.split('|') : ['']
- end || add_filter(field, '=', expression.split('|'))
+ end || add_filter(field, '=', expression.to_s.split('|'))
end
# Add multiple filters using +add_filter+
) unless project_values.empty?
end
end
+
+ add_available_filter("issue_id", :type => :tree, :label => :label_issue)
+
principals.uniq!
principals.sort!
users = principals.select {|p| p.is_a?(User)}
includes(:activity).
references(:activity)
end
+
+ def sql_for_issue_id_field(field, operator, value)
+ case operator
+ when "="
+ "#{TimeEntry.table_name}.issue_id = #{value.first.to_i}"
+ when "~"
+ issue = Issue.where(:id => value.first.to_i).first
+ if issue && (issue_ids = issue.self_and_descendants.pluck(:id)).any?
+ "#{TimeEntry.table_name}.issue_id IN (#{issue_ids.join(',')})"
+ else
+ "1=0"
+ end
+ when "!*"
+ "#{TimeEntry.table_name}.issue_id IS NULL"
+ when "*"
+ "#{TimeEntry.table_name}.issue_id IS NOT NULL"
+ end
+ end
def sql_for_activity_id_field(field, operator, value)
condition_on_id = sql_for_field(field, operator, value, Enumeration.table_name, 'id')
</div>
<div class="tabs hide-when-print">
-<% query_params = params.slice(:f, :op, :v, :sort, :query_id) %>
+<% query_params = request.query_parameters %>
<ul>
- <li><%= link_to(l(:label_details), _time_entries_path(@project, @issue, query_params),
+ <li><%= link_to(l(:label_details), _time_entries_path(@project, nil, :params => query_params),
:class => (action_name == 'index' ? 'selected' : nil)) %></li>
- <li><%= link_to(l(:label_report), _report_time_entries_path(@project, @issue, query_params),
+ <li><%= link_to(l(:label_report), _report_time_entries_path(@project, nil, :params => query_params),
:class => (action_name == 'report' ? 'selected' : nil)) %></li>
</ul>
</div>
:class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project, :global => true) %>
</div>
-<%= render_timelog_breadcrumb %>
-
<h2><%= @query.new_record? ? l(:label_spent_time) : @query.name %></h2>
-<%= form_tag(params.slice(:project_id, :issue_id), :method => :get, :id => 'query_form') do %>
+<%= form_tag(_time_entries_path(@project, nil), :method => :get, :id => 'query_form') do %>
<%= render :partial => 'date_range' %>
<% end %>
:class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project, :global => true) %>
</div>
-<%= render_timelog_breadcrumb %>
-
<h2><%= @query.new_record? ? l(:label_spent_time) : @query.name %></h2>
-<%= form_tag(params.slice(:project_id, :issue_id), :method => :get, :id => 'query_form') do %>
+<%= form_tag(_report_time_entries_path(@project, nil), :method => :get, :id => 'query_form') do %>
<% @report.criteria.each do |criterion| %>
<%= hidden_field_tag 'criteria[]', criterion, :id => nil %>
<% end %>
match 'bulk_edit', :via => [:get, :post]
post 'bulk_update'
end
- resources :time_entries, :controller => 'timelog', :except => [:show, :edit, :update, :destroy] do
- collection do
- get 'report'
- end
- end
+ resources :time_entries, :controller => 'timelog', :only => [:new, :create]
shallow do
resources :relations, :controller => 'issue_relations', :only => [:index, :show, :create, :destroy]
end
assert_equal "4.25", "%.2f" % assigns(:report).total_hours
end
- def test_report_at_issue_level
- get :report, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"]
- assert_response :success
- assert_template 'report'
- assert_not_nil assigns(:report)
- assert_equal "154.25", "%.2f" % assigns(:report).total_hours
- assert_select 'form#query_form[action=?]', '/issues/1/time_entries/report'
- end
-
def test_report_by_week_should_use_commercial_year
TimeEntry.delete_all
TimeEntry.generate!(:hours => '2', :spent_on => '2009-12-25') # 2009-52
assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
end
- def test_index_at_issue_level
- get :index, :issue_id => 1
- assert_response :success
- assert_template 'index'
- assert_not_nil assigns(:entries)
- assert_equal 2, assigns(:entries).size
- assert_not_nil assigns(:total_hours)
- assert_equal 154.25, assigns(:total_hours)
- # display all time
- assert_nil assigns(:from)
- assert_nil assigns(:to)
- assert_select 'form#query_form[action=?]', '/issues/1/time_entries'
- end
-
def test_index_should_sort_by_spent_on_and_created_on
t1 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:00:00', :activity_id => 10)
t2 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:05:00', :activity_id => 10)
end
end
- def test_index_at_issue_level_should_include_csv_export_dialog
- get :index, :issue_id => 3
- assert_response :success
-
- assert_select '#csv-export-options' do
- assert_select 'form[action=?][method=get]', '/issues/3/time_entries.csv'
- end
- end
-
def test_index_csv_all_projects
with_settings :date_format => '%m/%d/%Y' do
get :index, :format => 'csv'
end
def test_timelogs_scoped_under_issues
- should_route 'GET /issues/234/time_entries' => 'timelog#index', :issue_id => '234'
- should_route 'GET /issues/234/time_entries.csv' => 'timelog#index', :issue_id => '234', :format => 'csv'
- should_route 'GET /issues/234/time_entries.atom' => 'timelog#index', :issue_id => '234', :format => 'atom'
- should_route 'GET /issues/234/time_entries/new' => 'timelog#new', :issue_id => '234'
+ should_route 'GET /issues/234/time_entries/new' => 'timelog#new', :issue_id => '234'
should_route 'POST /issues/234/time_entries' => 'timelog#create', :issue_id => '234'
end
should_route 'GET /projects/foo/time_entries/report' => 'timelog#report', :project_id => 'foo'
should_route 'GET /projects/foo/time_entries/report.csv' => 'timelog#report', :project_id => 'foo', :format => 'csv'
-
- should_route 'GET /issues/234/time_entries/report' => 'timelog#report', :issue_id => '234'
- should_route 'GET /issues/234/time_entries/report.csv' => 'timelog#report', :issue_id => '234', :format => 'csv'
end
def test_timelogs_bulk_edit
def test_time_entries_path
assert_equal '/projects/ecookbook/time_entries', _time_entries_path(Project.find(1), nil)
- assert_equal '/issues/1/time_entries', _time_entries_path(Project.find(1), Issue.find(1))
- assert_equal '/issues/1/time_entries', _time_entries_path(nil, Issue.find(1))
assert_equal '/time_entries', _time_entries_path(nil, nil)
end
def test_report_time_entries_path
assert_equal '/projects/ecookbook/time_entries/report', _report_time_entries_path(Project.find(1), nil)
- assert_equal '/issues/1/time_entries/report', _report_time_entries_path(Project.find(1), Issue.find(1))
- assert_equal '/issues/1/time_entries/report', _report_time_entries_path(nil, Issue.find(1))
assert_equal '/time_entries/report', _report_time_entries_path(nil, nil)
end