Project

General

Profile

« Previous | Next » 

Revision cdd8bb6f

Added by Paul Kelly about 14 years ago

  • ID cdd8bb6f9dedcfc2eccd882ad79c5ac637c6bcf5

Fixes #183 - Adds searchbar facility to hosts

Qualified the fact_selected partial
Added a reset button
Added popup help
Beautification and grooming

View differences:

app/controllers/application_controller.rb
return "#{klass}ScaffoldController".constantize rescue super
end
# host list AJAX methods
# its located here, as it might be requested from the dashboard controller or via the hosts controller
def fact_selected
@fact_name_id = params[:search_fact_values_fact_name_id_eq].to_i
@fact_values = FactValue.find(:all, :select => 'DISTINCT value', :conditions => {
:fact_name_id => @fact_name_id }, :order => 'value ASC') if @fact_name_id > 0
render :partial => 'common/fact_selected', :layout => false
end
protected
def require_ssl
......
end
def invalid_request
render :text => 'Invalid query', :status => 400 and return
render :text => 'Invalid query', :status => 400 and return
end
def setgraph chart, data, options = {}
......
return chart
end
private
def load_tabs
@tabs = session[:tabs] ||= {}
@active_tab = session[:active_tab]
end
def manage_tabs
return if params[:tab_name].empty? or params[:tab_name] == "Reset"
if params[:remove_me] and @tabs.has_key? params[:tab_name]
@tabs.delete params[:tab_name]
@active_tab = session[:active_tab] = @tabs.keys.sort.first
else
@active_tab = session[:active_tab] = params[:tab_name]
@tabs[@active_tab] = params[:search]
end
end
end
app/controllers/dashboard_controller.rb
class DashboardController < ApplicationController
before_filter :prefetch_data, :graphs, :only => :index
before_filter :load_tabs, :manage_tabs, :only => [:errors, :OutOfSync, :active]
helper :hosts
def index
app/controllers/hosts_controller.rb
before_filter :require_ssl, :except => [ :query, :externalNodes, :lookup ]
before_filter :find_hosts, :only => :query
before_filter :ajax_methods, :only => [:environment_selected, :architecture_selected, :os_selected]
before_filter :load_tabs, :manage_tabs, :only => :index
helper :hosts
def index
......
assign_parameter "operatingsystem"
end
# list AJAX methods
def fact_selected
@fact_name_id = params[:search_fact_values_fact_name_id_eq].to_i
@fact_values = FactValue.find(:all, :select => 'DISTINCT value', :conditions => {
:fact_name_id => @fact_name_id }, :order => 'value ASC') if @fact_name_id > 0
render :partial => 'fact_selected', :layout => false
end
#returns a yaml file ready to use for puppet external nodes script
#expected a fqdn parameter to provide hostname to lookup
#see example script in extras directory
......
redirect_to :controller => "reports", :action => "show", :id => Report.maximum('id', :conditions => {:host_id => params[:id]})
end
# shows all reports for a certian host
# shows all reports for a certain host
def reports
@host = Host.find(params[:id])
end
app/helpers/application_helper.rb
:position => {:after => {:success => "selected_classes" }}
end
def searchtab title, search, options
opts = {:action => params[:action], :tab_name => title, :search => search}
selected_class = options[:selected] ? "selectedtab" : ""
content_tag(:li) do
link_to opts, :class => selected_class do
title + (options[:no_close_button] ? "": (link_to "x", opts.merge(:remove_me => true), :class => "#{selected_class} close"))
end
end
end
def toggle_searchbar
update_page do |page|
page['search'].toggle
page['tabs'].toggle
end
end
end
app/views/common/_fact_selected.html.erb
<span id=fact_search>
<%= label_tag "Fact Name" %>
<%= collection_select :search, :fact_values_fact_name_id_eq,
Puppet::Rails::FactName.find(:all, :order => "name ASC"),
:id, :name, :selected => @fact_name_id, :include_blank => "Select a fact"
%>
<% if @fact_values -%>
<%= label :fact_values_value_eq, "Value" %>
<%= collection_select :search, :fact_values_value_eq, @fact_values, :value, :value %>
<% end -%>
</span>
<%= observe_field(:search_fact_values_fact_name_id_eq,
:url => { :action => :fact_selected },
:update => :fact_search,
:with => :search_fact_values_fact_name_id_eq) %>
app/views/common/_searchbar.erb
<% if @search -%>
<div id="searchbar" style="clear:both;">
<div id="tabs" class="even">
<ul>
<li><%= link_to_function "Search", toggle_searchbar %><li>
<% for tab in @tabs.keys.sort -%>
<%= searchtab tab, @tabs[tab], :selected => (@active_tab == tab) %>
<% end -%>
<%= searchtab "Reset", "/", :selected => false, :no_close_button => true %>
</ul>
</div>
<div id="search" style="display:none">
<ul>
<li><%= link_to_function "Search", toggle_searchbar %></li>
<li>
<% form_for @search do |f|-%>
<span title="A substring match">
<%= f.label :name_like, "Name" %>
<%= f.text_field :name_like, :size => 10 %>
</span>
<%= f.label :hostgroup, "Role" %>
<%= f.collection_select :hostgroup_id_eq, Hostgroup.all, :id, :name, :include_blank => true %>
<%= render :partial => 'common/fact_selected' %>
<%= f.submit "Go" %> Save as tab: <%= text_field_tag :tab_name, "" %>
<% end %>
</li>
</ul>
</div>
</div>
<% end -%>
app/views/hosts/_fact_selected.html.erb
<span id=fact_search>
<%= label_tag "Fact Name" %>
<%= collection_select :search, :fact_values_fact_name_id_eq,
Puppet::Rails::FactName.find(:all, :order => "name ASC"),
:id, :name, :selected => @fact_name_id, :include_blank => true
%>
<% if @fact_values %>
<%= label :fact_values_value_eq, "Value" %>
<%= collection_select :search, :fact_values_value_eq, @fact_values, :value, :value %>
<% end %>
</span>
<%= observe_field(:search_fact_values_fact_name_id_eq,
:url => { :action => :fact_selected },
:update => :fact_search,
:with => :search_fact_values_fact_name_id_eq) %>
app/views/hosts/_minilist.html.erb
<div id="hostlist">
<%= link_to_function "Search", toggle_div(:search) %>
<div id="search" style="display:none;">
<% form_for @search do |f|-%>
<%= f.label :name_like, "Name" %>
<%= f.text_field :name_like, :size => 15 %>
<%= f.label :environment_id_equals, "Environment" %>
<%= f.collection_select :environment_id_equals, Environment.all, :id, :name, :include_blank => true %>
<%= f.label :hostgroup, "Role" %>
<%= f.collection_select :hostgroup_id_eq, Hostgroup.all, :id, :name, :include_blank => true %>
<%= render :partial => 'hosts/fact_selected' %>
<p>
<%= f.submit "Search" %>
<% end %>
</div>
<% if hosts.size > 0 -%>
<strong><center><%= header ||= "" -%></center></strong><br/>
<table class="list">
<caption> <%= header ||= "" -%> </caption>
<th colspan="8"><%= render "common/searchbar" %></th>
<tr>
<th><%= order @search, :by => :name %></th>
<th>Operating system</th>
......
<% end -%>
</tr>
</table>
<% else -%>
<p>No Hosts found</p>
<% end -%>
</div>
<%= page_entries_info hosts %>
app/views/hosts/index.html.erb
<%= link_to "New Host", new_host_path %>
</span>
<%= render 'minilist', :hosts => @hosts, :header => "Hosts" %>
<%= render 'minilist', :hosts => @hosts, :header => "Host list" %>
app/views/layouts/standard.rhtml
</div>
<%= content_tag('div', flash[:foreman_error], :class => 'flash error') if flash[:foreman_error] -%>
<%= content_tag('div', flash[:foreman_notice], :class => 'flash notice') if flash[:foreman_notice] -%>
<div id="content">
<div id="content" style="clear:both;">
<%- if show_title? -%>
<h1><%=h yield(:title) %></h1>
<%- end -%>
<%= yield -%>
</div>
<div id="footer">
&copy; 2009-2010 <%= mail_to "pikelly@blueyonder.cookies.uk", "Paul Kelly" %> and <%= mail_to "ohadlevy@gmail.com", "Ohad Levy" %>
&copy; 2009-2010 <%= mail_to "paul.ian.kelly@googlemail.com", "Paul Kelly" %> and <%= mail_to "ohadlevy@gmail.com", "Ohad Levy" %>
</div>
</body>
</html>
public/stylesheets/style.css
position: relative;
float: right;
}
#searchbar ul {
margin: 0; padding: 0;
list-style: none;
float: left;
width: 100%;
background-color: #ffffff;
}
#searchbar li {
float:left;
padding-right: 4px;
list-style-type:none;
}
#searchbar li .selectedtab {
padding-right: 4px;
background-color:#e4e4e4;
}
#searchbar li a.close{
color: red;
padding-left: 1px;
padding-top: 1px;
padding-bottom: 7px;
text-decoration: none;
}
#searchbar li a {
display: block;
float:left;
color: #484848;
font-weight: bold;
margin: 0;
padding: 4px 4px 4px 10px;
}
/* Maybe someone else can ge ths hovering to work esthetically
#searchbar li a:hover {background:#759FCF; color:#fff;}
#searchbar li a.active, li a.selected:hover {background:#fff; color:#555;}
#searchbar li a.close:hover {background:#e4e4e4; color:red;}
#searchbar li a.active, li a.selected:hover {background:#fff; color:#555;}
*/

Also available in: Unified diff