Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search to Services list view #2225

Merged
merged 8 commits into from
Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/controllers/application_controller/advanced_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def adv_search_redraw_left_div
build_configuration_manager_tree(:configuration_manager_cs_filter, x_active_tree)
build_accordions_and_trees
load_or_clear_adv_search
elsif @edit[:in_explorer] || %w(storage_tree configuration_scripts_tree).include?(x_active_tree.to_s)
elsif @edit[:in_explorer] || %w(storage_tree configuration_scripts_tree svcs_tree).include?(x_active_tree.to_s)
tree_type = x_active_tree.to_s.sub(/_tree/, '').to_sym
builder = TreeBuilder.class_for_type(tree_type)
tree = builder.new(x_active_tree, tree_type, @sb)
Expand Down Expand Up @@ -295,14 +295,15 @@ def adv_search_clear
respond_to do |format|
format.js do
@explorer = true
if x_active_tree.to_s =~ /_filter_tree$/ &&
if (x_active_tree.to_s =~ /_filter_tree$/ || x_active_tree.to_s == "svcs_tree") &&
!%w(Vm MiqTemplate).include?(TreeBuilder.get_model_for_prefix(@nodetype))
search_id = 0
adv_search_build(model_from_active_tree(x_active_tree))
session[:edit] = @edit # Set because next method will restore @edit from session
end
listnav_search_selected(search_id) # Clear or set the adv search filter
self.x_node = "root"
# no root node for My Services
self.x_node = x_active_tree.to_s == "svcs_tree" ? "xx-asrv" : "root"
replace_right_cell
end
format.html do
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def listnav_search_selected(id = nil)
@edit = session[:edit]
@edit[:selected] = true # Set a flag, this is checked whether to load initial default or clear was clicked
if id.to_i.zero?
@edit[:selected] = false
clear_selected_search
else
load_selected_search(id)
Expand Down
42 changes: 37 additions & 5 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def show_list
end

def explorer
@explorer = true
@lastaction = "explorer"
@explorer = true

# if AJAX request, replace right cell, and return
if request.xml_http_request?
Expand Down Expand Up @@ -273,6 +272,9 @@ def get_node_info(treenodeid, _show_list = true)
process_show_list(:named_scope => [:retired, :displayed])
@right_cell_text = _("Retired Services")
end
when "MiqSearch"
load_adv_search # Select/load filter from Global/My Filters
@right_cell_text = _("All Services")
else # Get list of child Catalog Items/Services of this node
if x_node == "root"
process_show_list(:where_clause => "ancestry is null")
Expand All @@ -287,8 +289,33 @@ def get_node_info(treenodeid, _show_list = true)
@right_cell_text = _("%{model} \"%{name}\"") % {:name => @record.name, :model => ui_lookup(:model => typ)}
end
end
x_history_add_item(:id => treenodeid, :text => @right_cell_text)
{:view => @view, :pages => @pages}
@right_cell_text += @edit[:adv_search_applied][:text] if x_tree && @edit && @edit[:adv_search_applied]

if @edit && @edit.fetch_path(:adv_search_applied, :qs_exp) # If qs is active, save it in history
x_history_add_item(:id => x_node,
:qs_exp => @edit[:adv_search_applied][:qs_exp],
:text => @right_cell_text)
else
x_history_add_item(:id => treenodeid, :text => @right_cell_text) # Add to history pulldown array
end
end

# Select/load filter from Global/My Filters
def load_adv_search
adv_search_build("Service")
session[:edit] = @edit
@explorer = true
@nodetype, id = parse_nodetype_and_id(valid_active_node(x_node))

if @nodetype == "ms"
listnav_search_selected(from_cid(id)) unless params.key?(:search_text)
if @edit[:adv_search_applied] &&
MiqExpression.quick_search?(@edit[:adv_search_applied][:exp]) &&
%w(reload tree_select).include?(params[:action])
self.x_node = params[:id]
quick_search_show
end
end
end

# set partial name and cell header for edit screens
Expand Down Expand Up @@ -329,7 +356,7 @@ def replace_right_cell(options = {})
action, replace_trees = options.values_at(:action, :replace_trees)
@explorer = true
partial, action_url, @right_cell_text = set_right_cell_vars(action) if action # Set partial name, action and cell header
get_node_info(x_node) if !@edit && !@in_a_form && !params[:display]
get_node_info(x_node) if !action && !@in_a_form && !params[:display]
replace_trees = @replace_trees if @replace_trees # get_node_info might set this
type, = parse_nodetype_and_id(x_node)
record_showing = type && ["Service"].include?(TreeBuilder.get_model_for_prefix(type))
Expand Down Expand Up @@ -413,6 +440,11 @@ def replace_right_cell(options = {})

presenter[:lock_sidebar] = @edit && @edit[:current]
presenter[:osf_node] = x_node

# Hide/show searchbox depending on if a list is showing
presenter.set_visibility(!(@record || @in_a_form), :adv_searchbox_div)
presenter[:clear_search_toggle] = clear_search_status

# unset variable that was set in form_field_changed to prompt for changes when leaving the screen
presenter.reset_changes

Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ def display_adv_search?
retired
security_group
service
services
storage
templates
vm
Expand Down Expand Up @@ -992,6 +993,8 @@ def model_from_active_tree(tree)
"ManageIQ::Providers::CloudManager::Vm"
when :images_filter_tree
"ManageIQ::Providers::CloudManager::Template"
when :svcs_tree
"Service"
when :vms_filter_tree
"ManageIQ::Providers::InfraManager::Vm"
when :templates_filter_tree
Expand Down Expand Up @@ -1577,6 +1580,7 @@ def tree_with_advanced_search?
instances_filter
providers
storage
svcs
templates_filter
templates_images_filter
vandt
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/explorer_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def for_render_default
data[:resetOneTrans] = !!@options[:reset_one_trans]
data[:oneTransIE] = !!@options[:one_trans_ie]
data[:focus] = @options[:focus]
data[:clearSearch] = @options[:clear_search_toggle] if @options[:clear_search_toggle]
data[:clearSearch] = @options[:clear_search_toggle] if @options.key?(:clear_search_toggle)
data[:hideModal] if @options[:hide_modal]
data[:initAccords] if @options[:init_accords]
data[:reportData] = @options[:report_data] if @options[:report_data]
Expand Down
1 change: 1 addition & 0 deletions app/presenters/tree_builder_default_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class TreeBuilderDefaultFilters < TreeBuilder
:containerservice => %w(Containers Services),
:host => %w(Infrastructure Hosts),
:miqtemplate => %w(Services Workloads Templates\ &\ Images),
:service => %w(Services My\ Services),
:storage => %w(Infrastructure Datastores),
:vm => %w(Services Workloads VMs\ &\ Instances),
:"manageiq::providers::cloudmanager::template" => %w(Cloud Instances Images),
Expand Down
32 changes: 31 additions & 1 deletion app/presenters/tree_builder_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,46 @@ def x_get_tree_roots(count_only, _options)
:icon => "pficon pficon-folder-close",
:load_children => true,
:tip => _("Retired Services"))
objects.push(:id => "global",
:text => _("Global Filters"),
:icon => "pficon pficon-folder-close",
:selectable => false,
:tip => _("Global Shared Filters"))
objects.push(:id => "my",
:text => _("My Filters"),
:icon => "pficon pficon-folder-close",
:selectable => false,
:tip => _("My Personal Filters"))
count_only_or_objects(count_only, objects)
end

def x_get_tree_custom_kids(object, count_only, _options)
services = Rbac.filtered(Service.where(:retired => object[:id] != 'asrv', :display => true))
if count_only
if %w(global my).include?(object[:id]) # Get My Filters and Global Filters
count_only_or_objects(count_only, x_get_search_results(object, _options[:leaf]))
elsif count_only
services.size
else
MiqPreloader.preload(services.to_a, :picture)
Service.arrange_nodes(services.sort_by { |n| [n.ancestry.to_s, n.name.downcase] })
end
end

def x_get_search_results(object, leaf)
case object[:id]
when "global" # Global filters
x_get_global_filter_search_results(leaf)
when "my" # My filters
x_get_my_filter_search_results(leaf)
end
end

def x_get_global_filter_search_results(leaf)
MiqSearch.where(:db => leaf).visible_to_all.sort_by { |a| a.description.downcase }
end

def x_get_my_filter_search_results(leaf)
MiqSearch.where(:db => leaf, :search_type => "user", :search_key => User.current_user.userid)
.sort_by { |a| a.description.downcase }
end
end
3 changes: 3 additions & 0 deletions app/views/service/explorer.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- content_for :search do
= render(:partial => "layouts/x_adv_searchbox")
= render(:partial => 'layouts/quick_search')
- if TreeBuilder.get_model_for_prefix(@nodetype) == "Service"
-# Showing a specific Service
#main_div
Expand Down
10 changes: 9 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2967,12 +2967,16 @@
:post => %w(
button
explorer
listnav_search_selected
ownership_field_changed
ownership_update
quick_search
reload
retire
service_edit
service_tag
show
show_list
tag_edit_form_field_changed
tagging_edit
tree_autoload
Expand All @@ -2982,7 +2986,11 @@
x_show
ownership_form_fields
) +
dialog_runner_post
dialog_runner_post +
adv_search_post +
exp_post +
save_post +
x_post
},

:storage => {
Expand Down
4 changes: 3 additions & 1 deletion spec/presenters/tree_builder_services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
let(:builder) { TreeBuilderServices.new("x", "y", {}) }

it "generates tree" do
User.current_user = FactoryGirl.create(:user)
allow(User).to receive(:server_timezone).and_return("UTC")
create_deep_tree

expect(root_nodes.size).to eq(2)
expect(root_nodes.size).to eq(4)
active_nodes = kid_nodes(root_nodes[0])
retired_nodes = kid_nodes(root_nodes[1])
expect(active_nodes).to eq(
Expand Down