diff --git a/app/controllers/application_controller/miq_request_methods.rb b/app/controllers/application_controller/miq_request_methods.rb index 8943ffaa458..ad2ce1ccec7 100644 --- a/app/controllers/application_controller/miq_request_methods.rb +++ b/app/controllers/application_controller/miq_request_methods.rb @@ -148,7 +148,7 @@ def pre_prov end elsif params[:hide_deprecated_templates] @edit = session[:edit] - @edit[:hide_deprecated_templates] = params[:hide_deprecated_templates] == "true" + @edit[:hide_deprecated_templates] = provisioning_is_cloud? ? params[:hide_deprecated_templates] == "true" : nil render_updated_templates else # First time in, build pre-provision screen set_pre_prov_vars @@ -159,6 +159,7 @@ def pre_prov def render_updated_templates report_scopes = [:eligible_for_provisioning] + report_scopes.push([:filter_with_name, params[:search_text]]) report_scopes.push(:non_deprecated) if @edit[:hide_deprecated_templates] options = options_for_provisioning(get_template_kls.to_s, report_scopes) diff --git a/app/controllers/mixins/generic_show_mixin.rb b/app/controllers/mixins/generic_show_mixin.rb index 0bacb3ff5ef..de724e8b8c6 100644 --- a/app/controllers/mixins/generic_show_mixin.rb +++ b/app/controllers/mixins/generic_show_mixin.rb @@ -38,6 +38,13 @@ def show end end + if @showtype == @display + case @display + when "instances" + + end + end + if params[:action] == 'show' && !performed? && self.class.respond_to?(:default_show_template) render :template => self.class.default_show_template end @@ -182,5 +189,33 @@ def nested_list(model, options = {}) @view, @pages = get_view(model, view_options) @showtype = @display end + + #private + + #def handle_display_modes + # @search_text = params[:text] + # @items = fetch_items_based_on_display(@display, @search_text) + #end + + #def fetch_items_based_on_display(display, search_text) + # case display + # when "images" + # filter_items(Image, search_text) + # when "instance" + # filter_items(MiqAeInstance, search_text) + # when "cloud_object_store_containers" + # filter_items(CloudObjectStoreContainer, search_text) + # when "security_groups" + # filter_items(SecurityGroup, search_text) + # when "cloud_networks" + # filter_items(CloudNetwork, search_text) + # end + #end + + #def filter_items(model_class, search_text) + # query = model_class.all + # query = query.where("name ILIKE ?", "%#{search_text}%") if search_text.present? + # query + #end end end diff --git a/app/javascript/components/filter-provision-instance/index.jsx b/app/javascript/components/filter-provision-instance/index.jsx new file mode 100644 index 00000000000..df68e40ac5a --- /dev/null +++ b/app/javascript/components/filter-provision-instance/index.jsx @@ -0,0 +1,100 @@ +import React, { useState, useEffect } from 'react'; +import PropTypes from 'prop-types'; +import { Search32, Close32 } from '@carbon/icons-react'; +import { Button, Checkbox, TextInput } from 'carbon-components-react'; + +/** Component to filter the images at provisioning instances page. */ +const FilterProvisionInstance = ({ + hideDeprecated, searchText, url, showCheckbox, +}) => { + const [data, setData] = useState({ + loading: false, + searchText, + hideDeprecated, + }); + + useEffect(() => { + if (data.loading) { + $.post(`${url}?search_text=${encodeURIComponent(data.searchText)}&hide_deprecated_templates=${data.hideDeprecated}`); + } + }, [data.loading]); + + /** Function to handle the clear button's click event of the search bar. */ + const onClear = () => { + const updatedData = searchText ? { loading: true } : {}; + setData({ ...data, searchText: '', ...updatedData }); + }; + + /** Function to render the Clear button. */ + const renderClear = () => ( +