Project

General

Profile

Patch #1671 » version_times_251.diff

P S, 2014-05-15 14:52

View differences:

app/helpers/versions_helper.rb (kopia robocza)
def render_issue_status_by(version, criteria)
criteria = 'tracker' unless STATUS_BY_CRITERIAS.include?(criteria)
h = Hash.new {|k,v| k[v] = [0, 0]}
begin
# Total issue count
Issue.where(:fixed_version_id => version.id).group(criteria).count.each {|c,s| h[c][0] = s}
# Open issues count
Issue.open.where(:fixed_version_id => version.id).group(criteria).count.each {|c,s| h[c][1] = s}
rescue ActiveRecord::RecordNotFound
# When grouping by an association, Rails throws this exception if there's no result (bug)
#sort them alphabetically by category name
metrics = version.get_grouped_metrics(criteria).to_a.sort {|x, y| x[0].to_s <=> y[0].to_s}
max = {}
[{:count => :total}, {:time => :total}].each do |metric_info|
metrics_group, total_metric = metric_info.to_a.flatten
max[metrics_group] = metrics.map{|item| item[1]}.map {|item| item[metrics_group]}.map {|item| item[total_metric]}.max
max[metrics_group] = 1 if max[metrics_group] == 0
end
# Sort with nil keys in last position
counts = h.keys.sort {|a,b| a.nil? ? 1 : (b.nil? ? -1 : a <=> b)}.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}}
max = counts.collect {|c| c[:total]}.max
render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max}
render :partial => 'issue_counts', :locals => {:version => version,
:criteria => criteria, :grouped_metrics => metrics, :max => max,
:spent_time_allowed => User.current.allowed_to?(:view_time_entries, @project),
}
end
def time_progress(time_info)
logger.debug "time_info[:spent] = #{time_info[:spent].inspect}"
logger.debug "time_info[:total] = #{time_info[:total].inspect}"
if (time_info[:total] != 0)
time_progress = time_info[:spent].to_f / time_info[:total]
else
time_progress = 0 #no total also means there's no spent time
end
time_progress
end
def status_by_options_for_select(value)
options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value)
app/models/version.rb (kopia robocza)
def spent_hours
@spent_hours ||= TimeEntry.joins(:issue).where("#{Issue.table_name}.fixed_version_id = ?", id).sum(:hours).to_f
end
def calc_remaining_and_total_time
@remaining_hours = 0
@total_hours = 0
get_grouped_metrics(:category).to_a.map{|item| item[1]}.map {|item| item[:time]}.each do |times|
@remaining_hours += times[:remaining]
@total_hours += times[:total]
end
end
def remaining_hours
return @remaining_hours if @remaining_hours
calc_remaining_and_total_time
@remaining_hours
end
def total_hours
return @total_hours if @total_hours
calc_remaining_and_total_time
@total_hours
end
def closed?
status == 'closed'
end
......
@closed_issues_count
end
def not_estimated_undone_count
@not_estimated_undone_count ||= Issue.count(:all, :conditions =>
["fixed_version_id = ? AND estimated_hours IS NULL AND " +
"(closed_on is null)", self.id
], :include => :status)
end
def wiki_page
if project.wiki && !wiki_page_title.blank?
@wiki_page ||= project.wiki.find_page(wiki_page_title)
......
end
end
def get_grouped_metrics(criteria)
condition = issues_version_condition
issues = Issue.find(:all, :include => [:status, criteria],
:conditions => condition)
spent_times = {}
TimeEntry.sum(:hours, :group => :issue_id, :include => :issue,
:conditions => condition).each do |issue_id, hours|
spent_times[issue_id] = hours
end
categories_metrics = {}
issues.each do |issue|
category = issue.send(criteria)
categories_metrics[category] ||= {}
categories_metrics[category][:time] ||= {:estimated => 0,
:spent => 0, :remaining => 0, :total => 0}
metrics = categories_metrics[category][:time]
estimated = issue.estimated_hours || 0
metrics[:estimated] += estimated
spent = spent_times[issue.id] || 0
metrics[:spent] += spent
remaining = issue.closed? ? 0 : estimated - spent
remaining = 0 if remaining < 0
metrics[:remaining] += remaining
metrics[:total] += (remaining + spent)
categories_metrics[category][:count] ||= {:open => 0, :closed => 0, :total => 0}
metrics = categories_metrics[category][:count]
metrics[:total] += 1
if issue.closed?
metrics[:closed] += 1
else
metrics[:open] += 1
end
end
categories_metrics
end
def issues_version_condition
["#{Issue.table_name}.fixed_version_id = ?", id]
end
private
def load_issue_counts
unless @issue_count
@open_issues_count = 0
app/views/versions/_issue_counts.html.erb (kopia robocza)
:id => 'status_by_select',
:data => {:remote => true, :method => 'post', :url => status_by_version_path(version)})).html_safe %>
</legend>
<% if counts.empty? %>
<% if grouped_metrics.empty? %>
<p><em><%= l(:label_no_data) %></em></p>
<% else %>
<table>
<% counts.each do |count| %>
<tr>
<td style="width:130px; text-align:right;">
<% if count[:group] -%>
<%= link_to(h(count[:group]), project_issues_path(version.project, :set_filter => 1, :status_id => '*', :fixed_version_id => version, "#{criteria}_id" => count[:group])) %>
<% else -%>
<%= link_to(l(:label_none), project_issues_path(version.project, :set_filter => 1, :status_id => '*', :fixed_version_id => version, "#{criteria}_id" => "!*")) %>
<% end %>
</td>
<td style="width:240px;">
<%= progress_bar((count[:closed].to_f / count[:total])*100,
:legend => "#{count[:closed]}/#{count[:total]}",
:width => "#{(count[:total].to_f / max * 200).floor}px;") %>
</td>
</tr>
<table class="category_metrics">
<% grouped_metrics.each do |metrics_group|
category, metrics = *metrics_group
%>
<% color_class = cycle('odd', 'even')%>
<tr class="header <%= color_class %>">
<td colspan="5">
<%= criteria_operator = category ? "=" : "!*"
link_to category || "[#{l(:text_not_assigned)}]",
{:controller => 'issues',
:action => 'index',
:project_id => version.project,
:set_filter => 1,
:fields => ["#{criteria}_id", "fixed_version_id", "status_id"],
:values => {"#{criteria}_id" => [category], "fixed_version_id" => [version], "status_id" => [1]},
:operators => {"#{criteria}_id" => criteria_operator, "fixed_version_id" => "=", "status_id" => "*"}
}
%>
</td>
</tr>
<tr class="<%= color_class %>">
<td><%= l(:label_issues_count) %> </td>
<% if spent_time_allowed %>
<td><%= l(:label_time) %></td>
<% end %>
<td class="metric_comment">
<span title="<%= l(:field_estimated_hours) %>">
<%= l(:label_estimated_time_short) %>
</span>
</td>
<% if spent_time_allowed %>
<td class="metric_comment">
<span title="<%= l(:label_spent_time) %>">
<%= l(:label_spent_time_short) %>
</span>
</td>
<td class="metric_comment">
<span title="<%= l(:label_remaining_time) %>">
<%= l(:label_remaining_time_short) %>
</span>
</td>
<% max_progress_width = 95 %>
<% else
max_progress_width = 150
end %>
</tr>
<tr class="<%= color_class %>">
<td class="progress count">
<%= count = metrics[:count]; progress_bar((count[:closed].to_f / count[:total])*100,
:legend =>
"#{count[:closed]}/#{count[:total]}</span>".html_safe,
:width => "#{(count[:total].to_f / max[:count] * max_progress_width).floor}px;") %>
</td>
<%
time = metrics[:time]
if spent_time_allowed %>
<td class="progress time">
<%= progress_bar(time_progress(time)*100,
:legend =>
"#{time[:spent].ceil}/#{time[:total].ceil}",
:width => "#{(time[:total] / max[:time] * max_progress_width).floor}px;") %>
</td>
<% end %>
<% hours = l(:text_hours_short) %>
<td class="metric_comment">
<span title="<%= l(:field_estimated_hours) %>">
<%= "#{time[:estimated].ceil}#{hours}" %>
</span>
</td>
<% if spent_time_allowed %>
<td class="metric_comment">
<span title="<%= l(:label_spent_time) %>">
<%= "#{time[:spent].ceil}#{hours}" %>
</span>
</td>
<td class="metric_comment">
<span title="<%= l(:label_remaining_time) %>">
<%= "#{time[:remaining].ceil}#{hours}" %>
</span>
</td>
<% end %>
</tr>
<% end %>
</table>
<% end %>
app/views/versions/show.html.erb (kopia robocza)
<th><%= l(:field_estimated_hours) %></th>
<td class="total-hours"><%= html_hours(l_hours(@version.estimated_hours)) %></td>
</tr>
<% if @version.not_estimated_undone_count > 0 %>
<tr>
<th><%= l(:label_not_estimated_and_undone) %></th>
<td class="not_estimated total-hours"><%= link_to("%s" %
[@version.not_estimated_undone_count.to_s+" "+l(:label_issue_plural).downcase, @version.not_estimated_undone_count],
{:controller => 'issues',
:action => 'index',
:project_id => @version.project,
:set_filter => 1,
:fields => ["estimated_hours", "fixed_version_id", "status_id"],
:values => {"estimated_hours" => [1], "fixed_version_id" => [@version], "status_id" => [1]},
:operators => {"estimated_hours" => "!*", "fixed_version_id" => "=", "status_id" => "o"}
}
)%></td>
</tr>
<% end %>
<% if User.current.allowed_to?(:view_time_entries, @project) %>
<tr>
<th><%= l(:label_spent_time) %></th>
<td class="total-hours"><%= html_hours(l_hours(@version.spent_hours)) %></td>
</tr>
<tr>
<th><%= l(:label_remaining_time) %></th>
<td class="total-hours"><%= html_hours(l_hours(@version.remaining_hours)) %></td>
</tr>
<tr>
<% title = "#{l(:label_spent_time)} + #{l(:label_remaining_time)}" %>
<th title="<%= title %>"><%= l(:label_current_total_time) %></th>
<td class="total-hours" "><%= html_hours(l_hours(@version.total_hours)) %></td>
</tr>
<% end %>
</table>
</fieldset>
config/locales/en.yml (kopia robocza)
setting_enabled_scm: Enabled SCM
setting_mail_handler_body_delimiters: "Truncate emails after one of these lines"
setting_mail_handler_api_enabled: Enable WS for incoming emails
label_remaining_time: Remaining time
label_current_total_time: Total
label_estimated_time_short: Est.
label_spent_time_short: Spent
label_remaining_time_short: Rem.
label_issues_count: Count
label_not_estimated_and_undone: Not estimated
label_time: Time
setting_mail_handler_api_key: API key
setting_sequential_project_identifiers: Generate sequential project identifiers
setting_gravatar_enabled: Use Gravatar user icons
......
label_open_issues_plural: open
label_closed_issues: closed
label_closed_issues_plural: closed
label_done_issues: done
label_done_issues_plural: done
label_undone_issues: undone
label_undone_issues_plural: undone
label_x_open_issues_abbr_on_total:
zero: 0 open / %{total}
one: 1 open / %{total}
config/locales/pl.yml (kopia robocza)
label_closed_issues_plural234: zamknięte
label_closed_issues_plural5: zamknięte
label_closed_issues_plural: zamknięte
label_done_issues: done
label_done_issues_plural: done
label_undone_issues: undone
label_undone_issues_plural: undone
label_x_open_issues_abbr_on_total:
zero: 0 otwartych / %{total}
one: 1 otwarty / %{total}
......
setting_login_required: Wymagane zalogowanie
setting_mail_from: Adres e-mail wysyłki
setting_mail_handler_api_enabled: Uaktywnij usługi sieciowe (WebServices) dla poczty przychodzącej
label_remaining_time: Pozostały czas
label_current_total_time: Suma
label_estimated_time_short: Szacz.
label_spent_time_short: Przepr.
label_remaining_time_short: Pozost.
label_issues_count: Count
label_time: Czas
label_not_estimated_and_undone: Nie oszacowane
text_hours_short: h
text_not_assigned: Nie przydzielone
setting_mail_handler_api_key: Klucz API
setting_per_page_options: Opcje ilości obiektów na stronie
setting_plain_text_mail: tylko tekst (bez HTML)
public/stylesheets/application.css (kopia robocza)
div#version-summary fieldset { margin-bottom: 1em; }
div#version-summary fieldset.time-tracking table { width:100%; }
div#version-summary th, div#version-summary td.total-hours { text-align: right; }
.not_estimated a { color: red; }
table#time-report td.hours, table#time-report th.period, table#time-report th.total { text-align: right; padding-right: 0.5em; }
table#time-report tbody tr.subtotal { font-style: italic; color:#777;}
(5-5/6)