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 +4 -4
- data/app/forms/tramway/core/application_forms/association_object_helpers.rb +10 -8
- data/app/forms/tramway/core/application_forms/frontend.rb +9 -0
- data/app/helpers/tramway/core/inputs/polymorphic_associations_helper.rb +3 -1
- data/app/helpers/tramway/core/inputs_helper.rb +2 -0
- data/app/views/tramway/core/shared/_input.html.haml +5 -2
- data/lib/tramway/core/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 071cf2ccd054e5bde3e9ecc232476ec1a48d2aa4e3d51246befdd770a6e89876
|
4
|
+
data.tar.gz: 7aa40b3777e070784dd0f0ca57baf12b4fd6378e5911b1e3dfa25ec6b427e24f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
@@ -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
|
-
|
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
|
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
|
-
|
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
|
data/lib/tramway/core/version.rb
CHANGED
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-
|
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
|