tramway-core 4.0.1 → 4.0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60e501986748c5fcfe27092b525dcf97a9f8a591e9a00ea9659f150b746123d1
4
- data.tar.gz: 840750721db0f18d04437cd3e840bcf311094aa044dc95cb9f1c50f2e520e516
3
+ metadata.gz: 071cf2ccd054e5bde3e9ecc232476ec1a48d2aa4e3d51246befdd770a6e89876
4
+ data.tar.gz: 7aa40b3777e070784dd0f0ca57baf12b4fd6378e5911b1e3dfa25ec6b427e24f
5
5
  SHA512:
6
- metadata.gz: 341c866e0797198604e6edc1f5275b0b0636e1b24635b5c5a019050f1ee86f46eb664fee80256170db9e41219d926c004bdc7368d32e8afafec417c6595e0b87
7
- data.tar.gz: fb50c72df380f9c9bc23564414c06131444b838ea9e6810a0decf083add8a6234283ac83405d539360190282d5123ec7c7ecac2d8e3e206368339c2c9d9b29d2
6
+ metadata.gz: 8ff54066670f690934e828bd599b8cbeac5ad3cf27c43d2d56f54425f0bbf38708ae9d0bea74983d35a8b08a6a5393ed88810bd5e37672290653293dcb170919
7
+ data.tar.gz: 521157e341cc6eada7c4c1c4e97b620e5233dc28d15adbe148d53daa0b397d138b4084d69228379cd6a1e45e5fe7bf065f19181080f23d3ee00fc828b4bf8636
@@ -14,14 +14,16 @@ module Tramway::Core::ApplicationForms::AssociationObjectHelpers
14
14
 
15
15
  def define_polymorphic_association(association, _class_name)
16
16
  self.class.send(:define_method, "#{association}=") do |value|
17
- association_class = value.split('_')[0..-2].join('_').camelize
18
- association_class = association_class.constantize if association_class.is_a? String
19
- if association_class.nil?
20
- Tramway::Error.raise_error :tramway, :core, :application_form, :initialize, :polymorphic_class_is_nil,
21
- association_name: association
22
- else
23
- model.send "#{association}=", association_class.find(value.split('_')[-1])
24
- send "#{association}_type=", association_class.to_s
17
+ if value.present?
18
+ association_class = value.split('_')[0..-2].join('_').camelize
19
+ association_class = association_class.constantize if association_class.is_a? String
20
+ if association_class.nil?
21
+ Tramway::Error.raise_error :tramway, :core, :application_form, :initialize, :polymorphic_class_is_nil,
22
+ association_name: association
23
+ else
24
+ model.send "#{association}=", association_class.find(value.split('_')[-1])
25
+ send "#{association}_type=", association_class.to_s
26
+ end
25
27
  end
26
28
  end
27
29
  end
@@ -0,0 +1,9 @@
1
+ module Tramway::Core::ApplicationForms::Frontend
2
+ def react_component(on = false)
3
+ @@react_component = on
4
+ end
5
+
6
+ def is_react_component?
7
+ @@react_component ||= false
8
+ end
9
+ end
@@ -15,7 +15,9 @@ module Tramway::Core::Inputs::PolymorphicAssociationsHelper
15
15
  if form_object.send(property).present?
16
16
  "#{form_object.send(property).class.to_s.underscore}_#{form_object.send(property).id}"
17
17
  else
18
- "#{value[:type]&.underscore}_#{value[:id]}"
18
+ if value[:type].present? && value[:id].present?
19
+ "#{value[:type]&.underscore}_#{value[:id]}"
20
+ end
19
21
  end
20
22
  end
21
23
 
@@ -15,6 +15,7 @@ module Tramway::Core::InputsHelper
15
15
  build_input_attributes(object: object, property: property, options: options,
16
16
  value: build_value_for_association(form_object, property, value),
17
17
  collection: build_collection_for_association(form_object, property),
18
+ include_blank: true,
18
19
  selected: form_object.model.send("#{property}_id") || value)
19
20
  end
20
21
 
@@ -25,6 +26,7 @@ module Tramway::Core::InputsHelper
25
26
  collection: build_collection_for_polymorphic_association(form_object, property),
26
27
  options: options.merge(
27
28
  as: :select,
29
+ include_blank: true,
28
30
  label_method: ->(obj) { "#{obj.class.model_name.human} | #{obj.name}" },
29
31
  value_method: lambda { |obj|
30
32
  "#{obj.class.to_s.underscore.sub(/_decorator$/, '')}_#{obj.id}"
@@ -6,7 +6,7 @@
6
6
  - type = type[:type]
7
7
  - if type.class.in?([ Symbol, String ]) || type&.dig(:input_options)
8
8
  - type = type.to_sym
9
- - if type != :hidden && input_params.dig(:options, :label) != false
9
+ - if !type.in?([ :hidden ]) && input_params.dig(:options, :label) != false
10
10
  = form.label form_object.model.class.human_attribute_name property
11
11
  - case type
12
12
  - when :default
@@ -14,7 +14,10 @@
14
14
  - when :association
15
15
  = form.association property, **association_params(**input_params)
16
16
  - when :hidden_association
17
- = form.association property, **association_params(**input_params).merge(as: :hidden, input_html: { value: value || form_object.public_send(property).id })
17
+ - if form_object.public_send(property)&.id
18
+ = form.association property, **association_params(**input_params).merge(as: :hidden, input_html: { value: form_object.public_send(property)&.id })
19
+ - else
20
+ = form.association property, **association_params(**input_params).merge(as: :hidden)
18
21
  - when :polymorphic_association
19
22
  = form.input property, **polymorphic_association_params(**input_params.merge(value: value))
20
23
  - else
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '4.0.1'
5
+ VERSION = '4.0.2.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-02-09 00:00:00.000000000 Z
12
+ date: 2022-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: audited
@@ -326,6 +326,7 @@ files:
326
326
  - app/forms/tramway/core/application_forms/association_object_helpers.rb
327
327
  - app/forms/tramway/core/application_forms/constant_class_actions.rb
328
328
  - app/forms/tramway/core/application_forms/constant_object_actions.rb
329
+ - app/forms/tramway/core/application_forms/frontend.rb
329
330
  - app/forms/tramway/core/application_forms/object_helpers.rb
330
331
  - app/forms/tramway/core/application_forms/properties_object_helper.rb
331
332
  - app/forms/tramway/core/application_forms/submit_helper.rb