You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add to your Gemfile: `gem 'tiny_admin', '~> 0.4'`
19
+
- Add to your Gemfile: `gem 'tiny_admin', '~> 0.5'`
20
20
- Mount the app in a route (check some examples with: Hanami, Rails, Roda and standalone in [extra](extra))
21
21
+ in Rails, update _config/routes.rb_: `mount TinyAdmin::Router => '/admin'`
22
-
- Configure the dashboard using `TinyAdmin.configure` and/or `TinyAdmin.configure_from_file` (see [configuration](#configuration) below):
22
+
- Configure the dashboard using `TinyAdmin.configure` and/or `TinyAdmin.configure_from_file`with a YAML config file (see [configuration](#configuration) below):
23
23
24
24
```rb
25
25
TinyAdmin.configure do |settings|
@@ -35,32 +35,37 @@ end
35
35
### Authentication
36
36
37
37
Plugins available:
38
-
-_SimpleAuth_: session authentication based on Warden (`warden` gem must be included in the Gemfile) using a password hash provided via config or via environment variable (`ADMIN_PASSWORD_HASH`);
39
-
-_NoAuth_: no authentication.
38
+
39
+
-**SimpleAuth**: a session authentication based on Warden (`warden` gem must be included in the Gemfile) using a password hash provided via config or via environment variable (`ADMIN_PASSWORD_HASH`). _Disclaimer: this plugin is provided as example, if you need a secure authentication I suggest to create your own._
40
+
41
+
-**NoAuth**: no authentication.
40
42
41
43
### Repository
42
44
43
45
Plugin available:
44
-
-_ActiveRecordRepository_: isolates the query layer to expose the resources in the admin interface.
46
+
47
+
-**ActiveRecordRepository**: isolates the query layer to expose the resources in the admin interface.
45
48
46
49
### View pages
47
50
48
51
Pages available:
49
-
-_Root_: define how to present the content in the main page of the interface;
50
-
-_PageNotFound_: define how to present pages not found;
51
-
-_RecordNotFound_: define how to present record not found page;
52
-
-_SimpleAuthLogin_: define how to present the login form for SimpleAuth plugin;
53
-
-_Index_: define how to present a collection of items;
54
-
-_Show_: define how to present the details of an item.
52
+
53
+
-**Root**: define how to present the content in the main page of the interface;
54
+
-**PageNotFound**: define how to present pages not found;
55
+
-**RecordNotFound**: define how to present record not found page;
56
+
-**SimpleAuthLogin**: define how to present the login form for SimpleAuth plugin;
57
+
-**Index**: define how to present a collection of items;
58
+
-**Show**: define how to present the details of an item.
55
59
56
60
### View components
57
61
58
62
Components available:
59
-
-_FiltersForm_: define how to present the filters form in the resource collection pages;
60
-
-_Flash_: define how to present the flash messages;
61
-
-_Head_: define how to present the Head tag;
62
-
-_Navbar_: define how to present the navbar (the default one uses the Bootstrap structure);
63
-
-_Pagination_: define how to present the pagination of a collection.
63
+
64
+
-**FiltersForm**: define how to present the filters form in the resource collection pages;
65
+
-**Flash**: define how to present the flash messages;
66
+
-**Head**: define how to present the Head tag;
67
+
-**Navbar**: define how to present the navbar (the default one uses the Bootstrap structure);
68
+
-**Pagination**: define how to present the pagination of a collection.
64
69
65
70
## Configuration
66
71
@@ -70,9 +75,10 @@ See [extra](extra) folder for some usage examples.
70
75
The following options are supported:
71
76
72
77
`root` (Hash): define the root section of the admin, properties:
73
-
-`title` (String): root section's title;
74
-
-`page` (String): a view object to render;
75
-
-`redirect` (String): alternative to _page_ option - redirects to a specific slug;
78
+
79
+
-`title` (String): root section's title;
80
+
-`page` (String): a view object to render;
81
+
-`redirect` (String): alternative to _page_ option - redirects to a specific slug;
76
82
77
83
Example:
78
84
@@ -88,9 +94,21 @@ root:
88
94
89
95
`record_not_found` (String): a view object to render when a missing record is requested.
90
96
97
+
`style_links` (Array of hashes): list of styles files to include, properties:
98
+
99
+
- `href` (String): URL for the style file;
100
+
- `rel` (String): type of style file.
101
+
102
+
`scripts` (Array of hashes): list of scripts to include, properties:
103
+
104
+
- `src` (String): source URL for the script.
105
+
106
+
`extra_styles` (String): inline CSS styles.
107
+
91
108
`authentication` (Hash): define the authentication method, properties:
92
-
- `plugin` (String): a plugin class to use (ex. `TinyAdmin::Plugins::SimpleAuth`);
93
-
- `password` (String): a password hash used by _SimpleAuth_ plugin (generated with `Digest::SHA512.hexdigest("some password")`).
109
+
110
+
- `plugin` (String): a plugin class to use (ex. `TinyAdmin::Plugins::SimpleAuth`);
111
+
- `password` (String): a password hash used by _SimpleAuth_ plugin (generated with `Digest::SHA512.hexdigest("some password")`).
94
112
95
113
Example:
96
114
@@ -101,15 +119,17 @@ authentication:
101
119
```
102
120
103
121
`sections` (Array of hashes): define the admin sections, properties:
104
-
- `slug` (String): section reference identifier;
105
-
- `name` (String): section's title;
106
-
- `type` (String): the type of section: `url`, `page` or `resource`;
107
-
- other properties depends on the section's type.
122
+
123
+
- `slug` (String): section reference identifier;
124
+
- `name` (String): section's title;
125
+
- `type` (String): the type of section: `url`, `page` or `resource`;
126
+
- other properties depends on the section's type.
108
127
109
128
For _url_ sections:
110
-
- `url` (String): the URL to load when clicking on the section's menu item;
111
-
- `options` (Hash): properties:
112
-
+ `target` (String): link _target_ attributes (ex. `_blank`).
129
+
130
+
- `url` (String): the URL to load when clicking on the section's menu item;
131
+
- `options` (Hash): properties:
132
+
+ `target` (String): link _target_ attributes (ex. `_blank`).
113
133
114
134
Example:
115
135
@@ -123,7 +143,8 @@ options:
123
143
```
124
144
125
145
For _page_ sections:
126
-
- `page` (String): a view object to render.
146
+
147
+
- `page` (String): a view object to render.
127
148
128
149
Example:
129
150
@@ -135,14 +156,15 @@ page: Admin::Stats
135
156
```
136
157
137
158
For _resource_ sections:
138
-
- `model` (String): the class to use to fetch the data on an item of a collection;
139
-
- `repository` (String): the class to get the properties related to the model;
140
-
- `index` (Hash): collection's action options;
141
-
- `show` (Hash): detail's action options;
142
-
- `collection_actions` (Array of hashes): custom collection's actions;
143
-
- `member_actions` (Array of hashes): custom details's actions;
144
-
- `only` (Array of strings): list of supported actions (ex. `index`);
145
-
- `options` (Array of strings): resource options (ex. `hidden`).
159
+
160
+
- `model` (String): the class to use to fetch the data on an item of a collection;
161
+
- `repository` (String): the class to get the properties related to the model;
162
+
- `index` (Hash): collection's action options (see below);
163
+
- `show` (Hash): detail's action options (see below);
164
+
- `collection_actions` (Array of hashes): custom collection's actions;
165
+
- `member_actions` (Array of hashes): custom details's actions;
166
+
- `only` (Array of strings): list of supported actions (ex. `index`);
167
+
- `options` (Array of strings): resource options (ex. `hidden`).
146
168
147
169
Example:
148
170
@@ -153,14 +175,72 @@ type: resource
153
175
model: Post
154
176
```
155
177
156
-
`style_links` (Array of hashes): list of styles files to include, properties:
157
-
- `href` (String): URL for the style file;
158
-
- `rel` (String): type of style file.
178
+
#### Resource index options
159
179
160
-
`scripts` (Array of hashes): list of scripts to include, properties:
161
-
- `src` (String): source URL for the script.
180
+
The Index hash supports the following options:
162
181
163
-
`extra_styles` (String): inline CSS styles.
182
+
- `attributes` (Array): fields to expose in the resource list page;
183
+
- `filters` (Array): filter the current listing;
184
+
- `links` (Array): custom member actions to expose for each list's entry (defined in _member_actions_);
185
+
- `pagination` (Integer): max pages size;
186
+
- `sort` (Array): sort options to pass to the listing query.
187
+
188
+
Example:
189
+
190
+
```yml
191
+
index:
192
+
sort:
193
+
- id DESC
194
+
pagination: 10
195
+
attributes:
196
+
- id
197
+
- author: call, name
198
+
- position: round, 1
199
+
- field: author_id
200
+
header: The author
201
+
link_to: authors
202
+
call: author, name
203
+
filters:
204
+
- title
205
+
- field: state
206
+
type: select
207
+
values:
208
+
- published
209
+
- draft
210
+
- archived
211
+
links:
212
+
- show
213
+
- author_posts
214
+
- csv_export
215
+
```
216
+
217
+
#### Resource show options
218
+
219
+
The Show hash supports the following options:
220
+
221
+
- `attributes` (Array): fields to expose in the resource details page.
222
+
223
+
Example:
224
+
225
+
```yml
226
+
show:
227
+
attributes:
228
+
# Expose the id column
229
+
- id
230
+
# Expose the title column, calling `downcase` support method
231
+
- title: downcase
232
+
# Expose the category column, calling `upcase` support method
233
+
- category: upcase
234
+
# Expose the position column, calling `format` support method with argument %f
235
+
- position: format, %f
236
+
# Expose the position created_at, calling `strftime` support method with argument %Y%m%d %H:%M
237
+
- created_at: strftime, %Y%m%d %H:%M
238
+
# Expose the author_id column, with a custom header label, linked to authors section and calling author.name to get the value
0 commit comments