Class: Faalis::Dashboard::DSL::Index

Inherits:
Base
  • Object
show all
Defined in:
lib/faalis/dashboard/dsl/index.rb

Instance Attribute Summary (collapse)

Attributes inherited from Base

#action_buttons, #default_scope, #fields, #model

Instance Method Summary (collapse)

Methods inherited from Base

#action_button, #initialize, #resolve_model_reflections, #scope

Constructor Details

This class inherits a constructor from Faalis::Dashboard::DSL::Base

Instance Attribute Details

- (Object) tool_buttons (readonly)

Returns the value of attribute tool_buttons



5
6
7
# File 'lib/faalis/dashboard/dsl/index.rb', line 5

def tool_buttons
  @tool_buttons
end

Instance Method Details

- (Object) attributes(*fields_name, **options, &block) Also known as: table_fields

Allow user to specify an array of model attributes to be used in respected section. For example attributes to show as header columns in index section



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/faalis/dashboard/dsl/index.rb', line 10

def attributes(*fields_name, **options, &block)
  if options.include? :except
    @fields = resolve_model_reflections.reject do |field|
      options[:except].include? field.to_sym
    end
  else
    # set new value for fields
    @fields = fields_name.map(&:to_s) unless fields_name.empty?
  end

  @fields.concat(block.call.map(&:to_s)) if block_given?
end

- (Object) tool_button(**options, &block)

Define a new tool on the tool place of the index section options: Is a hash which contains the tool button properties.

name: name of the button. used as identifier class: classes of the button. icon_class: font awesome icon to use in button. remote: whether

You have to provide a block for this method which returns a string to be used as the href for the link



33
34
35
36
37
38
39
# File 'lib/faalis/dashboard/dsl/index.rb', line 33

def tool_button(**options, &block)
  fail 'You have to provide a block for `tool_button`' if !block_given?

  options[:block] = block
  @tool_buttons ||= {}
  @tool_buttons[options[:name]] = options
end