From 930a5e809902bed2f9c34644fa868040b794dc71 Mon Sep 17 00:00:00 2001 From: Harpreet Kataria Date: Thu, 10 Dec 2020 18:09:20 -0500 Subject: [PATCH] Event Explorer De-Explorization Changes to support Events related screens as other normal screens in the product to help support direct linking. --- app/controllers/miq_event_controller.rb | 188 +-------------------- app/presenters/menu/default_menu.rb | 2 +- app/presenters/tree_builder.rb | 2 - app/presenters/tree_builder_event.rb | 20 --- app/views/miq_event/show.html.haml | 213 ++++++++++++++++++++++++ app/views/miq_event/show_list.html.haml | 2 + config/routes.rb | 9 +- 7 files changed, 222 insertions(+), 214 deletions(-) delete mode 100644 app/presenters/tree_builder_event.rb create mode 100644 app/views/miq_event/show.html.haml create mode 100644 app/views/miq_event/show_list.html.haml diff --git a/app/controllers/miq_event_controller.rb b/app/controllers/miq_event_controller.rb index 13c014445cbb..64c95a31f7c5 100644 --- a/app/controllers/miq_event_controller.rb +++ b/app/controllers/miq_event_controller.rb @@ -4,7 +4,9 @@ class MiqEventController < ApplicationController after_action :cleanup_action after_action :set_session_data + include Mixins::GenericListMixin include Mixins::GenericSessionMixin + include Mixins::GenericShowMixin include Mixins::BreadcrumbsMixin include Mixins::PolicyMixin @@ -12,194 +14,8 @@ def title @title = _("Events") end - def index - flash_to_session - redirect_to(:action => 'explorer') - end - - def explorer - @breadcrumbs = [] - @explorer = true - - self.x_active_tree ||= 'event_tree' - self.x_active_accord ||= 'event' - - 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 => x_node) - end - private - # 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 - x_node == "root" ? event_get_all : event_get_info(MiqEventDefinition.find(nodeid)) - @show_adv_search = @nodetype == "root" - {:view => @view, :pages => @pages} - 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 - - 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] - ) - - presenter[:osf_node] = x_node - - # Replace right side with based on selected tree node type - case nodetype - when 'root' - partial_name, model = ['event_list', _('Events')] - 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 condition_tree policy_tree].exclude?(x_active_tree.to_s) - when 'ev' - presenter.update(:main_div, r[:partial => 'event_details', :locals => {:read_only => true}]) - options = {:name => @event.description} - right_cell_text = @edit ? _("Editing Event \"%{name}\"") % options : _("Event \"%{name}\"") % options - 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 send_button_changes - if @edit - @changed = (@edit[:new] != @edit[:current]) - elsif @assign - @changed = (@assign[:new] != @assign[:current]) - end - render :update do |page| - page << javascript_prologue - if @edit - if @refresh_inventory - page.replace("action_options_div", :partial => "action_options") - end - if @action_type_changed || @snmp_trap_refresh - page.replace("action_options_div", :partial => "action_options") - elsif @alert_refresh - page.replace("alert_details_div", :partial => "alert_details") - elsif @to_email_refresh - page.replace("edit_to_email_div", - :partial => "layouts/edit_to_email", - :locals => {:action_url => "alert_field_changed", :record => @alert}) - elsif @alert_snmp_refresh - page.replace("alert_snmp_div", :partial => "alert_snmp") - elsif @alert_mgmt_event_refresh - page.replace("alert_mgmt_event_div", :partial => "alert_mgmt_event") - end - elsif @assign - if params.key?(:chosen_assign_to) || params.key?(:chosen_cat) - page.replace("alert_profile_assign_div", :partial => "alert_profile_assign") - end - end - page << javascript_for_miq_button_visibility_changed(@changed) - page << "miqSparkle(false);" - end - end - - def event_get_all - @events = MiqPolicy.all_policy_events.sort_by { |e| e.description.downcase } - set_search_text - @events = apply_search_filter(@search_text, @events) if @search_text.present? - @right_cell_text = _("All Events") - @right_cell_div = "event_list" - end - - # Get information for an event - def event_get_info(event) - @record = @event = event - @policy = MiqPolicy.find(@sb[:node_ids][x_active_tree]["p"]) unless x_active_tree == :event_tree - @right_cell_text = _("Event \"%{name}\"") % {:name => event.description} - @right_cell_div = "event_details" - - if x_active_tree == :event_tree - @event_policies = @event.miq_policies.sort_by { |p| p.description.downcase } - else - @event_true_actions = MiqPolicy.find(@sb[:node_ids][x_active_tree]["p"]).actions_for_event(event, :success) - @event_false_actions = MiqPolicy.find(@sb[:node_ids][x_active_tree]["p"]).actions_for_event(event, :failure) - end - end - def get_session_data @title = _("Events") @layout = "miq_event" diff --git a/app/presenters/menu/default_menu.rb b/app/presenters/menu/default_menu.rb index 95c713e15f21..8c6be1e08c37 100644 --- a/app/presenters/menu/default_menu.rb +++ b/app/presenters/menu/default_menu.rb @@ -228,7 +228,7 @@ def control_menu_section Menu::Section.new(:con, N_("Control"), 'carbon--IbmSecurity', [ Menu::Item.new('miq_policy_set', N_('Policy Profiles'), 'miq_policy_set', {:feature => 'miq_policy_set_show_list'}, '/miq_policy_set/show_list'), Menu::Item.new('miq_policy', N_('Policies'), 'miq_policy', {:feature => 'miq_policy', :any => true}, '/miq_policy/explorer'), - Menu::Item.new('miq_event', N_('Events'), 'miq_event', {:feature => 'miq_event', :any => true}, '/miq_event/explorer'), + Menu::Item.new('miq_event', N_('Events'), 'miq_event', {:feature => 'miq_event_show_list'}, '/miq_event/show_list'), 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'), diff --git a/app/presenters/tree_builder.rb b/app/presenters/tree_builder.rb index c1887cc29669..f9e72ba58117 100644 --- a/app/presenters/tree_builder.rb +++ b/app/presenters/tree_builder.rb @@ -387,8 +387,6 @@ def prefixed_title(prefix, title) ## Explorer ### Policies :policy => "TreeBuilderPolicy", - ### Events - :event => "TreeBuilderEvent", ### Conditions :condition => "TreeBuilderCondition", ### Actions diff --git a/app/presenters/tree_builder_event.rb b/app/presenters/tree_builder_event.rb deleted file mode 100644 index 7ba75a73738c..000000000000 --- a/app/presenters/tree_builder_event.rb +++ /dev/null @@ -1,20 +0,0 @@ -class TreeBuilderEvent < TreeBuilder - private - - def tree_init_options - {:full_ids => true} - end - - # level 0 - root - def root_options - { - :text => t = _("All Events"), - :tooltip => t - } - end - - # level 1 - events - def x_get_tree_roots - count_only_or_objects(false, MiqPolicy.all_policy_events, :description) - end -end diff --git a/app/views/miq_event/show.html.haml b/app/views/miq_event/show.html.haml new file mode 100644 index 000000000000..adaf0ac53736 --- /dev/null +++ b/app/views/miq_event/show.html.haml @@ -0,0 +1,213 @@ +#main_div + -#= render :partial => "layouts/textual_groups_generic" + - if @event + #event_info_div + = render :partial => "layouts/flash_msg" + %h3= _("Basic Information") + .form-horizontal + .form-group + %label.control-label.col-md-2= _("Event Group") + .col-md-10 + %p.form-control-static= h(@event.memberof.first.description) + - if @policy + .form-group + %label.control-label.col-md-2= _("Attached to Policy") + .col-md-10 + %p.form-control-static= h(@policy.description) + %hr + + - if @event_policies + %h3= _("Assigned to Policies") + - if @event_policies.empty? + = render :partial => 'layouts/info_msg', :locals => {:message => _("This Event is not assigned to any Policies.")} + - else + %table.table.table-striped.table-bordered.table-hover + %tbody + - @event_policies.each do |p| + - id = "xx-#{p.mode.downcase}_xx-#{p.mode.downcase}-#{p.towhat.camelize(:lower)}_p-#{p.id}" + %tr + %td.table-view-pf-select + %i{:class => p.decorate.fonticon} + %td + = p.description + - else + %h3= _("Order of Actions if ALL Conditions are True") + - if @edit + .col-md-5 + = _('Available Actions:') + %span#choices_chosen_true_div + = select_tag('choices_chosen_true[]', + options_for_select(@edit[:choices_true].sort), + :multiple => true, + :class => "form-control", + :style => "overflow-x: scroll;", + :size => 8, + :id => "choices_chosen_true") + + .col-md-1{:style => "padding: 10px"} + .spacer + .spacer + - [[_("Move selected Actions into this Event"), 'choices_chosen_true_div', 'true_right', 'fa-angle-right'], + [_("Remove all Actions from this Event"), nil, 'true_allleft', 'fa-angle-double-left'], + [_("Remove selected Actions from this Event"), 'members_chosen_true_div', 'true_left', 'fa-angle-left']].each do |title, chosen_div, action, arrow_style| + %button.btn.btn-default.btn-block{:title => title, + :remote => true, + "data-submit" => chosen_div, + "data-method" => :post, + "data-miq_sparkle_on" => true, + "data-miq_sparkle_off" => true, + "data-click_url" => {:url => url_for_only_path(:action => 'miq_event_edit', + :button => action, + :id => @event)}.to_json} + %i.fa.fa-lg.hidden-xs.hidden-sm{:class => arrow_style} + %i.fa.fa-lg.fa-rotate-90.hidden-md.hidden-lg{:class => arrow_style} + + .spacer + .col-md-5.col-sm-11.col-xs-11 + = _(' Selected Actions:') + %span#members_chosen_true_div + = select_tag('members_chosen_true[]', + options_for_select(@edit[:new][:actions_true], @true_selected), + :multiple => true, + :class => "form-control", + :style => "overflow-x: scroll;", + :size => 8, + :id => "members_chosen_true") + + .col-md-1.col-sm-1.col-xs-1{:style => "padding: 10px"} + .spacer + .spacer + - [[_("Move selected Action up"), 'members_chosen_true_div', 'true_up', 'fa-angle-up'], + [_("Move selected Action down"), 'members_chosen_true_div', 'true_down', 'fa-angle-down'], + [_("Set selected Actions to Synchronous"), 'members_chosen_true_div', 'true_sync', 'S'], + [_("Set selected Actions to Asynchronous"), 'members_chosen_true_div', 'true_async', 'A']].each do |title, chosen_div, action, arrow_style| + %button.btn.btn-default.btn-block{:title => title, + :remote => true, + "data-submit" => chosen_div, + "data-method" => :post, + "data-miq_sparkle_on" => true, + "data-miq_sparkle_off" => true, + "data-click_url" => {:url => url_for_only_path(:action => 'miq_event_edit', + :button => action, + :id => @event)}.to_json} + - if %w(A S).include?(arrow_style) + =_(arrow_style) + - else + %i.fa.fa-lg{:class => arrow_style} + + .spacer + %hr + - else + - if @event_true_actions.empty? + = render :partial => 'layouts/info_msg', :locals => {:message => _("This Event has no true Actions.")} + - else + %table.table.table-striped.table-bordered.table-hover + %thead + %tr + %th.table-view-pf-select + %th= _("Description") + %th= _("Synchronous") + %th= _("Type") + %tbody + - @event_true_actions.each do |a| + %tr + %td.table-view-pf-select + %i.pficon.pficon-ok + %td + = a.description + %td + = a.v_synchronicity + %td + = a.action_type + + %br{:style => "clear: both"} + %h3= _("Order of Actions if ANY Conditions are False") + - if @edit + + .col-md-5 + = _("Available Actions:") + %span#choices_chosen_false_div + = select_tag('choices_chosen_false[]', + options_for_select(@edit[:choices_false].sort), + :multiple => true, + :class => "form-control", + :style => "overflow-x: scroll;", + :size => 8, + :id => "choices_chosen_false") + + .col-md-1{:style => "padding: 10px"} + .spacer + .spacer + - [[_("Move selected Actions into this Event"), 'choices_chosen_false_div', 'false_right', 'fa-angle-right'], + [_("Remove all Actions from this Event"), nil, 'false_allleft', 'fa-angle-double-left'], + [_("Remove selected Actions from this Event"), 'members_chosen_false_div', 'false_left', 'fa-angle-left']].each do |title, chosen_div, action, arrow_style| + %button.btn.btn-default.btn-block{:title => title, + :remote => true, + "data-submit" => chosen_div, + "data-method" => :post, + "data-miq_sparkle_on" => true, + "data-miq_sparkle_off" => true, + "data-click_url" => {:url => url_for_only_path(:action => 'miq_event_edit', + :button => action, + :id => @event)}.to_json} + %i.fa.fa-lg.hidden-xs.hidden-sm{:class => arrow_style} + %i.fa.fa-lg.fa-rotate-90.hidden-md.hidden-lg{:class => arrow_style} + + .spacer + + .col-md-5.col-sm-11.col-xs-11 + = _(" Selected Actions:") + %span#members_chosen_false_div + = select_tag('members_chosen_false[]', + options_for_select(@edit[:new][:actions_false], @false_selected), + :multiple => true, + :class => "form-control", + :style => "overflow-x: scroll;", + :size => 8, + :id => "members_chosen_false") + + .col-md-1.col-sm-1.col-xs-1{:style => "padding: 10px"} + .spacer + .spacer + - [[_("Move selected Action up"), 'members_chosen_false_div', 'false_up', 'fa-angle-up'], + [_("Move selected Action down"), 'members_chosen_false_div', 'false_down', 'fa-angle-down'], + [_("Set selected Actions to Synchronous"), 'members_chosen_false_div', 'false_sync', 'S'], + [_("Set selected Actions to Asynchronous"), 'members_chosen_false_div', 'false_async', 'A']].each do |title, chosen_div, action, arrow_style| + %button.btn.btn-default.btn-block{:title => title, + :remote => true, + "data-submit" => chosen_div, + "data-method" => :post, + "data-miq_sparkle_on" => true, + "data-miq_sparkle_off" => true, + "data-click_url" => {:url => url_for_only_path(:action => 'miq_event_edit', + :button => action, + :id => @event)}.to_json} + - if %w(A S).include?(arrow_style) + =_(arrow_style) + - else + %i.fa.fa-lg{:class => arrow_style} + .spacer + + - else + - if @event_false_actions.empty? + = render :partial => 'layouts/info_msg', :locals => {:message => _("This Event has no false Actions.")} + - else + %table.table.table-striped.table-bordered.table-hover + %thead + %tr + %th.table-view-pf-select + %th= _('Description') + %th= _('Synchronous') + %th= _('Type') + %tbody + - @event_false_actions.each do |a| + %tr + %td.table-view-pf-select + %i.pficon.pficon-error-circle-o + %td + = a.description + %td + = a.v_synchronicity + %td + = a.action_type + diff --git a/app/views/miq_event/show_list.html.haml b/app/views/miq_event/show_list.html.haml new file mode 100644 index 000000000000..039604839f28 --- /dev/null +++ b/app/views/miq_event/show_list.html.haml @@ -0,0 +1,2 @@ +#main_div + = render :partial => 'layouts/gtl' diff --git a/config/routes.rb b/config/routes.rb index 6960c2b27054..57e3a5cb4064 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2191,13 +2191,12 @@ :miq_event => { :get => %w( - explorer + show + show_list ), :post => %w( - tree_autoload - tree_select - ) + - x_post + + ) }, :condition => {