Sha256: 83890d4aa5fc4797bf84d7318c290e1e6fc0a7b705417d293efaafe3151f06ef

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

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|
                           { :filter => set_filter(key, value), :items => send("#{value}_filter", key) }
                         end

      locals[:hidden_filters] = params.dup

      # Remove default params.
      rejections = %w(controller action locale utf8 sort_order order_by)
      locals[:hidden_filters].delete_if { |k, v| rejections.include?(k) }

      # Remove also custom params.
      rejections = locals[:filters].map { |f| f[:filter] }
      locals[:hidden_filters].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

6 entries across 6 versions & 1 rubygems

Version Path
typus-3.1.0.rc18 app/helpers/admin/resources/filters_helper.rb
typus-3.1.0.rc17 app/helpers/admin/resources/filters_helper.rb
typus-3.1.0.rc16 app/helpers/admin/resources/filters_helper.rb
typus-3.1.0.rc15 app/helpers/admin/resources/filters_helper.rb
typus-3.1.0.rc14 app/helpers/admin/resources/filters_helper.rb
typus-3.1.0.rc13 app/helpers/admin/resources/filters_helper.rb