##// END OF EJS Templates
Load RMagick before the gantt helper (#12097)....
Load RMagick before the gantt helper (#12097). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10915 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r10372:3a178a42cfc0
r10688:bd10a712177e
Show More
timelog_helper.rb
197 lines | 7.2 KiB | text/x-ruby | RubyLexer
/ app / helpers / timelog_helper.rb
Jean-Philippe Lang
Added encoding comment to helpers (#9792)....
r8090 # encoding: utf-8
#
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791 # Redmine - project management software
Jean-Philippe Lang
Copyright update....
r9453 # Copyright (C) 2006-2012 Jean-Philippe Lang
Jean-Philippe Lang
Added time report....
r569 #
# 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.
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791 #
Jean-Philippe Lang
Added time report....
r569 # 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.
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791 #
Jean-Philippe Lang
Added time report....
r569 # 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
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791
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
Jean-Philippe Lang
Don't reveal issue subjects if user is only allowed to view spent time (#3187)....
r2929 if @issue
if @issue.visible?
links << link_to_issue(@issue, :subject => false)
else
links << "##{@issue.id}"
end
end
Jean-Philippe Lang
Adds cross-project time reports support (#994)....
r1777 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.
Eric Davis
Changed the Timelogs to use both the Systemwide and Project specific TimeEntryActivities...
r2834 def activity_collection_for_select_options(time_entry=nil, project=nil)
project ||= @project
if project.nil?
Jean-Philippe Lang
Changes misleading scopes on Enumeration....
r2969 activities = TimeEntryActivity.shared.active
Eric Davis
Changed the Timelogs to use both the Systemwide and Project specific TimeEntryActivities...
r2834 else
activities = project.activities
end
Jean-Philippe Lang
Addq "please select" to activity select box if no activity is set as default (#937)....
r1588 collection = []
Eric Davis
Changed the Timelogs to use both the Systemwide and Project specific TimeEntryActivities...
r2834 if time_entry && time_entry.activity && !time_entry.activity.active?
Eric Davis
Added an active field track if an Enumeration is active on the frontend view....
r2832 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
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791
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? }
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791 else
Jean-Philippe Lang
Fixes time report with JRuby (#5404)....
r3594 data.select {|row| row[criteria].to_s == value.to_s}
Jean-Philippe Lang
Show timelog reports for non-versioned issues (#3051)....
r2554 end
Jean-Philippe Lang
Added time report....
r569 end
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791
Jean-Philippe Lang
Added time report....
r569 def sum_hours(data)
sum = 0
data.each do |row|
sum += row['hours'].to_f
end
sum
end
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791
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'],
Jean-Philippe Lang
Add "last 2 weeks" preset to time entries reporting (#11862)....
r10372 [l(:label_last_n_weeks, 2), 'last_2_weeks'],
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 [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
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 def entries_to_csv(entries)
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
Use FasterCSV or ruby1.9 CSV instead of ruby1.8 builtin CSV....
r2893 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 # 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)
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791
Toshi MARUYAMA
fix malformed time log csv encoding in case of unable to convert (#8549)...
r7699 csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8(
c.to_s,
l(:general_csv_encoding) ) }
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 # 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
Display of multi custom fields....
r8606 fields += custom_fields.collect {|f| show_value(entry.custom_field_values.detect {|v| v.custom_field_id == f.id}) }
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791
Toshi MARUYAMA
fix malformed time log csv encoding in case of unable to convert (#8549)...
r7699 csv << fields.collect {|c| Redmine::CodesetUtil.from_utf8(
c.to_s,
l(:general_csv_encoding) ) }
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 end
end
export
end
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 def format_criteria_value(criteria_options, value)
Jean-Philippe Lang
Don't reveal issue subjects if user is only allowed to view spent time (#3187)....
r2929 if value.blank?
Jean-Philippe Lang
Display "none" inside square brackets....
r8524 "[#{l(:label_none)}]"
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 elsif k = criteria_options[:klass]
Jean-Philippe Lang
Don't reveal issue subjects if user is only allowed to view spent time (#3187)....
r2929 obj = k.find_by_id(value.to_i)
if obj.is_a?(Issue)
Toshi MARUYAMA
backout r6356: HTML escape of app/helpers/timelog_helper.rb...
r7821 obj.visible? ? "#{obj.tracker} ##{obj.id}: #{obj.subject}" : "##{obj.id}"
Jean-Philippe Lang
Don't reveal issue subjects if user is only allowed to view spent time (#3187)....
r2929 else
obj
end
else
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 format_value(value, criteria_options[:format])
Jean-Philippe Lang
Don't reveal issue subjects if user is only allowed to view spent time (#3187)....
r2929 end
Jean-Philippe Lang
Custom fields (list and boolean) can be used as criteria in time report (#1012)....
r1325 end
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 def report_to_csv(report)
Toshi MARUYAMA
fix csv decimal separator of time entry csv (#8368)...
r7830 decimal_separator = l(:general_csv_decimal_separator)
Jean-Philippe Lang
Use FasterCSV or ruby1.9 CSV instead of ruby1.8 builtin CSV....
r2893 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 # Column headers
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 headers = report.criteria.collect {|criteria| l(report.available_criteria[criteria][:label]) }
headers += report.periods
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 headers << l(:label_total)
Toshi MARUYAMA
fix malformed time entry report csv encoding in case of unable to convert (#8549)...
r7700 csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8(
c.to_s,
l(:general_csv_encoding) ) }
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 # Content
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 report_criteria_to_csv(csv, report.available_criteria, report.columns, report.criteria, report.periods, report.hours)
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 # Total row
Toshi MARUYAMA
fix time entry csv last line encoding (#8549)...
r7827 str_total = Redmine::CodesetUtil.from_utf8(l(:label_total), l(:general_csv_encoding))
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 row = [ str_total ] + [''] * (report.criteria.size - 1)
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 total = 0
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 report.periods.each do |period|
sum = sum_hours(select_hours(report.hours, report.columns, period.to_s))
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 total += sum
Toshi MARUYAMA
fix csv decimal separator of time entry csv (#8368)...
r7830 row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '')
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 end
Toshi MARUYAMA
fix csv decimal separator of time entry csv (#8368)...
r7830 row << ("%.2f" % total).gsub('.',decimal_separator)
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 csv << row
end
export
end
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/timelog_helper.rb....
r6791
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 def report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours, level=0)
Toshi MARUYAMA
fix csv decimal separator of time entry csv (#8368)...
r7830 decimal_separator = l(:general_csv_decimal_separator)
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 hours.collect {|h| h[criteria[level]].to_s}.uniq.each do |value|
hours_for_value = select_hours(hours, criteria[level], value)
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 next if hours_for_value.empty?
row = [''] * level
Toshi MARUYAMA
fix malformed time entry report csv encoding in case of unable to convert (#8549)...
r7700 row << Redmine::CodesetUtil.from_utf8(
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 format_criteria_value(available_criteria[criteria[level]], value).to_s,
Toshi MARUYAMA
fix malformed time entry report csv encoding in case of unable to convert (#8549)...
r7700 l(:general_csv_encoding) )
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 row += [''] * (criteria.length - level - 1)
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 total = 0
periods.each do |period|
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 sum = sum_hours(select_hours(hours_for_value, columns, period.to_s))
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 total += sum
Toshi MARUYAMA
fix csv decimal separator of time entry csv (#8368)...
r7830 row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '')
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 end
Toshi MARUYAMA
fix csv decimal separator of time entry csv (#8368)...
r7830 row << ("%.2f" % total).gsub('.',decimal_separator)
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 csv << row
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 if criteria.length > level + 1
report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours_for_value, level + 1)
Jean-Philippe Lang
CSV export added to timelog report (#1009)....
r1323 end
end
end
Jean-Philippe Lang
Simple time tracking functionality added. Time can be logged at issue or project level....
r365 end