activeadmin-menu_tree 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -15
- data/lib/activeadmin/menu_tree/config.rb +2 -3
- data/lib/activeadmin/menu_tree/dsl.rb +1 -2
- data/lib/activeadmin/menu_tree/version.rb +1 -1
- data/lib/activeadmin/menu_tree.rb +2 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0caee8014a99e9c19b47e24c1fe5f9c3950a6707f00389d7a6572dc1c4671024
|
4
|
+
data.tar.gz: 48b3919992e7df05e26103655f8301ab405210b4f7b114fd097bd0aae2850c26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17618bae45e7f27646ad1aa1b65f0f8ab8dd221cdb5c949edb960e8e3d5ff01a837a7091ab7d772a149f9ce739c017bc56906fe939f30488794b6c4b731ba76b
|
7
|
+
data.tar.gz: 5345872721f7072db40551286347bdd2a6d072ddfccf08e0fc1bf02f626d471960d5c9efd7bfea1887a64418fdaa060026104dd48552ce5f683ab27c19fc8260
|
data/README.md
CHANGED
@@ -46,12 +46,12 @@ Write the configuration in a yaml file.
|
|
46
46
|
# config/activeadmin-menu_tree.yml or anywhere you like
|
47
47
|
activeadmin:
|
48
48
|
menu_tree:
|
49
|
-
-
|
49
|
+
- id: Dashboard
|
50
50
|
- label: Admin
|
51
51
|
children:
|
52
|
-
-
|
52
|
+
- id: AdminUser
|
53
53
|
label: Admin Users
|
54
|
-
-
|
54
|
+
- id: Comment
|
55
55
|
label: Admin Comments
|
56
56
|
```
|
57
57
|
|
@@ -92,13 +92,13 @@ If you want to use dynamic specification using `proc` in menu_tree (instead of i
|
|
92
92
|
```ruby
|
93
93
|
ActiveAdmin::MenuTree.setup do |config|
|
94
94
|
config.menu_tree = [
|
95
|
-
{
|
95
|
+
{ id: "Dashboard", label: proc { I18n.t("active_admin.dashboard") } },
|
96
96
|
{
|
97
97
|
label: "Foo",
|
98
98
|
if: proc { "Something dynamic" },
|
99
99
|
children: [
|
100
|
-
{
|
101
|
-
{
|
100
|
+
{ id: "Bar" },
|
101
|
+
{ id: "Baz" }
|
102
102
|
]
|
103
103
|
}
|
104
104
|
]
|
@@ -125,26 +125,26 @@ Or you can use other configuration gems like [global gem](https://github.com/rai
|
|
125
125
|
```yaml
|
126
126
|
activeadmin:
|
127
127
|
menu_tree:
|
128
|
-
# Specify the resource
|
129
|
-
-
|
130
|
-
-
|
128
|
+
# Specify the resource with `id`.
|
129
|
+
- id: Dashboard
|
130
|
+
- id: Product
|
131
131
|
# Specify a menu label with `label`.
|
132
132
|
- label: User Info
|
133
133
|
# Specify child elements with `children`.
|
134
134
|
children:
|
135
|
-
-
|
136
|
-
-
|
135
|
+
- id: User
|
136
|
+
- id: Profile
|
137
137
|
- label: Admin
|
138
138
|
children:
|
139
|
-
-
|
139
|
+
- id: AdminUser
|
140
140
|
label: Admin Users
|
141
141
|
# Comment resource will be handled specially.
|
142
|
-
-
|
142
|
+
- id: Comment
|
143
143
|
label: Admin Comments
|
144
144
|
- label: Others
|
145
145
|
children:
|
146
|
-
-
|
147
|
-
-
|
146
|
+
- id: Foo
|
147
|
+
- id: Bar
|
148
148
|
- label: Example Site
|
149
149
|
# You can pass the other options available for `menu` DSL, like `url`, `html_options`.
|
150
150
|
url: 'https://example.com'
|
@@ -165,6 +165,9 @@ activeadmin:
|
|
165
165
|
target: blank
|
166
166
|
```
|
167
167
|
|
168
|
+
<img width="1573" alt="screenshot" src="https://user-images.githubusercontent.com/7542105/153759374-fd516cb8-8022-4e44-aad9-c97f77afc4e7.png">
|
169
|
+
|
170
|
+
|
168
171
|
## Development
|
169
172
|
|
170
173
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -17,8 +17,8 @@ module ActiveAdmin::MenuTree
|
|
17
17
|
@menu_options = flatten_options(@menu_tree)
|
18
18
|
end
|
19
19
|
|
20
|
-
def find_menu_option(
|
21
|
-
menu_options.find { |item| item[:
|
20
|
+
def find_menu_option(id:)
|
21
|
+
menu_options.find { |item| item[:id] == id }
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
@@ -38,7 +38,6 @@ module ActiveAdmin::MenuTree
|
|
38
38
|
# TODO: validate option
|
39
39
|
options = item.except(:children)
|
40
40
|
options[:priority] = index * 10
|
41
|
-
options[:id] ||= item[:name]
|
42
41
|
options[:parent] = parent if parent.present?
|
43
42
|
options
|
44
43
|
end
|
@@ -4,8 +4,7 @@ module ActiveAdmin::MenuTree
|
|
4
4
|
# ActiveAdmin::MenuTree::DSL class
|
5
5
|
module DSL
|
6
6
|
def menu_tree(**args)
|
7
|
-
options = menu_tree_config.find_menu_option(
|
8
|
-
options = options.except(:name)
|
7
|
+
options = menu_tree_config.find_menu_option(id: config.resource_name.name) || {}
|
9
8
|
options = options.merge(args)
|
10
9
|
menu(**options)
|
11
10
|
end
|
@@ -32,12 +32,11 @@ module ActiveAdmin
|
|
32
32
|
private
|
33
33
|
|
34
34
|
def setup_menu_options(aa_config)
|
35
|
-
comments_menu = config.find_menu_option(
|
35
|
+
comments_menu = config.find_menu_option(id: "Comment")
|
36
36
|
aa_config.comments_menu = comments_menu if comments_menu.present?
|
37
37
|
|
38
38
|
menu_options = config.menu_options
|
39
|
-
.reject{ |item| item[:
|
40
|
-
.map{ |item| item.except(:name) }
|
39
|
+
.reject{ |item| item[:id] == "Comment" }
|
41
40
|
|
42
41
|
aa_config.namespace :admin do |admin|
|
43
42
|
admin.build_menu do |menu|
|