OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/helpers/costlog_helper.rb

86 lines
3.1 KiB

module CostlogHelper
include TimelogHelper
def render_costlog_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
def cost_types_collection_for_select_options(selected_type = nil)
cost_types = CostType.all.sort
collection = []
collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless cost_types.detect(&:is_default)
cost_types.each { |t| collection << [t.name, t.id] }
collection
end
def user_collection_for_select_options(options = {})
users = @project.assignable_users
collection = []
users.each { |u| collection << [u.name, u.id] }
collection
end
def entries_to_csv(entries)
# TODO
raise( NotImplementedError, "entries_to_csv is not implemented yet" )
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
decimal_separator = l(:general_csv_decimal_separator)
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_project),
l(:field_issue),
l(:field_tracker),
l(:field_subject),
l(:field_comments),
l(:field_cost_type),
l(:field_unit_price),
l(:field_units),
l(:field_overall_costs)
]
csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
# csv lines
entries.each do |entry|
fields = [format_date(entry.spent_on),
entry.user,
entry.project,
(entry.issue ? entry.issue.id : nil),
(entry.issue ? entry.issue.tracker : nil),
(entry.issue ? entry.issue.subject : nil),
entry.comments,
entry.cost_type.name,
User.current.allowed_to?(:view_unit_price, entry.project) ? entry.cost_type.unit_price.to_s.gsub('.', decimal_separator): "-",
entry.units.to_s.gsub('.', decimal_separator),
User.current.allowed_to?(:view_unit_price, entry.project) ? entry.cost.to_s.gsub('.', decimal_separator): "-"
]
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
end
end
export.rewind
export
end
def extended_progress_bar(pcts, options={})
return progress_bar(pcts, options) unless pcts.is_a?(Numeric) && pcts > 100
width = options[:width] || '100px;'
legend = options[:legend] || ''
content_tag('table',
content_tag('tr',
content_tag('td', '', :style => "width: #{(100 / pcts).round}%;", :class => 'closed') +
content_tag('td', '', :style => "width: #{100 - (100 / pcts).round}%;", :class => 'exceeded')
), :class => 'progress', :style => "width: #{width};") +
content_tag('p', legend, :class => 'pourcent')
end
end