Class: ActionAdmin::Header
- Inherits:
-
Object
- Object
- ActionAdmin::Header
- Defined in:
- lib/action_admin/header.rb
Instance Method Summary collapse
- #action(names) ⇒ Object
- #action_links(name, context) ⇒ Object
- #action_title(name, context) ⇒ Object
- #default_action_links(name, context) ⇒ Object
- #default_links(context) ⇒ Object
- #default_title(context) ⇒ Object
-
#initialize ⇒ Header
constructor
A new instance of Header.
- #link(options) ⇒ Object
- #links(names) ⇒ Object
- #title(value) ⇒ Object
Constructor Details
#initialize ⇒ Header
Returns a new instance of Header.
7 8 9 10 |
# File 'lib/action_admin/header.rb', line 7 def initialize self.actions = {} self.active_links = {} end |
Instance Method Details
#action(names) ⇒ Object
12 13 14 |
# File 'lib/action_admin/header.rb', line 12 def action(names) self.current_actions = Array(names) end |
#action_links(name, context) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/action_admin/header.rb', line 33 def action_links(name, context) active = self.active_links[:"#{name}"] links = Hash(actions[:"#{name}"]).fetch :links, default_action_links(name, context) links = links.select { |k, _v| k.in? active } if active.is_a? Array links = links.values if links.is_a? Hash Array(links).reject(&:blank?).map do |link| Hash[link.map { |k, v| [k, evaluate_value(v, context)] }] end end |
#action_title(name, context) ⇒ Object
28 29 30 31 |
# File 'lib/action_admin/header.rb', line 28 def action_title(name, context) title = Hash(actions[:"#{name}"]).fetch :title, default_title(context) evaluate_value(title, context) end |
#default_action_links(name, context) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/action_admin/header.rb', line 55 def default_action_links(name, context) setup = { index: :new, new: :index, show: [:index, :app, :edit, :destroy], edit: [:index, :app, :show, :destroy] } links = default_links(context) Hash[Array(setup[:"#{name}"]).map { |l| [l, links[l]] }.reject(&:nil?)] end |
#default_links(context) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/action_admin/header.rb', line 62 def default_links(context) return {} unless context.controller.respond_to? :permitted_params show = -> { method(ActionAdmin.config.app_urls).call(current_record) rescue nil } { app: { label: 'Web', icon: 'web', url: show, html: { class: 'info', target: :_blank } }, # show: { label: 'View', icon: 'eye', url: :record_path, html: { class: 'success' } }, index: { label: 'Back', icon: 'arrow-left', url: :records_path, html: { class: 'secondary' } }, new: { label: 'New', icon: 'plus', url: :new_record_path, html: { class: 'success' } }, edit: { label: 'Edit', icon: 'pencil', url: :edit_record_path, html: { class: 'warning' } }, destroy: { label: 'Delete', icon: 'delete', url: :record_path, html: { class: 'alert' }, method: 'delete' } } end |
#default_title(context) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/action_admin/header.rb', line 44 def default_title(context) singular = context.controller.try(:instance_name) plural = context.controller.try(:collection_name) if context.action_name == 'index' "#{plural || context.controller_name}".strip.titleize else "#{context.action_name} #{singular}".strip.titleize end end |
#link(options) ⇒ Object
20 21 22 |
# File 'lib/action_admin/header.rb', line 20 def link() current_actions.each { |a| add_action_key(a, :links, , true) } end |
#links(names) ⇒ Object
24 25 26 |
# File 'lib/action_admin/header.rb', line 24 def links(names) current_actions.each { |a| self.active_links[a] = Array(names) } end |
#title(value) ⇒ Object
16 17 18 |
# File 'lib/action_admin/header.rb', line 16 def title(value) current_actions.each { |a| add_action_key(a, :title, value) } end |