Sha256: df9251206b2aad621c07916e0f3b2faf8e2b1087ec8b73a02f5267feccb9ba23

Contents?: true

Size: 945 Bytes

Versions: 14

Compression:

Stored size: 945 Bytes

Contents

module Admin::Resources::FiltersHelper

  def build_filters(resource = @resource, params = params)
    if (typus_filters = resource.typus_filters).any?
      locals = {}

      locals[:filters] = typus_filters.map do |key, value|
                           { :key => set_filter(key, value),
                             :value => send("#{value}_filter", key) }
                         end

      rejections = %w(controller action locale utf8 sort_order order_by) + locals[:filters].map { |f| f[:key] }
      locals[:hidden_filters] = params.dup.delete_if { |k, v| rejections.include?(k) }

      render "helpers/admin/resources/filters", locals
    end
  end

  def set_filter(key, value)
    return key unless value == :belongs_to

    att_assoc = @resource.reflect_on_association(key.to_sym)
    class_name = att_assoc.options[:class_name] || key.capitalize.camelize
    resource = class_name.constantize
    att_assoc.foreign_key
  end

end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
brainsome_typus-4.0.0.beta9 app/helpers/admin/resources/filters_helper.rb
brainsome_typus-4.0.0.beta8 app/helpers/admin/resources/filters_helper.rb
brainsome_typus-4.0.0.beta7 app/helpers/admin/resources/filters_helper.rb
brainsome_typus-4.0.0.beta6 app/helpers/admin/resources/filters_helper.rb
brainsome_typus-4.0.0.beta5 app/helpers/admin/resources/filters_helper.rb
brainsome_typus-4.0.0.beta4 app/helpers/admin/resources/filters_helper.rb
brainsome_typus-4.0.0.beta3 app/helpers/admin/resources/filters_helper.rb
brainsome_typus-4.0.0.beta2 app/helpers/admin/resources/filters_helper.rb
brainsome_typus-4.0.0.beta1 app/helpers/admin/resources/filters_helper.rb
typus-3.1.10 app/helpers/admin/resources/filters_helper.rb
typus-3.1.9 app/helpers/admin/resources/filters_helper.rb
typus-3.1.8 app/helpers/admin/resources/filters_helper.rb
typus-3.1.7 app/helpers/admin/resources/filters_helper.rb
typus-3.1.6 app/helpers/admin/resources/filters_helper.rb