lib/ab_admin/config/base.rb in ab_admin-0.7.0 vs lib/ab_admin/config/base.rb in ab_admin-0.8.0

- old
+ new

@@ -1,22 +1,21 @@ module AbAdmin module Config class BaseBuilder attr_reader :options, :fields attr_accessor :partial - class_attribute :field_defaults, :partial_name, instance_writer: false - self.field_defaults = {} + class_attribute :partial_name, instance_writer: false def initialize(options={}, &block) @fields = [] @options = options @partial = options[:partial] instance_eval(&block) if block_given? end def field(name, options={}, &block) - @fields << Field.new(name, options.reverse_merge!(field_defaults), &block) + @fields << Field.new(name, options, &block) end def self.default_for_model(model, options={}) new.tap do |builder| builder.field(:id) unless options[:skip].try(:include?, :id) @@ -28,18 +27,21 @@ end end end class Table < BaseBuilder - self.field_defaults = {sortable: true} self.partial_name = 'table' end class Search < BaseBuilder self.partial_name = 'search_form' end + class Chart < BaseBuilder + self.partial_name = 'chart' + end + class Export < BaseBuilder def render_options {column_names: fields.map(&:name), column_data: fields.map(&:data), column_separator: options[:column_separator], worksheet_name: options[:worksheet_name], filename: options[:filename]} @@ -162,14 +164,14 @@ attr_reader :name, :options, :data def initialize(name, options={}, &block) @name = name @options = options + @options[:badge] = {} if @options[:badge] && !@options[:badge].is_a?(Hash) @data = block end def apply(relation, params) - return relation unless params[name].present? data.is_a?(Proc) ? data.call(relation, params) : relation.public_send(name) end end end end