five-two-nw-olivander 0.2.0.33 → 0.2.0.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/components/olivander/components/resource_form_component.html.haml +5 -4
- data/app/components/olivander/components/resource_form_component.rb +8 -7
- data/app/helpers/olivander/application_helper.rb +53 -37
- data/lib/o18n.rb +6 -6
- data/lib/olivander/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20a2a1f0d91b619aa91cb6e5670939246a5471a40a1fdcc772934f11de447c7c
|
4
|
+
data.tar.gz: 010f45ad72e71c350fbbcf73385fe2b39b47458e613a7da714dfd9dd378a367d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7175c69a12f98b0b31e6525b87b8e51a2fe9a8c3a02b577617acfc741b184edcdd1323d896fe5317278a238ae71c97905e4f0a49270efdfa6ce837f6acd4ed14
|
7
|
+
data.tar.gz: 2fb042867661f164131bcdd36ebc74e8f7ed62e2711b20b2b0ee9f5c1290f85db9947ca8f745ca1cf1d3048bb4b901418c15337b014f9ce80564a8bd66a574af
|
@@ -4,14 +4,15 @@
|
|
4
4
|
- rfg.sections.each do |section|
|
5
5
|
.row
|
6
6
|
- section.fields.each do |field|
|
7
|
+
- label = field_label_for(@resource.class, field.sym)
|
7
8
|
%div{ class: section.column_class }
|
8
9
|
- if association?(field)
|
9
10
|
- collection = collection_for(field)
|
10
11
|
- if one_through?(field)
|
11
|
-
= @f.input field.sym, collection: [collection].flatten, disabled: !field.editable, input_html: { data: association_data_hash_for(field) }, selected: collection
|
12
|
+
= @f.input field.sym, label: label, collection: [collection].flatten, disabled: !field.editable, input_html: { data: association_data_hash_for(field) }, selected: collection
|
12
13
|
- else
|
13
|
-
= @f.association field.sym, collection: [collection].flatten, disabled: !field.editable, input_html: { data: association_data_hash_for(field) }
|
14
|
+
= @f.association field.sym, label: label, collection: [collection].flatten, disabled: !field.editable, input_html: { data: association_data_hash_for(field) }
|
14
15
|
- elsif boolean?(field)
|
15
|
-
= @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, input_html: { data: input_data_hash_for(field) }
|
16
|
+
= @f.input field.sym, label: label, disabled: !field.editable, as: field.type.to_sym, input_html: { data: input_data_hash_for(field) }
|
16
17
|
- else
|
17
|
-
= @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, picker_options: input_picker_options_for(field), input_html: { rows: 10, data: input_data_hash_for(field) }
|
18
|
+
= @f.input field.sym, label: label, disabled: !field.editable, as: field.type.to_sym, picker_options: input_picker_options_for(field), input_html: { rows: 10, data: input_data_hash_for(field) }
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
class Olivander::Components::ResourceFormComponent < ViewComponent::Base
|
4
4
|
delegate :resource_field_group_label, to: :helpers
|
5
|
+
delegate :field_label_for, to: :helpers
|
5
6
|
|
6
7
|
def initialize(resource, form_builder)
|
7
8
|
@resource = resource
|
@@ -16,7 +17,8 @@ class Olivander::Components::ResourceFormComponent < ViewComponent::Base
|
|
16
17
|
def association_data_hash_for(field)
|
17
18
|
{
|
18
19
|
collection_path: collection_path_for(field),
|
19
|
-
controller: "association-#{@resource.class.name.underscore.dasherize.gsub('/',
|
20
|
+
controller: "association-#{@resource.class.name.underscore.dasherize.gsub('/',
|
21
|
+
'-')}-#{field.sym} input-control-association",
|
20
22
|
taggable: taggable?(field),
|
21
23
|
tag_field_name: tag_field_name(field)
|
22
24
|
}
|
@@ -24,7 +26,8 @@ class Olivander::Components::ResourceFormComponent < ViewComponent::Base
|
|
24
26
|
|
25
27
|
def input_data_hash_for(field)
|
26
28
|
{
|
27
|
-
controller: "input-#{@resource.class.name.underscore.dasherize.gsub('/',
|
29
|
+
controller: "input-#{@resource.class.name.underscore.dasherize.gsub('/',
|
30
|
+
'-')}-#{field.sym} input-control-#{field.type}"
|
28
31
|
}
|
29
32
|
end
|
30
33
|
|
@@ -53,11 +56,9 @@ class Olivander::Components::ResourceFormComponent < ViewComponent::Base
|
|
53
56
|
end
|
54
57
|
|
55
58
|
def collection_path_for(field)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
''
|
60
|
-
end
|
59
|
+
polymorphic_path(@resource.class.reflect_on_association(field.sym).klass, format: :json)
|
60
|
+
rescue StandardError
|
61
|
+
''
|
61
62
|
end
|
62
63
|
|
63
64
|
def association?(field)
|
@@ -2,15 +2,16 @@ module Olivander
|
|
2
2
|
module ApplicationHelper
|
3
3
|
def chart_column_class_num(label, count, min)
|
4
4
|
return "col-#{label}-#{min}" if count >= 12
|
5
|
+
|
5
6
|
modded = count % 12
|
6
7
|
divisor = modded.zero? ? 1 : modded
|
7
|
-
"col-#{label}-#{[12/divisor, min].max}"
|
8
|
-
|
8
|
+
"col-#{label}-#{[12 / divisor, min].max}"
|
9
|
+
|
9
10
|
divisor = count
|
10
|
-
result = 12/divisor
|
11
|
+
result = 12 / divisor
|
11
12
|
while result < min
|
12
|
-
divisor
|
13
|
-
result = 12/divisor
|
13
|
+
divisor /= 2
|
14
|
+
result = 12 / divisor
|
14
15
|
end
|
15
16
|
"col-#{label}-#{result}"
|
16
17
|
end
|
@@ -35,21 +36,21 @@ module Olivander
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def authorized_resource_actions(resource, for_action: :show)
|
38
|
-
|
39
|
+
action_klass = action_klass_for(resource)
|
40
|
+
action_resource = action_resource_for(resource)
|
41
|
+
raw_name = action_klass.name
|
39
42
|
plural_name = raw_name.demodulize.underscore.pluralize
|
40
43
|
routed_resource = Olivander::CurrentContext.application_context.route_builder.resources[plural_name.to_sym]
|
41
44
|
return [] if routed_resource.nil?
|
42
45
|
|
43
46
|
actions = if resource.is_a?(Class)
|
44
47
|
routed_resource.unpersisted_crud_actions | routed_resource.collection_actions.reject(&:crud_action)
|
48
|
+
elsif resource.persisted?
|
49
|
+
routed_resource.persisted_crud_actions | routed_resource.member_actions.reject(&:crud_action)
|
45
50
|
else
|
46
|
-
|
47
|
-
routed_resource.persisted_crud_actions | routed_resource.member_actions.reject(&:crud_action)
|
48
|
-
else
|
49
|
-
[]
|
50
|
-
end
|
51
|
+
[]
|
51
52
|
end
|
52
|
-
actions = actions.select{ |a| authorized_resource_action?(a.sym,
|
53
|
+
actions = actions.select { |a| authorized_resource_action?(a.sym, action_resource, for_action) }
|
53
54
|
preferred = %i[show edit destroy]
|
54
55
|
[].tap do |arr|
|
55
56
|
preferred.each do |p|
|
@@ -57,12 +58,21 @@ module Olivander
|
|
57
58
|
arr << a if a.sym == p
|
58
59
|
end
|
59
60
|
end
|
60
|
-
actions.reject{ |x| preferred.include?(x.sym) }.each do |a|
|
61
|
+
actions.reject { |x| preferred.include?(x.sym) }.each do |a|
|
61
62
|
arr << a
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
67
|
+
def action_klass_for(resource)
|
68
|
+
klazz = resource.is_a?(Class) ? resource : resource.class
|
69
|
+
klazz.respond_to?(:action_klass) ? klazz.action_klass : klazz
|
70
|
+
end
|
71
|
+
|
72
|
+
def action_resource_for(resource)
|
73
|
+
resource.respond_to?(:action_resource) ? resource.action_resource : resource
|
74
|
+
end
|
75
|
+
|
66
76
|
def authorized_resource_action?(action, resource, except = nil)
|
67
77
|
return false if action == except
|
68
78
|
|
@@ -70,12 +80,15 @@ module Olivander
|
|
70
80
|
end
|
71
81
|
|
72
82
|
def resource_form_actions(resource, for_action: :show)
|
73
|
-
render partial: 'resource_form_actions',
|
83
|
+
render partial: 'resource_form_actions',
|
84
|
+
locals: { actions: authorized_resource_actions(resource, for_action: for_action).select(&:show_in_form) }
|
74
85
|
end
|
75
86
|
|
76
87
|
def resource_form_action_tooltip(resource, action)
|
77
88
|
key = resource.class.name.underscore
|
78
|
-
|
89
|
+
if I18n.exists?("activerecord.actions.#{key}.#{action}-tooltip")
|
90
|
+
return O18n.t("activerecord.actions.#{key}.#{action}-tooltip")
|
91
|
+
end
|
79
92
|
return O18n.t("activerecord.actions.#{action}-tooltip") if I18n.exists?("activerecord.actions.#{action}-tooltip")
|
80
93
|
|
81
94
|
action.to_s.titleize
|
@@ -91,7 +104,9 @@ module Olivander
|
|
91
104
|
|
92
105
|
def resource_form_action_icon(resource, action)
|
93
106
|
key = resource.class.name.underscore
|
94
|
-
|
107
|
+
if I18n.exists?("activerecord.actions.#{key}.#{action}-icon")
|
108
|
+
return O18n.t("activerecord.actions.#{key}.#{action}-icon")
|
109
|
+
end
|
95
110
|
return O18n.t("activerecord.actions.#{action}-icon") if I18n.exists?("activerecord.actions.#{action}-icon")
|
96
111
|
|
97
112
|
action.to_s.titleize
|
@@ -111,7 +126,7 @@ module Olivander
|
|
111
126
|
end
|
112
127
|
|
113
128
|
def resource_attributes(resource, effective_resource)
|
114
|
-
er_attributes = effective_resource&.model_attributes&.collect{ |x| x[0] }
|
129
|
+
er_attributes = effective_resource&.model_attributes&.collect { |x| x[0] }
|
115
130
|
return er_attributes if er_attributes.present? && er_attributes.size.positive?
|
116
131
|
|
117
132
|
resource.auto_form_attributes
|
@@ -119,7 +134,6 @@ module Olivander
|
|
119
134
|
|
120
135
|
def render_optional_partial(partial, locals: {})
|
121
136
|
render partial: partial, locals: locals
|
122
|
-
|
123
137
|
rescue ActionView::MissingTemplate
|
124
138
|
Rails.logger.debug "did not find partial: #{partial}"
|
125
139
|
nil
|
@@ -138,7 +152,9 @@ module Olivander
|
|
138
152
|
end
|
139
153
|
|
140
154
|
def sidebar_context_name
|
141
|
-
[Olivander::CurrentContext.application_context.name, sidebar_context_suffix&.upcase].reject
|
155
|
+
[Olivander::CurrentContext.application_context.name, sidebar_context_suffix&.upcase].reject do |x|
|
156
|
+
x.blank? or x == 'PRODUCTION'
|
157
|
+
end.join(' ')
|
142
158
|
end
|
143
159
|
|
144
160
|
def sidebar_context_suffix
|
@@ -166,31 +182,31 @@ module Olivander
|
|
166
182
|
favicon_link_tag(image_path(favicon_path))
|
167
183
|
end
|
168
184
|
|
169
|
-
def flash_class
|
185
|
+
def flash_class(key)
|
170
186
|
case key
|
171
|
-
when
|
172
|
-
|
173
|
-
when
|
174
|
-
|
175
|
-
when
|
176
|
-
|
187
|
+
when 'error'
|
188
|
+
'danger'
|
189
|
+
when 'notice'
|
190
|
+
'info'
|
191
|
+
when 'alert'
|
192
|
+
'danger'
|
177
193
|
else
|
178
194
|
key
|
179
195
|
end
|
180
196
|
end
|
181
197
|
|
182
|
-
def flash_icon
|
198
|
+
def flash_icon(key)
|
183
199
|
case key
|
184
|
-
when
|
185
|
-
|
186
|
-
when
|
187
|
-
|
188
|
-
when
|
189
|
-
|
190
|
-
when
|
191
|
-
|
200
|
+
when 'error'
|
201
|
+
'fas fa-exclamation-circle'
|
202
|
+
when 'notice'
|
203
|
+
'fas fa-info-circle'
|
204
|
+
when 'alert'
|
205
|
+
'fas fa-info-circle'
|
206
|
+
when 'success'
|
207
|
+
'fas fa-check-circle'
|
192
208
|
else
|
193
|
-
|
209
|
+
'fas fa-question-circle'
|
194
210
|
end
|
195
211
|
end
|
196
212
|
|
@@ -209,7 +225,7 @@ module Olivander
|
|
209
225
|
builder.footer_buttons.call
|
210
226
|
end
|
211
227
|
end
|
212
|
-
end
|
228
|
+
end
|
213
229
|
end
|
214
230
|
end
|
215
231
|
end
|
data/lib/o18n.rb
CHANGED
@@ -6,13 +6,13 @@ class O18n
|
|
6
6
|
|
7
7
|
def self.t(*args, **kwargs)
|
8
8
|
value = I18n.t(*args, **kwargs)
|
9
|
-
value.gsub(ENV_REGEX)
|
10
|
-
envar = ENV[
|
11
|
-
|
12
|
-
|
9
|
+
value.gsub(ENV_REGEX) do
|
10
|
+
envar = ENV[Regexp.last_match(1)]
|
11
|
+
if envar.blank?
|
12
|
+
Regexp.last_match(1).titleize
|
13
13
|
else
|
14
|
-
|
14
|
+
I18n.exists?(envar) ? I18n.t(envar) : envar
|
15
15
|
end
|
16
|
-
|
16
|
+
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/olivander/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: five-two-nw-olivander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0.
|
4
|
+
version: 0.2.0.36
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Dennis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chartkick
|