From cdb60686982c7abc96f9e5f9474713c70e5b569c Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Mon, 25 Sep 2017 15:25:35 +0200 Subject: [PATCH 1/8] Display filters in My Services list view Display Global Filters and My Filters in accordion in Services -> My Services (My Services list view screen). --- app/presenters/tree_builder_services.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/presenters/tree_builder_services.rb b/app/presenters/tree_builder_services.rb index e8df96530ef..0981dc48d8d 100644 --- a/app/presenters/tree_builder_services.rb +++ b/app/presenters/tree_builder_services.rb @@ -32,6 +32,16 @@ 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 From c8d14b644b5246e0ef16c07d507a87d9ab14c108 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Thu, 5 Oct 2017 15:37:49 +0200 Subject: [PATCH 2/8] Add Search, Adv search to Services list view Add Search form and Advanced search bar to My Services list view screen. --- app/helpers/application_helper.rb | 2 ++ app/views/service/explorer.html.haml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5c66d407dc6..4682d743c5e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -904,6 +904,7 @@ def display_adv_search? retired security_group service + services storage templates vm @@ -1577,6 +1578,7 @@ def tree_with_advanced_search? instances_filter providers storage + svcs templates_filter templates_images_filter vandt diff --git a/app/views/service/explorer.html.haml b/app/views/service/explorer.html.haml index b619e06a022..11e1b7332c8 100644 --- a/app/views/service/explorer.html.haml +++ b/app/views/service/explorer.html.haml @@ -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 From 5a50e271e8573b99c83dddb210e9a61ab6d73b12 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Thu, 5 Oct 2017 15:43:15 +0200 Subject: [PATCH 3/8] Add missing routes --- config/routes.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index eb91e4c690b..4d72f79ca08 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 @@ -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 => { From 9619cc41ddcec3f4e6961c0b680132518fe2c7d2 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Mon, 9 Oct 2017 17:45:27 +0200 Subject: [PATCH 4/8] Display saved filters in accordion Display the new, saved filters in the tree, under Global or My Filters in accordion. --- app/presenters/tree_builder_services.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/presenters/tree_builder_services.rb b/app/presenters/tree_builder_services.rb index 0981dc48d8d..f1df9cd0f78 100644 --- a/app/presenters/tree_builder_services.rb +++ b/app/presenters/tree_builder_services.rb @@ -47,11 +47,31 @@ def x_get_tree_roots(count_only, _options) 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 From c91562ad0800e8168b6f4a29509fcc422d4633d2 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Mon, 23 Oct 2017 15:56:51 +0200 Subject: [PATCH 5/8] Make created filters work Make created Global and My Filters work in My Services screen when clicking on filter in the tree. Add Service to get_model_from_active_tree method. --- .../application_controller/advanced_search.rb | 5 +-- .../application_controller/filter.rb | 1 + app/controllers/service_controller.rb | 32 +++++++++++++++++-- app/helpers/application_helper.rb | 2 ++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller/advanced_search.rb b/app/controllers/application_controller/advanced_search.rb index 04ece7274d2..77a0b6615af 100644 --- a/app/controllers/application_controller/advanced_search.rb +++ b/app/controllers/application_controller/advanced_search.rb @@ -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 diff --git a/app/controllers/application_controller/filter.rb b/app/controllers/application_controller/filter.rb index a44041240ed..5dd95de8908 100644 --- a/app/controllers/application_controller/filter.rb +++ b/app/controllers/application_controller/filter.rb @@ -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) diff --git a/app/controllers/service_controller.rb b/app/controllers/service_controller.rb index a818904a758..d147b7e0641 100644 --- a/app/controllers/service_controller.rb +++ b/app/controllers/service_controller.rb @@ -273,6 +273,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") @@ -287,8 +290,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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4682d743c5e..b4380ff888b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -993,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 From beff9372aa90baea8026f95b9a0ddcd82bc40dea Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Fri, 27 Oct 2017 14:24:19 +0200 Subject: [PATCH 6/8] Appear "clear" in title after applying a filter Appear "clear" link in My Services screen at the end of the title right after applying a filter in Advanced search to be able to clear selected filter/search. Update title of the screen properly after clearing selected search. --- app/controllers/service_controller.rb | 7 ++++++- app/presenters/explorer_presenter.rb | 2 +- app/presenters/tree_builder_default_filters.rb | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/service_controller.rb b/app/controllers/service_controller.rb index d147b7e0641..049ac4cbddd 100644 --- a/app/controllers/service_controller.rb +++ b/app/controllers/service_controller.rb @@ -357,7 +357,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)) @@ -441,6 +441,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 diff --git a/app/presenters/explorer_presenter.rb b/app/presenters/explorer_presenter.rb index 059f648a333..e1140a2f38b 100644 --- a/app/presenters/explorer_presenter.rb +++ b/app/presenters/explorer_presenter.rb @@ -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] diff --git a/app/presenters/tree_builder_default_filters.rb b/app/presenters/tree_builder_default_filters.rb index c42cad8eea2..9cde785e3ef 100644 --- a/app/presenters/tree_builder_default_filters.rb +++ b/app/presenters/tree_builder_default_filters.rb @@ -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), From d69e3c9099c185dd19e97094af1d3c09bcb6d7cd Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Fri, 27 Oct 2017 19:09:40 +0200 Subject: [PATCH 7/8] Add changes to make Adv search work Add small changes to make Advanced search in My Services screen work properly, especially when opening Adv search and deleting a filter. --- app/controllers/application_controller/advanced_search.rb | 2 +- app/controllers/service_controller.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller/advanced_search.rb b/app/controllers/application_controller/advanced_search.rb index 77a0b6615af..e67d8c82d00 100644 --- a/app/controllers/application_controller/advanced_search.rb +++ b/app/controllers/application_controller/advanced_search.rb @@ -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) diff --git a/app/controllers/service_controller.rb b/app/controllers/service_controller.rb index 049ac4cbddd..ff3aa65de28 100644 --- a/app/controllers/service_controller.rb +++ b/app/controllers/service_controller.rb @@ -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? From cdef2c9b54e2db1e6d254025c4f4637978a994ef Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Fri, 27 Oct 2017 20:18:37 +0200 Subject: [PATCH 8/8] Edit spec test to generate tree Edit a spec test for TreeBuilderServices to generate tree in My Services properly, as there are four nodes now, including nodes for Global and My Filters. --- spec/presenters/tree_builder_services_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/presenters/tree_builder_services_spec.rb b/spec/presenters/tree_builder_services_spec.rb index aba262a1b58..479d7fea07c 100644 --- a/spec/presenters/tree_builder_services_spec.rb +++ b/spec/presenters/tree_builder_services_spec.rb @@ -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(