trestle 0.9.7 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +4 -2
- data/.gitignore +4 -0
- data/README.md +1 -1
- data/app/assets/bundle/trestle/bundle.css +4 -4
- data/app/assets/bundle/trestle/bundle.js +12 -26
- data/app/controllers/concerns/trestle/controller/toolbars.rb +1 -1
- data/app/controllers/concerns/trestle/resource/controller/actions.rb +5 -5
- data/app/controllers/concerns/trestle/resource/controller/redirection.rb +5 -3
- data/app/controllers/trestle/admin_controller.rb +4 -0
- data/app/helpers/trestle/card_helper.rb +2 -2
- data/app/helpers/trestle/navigation_helper.rb +3 -1
- data/app/helpers/trestle/toolbars_helper.rb +1 -1
- data/app/views/trestle/flash/_flash.html.erb +1 -1
- data/app/views/trestle/resource/_scopes.html.erb +1 -1
- data/config/locales/vi.yml +1 -1
- data/frontend/css/components/_fields.scss +1 -0
- data/frontend/css/components/_toolbars.scss +1 -19
- data/frontend/css/core/_mixins.scss +1 -4
- data/frontend/css/layout/_content.scss +1 -1
- data/frontend/js/components/tabs.js +1 -1
- data/lib/generators/trestle/install/install_generator.rb +6 -2
- data/lib/generators/trestle/install/templates/_custom.css +8 -0
- data/lib/trestle/adapters/active_record_adapter.rb +1 -1
- data/lib/trestle/admin/builder.rb +7 -0
- data/lib/trestle/admin.rb +12 -6
- data/lib/trestle/configurable.rb +2 -2
- data/lib/trestle/debug_errors.rb +24 -0
- data/lib/trestle/form/automatic.rb +3 -1
- data/lib/trestle/hook/helpers.rb +1 -1
- data/lib/trestle/navigation/group.rb +1 -2
- data/lib/trestle/navigation/item.rb +2 -2
- data/lib/trestle/reloader.rb +2 -11
- data/lib/trestle/resource/builder.rb +1 -8
- data/lib/trestle/resource.rb +2 -2
- data/lib/trestle/scopes/block.rb +7 -7
- data/lib/trestle/scopes/definition.rb +2 -2
- data/lib/trestle/scopes/scope.rb +4 -0
- data/lib/trestle/version.rb +1 -1
- data/lib/trestle.rb +5 -0
- data/package.json +1 -1
- data/trestle.gemspec +7 -7
- data/webpack.config.js +8 -1
- data/yarn.lock +1444 -2603
- metadata +23 -21
@@ -25,7 +25,7 @@ module Trestle
|
|
25
25
|
respond_to do |format|
|
26
26
|
format.html do
|
27
27
|
flash[:message] = flash_message("create.success", title: "Success!", message: "The %{lowercase_model_name} was successfully created.")
|
28
|
-
redirect_to_return_location(:create, instance
|
28
|
+
redirect_to_return_location(:create, instance) { admin.instance_path(instance) }
|
29
29
|
end
|
30
30
|
format.json { render json: instance, status: :created, location: admin.instance_path(instance) }
|
31
31
|
|
@@ -85,7 +85,7 @@ module Trestle
|
|
85
85
|
respond_to do |format|
|
86
86
|
format.html do
|
87
87
|
flash[:message] = flash_message("update.success", title: "Success!", message: "The %{lowercase_model_name} was successfully updated.")
|
88
|
-
redirect_to_return_location(:update, instance
|
88
|
+
redirect_to_return_location(:update, instance) { admin.instance_path(instance) }
|
89
89
|
end
|
90
90
|
format.json { render json: instance, status: :ok }
|
91
91
|
|
@@ -111,14 +111,14 @@ module Trestle
|
|
111
111
|
format.html do
|
112
112
|
if success
|
113
113
|
flash[:message] = flash_message("destroy.success", title: "Success!", message: "The %{lowercase_model_name} was successfully deleted.")
|
114
|
-
redirect_to_return_location(:destroy, instance
|
114
|
+
redirect_to_return_location(:destroy, instance) { admin.path(:index) }
|
115
115
|
else
|
116
116
|
flash[:error] = flash_message("destroy.failure", title: "Warning!", message: "Could not delete %{lowercase_model_name}.")
|
117
117
|
|
118
118
|
if load_instance
|
119
|
-
redirect_to_return_location(:update, instance
|
119
|
+
redirect_to_return_location(:update, instance) { admin.instance_path(instance) }
|
120
120
|
else
|
121
|
-
redirect_to_return_location(:destroy, instance
|
121
|
+
redirect_to_return_location(:destroy, instance) { admin.path(:index) }
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
@@ -3,18 +3,20 @@ module Trestle
|
|
3
3
|
module Controller
|
4
4
|
module Redirection
|
5
5
|
protected
|
6
|
-
def redirect_to_return_location(action, instance, default:)
|
6
|
+
def redirect_to_return_location(action, instance, default: nil, &block)
|
7
|
+
fallback_location = block_given? ? block : default
|
8
|
+
|
7
9
|
if admin.return_locations[action] && !dialog_request?
|
8
10
|
location = instance_exec(instance, &admin.return_locations[action])
|
9
11
|
|
10
12
|
case location
|
11
13
|
when :back
|
12
|
-
redirect_back fallback_location:
|
14
|
+
redirect_back fallback_location: fallback_location, turbolinks: false
|
13
15
|
else
|
14
16
|
redirect_to location, turbolinks: false
|
15
17
|
end
|
16
18
|
else
|
17
|
-
redirect_to
|
19
|
+
redirect_to fallback_location, turbolinks: false
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -11,12 +11,12 @@ module Trestle
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def panel(options={}, &block)
|
14
|
-
|
14
|
+
Trestle.deprecator.warn("The panel helper is deprecated and will be removed in future versions of Trestle. Please use the card helper instead.")
|
15
15
|
card(options.merge(header: options[:title]), &block)
|
16
16
|
end
|
17
17
|
|
18
18
|
def well(options={}, &block)
|
19
|
-
|
19
|
+
Trestle.deprecator.warn("The well helper is deprecated and will be removed in future versions of Trestle. Please use the card helper instead.")
|
20
20
|
card(options, &block)
|
21
21
|
end
|
22
22
|
end
|
@@ -5,7 +5,9 @@ module Trestle
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def current_admin?(admin)
|
8
|
-
respond_to?(:admin) &&
|
8
|
+
respond_to?(:admin) &&
|
9
|
+
self.admin.respond_to?(:name) &&
|
10
|
+
self.admin.name == admin.name
|
9
11
|
end
|
10
12
|
|
11
13
|
def navigation_group_collapsed?(group)
|
@@ -16,7 +16,7 @@ module Trestle
|
|
16
16
|
|
17
17
|
def deprecated_toolbar(name)
|
18
18
|
if content_for?(:"#{name}_toolbar")
|
19
|
-
|
19
|
+
Trestle.deprecator.warn("Using content_for(:#{name}_toolbar) is deprecated. Please use toolbar(:#{name}) instead.")
|
20
20
|
content_for(:"#{name}_toolbar")
|
21
21
|
end
|
22
22
|
end
|
@@ -2,6 +2,6 @@
|
|
2
2
|
<%= render "trestle/flash/alert", html_class: "alert-success", icon: icon("alert-icon far fa-check-circle"), alert: normalize_flash_alert(flash[:message]) %>
|
3
3
|
<% elsif flash[:error] -%>
|
4
4
|
<%= render layout: "trestle/flash/alert", locals: { html_class: "alert-danger", icon: icon("alert-icon far fa-times-circle"), alert: normalize_flash_alert(flash[:error]) } do %>
|
5
|
-
<%= render "trestle/flash/debug", errors: instance.errors if debug_form_errors? %>
|
5
|
+
<%= render "trestle/flash/debug", errors: Trestle::DebugErrors.new(instance.errors) if debug_form_errors? %>
|
6
6
|
<% end %>
|
7
7
|
<% end -%>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<li>
|
9
9
|
<%= link_to persistent_params.merge(scope: (scope unless scope.active?(params))), class: ["scope", ("active" if scope.active?(params))] do %>
|
10
10
|
<strong><%= scope.label %></strong>
|
11
|
-
(<%= number_with_delimiter(scope.count(admin.collection(params))) %>)
|
11
|
+
<% if scope.count? %>(<%= number_with_delimiter(scope.count(admin.collection(params))) %>)<% end %>
|
12
12
|
<% end %>
|
13
13
|
</li>
|
14
14
|
<% end %>
|
data/config/locales/vi.yml
CHANGED
@@ -1,23 +1,5 @@
|
|
1
1
|
.btn-toolbar {
|
2
|
-
|
3
|
-
.btn-group,
|
4
|
-
.input-group {
|
5
|
-
+ .btn,
|
6
|
-
+ .btn-group,
|
7
|
-
+ .input-group {
|
8
|
-
margin-left: 5px;
|
9
|
-
}
|
10
|
-
}
|
11
|
-
|
12
|
-
.btn-group {
|
13
|
-
.btn,
|
14
|
-
.btn-group {
|
15
|
-
+ .btn,
|
16
|
-
+ .btn-group {
|
17
|
-
margin-left: 0;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
}
|
2
|
+
gap: 5px;
|
21
3
|
}
|
22
4
|
|
23
5
|
.primary-toolbar {
|
@@ -6,7 +6,7 @@ import { init } from '../core/events'
|
|
6
6
|
|
7
7
|
const TAB_SELECTOR = 'a[data-toggle="tab"]'
|
8
8
|
const TAB_PANE_SELECTOR = '.tab-pane'
|
9
|
-
const ERROR_SELECTOR = '.
|
9
|
+
const ERROR_SELECTOR = '.has-error'
|
10
10
|
|
11
11
|
// Save active tab to URL hash
|
12
12
|
init(function (root) {
|
@@ -10,8 +10,12 @@ module Trestle
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def create_assets
|
13
|
-
|
14
|
-
|
13
|
+
if defined?(Sass) || defined?(SassC)
|
14
|
+
template "_custom.scss", "app/assets/stylesheets/trestle/_custom.scss"
|
15
|
+
template "_theme.scss", "app/assets/stylesheets/trestle/_theme.scss"
|
16
|
+
else
|
17
|
+
template "_custom.css", "app/assets/stylesheets/trestle/_custom.css"
|
18
|
+
end
|
15
19
|
|
16
20
|
template "custom.js", "app/assets/javascripts/trestle/custom.js"
|
17
21
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/* This file may be used for providing additional customizations to the Trestle
|
2
|
+
* admin. It will be automatically included within all admin pages.
|
3
|
+
*
|
4
|
+
* For organizational purposes, you may wish to define your customizations
|
5
|
+
* within individual partials in this folder and they'll be required below.
|
6
|
+
*
|
7
|
+
*= require_tree .
|
8
|
+
*/
|
@@ -88,6 +88,13 @@ module Trestle
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
+
def remove_action(*actions)
|
92
|
+
actions.each do |action|
|
93
|
+
controller.remove_possible_method(action.to_sym)
|
94
|
+
@admin.actions.delete(action.to_sym)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
91
98
|
protected
|
92
99
|
def normalize_table_options(name, options)
|
93
100
|
if name.is_a?(Hash)
|
data/lib/trestle/admin.rb
CHANGED
@@ -2,8 +2,6 @@ module Trestle
|
|
2
2
|
class Admin
|
3
3
|
require_relative "admin/builder"
|
4
4
|
|
5
|
-
delegate :to_param, to: :class
|
6
|
-
|
7
5
|
def initialize(context=nil)
|
8
6
|
@context = context
|
9
7
|
end
|
@@ -52,13 +50,13 @@ module Trestle
|
|
52
50
|
end
|
53
51
|
|
54
52
|
def breadcrumbs
|
55
|
-
Breadcrumb::Trail.new(Array(Trestle.config.root_breadcrumbs) + [breadcrumb])
|
53
|
+
Breadcrumb::Trail.new(Array(Trestle.config.root_breadcrumbs) + [breadcrumb].compact)
|
56
54
|
end
|
57
55
|
|
58
56
|
def breadcrumb
|
59
57
|
if @breadcrumb
|
60
58
|
Breadcrumb.cast(@breadcrumb.call)
|
61
|
-
|
59
|
+
elsif actions.include?(:index)
|
62
60
|
default_breadcrumb
|
63
61
|
end
|
64
62
|
end
|
@@ -128,10 +126,14 @@ module Trestle
|
|
128
126
|
raise NoMethodError, "#to_param called on non-resourceful admin. You may need to explicitly specify the admin."
|
129
127
|
end
|
130
128
|
|
131
|
-
def
|
129
|
+
def default_actions
|
132
130
|
[:index]
|
133
131
|
end
|
134
132
|
|
133
|
+
def actions
|
134
|
+
@actions ||= default_actions.dup
|
135
|
+
end
|
136
|
+
|
135
137
|
def root_action
|
136
138
|
:index
|
137
139
|
end
|
@@ -145,7 +147,7 @@ module Trestle
|
|
145
147
|
|
146
148
|
Proc.new do
|
147
149
|
scope controller: admin.controller_namespace, path: admin.options[:path] || admin.admin_name do
|
148
|
-
get "", action: "index", as: admin.route_name
|
150
|
+
get "", action: "index", as: admin.route_name if admin.actions.include?(:index)
|
149
151
|
|
150
152
|
admin.additional_routes.each do |block|
|
151
153
|
instance_exec(&block)
|
@@ -176,5 +178,9 @@ module Trestle
|
|
176
178
|
end
|
177
179
|
end
|
178
180
|
end
|
181
|
+
|
182
|
+
# This delegate call is deferred until the class method is defined,
|
183
|
+
# since the method signature is different from Object#to_param.
|
184
|
+
delegate :to_param, to: :class
|
179
185
|
end
|
180
186
|
end
|
data/lib/trestle/configurable.rb
CHANGED
@@ -71,11 +71,11 @@ module Trestle
|
|
71
71
|
|
72
72
|
def deprecated_option(name, message=nil)
|
73
73
|
define_method("#{name}=") do |value|
|
74
|
-
|
74
|
+
Trestle.deprecator.warn(message)
|
75
75
|
end
|
76
76
|
|
77
77
|
define_method(name) do |*args|
|
78
|
-
|
78
|
+
Trestle.deprecator.warn(message)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Trestle
|
2
|
+
class DebugErrors
|
3
|
+
def initialize(errors)
|
4
|
+
@errors = errors
|
5
|
+
end
|
6
|
+
|
7
|
+
def any?
|
8
|
+
@errors.any?
|
9
|
+
end
|
10
|
+
|
11
|
+
def each
|
12
|
+
if defined?(ActiveModel::Error)
|
13
|
+
# Rails 6.1 introduces a unified Error class
|
14
|
+
@errors.each do |error|
|
15
|
+
yield error.attribute, error.message
|
16
|
+
end
|
17
|
+
else
|
18
|
+
@errors.each do |error, message|
|
19
|
+
yield error, message
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -31,7 +31,9 @@ module Trestle
|
|
31
31
|
when :datetime
|
32
32
|
datetime_field attribute.name
|
33
33
|
when :boolean
|
34
|
-
|
34
|
+
form_group label: false do
|
35
|
+
check_box attribute.name
|
36
|
+
end
|
35
37
|
when :enum
|
36
38
|
collection_radio_buttons attribute.name, attribute.options[:values] || [], :first, :last
|
37
39
|
when :json, :jsonb
|
data/lib/trestle/hook/helpers.rb
CHANGED
@@ -4,7 +4,7 @@ module Trestle
|
|
4
4
|
attr_reader :name, :path, :options
|
5
5
|
|
6
6
|
def initialize(name, path=nil, options={})
|
7
|
-
@name, @path, @options = name, path, options
|
7
|
+
@name, @path, @options = name.to_s, path, options
|
8
8
|
end
|
9
9
|
|
10
10
|
def ==(other)
|
@@ -40,7 +40,7 @@ module Trestle
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def label
|
43
|
-
options[:label] || I18n.t("admin.navigation.items.#{name}", default: name.
|
43
|
+
options[:label] || I18n.t("admin.navigation.items.#{name}", default: name.titlecase)
|
44
44
|
end
|
45
45
|
|
46
46
|
def icon
|
data/lib/trestle/reloader.rb
CHANGED
@@ -38,17 +38,8 @@ module Trestle
|
|
38
38
|
|
39
39
|
app.reloaders << reloader
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
app.reloader.to_run do
|
44
|
-
reloader.execute_if_updated
|
45
|
-
true # Rails <= 5.1
|
46
|
-
end
|
47
|
-
else
|
48
|
-
# Rails 4.2
|
49
|
-
ActionDispatch::Reloader.to_prepare do
|
50
|
-
reloader.execute_if_updated
|
51
|
-
end
|
41
|
+
app.reloader.to_run do
|
42
|
+
reloader.execute_if_updated
|
52
43
|
end
|
53
44
|
|
54
45
|
reloader.execute
|
@@ -14,13 +14,6 @@ module Trestle
|
|
14
14
|
admin.adapter_class = adapter
|
15
15
|
end
|
16
16
|
|
17
|
-
def remove_action(*actions)
|
18
|
-
actions.each do |action|
|
19
|
-
controller.remove_possible_method(action.to_sym)
|
20
|
-
admin.actions.delete(action.to_sym)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
17
|
def collection(&block)
|
25
18
|
admin.define_adapter_method(:collection, &block)
|
26
19
|
end
|
@@ -85,7 +78,7 @@ module Trestle
|
|
85
78
|
|
86
79
|
def scopes(options={}, &block)
|
87
80
|
admin.scopes.options.merge!(options)
|
88
|
-
admin.scopes.append(&block) if block_given?
|
81
|
+
admin.scopes.append(options, &block) if block_given?
|
89
82
|
end
|
90
83
|
|
91
84
|
def scope(name, scope=nil, options={}, &block)
|
data/lib/trestle/resource.rb
CHANGED
data/lib/trestle/scopes/block.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
module Trestle
|
2
2
|
class Scopes
|
3
3
|
class Block
|
4
|
-
attr_reader :block
|
4
|
+
attr_reader :block, :options
|
5
5
|
|
6
|
-
def initialize(&block)
|
7
|
-
@block = block
|
6
|
+
def initialize(options={}, &block)
|
7
|
+
@options, @block = options, block
|
8
8
|
end
|
9
9
|
|
10
10
|
# Evaluates the scope block within the given admin context
|
11
11
|
# and returns an array of the scopes that were defined.
|
12
12
|
def scopes(context)
|
13
|
-
context = Evaluator.new(context)
|
13
|
+
context = Evaluator.new(context, options)
|
14
14
|
context.instance_exec(context, &block)
|
15
15
|
context.scopes
|
16
16
|
end
|
@@ -20,8 +20,8 @@ module Trestle
|
|
20
20
|
|
21
21
|
attr_reader :scopes
|
22
22
|
|
23
|
-
def initialize(context=nil)
|
24
|
-
@context = context
|
23
|
+
def initialize(context=nil, defaults={})
|
24
|
+
@context, @defaults = context, defaults
|
25
25
|
@scopes = []
|
26
26
|
end
|
27
27
|
|
@@ -31,7 +31,7 @@ module Trestle
|
|
31
31
|
scope = nil
|
32
32
|
end
|
33
33
|
|
34
|
-
scopes << Scope.new(@context, name, options, &(scope || block))
|
34
|
+
scopes << Scope.new(@context, name, @defaults.merge(options), &(scope || block))
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/trestle/scopes/scope.rb
CHANGED
data/lib/trestle/version.rb
CHANGED
data/lib/trestle.rb
CHANGED
@@ -11,6 +11,7 @@ module Trestle
|
|
11
11
|
require_relative "trestle/adapters"
|
12
12
|
require_relative "trestle/attribute"
|
13
13
|
require_relative "trestle/breadcrumb"
|
14
|
+
require_relative "trestle/debug_errors"
|
14
15
|
require_relative "trestle/lazy"
|
15
16
|
require_relative "trestle/configurable"
|
16
17
|
require_relative "trestle/configuration"
|
@@ -84,6 +85,10 @@ module Trestle
|
|
84
85
|
[locale]
|
85
86
|
end
|
86
87
|
end
|
88
|
+
|
89
|
+
def self.deprecator
|
90
|
+
@deprecator ||= ActiveSupport::Deprecation.new
|
91
|
+
end
|
87
92
|
end
|
88
93
|
|
89
94
|
require_relative "trestle/engine" if defined?(Rails)
|
data/package.json
CHANGED
@@ -22,9 +22,9 @@
|
|
22
22
|
"css-minimizer-webpack-plugin": "^3.0.2",
|
23
23
|
"expose-loader": "^3.0.0",
|
24
24
|
"mini-css-extract-plugin": "^2.0.0",
|
25
|
-
"node-sass": "^7.0.1",
|
26
25
|
"postcss": "^8.3.5",
|
27
26
|
"postcss-loader": "^6.1.1",
|
27
|
+
"sass": "^1.76.0",
|
28
28
|
"sass-loader": "^12.1.0",
|
29
29
|
"webpack": "^5.42.0",
|
30
30
|
"webpack-cli": "^4.7.2"
|
data/trestle.gemspec
CHANGED
@@ -20,18 +20,18 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = ">= 2.2.2"
|
22
22
|
|
23
|
-
spec.add_dependency "railties", ">=
|
24
|
-
spec.add_dependency "activemodel", ">=
|
23
|
+
spec.add_dependency "railties", ">= 5.2.0"
|
24
|
+
spec.add_dependency "activemodel", ">= 5.2.0"
|
25
25
|
spec.add_dependency "sprockets-rails", ">= 2.0.0"
|
26
26
|
spec.add_dependency "kaminari", ">= 1.1.0"
|
27
27
|
|
28
|
-
spec.add_development_dependency "rspec-rails", "
|
29
|
-
spec.add_development_dependency "rspec-html-matchers", "~> 0.
|
30
|
-
spec.add_development_dependency "database_cleaner", "~>
|
31
|
-
spec.add_development_dependency "ammeter", "~> 1.1.
|
28
|
+
spec.add_development_dependency "rspec-rails", ">= 5.1.2"
|
29
|
+
spec.add_development_dependency "rspec-html-matchers", "~> 0.10.0"
|
30
|
+
spec.add_development_dependency "database_cleaner", "~> 2.0.2"
|
31
|
+
spec.add_development_dependency "ammeter", "~> 1.1.5"
|
32
32
|
|
33
33
|
spec.add_development_dependency "bundler"
|
34
34
|
spec.add_development_dependency "rake"
|
35
|
-
spec.add_development_dependency "sqlite3"
|
35
|
+
spec.add_development_dependency "sqlite3"
|
36
36
|
spec.add_development_dependency "turbolinks"
|
37
37
|
end
|