trestle 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/bundle/trestle/bundle.css +0 -0
- data/app/assets/bundle/trestle/bundle.js +0 -0
- data/app/assets/javascripts/trestle/admin.js +1 -0
- data/app/assets/javascripts/trestle/i18n.js.erb +8 -0
- data/app/helpers/trestle/grid_helper.rb +44 -4
- data/app/helpers/trestle/i18n_helper.rb +8 -15
- data/app/helpers/trestle/table_helper.rb +7 -3
- data/app/helpers/trestle/title_helper.rb +11 -0
- data/app/helpers/trestle/toolbars_helper.rb +0 -11
- data/app/views/layouts/trestle/admin.html.erb +4 -4
- data/app/views/trestle/application/_dialog.html.erb +1 -1
- data/app/views/trestle/application/_header.html.erb +1 -3
- data/app/views/trestle/resource/edit.html.erb +2 -2
- data/app/views/trestle/resource/index.html.erb +1 -1
- data/app/views/trestle/resource/new.html.erb +1 -1
- data/app/views/trestle/resource/show.html.erb +2 -2
- data/app/views/trestle/shared/_sidebar.html.erb +1 -1
- data/config/locales/de.rb +18 -0
- data/config/locales/de.yml +101 -0
- data/frontend/js/components/tabs.js +2 -2
- data/lib/generators/trestle/resource/resource_generator.rb +15 -1
- data/lib/generators/trestle/resource/templates/admin.rb.erb +15 -8
- data/lib/trestle.rb +13 -0
- data/lib/trestle/adapters/active_record_adapter.rb +1 -1
- data/lib/trestle/admin.rb +5 -2
- data/lib/trestle/admin/builder.rb +5 -1
- data/lib/trestle/admin/controller.rb +8 -1
- data/lib/trestle/application_controller.rb +2 -0
- data/lib/trestle/configuration.rb +1 -1
- data/lib/trestle/controller/breadcrumbs.rb +1 -1
- data/lib/trestle/controller/title.rb +20 -0
- data/lib/trestle/controller/toolbars.rb +30 -0
- data/lib/trestle/form/automatic.rb +2 -2
- data/lib/trestle/form/field.rb +12 -2
- data/lib/trestle/form/fields/check_box_helpers.rb +1 -1
- data/lib/trestle/form/fields/collection_select.rb +1 -1
- data/lib/trestle/form/fields/date_select.rb +1 -1
- data/lib/trestle/form/fields/datetime_select.rb +1 -1
- data/lib/trestle/form/fields/select.rb +1 -1
- data/lib/trestle/form/fields/static_field.rb +5 -1
- data/lib/trestle/form/fields/tag_select.rb +1 -1
- data/lib/trestle/form/fields/time_select.rb +1 -1
- data/lib/trestle/form/fields/time_zone_select.rb +1 -1
- data/lib/trestle/navigation/item.rb +4 -0
- data/lib/trestle/resource.rb +1 -0
- data/lib/trestle/resource/controller.rb +9 -166
- data/lib/trestle/resource/controller/actions.rb +133 -0
- data/lib/trestle/resource/controller/data_methods.rb +52 -0
- data/lib/trestle/resource/controller/redirection.rb +23 -0
- data/lib/trestle/resource/controller/toolbar.rb +11 -0
- data/lib/trestle/resource/toolbar.rb +29 -0
- data/lib/trestle/table.rb +6 -0
- data/lib/trestle/version.rb +1 -1
- data/trestle.gemspec +1 -0
- data/yarn.lock +518 -496
- metadata +27 -2
data/lib/trestle.rb
CHANGED
@@ -37,6 +37,8 @@ module Trestle
|
|
37
37
|
autoload :Helpers
|
38
38
|
autoload :Layout
|
39
39
|
autoload :Location
|
40
|
+
autoload :Title
|
41
|
+
autoload :Toolbars
|
40
42
|
end
|
41
43
|
|
42
44
|
mattr_accessor :admins
|
@@ -71,6 +73,17 @@ module Trestle
|
|
71
73
|
blocks = config.menus + admins.values.map(&:menu).compact
|
72
74
|
Navigation.build(blocks, context)
|
73
75
|
end
|
76
|
+
|
77
|
+
def self.i18n_fallbacks(locale=I18n.locale)
|
78
|
+
if I18n.respond_to?(:fallbacks)
|
79
|
+
I18n.fallbacks[locale]
|
80
|
+
elsif locale.to_s.include?("-")
|
81
|
+
fallback = locale.to_s.split("-").first
|
82
|
+
[locale, fallback]
|
83
|
+
else
|
84
|
+
[locale]
|
85
|
+
end
|
86
|
+
end
|
74
87
|
end
|
75
88
|
|
76
89
|
require "trestle/engine" if defined?(Rails)
|
data/lib/trestle/admin.rb
CHANGED
@@ -67,7 +67,10 @@ module Trestle
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def default_breadcrumb
|
70
|
-
|
70
|
+
deprecated = I18n.t(:"admin.breadcrumbs.#{i18n_key}", default: human_admin_name)
|
71
|
+
label = translate("breadcrumbs.index", default: deprecated)
|
72
|
+
|
73
|
+
Breadcrumb.new(label, path)
|
71
74
|
end
|
72
75
|
|
73
76
|
def admin_name
|
@@ -79,7 +82,7 @@ module Trestle
|
|
79
82
|
end
|
80
83
|
|
81
84
|
def human_admin_name
|
82
|
-
|
85
|
+
translate("name", default: default_human_admin_name)
|
83
86
|
end
|
84
87
|
|
85
88
|
def default_human_admin_name
|
@@ -53,7 +53,11 @@ module Trestle
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def form(options={}, &block)
|
56
|
-
|
56
|
+
if block_given?
|
57
|
+
admin.form = Form.new(options, &block)
|
58
|
+
else
|
59
|
+
admin.form = Form::Automatic.new(admin, options)
|
60
|
+
end
|
57
61
|
end
|
58
62
|
|
59
63
|
def hook(name, options={}, &block)
|
@@ -21,7 +21,14 @@ module Trestle
|
|
21
21
|
|
22
22
|
protected
|
23
23
|
def breadcrumbs
|
24
|
-
@
|
24
|
+
@_breadcrumbs ||= admin.breadcrumbs.dup
|
25
|
+
end
|
26
|
+
|
27
|
+
def flash_message(type, title:, message:)
|
28
|
+
{
|
29
|
+
title: admin.t("flash.#{type}.title", default: title),
|
30
|
+
message: admin.t("flash.#{type}.message", default: message)
|
31
|
+
}
|
25
32
|
end
|
26
33
|
end
|
27
34
|
end
|
@@ -41,7 +41,7 @@ module Trestle
|
|
41
41
|
option :root, -> { Trestle.config.path }
|
42
42
|
|
43
43
|
# Initial breadcrumbs to display in the breadcrumb trail
|
44
|
-
option :root_breadcrumbs, -> { [Trestle::Breadcrumb.new(I18n.t("admin.breadcrumbs.home", default: "Home"), Trestle.config.root)] }
|
44
|
+
option :root_breadcrumbs, -> { [Trestle::Breadcrumb.new(I18n.t(:"admin.breadcrumbs.home", default: "Home"), Trestle.config.root)] }
|
45
45
|
|
46
46
|
# Default icon class to use when it is not explicitly provided
|
47
47
|
option :default_navigation_icon, "fa fa-arrow-circle-o-right"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Trestle
|
2
|
+
module Controller
|
3
|
+
module Title
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
helper_method :default_title
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
def title(title=nil)
|
12
|
+
@_title = title if title
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_title
|
16
|
+
@_title || action_name.titleize
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Trestle
|
2
|
+
module Controller
|
3
|
+
module Toolbars
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
helper_method :toolbars
|
8
|
+
helper_method :toolbar
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def toolbars
|
13
|
+
@_toolbars ||= {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def toolbar(name, options={}, &block)
|
17
|
+
builder = options[:builder] || default_toolbar_builder
|
18
|
+
|
19
|
+
toolbar = (toolbars[name.to_s] ||= Toolbar.new(builder))
|
20
|
+
toolbar.clear! if options[:clear]
|
21
|
+
toolbar.prepend(&block) if block_given?
|
22
|
+
toolbar
|
23
|
+
end
|
24
|
+
|
25
|
+
def default_toolbar_builder
|
26
|
+
Toolbar::Builder
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Trestle
|
2
2
|
class Form
|
3
3
|
class Automatic < Form
|
4
|
-
def initialize(admin)
|
5
|
-
super() do |instance|
|
4
|
+
def initialize(admin, options={})
|
5
|
+
super(options) do |instance|
|
6
6
|
admin.default_form_attributes.each do |attribute|
|
7
7
|
if attribute.array?
|
8
8
|
if [:string, :text].include?(attribute.type)
|
data/lib/trestle/form/field.rb
CHANGED
@@ -7,8 +7,8 @@ module Trestle
|
|
7
7
|
|
8
8
|
def initialize(builder, template, name, options={}, &block)
|
9
9
|
@builder, @template, @name, @block = builder, template, name, block
|
10
|
-
@options = defaults.merge(options)
|
11
10
|
|
11
|
+
assign_options!(options)
|
12
12
|
normalize_options!
|
13
13
|
end
|
14
14
|
|
@@ -39,7 +39,11 @@ module Trestle
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def defaults
|
42
|
-
Trestle::Options.new(readonly:
|
42
|
+
Trestle::Options.new(readonly: readonly?)
|
43
|
+
end
|
44
|
+
|
45
|
+
def readonly?
|
46
|
+
options[:readonly] || admin.readonly?
|
43
47
|
end
|
44
48
|
|
45
49
|
def normalize_options!
|
@@ -48,6 +52,12 @@ module Trestle
|
|
48
52
|
end
|
49
53
|
|
50
54
|
protected
|
55
|
+
def assign_options!(options)
|
56
|
+
# Assign @options first so that it can be referenced from within #defaults if required
|
57
|
+
@options = Trestle::Options.new(options)
|
58
|
+
@options = defaults.merge(options)
|
59
|
+
end
|
60
|
+
|
51
61
|
def extract_wrapper_options!
|
52
62
|
unless options[:wrapper] == false
|
53
63
|
@wrapper = extract_wrapper_options(*Fields::FormGroup::WRAPPER_OPTIONS).merge(options.delete(:wrapper))
|
@@ -16,7 +16,7 @@ module Trestle
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def default_html_options
|
19
|
-
Trestle::Options.new(class: ["form-control"], disabled:
|
19
|
+
Trestle::Options.new(class: ["form-control"], disabled: readonly?, data: { enable_select2: true })
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -17,7 +17,7 @@ module Trestle
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def default_html_options
|
20
|
-
Trestle::Options.new(class: ["form-control"], disabled:
|
20
|
+
Trestle::Options.new(class: ["form-control"], disabled: readonly?, data: { enable_select2: true })
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -17,7 +17,7 @@ module Trestle
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def default_html_options
|
20
|
-
Trestle::Options.new(class: ["form-control"], disabled:
|
20
|
+
Trestle::Options.new(class: ["form-control"], disabled: readonly?, data: { enable_select2: true })
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -18,7 +18,7 @@ module Trestle
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def default_html_options
|
21
|
-
Trestle::Options.new(class: ["form-control"], disabled:
|
21
|
+
Trestle::Options.new(class: ["form-control"], disabled: readonly?, data: { enable_select2: true })
|
22
22
|
end
|
23
23
|
|
24
24
|
def default_choices
|
@@ -18,9 +18,13 @@ module Trestle
|
|
18
18
|
if block
|
19
19
|
template.capture(&block)
|
20
20
|
else
|
21
|
-
content_tag(:p, value, class: "form-control-static")
|
21
|
+
content_tag(:p, value || default_value, class: "form-control-static")
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
def default_value
|
26
|
+
builder.object.send(name) if builder.object
|
27
|
+
end
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
@@ -7,7 +7,7 @@ module Trestle
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def default_html_options
|
10
|
-
super.merge(multiple: true, class: "tag-select", disabled:
|
10
|
+
super.merge(multiple: true, class: "tag-select", disabled: readonly?, data: { tags: true })
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -17,7 +17,7 @@ module Trestle
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def default_html_options
|
20
|
-
Trestle::Options.new(class: ["form-control"], disabled:
|
20
|
+
Trestle::Options.new(class: ["form-control"], disabled: readonly?, data: { enable_select2: true })
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -16,7 +16,7 @@ module Trestle
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def default_html_options
|
19
|
-
Trestle::Options.new(class: ["form-control"], disabled:
|
19
|
+
Trestle::Options.new(class: ["form-control"], disabled: readonly?, data: { enable_select2: true })
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -55,6 +55,10 @@ module Trestle
|
|
55
55
|
Badge.new(options[:badge]) if badge?
|
56
56
|
end
|
57
57
|
|
58
|
+
def html_options
|
59
|
+
options.except(:admin, :badge, :group, :icon, :if, :label, :priority, :unless)
|
60
|
+
end
|
61
|
+
|
58
62
|
def visible?(context)
|
59
63
|
if options[:if]
|
60
64
|
context.instance_exec(&options[:if])
|
data/lib/trestle/resource.rb
CHANGED
@@ -1,174 +1,17 @@
|
|
1
1
|
module Trestle
|
2
2
|
class Resource
|
3
3
|
class Controller < Admin::Controller
|
4
|
-
|
5
|
-
before_action :load_instance, only: [:show, :edit, :update, :destroy]
|
4
|
+
extend ActiveSupport::Autoload
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
autoload :Actions
|
7
|
+
autoload :DataMethods
|
8
|
+
autoload :Redirection
|
9
|
+
autoload :Toolbar
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def new
|
17
|
-
self.instance = admin.build_instance(params.key?(admin.parameter_name) ? admin.permitted_params(params) : {}, params)
|
18
|
-
|
19
|
-
respond_to do |format|
|
20
|
-
format.html
|
21
|
-
format.json { render json: instance }
|
22
|
-
|
23
|
-
yield format if block_given?
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def create
|
28
|
-
self.instance = admin.build_instance(admin.permitted_params(params), params)
|
29
|
-
|
30
|
-
if admin.save_instance(instance, params)
|
31
|
-
respond_to do |format|
|
32
|
-
format.html do
|
33
|
-
flash[:message] = flash_message("create.success", title: "Success!", message: "The %{lowercase_model_name} was successfully created.")
|
34
|
-
redirect_to_return_location(:create, instance, default: admin.instance_path(instance))
|
35
|
-
end
|
36
|
-
format.json { render json: instance, status: :created, location: admin.instance_path(instance) }
|
37
|
-
|
38
|
-
yield format if block_given?
|
39
|
-
end
|
40
|
-
else
|
41
|
-
respond_to do |format|
|
42
|
-
format.html do
|
43
|
-
flash.now[:error] = flash_message("create.failure", title: "Warning!", message: "Please correct the errors below.")
|
44
|
-
render "new", status: :unprocessable_entity
|
45
|
-
end
|
46
|
-
format.json { render json: instance.errors, status: :unprocessable_entity }
|
47
|
-
|
48
|
-
yield format if block_given?
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def show
|
54
|
-
if admin.singular? && instance.nil?
|
55
|
-
respond_to do |format|
|
56
|
-
format.html { redirect_to action: :new }
|
57
|
-
format.json { head :not_found }
|
58
|
-
|
59
|
-
yield format if block_given?
|
60
|
-
end
|
61
|
-
else
|
62
|
-
respond_to do |format|
|
63
|
-
format.html
|
64
|
-
format.json { render json: instance }
|
65
|
-
|
66
|
-
yield format if block_given?
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def edit
|
72
|
-
if admin.singular? && instance.nil?
|
73
|
-
respond_to do |format|
|
74
|
-
format.html { redirect_to action: :new }
|
75
|
-
format.json { head :not_found }
|
76
|
-
|
77
|
-
yield format if block_given?
|
78
|
-
end
|
79
|
-
else
|
80
|
-
respond_to do |format|
|
81
|
-
format.html
|
82
|
-
format.json { render json: instance }
|
83
|
-
|
84
|
-
yield format if block_given?
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def update
|
90
|
-
admin.update_instance(instance, admin.permitted_params(params), params)
|
91
|
-
|
92
|
-
if admin.save_instance(instance, params)
|
93
|
-
respond_to do |format|
|
94
|
-
format.html do
|
95
|
-
flash[:message] = flash_message("update.success", title: "Success!", message: "The %{lowercase_model_name} was successfully updated.")
|
96
|
-
redirect_to_return_location(:update, instance, default: admin.instance_path(instance))
|
97
|
-
end
|
98
|
-
format.json { render json: instance, status: :ok }
|
99
|
-
|
100
|
-
yield format if block_given?
|
101
|
-
end
|
102
|
-
else
|
103
|
-
respond_to do |format|
|
104
|
-
format.html do
|
105
|
-
flash.now[:error] = flash_message("update.failure", title: "Warning!", message: "Please correct the errors below.")
|
106
|
-
render "show", status: :unprocessable_entity
|
107
|
-
end
|
108
|
-
format.json { render json: instance.errors, status: :unprocessable_entity }
|
109
|
-
|
110
|
-
yield format if block_given?
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def destroy
|
116
|
-
success = admin.delete_instance(instance, params)
|
117
|
-
|
118
|
-
respond_to do |format|
|
119
|
-
format.html do
|
120
|
-
if success
|
121
|
-
flash[:message] = flash_message("destroy.success", title: "Success!", message: "The %{lowercase_model_name} was successfully deleted.")
|
122
|
-
redirect_to_return_location(:destroy, instance, default: admin.path(:index))
|
123
|
-
else
|
124
|
-
flash[:error] = flash_message("destroy.failure", title: "Warning!", message: "Could not delete %{lowercase_model_name}.")
|
125
|
-
|
126
|
-
if self.instance = admin.find_instance(params)
|
127
|
-
redirect_to_return_location(:update, instance, default: admin.instance_path(instance))
|
128
|
-
else
|
129
|
-
redirect_to_return_location(:destroy, instance, default: admin.path(:index))
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
format.json { head :no_content }
|
134
|
-
|
135
|
-
yield format if block_given?
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
protected
|
140
|
-
def load_instance
|
141
|
-
self.instance = admin.find_instance(params)
|
142
|
-
end
|
143
|
-
|
144
|
-
def load_collection
|
145
|
-
self.collection = admin.prepare_collection(params)
|
146
|
-
end
|
147
|
-
|
148
|
-
attr_accessor :instance, :collection
|
149
|
-
helper_method :instance, :collection
|
150
|
-
|
151
|
-
def flash_message(type, title:, message:)
|
152
|
-
{
|
153
|
-
title: admin.t("flash.#{type}.title", default: title),
|
154
|
-
message: admin.t("flash.#{type}.message", default: message)
|
155
|
-
}
|
156
|
-
end
|
157
|
-
|
158
|
-
def redirect_to_return_location(action, instance, default:)
|
159
|
-
if admin.return_locations[action] && !dialog_request?
|
160
|
-
location = instance_exec(instance, &admin.return_locations[action])
|
161
|
-
|
162
|
-
case location
|
163
|
-
when :back
|
164
|
-
redirect_back fallback_location: default, turbolinks: false
|
165
|
-
else
|
166
|
-
redirect_to location, turbolinks: false
|
167
|
-
end
|
168
|
-
else
|
169
|
-
redirect_to default, turbolinks: false
|
170
|
-
end
|
171
|
-
end
|
11
|
+
include Actions
|
12
|
+
include DataMethods
|
13
|
+
include Redirection
|
14
|
+
include Toolbar
|
172
15
|
end
|
173
16
|
end
|
174
17
|
end
|