ManageIQ/manageiq-ui-classic

View on GitHub
app/views/layouts/exp_atom/_edit_find.html.haml

Summary

Maintainability
Test Coverage
- url = url_for_only_path(:action => 'exp_changed')

-# Parameters:
-# exp_model      Model in use for this expression

.spacer

= select_tag('chosen_field',
  options_for_select(["<#{_('Choose')}>"] + MiqExpression.miq_adv_search_lists(exp_model, :exp_available_finds), @edit[@expkey][:exp_field]),
  :multiple              => false,
  :class                 => 'selectpicker',
  'data-live-search'     => true,
  "data-miq_sparkle_on"  => true,
  "data-miq_sparkle_off" => true)

- if adv_search_show_alias_checkbox? && !@edit[@expkey][:exp_field].blank?
  = check_box_tag("use_alias", "1", !@edit[@expkey][:alias].blank?,
    :style                      => "width: 20px",
    "data-miq_sparkle_on"       => true,
    "data-miq_sparkle_off"      => true,
    "data-miq_observe_checkbox" => {:url => url}.to_json)
  = _('Use Alias')
  - unless @edit[@expkey][:alias].blank?
    = text_field_tag("alias", @edit[@expkey][:alias],
      :maxlength         => 50,
      "data-miq_observe" => {:interval => '.5', :url => url}.to_json)

- if @edit[@expkey][:exp_field]
  .spacer
  = select_tag('chosen_skey',
    options_for_select(MiqExpression.get_col_operators(@edit[@expkey][:exp_field]), @edit[@expkey][:exp_skey]),
    :multiple              => false,
    :class                 => 'selectpicker',
    "data-miq_sparkle_on"  => true,
    "data-miq_sparkle_off" => true)
  - unless @edit[@expkey][:exp_skey].nil? || @edit[@expkey][:exp_skey].include?("NULL") || @edit[@expkey][:exp_skey].include?("EMPTY")
    %span#chosen_value_span
      - if @edit[@expkey][:val1][:type] == :boolean
        - values = [[_("true"), "true"], [_("false"), "false"]]
        - values.insert(0, ["<#{_('Choose')}>", ""]) if @edit[@expkey][:exp_value].blank?
        = select_tag('chosen_value',
          options_for_select(values, @edit[@expkey][:exp_value]),
          :multiple              => false,
          :class                 => 'selectpicker',
          "data-miq_sparkle_on"  => true,
          "data-miq_sparkle_off" => true)

      - elsif [:date, :datetime].include?(@edit[@expkey][:val1][:type])
        - if @edit[@expkey][:val1][:date_format] == 's'
          = datepicker_input_tag("miq_date_1_0",
            @edit[@expkey][:exp_value][0] ? @edit[@expkey][:exp_value][0].split(" ").first : "",
            :readonly               => "true",
            :size                   => 10,
            "data-miq_observe_date" => {:interval => '.5', :url => url}.to_json)
          - if @edit[@expkey][:exp_value][0].to_s.include?(":")
            = select_tag("miq_time_1_0",
              options_for_select(Array.new(24) { |i| ["#{i}:00", "#{i}:15", "#{i}:30", "#{i}:45"] }.flatten, @edit[@expkey][:exp_value][0].split(" ").last),
              :class                 => 'selectpicker',
              "data-miq_sparkle_on"  => true,
              "data-miq_sparkle_off" => true)
        - else
          - opts = (@edit[@expkey][:val1][:type] == :datetime ? ViewHelper::FROM_HOURS : [])
          - opts += ViewHelper::FROM_DAYS + ViewHelper::FROM_WEEKS + ViewHelper::FROM_MONTHS + ViewHelper::FROM_QUARTERS + ViewHelper::FROM_YEARS
          = select_tag('chosen_from_1',
            options_for_select(Hash[opts.map{|x| [_(x), x]}], @edit[@expkey][:exp_value][0]),
            :multiple              => false,
            :class                 => 'selectpicker',
            "data-miq_sparkle_on"  => true,
            "data-miq_sparkle_off" => true)

        - if @edit[@expkey][:exp_skey] == ApplicationController::Filter::EXP_FROM && @edit[@expkey][:exp_value][0]
          = ('THROUGH')
          - if @edit[@expkey][:val1][:date_format] == 's'
            = datepicker_input_tag("miq_date_1_1",
              @edit[@expkey][:exp_value][1] ? @edit[@expkey][:exp_value][1].split(" ").first : "",
              :readonly               => "true",
              :size                   => 10,
              "data-miq_observe_date" => {:interval => '.5', :url => url}.to_json)
            - if @edit[@expkey][:exp_value][1].to_s.include?(":")
              = select_tag("miq_time_1_1",
                options_for_select(Array.new(24) { |i| ["#{i}:00", "#{i}:15", "#{i}:30", "#{i}:45"] }.flatten, @edit[@expkey][:exp_value][1].split(" ").last),
                :class                 => 'selectpicker',
                "data-miq_sparkle_on"  => true,
                "data-miq_sparkle_off" => true)
          - else
            - if @edit[@expkey][:val1][:through_choices].length > 1
              = select_tag('chosen_through_1',
                options_for_select(@edit[@expkey][:val1][:through_choices], @edit[@expkey][:exp_value][1]),
                :multiple              => false,
                :class                 => 'selectpicker',
                "data-miq_sparkle_on"  => true,
                "data-miq_sparkle_off" => true)
            - else
              = h(@edit[@expkey][:exp_value][1])

        - if @edit[@expkey][:val1][:date_format] == 's'
          = link_to({:action => 'exp_changed', :date_format_1 => 'r'},
            "data-miq_sparkle_on"  => true,
            "data-miq_sparkle_off" => true,
            :remote                => true,
            :class                 => 'btn btn-default',
            "data-method"          => :post,
            :title                 => _('Click to change to a relative Date/Time format')) do
            %i.fa.fa-moon-o
        - else
          = link_to({:action => 'exp_changed', :date_format_1 => 's'},
            "data-miq_sparkle_on"  => true,
            "data-miq_sparkle_off" => true,
            :remote                => true,
            :class                 => 'btn btn-default',
            "data-method"          => :post,
            :title                 => _('Click to change to a specific Date/Time format')) do
            %i.fa.fa-calendar

      - else
        = text_field_tag("chosen_value", @edit[@expkey][:exp_value],
          :maxlength         => 500,
          "data-miq_observe" => {:interval => '.5', :url => url}.to_json)
        - if @edit[@expkey][:val1][:type] == :percent
          \%
        - elsif MiqExpression::FORMAT_SUB_TYPES[@edit[@expkey][:val1][:type]][:units]
          = select_tag('chosen_suffix',
            options_for_select(MiqExpression::FORMAT_SUB_TYPES[@edit[@expkey][:val1][:type]][:units], @edit[@expkey].val1_suffix),
            :multiple              => false,
            :class                 => 'selectpicker',
            "data-miq_sparkle_on"  => true,
            "data-miq_sparkle_off" => true)
  .spacer
  - opts = [[_("Check All"), "checkall"], [_("Check Any"), "checkany"], [_("Check Count"), "checkcount"]]
  = select_tag('chosen_check',
    options_for_select(opts, @edit[@expkey][:exp_check]),
    :multiple              => false,
    :class                 => 'selectpicker',
    "data-miq_sparkle_on"  => true,
    "data-miq_sparkle_off" => true)
  - if @edit[@expkey][:exp_check] != "checkcount"
    = select_tag('chosen_cfield',
      options_for_select(["<Choose>"] + @edit[@expkey].exp_available_cfields, @edit[@expkey][:exp_cfield]),
      :multiple              => false,
      :class                 => 'selectpicker',
      "data-miq_sparkle_on"  => true,
      "data-miq_sparkle_off" => true)
    - if @edit[@expkey][:exp_cfield]
      = select_tag('chosen_ckey',
        options_for_select(MiqExpression.get_col_operators(@edit[@expkey][:exp_cfield]), @edit[@expkey][:exp_ckey]),
        :multiple              => false,
        :class                 => 'selectpicker',
        "data-miq_sparkle_on"  => true,
        "data-miq_sparkle_off" => true)
      - unless @edit[@expkey][:exp_ckey].include?("NULL") || @edit[@expkey][:exp_ckey].include?("EMPTY")
        %span#chosen_cvalue_span
          - if @edit[@expkey][:val2][:type] == :boolean
            - cvalues = [[_("true"), "true"], [_("false"), "false"]]
            - cvalues.insert(0, ["<Choose>", ""]) if @edit[@expkey][:exp_cvalue].blank?
            = select_tag('chosen_cvalue',
              options_for_select(cvalues, @edit[@expkey][:exp_cvalue]),
              :multiple              => false,
              :class                 => 'selectpicker',
              "data-miq_sparkle_on"  => true,
              "data-miq_sparkle_off" => true)

          - elsif [:date, :datetime].include?(@edit[@expkey][:val2][:type])
            - if @edit[@expkey][:val2][:date_format] == 's'
              - v = @edit[@expkey][:exp_cvalue][0] ? @edit[@expkey][:exp_cvalue][0].split(" ").first : ""
              = datepicker_input_tag("miq_date_2_0", v,
                :readonly               => "true",
                :size                   => 10,
                "data-miq_observe_date" => {:interval => '.5', :url => url}.to_json)
              - if @edit[@expkey][:exp_cvalue][0].to_s.include?(":")
                - opts = Array.new(24) { |i| ["#{i}:00", "#{i}:15", "#{i}:30", "#{i}:45"] }.flatten
                = select_tag("miq_time_2_0",
                  options_for_select(opts, @edit[@expkey][:exp_cvalue][0].split(" ").last),
                  :class                 => 'selectpicker',
                  "data-miq_sparkle_on"  => true,
                  "data-miq_sparkle_off" => true)
            - else
              - opts = (@edit[@expkey][:val2][:type] == :datetime ? ViewHelper::FROM_HOURS : [])
              - opts += ViewHelper::FROM_DAYS + ViewHelper::FROM_WEEKS + ViewHelper::FROM_MONTHS + ViewHelper::FROM_QUARTERS + ViewHelper::FROM_YEARS
              = select_tag('chosen_from_2',
                options_for_select(Hash[opts.map {|x| [_(x), x]}], @edit[@expkey][:exp_cvalue][0]),
                :multiple              => false,
                :class                 => 'selectpicker',
                "data-miq_sparkle_on"  => true,
                "data-miq_sparkle_off" => true)

            - if @edit[@expkey][:exp_ckey] == ApplicationController::Filter::EXP_FROM && @edit[@expkey][:exp_cvalue][0]
              = _('THROUGH')
              - if @edit[@expkey][:val2][:date_format] == 's'
                - val = @edit[@expkey][:exp_cvalue][1] ? @edit[@expkey][:exp_cvalue][1].split(" ").first : ""
                = datepicker_input_tag("miq_date_2_1", val,
                  :readonly               => "true",
                  :size                   => 10,
                  "data-miq_observe_date" => {:interval => '.5', :url => url}.to_json)
                - if @edit[@expkey][:exp_cvalue][1].to_s.include?(":")
                  - opts = Array.new(24) { |i| ["#{i}:00", "#{i}:15", "#{i}:30", "#{i}:45"] }.flatten
                  = select_tag("miq_time_2_1",
                    options_for_select(opts, @edit[@expkey][:exp_cvalue][1].split(" ").last),
                    :class                 => 'selectpicker',
                    "data-miq_sparkle_on"  => true,
                    "data-miq_sparkle_off" => true)
              - else
                - if @edit[@expkey][:val2][:through_choices].length > 1
                  = select_tag('chosen_through_2',
                    options_for_select(@edit[@expkey][:val2][:through_choices], @edit[@expkey][:exp_cvalue][1]),
                    :multiple              => false,
                    :class                 => 'selectpicker',
                    "data-miq_sparkle_on"  => true,
                    "data-miq_sparkle_off" => true)
                - else
                  = h(@edit[@expkey][:exp_cvalue][1])

            - if @edit[@expkey][:val2][:date_format] == 's'
              = link_to({:action => 'exp_changed', :date_format_2 => 'r'},
                "data-miq_sparkle_on"  => true,
                "data-miq_sparkle_off" => true,
                :remote                => true,
                :class                 => 'btn btn-default',
                "data-method"          => :post,
                :title                 => _('Click to change to a relative Date/Time format')) do
                %i.fa.fa-moon-o
            - else
              = link_to({:action => 'exp_changed', :date_format_2 => 's'},
                "data-miq_sparkle_on"  => true,
                "data-miq_sparkle_off" => true,
                :remote                => true,
                :class                 => 'btn btn-default',
                "data-method"          => :post,
                :title                 => _('Click to change to a specific Date/Time format')) do
                %i.fa.fa-calendar

          - else
            = text_field_tag("chosen_cvalue", @edit[@expkey][:exp_cvalue],
              :maxlength         => 500,
              "data-miq_observe" => {:interval => '.5', :url => url}.to_json)
            - if @edit[@expkey][:val2][:type] == :percent
              \%
            - elsif MiqExpression::FORMAT_SUB_TYPES[@edit[@expkey][:val2][:type]][:units]
              = select_tag('chosen_suffix2',
                options_for_select(MiqExpression::FORMAT_SUB_TYPES[@edit[@expkey][:val2][:type]][:units], @edit[@expkey].val2_suffix),
                :multiple              => false,
                :class                 => 'selectpicker',
                "data-miq_sparkle_on"  => true,
                "data-miq_sparkle_off" => true)
  - else
    = select_tag('chosen_ckey',
      options_for_select(MiqExpression.get_col_operators(:count), @edit[@expkey][:exp_ckey]),
      :multiple              => false,
      :class                 => 'selectpicker',
      "data-miq_sparkle_on"  => true,
      "data-miq_sparkle_off" => true)
    %span#chosen_cvalue_span
      = text_field_tag("chosen_cvalue", @edit[@expkey][:exp_cvalue],
        :maxlength         => 40,
        "data-miq_observe" => {:interval => '.5', :url => url}.to_json)

:javascript
  miqInitSelectPicker();
  miqSelectPickerEvent('chosen_field', '#{url}');
  miqSelectPickerEvent('chosen_skey', '#{url}');
  miqSelectPickerEvent('chosen_value', '#{url}');
  miqSelectPickerEvent('miq_time_1_0', '#{url}');
  miqSelectPickerEvent('chosen_from_1', '#{url}');
  miqSelectPickerEvent('miq_time_1_1', '#{url}');
  miqSelectPickerEvent('chosen_through_1', '#{url}');
  miqSelectPickerEvent('chosen_suffix', '#{url}');
  miqSelectPickerEvent('chosen_check', '#{url}');
  miqSelectPickerEvent('chosen_cfield', '#{url}');
  miqSelectPickerEvent('chosen_ckey', '#{url}');
  miqSelectPickerEvent('chosen_cvalue', '#{url}');
  miqSelectPickerEvent('miq_time_2_0', '#{url}');
  miqSelectPickerEvent('chosen_from_2', '#{url}');
  miqSelectPickerEvent('miq_time_2_1', '#{url}');
  miqSelectPickerEvent('chosen_through_2', '#{url}');
  miqSelectPickerEvent('chosen_suffix2', '#{url}');
  miqSelectPickerEvent('chosen_ckey', '#{url}');