diff --git a/app/controllers/graphs_controller.rb b/app/controllers/graphs_controller.rb
index c94e833..b2843eb 100644
--- a/app/controllers/graphs_controller.rb
+++ b/app/controllers/graphs_controller.rb
@@ -9,8 +9,8 @@ class GraphsController < ApplicationController
menu_item :issues, :only => [:issue_growth, :old_issues]
before_filter :find_version, :only => [:target_version_graph]
+ before_filter :confirm_issues_exist, :only => [:issue_growth]
before_filter :find_open_issues, :only => [:old_issues, :issue_age_graph]
- before_filter :find_optional_project, :only => [:issue_growth, :issue_growth_graph]
helper IssuesHelper
@@ -63,14 +63,12 @@ class GraphsController < ApplicationController
# Displays total number of issues over time
def issue_growth
- render_404 if @project && @project.issues.empty?
end
# Displays created vs update date on open issues over time
def old_issues
- render_404 if @project && @project.issues.empty?
@issues_by_created_on = @issues.sort {|a,b| a.created_on<=>b.created_on}
- @issues_by_updated_on = @issues.sort {|a,b| a.updated_on<=>b.updated_on}
+ @issues_by_updated_on = @issues.sort {|a,b| a.updated_on<=>b.updated_on}
end
@@ -97,7 +95,7 @@ class GraphsController < ApplicationController
:width => 720,
:x_label_format => "%Y-%m-%d"
})
-
+
# Get the top visible projects by issue count
sql = "SELECT project_id, COUNT(*) as issue_count"
sql << " FROM issues"
@@ -172,7 +170,7 @@ class GraphsController < ApplicationController
graph.add_data({
:data => created_on_line.sort.flatten,
:title => l(:field_created_on)
- })
+ }) unless issues_by_created_on.empty?
# Generate the closed_on line
updated_count = 0
@@ -182,8 +180,8 @@ class GraphsController < ApplicationController
graph.add_data({
:data => updated_on_line.sort.flatten,
:title => l(:field_updated_on)
- })
-
+ }) unless issues_by_updated_on.empty?
+
# Compile the graph
headers["Content-Type"] = "image/svg+xml"
send_data(graph.burn, :type => "image/svg+xml", :disposition => "inline")
@@ -258,6 +256,19 @@ class GraphsController < ApplicationController
# Private methods
############################################################################
private
+
+ def confirm_issues_exist
+ find_optional_project
+ if !@project.nil?
+ ids = [@project.id]
+ ids += @project.descendants.active.visible.collect(&:id)
+ @issues = Issue.visible.find(:first, :conditions => ["#{Project.table_name}.id IN (?)", ids])
+ else
+ @issues = Issue.visible.find(:first)
+ end
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
def find_open_issues
find_optional_project
diff --git a/app/views/graphs/issue_growth.html.erb b/app/views/graphs/issue_growth.html.erb
index f62f133..029ebaa 100644
--- a/app/views/graphs/issue_growth.html.erb
+++ b/app/views/graphs/issue_growth.html.erb
@@ -1,6 +1,10 @@
<%= l(:label_graphs_issue_growth) %>
-<%= tag("embed", :width => "100%", :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'issue_growth_graph')) if @project.nil? %>
-<%= tag("embed", :width => "100%", :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'issue_growth_graph', :project_id => @project.id)) unless @project.nil? %>
+<% unless @issues.nil? %>
+ <%= tag("embed", :width => "100%", :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'issue_growth_graph')) if @project.nil? %>
+ <%= tag("embed", :width => "100%", :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'issue_growth_graph', :project_id => @project.id)) unless @project.nil? %>
+<% else %>
+ <%= render :partial => 'issues/list_simple', :locals => { :issues => @issues } %>
+<% end %>
<% content_for :sidebar do %>
<%= render :partial => 'issues/sidebar' %>
diff --git a/app/views/graphs/old_issues.html.erb b/app/views/graphs/old_issues.html.erb
index 1acac35..ae4e280 100644
--- a/app/views/graphs/old_issues.html.erb
+++ b/app/views/graphs/old_issues.html.erb
@@ -1,6 +1,8 @@
<%= l(:label_graphs_old_issues) %>
-<%= tag("embed", :width => "100%", :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'issue_age_graph')) if @project.nil? %>
-<%= tag("embed", :width => "100%", :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'issue_age_graph', :project_id => @project.id)) unless @project.nil? %>
+<% unless @issues_by_created_on.empty? %>
+ <%= tag("embed", :width => "100%", :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'issue_age_graph')) if @project.nil? %>
+ <%= tag("embed", :width => "100%", :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'issue_age_graph', :project_id => @project.id)) unless @project.nil? %>
+<% end %>
<%= l(:label_issues_by, :value => l(:field_created_on)) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index d6db526..4eda405 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -5,3 +5,5 @@ en:
label_graphs_issue_growth: Total issues over time
label_graphs_issue_status_flow: Recent status changes (within 24 hours)
label_graphs_assigned_to_status_flow: Recent assignment changes (within 24 hours)
+ warning_no_issues: There are no issues to graph.
+
\ No newline at end of file
diff --git a/lib/issues_sidebar_graph_hook.rb b/lib/issues_sidebar_graph_hook.rb
index 0b529bf..a4fd3de 100644
--- a/lib/issues_sidebar_graph_hook.rb
+++ b/lib/issues_sidebar_graph_hook.rb
@@ -8,7 +8,7 @@ class IssuesSidebarGraphHook < Redmine::Hook::ViewListener
output << link_to(l(:label_graphs_issue_growth), {:controller => 'graphs', :action => 'issue_growth', :only_path => true})
output << "
"
return output
- elsif !context[:project].nil? && !context[:project].issues.empty?
+ elsif !context[:project].nil?
output = "#{l(:label_graphs)}
"
output << link_to(l(:label_graphs_old_issues), {:controller => 'graphs', :action => 'old_issues', :project_id => context[:project], :only_path => true})
output << "
"