tiny_admin 0.7.0 → 0.8.0
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 +4 -4
- data/README.md +14 -1
- data/lib/tiny_admin/authentication.rb +5 -1
- data/lib/tiny_admin/field.rb +13 -0
- data/lib/tiny_admin/plugins/active_record_repository.rb +1 -4
- data/lib/tiny_admin/plugins/base_repository.rb +0 -14
- data/lib/tiny_admin/settings.rb +1 -0
- data/lib/tiny_admin/support.rb +4 -0
- data/lib/tiny_admin/utils.rb +1 -1
- data/lib/tiny_admin/version.rb +1 -1
- data/lib/tiny_admin/views/actions/index.rb +9 -10
- data/lib/tiny_admin/views/actions/show.rb +1 -7
- data/lib/tiny_admin/views/basic_layout.rb +4 -0
- data/lib/tiny_admin/views/components/field_value.rb +33 -0
- data/lib/tiny_admin/views/components/filters_form.rb +12 -4
- data/lib/tiny_admin/views/pages/simple_auth_login.rb +6 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71d42ca63e3a410de95780d584cdfb61dd94feb95b503f5f55379efabec9477e
|
4
|
+
data.tar.gz: 96c4b375cb65327635199296d11f54335e6c5266dacce39a7316e0eb2844046c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d377537524247253a871e016d3d5e688e47ab07d40c6d33814c5dfc0be761e734d3de3c8c23d3e3981d3f949ce15d230312b4c71fb2d7d6f33aeb45cc352223f
|
7
|
+
data.tar.gz: 4ddb16c2f1fbfefced95deb426cf369d28201866f800eee1f4b14895bd938233f6f67bf51d784a7edf340b48d7a75230a86b679db9ec71c07f18b726c23971a4
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ Please ⭐ if you like it.
|
|
19
19
|
|
20
20
|
## Install
|
21
21
|
|
22
|
-
- Add to your Gemfile: `gem 'tiny_admin', '~> 0.
|
22
|
+
- Add to your Gemfile: `gem 'tiny_admin', '~> 0.8'`
|
23
23
|
- Mount the app in a route (check some examples with: Hanami, Rails, Roda and standalone in [extra](extra))
|
24
24
|
+ in Rails, update _config/routes.rb_: `mount TinyAdmin::Router => '/admin'`
|
25
25
|
- Configure the dashboard using `TinyAdmin.configure` and/or `TinyAdmin.configure_from_file` with a YAML config file (see [configuration](#configuration) below):
|
@@ -85,6 +85,8 @@ The following options are supported:
|
|
85
85
|
- `redirect` (String): alternative to _page_ option - redirects to a specific slug;
|
86
86
|
- `widgets` (Array): list of widgets (as View components) to present.
|
87
87
|
|
88
|
+
> 📚 [Wiki Root page](https://github.com/blocknotes/tiny_admin/wiki/Root) available
|
89
|
+
|
88
90
|
Example:
|
89
91
|
|
90
92
|
```yml
|
@@ -98,6 +100,8 @@ root:
|
|
98
100
|
|
99
101
|
`helper_class` (String): class or module with helper methods, used for attributes' formatters.
|
100
102
|
|
103
|
+
> 📚 [Wiki Helper methods page](https://github.com/blocknotes/tiny_admin/wiki/Helper-methods) available
|
104
|
+
|
101
105
|
`page_not_found` (String): a view object to render when a missing page is requested.
|
102
106
|
|
103
107
|
`record_not_found` (String): a view object to render when a missing record is requested.
|
@@ -113,11 +117,15 @@ root:
|
|
113
117
|
|
114
118
|
`extra_styles` (String): inline CSS styles.
|
115
119
|
|
120
|
+
> 📚 [Wiki Styles and scripts page](https://github.com/blocknotes/tiny_admin/wiki/Styles-and-scripts) available
|
121
|
+
|
116
122
|
`authentication` (Hash): define the authentication method, properties:
|
117
123
|
|
118
124
|
- `plugin` (String): a plugin class to use (ex. `TinyAdmin::Plugins::SimpleAuth`);
|
119
125
|
- `password` (String): a password hash used by _SimpleAuth_ plugin (generated with `Digest::SHA512.hexdigest("some password")`).
|
120
126
|
|
127
|
+
> 📚 [Wiki Authentication page](https://github.com/blocknotes/tiny_admin/wiki/Authentication) available
|
128
|
+
|
121
129
|
Example:
|
122
130
|
|
123
131
|
```yml
|
@@ -134,6 +142,8 @@ authentication:
|
|
134
142
|
- `widgets` (Array): list of widgets (as View components) to present;
|
135
143
|
- other properties depends on the section's type.
|
136
144
|
|
145
|
+
> 📚 [Wiki Pages page](https://github.com/blocknotes/tiny_admin/wiki/Pages) available
|
146
|
+
|
137
147
|
For _content_ sections:
|
138
148
|
|
139
149
|
- `content` (String): the HTML content to present.
|
@@ -186,6 +196,9 @@ For _resource_ sections:
|
|
186
196
|
|
187
197
|
- `model` (String): the class to use to fetch the data on an item of a collection;
|
188
198
|
- `repository` (String): the class to get the properties related to the model;
|
199
|
+
|
200
|
+
> 📚 [Wiki Repository page](https://github.com/blocknotes/tiny_admin/wiki/Repository) available
|
201
|
+
|
189
202
|
- `index` (Hash): collection's action options (see below);
|
190
203
|
- `show` (Hash): detail's action options (see below);
|
191
204
|
- `collection_actions` (Array of hashes): custom collection's actions;
|
@@ -12,7 +12,11 @@ module TinyAdmin
|
|
12
12
|
end
|
13
13
|
|
14
14
|
r.post 'unauthenticated' do
|
15
|
-
|
15
|
+
warning = TinyAdmin.settings.helper_class.label_for(
|
16
|
+
'Failed to authenticate',
|
17
|
+
options: ['authentication.unauthenticated']
|
18
|
+
)
|
19
|
+
render_login(warnings: [warning])
|
16
20
|
end
|
17
21
|
|
18
22
|
r.get 'logout' do
|
data/lib/tiny_admin/field.rb
CHANGED
@@ -16,6 +16,19 @@ module TinyAdmin
|
|
16
16
|
messages.inject(target) { |result, msg| result&.send(msg) } if messages.any?
|
17
17
|
end
|
18
18
|
|
19
|
+
def translate_value(value)
|
20
|
+
if options && options[:method]
|
21
|
+
method, *args = options[:method].split(',').map(&:strip)
|
22
|
+
if options[:converter]
|
23
|
+
Object.const_get(options[:converter]).send(method, value, options: args || [])
|
24
|
+
else
|
25
|
+
TinyAdmin.settings.helper_class.send(method, value, options: args || [])
|
26
|
+
end
|
27
|
+
else
|
28
|
+
value&.to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
19
32
|
class << self
|
20
33
|
def create_field(name:, title: nil, type: nil, options: {})
|
21
34
|
field_name = name.to_s
|
@@ -6,10 +6,7 @@ module TinyAdmin
|
|
6
6
|
def index_record_attrs(record, fields: nil)
|
7
7
|
return record.attributes.transform_values(&:to_s) unless fields
|
8
8
|
|
9
|
-
fields.to_h
|
10
|
-
value = record.send(name)
|
11
|
-
[name, translate_value(value, field)]
|
12
|
-
end
|
9
|
+
fields.to_h { [_1, record.send(_1)] }
|
13
10
|
end
|
14
11
|
|
15
12
|
def index_title
|
@@ -10,20 +10,6 @@ module TinyAdmin
|
|
10
10
|
def initialize(model)
|
11
11
|
@model = model
|
12
12
|
end
|
13
|
-
|
14
|
-
def translate_value(value, field)
|
15
|
-
if field[:method]
|
16
|
-
method, *options = field[:method].split(',').map(&:strip)
|
17
|
-
if field[:converter]
|
18
|
-
converter = Object.const_get(field[:converter])
|
19
|
-
converter.send(method, value, options: options || [])
|
20
|
-
else
|
21
|
-
TinyAdmin.settings.helper_class.send(method, value, options: options || [])
|
22
|
-
end
|
23
|
-
else
|
24
|
-
value&.to_s
|
25
|
-
end
|
26
|
-
end
|
27
13
|
end
|
28
14
|
end
|
29
15
|
end
|
data/lib/tiny_admin/settings.rb
CHANGED
@@ -7,6 +7,7 @@ module TinyAdmin
|
|
7
7
|
DEFAULTS = {
|
8
8
|
%i[authentication plugin] => Plugins::NoAuth,
|
9
9
|
%i[authentication login] => Views::Pages::SimpleAuthLogin,
|
10
|
+
%i[components field_value] => Views::Components::FieldValue,
|
10
11
|
%i[components flash] => Views::Components::Flash,
|
11
12
|
%i[components head] => Views::Components::Head,
|
12
13
|
%i[components navbar] => Views::Components::Navbar,
|
data/lib/tiny_admin/support.rb
CHANGED
data/lib/tiny_admin/utils.rb
CHANGED
data/lib/tiny_admin/version.rb
CHANGED
@@ -69,13 +69,7 @@ module TinyAdmin
|
|
69
69
|
attributes.each do |key, value|
|
70
70
|
field = fields[key]
|
71
71
|
td(class: "field-value-#{field.name} field-value-type-#{field.type}") {
|
72
|
-
|
73
|
-
a(href: TinyAdmin.route_for(field.options[:link_to], reference: value)) {
|
74
|
-
field.apply_call_option(record) || value
|
75
|
-
}
|
76
|
-
else
|
77
|
-
value
|
78
|
-
end
|
72
|
+
render TinyAdmin.settings.components[:field_value].new(field, value, record: record)
|
79
73
|
}
|
80
74
|
end
|
81
75
|
|
@@ -86,15 +80,20 @@ module TinyAdmin
|
|
86
80
|
links.each do |link|
|
87
81
|
whitespace
|
88
82
|
if link == 'show'
|
89
|
-
a(href: TinyAdmin.route_for(slug, reference: record.id), class: link_class) {
|
83
|
+
a(href: TinyAdmin.route_for(slug, reference: record.id), class: link_class) {
|
84
|
+
label_for('Show', options: ['actions.index.links.show'])
|
85
|
+
}
|
90
86
|
else
|
91
87
|
a(href: TinyAdmin.route_for(slug, reference: record.id, action: link), class: link_class) {
|
92
|
-
|
88
|
+
fallback = humanize(link)
|
89
|
+
label_for(fallback, options: ["actions.index.links.#{link}"])
|
93
90
|
}
|
94
91
|
end
|
95
92
|
end
|
96
93
|
else
|
97
|
-
a(href: TinyAdmin.route_for(slug, reference: record.id), class: link_class) {
|
94
|
+
a(href: TinyAdmin.route_for(slug, reference: record.id), class: link_class) {
|
95
|
+
label_for('Show', options: ['actions.index.links.show'])
|
96
|
+
}
|
98
97
|
end
|
99
98
|
}
|
100
99
|
}
|
@@ -25,13 +25,7 @@ module TinyAdmin
|
|
25
25
|
div(class: 'field-header col-2') { field.options[:header] || field.title }
|
26
26
|
end
|
27
27
|
div(class: 'field-value col-10') {
|
28
|
-
|
29
|
-
a(href: TinyAdmin.route_for(field.options[:link_to], reference: value)) {
|
30
|
-
field.apply_call_option(record) || value
|
31
|
-
}
|
32
|
-
else
|
33
|
-
value
|
34
|
-
end
|
28
|
+
render TinyAdmin.settings.components[:field_value].new(field, value, record: record)
|
35
29
|
}
|
36
30
|
}
|
37
31
|
end
|
@@ -7,6 +7,10 @@ module TinyAdmin
|
|
7
7
|
|
8
8
|
attr_accessor :content, :widgets
|
9
9
|
|
10
|
+
def label_for(value, options: [])
|
11
|
+
TinyAdmin.settings.helper_class.label_for(value, options: options)
|
12
|
+
end
|
13
|
+
|
10
14
|
def update_attributes(attributes)
|
11
15
|
attributes.each do |key, value|
|
12
16
|
send("#{key}=", value)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TinyAdmin
|
4
|
+
module Views
|
5
|
+
module Components
|
6
|
+
class FieldValue < BasicComponent
|
7
|
+
attr_reader :field, :value, :record
|
8
|
+
|
9
|
+
def initialize(field, value, record:)
|
10
|
+
@field = field
|
11
|
+
@value = value
|
12
|
+
@record = record
|
13
|
+
end
|
14
|
+
|
15
|
+
def template
|
16
|
+
translated_value = field.translate_value(value)
|
17
|
+
value_class = field.options[:options]&.include?('value_class') ? "value-#{value}" : nil
|
18
|
+
if field.options[:link_to]
|
19
|
+
a(href: TinyAdmin.route_for(field.options[:link_to], reference: translated_value)) {
|
20
|
+
span(class: value_class) {
|
21
|
+
field.apply_call_option(record) || translated_value
|
22
|
+
}
|
23
|
+
}
|
24
|
+
else
|
25
|
+
span(class: value_class) {
|
26
|
+
translated_value
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -17,8 +17,12 @@ module TinyAdmin
|
|
17
17
|
when :boolean
|
18
18
|
select(class: 'form-select', id: "filter-#{name}", name: "q[#{name}]") {
|
19
19
|
option(value: '') { '-' }
|
20
|
-
option(value: '0', selected: filter[:value] == '0') {
|
21
|
-
|
20
|
+
option(value: '0', selected: filter[:value] == '0') {
|
21
|
+
TinyAdmin.settings.helper_class.label_for('false', options: ['components.filters_form.boolean.false'])
|
22
|
+
}
|
23
|
+
option(value: '1', selected: filter[:value] == '1') {
|
24
|
+
TinyAdmin.settings.helper_class.label_for('true', options: ['components.filters_form.boolean.true'])
|
25
|
+
}
|
22
26
|
}
|
23
27
|
when :date
|
24
28
|
input(type: 'date', class: 'form-control', id: "filter-#{name}", name: "q[#{name}]", value: filter[:value])
|
@@ -40,9 +44,13 @@ module TinyAdmin
|
|
40
44
|
end
|
41
45
|
|
42
46
|
div(class: 'mt-3') {
|
43
|
-
a(href: section_path, class: 'button_clear btn btn-secondary text-white') {
|
47
|
+
a(href: section_path, class: 'button_clear btn btn-secondary text-white') {
|
48
|
+
TinyAdmin.settings.helper_class.label_for('Clear', options: ['components.filters_form.buttons.clear'])
|
49
|
+
}
|
44
50
|
whitespace
|
45
|
-
button(type: 'submit', class: 'button_filter btn btn-secondary') {
|
51
|
+
button(type: 'submit', class: 'button_filter btn btn-secondary') {
|
52
|
+
TinyAdmin.settings.helper_class.label_for('Filter', options: ['components.filters_form.buttons.submit'])
|
53
|
+
}
|
46
54
|
}
|
47
55
|
}
|
48
56
|
end
|
@@ -11,12 +11,16 @@ module TinyAdmin
|
|
11
11
|
|
12
12
|
form(class: 'form_login', method: 'post') {
|
13
13
|
div(class: 'mt-3') {
|
14
|
-
label(for: 'secret', class: 'form-label') {
|
14
|
+
label(for: 'secret', class: 'form-label') {
|
15
|
+
label_for('Password', options: ['pages.simple_auth_login.inputs.password'])
|
16
|
+
}
|
15
17
|
input(type: 'password', name: 'secret', class: 'form-control', id: 'secret')
|
16
18
|
}
|
17
19
|
|
18
20
|
div(class: 'mt-3') {
|
19
|
-
button(type: 'submit', class: 'button_login btn btn-primary') {
|
21
|
+
button(type: 'submit', class: 'button_login btn btn-primary') {
|
22
|
+
label_for('Login', options: ['pages.simple_auth_login.buttons.submit'])
|
23
|
+
}
|
20
24
|
}
|
21
25
|
}
|
22
26
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phlex
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- lib/tiny_admin/views/basic_layout.rb
|
99
99
|
- lib/tiny_admin/views/basic_widget.rb
|
100
100
|
- lib/tiny_admin/views/components/basic_component.rb
|
101
|
+
- lib/tiny_admin/views/components/field_value.rb
|
101
102
|
- lib/tiny_admin/views/components/filters_form.rb
|
102
103
|
- lib/tiny_admin/views/components/flash.rb
|
103
104
|
- lib/tiny_admin/views/components/head.rb
|