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

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

Direct Known Subclasses

Show

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, #scope

Constructor Details

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

Instance Attribute Details

#tool_buttonsObject (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

#attributes(*fields_name, **options, &block) ⇒ Object 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
22
23
# 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
  elsif options.include? :append
     @fields += options[:append]
  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

#tool_button(**options, &block) ⇒ Object

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



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

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