Patch #1582 » add_time_spent_column_to_issues_withpermissions.patch
| app/controllers/issues_controller.rb | ||
|---|---|---|
|
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
|
||
|
:order => sort_clause,
|
||
|
:offset => @issue_pages.current.offset,
|
||
|
:limit => limit)
|
||
|
:limit => limit,
|
||
|
:joins => 'LEFT OUTER JOIN time_entries ON issues.id = time_entries.issue_id',
|
||
|
:group => 'issues.id'
|
||
|
)
|
||
|
@issue_count_by_group = @query.issue_count_by_group
|
||
|
|
||
|
respond_to do |format|
|
||
| app/helpers/issues_helper.rb | ||
|---|---|---|
|
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||
|
decimal_separator = l(:general_csv_decimal_separator)
|
||
|
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||
|
# csv header fields
|
||
|
headers = [ "#",
|
||
|
l(:field_status),
|
||
|
l(:field_project),
|
||
|
l(:field_tracker),
|
||
|
l(:field_priority),
|
||
|
l(:field_subject),
|
||
|
l(:field_assigned_to),
|
||
|
l(:field_category),
|
||
|
l(:field_fixed_version),
|
||
|
l(:field_author),
|
||
|
l(:field_start_date),
|
||
|
l(:field_due_date),
|
||
|
l(:field_done_ratio),
|
||
|
l(:field_estimated_hours),
|
||
|
l(:field_parent_issue),
|
||
|
l(:field_created_on),
|
||
|
l(:field_updated_on)
|
||
|
]
|
||
|
if User.current.allowed_to?(:view_time_entries, @project)
|
||
|
#if !@project.nil? || !(User.current.allowed_to?(:view_time_entries, @project))
|
||
|
# csv header fields
|
||
|
headers = [ "#",
|
||
|
l(:field_status),
|
||
|
l(:field_project),
|
||
|
l(:field_tracker),
|
||
|
l(:field_priority),
|
||
|
l(:field_subject),
|
||
|
l(:field_assigned_to),
|
||
|
l(:field_category),
|
||
|
l(:field_fixed_version),
|
||
|
l(:field_author),
|
||
|
l(:field_start_date),
|
||
|
l(:field_due_date),
|
||
|
l(:field_done_ratio),
|
||
|
l(:field_estimated_hours),
|
||
|
l(:field_spent_hours),
|
||
|
l(:field_parent_issue),
|
||
|
l(:field_created_on),
|
||
|
l(:field_updated_on)
|
||
|
]
|
||
|
else
|
||
|
# csv header fields
|
||
|
headers = [ "#",
|
||
|
l(:field_status),
|
||
|
l(:field_project),
|
||
|
l(:field_tracker),
|
||
|
l(:field_priority),
|
||
|
l(:field_subject),
|
||
|
l(:field_assigned_to),
|
||
|
l(:field_category),
|
||
|
l(:field_fixed_version),
|
||
|
l(:field_author),
|
||
|
l(:field_start_date),
|
||
|
l(:field_due_date),
|
||
|
l(:field_done_ratio),
|
||
|
l(:field_estimated_hours),
|
||
|
l(:field_parent_issue),
|
||
|
l(:field_created_on),
|
||
|
l(:field_updated_on)
|
||
|
]
|
||
|
end
|
||
|
# Export project custom fields if project is given
|
||
|
# otherwise export custom fields marked as "For all projects"
|
||
|
custom_fields = project.nil? ? IssueCustomField.for_all : project.all_issue_custom_fields
|
||
| ... | ... | |
|
csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||
|
# csv lines
|
||
|
issues.each do |issue|
|
||
|
if User.current.allowed_to?(:view_time_entries, @project)
|
||
|
fields = [issue.id,
|
||
|
issue.status.name,
|
||
|
issue.project.name,
|
||
| ... | ... | |
|
format_date(issue.due_date),
|
||
|
issue.done_ratio,
|
||
|
issue.estimated_hours.to_s.gsub('.', decimal_separator),
|
||
|
issue.spent_hours.to_s.gsub('.', decimal_separator),
|
||
|
issue.parent_id,
|
||
|
format_time(issue.created_on),
|
||
|
format_time(issue.updated_on)
|
||
|
]
|
||
|
else
|
||
|
fields = [issue.id,
|
||
|
issue.status.name,
|
||
|
issue.project.name,
|
||
|
issue.tracker.name,
|
||
|
issue.priority.name,
|
||
|
issue.subject,
|
||
|
issue.assigned_to,
|
||
|
issue.category,
|
||
|
issue.fixed_version,
|
||
|
issue.author.name,
|
||
|
format_date(issue.start_date),
|
||
|
format_date(issue.due_date),
|
||
|
issue.done_ratio,
|
||
|
issue.estimated_hours.to_s.gsub('.', decimal_separator),
|
||
|
issue.parent_id,
|
||
|
format_time(issue.created_on),
|
||
|
format_time(issue.updated_on)
|
||
|
]
|
||
|
end
|
||
|
|
||
|
custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) }
|
||
|
fields << issue.description
|
||
|
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||
| app/helpers/queries_helper.rb | ||
|---|---|---|
|
when 'Fixnum', 'Float'
|
||
|
if column.name == :done_ratio
|
||
|
progress_bar(value, :width => '80px')
|
||
|
else
|
||
|
elsif column.name == :spent_hours
|
||
|
return issue.send :spent_hours_colored, value
|
||
|
else
|
||
|
value.to_s
|
||
|
end
|
||
|
when 'User'
|
||
| ... | ... | |
|
link_to_project value
|
||
|
when 'Version'
|
||
|
link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
|
||
|
# when 'spentHours'
|
||
|
# return issue.send : spent_hours_colored, value
|
||
|
when 'TrueClass'
|
||
|
l(:general_text_Yes)
|
||
|
when 'FalseClass'
|
||
| app/models/issue.rb | ||
|---|---|---|
|
def estimated_hours=(h)
|
||
|
write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
|
||
|
end
|
||
|
def spent_hours
|
||
|
#write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
|
||
|
@spent_hours ||= (time_entries.sum(:hours)*100).round.to_f / 100 || 0
|
||
|
end
|
||
|
def spent_hours_colored(value)
|
||
|
if (estimated_hours.nil?)
|
||
|
return ('%.2f' % value).to_s
|
||
|
elsif(value > estimated_hours)
|
||
|
return "<FONT COLOR='RED'>"+('%.2f' % value).to_s+"</FONT>"
|
||
|
else return ('%.2f' % value).to_s
|
||
|
end
|
||
|
end
|
||
|
|
||
|
SAFE_ATTRIBUTES = %w(
|
||
|
tracker_id
|
||
| app/models/query.rb | ||
|---|---|---|
|
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
|
||
|
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
|
||
|
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
|
||
|
QueryColumn.new(:spent_hours, :sortable => "SUM(time_entries.hours)" ),
|
||
|
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio", :groupable => true),
|
||
|
QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'),
|
||
|
]
|
||
| app/views/issues/_list.rhtml | ||
|---|---|---|
|
</th>
|
||
|
<%= sort_header_tag('id', :caption => '#', :default_order => 'desc') %>
|
||
|
<% query.columns.each do |column| %>
|
||
|
<%= column_header(column) %>
|
||
|
<% if column.name == :spent_hours %>
|
||
|
<% if User.current.allowed_to?(:view_time_entries, @project) %>
|
||
|
<%= column_header(column) %>
|
||
|
<% end %>
|
||
|
<% else %>
|
||
|
<%= column_header(column) %>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
</tr></thead>
|
||
|
<% previous_group = false %>
|
||
| ... | ... | |
|
<tr id="issue-<%= issue.id %>" class="hascontextmenu <%= cycle('odd', 'even') %> <%= issue.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
|
||
|
<td class="checkbox"><%= check_box_tag("ids[]", issue.id, false, :id => nil) %></td>
|
||
|
<td class="id"><%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %></td>
|
||
|
<% query.columns.each do |column| %><%= content_tag 'td', column_content(column, issue), :class => column.name %><% end %>
|
||
|
<% query.columns.each do |column| %>
|
||
|
<% if column.name == :spent_hours %>
|
||
|
<% if User.current.allowed_to?(:view_time_entries, @project) %>
|
||
|
<%= content_tag 'td', column_content(column, issue) , :class => column.name %>
|
||
|
<% end %>
|
||
|
<% else %>
|
||
|
<%= content_tag 'td', column_content(column, issue), :class => column.name %>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
</tr>
|
||
|
<% end -%>
|
||
|
</tbody>
|
||
| app/views/issues/index.rhtml | ||
|---|---|---|
|
<% other_formats_links do |f| %>
|
||
|
<%= f.link_to 'Atom', :url => { :project_id => @project, :query_id => (@query.new_record? ? nil : @query), :key => User.current.rss_key } %>
|
||
|
<%= f.link_to 'CSV', :url => { :project_id => @project } %>
|
||
|
<%= f.link_to 'PDF', :url => { :project_id => @project } %>
|
||
|
<% if User.current.allowed_to?(:view_time_entries, @project) %>
|
||
|
<%= f.link_to 'PDF', :url => { :project_id => @project } %>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
field_author: Author
|
||
|
field_created_on: Created
|
||
|
field_updated_on: Updated
|
||
|
field_spent_hours: Spent hours
|
||
|
field_field_format: Format
|
||
|
field_is_for_all: For all projects
|
||
|
field_possible_values: Possible values
|
||
| config/locales/fr.yml | ||
|---|---|---|
|
field_author: Auteur
|
||
|
field_created_on: "Créé "
|
||
|
field_updated_on: "Mis-à-jour "
|
||
|
field_spent_hours: "Temps passé"
|
||
|
field_field_format: Format
|
||
|
field_is_for_all: Pour tous les projets
|
||
|
field_possible_values: Valeurs possibles
|
||