ManageIQ/manageiq-ui-classic

View on GitHub
app/views/catalog/_form_resources_info.html.haml

Summary

Maintainability
Test Coverage
- url = url_for_only_path(:id => (@edit[:rec_id] || "new").to_s,
  :action => @edit[:new][:service_type] == "composite" ? "st_form_field_changed" : "atomic_form_field_changed")

#resources_info_div
  - if @edit[:new][:service_type] == "composite"
    %h3
      = _('Resources')
    .form-horizontal
      .form-group
        %label.col-md-2.control-label
          = _('Add a Resource')
        .col-md-8
          %p.form-control-static
            - array = Array(@edit[:new][:available_resources].invert).sort_by { |a, _| a.first.downcase }
            = select_tag('resource_id',
                         options_for_select(([["<#{_('Choose')}>", nil]]) + array, nil),
                         "data-miq_sparkle_on" => true,
                         :class                => "selectpicker")
            .note
              %b= _("Note: Ansible Playbook based resources can not be added to a Catalog Bundle")
            :javascript
              miqInitSelectPicker();
              miqSelectPickerEvent('resource_id', '#{url}')
    - unless @edit[:new][:selected_resources].empty?
      %hr
      %h3
        = _('Selected Resources')
      %table.table.table-bordered.table-striped
        %thead
          %tr
            %th.table-view-pf-select
            - [_('Name'), _('Action Order'), _('Provision Order'), _('Action'), _('Delay (mins)')].each_with_index do |title, id|
              %th{:colspan => (id >= 3) ? 2 : 1}
                = title
          %tr
            %th{:colspan => '4'}
            - [_('Start'), _('Stop'), _('Start'), _('Stop')].each do |st|
              %th
                = st
        %tbody
          - @edit[:new][:rsc_groups].each_with_index do |groups, i|
            -# add blank tr after each group
            - if i != 0 && !groups.empty? && i < @edit[:new][:rsc_groups].length - 1
              %tr.separator
                %td{:colspan => '9'}

            - groups.sort_by { |g| g[:name].downcase }.each_with_index do |sr, k|
              %tr
                %td
                  = link_to({:action => "resource_delete", :rec_id => sr[:id], :id => @edit[:rec_id] || "new", :grp_id => i},
                    "data-miq_sparkle_on"  => true,
                    "data-miq_sparkle_off" => true,
                    :remote                => true,
                    :class                 => 'btn btn-default',
                    "data-method"          => :post,
                    :title                 => _("Click to remove this Resource from the Catalog Item")) do
                    %i.pficon.pficon-delete
                %td
                  = h(sr[:name])
                %td
                  - if @edit[:new][:selected_resources].length <= 1
                    = h(@edit[:new][:selected_resources].length)
                  - else
                    = select_tag("gidx_#{sr[:id]}",
                      options_for_select((1..@edit[:new][:rsc_groups].length).to_a, (i + 1).to_s),
                      "data-miq_sparkle_on" => true)
                    :javascript
                      miqSelectPickerEvent('gidx_#{sr[:id]}', '#{url}')
                %td
                  - if @edit[:new][:selected_resources].length <= 1
                    = h(@edit[:new][:selected_resources].length)
                  - else
                    = select_tag("provision_index_#{i}_#{k}",
                      options_for_select((1..@edit[:new][:provision_order].length).to_a, (sr[:provision_index] + 1).to_s),
                      "data-miq_sparkle_on" => true)
                    :javascript
                      miqSelectPickerEvent('provision_index_#{i}_#{k}', '#{url}')
                - start_action_values = [_('Do Nothing'), _('Power On')]
                - stop_action_values = [_('Do Nothing'), _('Suspend'), _('Shutdown'), _('Power Off')]
                - delay_values = [[_("None"), 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60]]
                %td
                  = select_tag("start_action_#{i}_#{k}",
                    options_for_select(start_action_values, sr[:start_action]),
                    "data-miq_sparkle_on" => true)
                  :javascript
                    miqSelectPickerEvent('start_action_#{i}_#{k}', '#{url}')
                %td
                  = select_tag("stop_action_#{i}_#{k}",
                    options_for_select(stop_action_values, sr[:stop_action]),
                    "data-miq_sparkle_on" => true)
                  :javascript
                    miqSelectPickerEvent('stop_action_#{i}_#{k}', '#{url}')
                %td
                  = select_tag("start_delay_#{i}_#{k}",
                    options_for_select(delay_values, (sr[:start_delay] / 60).to_s),
                    "data-miq_sparkle_on" => true)
                  :javascript
                    miqSelectPickerEvent('start_delay_#{i}_#{k}', '#{url}')
                %td
                  = select_tag("stop_delay_#{i}_#{k}",
                    options_for_select(delay_values, (sr[:stop_delay] / 60).to_s),
                    "data-miq_sparkle_on" => true)
                  :javascript
                    miqSelectPickerEvent('stop_delay_#{i}_#{k}', '#{url}')