five-two-nw-olivander 0.2.0.30 → 0.2.0.32

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: bf65e51e30f810ec8599078545ed70b9b8ba984c6e32c6485823a46995bac530
4
- data.tar.gz: e4b702e0da5ef1bda84add56712f4bf2d20ae672e955a44645eb3e44a80ed96f
3
+ metadata.gz: 3aa4679fd3ac4496649900ee060cb20b1826f8e1b43c4757d548a9d5b77b6e4c
4
+ data.tar.gz: 61615323b1201dbd021800a5525062036bc80aab414c36028aa4e43c8ab1e2d0
5
5
  SHA512:
6
- metadata.gz: 24050b1455acf076f8707f4d031972995e98e31e82ebf2eaa970f0e24c8fc52fe1120a3bd1425c62499cfea954039f6e8c5bdb9b23e4d3c1c384696b7b6e9004
7
- data.tar.gz: 3778d4b7121de45d24e60421bb9d7bdad26fd1424bb4073fff5f4419624c9aaf24aa7516c8faad407eb5d796dcefe03d55c7049d92d666b955d9f43f15fd94e2
6
+ metadata.gz: 50bc6dc97b5826eef4ec98b15e20f11560a758f4b9c82b42e04d6962bc492cb697caa9094264ded682f0afdfc3195122953313595809f6a428aef461b9b68ea9
7
+ data.tar.gz: 577a779f683e1a5a5719747dc74f585633628186025770629b0e847c99fbfe47a573a045fbe1775cb15e0a75ed54c89b536a6bc7d5b1bfeb9bec9bfb6e090902
@@ -14,4 +14,4 @@
14
14
  - elsif boolean?(field)
15
15
  = @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, input_html: { data: input_data_hash_for(field) }
16
16
  - else
17
- = @f.input field.sym, disabled: !field.editable, as: field.type.to_sym, input_html: { rows: 10, data: input_data_hash_for(field) }
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) }
@@ -28,6 +28,17 @@ class Olivander::Components::ResourceFormComponent < ViewComponent::Base
28
28
  }
29
29
  end
30
30
 
31
+ def input_picker_options_for(field)
32
+ case field.type
33
+ when :datetime
34
+ { icons: { time: 'far fa-clock' } }
35
+ when :date
36
+ { 'format': 'MM/DD/YYYY' }
37
+ else
38
+ {}
39
+ end
40
+ end
41
+
31
42
  def taggable?(field)
32
43
  method_key = "#{field.sym}_taggable?"
33
44
  return false unless @resource.class.respond_to?(method_key)
@@ -66,10 +66,11 @@ 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
69
70
  begin
70
- resource_field(r.name, r.association_class.name.demodulize.underscore.to_sym, editable: editable && !r.options.keys.include?(:through))
71
+ resource_field(r.name, type, editable: editable && !uneditable_association?(r, type))
71
72
  rescue NotImplementedError
72
- resource_field(r.name, :association, editable: editable && !r.options.keys.include?(:through))
73
+ resource_field(r.name, :association, editable: editable && !uneditable_association?(r, type))
73
74
  end
74
75
  end
75
76
 
@@ -82,6 +83,13 @@ module Olivander
82
83
  end
83
84
  end
84
85
 
86
+ def self.uneditable_association?(r, type)
87
+ return false unless r.options.keys.include?(:through)
88
+
89
+ # this collection may prove to be larger than one...
90
+ %i[has_one_through_association].include?(type)
91
+ end
92
+
85
93
  def self.resource_field_group(key = :default, editable: true, &block)
86
94
  self.resource_field_group_collection ||= []
87
95
  self.current_resource_field_group = resource_field_group_collection.select{ |x| x.key == key}.first
@@ -195,8 +195,10 @@ module Olivander
195
195
  def rearrange_date_param(value)
196
196
  return nil if value.blank?
197
197
 
198
- parts = value.split('/')
199
- "#{parts[2]}-#{parts[0]}-#{parts[1]}"
198
+ datetime_parts = value.split(' ')
199
+ date_parts = datetime_parts.first.split('/')
200
+ datetime_parts[0] = "#{date_parts[2]}-#{date_parts[0]}-#{date_parts[1]}"
201
+ datetime_parts.join(' ')
200
202
  end
201
203
  end
202
204
  end
@@ -5,7 +5,7 @@ module Olivander
5
5
  modded = count % 12
6
6
  divisor = modded.zero? ? 1 : modded
7
7
  "col-#{label}-#{[12/divisor, min].max}"
8
-
8
+
9
9
  divisor = count
10
10
  result = 12/divisor
11
11
  while result < min
@@ -1,12 +1,10 @@
1
1
  class DateTimeInput < SimpleForm::Inputs::Base
2
2
  def input(wrapper_options)
3
- date_format = options[:date_format] || '%m/%d/%Y'
4
- raw_value = object.public_send(attribute_name)
5
- raw_value = raw_value.strftime(date_format) if raw_value.present?
3
+ raw_value = parse_value(object.public_send(attribute_name), options[:date_format])
6
4
 
7
5
  disabled = options[:disabled] || false
8
6
 
9
- hash = { id: "#{attribute_name}_datetimepicker", class: 'form-control', value: raw_value, disabled: disabled, 'data-toggle': 'datetimepicker', 'data-target': "##{attribute_name}_datetimepicker" }
7
+ hash = { id: "#{attribute_name}_datetimepicker", class: 'form-control datetimepicker-input', value: raw_value, disabled: disabled, 'data-toggle': 'datetimepicker', 'data-target': "##{attribute_name}_datetimepicker" }
10
8
  data = options[:data] || {}
11
9
  data.keys.each do |d|
12
10
  hash["data-#{d.to_s.dasherize}".to_sym] = data[d]
@@ -26,7 +24,7 @@ class DateTimeInput < SimpleForm::Inputs::Base
26
24
 
27
25
  script = "".html_safe
28
26
  unless disabled then
29
- picker_options = options[:picker_options] || { "format" => "MM/DD/YYYY" }
27
+ picker_options = options[:picker_options] || { "format": "MM/DD/YYYY" }
30
28
 
31
29
  script = """
32
30
  <script>
@@ -41,4 +39,16 @@ class DateTimeInput < SimpleForm::Inputs::Base
41
39
 
42
40
  all + script
43
41
  end
42
+
43
+ def parse_value(raw_value, format)
44
+ return nil unless raw_value.present?
45
+
46
+ format ||= case raw_value.class.name
47
+ when 'Time', 'ActiveSupport::TimeWithZone'
48
+ '%m/%d/%Y %H:%M %p'
49
+ else
50
+ '%m/%d/%Y'
51
+ end
52
+ raw_value.strftime(format)
53
+ end
44
54
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # needed for gem
4
4
  module Olivander
5
- VERSION = '0.2.0.30'
5
+ VERSION = '0.2.0.32'
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.30
4
+ version: 0.2.0.32
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-08-27 00:00:00.000000000 Z
11
+ date: 2024-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick