five-two-nw-olivander 0.2.0.32 → 0.2.0.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3aa4679fd3ac4496649900ee060cb20b1826f8e1b43c4757d548a9d5b77b6e4c
4
- data.tar.gz: 61615323b1201dbd021800a5525062036bc80aab414c36028aa4e43c8ab1e2d0
3
+ metadata.gz: 20309038b9a2b17f545f6c06658c87f41fc20a565b8d39b6c079894add49c644
4
+ data.tar.gz: 5c6429e2fdd1204b7324b36a7c4cd118ea136229b23a56f9ded5cab92fab801a
5
5
  SHA512:
6
- metadata.gz: 50bc6dc97b5826eef4ec98b15e20f11560a758f4b9c82b42e04d6962bc492cb697caa9094264ded682f0afdfc3195122953313595809f6a428aef461b9b68ea9
7
- data.tar.gz: 577a779f683e1a5a5719747dc74f585633628186025770629b0e847c99fbfe47a573a045fbe1775cb15e0a75ed54c89b536a6bc7d5b1bfeb9bec9bfb6e090902
6
+ metadata.gz: 248d5ca6b004d3f76c47b0a70e5268ec26970df86e7a0e45ba2879cf07468b0f9c71fb045321ccd76c7dea764252fc40a865de5a19a3b14c1f657045f6dedb39
7
+ data.tar.gz: 884dd31cca4c245d24b227ca9ae2d7854d36059df578a70bb1325f76758ad87a1eb0b987273db88757d4e332028d277b5d659593dacc6f6b851762c6454f5663
@@ -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('/', '-')}-#{field.sym} input-control-association",
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('/', '-')}-#{field.sym} input-control-#{field.type}",
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
- begin
57
- polymorphic_path(@resource.class.reflect_on_association(field.sym).klass, format: :json)
58
- rescue
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)
@@ -66,8 +66,8 @@ module Olivander
66
66
  reflections.map{ |x| x[1] }
67
67
  .filter{ |x| x.foreign_key == inc || x.name == inc }
68
68
  .each do |r|
69
- type = r.association_class.name.demodulize.underscore.to_sym
70
69
  begin
70
+ type = r.association_class.name.demodulize.underscore.to_sym
71
71
  resource_field(r.name, type, editable: editable && !uneditable_association?(r, type))
72
72
  rescue NotImplementedError
73
73
  resource_field(r.name, :association, editable: editable && !uneditable_association?(r, type))
@@ -48,7 +48,7 @@ module Olivander
48
48
 
49
49
  def confirmation_message
50
50
  return confirm_with if confirm_with.present?
51
- return I18n.t('activerecord.actions.delete-confirmation') if verb == :delete
51
+ return O18n.t('activerecord.actions.delete-confirmation') if verb == :delete
52
52
 
53
53
  nil
54
54
  end
@@ -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 = divisor/2
13
- result = 12/divisor
13
+ divisor /= 2
14
+ result = 12 / divisor
14
15
  end
15
16
  "col-#{label}-#{result}"
16
17
  end
@@ -21,7 +22,7 @@ module Olivander
21
22
 
22
23
  controller_key = controller.class.name.underscore
23
24
  key = "page_titles.#{controller_key}.#{action_name}"
24
- return I18n.t(key) if I18n.exists?(key)
25
+ return O18n.t(key) if I18n.exists?(key)
25
26
 
26
27
  return @page_title if @page_title
27
28
 
@@ -35,21 +36,20 @@ module Olivander
35
36
  end
36
37
 
37
38
  def authorized_resource_actions(resource, for_action: :show)
38
- raw_name = resource.is_a?(Class) ? resource.name : resource.class.name
39
+ action_resource = action_resource_for(resource)
40
+ raw_name = action_resource.name
39
41
  plural_name = raw_name.demodulize.underscore.pluralize
40
42
  routed_resource = Olivander::CurrentContext.application_context.route_builder.resources[plural_name.to_sym]
41
43
  return [] if routed_resource.nil?
42
44
 
43
45
  actions = if resource.is_a?(Class)
44
46
  routed_resource.unpersisted_crud_actions | routed_resource.collection_actions.reject(&:crud_action)
47
+ elsif resource.persisted?
48
+ routed_resource.persisted_crud_actions | routed_resource.member_actions.reject(&:crud_action)
45
49
  else
46
- if resource.persisted?
47
- routed_resource.persisted_crud_actions | routed_resource.member_actions.reject(&:crud_action)
48
- else
49
- []
50
- end
50
+ []
51
51
  end
52
- actions = actions.select{ |a| authorized_resource_action?(a.sym, resource, for_action) }
52
+ actions = actions.select { |a| authorized_resource_action?(a.sym, action_resource, for_action) }
53
53
  preferred = %i[show edit destroy]
54
54
  [].tap do |arr|
55
55
  preferred.each do |p|
@@ -57,12 +57,17 @@ module Olivander
57
57
  arr << a if a.sym == p
58
58
  end
59
59
  end
60
- actions.reject{ |x| preferred.include?(x.sym) }.each do |a|
60
+ actions.reject { |x| preferred.include?(x.sym) }.each do |a|
61
61
  arr << a
62
62
  end
63
63
  end
64
64
  end
65
65
 
66
+ def action_resource_for(resource)
67
+ klazz = resource.is_a?(Class) ? resource : resource.class
68
+ klazz.respond_to?(:action_resource) ? klazz.action_resource : klazz
69
+ end
70
+
66
71
  def authorized_resource_action?(action, resource, except = nil)
67
72
  return false if action == except
68
73
 
@@ -70,36 +75,41 @@ module Olivander
70
75
  end
71
76
 
72
77
  def resource_form_actions(resource, for_action: :show)
73
- render partial: 'resource_form_actions', locals: { actions: authorized_resource_actions(resource, for_action: for_action).select(&:show_in_form) }
78
+ render partial: 'resource_form_actions',
79
+ locals: { actions: authorized_resource_actions(resource, for_action: for_action).select(&:show_in_form) }
74
80
  end
75
81
 
76
82
  def resource_form_action_tooltip(resource, action)
77
83
  key = resource.class.name.underscore
78
- return I18n.t("activerecord.actions.#{key}.#{action}-tooltip") if I18n.exists?("activerecord.actions.#{key}.#{action}-tooltip")
79
- return I18n.t("activerecord.actions.#{action}-tooltip") if I18n.exists?("activerecord.actions.#{action}-tooltip")
84
+ if I18n.exists?("activerecord.actions.#{key}.#{action}-tooltip")
85
+ return O18n.t("activerecord.actions.#{key}.#{action}-tooltip")
86
+ end
87
+ return O18n.t("activerecord.actions.#{action}-tooltip") if I18n.exists?("activerecord.actions.#{action}-tooltip")
80
88
 
81
89
  action.to_s.titleize
82
90
  end
83
91
 
84
92
  def resource_form_action_label(resource, action)
85
93
  key = resource.class.name.underscore
86
- return I18n.t("activerecord.actions.#{key}.#{action}") if I18n.exists?("activerecord.actions.#{key}.#{action}")
87
- return I18n.t("activerecord.actions.#{action}") if I18n.exists?("activerecord.actions.#{action}")
94
+ return O18n.t("activerecord.actions.#{key}.#{action}") if I18n.exists?("activerecord.actions.#{key}.#{action}")
95
+ return O18n.t("activerecord.actions.#{action}") if I18n.exists?("activerecord.actions.#{action}")
88
96
 
89
97
  action.to_s.titleize
90
98
  end
91
99
 
92
100
  def resource_form_action_icon(resource, action)
93
101
  key = resource.class.name.underscore
94
- return I18n.t("activerecord.actions.#{key}.#{action}-icon") if I18n.exists?("activerecord.actions.#{key}.#{action}-icon")
95
- return I18n.t("activerecord.actions.#{action}-icon") if I18n.exists?("activerecord.actions.#{action}-icon")
102
+ if I18n.exists?("activerecord.actions.#{key}.#{action}-icon")
103
+ return O18n.t("activerecord.actions.#{key}.#{action}-icon")
104
+ end
105
+ return O18n.t("activerecord.actions.#{action}-icon") if I18n.exists?("activerecord.actions.#{action}-icon")
96
106
 
97
107
  action.to_s.titleize
98
108
  end
99
109
 
100
110
  def resource_field_group_label(resource_class, key)
101
111
  i18n_key = "activerecord.attributes.#{resource_class.name.underscore}.resource_field_groups.#{key}"
102
- I18n.exists?(i18n_key) ? I18n.t(i18n_key) : key.to_s.titleize
112
+ I18n.exists?(i18n_key) ? O18n.t(i18n_key) : key.to_s.titleize
103
113
  end
104
114
 
105
115
  def current_user
@@ -111,7 +121,7 @@ module Olivander
111
121
  end
112
122
 
113
123
  def resource_attributes(resource, effective_resource)
114
- er_attributes = effective_resource&.model_attributes&.collect{ |x| x[0] }
124
+ er_attributes = effective_resource&.model_attributes&.collect { |x| x[0] }
115
125
  return er_attributes if er_attributes.present? && er_attributes.size.positive?
116
126
 
117
127
  resource.auto_form_attributes
@@ -119,7 +129,6 @@ module Olivander
119
129
 
120
130
  def render_optional_partial(partial, locals: {})
121
131
  render partial: partial, locals: locals
122
-
123
132
  rescue ActionView::MissingTemplate
124
133
  Rails.logger.debug "did not find partial: #{partial}"
125
134
  nil
@@ -128,7 +137,7 @@ module Olivander
128
137
  def field_label_for(resource_class, sym)
129
138
  sym_s = sym.to_s.gsub('.', '_')
130
139
  i18n_key = "activerecord.attributes.#{resource_class.name.underscore}.#{sym_s}"
131
- return I18n.t(i18n_key) if I18n.exists?(i18n_key)
140
+ return O18n.t(i18n_key) if I18n.exists?(i18n_key)
132
141
 
133
142
  sym.to_s.titleize
134
143
  end
@@ -138,7 +147,9 @@ module Olivander
138
147
  end
139
148
 
140
149
  def sidebar_context_name
141
- [Olivander::CurrentContext.application_context.name, sidebar_context_suffix&.upcase].reject{ |x| x.blank? or x == 'PRODUCTION' }.join(' ')
150
+ [Olivander::CurrentContext.application_context.name, sidebar_context_suffix&.upcase].reject do |x|
151
+ x.blank? or x == 'PRODUCTION'
152
+ end.join(' ')
142
153
  end
143
154
 
144
155
  def sidebar_context_suffix
@@ -166,31 +177,31 @@ module Olivander
166
177
  favicon_link_tag(image_path(favicon_path))
167
178
  end
168
179
 
169
- def flash_class key
180
+ def flash_class(key)
170
181
  case key
171
- when "error"
172
- "danger"
173
- when "notice"
174
- "info"
175
- when "alert"
176
- "danger"
182
+ when 'error'
183
+ 'danger'
184
+ when 'notice'
185
+ 'info'
186
+ when 'alert'
187
+ 'danger'
177
188
  else
178
189
  key
179
190
  end
180
191
  end
181
192
 
182
- def flash_icon key
193
+ def flash_icon(key)
183
194
  case key
184
- when "error"
185
- "fas fa-exclamation-circle"
186
- when "notice"
187
- "fas fa-info-circle"
188
- when "alert"
189
- "fas fa-info-circle"
190
- when "success"
191
- "fas fa-check-circle"
195
+ when 'error'
196
+ 'fas fa-exclamation-circle'
197
+ when 'notice'
198
+ 'fas fa-info-circle'
199
+ when 'alert'
200
+ 'fas fa-info-circle'
201
+ when 'success'
202
+ 'fas fa-check-circle'
192
203
  else
193
- "fas fa-question-circle"
204
+ 'fas fa-question-circle'
194
205
  end
195
206
  end
196
207
 
@@ -209,7 +220,7 @@ module Olivander
209
220
  builder.footer_buttons.call
210
221
  end
211
222
  end
212
- end
223
+ end
213
224
  end
214
225
  end
215
226
  end
@@ -12,6 +12,6 @@
12
12
  = render Olivander::Components::ResourceFormComponent.new(@resource, f)
13
13
  = render_optional_partial 'form_inside_after', locals: {f: f}
14
14
  .card-footer.text-right
15
- = link_to 'Cancel', @_effective_resource.action_path(:index), class: 'btn btn-secondary'
15
+ = link_to 'Cancel', @cancel_path || @_effective_resource.action_path(:index), class: 'btn btn-secondary'
16
16
  - unless read_only
17
17
  = f.button :submit, class: 'btn btn-primary'
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[$1]
11
- unless envar.blank?
12
- I18n.exists?(envar) ? I18n.t(envar) : envar
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
- $1.titleize
14
+ I18n.exists?(envar) ? I18n.t(envar) : envar
15
15
  end
16
- }
16
+ end
17
17
  end
18
18
  end
@@ -77,9 +77,9 @@ module Olivander
77
77
  return nil unless raw
78
78
 
79
79
  if key && I18n.exists?(key)
80
- I18n.t(key)
80
+ O18n.t(key)
81
81
  elsif fallback && I18n.exists?(fallback)
82
- I18n.t(fallback)
82
+ O18n.t(fallback)
83
83
  else
84
84
  raw.titleize
85
85
  end
@@ -88,12 +88,12 @@ module Olivander
88
88
 
89
89
  class Badge
90
90
  attr_accessor :text, :badge_class
91
-
91
+
92
92
  def initialize(text = nil, badge_class = nil)
93
93
  @text = text
94
94
  @badge_class = badge_class
95
95
  end
96
-
96
+
97
97
  def with_proc
98
98
  yield(self)
99
99
  self
@@ -2,5 +2,5 @@
2
2
 
3
3
  # needed for gem
4
4
  module Olivander
5
- VERSION = '0.2.0.32'
5
+ VERSION = '0.2.0.35'
6
6
  end
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.32
4
+ version: 0.2.0.35
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-09-19 00:00:00.000000000 Z
11
+ date: 2024-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick