Module: AbAdmin::Views::ManagerHelpers

Defined in:
lib/ab_admin/views/manager_helpers.rb

Constant Summary collapse

INDEX_VIEW_ICONS =
{table: 'list', tree: 'move', grid: 'th', chart: 'signal', map: 'map-marker', stats: 'eye-open'}

Instance Method Summary collapse

Instance Method Details

#action_item_admin_path(name, record = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/ab_admin/views/manager_helpers.rb', line 46

def action_item_admin_path(name, record=nil)
  custom_action = manager.custom_action_for(name, self)
  if custom_action.collection?
    admin_collection_action_path(model_name: resource_collection_name, custom_action: custom_action.name)
  else
    record ||= resource
    admin_member_action_path(model_name: resource_collection_name, id: record.id, custom_action: custom_action.name)
  end
end

#chart_builderObject



16
17
18
# File 'lib/ab_admin/views/manager_helpers.rb', line 16

def chart_builder
  manager.chart ||= ::AbAdmin::Config::Chart.default_for_model(resource_class)
end

#form_builderObject



12
13
14
# File 'lib/ab_admin/views/manager_helpers.rb', line 12

def form_builder
  manager.form ||= ::AbAdmin::Config::Form.default_for_model(resource_class, skip: [:id, :created_at, :updated_at, :lft, :rgt, :depth])
end


57
58
59
60
61
62
# File 'lib/ab_admin/views/manager_helpers.rb', line 57

def index_view_link(index_view)
  options = {class: "btn tool tool-bottom #{('active' if settings[:current_index_view] == index_view)}", title: t("admin.index_view.#{index_view}", default: index_view.to_s)}
  url = url_for({index_view: index_view, q: params[:q]}.reject_blank)
  title = INDEX_VIEW_ICONS[index_view.to_sym] ? icon(INDEX_VIEW_ICONS[index_view.to_sym]) : index_view
  link_to title, url, options
end

#map_builderObject



20
21
22
# File 'lib/ab_admin/views/manager_helpers.rb', line 20

def map_builder
  manager.map ||= ::AbAdmin::Config::Map.default_for_model(resource_class)
end


24
25
26
# File 'lib/ab_admin/views/manager_helpers.rb', line 24

def modal_form_builder
  manager.modal_form ||= ::AbAdmin::Config::ModalForm.default_for_model(resource_class, skip: [:id, :created_at, :updated_at, :lft, :rgt, :depth])
end

#search_builderObject



8
9
10
# File 'lib/ab_admin/views/manager_helpers.rb', line 8

def search_builder
  manager.search ||= ::AbAdmin::Config::Search.default_for_model(resource_class)
end

#show_builderObject



28
29
30
# File 'lib/ab_admin/views/manager_helpers.rb', line 28

def show_builder
  manager.show ||= ::AbAdmin::Config::Show.default_for_model(resource_class)
end

#table_builderObject



4
5
6
# File 'lib/ab_admin/views/manager_helpers.rb', line 4

def table_builder
  manager.table ||= ::AbAdmin::Config::Table.default_for_model(resource_class)
end

#table_item_field(item, field) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ab_admin/views/manager_helpers.rb', line 32

def table_item_field(item, field)
  if field.options[:editable] && field.data.is_a?(Symbol)
    if field.data.to_s.start_with?('is_')
      editable_bool(item, field.data)
    else
      admin_editable item, field.data, field.options[:editable]
    end
  elsif field.options[:image]
    item_image_link(item, assoc: field.name)
  else
    admin_pretty_data call_method_or_proc_on(item, field.data)
  end
end