diff --git a/app/controllers/condition_controller.rb b/app/controllers/condition_controller.rb index e5d9f417156..9a96608669e 100644 --- a/app/controllers/condition_controller.rb +++ b/app/controllers/condition_controller.rb @@ -4,345 +4,144 @@ class ConditionController < ApplicationController after_action :cleanup_action after_action :set_session_data + include Mixins::GenericFormMixin + include Mixins::GenericListMixin include Mixins::GenericSessionMixin + include Mixins::GenericShowMixin include Mixins::BreadcrumbsMixin include Mixins::PolicyMixin - UI_FOLDERS = [Host, Vm, ContainerReplicator, ContainerGroup, ContainerNode, ContainerImage, ContainerProject, ExtManagementSystem, PhysicalServer].freeze - def title @title = _("Conditions") 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 - - CONDITION_X_BUTTON_ALLOWED_ACTIONS = { - 'condition_edit' => :condition_edit, - 'condition_copy' => :condition_edit, - 'condition_policy_copy' => :condition_edit, - 'condition_new' => :condition_edit, - 'condition_remove' => :condition_remove - }.freeze - - def x_button - generic_x_button(CONDITION_X_BUTTON_ALLOWED_ACTIONS) - end - - def explorer - @breadcrumbs = [] - @explorer = true - session[:export_data] = nil - - self.x_active_tree ||= 'condition_tree' - self.x_active_accord ||= 'condition' - - 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 + # Item clicked + def show + assert_privileges("condition_show") + super + @condition = @record + @expression_table = @condition.expression.kind_of?(MiqExpression) ? exp_build_table(@condition.expression.exp) : nil + @applies_to_exp_table = @condition.applies_to_exp.kind_of?(MiqExpression) ? exp_build_table(@condition.applies_to_exp.exp) : nil + @condition_policies = @condition.miq_policies.sort_by { |p| p.description.downcase } + add_flash(_("Ruby scripts are no longer supported in expressions, please change or remove them."), :warning) if @condition.expression.exp.key?('RUBY') 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) + def new + condition_edit 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) + def edit + condition_edit end - def search - get_node_info(x_node) - replace_right_cell(:nodetype => "xx") + def copy + condition_edit end def condition_edit case params[:button] when "cancel" id = params[:id] || "new" - return unless load_edit("condition_edit__#{id}", "replace_cell__explorer") + return unless load_edit("condition_edit__#{id}") @condition = @edit[:condition_id] ? Condition.find(@edit[:condition_id]) : Condition.new if @condition.try(:id) - add_flash(_("Edit of %{model} Condition \"%{name}\" was cancelled by the user") % {:model => ui_lookup(:model => @edit[:new][:towhat]), :name => @condition.description}) + flash_msg = _("Edit of %{model} Condition \"%{name}\" was cancelled by the user") % {:model => ui_lookup(:model => @edit[:new][:towhat]), :name => @condition.description} else - add_flash(_("Add of new %{model} Condition was cancelled by the user") % {:model => ui_lookup(:model => @edit[:new][:towhat])}) + flash_msg = _("Add of new %{model} Condition was cancelled by the user") % {:model => ui_lookup(:model => @edit[:new][:towhat])} end - @sb[:action] = @edit = nil - get_node_info(x_node) - replace_right_cell(:nodetype => @nodetype, :remove_form_buttons => true) + @edit = session[:edit] = nil # clean out the saved info + session[:changed] = false + javascript_redirect(:action => @condition.id ? @lastaction : "show_list", :id => params[:id], :flash_msg => flash_msg) return when "reset", nil # Reset or first time in + @_params[:id] ||= find_checked_items[0] condition_build_edit_screen - @sb[:action] = "condition_edit" - add_flash(_("Ruby scripts are no longer supported in expressions, please change or remove them."), :warning) if @edit[:current][:expression].key?('RUBY') - if params[:button] == "reset" - add_flash(_("All changes have been reset"), :warning) + if flash_errors? + flash_to_session + redirect_to(:action => 'show_list') + else + add_flash(_("Ruby scripts are no longer supported in expressions, please change or remove them."), :warning) if @edit[:current][:expression] && @edit[:current][:expression].key?('RUBY') + session[:flash_msgs] = @flash_array + javascript_redirect(:action => 'edit', + :id => params[:id], + :flash_msg => _("All changes have been reset"), + :flash_warning => true) if params[:button] == "reset" end - replace_right_cell(:nodetype => "co") - return - end - - # Load @edit/vars for other buttons - id = params[:id] || "new" - return unless load_edit("condition_edit__#{params[:button] == "add" ? "new" : id}", "replace_cell__explorer") + else + # Load @edit/vars for other buttons + id = params[:id] || "new" + return unless load_edit("condition_edit__#{params[:button] == "add" ? "new" : id}") - @condition = @edit[:condition_id] ? Condition.find(@edit[:condition_id]) : Condition.new + @condition = @edit[:condition_id] ? Condition.find(@edit[:condition_id]) : Condition.new - case params[:button] - when "save", "add" - assert_privileges("condition_#{@condition.id ? "edit" : "new"}") - policy = MiqPolicy.find(@sb[:node_ids][x_active_tree]["p"]) unless x_active_tree == :condition_tree - adding = @condition.id.blank? - condition = @condition # Get new or existing record - condition.description = @edit[:new][:description] - condition.notes = @edit[:new][:notes] - condition.towhat = @edit[:new][:towhat] if adding # Set the proper model if adding a record - exp_remove_tokens(@edit[:new][:expression]) - condition.expression = MiqExpression.new(@edit[:new][:expression]) - exp_remove_tokens(@edit[:new][:applies_to_exp]) - condition.applies_to_exp = @edit[:new][:applies_to_exp]["???"] ? nil : MiqExpression.new(@edit[:new][:applies_to_exp]) - if condition.expression.kind_of?(MiqExpression) && condition.expression.exp["???"] - add_flash(_("A valid expression must be present"), :error) - end - if condition.valid? && !@flash_array && condition.save - if adding && x_active_tree != :condition_tree # If adding to a policy - policy.conditions.push(condition) # add condition to the policy - policy.save + case params[:button] + when "save", "add" + assert_privileges("condition_#{@condition.id ? "edit" : "new"}") + if @edit[:new][:towhat].blank? + add_flash(_("Applies to is required"), :error) end - AuditEvent.success(build_saved_audit(condition, @edit)) - if params[:button] == "save" - add_flash(_("Condition \"%{name}\" was saved") % {:name => @edit[:new][:description]}) - else - add_flash(_("Condition \"%{name}\" was added") % {:name => @edit[:new][:description]}) + adding = @condition.id.blank? + condition = @condition # Get new or existing record + condition.description = @edit[:new][:description] + condition.notes = @edit[:new][:notes] + condition.towhat = @edit[:new][:towhat] if adding # Set the proper model if adding a record + exp_remove_tokens(@edit[:new][:expression]) + condition.expression = MiqExpression.new(@edit[:new][:expression]) + exp_remove_tokens(@edit[:new][:applies_to_exp]) + condition.applies_to_exp = @edit[:new][:applies_to_exp]["???"] ? nil : MiqExpression.new(@edit[:new][:applies_to_exp]) + if condition.expression.kind_of?(MiqExpression) && condition.expression.exp["???"] + add_flash(_("A valid expression must be present"), :error) end - @sb[:action] = @edit = nil - @nodetype = "co" - condition_get_info(condition) - if adding - case x_active_tree - when :condition_tree - @new_condition_node = "xx-#{condition.towhat.camelize(:lower)}_co-#{condition.id}" - replace_right_cell(:nodetype => "co", :replace_trees => %i[condition], :remove_form_buttons => true) - when :policy_tree - node_ids = @sb[:node_ids][x_active_tree] # Get the selected node ids - @new_policy_node = "xx-#{policy.mode.downcase}_xx-#{policy.mode.downcase}-#{policy.towhat.downcase}_p-#{node_ids["p"]}_co-#{condition.id}" - replace_right_cell(:nodetype => "co", :replace_trees => %i[condition], :remove_form_buttons => true) - when :policy_profile_tree - node_ids = @sb[:node_ids][x_active_tree] # Get the selected node ids - @new_profile_node = "pp-#{node_ids["pp"]}_p-#{node_ids["p"]}_co-#{condition.id}" - replace_right_cell(:nodetype => "co", :replace_trees => %i[condition], :remove_form_buttons => true) + if condition.valid? && !@flash_array && condition.save + AuditEvent.success(build_saved_audit(condition, @edit)) + if params[:button] == "save" + flash_msg = _("Condition \"%{name}\" was saved") % {:name => @edit[:new][:description]} + else + flash_msg = _("Condition \"%{name}\" was added") % {:name => @edit[:new][:description]} end + @edit = session[:edit] = nil # clean out the saved info + session[:changed] = @changed = false + javascript_redirect(:action => params[:button] == "add" ? "show_list" : @lastaction, :id => params[:id], :flash_msg => flash_msg) else - replace_right_cell(:nodetype => "co", :replace_trees => %i[condition], :remove_form_buttons => true) + condition.errors.each do |field, msg| + add_flash("#{field.to_s.capitalize} #{msg}", :error) + end + javascript_flash end - else - condition.errors.each do |field, msg| - add_flash("#{field.to_s.capitalize} #{msg}", :error) + when "expression", "applies_to_exp" + session[:changed] = (@edit[:new] != @edit[:current]) + @expkey = params[:button].to_sym + @edit[:expression_table] = exp_build_table_or_nil(@edit[:new][:expression]) + @edit[:scope_table] = exp_build_table_or_nil(@edit[:new][:applies_to_exp]) + @changed = (@edit[:new] != @edit[:current]) + render :update do |page| + page << javascript_prologue + page.replace("flash_msg_div", :partial => "layouts/flash_msg") + page.replace_html("form_div", :partial => "form") unless @flash_errors + page << javascript_for_miq_button_visibility(@changed) + page << "miqSparkle(false);" end - javascript_flash end - when "expression", "applies_to_exp" - session[:changed] = (@edit[:new] != @edit[:current]) - @expkey = params[:button].to_sym - @edit[:expression_table] = exp_build_table_or_nil(@edit[:new][:expression]) - @edit[:scope_table] = exp_build_table_or_nil(@edit[:new][:applies_to_exp]) - replace_right_cell(:nodetype => "co") end end def condition_field_changed - return unless load_edit("condition_edit__#{params[:id]}", "replace_cell__explorer") + return unless load_edit("condition_edit__#{params[:id]}") @condition = @edit[:condition_id] ? Condition.find(@edit[:condition_id]) : Condition.new @edit[:new][:description] = params[:description].presence if params[:description] @edit[:new][:notes] = params[:notes].presence if params[:notes] - + if params[:towhat] + @edit[:new][:towhat] = params[:towhat] + build_expression_vars + end send_button_changes 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 - condition_get_all_folders if x_node == "root" # Get node info of tree roots - folder_get_info(treenodeid) if treenodeid != "root" # Get folder info for all node types - condition_get_info(Condition.find(nodeid)) if @nodetype == "co" - @show_adv_search = (@nodetype == "xx" && !@folders) || (@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 - - trees = build_replaced_trees(replace_trees, %i[condition]) - - 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] - ) - - # Simply replace the tree partials to reload the trees - replace_trees.each do |name| - case name - when :condition - self.x_node = @new_condition_node if @new_condition_node - else - raise _("unknown tree in replace_trees: %{name}") % {name => name} - end - end - 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 = ['condition_folders', _('Conditions')] - 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 'xx' - presenter.update( - :main_div, - if @conditions - right_cell_text = _("All %{typ} Conditions") % {:typ => ui_lookup(:model => @sb[:folder].try(:camelize))} - r[:partial => 'condition_list'] - elsif @folders - mode = @sb[:folder] - right_cell_text = if mode == 'compliance' - _('Compliance Policies') - elsif mode == 'control' - _('Control Policies') - else - _("%{typ} Policies") % {:typ => mode.capitalize} - end - r[:partial => 'policy_folders'] - end - ) - right_cell_text += _(" (Names with \"%{search_text}\")") % {:search_text => @search_text} if @search_text.present? && !@folders - when 'co' - # Set the JS types and titles vars if value fields are showing (needed because 2 expression editors are present) - if @edit && @edit[@expkey] - %i[val1 val2].each do |val| - next unless @edit[@expkey][val] # unless an expression with value 1 is showing - - presenter[:exp] = {} - presenter[:exp]["#{val}_type".to_sym] = @edit[@expkey][val][:type].to_s if @edit[@expkey][val][:type] - presenter[:exp]["#{val}_title".to_sym] = @edit[@expkey][val][:title] if @edit[@expkey][val][:title] - end - end - presenter.update(:main_div, r[:partial => 'condition_details', :locals => {:read_only => true}]) - right_cell_text = if @condition.id.blank? - _("Adding a new Condition") - elsif @edit - _("Editing %{model} Condition \"%{name}\"") % - {:name => @condition.description, - :model => ui_lookup(:model => @edit[:new][:towhat])} - else - _("%{model} Condition \"%{name}\"") % - {:name => @condition.description, - :model => ui_lookup(:model => @condition.towhat)} - 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 - - # 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 - @conditions = Condition.where(:towhat => @sb[:folder].camelize).sort_by { |c| c.description.downcase } - set_search_text - @conditions = apply_search_filter(@search_text, @conditions) if @search_text.present? - @right_cell_text = _("All %{typ} Conditions") % {:typ => ui_lookup(:model => @sb[:folder].try(:camelize))} - @right_cell_div = "condition_list" - end - def build_expression(parent, model) @edit[:new][:expression] = parent.expression.kind_of?(MiqExpression) ? parent.expression.exp : nil # Populate exp editor fields for the expression column @@ -367,25 +166,37 @@ def condition_build_edit_screen @edit[:new] = {} @edit[:current] = {} - if params[:copy] # If copying, create a new condition based on the original + if params[:action] == "copy" # If copying, create a new condition based on the original cond = Condition.find(params[:id]) @condition = cond.dup.tap { |c| c.name = nil } + @edit[:new][:copy] = true else @condition = params[:id] && params[:typ] != "new" ? Condition.find(params[:id]) : Condition.new # Get existing or new record end + + if @condition.read_only + add_flash(_("Read only condition can not be edited"), :error) + return + end + @edit[:key] = "condition_edit__#{@condition.id || "new"}" @edit[:rec_id] = @condition.id || nil - @edit[:new][:towhat] = if params[:id] && params[:typ] != "new" # If editing existing condition, grab model - Condition.find(params[:id]).towhat - else - x_active_tree == :condition_tree ? @sb[:folder].camelize : MiqPolicy.find(@sb[:node_ids][x_active_tree]["p"]).towhat - end - + @edit[:new][:towhat] = @condition.towhat @edit[:condition_id] = @condition.id @edit[:new][:description] = @condition.description @edit[:new][:notes] = @condition.notes + build_expression_vars if @edit[:new][:towhat] + + @edit[:current] = copy_hash(@edit[:new]) + + @embedded = true + @in_a_form = true + @edit[:current][:add] = true if @edit[:condition_id].nil? # Force changed to be true if adding a record + session[:changed] = (@edit[:new] != @edit[:current]) + end + def build_expression_vars @edit[:new][:expression] = @condition.expression.kind_of?(MiqExpression) ? @condition.expression.exp : nil @edit[:new][:applies_to_exp] = @condition.applies_to_exp.kind_of?(MiqExpression) ? @condition.applies_to_exp.exp : nil @@ -421,34 +232,6 @@ def condition_build_edit_screen @edit[:applies_to_exp][:exp_table] = exp_build_table(@edit[:applies_to_exp][:expression]) @expkey = :expression # Reset to default to editing the expression column @edit[:applies_to_exp][:exp_model] = @edit[:new][:towhat] # Set model for the exp editor - - @edit[:current] = copy_hash(@edit[:new]) - - @embedded = true - @in_a_form = true - @edit[:current][:add] = true if @edit[:condition_id].nil? # Force changed to be true if adding a record - session[:changed] = (@edit[:new] != @edit[:current]) - end - - def condition_get_all_folders - @folders = ConditionController::UI_FOLDERS.collect(&:name) - @right_cell_text = _("All Conditions") - @right_cell_div = "condition_folders" - end - - # Get information for a condition - def condition_get_info(condition) - @record = @condition = condition - @right_cell_text = _("Condition \"%{name}\"") % {:name => condition.description} - @right_cell_div = "condition_details" - @expression_table = @condition.expression.kind_of?(MiqExpression) ? exp_build_table(@condition.expression.exp) : nil - @applies_to_exp_table = @condition.applies_to_exp.kind_of?(MiqExpression) ? exp_build_table(@condition.applies_to_exp.exp) : nil - if x_active_tree == :condition_tree - @condition_policies = @condition.miq_policies.sort_by { |p| p.description.downcase } - else - @condition_policy = MiqPolicy.find(@sb[:node_ids][x_active_tree]["p"]) - end - add_flash(_("Ruby scripts are no longer supported in expressions, please change or remove them."), :warning) if @condition.expression.exp.key?('RUBY') end def get_session_data @@ -465,26 +248,16 @@ def set_session_data session[:condition_current_page] = @current_page end - def features - [ - { - :name => :condition, - :title => _("Conditions"), - :role => "condition", - :role_any => true - }, - ].map { |hsh| ApplicationController::Feature.new_with_hash(hsh) } - end - def breadcrumbs_options { :breadcrumbs => [ {:title => _("Control")}, - {:title => _('Explorer')}, + {:title => _('Conditions'), :url => controller_url}, ].compact, :record_title => :description, } end + toolbar :condition,:conditions menu_section :con end diff --git a/app/controllers/mixins/policy_mixin.rb b/app/controllers/mixins/policy_mixin.rb index a77cd26cf53..749c510cdf6 100644 --- a/app/controllers/mixins/policy_mixin.rb +++ b/app/controllers/mixins/policy_mixin.rb @@ -27,6 +27,8 @@ def send_button_changes page.replace("alert_snmp_div", :partial => "alert_snmp") elsif @alert_mgmt_event_refresh page.replace("alert_mgmt_event_div", :partial => "alert_mgmt_event") + elsif params[:towhat] + page.replace("form_div", :partial => "form") end elsif @assign if params.key?(:chosen_assign_to) || params.key?(:chosen_cat) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7fdbbba12ae..d2daee4f065 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1077,7 +1077,6 @@ def pdf_page_size_style cloud_volume_backup cloud_volume_snapshot cloud_volume_type - condition configuration_job configuration_profile configuration_script_source diff --git a/app/helpers/application_helper/button/condition.rb b/app/helpers/application_helper/button/condition.rb index 349df15eb5c..ec98c42b54c 100644 --- a/app/helpers/application_helper/button/condition.rb +++ b/app/helpers/application_helper/button/condition.rb @@ -1,5 +1,5 @@ class ApplicationHelper::Button::Condition < ApplicationHelper::Button::ReadOnly def role_allows_feature? - @view_context.x_active_tree == :condition_tree && role_allows?(:feature => self[:child_id]) + role_allows?(:feature => self[:child_id]) end end diff --git a/app/helpers/application_helper/button/condition_policy.rb b/app/helpers/application_helper/button/condition_policy.rb index 97460168f0a..38ebb201a7d 100644 --- a/app/helpers/application_helper/button/condition_policy.rb +++ b/app/helpers/application_helper/button/condition_policy.rb @@ -2,6 +2,6 @@ class ApplicationHelper::Button::ConditionPolicy < ApplicationHelper::Button::Re needs :@sb def role_allows_feature? - @view_context.x_active_tree != :condition_tree && role_allows?(:feature => self[:child_id]) + role_allows?(:feature => self[:child_id]) end end diff --git a/app/helpers/application_helper/button/condition_policy_copy.rb b/app/helpers/application_helper/button/condition_policy_copy.rb index 38ee3f2554f..a96e78e2562 100644 --- a/app/helpers/application_helper/button/condition_policy_copy.rb +++ b/app/helpers/application_helper/button/condition_policy_copy.rb @@ -2,6 +2,6 @@ class ApplicationHelper::Button::ConditionPolicyCopy < ApplicationHelper::Button needs :@sb def role_allows_feature? - @view_context.x_active_tree != :condition_tree && role_allows?(:feature => self[:child_id]) + role_allows?(:feature => self[:child_id]) end end diff --git a/app/helpers/application_helper/page_layouts.rb b/app/helpers/application_helper/page_layouts.rb index f957d61e42e..d6dafffd589 100644 --- a/app/helpers/application_helper/page_layouts.rb +++ b/app/helpers/application_helper/page_layouts.rb @@ -13,6 +13,7 @@ def layout_uses_listnav? chargeback_assignment chargeback_rate chargeback_report + condition configuration container_dashboard container_topology diff --git a/app/helpers/application_helper/toolbar/condition_center.rb b/app/helpers/application_helper/toolbar/condition_center.rb index d11770176d2..0db7965e7d2 100644 --- a/app/helpers/application_helper/toolbar/condition_center.rb +++ b/app/helpers/application_helper/toolbar/condition_center.rb @@ -11,25 +11,15 @@ class ApplicationHelper::Toolbar::ConditionCenter < ApplicationHelper::Toolbar:: 'pficon pficon-edit fa-lg', t = N_('Edit this Condition'), t, - :url_parms => "?type=basic", - :klass => ApplicationHelper::Button::ReadOnly), + :url => "/edit", + :klass => ApplicationHelper::Button::ReadOnly), button( :condition_copy, 'fa fa-files-o fa-lg', t = N_('Copy this Condition to a new Condition'), t, - :url_parms => "?copy=true", - :klass => ApplicationHelper::Button::Condition), - button( - :condition_policy_copy, - 'fa fa-files-o fa-lg', - t = proc do - _('Copy this Condition to a new Condition assigned to Policy [%{condition_policy_description}]') % - {:condition_policy_description => @condition_policy.try(:description)} - end, - t, - :url_parms => "?copy=true", - :klass => ApplicationHelper::Button::ConditionPolicyCopy), + :url => "/copy", + :klass => ApplicationHelper::Button::Condition), button( :condition_delete, 'pficon pficon-delete fa-lg', @@ -40,25 +30,10 @@ class ApplicationHelper::Toolbar::ConditionCenter < ApplicationHelper::Toolbar:: :klass => ApplicationHelper::Button::ConditionDelete, :data => {'function' => 'sendDataWithRx', 'function-data' => {:api_url => 'conditions', + :redirect_url => '/condition/show_list', :component_name => 'RemoveGenericItemModal', :controller => 'provider_dialogs', - :display_field => 'description', - :ajax_reload => true}}), - button( - :condition_remove, - 'pficon pficon-delete fa-lg', - t = proc do - _('Remove this Condition from Policy [%{condition_policy_description}]') % - {:condition_policy_description => @condition_policy.try(:description)} - end, - t, - :url_parms => "?policy_id=\#{@condition_policy.try(:id)}", - :klass => ApplicationHelper::Button::ConditionPolicy, - :confirm => proc do - _("Are you sure you want to remove this Condition from Policy [%{condition_policy_description}]?") % - {:condition_policy_description => @condition_policy.try(:description)} - end - ), + :display_field => 'description'}}), ]), ]) end diff --git a/app/helpers/application_helper/toolbar/conditions_center.rb b/app/helpers/application_helper/toolbar/conditions_center.rb index 20512223d4d..a6305f07543 100644 --- a/app/helpers/application_helper/toolbar/conditions_center.rb +++ b/app/helpers/application_helper/toolbar/conditions_center.rb @@ -9,17 +9,35 @@ class ApplicationHelper::Toolbar::ConditionsCenter < ApplicationHelper::Toolbar: button( :condition_new, 'pficon pficon-add-circle-o fa-lg', - t = proc do - if @sb[:folder].upcase == "VM" - _('Add a New VM Condition') - else - _('Add a New %{condition_type} Condition') % { - :condition_type => ui_lookup(:model => @sb[:folder].camelize) - } - end - end, + t = _('Add a New Condition'), t, + :url => "/new", :klass => ApplicationHelper::Button::ButtonNewDiscover), + button( + :condition_edit, + 'pficon pficon-edit fa-lg', + t = N_('Edit the selected Condition'), + t, + :url => "/edit", + :url_parms => "main_div", + :send_checked => true, + :enabled => false, + :onwhen => "1"), + button( + :condition_delete, + 'pficon pficon-delete fa-lg', + N_('Delete selected Conditions'), + N_('Delete Conditions'), + :enabled => false, + :onwhen => "1+", + :data => {'function' => 'sendDataWithRx', + 'function-data' => {:api_url => 'conditions', + :redirect_url => '/condition/show_list', + :component_name => 'RemoveGenericItemModal', + :controller => 'provider_dialogs', + :display_field => 'description', + :modal_text => N_("Are you sure you want to delete selected Conditions?"), + :modal_title => N_("Delete Conditions")}}) ] ), ]) diff --git a/app/helpers/application_helper/toolbar_chooser.rb b/app/helpers/application_helper/toolbar_chooser.rb index 861e3392208..f4350bc047c 100644 --- a/app/helpers/application_helper/toolbar_chooser.rb +++ b/app/helpers/application_helper/toolbar_chooser.rb @@ -35,7 +35,7 @@ def view_toolbar_filename 'dashboard_summary_toggle_view_tb' elsif %w[container_project].include?(@layout) 'container_project_view_tb' - elsif !%w[all_tasks timeline diagnostics miq_policy my_tasks miq_server usage].include?(@layout) && + elsif !%w[all_tasks condition timeline diagnostics miq_policy my_tasks miq_server usage].include?(@layout) && !@layout.starts_with?("miq_request") && @display == "main" && @showtype == "main" && !@in_a_form 'summary_view_tb' @@ -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_action miq_alert miq_alert_set miq_event].include?(@layout) + elsif %w[miq_action miq_alert miq_alert_set miq_event].include?(@layout) center_toolbar_filename_miq_policy elsif @layout == "ops" center_toolbar_filename_ops @@ -218,7 +218,9 @@ def center_toolbar_filename_chargeback_report def center_toolbar_filename_miq_policy if @nodetype == "xx" - if @conditions + if @policies || (@view && @sb[:tree_typ] == "policies") + return "miq_policies_center_tb" + elsif @conditions return "conditions_center_tb" elsif @alert_profiles return "miq_alert_sets_center_tb" @@ -230,6 +232,7 @@ def center_toolbar_filename_miq_policy when :action_tree then "miq_actions_center_tb" when :alert_tree then "miq_alerts_center_tb" end + when "p" then "miq_policy_center_tb" when "co" then "condition_center_tb" when "ev" then "miq_event_center_tb" when "a" then "miq_action_center_tb" diff --git a/app/presenters/menu/default_menu.rb b/app/presenters/menu/default_menu.rb index f93ea8b307d..a4b3acee5e9 100644 --- a/app/presenters/menu/default_menu.rb +++ b/app/presenters/menu/default_menu.rb @@ -229,7 +229,7 @@ def control_menu_section 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_show_list'}, '/miq_policy/show_list'), 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('condition', N_('Conditions'), 'condition', {:feature => 'condition_show_list'}, '/condition/show_list'), 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_alert', N_('Alerts'), 'miq_alert', {:feature => 'miq_alert', :any => true}, '/miq_alert/explorer'), diff --git a/app/presenters/tree_builder.rb b/app/presenters/tree_builder.rb index c1887cc2966..da8e20c82af 100644 --- a/app/presenters/tree_builder.rb +++ b/app/presenters/tree_builder.rb @@ -389,8 +389,6 @@ def prefixed_title(prefix, title) :policy => "TreeBuilderPolicy", ### Events :event => "TreeBuilderEvent", - ### Conditions - :condition => "TreeBuilderCondition", ### Actions :action => "TreeBuilderAction", ### Alert Profiles diff --git a/app/presenters/tree_builder_condition.rb b/app/presenters/tree_builder_condition.rb index 82bf1e0d62c..e69de29bb2d 100644 --- a/app/presenters/tree_builder_condition.rb +++ b/app/presenters/tree_builder_condition.rb @@ -1,55 +0,0 @@ -class TreeBuilderCondition < TreeBuilder - private - - def tree_init_options - {:full_ids => true} - end - - # level 0 - root - def root_options - { - :text => t = _("All Conditions"), - :tooltip => t - } - end - - # not using decorators for now because there are some inconsistencies - def self.folder_icon(klassname) - klassname.safe_constantize.try(:decorate).try(:fonticon) - end - - # level 1 - host / vm - def x_get_tree_roots - text_i18n = {:Host => _("Host Conditions"), - :Vm => _("VM and Instance Conditions"), - :ContainerReplicator => _("Replicator Conditions"), - :ContainerGroup => _("Pod Conditions"), - :ContainerNode => _("Container Node Conditions"), - :ContainerImage => _("Container Image Conditions"), - :ContainerProject => _("Container Project Conditions"), - :ExtManagementSystem => _("Provider Conditions"), - :PhysicalServer => _("Physical Infrastructure Conditions")} - - objects = ConditionController::UI_FOLDERS.collect do |model| - text = text_i18n[model.name.to_sym] - icon = self.class.folder_icon(model.to_s) - - { - :id => model.name.camelize(:lower), - :icon => icon, - :text => text, - :tip => text - } - end - count_only_or_objects(false, objects) - end - - # level 2 - conditions - def x_get_tree_custom_kids(parent, count_only) - towhat = parent[:id].camelize - return super unless ConditionController::UI_FOLDERS.collect(&:name).include?(towhat) - - objects = Condition.where(:towhat => towhat) - count_only_or_objects(count_only, objects, :description) - end -end diff --git a/app/presenters/tree_node/condition.rb b/app/presenters/tree_node/condition.rb deleted file mode 100644 index 6e9e488f015..00000000000 --- a/app/presenters/tree_node/condition.rb +++ /dev/null @@ -1,5 +0,0 @@ -module TreeNode - class Condition < Node - set_attribute(:text, &:description) - end -end diff --git a/app/views/condition/_condition_details.html.haml b/app/views/condition/_condition_details.html.haml deleted file mode 100644 index 7ce9be37663..00000000000 --- a/app/views/condition/_condition_details.html.haml +++ /dev/null @@ -1,111 +0,0 @@ -- if @edit - - url = url_for_only_path(:action => 'condition_field_changed', :id => (@condition.id || 'new')) - - observe_with_interval = {:interval => '.5', :url => url}.to_json -#condition_details_div - - if @condition - #condition_info_div - = render :partial => "layouts/flash_msg" - .form-horizontal - - if @edit - -# Don't show basic info box with description only unless in edit mode - %h3= _("Basic Information") - .form-horizontal - .form-group - %label.control-label.col-md-2 - = _("Description") - .col-md-8 - - if @edit - = text_field_tag("description", @edit[:new][:description], - :maxlength => ViewHelper::MAX_DESC_LEN, - "data-miq_observe" => observe_with_interval, - :class => "form-control") - = javascript_tag(javascript_focus('description')) - - else - %p.form-control-static - = h(@condition.description) - %hr - - - if @edit - %h3= _("Scope") - .form-horizontal - .form-group - %label.control-label.col-md-2 - .col-md-8 - = render :partial => "form_scope" - - else - %h3= _("Scope") - .form-horizontal - .form-group - %label.control-label.col-md-2 - = _("Description") - .col-md-8 - - if !@applies_to_exp_table.nil? - - @applies_to_exp_table.each do |token| - - if ! ["AND", "OR", "(", ")"].include?([token].flatten.first) - = h([token].flatten.first) - - else - %font{:color => "black"} - %b - = h([token].flatten.first) - - else - = render :partial => 'layouts/info_msg', :locals => {:message => _("No scope defined, the scope of this condition includes all elements.")} - %hr - - %h3= _("Expression") - .form-horizontal - .form-group - %label.control-label.col-md-2 - .col-md-8 - - if @edit - = render :partial => "form_expression" - - else - - if !@expression_table.nil? - - @expression_table.each do |token| - - if ! ["AND", "OR", "(", ")"].include?([token].flatten.first) - = h([token].flatten.first) - - else - %font{:color => "black"} - %b - = h([token].flatten.first) - - else - = render :partial => 'layouts/info_msg', :locals => {:message => _("A condition must contain a valid expression.")} - %hr - - - -# Notes field - %h3= _("Notes") - .form-horizontal - - if @edit - .form-group - %label.control-label.col-md-2 - .col-md-8 - ( - %span#notes_count= @edit[:new][:notes] ? @edit[:new][:notes].length : 0 - \/ 512) - = text_area_tag("notes", @edit[:new][:notes], - :rows => 4, - :maxlength => "512", - :counter => "notes_count", - "data-miq_check_max_length" => true, - "data-miq_observe" => observe_with_interval) - - else - - if @condition.notes.blank? - = render :partial => 'layouts/info_msg', :locals => {:message => _("No notes have been entered.")} - - else - = text_area_tag("notes", @condition.notes, :readonly => true, :rows => 5) - %hr - - - if x_active_tree == :condition_tree && !@edit - %h3= _("Assigned to Policies") - - if @condition_policies.empty? - = render :partial => 'layouts/info_msg', :locals => {:message => _("This Condition is not assigned to any Policies.")} - - else - %table.table.table-striped.table-bordered.table-hover - %tbody - - @condition_policies.each do |p| - - id = "xx-#{p.mode.downcase}_xx-#{p.mode.downcase}-#{p.towhat.camelize(:lower)}_p-#{p.id}" - %tr{:title => _("Click to view Policy")} - %td.table-view-pf-select - %i{:class => p.decorate.fonticon} - %td - = p.description diff --git a/app/views/condition/_condition_folders.html.haml b/app/views/condition/_condition_folders.html.haml deleted file mode 100644 index 8737a0a8372..00000000000 --- a/app/views/condition/_condition_folders.html.haml +++ /dev/null @@ -1,12 +0,0 @@ -#condition_folders_div - - if @folders - = render :partial => "layouts/flash_msg" - %table.table.table-striped.table-bordered.table-hover - %tbody - - @folders.each do |f| - %tr{:title => _("View Condition"), - :onclick => "miqTreeActivateNode('condition_tree', 'xx-#{f.camelize(:lower)}');"} - %td.table-view-pf-select - %i{:class => TreeBuilderCondition.folder_icon(f)} - %td - = _("%{object} Conditions") % {:object => ui_lookup(:model => f)} diff --git a/app/views/condition/_condition_list.html.haml b/app/views/condition/_condition_list.html.haml deleted file mode 100644 index 6548399a4e2..00000000000 --- a/app/views/condition/_condition_list.html.haml +++ /dev/null @@ -1,21 +0,0 @@ -#condition_list_div - - if @conditions - %div{:style => "padding-top: 10px;"} - = render :partial => "layouts/flash_msg" - - if @conditions.empty? - - model = ui_lookup(:model => @sb[:folder].camelize) - - if @search_text.blank? - - msg = _("No %{model} Conditions are defined.") % {:model => model} - - else - - msg = _("No %{model} Conditions are defined that match the entered search string.") % {:model => model} - = render :partial => 'layouts/info_msg', :locals => {:message => msg} - - else - %table.table.table-striped.table-bordered.table-hover - %tbody - - @conditions.each do |c| - %tr{:title => _("View this Condition"), - :onclick => "miqTreeActivateNode('condition_tree', 'xx-#{c.towhat.camelize(:lower)}_co-#{c.id}');"} - %td.table-view-pf-select - %i.fa.fa-diamond - %td - = c.description diff --git a/app/views/condition/_form.html.haml b/app/views/condition/_form.html.haml new file mode 100644 index 00000000000..d2a1211a8a5 --- /dev/null +++ b/app/views/condition/_form.html.haml @@ -0,0 +1,86 @@ +- url = url_for_only_path(:action => 'condition_field_changed', :id => (@condition.id || 'new')) +- observe_with_interval = {:interval => '.5', :url => url}.to_json +#form_div + = render :partial => "layouts/flash_msg" + .form-horizontal + -# Don't show basic info box with description only unless in edit mode + %h3= _("Basic Information") + .form-horizontal + .form-group + %label.control-label.col-md-2 + = _("Description") + .col-md-8 + - if @edit + = text_field_tag("description", @edit[:new][:description], + :maxlength => ViewHelper::MAX_DESC_LEN, + "data-miq_observe" => observe_with_interval, + :class => "form-control") + = javascript_tag(javascript_focus('description')) + %hr + .form-horizontal + .form-group + %label.control-label.col-md-2 + = _("Applies To") + .col-md-8 + - if @edit[:new][:copy] + = Condition::TOWHAT_APPLIES_TO_CLASSES[@edit[:new][:towhat]] + - else + = select_tag('towhat', + options_for_select([[_(""), nil]] + Array(Condition::TOWHAT_APPLIES_TO_CLASSES.invert), @edit[:new][:towhat]), + :class => "selectpicker form-control") + :javascript + miqInitSelectPicker(); + miqSelectPickerEvent("towhat", "#{url}"); + + - if @edit[:new][:towhat] + %h3= _("Scope") + .form-horizontal + .form-group + %label.control-label.col-md-2 + .col-md-8 + = render :partial => "form_scope" + %hr + + %h3= _("Expression") + .form-horizontal + .form-group + %label.control-label.col-md-2 + .col-md-8 + = render :partial => "form_expression" + %hr + + -# Notes field + %h3= _("Notes") + .form-horizontal + .form-group + %label.control-label.col-md-2 + .col-md-8 + ( + %span#notes_count= @edit[:new][:notes] ? @edit[:new][:notes].length : 0 + \/ 512) + = text_area_tag("notes", @edit[:new][:notes], + :rows => 4, + :maxlength => "512", + :counter => "notes_count", + "data-miq_check_max_length" => true, + "data-miq_observe" => observe_with_interval) + %hr + - unless @edit[:rec_id] + %table{:width => "100%"} + %tr + %td{:align => 'right'} + = button_tag(t = _("Add"), + :class => 'btn btn-primary', + :alt => t, + :title => t, + :onclick => "miqAjaxButton('#{url_for_only_path(:action => 'edit', + :button => "add")}');") + = button_tag(t = _("Cancel"), + :class => 'btn btn-default', + :alt => t, + :title => t, + :onclick => "miqAjaxButton('#{url_for_only_path(:action => 'edit', + :button => "cancel")}');") + - else + = render :partial => '/layouts/edit_form_buttons', + :locals => {:action_url => "edit", :record_id => @edit[:rec_id], :ajax_buttons => true} diff --git a/app/views/condition/copy.html.haml b/app/views/condition/copy.html.haml new file mode 100644 index 00000000000..c66fabf2cd6 --- /dev/null +++ b/app/views/condition/copy.html.haml @@ -0,0 +1 @@ += render :partial => 'form' diff --git a/app/views/condition/edit.html.haml b/app/views/condition/edit.html.haml new file mode 100644 index 00000000000..c66fabf2cd6 --- /dev/null +++ b/app/views/condition/edit.html.haml @@ -0,0 +1 @@ += render :partial => 'form' diff --git a/app/views/condition/explorer.html.haml b/app/views/condition/explorer.html.haml deleted file mode 100644 index 53f552d186a..00000000000 --- a/app/views/condition/explorer.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -- content_for :search do - = render(:partial => "layouts/x_adv_searchbox", :locals => {:nameonly => true}) - -#main_div - - case @nodetype - - when "root" - = render :partial => "condition_folders" - - when "xx" - = render :partial => "condition_list" - - when "co" - = render :partial => "condition_details", :locals => {:read_only => true} diff --git a/app/views/condition/new.html.haml b/app/views/condition/new.html.haml new file mode 100644 index 00000000000..c66fabf2cd6 --- /dev/null +++ b/app/views/condition/new.html.haml @@ -0,0 +1 @@ += render :partial => 'form' diff --git a/app/views/condition/show.html.haml b/app/views/condition/show.html.haml new file mode 100644 index 00000000000..315b8989e7a --- /dev/null +++ b/app/views/condition/show.html.haml @@ -0,0 +1,91 @@ +#condition_details_div + = render :partial => "layouts/flash_msg" + .form-horizontal + -# Don't show basic info box with description only unless in edit mode + %h3= _("Basic Information") + .form-horizontal + .form-group + %label.control-label.col-md-2 + = _("Description") + .col-md-8 + %p.form-control-static + = h(@condition.description) + + .form-horizontal + .form-group + %label.control-label.col-md-2 + = _("Applies To") + .col-md-8 + = Condition::TOWHAT_APPLIES_TO_CLASSES[@edit ? @edit[:new][:towhat] : @condition.towhat] + + %h3= _("Scope") + .form-horizontal + .form-group + %label.control-label.col-md-2 + = _("Description") + .col-md-8 + - if !@applies_to_exp_table.nil? + - @applies_to_exp_table.each do |token| + - if ! ["AND", "OR", "(", ")"].include?([token].flatten.first) + = h([token].flatten.first) + - else + %font{:color => "black"} + %b + = h([token].flatten.first) + - else + = render :partial => 'layouts/info_msg', :locals => {:message => _("No scope defined, the scope of this condition includes all elements.")} + %hr + + %h3= _("Expression") + .form-horizontal + .form-group + %label.control-label.col-md-2 + .col-md-8 + - if !@expression_table.nil? + - @expression_table.each do |token| + - if ! ["AND", "OR", "(", ")"].include?([token].flatten.first) + = h([token].flatten.first) + - else + %font{:color => "black"} + %b + = h([token].flatten.first) + - else + = render :partial => 'layouts/info_msg', :locals => {:message => _("A condition must contain a valid expression.")} + %hr + + -# Notes field + %h3= _("Notes") + .form-horizontal + - if @condition.notes.blank? + = render :partial => 'layouts/info_msg', :locals => {:message => _("No notes have been entered.")} + - else + = text_area_tag("notes", @condition.notes, :readonly => true, :rows => 5) + %hr + + %h3= _("Assigned to Policies") + - if @condition_policies.empty? + = render :partial => 'layouts/info_msg', :locals => {:message => _("This Condition is not assigned to any Policies.")} + - else + %table.table.table-striped.table-bordered.table-hover + %tbody + - @condition_policies.each do |p| + - id = "xx-#{p.mode.downcase}_xx-#{p.mode.downcase}-#{p.towhat.camelize(:lower)}_p-#{p.id}" + %tr{:title => _("Click to view Policy")} + %td.table-view-pf-select + %i{:class => p.decorate.fonticon} + %td + = p.description + - if !@edit + %h3= _("Assigned to Policies") + - if @condition_policies.empty? + = render :partial => 'layouts/info_msg', :locals => {:message => _("This Condition is not assigned to any Policies.")} + - else + %table.table.table-striped.table-bordered.table-hover + %tbody + - @condition_policies.each do |p| + - id = "xx-#{p.mode.downcase}_xx-#{p.mode.downcase}-#{p.towhat.camelize(:lower)}_p-#{p.id}" + %tr{:title => _("Click to view Policy")} + %td.table-view-pf-select + %i{:class => p.decorate.fonticon} + %td + = p.description diff --git a/app/views/condition/show_list.html.haml b/app/views/condition/show_list.html.haml new file mode 100644 index 00000000000..039604839f2 --- /dev/null +++ b/app/views/condition/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 467d5e962cc..133f85508cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2194,18 +2194,21 @@ :condition => { :get => %w( - explorer + copy + edit + new + show + show_list ), :post => %w( condition_edit condition_field_changed - reload - tree_autoload - tree_select + edit + show + show_list ) + adv_search_post + - exp_post + - x_post + exp_post }, :miq_request => { diff --git a/product/views/Condition.yaml b/product/views/Condition.yaml index d043ae28c10..f95d205071c 100644 --- a/product/views/Condition.yaml +++ b/product/views/Condition.yaml @@ -20,6 +20,7 @@ db: Condition # Columns to fetch from the main table cols: - description +- towhat # Included tables (joined, has_one, has_many) and columns include: @@ -27,10 +28,12 @@ include: # Order of columns (from all tables) col_order: - description +- towhat # Column titles, in order headers: - Description +- Type # Condition(s) string for the SQL query conditions: diff --git a/spec/config/routes.pending.yml b/spec/config/routes.pending.yml index 23a3b274577..e8c440eb1f6 100644 --- a/spec/config/routes.pending.yml +++ b/spec/config/routes.pending.yml @@ -258,15 +258,9 @@ ConditionController: - exp_button - exp_changed - exp_token_pressed -- explorer - index - reload - search_clear -- tree_autoload -- tree_select -- x_history -- x_search_by_name -- x_show ConfigurationController: - index - report_data diff --git a/spec/controllers/condition_controller_spec.rb b/spec/controllers/condition_controller_spec.rb index 74d99657587..697ecab737d 100644 --- a/spec/controllers/condition_controller_spec.rb +++ b/spec/controllers/condition_controller_spec.rb @@ -1,34 +1,26 @@ describe ConditionController do - describe '#condition_edit' do - context 'adding new condition' do - let(:params) { {:button => 'add'} } + before { stub_user(:features => :all) } - before do - allow(subject).to receive(:add_flash) - allow(subject).to receive(:assert_privileges) - allow(subject).to receive(:build_saved_audit).and_return(:event => 'condition_record_add', - :target_id => 1, - :target_class => 'Condition', - :userid => 'admin', - :message => '') - allow(subject).to receive(:exp_build_table) - allow(subject).to receive(:exp_remove_tokens) - allow(subject).to receive(:load_edit).and_return(true) - allow(subject).to receive(:replace_right_cell) - allow(subject).to receive(:x_active_tree).and_return(:condition_tree) - subject.instance_variable_set(:@edit, :new => {:towhat => 'ContainerReplicator', - :description => 'New_condition', - :notes => nil, - :expression => {}, - :applies_to_exp => {"???"=>"???"}}) - subject.instance_variable_set(:@sb, :folder => 'containerReplicator') - end + describe "#show_list" do + render_views - it 'sets new node correctly' do - controller.params = {:button => 'add'} - subject.send(:condition_edit) - expect(subject.instance_variable_get(:@new_condition_node)).to include('xx-containerReplicator_co-') - end + it "renders index" do + get :index + expect(response.status).to eq(302) + expect(response).to redirect_to(:action => 'show_list') + end + end + + describe "#show" do + before do + @condition = FactoryBot.create(:condition, :name => "Test_Condition") + end + + it "render show" do + get(:show, :params => {:id => @condition.id}) + + expect(response.status).to eq(200) + expect(controller.instance_variable_get(:@expression_table)).to eq([["VM and Instance : Number of CPUs >= 2", 1]]) end end end diff --git a/spec/presenters/tree_node/condition_spec.rb b/spec/presenters/tree_node/condition_spec.rb deleted file mode 100644 index 7c5ed02d6db..00000000000 --- a/spec/presenters/tree_node/condition_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -describe TreeNode::Condition do - subject { described_class.new(object, nil, nil) } - let(:object) { FactoryBot.create(:condition) } - - include_examples 'TreeNode::Node#key prefix', 'co-' - include_examples 'TreeNode::Node#icon', 'fa fa-diamond' -end diff --git a/spec/routing/condition_routing_spec.rb b/spec/routing/condition_routing_spec.rb index 0f6decb1633..1497ef72588 100644 --- a/spec/routing/condition_routing_spec.rb +++ b/spec/routing/condition_routing_spec.rb @@ -3,9 +3,25 @@ describe 'routes for ConditionController' do let(:controller_name) { 'condition' } - describe '#condition_edit' do + describe '#edit' do + it 'routes with GET' do + expect(get("/#{controller_name}/edit")).to route_to("#{controller_name}#edit") + end + it 'routes with POST' do - expect(post("/#{controller_name}/condition_edit")).to route_to("#{controller_name}#condition_edit") + expect(post("/#{controller_name}/edit")).to route_to("#{controller_name}#edit") + end + end + + describe '#copy' do + it 'routes with GET' do + expect(get("/#{controller_name}/copy")).to route_to("#{controller_name}#copy") + end + end + + describe '#new' do + it 'routes with GET' do + expect(get("/#{controller_name}/new")).to route_to("#{controller_name}#new") end end @@ -17,21 +33,23 @@ end end - describe '#x_button' do - it 'routes with POST' do - expect(post("/#{controller_name}/x_button")).to route_to("#{controller_name}#x_button") + describe '#show' do + it 'routes with GET' do + expect(get("/#{controller_name}/show")).to route_to("#{controller_name}#show") end - end - describe '#x_history' do it 'routes with POST' do - expect(post("/#{controller_name}/x_history")).to route_to("#{controller_name}#x_history") + expect(post("/#{controller_name}/show")).to route_to("#{controller_name}#show") end end - describe '#x_show' do + describe '#show_list' do + it 'routes with GET' do + expect(get("/#{controller_name}/show_list")).to route_to("#{controller_name}#show_list") + end + it 'routes with POST' do - expect(post("/#{controller_name}/x_show")).to route_to("#{controller_name}#x_show") + expect(post("/#{controller_name}/show_list")).to route_to("#{controller_name}#show_list") end end end