action_admin 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 744d35d72168f97e4b21090228b74cb79f7e63e4
4
- data.tar.gz: 37e859e3f7beb0093b102796002490a04cbe1b59
3
+ metadata.gz: 982edc1021b2a77531f490363c7bd03ccd771dc6
4
+ data.tar.gz: d31e4dd9c6d0a407a1484ca3fbc4e303f1ab5299
5
5
  SHA512:
6
- metadata.gz: 2873abf6a53398466252f625d5019f150b0f11fa4238f8757a5ce86f737169fed06c396b77693b9a04828f92c26afa2739343943d843539097da6072c129b0a2
7
- data.tar.gz: 215d8e6fdf62b86e3b20247afc1f77cd7b51c2c95069179f3522e1539be645a1aacde44772f1b217b4ee100e87ecc51085f6cb668c2916b3f321fd8590c92a4e
6
+ metadata.gz: dbc141a4e4a8da89026d6d74f925a6408723cdbd7fb99aad16311e6c4d9e1741077170adebfe74b1eef46ac20f2060c0a31b0eeb4851559c5e151effd3683625
7
+ data.tar.gz: 18fd1ac7ffa3a656ed76982930ca505222c24d5f0f6bd6dce7ca750ce7a830f5b7c8d790e698308514fdfe0131e8c5ba023c728db53db3c73b4bfa04113fb702
@@ -19,6 +19,12 @@ module ActionAdmin
19
19
  self.action_header.action(nil)
20
20
  end
21
21
 
22
+ def action_links(action, links=[])
23
+ self.action_header.action(action)
24
+ self.action_header.links(links)
25
+ self.action_header.action(nil)
26
+ end
27
+
22
28
  def action_template(action, template, options={})
23
29
  self._action_templates = self._action_templates.merge(
24
30
  action => options.merge(partial: "admin/templates/#{template}")
@@ -27,16 +27,35 @@ module ActionAdmin
27
27
  content_tag :div, info + links, class: 'grid-x'
28
28
  end
29
29
 
30
+ def admin_settings_menu(records, label_method=:id)
31
+ options = {
32
+ menu_class: 'menu horizontal',
33
+ active_class: 'active',
34
+ keep_defaults: false
35
+ }
36
+
37
+ items = records.map do |record|
38
+ label = record.send(label_method)
39
+ url = edit_record_url(record)
40
+
41
+ [:"#{label.downcase.underscore}", { label: label, url: url, html: { class: 'padding-1' } }]
42
+ end
43
+
44
+ smart_navigation_for Hash[items], options
45
+ end
46
+
30
47
  def admin_primary_menu
31
48
  options = {
32
49
  menu_class: 'vertical menu icons icon-left accordion-menu',
33
50
  menu_html: { 'data-accordion-menu': '', 'data-submenu-toggle': true },
34
- separator_class: 'is-separator',
35
- submenu_parent_class: 'has-children',
51
+ menu_icons: true,
52
+ submenu_icons: false,
36
53
  submenu_class: 'vertical menu nested',
37
54
  active_class: 'is-current',
38
55
  active_submenu_class: 'is-current',
39
- icon_prefix: 'mdi mdi-'
56
+ icon_prefix: 'mdi mdi-',
57
+ icon_position: 'left',
58
+ keep_defaults: false
40
59
  }
41
60
 
42
61
  smart_navigation_for ActionAdmin.config.menus.primary, options
@@ -45,13 +64,11 @@ module ActionAdmin
45
64
  def admin_secondary_menu
46
65
  options = {
47
66
  menu_class: 'vertical menu secondary icons icon-right',
48
- separator_class: 'is-separator',
49
- submenu_parent_class: 'has-children',
50
- submenu_class: 'vertical menu nested',
67
+ menu_icons: true,
51
68
  active_class: 'is-current',
52
- active_submenu_class: 'is-current',
53
69
  icon_prefix: 'mdi mdi-',
54
- icon_position: 'right'
70
+ icon_position: 'right',
71
+ keep_defaults: false
55
72
  }
56
73
 
57
74
  smart_navigation_for ActionAdmin.config.menus.secondary, options
@@ -68,14 +85,12 @@ module ActionAdmin
68
85
  }
69
86
 
70
87
  options = {
71
- menu_class: 'menu icons icon-left',
72
- separator_class: 'is-separator',
73
- submenu_parent_class: 'has-children',
74
- submenu_class: 'vertical menu nested',
75
- active_class: 'is-current',
76
- active_submenu_class: 'is-current',
77
- icon_prefix: 'mdi mdi-',
78
- icon_position: 'left'
88
+ menu_class: 'menu icons icon-left',
89
+ menu_icons: true,
90
+ submenu_class: 'vertical menu nested',
91
+ icon_prefix: 'mdi mdi-',
92
+ icon_position: 'left',
93
+ keep_defaults: false
79
94
  }
80
95
 
81
96
  custom = ActionAdmin.config.menus.send(:"topbar_#{position}")
@@ -87,27 +102,33 @@ module ActionAdmin
87
102
  def admin_action_links(action=nil)
88
103
  name = action || action_name
89
104
  links = controller.action_header.action_links(name, self).map do |link|
90
- opts = Hash(link[:html]).merge(method: link[:method])
91
- classes = "button small hollow #{opts[:class]}".strip
92
- label = admin_icon(link[:icon], text: link[:label])
105
+ unless link[:url].nil?
106
+ opts = Hash(link[:html]).merge(method: link[:method])
107
+ classes = "button small hollow #{opts[:class]}".strip
108
+ label = admin_icon(link[:icon], text: link[:label])
93
109
 
94
- link_to label, link[:url], opts.merge(class: classes)
110
+ link_to label, link[:url], opts.merge(class: classes)
111
+ end
95
112
  end
96
113
 
97
- links.join(' ').html_safe
114
+ links.reject(&:blank?).join(' ').html_safe
98
115
  end
99
116
 
100
117
  def admin_table_action_links(record, actions=nil)
118
+ app_url = method(ActionAdmin.config.app_urls).call(record) rescue nil
119
+ app_link = link_to admin_icon('web'), app_url, title: 'Web', target: :_blank, class: 'button hollow info' if app_url.present?
120
+
101
121
  options = {
102
- show: { label: admin_icon('eye'), title: 'View', class: 'success' },
122
+ # show: { label: admin_icon('eye'), title: 'View', class: 'success' },
103
123
  edit: { label: admin_icon('pencil'), title: 'Edit' },
104
124
  destroy: { label: admin_icon('delete'), title: 'Delete', class: 'alert' }
105
125
  }
106
126
 
107
- options = options.select { |k, _v| k.in? actions } if actions.present?
108
- options = options.merge(html: { class: 'button hollow' })
127
+ options = options.select { |k, _v| k.in? actions } if actions.present?
128
+ options = options.merge(html: { class: 'button hollow' })
129
+ all_links = record_links_to record, options
109
130
 
110
- record_links_to record, options
131
+ app_link.nil? ? all_links : (app_link + all_links)
111
132
  end
112
133
  end
113
134
  end
@@ -16,7 +16,7 @@ module ActionAdmin
16
16
  if attributes.keys.any?
17
17
  attributes.keys
18
18
  else
19
- items = ['title', 'name', 'email', 'id']
19
+ items = ['title', 'name', 'email', 'id', 'var']
20
20
  names = @record.class.attribute_names.select { |i| i.in? items }
21
21
 
22
22
  names.sort_by { |i| items.index i }.first(1)
@@ -61,32 +61,41 @@ module ActionAdmin
61
61
  end
62
62
 
63
63
  def fields
64
- self.record_fields
64
+ if self.record_fields.any?
65
+ self.record_fields
66
+ else
67
+ Hash[@record.permitted_attributes.map { |e| [:"#{e}", {}] }]
68
+ end
65
69
  end
66
70
 
67
71
  def render_field(form, field, options={})
72
+ options = Hash(options)
68
73
  association = options[:association]
69
74
 
70
75
  if association.present?
71
- form.association field, Hash(options).except(:association)
76
+ form.association field, options.except(:association)
72
77
  else
73
- form.input field, Hash(options)
78
+ form.input field, options
74
79
  end
75
80
  end
76
81
 
77
82
  def render_fields(form)
78
- fields.map { |f, o| render_field(form, f, 0) }.join.html_safe
83
+ fields.map { |f, o| render_field(form, f, o) }.join.html_safe
79
84
  end
80
85
 
81
86
  def panels
82
- self.record_panels
87
+ if self.record_panels.any?
88
+ self.record_panels
89
+ else
90
+ { attributes: { title: 'Attributes', fields: fields.keys } }
91
+ end
83
92
  end
84
93
 
85
94
  def render_panel(form, options={})
86
95
  template = "admin/panels/#{options.fetch :template, 'default'}"
87
- content = Array(options[:fields]).map { |f| render_panel_field(form, f, options) }
88
- footer = Array(Hash(options[:footer])[:fields]).map { |f| render_panel_field(form, f, options) }.join.html_safe
89
- footer = nil if footer.blank?
96
+ content = Array(options[:fields]).map { |f| render_panel_field(form, f, options) }
97
+ footer = Array(Hash(options[:footer])[:fields]).map { |f| render_panel_field(form, f, options) }.join.html_safe
98
+ footer = nil if footer.blank?
90
99
 
91
100
  options = {
92
101
  layout: false,
@@ -0,0 +1,22 @@
1
+ = admin_form_for([:admin, current_record]) do |f|
2
+ = f.error_notification
3
+
4
+ / .page-content
5
+ / .sidebar
6
+ / .panel
7
+ / .panel-header.border
8
+ / = 'Menu'
9
+ /
10
+ / .panel-content
11
+ / = admin_settings_menu collection, label_method
12
+ /
13
+ / .content
14
+ / = admin_present(current_record).render_panels(form: f)
15
+ / = f.button :submit
16
+
17
+ .panel
18
+ .panel-content.padding-0
19
+ = admin_settings_menu collection, label_method
20
+
21
+ = admin_present(current_record).render_panels(form: f)
22
+ = f.button :submit
@@ -2,9 +2,11 @@ module ActionAdmin
2
2
  class Header
3
3
  class_attribute :actions
4
4
  class_attribute :current_actions
5
+ class_attribute :active_links
5
6
 
6
7
  def initialize
7
- self.actions = {}
8
+ self.actions = {}
9
+ self.active_links = {}
8
10
  end
9
11
 
10
12
  def action(names)
@@ -19,15 +21,22 @@ module ActionAdmin
19
21
  current_actions.each { |a| add_action_key(a, :links, options, true) }
20
22
  end
21
23
 
24
+ def links(names)
25
+ current_actions.each { |a| self.active_links[a] = Array(names) }
26
+ end
27
+
22
28
  def action_title(name, context)
23
29
  title = Hash(actions[:"#{name}"]).fetch :title, default_title(context)
24
30
  evaluate_value(title, context)
25
31
  end
26
32
 
27
33
  def action_links(name, context)
28
- links = Hash(actions[:"#{name}"]).fetch :links, default_action_links(name, context)
34
+ active = self.active_links[:"#{name}"]
35
+ links = Hash(actions[:"#{name}"]).fetch :links, default_action_links(name, context)
36
+ links = links.select { |k, _v| k.in? active } if active.is_a? Array
37
+ links = links.values if links.is_a? Hash
29
38
 
30
- Array(links).map do |link|
39
+ Array(links).reject(&:blank?).map do |link|
31
40
  Hash[link.map { |k, v| [k, evaluate_value(v, context)] }]
32
41
  end
33
42
  end
@@ -41,17 +50,20 @@ module ActionAdmin
41
50
  end
42
51
 
43
52
  def default_action_links(name, context)
44
- setup = { index: :new, new: :index, show: [:index, :edit, :destroy], edit: [:index, :show, :destroy] }
53
+ setup = { index: :new, new: :index, show: [:index, :app, :edit, :destroy], edit: [:index, :app, :show, :destroy] }
45
54
  links = default_links(context)
46
55
 
47
- Array(setup[:"#{name}"]).map { |l| links[l] }.reject(&:nil?)
56
+ Hash[Array(setup[:"#{name}"]).map { |l| [l, links[l]] }.reject(&:nil?)]
48
57
  end
49
58
 
50
59
  def default_links(context)
51
60
  return {} unless context.controller.respond_to? :permitted_params
52
61
 
62
+ show = -> { method(ActionAdmin.config.app_urls).call(current_record) rescue nil }
63
+
53
64
  {
54
- show: { label: 'View', icon: 'eye', url: :record_path, html: { class: 'success' } },
65
+ app: { label: 'Web', icon: 'web', url: show, html: { class: 'info', target: :_blank } },
66
+ # show: { label: 'View', icon: 'eye', url: :record_path, html: { class: 'success' } },
55
67
  index: { label: 'Back', icon: 'arrow-left', url: :records_path, html: { class: 'secondary' } },
56
68
  new: { label: 'New', icon: 'plus', url: :new_record_path, html: { class: 'success' } },
57
69
  edit: { label: 'Edit', icon: 'pencil', url: :edit_record_path, html: { class: 'warning' } },
@@ -1,3 +1,3 @@
1
1
  module ActionAdmin
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonian Guveli
@@ -237,6 +237,7 @@ files:
237
237
  - app/views/admin/records/index.html.slim
238
238
  - app/views/admin/records/new.html.slim
239
239
  - app/views/admin/records/show.html.slim
240
+ - app/views/admin/templates/_settings.html.slim
240
241
  - app/views/admin/templates/_upload.html.slim
241
242
  - app/views/layouts/admin.html.slim
242
243
  - app/views/layouts/admin/devise.html.slim