2008年4月7日月曜日

Redmineの工数詳細を100件に制限

工数登録が多くなると表示がかなり遅くなるので、
100 件で制限しておく。
全部表示したい場合は csv を指定すれば OK。

=====================================
app/controllers/timelog_controller.rb
=====================================

def details
sort_init 'spent_on', 'desc'
sort_update

####### 変更開始
#@entries = (@issue ? @issue : @project).time_entries.find(:all, :include => [:activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], :order => sort_clause)
find_param = [:all, {:include => [:activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], :order => sort_clause}]
if 'csv' != params[:export]
find_param[1][:limit] = 100
end
@entries = (@issue ? @issue : @project).time_entries.find(*find_param)
####### ここまで

@total_hours = @entries.inject(0) { |sum,entry| sum + entry.hours }
@owner_id = User.current.id

send_csv and return if 'csv' == params[:export]
render :action => 'details', :layout => false if request.xhr?
end