##// END OF EJS Templates
Added an active field track if an Enumeration is active on the frontend view....
Added an active field track if an Enumeration is active on the frontend view. * Changed TimelogHelper#activity_collection_for_select_options to only use active TimeEntryActivities. * Changed TimelogHelper#activity_collection_for_select_options to return a blank option if the time_entry's current activity is inactive. #4077 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2946 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r2832:e76d4c5c4c3f
r2832:e76d4c5c4c3f
Show More
timelog_helper.rb
171 lines | 6.1 KiB | text/x-ruby | RubyLexer
/ app / helpers / timelog_helper.rb
Jean-Philippe Lang
Added time report....
r569 # redMine - project management software
# Copyright (C) 2006 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Jean-Philippe Lang
Simple time tracking functionality added. Time can be logged at issue or project level....
r365 module TimelogHelper
Jean-Philippe Lang
Fixed: Details time log report CSV export doesn't honour date format from settings (patch #2466 by Russell Hind)....
r2300 include ApplicationHelper
Jean-Philippe Lang
Adds cross-project time reports support (#994)....
r1777 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
links << link_to_issue(@issue) if @issue
breadcrumb links
end
Eric Davis
Added an active field track if an Enumeration is active on the frontend view....
r2832
# 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.
def activity_collection_for_select_options(time_entry=nil)
activities = TimeEntryActivity.active
Jean-Philippe Lang
Addq "please select" to activity select box if no activity is set as default (#937)....
r1588 collection = []
Eric Davis
Added an active field track if an Enumeration is active on the frontend view....
r2832 if time_entry && !time_entry.activity.active?
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ]
else
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default)
end
Jean-Philippe Lang
Addq "please select" to activity select box if no activity is set as default (#937)....
r1588 activities.each { |a| collection << [a.name, a.id] }
collection
end
Jean-Philippe Lang
Added time report....
r569 def select_hours(data, criteria, value)
Jean-Philippe Lang
Show timelog reports for non-versioned issues (#3051)....
r2554 if value.to_s.empty?
data.select {|row| row[criteria].blank? }
else
data.select {|row| row[criteria] == value}
end
Jean-Philippe Lang
Added time report....
r569 end
def sum_hours(data)
sum = 0
data.each do |row|
sum += row['hours'].to_f
end
sum
end
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159
def options_for_period_select(value)
options_for_select([[l(:label_all_time), 'all'],
[l(:label_today), 'today'],
[l(:label_yesterday), 'yesterday'],
[l(:label_this_week), 'current_week'],
[l(:label_last_week), 'last_week'],
[l(:label_last_n_days, 7), '7_days'],
[l(:label_this_month), 'current_month'],
[l(:label_last_month), 'last_month'],
[l(:label_last_n_days, 30), '30_days'],
[l(:label_this_year), 'current_year']],
value)
end
def entries_to_csv(entries)
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
Jean-Philippe Lang
Adds a key in lang files (general_csv_decimal_separator) to set the decimal separator (point or comma) in csv exports (#1372)....
r1577 decimal_separator = l(:general_csv_decimal_separator)
Jean-Philippe Lang
Adds custom fields to the time entries csv export....
r1673 custom_fields = TimeEntryCustomField.find(:all)
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 export = StringIO.new
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
# csv header fields
headers = [l(:field_spent_on),
l(:field_user),
l(:field_activity),
Jean-Philippe Lang
Propagates time tracking to the parent project (closes #433). Time report enhancements....
r1162 l(:field_project),
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 l(:field_issue),
l(:field_tracker),
l(:field_subject),
l(:field_hours),
l(:field_comments)
]
Jean-Philippe Lang
Adds custom fields to the time entries csv export....
r1673 # Export custom fields
headers += custom_fields.collect(&:name)
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
# csv lines
entries.each do |entry|
Jean-Philippe Lang
Fixed: Details time log report CSV export doesn't honour date format from settings (patch #2466 by Russell Hind)....
r2300 fields = [format_date(entry.spent_on),
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 entry.user,
entry.activity,
Jean-Philippe Lang
Propagates time tracking to the parent project (closes #433). Time report enhancements....
r1162 entry.project,
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 (entry.issue ? entry.issue.id : nil),
(entry.issue ? entry.issue.tracker : nil),
(entry.issue ? entry.issue.subject : nil),
Jean-Philippe Lang
Adds a key in lang files (general_csv_decimal_separator) to set the decimal separator (point or comma) in csv exports (#1372)....
r1577 entry.hours.to_s.gsub('.', decimal_separator),
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 entry.comments
]
Jean-Philippe Lang
Adds custom fields to the time entries csv export....
r1673 fields += custom_fields.collect {|f| show_value(entry.custom_value_for(f)) }
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
end
end
export.rewind
export
end
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323
Jean-Philippe Lang
Custom fields (list and boolean) can be used as criteria in time report (#1012)....
r1325 def format_criteria_value(criteria, value)
value.blank? ? l(:label_none) : ((k = @available_criterias[criteria][:klass]) ? k.find_by_id(value.to_i) : format_value(value, @available_criterias[criteria][:format]))
end
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 def report_to_csv(criterias, periods, hours)
export = StringIO.new
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
# Column headers
headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
headers += periods
headers << l(:label_total)
csv << headers.collect {|c| to_utf8(c) }
# Content
report_criteria_to_csv(csv, criterias, periods, hours)
# Total row
row = [ l(:label_total) ] + [''] * (criterias.size - 1)
total = 0
periods.each do |period|
sum = sum_hours(select_hours(hours, @columns, period.to_s))
total += sum
row << (sum > 0 ? "%.2f" % sum : '')
end
row << "%.2f" %total
csv << row
end
export.rewind
export
end
def report_criteria_to_csv(csv, criterias, periods, hours, level=0)
Jean-Philippe Lang
Custom fields (list and boolean) can be used as criteria in time report (#1012)....
r1325 hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value|
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 hours_for_value = select_hours(hours, criterias[level], value)
next if hours_for_value.empty?
row = [''] * level
Jean-Philippe Lang
Custom fields (list and boolean) can be used as criteria in time report (#1012)....
r1325 row << to_utf8(format_criteria_value(criterias[level], value))
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 row += [''] * (criterias.length - level - 1)
total = 0
periods.each do |period|
sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s))
total += sum
row << (sum > 0 ? "%.2f" % sum : '')
end
row << "%.2f" %total
csv << row
if criterias.length > level + 1
report_criteria_to_csv(csv, criterias, periods, hours_for_value, level + 1)
end
end
end
def to_utf8(s)
@ic ||= Iconv.new(l(:general_csv_encoding), 'UTF-8')
begin; @ic.iconv(s.to_s); rescue; s.to_s; end
end
Jean-Philippe Lang
Simple time tracking functionality added. Time can be logged at issue or project level....
r365 end