Sha256: 59959d2236b6233ca8b963ad0c4acb03c7ece40c97c2a4289348f8766e83fbb6

Contents?: true

Size: 1.32 KB

Versions: 33

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module PgEngine
  module IndexHelper
    def encabezado(campo, options = {})
      campo = campo.to_s.sub(/_f\z/, '')
      campo = campo.to_s.sub(/_text\z/, '')
      clase = options[:clase] || @clase_modelo
      if options[:ordenable]
        field = controller.instance_variable_get(:@field)
        direction = controller.instance_variable_get(:@direction)
        uri = URI.parse(request.url)
        cgi = if uri.query.present?
                CGI.parse(uri.query)
              else
                {}
              end
        cgi['order_by'] = campo
        cgi['order_direction'] =
          if field.to_s == campo.to_s && direction.to_s == 'asc'
            'desc'
          else
            'asc'
          end

        symbol = if field.to_s == campo.to_s
                   if direction.to_s == 'asc'
                     '<i class="bi bi-sort-down-alt" />'
                   elsif direction.to_s == 'desc'
                     '<i class="bi bi-sort-up" />'
                   end
                 else
                   ''
                 end

        uri.query = cgi.transform_values { |b| (b.length == 1 ? b.first : b) }.to_query

        link_to(clase.human_attribute_name(campo), uri.to_s) + " #{symbol}".html_safe
      else
        clase.human_attribute_name(campo)
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
pg_rails-7.1.1.pre.1 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.1.0 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.112 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.111 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.110 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.109 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.108 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.107 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.106 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.105 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.104 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.103 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.102 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.101 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.100 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.99 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.98 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.97 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.96 pg_engine/app/helpers/pg_engine/index_helper.rb
pg_rails-7.0.8.pre.alpha.95 pg_engine/app/helpers/pg_engine/index_helper.rb