Module: Faalis::Generators::Concerns::Tabs

Included in:
DashboardScaffold
Defined in:
lib/faalis/generators/concerns/tabs.rb

Overview

Using this concern module user can specify an array of tab objects which each one has an id and name attribute. Tabs will be added to new view of resource. Also this concern will a tab key to field object. All the fields with same id as a tab will be grouped in that tab

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) any_tabs? (private)

Returns:

  • (Boolean)


50
51
52
# File 'lib/faalis/generators/concerns/tabs.rb', line 50

def any_tabs?
  resource_data.include? 'tabs'
end

- (Boolean) tab_has_field?(tab_name, field_name) (private)

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/faalis/generators/concerns/tabs.rb', line 45

def tab_has_field?(tab_name, field_name)
  it_does = tabs[tab_name].select { |f| f['name'] == field_name }
  !it_does.empty?
end

- (Object) tabs (private)

Process the user provided tabs return a Hash of tabs like



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/faalis/generators/concerns/tabs.rb', line 16

def tabs
  tabbed_fields = Set.new

  if resource_data.include? 'tabs'

    tabs = resource_data['tabs']
    result = {}
    tabs.each do |tab|
      name = tab['name']

      fields_list = fields_with('tab', tab['id'])
      fields_list.each { |f| tabbed_fields << f }

      result[name] = fields_list
    end
    all_fields = Set.new resource_data['fields']

    result.each do |k, v|
      if v.empty?
        diff = (all_fields ^ tabbed_fields).to_a
        result[k] = diff
      end
    end
    return result
  else
    {}
  end
end