mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-22 05:50:47 +02:00
Don't link to null projects
If you have fewer than 10 projects, then empty running projects were linked to with the path `/projects/-1`. Copy/pasted the list strategy from the other project sections in the same partial so the duplication becomes explicit.
This commit is contained in:
parent
6385059de8
commit
2686a0d3b5
3 changed files with 14 additions and 14 deletions
|
@ -531,7 +531,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' "+
|
||||
|
@ -539,16 +539,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -31,8 +31,14 @@
|
|||
<div class="stats_module">
|
||||
<h3><%= t('stats.top10_longrunning') %></h3>
|
||||
<% i=0
|
||||
@projects_and_runtime.each do |id, name, days|
|
||||
@projects_and_runtime.each do |p|
|
||||
i+=1 -%>
|
||||
<%= i -%> - <%= link_to name, {:controller => "projects", :action => "show", :id => id} %> (<%=days %> <%= t('common.days_midsentence', :count => days) %>) <br/>
|
||||
<% end -%>
|
||||
<%= 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
|
||||
-%>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue