Simplify stats projects view

Use `each_with_index` instead of hand-wrought index to loop through
projects, and use a partial for the duplicated empty list items.
This commit is contained in:
Katrina Owen 2013-03-02 00:38:54 -05:00
parent 2686a0d3b5
commit 254179b4c8
2 changed files with 15 additions and 33 deletions

View file

@ -0,0 +1,3 @@
<% from.upto 10 do |i| -%>
<%= i -%> - <%=t('common.not_available_abbr')%> (<%=t('common.not_available_abbr')%>) <br/>
<% end -%>

View file

@ -1,44 +1,23 @@
<div class="stats_module">
<h3><%= t('stats.top10_projects') %></h3>
<% i=0
@projects_and_actions.each do |p|
i+=1 -%>
<%= i -%> - <%= link_to p.name, {:controller => "projects", :action => "show", :id => p.id}%> (<%=p.count %> <%= t('common.actions_midsentence', :count => p.count) %>) <br/>
<% end
if i < 10
(i+1).upto 10 do |j| -%>
<%= j -%> - <%=t('common.not_available_abbr')%> (<%=t('common.not_available_abbr')%>) <br/>
<% end
end
-%>
<% @projects_and_actions.each_with_index do |p, i| -%>
<%= i + 1 -%> - <%= link_to p.name, {:controller => "projects", :action => "show", :id => p.id}%> (<%=p.count %> <%= t('common.actions_midsentence', :count => p.count) %>) <br/>
<% end -%>
<%= render :partial => 'null_list_item', :locals => {:from => @projects_and_actions.size + 1} -%>
</div>
<div class="stats_module">
<h3><%= t('stats.top10_projects_30days') %></h3>
<% i=0
@projects_and_actions_last30days.each do |p|
i+=1 -%>
<%= i -%> - <%= link_to p.name, {:controller => "projects", :action => "show", :id => p.id} %> (<%=p.count %> <%= t('common.actions_midsentence', :count => p.count) %>) <br/>
<% end
if i < 10
(i+1).upto 10 do |j| -%>
<%= j -%> - <%=t('common.not_available_abbr')%> (<%=t('common.not_available_abbr')%>) <br/>
<% end
end
-%>
<% @projects_and_actions_last30days.each_with_index do |p, i| -%>
<%= i + 1 -%> - <%= link_to p.name, {:controller => "projects", :action => "show", :id => p.id} %> (<%=p.count %> <%= t('common.actions_midsentence', :count => p.count) %>) <br/>
<% end -%>
<%= render :partial => 'null_list_item', :locals => {:from => @projects_and_actions_last30days.size + 1} -%>
</div>
<div class="stats_module">
<h3><%= t('stats.top10_longrunning') %></h3>
<% i=0
@projects_and_runtime.each do |p|
i+=1 -%>
<%= i -%> - <%= link_to p.name, {:controller => "projects", :action => "show", :id => p.id} %> (<%=p.age_in_days %> <%= t('common.days_midsentence', :count => p.age_in_days) %>) <br/>
<% end
if i < 10
(i+1).upto 10 do |j| -%>
<%= j -%> - <%=t('common.not_available_abbr')%> (<%=t('common.not_available_abbr')%>) <br/>
<% end
end
-%>
<% @projects_and_runtime.each_with_index do |p, i| -%>
<%= i + 1 -%> - <%= link_to p.name, {:controller => "projects", :action => "show", :id => p.id} %> (<%=p.age_in_days %> <%= t('common.days_midsentence', :count => p.age_in_days) %>) <br/>
<% end -%>
<%= render :partial => 'null_list_item', :locals => {:from => @projects_and_runtime.size + 1} -%>
</div>