Merge pull request #163 from kytrinyx/stats-project-view

Simplify stats project view
This commit is contained in:
Matt Rogers 2013-03-01 22:02:39 -08:00
commit ae42f9c076
5 changed files with 19 additions and 47 deletions

View file

@ -481,7 +481,7 @@ class StatsController < ApplicationController
# get the first 10 projects and their running time (creation date versus
# now())
@projects_and_runtime_sql = current_user.projects.find_by_sql(
@projects_and_runtime = current_user.projects.find_by_sql(
"SELECT id, name, created_at "+
"FROM projects "+
"WHERE state='active' "+
@ -489,16 +489,6 @@ class StatsController < ApplicationController
"ORDER BY created_at ASC "+
"LIMIT 10"
)
i=0
@projects_and_runtime = Array.new(10, [-1, t('common.not_available_abbr'), t('common.not_available_abbr')])
@projects_and_runtime_sql.each do |r|
days = difference_in_days(@today, r.created_at)
# add one so that a project that you just created returns 1 day
@projects_and_runtime[i]=[r.id, r.name, days.to_i+1]
i += 1
end
end
def get_stats_tags

View file

@ -145,6 +145,10 @@ class Project < ActiveRecord::Base
@new_record_before_save
end
def age_in_days
@age_in_days ||= (Date.today - created_at.to_date + 1).to_i
end
end
class NullProject

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,38 +1,6 @@
<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.upto 10 do |j| -%>
<%= i -%> - <%=t('common.not_available_abbr')%> (<%=t('common.not_available_abbr')%>) <br/>
<% end
end
-%>
</div>
<%= render :partial => 'projects_list', :locals => {:projects => @projects_and_actions, :key => 'projects', :n => :count} -%>
<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.upto 10 do |j| -%>
<%= i -%> - <%=t('common.not_available_abbr')%> (<%=t('common.not_available_abbr')%>) <br/>
<% end
end
-%>
</div>
<%= render :partial => 'projects_list', :locals => {:projects => @projects_and_actions_last30days, :key => 'projects_30days', :n => :count} -%>
<%= render :partial => 'projects_list', :locals => {:projects => @projects_and_runtime, :key => 'longrunning', :n => :age_in_days} -%>
<div class="stats_module">
<h3><%= t('stats.top10_longrunning') %></h3>
<% i=0
@projects_and_runtime.each do |id, name, days|
i+=1 -%>
<%= i -%> - <%= link_to name, {:controller => "projects", :action => "show", :id => id} %> (<%=days %> <%= t('common.days_midsentence', :count => days) %>) <br/>
<% end -%>
</div>

View file

@ -0,0 +1,7 @@
<div class="stats_module">
<h3><%= t("stats.top10_#{key}") %></h3>
<% projects.each_with_index do |p, i| -%>
<%= i + 1 -%> - <%= link_to p.name, project_path(p) %> (<%=p.send(n)%> <%= t('common.actions_midsentence', :count => p.send(n)) %>) <br/>
<% end -%>
<%= render :partial => 'null_list_item', :locals => {:from => projects.size + 1} -%>
</div>