From 5499f82bb5d437d23e5d6c2acf6a7f7da394f4e8 Mon Sep 17 00:00:00 2001 From: Harpreet Kataria Date: Wed, 19 Aug 2020 15:52:35 -0400 Subject: [PATCH] Control Explorer split part #5 In this commit, Alert Profiles accordion has been moved into it's own explorer, as part of Control explorer split. This is a pre-work for Control explorer de-explorization. Moved some common methods to `policy_mixin`. https://github.com/ManageIQ/manageiq-ui-classic/issues/6819 --- app/controllers/miq_alert_set_controller.rb | 539 ++++++++++++++++++ app/controllers/miq_policy_controller.rb | 246 +------- app/controllers/mixins/policy_mixin.rb | 203 +++++++ ...file_center.rb => miq_alert_set_center.rb} | 12 +- ...les_center.rb => miq_alert_sets_center.rb} | 8 +- .../application_helper/toolbar_chooser.rb | 6 +- app/presenters/menu/default_menu.rb | 1 + .../tree_builder_alert_profile_assign.rb | 2 +- .../tree_builder_alert_profile_obj.rb | 2 +- .../_alert_profile_assign.html.haml | 0 .../_alert_profile_details.html.haml | 2 +- .../_alert_profile_folders.html.haml | 0 .../_alert_profile_list.html.haml | 0 app/views/miq_alert_set/explorer.html.haml | 11 + config/routes.rb | 17 + 15 files changed, 809 insertions(+), 240 deletions(-) create mode 100644 app/controllers/miq_alert_set_controller.rb rename app/helpers/application_helper/toolbar/{miq_alert_profile_center.rb => miq_alert_set_center.rb} (82%) rename app/helpers/application_helper/toolbar/{miq_alert_profiles_center.rb => miq_alert_sets_center.rb} (66%) rename app/views/{miq_policy => miq_alert_set}/_alert_profile_assign.html.haml (100%) rename app/views/{miq_policy => miq_alert_set}/_alert_profile_details.html.haml (99%) rename app/views/{miq_policy => miq_alert_set}/_alert_profile_folders.html.haml (100%) rename app/views/{miq_policy => miq_alert_set}/_alert_profile_list.html.haml (100%) create mode 100644 app/views/miq_alert_set/explorer.html.haml diff --git a/app/controllers/miq_alert_set_controller.rb b/app/controllers/miq_alert_set_controller.rb new file mode 100644 index 000000000000..fd5745900f48 --- /dev/null +++ b/app/controllers/miq_alert_set_controller.rb @@ -0,0 +1,539 @@ +class MiqAlertSetController < ApplicationController + before_action :check_privileges + before_action :get_session_data + after_action :cleanup_action + after_action :set_session_data + + include Mixins::GenericSessionMixin + include Mixins::BreadcrumbsMixin + include Mixins::PolicyMixin + + UI_FOLDERS = [Host, Vm, ContainerReplicator, ContainerGroup, ContainerNode, ContainerImage, ContainerProject, ExtManagementSystem, PhysicalServer].freeze + + def title + @title = _("Policies") + end + + def index + flash_to_session + redirect_to(:action => 'explorer') + end + + # handle buttons pressed on the button bar + def button + @edit = session[:edit] # Restore @edit for adv search box + @refresh_div = "main_div" # Default div for button.rjs to refresh + + unless @refresh_partial # if no button handler ran, show not implemented msg + add_flash(_("Button not yet implemented"), :error) + @refresh_partial = "layouts/flash_msg" + @refresh_div = "flash_msg_div" + end + end + + ALERT_SET_X_BUTTON_ALLOWED_ACTIONS = { + 'miq_alert_set_assign' => :miq_alert_set_assign, + 'miq_alert_set_edit' => :miq_alert_set_edit, + 'miq_alert_set_new' => :miq_alert_set_edit, + }.freeze + + def x_button + generic_x_button(ALERT_SET_X_BUTTON_ALLOWED_ACTIONS) + end + + def explorer + @breadcrumbs = [] + @explorer = true + session[:export_data] = nil + + self.x_active_tree ||= 'alert_profile_tree' + self.x_active_accord ||= 'alert_profile' + + build_accordions_and_trees + get_node_info(x_node) + + render :layout => "application" + end + + # Item clicked on in the explorer right cell + def x_show + @explorer = true + tree_select + end + + def accordion_select + self.x_active_accord = params[:id].sub(/_accord$/, '') + self.x_active_tree = "#{self.x_active_accord}_tree" + get_node_info(x_node) + replace_right_cell(:nodetype => @nodetype) + end + + def tree_select + # set these when a link on one of the summary screen was pressed + self.x_active_accord = params[:accord] if params[:accord] + self.x_active_tree = "#{params[:accord]}_tree" if params[:accord] + self.x_active_tree = params[:tree] if params[:tree] + self.x_node = params[:id] + + @sb[:action] = nil + get_node_info(x_node) + replace_right_cell(:nodetype => @nodetype) + end + + def search + get_node_info(x_node) + replace_right_cell(:nodetype => "xx") + end + + def alert_profile_load + @alert_profile = @edit[:alert_profile_id] ? MiqAlertSet.find_by(:id => @edit[:alert_profile_id]) : MiqAlertSet.new + end + + def alert_profile_edit_cancel + return unless alert_profile_edit_load_edit + + @sb[:action] = @edit = nil + if @alert_profile && @alert_profile.id.blank? + add_flash(_("Add of new Alert Profile was cancelled by the user")) + else + add_flash(_("Edit of Alert Profile \"%{name}\" was cancelled by the user") % {:name => @alert_profile.description}) + end + get_node_info(x_node) + replace_right_cell(:nodetype => @nodetype, :remove_form_buttons => true) + end + + def alert_profile_edit_reset + alert_profile_build_edit_screen + @sb[:action] = "miq_alert_set_edit" + if params[:button] == 'reset' + add_flash(_("All changes have been reset"), :warning) + end + replace_right_cell(:nodetype => "ap") + end + + def alert_profile_edit_save_add + assert_privileges("miq_alert_set_#{@alert_profile.id ? "edit" : "new"}") + add_flash(_("Alert Profile must contain at least one Alert"), :error) if @edit[:new][:alerts].empty? + + alert_profile = @alert_profile.id.blank? ? MiqAlertSet.new : MiqAlertSet.find(@alert_profile.id) # Get new or existing record + alert_profile.description = @edit[:new][:description] + alert_profile.notes = @edit[:new][:notes] + alert_profile.mode = @edit[:new][:mode] + + unless alert_profile.valid? && !@flash_array && alert_profile.save + alert_profile.errors.each do |field, msg| + add_flash("#{field.to_s.capitalize} #{msg}", :error) + end + replace_right_cell(:nodetype => "ap") + return + end + + alerts = alert_profile.members # Get the sets members + current = alerts.collect(&:id) # Build an array of the current alert ids + mems = @edit[:new][:alerts].invert # Get the ids from the member list box + begin + alerts.each { |a| alert_profile.remove_member(MiqAlert.find(a)) unless mems.include?(a.id) } # Remove any alerts no longer in the members list box + mems.each_key { |m| alert_profile.add_member(MiqAlert.find(m)) unless current.include?(m) } # Add any alerts not in the set + rescue StandardError => bang + add_flash(_("Error during 'Alert Profile %{params}': %{message}") % + {:params => params[:button], :message => bang.message}, :error) + end + AuditEvent.success(build_saved_audit(alert_profile, @edit)) + flash_key = params[:button] == "save" ? _("Alert Profile \"%{name}\" was saved") : _("Alert Profile \"%{name}\" was added") + add_flash(flash_key % {:name => @edit[:new][:description]}) + alert_profile_get_info(MiqAlertSet.find(alert_profile.id)) + @sb[:action] = @edit = nil + self.x_node = @new_alert_profile_node = "xx-#{alert_profile.mode}_ap-#{alert_profile.id}" + get_node_info(@new_alert_profile_node) + replace_right_cell(:nodetype => "ap", :replace_trees => %i[alert_profile], :remove_form_buttons => true) + end + + def alert_profile_edit_move + handle_selection_buttons(:alerts) + session[:changed] = (@edit[:new] != @edit[:current]) + replace_right_cell(:nodetype => "ap") + end + + def alert_profile_edit_load_edit + # Load @edit/vars for other buttons + id = params[:id] || 'new' + return false unless load_edit("alert_profile_edit__#{id}", "replace_cell__explorer") + + alert_profile_load + true + end + + def miq_alert_set_edit + case params[:button] + when 'cancel' + alert_profile_edit_cancel + when 'reset', nil # Reset or first time in + alert_profile_edit_reset + when 'save', 'add' + return unless alert_profile_edit_load_edit + + alert_profile_edit_save_add + when 'move_right', 'move_left', 'move_allleft' + return unless alert_profile_edit_load_edit + + alert_profile_edit_move + end + end + + def miq_alert_set_assign + assert_privileges("miq_alert_set_assign") + @assign = @sb[:assign] + @alert_profile = @assign[:alert_profile] if @assign + case params[:button] + when "cancel" + @assign = nil + add_flash(_("Edit Alert Profile assignments cancelled by user")) + get_node_info(x_node) + replace_right_cell(:nodetype => @nodetype) + when "save" + if @assign[:new][:assign_to].to_s.ends_with?("-tags") && !@assign[:new][:cat] + add_flash(_("A Tag Category must be selected"), :error) + elsif @assign[:new][:assign_to] && @assign[:new][:assign_to] != "enterprise" && @assign[:new][:objects].empty? + add_flash(_("At least one Selection must be checked"), :error) + end + unless flash_errors? + alert_profile_assign_save + add_flash(_("Alert Profile \"%{alert_profile}\" assignments successfully saved") % + {:alert_profile => @alert_profile.description}) + get_node_info(x_node) + @assign = nil + end + replace_right_cell(:nodetype => "ap") + when "reset", nil # Reset or first time in + alert_profile_build_assign_screen + if params[:button] == "reset" + add_flash(_("All changes have been reset"), :warning) + end + replace_right_cell(:nodetype => "ap") + end + end + + def alert_profile_field_changed + return unless load_edit("alert_profile_edit__#{params[:id]}", "replace_cell__explorer") + + @alert_profile = @edit[:alert_profile_id] ? MiqAlertSet.find(@edit[:alert_profile_id]) : MiqAlertSet.new + + @edit[:new][:description] = params[:description].presence if params[:description] + @edit[:new][:notes] = params[:notes].presence if params[:notes] + + send_button_changes + end + + def alert_profile_assign_changed + @assign = @sb[:assign] + @alert_profile = @assign[:alert_profile] + + if params.key?(:chosen_assign_to) + @assign[:new][:assign_to] = params[:chosen_assign_to].presence + @assign[:new][:cat] = nil # Clear chosen tag category + end + + @assign[:new][:cat] = params[:chosen_cat].blank? ? nil : params[:chosen_cat].to_i if params.key?(:chosen_cat) + if params.key?(:chosen_assign_to) || params.key?(:chosen_cat) + @assign[:new][:objects] = [] # Clear selected objects + @assign[:obj_tree] = alert_profile_build_obj_tree # Build the selection tree + end + if params.key?(:id) + if params[:check] == "1" + @assign[:new][:objects].push(params[:id].split("-").last.to_i) + @assign[:new][:objects].sort! + else + @assign[:new][:objects].delete(params[:id].split("-").last.to_i) + end + end + + send_button_changes + end + + private + + def alert_profile_get_assign_to_objects_empty? + return true if @assign[:new][:assign_to].blank? + return true if @assign[:new][:assign_to] == "enterprise" + return true if @assign[:new][:assign_to].ends_with?("-tags") && @assign[:new][:cat].blank? + + false + end + + # Build the assign objects selection tree + def alert_profile_build_obj_tree + return nil if alert_profile_get_assign_to_objects_empty? + + if @assign[:new][:assign_to] == "ems_folder" + instantiate_tree("TreeBuilderEmsFolders", :ems_folders_tree, + @assign[:new][:objects].collect { |f| "EmsFolder_#{f}" }) + elsif @assign[:new][:assign_to] == "resource_pool" + instantiate_tree("TreeBuilderResourcePools", :resource_pools_tree, + @assign[:new][:objects].collect { |f| "ResourcePool_#{f}" }) + else + instantiate_tree("TreeBuilderAlertProfileObj", :object_tree, @assign[:new][:objects]) + end + end + + def instantiate_tree(tree_class, tree_name, selected_nodes) + tree_class.constantize.new(tree_name, + @sb, + true, + :assign_to => @assign[:new][:assign_to], + :cat => @assign[:new][:cat], + :selected_nodes => selected_nodes) + end + + def alert_profile_build_edit_screen + @edit = {} + @edit[:new] = {} + @edit[:current] = {} + + @alert_profile = params[:id] ? MiqAlertSet.find(params[:id]) : MiqAlertSet.new # Get existing or new record + @edit[:key] = "alert_profile_edit__#{@alert_profile.id || "new"}" + @edit[:rec_id] = @alert_profile.id || nil + + @edit[:alert_profile_id] = @alert_profile.id + @edit[:new][:description] = @alert_profile.description + @edit[:new][:notes] = @alert_profile.notes + @edit[:new][:mode] = @alert_profile.mode || @sb[:folder] # Use existing model or model from selected folder + + @edit[:new][:alerts] = {} + alerts = @alert_profile.members # Get the set's members + alerts.each { |a| @edit[:new][:alerts][a.description] = a.id } # Build a hash for the members list box + + @edit[:choices] = {} + MiqAlert.where(:db => @edit[:new][:mode]).select(:id, :description).each do |a| + @edit[:choices][a.description] = a.id # Build a hash for the alerts to choose from + end + + @edit[:new][:alerts].each_key do |key| + @edit[:choices].delete(key) # Remove any alerts that are in the members list box + end + + @edit[:current] = copy_hash(@edit[:new]) + + @embedded = true + @in_a_form = true + @edit[:current][:add] = true unless @edit[:alert_profile_id] # Force changed to be true if adding a record + session[:changed] = (@edit[:new] != @edit[:current]) + end + + def alert_profile_build_assign_screen + @assign = {} + @assign[:new] = {} + @assign[:current] = {} + @sb[:action] = "miq_alert_set_assign" + @assign[:rec_id] = params[:id] + + @alert_profile = MiqAlertSet.find(params[:id]) # Get existing record + @assign[:alert_profile] = @alert_profile + + @assign[:cats] = {} + Classification.categories.find_all { |c| !c.read_only? && c.show && !c.entries.empty? } + .each { |c| @assign[:cats][c.id] = c.description } + + @assign[:new][:assign_to] = nil + @assign[:new][:cat] = nil + @assign[:new][:objects] = [] + aa = @alert_profile.get_assigned_tos + if !aa[:objects].empty? # Objects are assigned + if aa[:objects].first.kind_of?(MiqEnterprise) # Assigned to Enterprise object + @assign[:new][:assign_to] = "enterprise" + else # Assigned to CIs + @assign[:new][:assign_to] = aa[:objects].first.class.base_class.to_s.underscore + @assign[:new][:objects] = aa[:objects].collect(&:id).sort! + end + elsif !aa[:tags].empty? # Tags are assigned + @assign[:new][:assign_to] = aa[:tags].first.last + "-tags" + @assign[:new][:cat] = aa[:tags].first.first.parent_id + @assign[:new][:objects] = aa[:tags].collect { |o| o.first.id } + end + @assign[:obj_tree] = alert_profile_build_obj_tree # Build the selection tree + + @assign[:current] = copy_hash(@assign[:new]) + + @embedded = true + @in_a_form = true + session[:changed] = (@assign[:new] != @assign[:current]) + end + + # Save alert profile assignments + def alert_profile_assign_save + @alert_profile.remove_all_assigned_tos # Remove existing assignments + if @assign[:new][:assign_to] # If an assignment is selected + if @assign[:new][:assign_to] == "enterprise" # Assign to enterprise + @alert_profile.assign_to_objects(MiqEnterprise.first) + elsif @assign[:new][:assign_to].ends_with?("-tags") # Assign to selected tags + @alert_profile.assign_to_tags(@assign[:new][:objects], @assign[:new][:assign_to].split("-").first) + elsif @assign[:new][:assign_to] # Assign to selected objects + @alert_profile.assign_to_objects(@assign[:new][:objects], @assign[:new][:assign_to]) + end + end + end + + def alert_profile_get_all_folders + @ap_folders = MiqAlert.base_tables.sort_by { |db| ui_lookup(:model => db) }.collect do |db| + [ui_lookup(:model => db), db] + end + @right_cell_text = _("All Alert Profiles") + @right_cell_div = "alert_profile_folders" + end + + # Get information for an alert profile + def alert_profile_get_info(alert_profile) + @record = @alert_profile = alert_profile + aa = @alert_profile.get_assigned_tos + @alert_profile_tag = Classification.find(aa[:tags].first.first.parent_id) unless aa[:tags].empty? + @alert_profile_alerts = @alert_profile.miq_alerts.sort_by { |a| a.description.downcase } + @right_cell_text = _("Alert Profile \"%{name}\"") % {:name => alert_profile.description} + @right_cell_div = "alert_profile_details" + end + + # Get all info for the node about to be displayed + def get_node_info(treenodeid, show_list = true) + @show_list = show_list + _modelname, nodeid, @nodetype = TreeBuilder.extract_node_model_and_id(valid_active_node(treenodeid)) + node_ids = {} + treenodeid.split("_").each do |p| + # Create a hash of all record ids represented by the selected tree node + node_ids[p.split("-").first] = p.split("-").last + end + @sb[:node_ids] ||= {} + @sb[:node_ids][x_active_tree] = node_ids + get_root_node_info if x_node == "root" # Get node info of tree roots + folder_get_info(treenodeid) if treenodeid != "root" # Get folder info for all node types + alert_profile_get_info(MiqAlertSet.find(nodeid)) if @nodetype == 'ap' + @show_adv_search = @nodetype == "xx" && !@folders + {:view => @view, :pages => @pages} + end + + # Fetches right side info if a tree root is selected + def get_root_node_info + alert_profile_get_all_folders + end + + # replace_trees can be an array of tree symbols to be replaced + def replace_right_cell(options = {}) + nodetype, replace_trees, presenter = options.values_at(:nodetype, :replace_trees, :presenter) + replace_trees = @replace_trees if @replace_trees # get_node_info might set this + replace_trees = Array(replace_trees) + @explorer = true + + trees = build_replaced_trees(replace_trees, %i[policy action alert_profile alert]) + + c_tb = build_toolbar(center_toolbar_filename) + + # Build a presenter to render the JS + presenter ||= ExplorerPresenter.new( + :active_tree => x_active_tree, + :open_accord => params[:accord] + ) + + self.x_node = @new_alert_profile_node if @new_alert_profile_node + + reload_trees_by_presenter(presenter, trees) + + presenter[:osf_node] = x_node + + @changed = session[:changed] if @edit # to get save/reset buttons to highlight when fields are moved left/right + + # Replace right side with based on selected tree node type + case nodetype + when 'root' + partial_name, model = ['alert_profile_folders', _('Alert Profiles')] + presenter.update(:main_div, r[:partial => partial_name]) + right_cell_text = _("All %{models}") % {:models => model} + right_cell_text += _(" (Names with \"%{search_text}\")") % {:search_text => @search_text} if @search_text.present? && %w[alert_profile_tree policy_tree].exclude?(x_active_tree.to_s) + when 'xx' + presenter.update( + :main_div, + if @alert_profiles + right_cell_text = _("All %{typ} Alert Profiles") % {:typ => ui_lookup(:model => @sb[:folder].try(:camelize))} + r[:partial => 'alert_profile_list'] + end + ) + right_cell_text += _(" (Names with \"%{search_text}\")") % {:search_text => @search_text} if @search_text.present? && !@folders + when 'ap' + presenter.update(:main_div, r[:partial => 'alert_profile_details', :locals => {:read_only => true}]) + right_cell_text = if @alert_profile.id.blank? + _("Adding a new Alert Profile") + elsif @edit + _("Editing %{model} Alert Profile \"%{name}\"") % {:name => @alert_profile.description, + :model => ui_lookup(:model => @edit[:new][:mode])} + else + _("Alert Profile \"%{name}\"") % {:name => @alert_profile.description} + end + end + presenter[:right_cell_text] = @right_cell_text = right_cell_text + + presenter.reload_toolbars(:center => c_tb) + + if ((@edit && @edit[:new]) || @assign) && params[:action] != "x_search_by_name" + locals = { + :action_url => @sb[:action], + :record_id => @edit ? @edit[:rec_id] : @assign[:rec_id], + } + presenter.hide(:toolbar) + # If was hidden for summary screen and there were no records on show_list + presenter.show(:paging_div, :form_buttons_div) + presenter.update(:form_buttons_div, r[:partial => "layouts/x_edit_buttons", :locals => locals]) + else + # Added so buttons can be turned off even tho div is not being displayed it still pops up + # Abandon changes box when trying to change a node on tree after saving a record + presenter.hide(:buttons_on).show(:toolbar).hide(:paging_div) + end + + presenter.hide(:form_buttons_div) if options[:remove_form_buttons] + + replace_search_box(presenter, :nameonly => true) + + # Hide/show searchbox depending on if a list is showing + presenter.set_visibility(@show_adv_search, :adv_searchbox_div) + + presenter[:record_id] = @record.try(:id) + + presenter[:lock_sidebar] = (@edit || @assign) && params[:action] != "x_search_by_name" + + presenter.update(:breadcrumbs, r[:partial => 'layouts/breadcrumbs']) + + render :json => presenter.for_render + end + + def get_session_data + @title = _("Alert Profiles") + @layout = "miq_alert_set" + @lastaction = session[:miq_alert_set_lastaction] + @display = session[:miq_alert_set_display] + @current_page = session[:miq_alert_set_current_page] + end + + def set_session_data + super + session[:layout] = @layout + session[:miq_alert_set_current_page] = @current_page + end + + def features + [ + { + :name => :alert_profile, + :title => _("Alert Profiles"), + :role => "alert_profile", + :role_any => true + }, + ].map { |hsh| ApplicationController::Feature.new_with_hash(hsh) } + end + + def breadcrumbs_options + { + :breadcrumbs => [ + {:title => _("Control")}, + {:title => _('Explorer')}, + ].compact, + :record_title => :description, + } + end + + menu_section :con +end diff --git a/app/controllers/miq_policy_controller.rb b/app/controllers/miq_policy_controller.rb index 442e2e180a78..d92ac0dbb40a 100644 --- a/app/controllers/miq_policy_controller.rb +++ b/app/controllers/miq_policy_controller.rb @@ -95,9 +95,6 @@ def button 'alert_edit' => :alert_edit, 'alert_copy' => :alert_edit, 'alert_new' => :alert_edit, - 'alert_profile_assign' => :alert_profile_assign, - 'alert_profile_edit' => :alert_profile_edit, - 'alert_profile_new' => :alert_profile_edit, 'miq_event_edit' => :miq_event_edit, 'policy_copy' => :policy_copy, 'policy_edit' => :policy_edit, @@ -266,7 +263,7 @@ def search case x_active_tree when "profile", "action", "alert" replace_right_cell(:nodetype => x_node) - when "policy", "alert_profile" + when "policy" replace_right_cell(:nodetype => "xx") end end @@ -372,13 +369,11 @@ def get_node_info(treenodeid, show_list = true) policy_get_info(MiqPolicy.find(nodeid)) when "a", "ta", "fa" # Action or True/False Action action_get_info(MiqAction.find(nodeid)) - when "ap" # Alert Profile - alert_profile_get_info(MiqAlertSet.find(nodeid)) when "al" # Alert alert_get_info(MiqAlert.find(nodeid)) end @show_adv_search = (@nodetype == "xx" && !@folders) || - (@nodetype == "root" && !%i[alert_profile_tree policy_tree].include?(x_active_tree)) + (@nodetype == "root" && !%i[policy_tree].include?(x_active_tree)) {:view => @view, :pages => @pages} end @@ -389,8 +384,6 @@ def get_root_node_info policy_get_all_folders when :action_tree action_get_all - when :alert_profile_tree - alert_profile_get_all_folders when :alert_tree alert_get_all end @@ -403,7 +396,7 @@ def replace_right_cell(options = {}) replace_trees = Array(replace_trees) @explorer = true - trees = build_replaced_trees(replace_trees, %i[policy action alert_profile alert]) + trees = build_replaced_trees(replace_trees, %i[policy action alert]) c_tb = build_toolbar(center_toolbar_filename) @@ -420,8 +413,6 @@ def replace_right_cell(options = {}) self.x_node = @new_policy_node if @new_policy_node when :action self.x_node = @new_action_node if @new_action_node - when :alert_profile - self.x_node = @new_alert_profile_node if @new_alert_profile_node when :alert self.x_node = @new_alert_node if @new_alert_node else @@ -441,13 +432,12 @@ def replace_right_cell(options = {}) case x_active_tree when :policy_tree then ['policy_folders', _('Policies')] when :action_tree then ['action_list', _('Actions')] - when :alert_profile_tree then ['alert_profile_folders', _('Alert Profiles')] when :alert_tree then ['alert_list', _('Alerts')] end presenter.update(:main_div, r[:partial => partial_name]) right_cell_text = _("All %{models}") % {:models => model} - right_cell_text += _(" (Names with \"%{search_text}\")") % {:search_text => @search_text} if @search_text.present? && %w[alert_profile_tree policy_tree].exclude?(x_active_tree.to_s) + right_cell_text += _(" (Names with \"%{search_text}\")") % {:search_text => @search_text} if @search_text.present? && %w[policy_tree].exclude?(x_active_tree.to_s) when 'xx' presenter.update( :main_div, @@ -466,9 +456,6 @@ def replace_right_cell(options = {}) _("%{typ} Policies") % {:typ => mode.capitalize} end r[:partial => 'policy_folders'] - elsif @alert_profiles - right_cell_text = _("All %{typ} Alert Profiles") % {:typ => ui_lookup(:model => @sb[:folder].try(:camelize))} - r[:partial => 'alert_profile_list'] end ) right_cell_text += _(" (Names with \"%{search_text}\")") % {:search_text => @search_text} if @search_text.present? && !@folders @@ -505,16 +492,6 @@ def replace_right_cell(options = {}) msg = @edit ? _("Editing Action \"%{name}\"") : _("Action \"%{name}\"") msg % {:name => @action.description} end - when 'ap' - presenter.update(:main_div, r[:partial => 'alert_profile_details', :locals => {:read_only => true}]) - right_cell_text = if @alert_profile.id.blank? - _("Adding a new Alert Profile") - elsif @edit - _("Editing %{model} Alert Profile \"%{name}\"") % {:name => @alert_profile.description, - :model => ui_lookup(:model => @edit[:new][:mode])} - else - _("Alert Profile \"%{name}\"") % {:name => @alert_profile.description} - end when 'al' presenter.update(:main_div, r[:partial => 'alert_details', :locals => {:read_only => true}]) right_cell_text = if @alert.id.blank? @@ -564,205 +541,32 @@ def replace_right_cell(options = {}) render :json => presenter.for_render end - def handle_selection_buttons_left(members, members_chosen, choices, _choices_chosen) - if params[members_chosen].nil? - add_flash(_("No %{members} were selected to move left") % {:members => members.to_s.split("_").first.titleize}, - :error) - return - end - - if @edit[:event_id] - # Handle Actions for an Event - params[members_chosen].each do |mc| - idx = nil - # Find the index of the new members array - @edit[:new][members].each_with_index { |mem, i| idx = mem[-1] == mc.to_i ? i : idx } - next if idx.nil? - - desc = @edit[:new][members][idx][0].slice(4..-1) # Remove (x) prefix from the chosen item - @edit[choices][desc] = mc.to_i # Add item back into the choices hash - @edit[:new][members].delete_at(idx) # Remove item from the array - end - else - mems = @edit[:new][members].invert - params[members_chosen].each do |mc| - @edit[choices][mems[mc.to_i]] = mc.to_i - @edit[:new][members].delete(mems[mc.to_i]) - end - end - end - - def handle_selection_buttons_right(members, _members_chosen, choices, choices_chosen) - if params[choices_chosen].nil? - add_flash(_("No %{member} were selected to move right") % - {:member => members.to_s.split("_").first.titleize}, :error) - return - end - - mems = @edit[choices].invert - if @edit[:event_id] - # Handle Actions for an Event - params[choices_chosen].each do |mc| - # Add selection to chosen members array, default to synch = true - @edit[:new][members].push(["(S) " + mems[mc.to_i], true, mc.to_i]) - @edit[choices].delete(mems[mc.to_i]) # Remove from the choices hash - end - else - params[choices_chosen].each do |mc| - @edit[:new][members][mems[mc.to_i]] = mc.to_i - @edit[choices].delete(mems[mc.to_i]) - end - end - end - - def handle_selection_buttons_allleft(members, _members_chosen, choices, _choices_chosen) - if @edit[:new][members].empty? - add_flash(_("No %{member} were selected to move left") % - {:member => members.to_s.split("_").first.titleize}, :error) - return - end - - if @edit[:event_id] - # Handle Actions for an Event - @edit[:new][members].each do |m| - # Put description/id of each chosen member back into choices hash - @edit[choices][m.first.slice(4..-1)] = m.last - end - else - @edit[:new][members].each do |key, value| - @edit[choices][key] = value - end - end - @edit[:new][members].clear - end - - def handle_selection_buttons_sortout_selected(members_chosen) - if params[:button].starts_with?("true") - @true_selected = params[members_chosen][0].to_i - else - @false_selected = params[members_chosen][0].to_i - end - end - - def handle_selection_buttons_up_down(members, members_chosen, _choices, _choices_chosen, up) - if params[members_chosen].nil? || params[members_chosen].length != 1 - message = if up - _("Select only one or consecutive %{member} to move up") - else - _("Select only one or consecutive %{member} to move down") - end - - add_flash(message % {:member => members.to_s.split("_").first.singularize.titleize}, :error) - return - end - - handle_selection_buttons_sortout_selected(members_chosen) - idx = nil - mc = params[members_chosen][0] - # Find item index in new members array - @edit[:new][members].each_with_index { |mem, i| idx = mem[-1] == mc.to_i ? i : idx } - - return if idx.nil? - return if up && idx.zero? # cannot go higher - return if !up && idx >= @edit[:new][members].length - 1 # canot go lower - - pulled = @edit[:new][members].delete_at(idx) - delta = up ? -1 : 1 - @edit[:new][members].insert(idx + delta, pulled) - end - - def handle_selection_buttons_sync_async(members, members_chosen, _choices, _choices_chosen, sync) - if params[members_chosen].nil? - msg = if sync - _("No %{member} selected to set to Synchronous") - else - _("No %{member} selected to set to Asynchronous") - end - add_flash(msg % {:member => members.to_s.split("_").first.titleize}, :error) - return - end - - handle_selection_buttons_sortout_selected(members_chosen) - - params[members_chosen].each do |mc| - idx = nil - # Find the index in the new members array - @edit[:new][members].each_with_index { |mem, i| idx = mem[-1] == mc.to_i ? i : idx } - next if idx.nil? - - letter = sync ? 'S' : 'A' - @edit[:new][members][idx][0] = "(#{letter}) " + @edit[:new][members][idx][0].slice(4..-1) # Change prefix to (A) - @edit[:new][members][idx][1] = sync # true for sync - end - end - - # Handle the middle buttons on the add/edit forms - # pass in member list symbols (i.e. :policies) - def handle_selection_buttons(members, - members_chosen = :members_chosen, - choices = :choices, - choices_chosen = :choices_chosen) - if params[:button].ends_with?("_left") - handle_selection_buttons_left(members, members_chosen, choices, choices_chosen) - elsif params[:button].ends_with?("_right") - handle_selection_buttons_right(members, members_chosen, choices, choices_chosen) - elsif params[:button].ends_with?("_allleft") - handle_selection_buttons_allleft(members, members_chosen, choices, choices_chosen) - elsif params[:button].ends_with?("_up") - handle_selection_buttons_up_down(members, members_chosen, choices, choices_chosen, true) - elsif params[:button].ends_with?("_down") - handle_selection_buttons_up_down(members, members_chosen, choices, choices_chosen, false) - elsif params[:button].ends_with?("_sync") - handle_selection_buttons_sync_async(members, members_chosen, choices, choices_chosen, true) - elsif params[:button].ends_with?("_async") - handle_selection_buttons_sync_async(members, members_chosen, choices, choices_chosen, false) - end - end - - def apply_search_filter(search_str, results) - if search_str.first == "*" - results.delete_if { |r| !r.description.downcase.ends_with?(search_str[1..-1].downcase) } - elsif search_str.last == "*" - results.delete_if { |r| !r.description.downcase.starts_with?(search_str[0..-2].downcase) } - else - results.delete_if { |r| !r.description.downcase.include?(search_str.downcase) } - end - end - # Get list of folder contents def folder_get_info(folder_node) nodetype, nodeid = folder_node.split("_") @sb[:mode] = nil @sb[:nodeid] = nil @sb[:folder] = nodeid.nil? ? nodetype.split("-").last : nodeid - if x_active_tree == :policy_tree - if nodeid.nil? && %w[compliance control].include?(nodetype.split('-').last) - # level 1 - compliance & control - _, mode = nodetype.split('-') - @folders = UI_FOLDERS.collect do |model| - "#{model.name.titleize} #{mode.titleize}" - end - @right_cell_text = case mode - when 'compliance' then _('Compliance Policies') - when 'control' then _('Control Policies') - else _("%{typ} Policies") % {:typ => mode.titleize} - end - else - # level 2 - host, vm, etc. under compliance/control - OR deeper levels - @sb[:mode] = nodeid.split("-")[1] - @sb[:nodeid] = nodeid.split("-").last - @sb[:folder] = "#{nodeid.split("-")[1]}-#{nodeid.split("-")[2]}" - set_search_text - policy_get_all if folder_node.split("_").length <= 2 - @right_cell_text = _("All %{typ} Policies") % {:typ => ui_lookup(:model => @sb[:nodeid].try(:camelize))} - @right_cell_div = "policy_list" + if nodeid.nil? && %w[compliance control].include?(nodetype.split('-').last) + # level 1 - compliance & control + _, mode = nodetype.split('-') + @folders = UI_FOLDERS.collect do |model| + "#{model.name.titleize} #{mode.titleize}" end - elsif x_active_tree == :alert_profile_tree - @alert_profiles = MiqAlertSet.where(:mode => @sb[:folder]).sort_by { |as| as.description.downcase } + @right_cell_text = case mode + when 'compliance' then _('Compliance Policies') + when 'control' then _('Control Policies') + else _("%{typ} Policies") % {:typ => mode.titleize} + end + else + # level 2 - host, vm, etc. under compliance/control - OR deeper levels + @sb[:mode] = nodeid.split("-")[1] + @sb[:nodeid] = nodeid.split("-").last + @sb[:folder] = "#{nodeid.split("-")[1]}-#{nodeid.split("-")[2]}" set_search_text - @alert_profiles = apply_search_filter(@search_text, @alert_profiles) if @search_text.present? - @right_cell_text = _("All %{typ} Alert Profiles") % {:typ => ui_lookup(:model => @sb[:folder].try(:camelize))} - @right_cell_div = "alert_profile_list" + policy_get_all if folder_node.split("_").length <= 2 + @right_cell_text = _("All %{typ} Policies") % {:typ => ui_lookup(:model => @sb[:nodeid].try(:camelize))} + @right_cell_div = "policy_list" end end @@ -871,12 +675,6 @@ def features :role => "policy", :role_any => true }, - { - :name => :alert_profile, - :title => _("Alert Profiles"), - :role => "alert_profile", - :role_any => true - }, { :name => :alert, :title => _("Alerts"), diff --git a/app/controllers/mixins/policy_mixin.rb b/app/controllers/mixins/policy_mixin.rb index 1f0db8348938..4a62f01e3cd2 100644 --- a/app/controllers/mixins/policy_mixin.rb +++ b/app/controllers/mixins/policy_mixin.rb @@ -146,5 +146,208 @@ def build_snmp_options(subkey, process_variables) end refresh end + + + def handle_selection_buttons_left(members, members_chosen, choices, _choices_chosen) + if params[members_chosen].nil? + add_flash(_("No %{members} were selected to move left") % {:members => members.to_s.split("_").first.titleize}, + :error) + return + end + + if @edit[:event_id] + # Handle Actions for an Event + params[members_chosen].each do |mc| + idx = nil + # Find the index of the new members array + @edit[:new][members].each_with_index { |mem, i| idx = mem[-1] == mc.to_i ? i : idx } + next if idx.nil? + + desc = @edit[:new][members][idx][0].slice(4..-1) # Remove (x) prefix from the chosen item + @edit[choices][desc] = mc.to_i # Add item back into the choices hash + @edit[:new][members].delete_at(idx) # Remove item from the array + end + else + mems = @edit[:new][members].invert + params[members_chosen].each do |mc| + @edit[choices][mems[mc.to_i]] = mc.to_i + @edit[:new][members].delete(mems[mc.to_i]) + end + end + end + + def handle_selection_buttons_right(members, _members_chosen, choices, choices_chosen) + if params[choices_chosen].nil? + add_flash(_("No %{member} were selected to move right") % + {:member => members.to_s.split("_").first.titleize}, :error) + return + end + + mems = @edit[choices].invert + if @edit[:event_id] + # Handle Actions for an Event + params[choices_chosen].each do |mc| + # Add selection to chosen members array, default to synch = true + @edit[:new][members].push(["(S) " + mems[mc.to_i], true, mc.to_i]) + @edit[choices].delete(mems[mc.to_i]) # Remove from the choices hash + end + else + params[choices_chosen].each do |mc| + @edit[:new][members][mems[mc.to_i]] = mc.to_i + @edit[choices].delete(mems[mc.to_i]) + end + end + end + + def handle_selection_buttons_allleft(members, _members_chosen, choices, _choices_chosen) + if @edit[:new][members].empty? + add_flash(_("No %{member} were selected to move left") % + {:member => members.to_s.split("_").first.titleize}, :error) + return + end + + if @edit[:event_id] + # Handle Actions for an Event + @edit[:new][members].each do |m| + # Put description/id of each chosen member back into choices hash + @edit[choices][m.first.slice(4..-1)] = m.last + end + else + @edit[:new][members].each do |key, value| + @edit[choices][key] = value + end + end + @edit[:new][members].clear + end + + def handle_selection_buttons_sortout_selected(members_chosen) + if params[:button].starts_with?("true") + @true_selected = params[members_chosen][0].to_i + else + @false_selected = params[members_chosen][0].to_i + end + end + + def handle_selection_buttons_up_down(members, members_chosen, _choices, _choices_chosen, up) + if params[members_chosen].nil? || params[members_chosen].length != 1 + message = if up + _("Select only one or consecutive %{member} to move up") + else + _("Select only one or consecutive %{member} to move down") + end + + add_flash(message % {:member => members.to_s.split("_").first.singularize.titleize}, :error) + return + end + + handle_selection_buttons_sortout_selected(members_chosen) + idx = nil + mc = params[members_chosen][0] + # Find item index in new members array + @edit[:new][members].each_with_index { |mem, i| idx = mem[-1] == mc.to_i ? i : idx } + + return if idx.nil? + return if up && idx.zero? # cannot go higher + return if !up && idx >= @edit[:new][members].length - 1 # canot go lower + + pulled = @edit[:new][members].delete_at(idx) + delta = up ? -1 : 1 + @edit[:new][members].insert(idx + delta, pulled) + end + + def handle_selection_buttons_sync_async(members, members_chosen, _choices, _choices_chosen, sync) + if params[members_chosen].nil? + msg = if sync + _("No %{member} selected to set to Synchronous") + else + _("No %{member} selected to set to Asynchronous") + end + add_flash(msg % {:member => members.to_s.split("_").first.titleize}, :error) + return + end + + handle_selection_buttons_sortout_selected(members_chosen) + + params[members_chosen].each do |mc| + idx = nil + # Find the index in the new members array + @edit[:new][members].each_with_index { |mem, i| idx = mem[-1] == mc.to_i ? i : idx } + next if idx.nil? + + letter = sync ? 'S' : 'A' + @edit[:new][members][idx][0] = "(#{letter}) " + @edit[:new][members][idx][0].slice(4..-1) # Change prefix to (A) + @edit[:new][members][idx][1] = sync # true for sync + end + end + + # Handle the middle buttons on the add/edit forms + # pass in member list symbols (i.e. :policies) + def handle_selection_buttons(members, + members_chosen = :members_chosen, + choices = :choices, + choices_chosen = :choices_chosen) + if params[:button].ends_with?("_left") + handle_selection_buttons_left(members, members_chosen, choices, choices_chosen) + elsif params[:button].ends_with?("_right") + handle_selection_buttons_right(members, members_chosen, choices, choices_chosen) + elsif params[:button].ends_with?("_allleft") + handle_selection_buttons_allleft(members, members_chosen, choices, choices_chosen) + elsif params[:button].ends_with?("_up") + handle_selection_buttons_up_down(members, members_chosen, choices, choices_chosen, true) + elsif params[:button].ends_with?("_down") + handle_selection_buttons_up_down(members, members_chosen, choices, choices_chosen, false) + elsif params[:button].ends_with?("_sync") + handle_selection_buttons_sync_async(members, members_chosen, choices, choices_chosen, true) + elsif params[:button].ends_with?("_async") + handle_selection_buttons_sync_async(members, members_chosen, choices, choices_chosen, false) + end + end + + def apply_search_filter(search_str, results) + if search_str.first == "*" + results.delete_if { |r| !r.description.downcase.ends_with?(search_str[1..-1].downcase) } + elsif search_str.last == "*" + results.delete_if { |r| !r.description.downcase.starts_with?(search_str[0..-2].downcase) } + else + results.delete_if { |r| !r.description.downcase.include?(search_str.downcase) } + end + end + + # Get list of folder contents + def folder_get_info(folder_node) + nodetype, nodeid = folder_node.split("_") + @sb[:mode] = nil + @sb[:nodeid] = nil + @sb[:folder] = nodeid.nil? ? nodetype.split("-").last : nodeid + if x_active_tree == :policy_tree + if nodeid.nil? && %w[compliance control].include?(nodetype.split('-').last) + # level 1 - compliance & control + _, mode = nodetype.split('-') + @folders = UI_FOLDERS.collect do |model| + "#{model.name.titleize} #{mode.titleize}" + end + @right_cell_text = case mode + when 'compliance' then _('Compliance Policies') + when 'control' then _('Control Policies') + else _("%{typ} Policies") % {:typ => mode.titleize} + end + else + # level 2 - host, vm, etc. under compliance/control - OR deeper levels + @sb[:mode] = nodeid.split("-")[1] + @sb[:nodeid] = nodeid.split("-").last + @sb[:folder] = "#{nodeid.split("-")[1]}-#{nodeid.split("-")[2]}" + set_search_text + policy_get_all if folder_node.split("_").length <= 2 + @right_cell_text = _("All %{typ} Policies") % {:typ => ui_lookup(:model => @sb[:nodeid].try(:camelize))} + @right_cell_div = "policy_list" + end + elsif x_active_tree == :alert_profile_tree + @alert_profiles = MiqAlertSet.where(:mode => @sb[:folder]).sort_by { |as| as.description.downcase } + set_search_text + @alert_profiles = apply_search_filter(@search_text, @alert_profiles) if @search_text.present? + @right_cell_text = _("All %{typ} Alert Profiles") % {:typ => ui_lookup(:model => @sb[:folder].try(:camelize))} + @right_cell_div = "alert_profile_list" + end + end end end diff --git a/app/helpers/application_helper/toolbar/miq_alert_profile_center.rb b/app/helpers/application_helper/toolbar/miq_alert_set_center.rb similarity index 82% rename from app/helpers/application_helper/toolbar/miq_alert_profile_center.rb rename to app/helpers/application_helper/toolbar/miq_alert_set_center.rb index f3519301cbb7..727e47ddb650 100644 --- a/app/helpers/application_helper/toolbar/miq_alert_profile_center.rb +++ b/app/helpers/application_helper/toolbar/miq_alert_set_center.rb @@ -1,27 +1,27 @@ -class ApplicationHelper::Toolbar::MiqAlertProfileCenter < ApplicationHelper::Toolbar::Basic - button_group('miq_alert_profile_vmdb', [ +class ApplicationHelper::Toolbar::MiqAlertSetCenter < ApplicationHelper::Toolbar::Basic + button_group('miq_alert_set_vmdb', [ select( - :miq_alert_profile_vmdb_choice, + :miq_alert_set_vmdb_choice, nil, t = N_('Configuration'), t, :items => [ button( - :alert_profile_edit, + :miq_alert_set_edit, 'pficon pficon-edit fa-lg', t = N_('Edit this Alert Profile'), t, :url_parms => "main_div", :send_checked => true), button( - :alert_profile_assign, + :miq_alert_set_assign, 'pficon pficon-edit fa-lg', t = N_('Edit assignments for this Alert Profile'), t, :url_parms => "main_div", :send_checked => true), button( - :alert_profile_delete, + :miq_alert_set_delete, 'pficon pficon-delete fa-lg', t = N_('Delete this Alert Profile'), t, diff --git a/app/helpers/application_helper/toolbar/miq_alert_profiles_center.rb b/app/helpers/application_helper/toolbar/miq_alert_sets_center.rb similarity index 66% rename from app/helpers/application_helper/toolbar/miq_alert_profiles_center.rb rename to app/helpers/application_helper/toolbar/miq_alert_sets_center.rb index 0fb2ade93c0d..abfb94707987 100644 --- a/app/helpers/application_helper/toolbar/miq_alert_profiles_center.rb +++ b/app/helpers/application_helper/toolbar/miq_alert_sets_center.rb @@ -1,13 +1,13 @@ -class ApplicationHelper::Toolbar::MiqAlertProfilesCenter < ApplicationHelper::Toolbar::Basic - button_group('miq_alert_profile_vmdb', [ +class ApplicationHelper::Toolbar::MiqAlertSetsCenter < ApplicationHelper::Toolbar::Basic + button_group('miq_alert_set_vmdb', [ select( - :miq_alert_profile_vmdb_choice, + :miq_alert_set_vmdb_choice, nil, t = N_('Configuration'), t, :items => [ button( - :alert_profile_new, + :miq_alert_set_new, 'pficon pficon-add-circle-o fa-lg', t = proc do _('Add a New %{alert_profile_type} Alert Profile') % {:alert_profile_type => ui_lookup(:model => @sb[:folder])} diff --git a/app/helpers/application_helper/toolbar_chooser.rb b/app/helpers/application_helper/toolbar_chooser.rb index cf9d8fbd6e22..1b25cc6d6e35 100644 --- a/app/helpers/application_helper/toolbar_chooser.rb +++ b/app/helpers/application_helper/toolbar_chooser.rb @@ -102,7 +102,7 @@ def center_toolbar_filename_explorer center_toolbar_filename_chargeback_report elsif @layout == "miq_ae_tools" super_admin_user? ? "miq_ae_tools_simulate_center_tb" : nil - elsif %w[condition miq_policy miq_policy_set].include?(@layout) + elsif %w[condition miq_alert_set miq_policy miq_policy_set].include?(@layout) center_toolbar_filename_miq_policy elsif @layout == "ops" center_toolbar_filename_ops @@ -222,7 +222,7 @@ def center_toolbar_filename_miq_policy elsif @conditions return "conditions_center_tb" elsif @alert_profiles - return "miq_alert_profiles_center_tb" + return "miq_alert_sets_center_tb" end end case @nodetype @@ -238,7 +238,7 @@ def center_toolbar_filename_miq_policy when "ev" then "miq_event_center_tb" when "a" then "miq_action_center_tb" when "al" then "miq_alert_center_tb" - when "ap" then "miq_alert_profile_center_tb" + when "ap" then "miq_alert_set_center_tb" end end diff --git a/app/presenters/menu/default_menu.rb b/app/presenters/menu/default_menu.rb index d5232ae806bb..5f852d9ad7a4 100644 --- a/app/presenters/menu/default_menu.rb +++ b/app/presenters/menu/default_menu.rb @@ -227,6 +227,7 @@ def control_menu_section Menu::Item.new('miq_event', N_('Events'), 'miq_event', {:feature => 'miq_event', :any => true}, '/miq_event/explorer'), Menu::Item.new('condition', N_('Conditions'), 'condition', {:feature => 'condition', :any => true}, '/condition/explorer'), Menu::Item.new('miq_action', N_('Actions'), 'miq_action', {:feature => 'miq_action', :any => true}, '/miq_action/explorer'), + Menu::Item.new('miq_alert_set', N_('Alert Profiles'), 'miq_alert_set', {:feature => 'miq_alert_set', :any => true}, '/miq_alert_set/explorer'), Menu::Item.new('miq_policy_rsop', N_('Simulation'), 'policy_simulation', {:feature => 'policy_simulation'}, '/miq_policy/rsop'), Menu::Item.new('miq_policy_export', N_('Import / Export'), 'policy_import_export', {:feature => 'policy_import_export'}, '/miq_policy/export'), Menu::Item.new('miq_policy_logs', N_('Log'), 'policy_log', {:feature => 'policy_log'}, '/miq_policy/log') diff --git a/app/presenters/tree_builder_alert_profile_assign.rb b/app/presenters/tree_builder_alert_profile_assign.rb index db7beab87af5..92c4634e4753 100644 --- a/app/presenters/tree_builder_alert_profile_assign.rb +++ b/app/presenters/tree_builder_alert_profile_assign.rb @@ -23,7 +23,7 @@ def tree_init_options :full_ids => true, :checkboxes => true, :oncheck => "miqOnCheckGeneric", - :check_url => "/miq_policy/alert_profile_assign_changed/" + :check_url => "/miq_alert_set/alert_profile_assign_changed/" } end end diff --git a/app/presenters/tree_builder_alert_profile_obj.rb b/app/presenters/tree_builder_alert_profile_obj.rb index 1d8db1d2e156..e88518e744c5 100644 --- a/app/presenters/tree_builder_alert_profile_obj.rb +++ b/app/presenters/tree_builder_alert_profile_obj.rb @@ -17,7 +17,7 @@ def tree_init_options { :checkboxes => true, :oncheck => "miqOnCheckGeneric", - :check_url => "/miq_policy/alert_profile_assign_changed/" + :check_url => "/miq_alert_set/alert_profile_assign_changed/" } end diff --git a/app/views/miq_policy/_alert_profile_assign.html.haml b/app/views/miq_alert_set/_alert_profile_assign.html.haml similarity index 100% rename from app/views/miq_policy/_alert_profile_assign.html.haml rename to app/views/miq_alert_set/_alert_profile_assign.html.haml diff --git a/app/views/miq_policy/_alert_profile_details.html.haml b/app/views/miq_alert_set/_alert_profile_details.html.haml similarity index 99% rename from app/views/miq_policy/_alert_profile_details.html.haml rename to app/views/miq_alert_set/_alert_profile_details.html.haml index 77435f741637..3a72964301b8 100644 --- a/app/views/miq_policy/_alert_profile_details.html.haml +++ b/app/views/miq_alert_set/_alert_profile_details.html.haml @@ -65,7 +65,7 @@ "data-method" => :post, "data-miq_sparkle_on" => true, "data-miq_sparkle_off" => true, - "data-click_url" => {:url => url_for_only_path(:action => 'alert_profile_edit', + "data-click_url" => {:url => url_for_only_path(:action => 'miq_alert_set_edit', :button => action, :id => @alert_profile)}.to_json} %i.fa.fa-lg.hidden-xs.hidden-sm{:class => arrow_style} diff --git a/app/views/miq_policy/_alert_profile_folders.html.haml b/app/views/miq_alert_set/_alert_profile_folders.html.haml similarity index 100% rename from app/views/miq_policy/_alert_profile_folders.html.haml rename to app/views/miq_alert_set/_alert_profile_folders.html.haml diff --git a/app/views/miq_policy/_alert_profile_list.html.haml b/app/views/miq_alert_set/_alert_profile_list.html.haml similarity index 100% rename from app/views/miq_policy/_alert_profile_list.html.haml rename to app/views/miq_alert_set/_alert_profile_list.html.haml diff --git a/app/views/miq_alert_set/explorer.html.haml b/app/views/miq_alert_set/explorer.html.haml new file mode 100644 index 000000000000..bc489d879af4 --- /dev/null +++ b/app/views/miq_alert_set/explorer.html.haml @@ -0,0 +1,11 @@ +- content_for :search do + = render(:partial => "layouts/x_adv_searchbox", :locals => {:nameonly => true}) + +#main_div + - case @nodetype + - when "root" + = render :partial => "alert_profile_folders" + - when "xx" + = render :partial => "alert_profile_list" + - when "ap" + = render :partial => "alert_profile_details" diff --git a/config/routes.rb b/config/routes.rb index c75b161cd41e..3272cb0376c8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2160,6 +2160,23 @@ x_post }, + :miq_alert_set => { + :get => %w( + explorer + ), + :post => %w( + alert_profile_assign_changed + alert_profile_field_changed + button + miq_alert_set_assign + miq_alert_set_edit + reload + tree_autoload + tree_select + ) + + x_post + }, + :miq_event => { :get => %w( explorer