From 98544d60d716593ee081eb1e6552437ce9070ca0 Mon Sep 17 00:00:00 2001
From: Jochen Schalanda <jochen@schalanda.name>
Date: Tue, 2 Nov 2010 13:53:35 +0000
Subject: [PATCH] Fixes #288 - Moved DashboardController actions (except for #index) to HostsController.

---
 app/controllers/dashboard_controller.rb |   28 ----------------------------
 app/controllers/hosts_controller.rb     |   29 +++++++++++++++++++++++++++++
 app/views/dashboard/index.html.erb      |    8 ++++----
 config/routes.rb                        |    8 +++++++-
 4 files changed, 40 insertions(+), 33 deletions(-)

diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index 3163803..ed033ed 100644
--- a/app/controllers/dashboard_controller.rb
+++ b/app/controllers/dashboard_controller.rb
@@ -6,22 +6,6 @@ class DashboardController < ApplicationController
   def index
   end
 
-  def errors
-    show_hosts Host.recent.with_error, "Hosts with errors"
-  end
-
-  def active
-    show_hosts Host.recent.with_changes, "Active Hosts"
-  end
-
-  def OutOfSync
-    show_hosts Host.out_of_sync, "Hosts which didn't run puppet in the last #{SETTINGS[:puppet_interval]} minutes"
-  end
-
-  def disabled
-    show_hosts Host.alerts_disabled, "Hosts with notifications disabled"
-  end
-
   private
   def graphs
 
@@ -60,16 +44,4 @@ class DashboardController < ApplicationController
     # the run interval to show in the dashboard graph
   end
 
-  def show_hosts list, title
-    @search = list.search(params[:search])
-    respond_to do |format|
-      format.html do
-        hosts = @search.paginate :page => params[:page]
-        @last_reports = Report.maximum(:id, :group => :host_id, :conditions => {:host_id => hosts})
-        render "hosts/_minilist", :locals => {:hosts => hosts, :header => title}
-      end
-      format.yml { render :text => @search.map(&:name).to_yaml }
-    end
-  end
-
 end
diff --git a/app/controllers/hosts_controller.rb b/app/controllers/hosts_controller.rb
index c09e81e..9d59428 100644
--- a/app/controllers/hosts_controller.rb
+++ b/app/controllers/hosts_controller.rb
@@ -373,6 +373,22 @@ class HostsController < ApplicationController
     render :nothing => true
   end
 
+  def errors
+    show_hosts Host.recent.with_error, "Hosts with errors"
+  end
+
+  def active
+    show_hosts Host.recent.with_changes, "Active Hosts"
+  end
+
+  def out_of_sync
+    show_hosts Host.out_of_sync, "Hosts which didn't run puppet in the last #{SETTINGS[:puppet_interval]} minutes"
+  end
+
+  def disabled
+    show_hosts Host.alerts_disabled, "Hosts with notifications disabled"
+  end
+
   private
   def find_hosts
     fact, klass, group = params[:fact], params[:class], params[:hostgroup]
@@ -471,4 +487,17 @@ class HostsController < ApplicationController
     end
   end
 
+  def show_hosts list, title
+    @search = list.search(params[:search])
+    respond_to do |format|
+      format.html do
+        hosts = @search.paginate :page => params[:page]
+        @last_reports = Report.maximum(:id, :group => :host_id, :conditions => {:host_id => hosts})
+        render "hosts/_minilist", :locals => {:hosts => hosts, :header => title}
+      end
+      format.yaml { render :text => @search.map(&:name).to_yaml }
+      format.json { render :json => @search.map(&:name).to_json }
+    end
+  end
+
 end
diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb
index 6db5998..4343762 100644
--- a/app/views/dashboard/index.html.erb
+++ b/app/views/dashboard/index.html.erb
@@ -4,10 +4,10 @@
   <p>Generated at <%= Time.now.to_s(:short) %></p>
   <p>Good Host Reports in the last <%= SETTINGS[:puppet_interval] %> minutes <%= "#{@good_hosts} / #{@total_hosts}" %> hosts (<%=@percentage%>%) </p>
   <h1>Summary</h1>
-  <p>Hosts that had performed modifications <%= link_to @active_hosts, :action => "active" %></p>
-  <p>Out Of Sync Hosts <%= link_to @out_of_sync_hosts, :action => "OutOfSync" %></p>
-  <p>Hosts in Error State <%= link_to @bad_hosts, :action => "errors" %></p>
-  <p>Hosts With Alerts Disabled <%= link_to @disabled_hosts, :action => "disabled" %></p>
+  <p>Hosts that had performed modifications <%= link_to @active_hosts, :controller => "hosts", :action => "active" %></p>
+  <p>Out Of Sync Hosts <%= link_to @out_of_sync_hosts, :controller => "hosts", :action => "out_of_sync" %></p>
+  <p>Hosts in Error State <%= link_to @bad_hosts, :controller => "hosts", :action => "errors" %></p>
+  <p>Hosts With Alerts Disabled <%= link_to @disabled_hosts, :controller => "hosts", :action => "disabled" %></p>
 
   <div id='overview'></div>
   <%= @overview.render('overview') %>
diff --git a/config/routes.rb b/config/routes.rb
index 7498fe8..3ddffd9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -4,7 +4,13 @@ ActionController::Routing::Routes.draw do |map|
   map.resources :reports
   map.connect "node/:name", :controller => 'hosts', :action => 'externalNodes',
     :requirements => { :name => /[^\.][\w\.-]+/ }
-  map.connect "/hosts/query", :controller => 'hosts', :action => 'query'
+  map.with_options :controller => 'hosts' do |hosts|
+    hosts.connect 'hosts/query', :action => 'query'
+    hosts.connect 'hosts/active', :action => 'active'
+    hosts.connect 'hosts/out_of_sync', :action => 'out_of_sync'
+    hosts.connect 'hosts/errors', :action => 'errors'
+    hosts.connect 'hosts/disabled', :action => 'disabled'
+  end
   map.resources :hosts,
     :requirements => {:id => /[^\/]+/},
     :member => { :report => :get, :reports => :get, :clone => :get,
-- 
1.7.0.4

