Sha256: 4cadff7d1c23ba8ccadae7b7fbc7ef2e400cc343c14e4373f76fd5ca47b2bdaf

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

module Godmin
  module Helpers
    module Tables
      def column_header(attribute)
        if @resource_service.orderable_column?(attribute.to_s)
          direction =
            if params[:order].present?
              if params[:order].match(/\A#{attribute.to_s}_(asc|desc)\z/)
                $1 == "desc" ? "asc" : "desc"
              elsif params[:order].match(/\A\w+_(asc|desc)\z/)
                $1
              else
                "desc"
              end
            else
              "desc"
            end
          link_to @resource_class.human_attribute_name(attribute.to_s), url_for(params.to_unsafe_h.merge(order: "#{attribute}_#{direction}"))
        else
          @resource_class.human_attribute_name(attribute.to_s)
        end
      end

      def column_value(resource, attribute)
        partial_override "#{controller_path}/columns/#{attribute}", resource: resource do
          column_value = resource.send(attribute)

          if column_value.is_a?(Date) || column_value.is_a?(Time)
            column_value = l(column_value, format: :long)
          end

          if column_value.is_a?(TrueClass) || column_value.is_a?(FalseClass)
            column_value = t(column_value.to_s)
          end

          return column_value
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
godmin-2.3.0 lib/godmin/helpers/tables.rb
godmin-2.2.2 lib/godmin/helpers/tables.rb