Project

General

Profile

« Previous | Next » 

Revision 452d6329

Added by Paul Kelly almost 14 years ago

  • ID 452d63292a366794bedff9a16a1f7364786b52c2

Fixes #248 - Generalise tab management and search facility

The search facility is now available from all controllers.
The search bar is only displayed if there is a partial
<controller_name>/_search_line.html.erb available.This partial also
describes and implements the possible search parameters for this controller
Active tab management is also improved

The appearence of the searchbar and other page elements has also been improved.

View differences:

app/controllers/application_controller.rb
helper 'layout'
before_filter :require_ssl, :require_login
before_filter :load_tabs, :manage_tabs
def self.active_scaffold_controller_for(klass)
return FactNamesController if klass == Puppet::Rails::FactName
......
end
private
def active_tab=(value); @active_tab = session[:controller_active_tabs][controller_name] = value; end
def load_tabs
@tabs = session[:tabs] ||= {}
@active_tab = session[:active_tab]
controller_tabs = session[:controller_tabs] ||= {}
@tabs = controller_tabs[controller_name] ||= {}
controller_active_tabs = session[:controller_active_tabs] ||= {}
@active_tab = controller_active_tabs[controller_name] ||= ""
end
def manage_tabs
return if params[:tab_name].empty? or params[:tab_name] == "Reset"
# Clear the active tab if jumping between different controller's
@controller_changed = session[:last_controller] != controller_name
session[:last_controller] = controller_name
self.active_tab = "" if @controller_changed
return if params[:tab_name].empty? or params[:action] != "index"
if params[:remove_me] and @tabs.has_key? params[:tab_name]
if params[:tab_name] == "Reset"
self.active_tab = ""
elsif params[:remove_me] and @tabs.has_key? params[:tab_name]
@tabs.delete params[:tab_name]
@active_tab = session[:active_tab] = @tabs.keys.sort.first
# If we delete the active tab then clear the active tab selection
if @active_tab == params[:tab_name]
self.active_tab = ""
else
# And redirect back as we do not want to perform the deleted tab's search
redirect_to :back
end
else
@active_tab = session[:active_tab] = params[:tab_name]
self.active_tab = params[:tab_name]
@tabs[@active_tab] = params[:search]
end
end
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
before_filter :find_multiple, :only => [:multiple_actions, :update_multiple_parameters,
:select_multiple_hostgroup, :select_multiple_environment, :multiple_parameters]
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"),
Puppet::Rails::FactName.all(:select => "id, name", :order => "name ASC"),
:id, :name, :selected => @fact_name_id, :include_blank => "Select a fact"
%>
<% if @fact_values -%>
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 id="searchbar" style="clear:both;">
<div id="tabs" class="odd">
<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>
<% end -%>
<div id="search" style="display:none">
<ul>
<li><%= link_to_function "Search", toggle_searchbar %></li>
<li>
<%= render :partial => 'search_line' %>
</li>
</ul>
</div>
</div>
app/views/hosts/_minilist.html.erb
<div id="hostlist">
<div id="hostlist" style="clear:both;">
<% if hosts.size > 0 -%>
<%= render "common/searchbar" %>
<% form_tag(multiple_actions_hosts_path,:method => "get", :id => "host_select_form") do %>
<strong><center><%= header ||= "" -%></center></strong><br/>
<% title header ||= "" %>
<table class="list">
<tr>
<td><%= order @search, :by => :name %></th>
<th><%= order @search, :by => :name %></th>
<th>Operating system</th>
<th>Environment</th>
<th>Model</th>
......
<td>
<%= link_to 'Edit', edit_host_url(host) %>
<%= link_to 'Clone', clone_host_url(host) %>
<%= link_to 'Destroy', host, :confirm => 'Are you sure?', :method => :delete %>
<%= link_to 'Destroy', host, :confirm => "Delete #{host.name}?", :method => :delete %>
</td>
<% end -%>
</tr>
app/views/hosts/_search_line.html.erb
<% 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, "", :size => 10 %>
<% end %>
app/views/hosts/index.html.erb
<%= link_to_function "Toggle All", "toggleCheck()" %>
</span>
<%= render 'minilist', :hosts => @hosts, :header => "Host list" %>
<%= render 'minilist', :hosts => @hosts, :header => "Hosts" %>
app/views/layouts/standard.rhtml
</div>
<%= render :partial => "home/menu" -%>
</div>
<%= render "common/searchbar" rescue "<!-- No searchbar facility available in this controller -->" %>
<%= 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" style="clear:both;">
<div id="content">
<%- if show_title? -%>
<h1><%=h yield(:title) %></h1>
<%- end -%>
app/views/operatingsystems/_search_line.html.erb
<% 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 :family, "OS family" %>
<%= f.collection_select :family_id, Family.families_as_collection, :value, :name,{ :include_blank => "Choose a family" } %>
<%= f.submit "Go" %> Save as tab: <%= text_field_tag :tab_name, "" %>
<% end %>
app/views/operatingsystems/index.html.erb
<% for operatingsystem in @operatingsystems %>
<tr class="<%= cycle("even", "odd") -%>">
<td><%= link_to h(operatingsystem.to_label), edit_operatingsystem_path(operatingsystem) %></td>
<td><%=h operatingsystem.family %></td>
<td><%= link_to "Destroy", operatingsystem, :confirm => 'Are you sure?', :method => :delete %></td>
<td><%= h operatingsystem.family %></td>
<td><%= link_to "Destroy", operatingsystem, :confirm => "Delete #{operatingsystem.fullname}?", :method => :delete %></td>
</tr>
<% end %>
</table>
public/stylesheets/style.css
p {
line-height: 130%;
}
#header {height:3.7em;margin:0;background-color:#406480;color:#E6DFCF;padding: 4px 8px 0px 6px; position:relative;}
#header {height:3.7em;margin:0;background-color:#406480;color:#E6DFCF;padding: 4px 8px 4px 6px; position:relative;}
#header a {
float:right;
......
position:relative;
float: center;
padding: 10px;
clear: both;
}
div#content h3 {
margin-top: 15px;
......
border: 2px solid;
}
div.flash {margin-top: 8px;}
div.flash {margin-top: 24px;}
div.flash.error, #errorExplanation {
background: url(../images/false.png) 8px 5px no-repeat;

Also available in: Unified diff