tramway-admin 1.28.0.1 → 1.28.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/tramway/admin/application_helper.rb +1 -1
- data/app/views/tramway/admin/records/_form.html.haml +1 -1
- data/lib/tramway/admin/version.rb +1 -1
- metadata +2 -4
- data/app/helpers/tramway/admin/inputs_helper.rb +0 -97
- data/app/views/tramway/admin/shared/_input.html.haml +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 014b33b22a49ea50a02c62acc74843d3a10f1bedf145c23bf1f551d3cbe19f25
|
4
|
+
data.tar.gz: 1876e573d17d2a4f23000b30f9552a56db789583fb913f12e53da233757fa48e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44158cd39d3f13f265dee522c363f0c64abe296227300ab645f45882153a09e2b63687122f0e41b9f84fd30b1743480a2f88d7516fe9f83022f9d37692282bce
|
7
|
+
data.tar.gz: 0ebf861138c441f5bd94ac2edce8551c40b03cc24732dc21c02c2fc11b44fed8ea4ee1b70b5b858d6aa1be7f6d7afd29c86f87e27ceaabeb61d501f66a5cff96
|
@@ -12,7 +12,7 @@ module Tramway
|
|
12
12
|
include ::Tramway::Admin::RecordsHelper
|
13
13
|
include ::Tramway::Admin::SingletonHelper
|
14
14
|
include ::Tramway::Admin::NavbarHelper
|
15
|
-
include ::Tramway::
|
15
|
+
include ::Tramway::Core::InputsHelper
|
16
16
|
include ::Tramway::Admin::FocusGeneratorHelper
|
17
17
|
include ::Tramway::Admin::ActionsHelper
|
18
18
|
include ::Tramway::Collections::Helper
|
@@ -10,7 +10,7 @@
|
|
10
10
|
.col-lg-12
|
11
11
|
= simple_form_for @record_form, url: { controller: :records, action: action, model: @record_form.model.class }, method: method, input_html: { class: 'form-horizontal' } do |f|
|
12
12
|
- @record_form.properties.each do |property, type|
|
13
|
-
= render 'tramway/
|
13
|
+
= render 'tramway/core/shared/input', property: property, object: :record, type: type, form: f, destination: :admin
|
14
14
|
= hidden_field_tag :redirect, params[:redirect]
|
15
15
|
= f.button :submit, t('helpers.links.save'), class: 'btn-success'
|
16
16
|
= link_to t('helpers.links.back'), current_model_records_path, class: 'btn btn-secondary'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tramway-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.28.
|
4
|
+
version: 1.28.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootstrap-kaminari-views
|
@@ -191,7 +191,6 @@ files:
|
|
191
191
|
- app/helpers/tramway/admin/application_helper.rb
|
192
192
|
- app/helpers/tramway/admin/cases_helper.rb
|
193
193
|
- app/helpers/tramway/admin/focus_generator_helper.rb
|
194
|
-
- app/helpers/tramway/admin/inputs_helper.rb
|
195
194
|
- app/helpers/tramway/admin/navbar_helper.rb
|
196
195
|
- app/helpers/tramway/admin/records_helper.rb
|
197
196
|
- app/helpers/tramway/admin/russian_cases_helper.rb
|
@@ -208,7 +207,6 @@ files:
|
|
208
207
|
- app/views/tramway/admin/records/index.html.haml
|
209
208
|
- app/views/tramway/admin/records/new.html.haml
|
210
209
|
- app/views/tramway/admin/records/show.html.haml
|
211
|
-
- app/views/tramway/admin/shared/_input.html.haml
|
212
210
|
- app/views/tramway/admin/shared/_show.html.haml
|
213
211
|
- app/views/tramway/admin/shared/errors/server_error.html.haml
|
214
212
|
- app/views/tramway/admin/shared/show/_attribute_tr.html.haml
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tramway
|
4
|
-
module Admin
|
5
|
-
module InputsHelper
|
6
|
-
def association_params(form_object:, property:, value:, object:, options: {})
|
7
|
-
full_class_name_association = form_object.class.full_class_name_association(property)
|
8
|
-
unless full_class_name_association
|
9
|
-
raise "It seems you've defined association attributes with `property` method. Please, use `association` method. `association :#{property}`"
|
10
|
-
end
|
11
|
-
if full_class_name_association.is_a? Array
|
12
|
-
raise "It seems you've used `association` input type in the Form. Please, use `polymorphic_association` type. `#{property}: :polymorphic_association`"
|
13
|
-
end
|
14
|
-
|
15
|
-
{
|
16
|
-
label: false,
|
17
|
-
input_html: {
|
18
|
-
name: "#{object}[#{property}]",
|
19
|
-
id: "#{object}_#{property}",
|
20
|
-
value: (form_object.send(property) || form_object.model.send("#{property}_id") || value)
|
21
|
-
},
|
22
|
-
selected: (form_object.model.send("#{property}_id") || value),
|
23
|
-
collection: full_class_name_association.active.map do |obj|
|
24
|
-
decorator_class(full_class_name_association).decorate obj
|
25
|
-
end.sort_by(&:name)
|
26
|
-
}.merge options
|
27
|
-
end
|
28
|
-
|
29
|
-
def polymorphic_association_params(object:, form_object:, property:, value:, options: {})
|
30
|
-
full_class_names = form_object.model.class.send("#{property}_type").values.map &:constantize
|
31
|
-
collection = full_class_names.map do |class_name|
|
32
|
-
class_name.active.map do |obj|
|
33
|
-
decorator_class(class_name).decorate obj
|
34
|
-
end
|
35
|
-
end.flatten.sort_by { |obj| obj.name.to_s }
|
36
|
-
builded_value = if form_object.send(property).present?
|
37
|
-
"#{form_object.send(property).class.to_s.underscore}_#{form_object.send(property).id}"
|
38
|
-
else
|
39
|
-
"#{value[:type]&.underscore}_#{value[:id]}"
|
40
|
-
end
|
41
|
-
{
|
42
|
-
as: :select,
|
43
|
-
label: false,
|
44
|
-
input_html: {
|
45
|
-
name: "#{object}[#{property}]",
|
46
|
-
id: "#{object}_#{property}",
|
47
|
-
value: builded_value
|
48
|
-
},
|
49
|
-
selected: builded_value,
|
50
|
-
collection: collection,
|
51
|
-
label_method: lambda do |obj|
|
52
|
-
"#{obj.class.model_name.human} | #{obj.name}"
|
53
|
-
end,
|
54
|
-
value_method: lambda do |obj|
|
55
|
-
"#{obj.class.to_s.underscore.sub(/_decorator$/, '')}_#{obj.id}"
|
56
|
-
end
|
57
|
-
}.merge options
|
58
|
-
end
|
59
|
-
|
60
|
-
def value_from_params(model_class:, property:, type:)
|
61
|
-
case type
|
62
|
-
when :polymorphic_association, 'polymorphic_association'
|
63
|
-
{
|
64
|
-
id: params.dig(model_class.to_s.underscore, property.to_s),
|
65
|
-
type: params.dig(model_class.to_s.underscore, "#{property}_type")
|
66
|
-
}
|
67
|
-
else
|
68
|
-
params.dig(model_class.to_s.underscore, property.to_s)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def default_params(property:, object:, form_object:, value:, options: {})
|
73
|
-
{
|
74
|
-
label: false,
|
75
|
-
input_html: {
|
76
|
-
name: "#{object}[#{property}]",
|
77
|
-
id: "#{object}_#{property}",
|
78
|
-
value: (form_object.send(property) || form_object.model.send(property) || value)
|
79
|
-
},
|
80
|
-
selected: (form_object.model.send(property) || value)
|
81
|
-
}.merge options
|
82
|
-
end
|
83
|
-
|
84
|
-
def else_params(property:, object:, type:, form_object:, value:, options: {})
|
85
|
-
{
|
86
|
-
as: type,
|
87
|
-
label: false,
|
88
|
-
input_html: {
|
89
|
-
name: "#{object}[#{property}]",
|
90
|
-
id: "#{object}_#{property}",
|
91
|
-
value: (form_object.send(property) || form_object.model.send(property) || value)
|
92
|
-
}
|
93
|
-
}.merge options
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
- value = value_from_params(model_class: model_class, property: property, type: type)
|
2
|
-
- form_object = instance_variable_get "@#{object}_form"
|
3
|
-
- input_params = { property: property, object: object, form_object: form_object, value: value }
|
4
|
-
- if !type.class.in?([ Symbol, String ]) && type[:input_options]
|
5
|
-
- input_params.merge!(options: type[:input_options])
|
6
|
-
- type = type[:type]
|
7
|
-
- if type.class.in?([ Symbol, String ]) || type&.dig(:input_options)
|
8
|
-
- type = type.to_sym
|
9
|
-
= form.label form_object.model.class.human_attribute_name property
|
10
|
-
- case type
|
11
|
-
- when :default
|
12
|
-
= form.input property, **default_params(**input_params)
|
13
|
-
- when :association
|
14
|
-
= form.association property, **association_params(**input_params)
|
15
|
-
- when :polymorphic_association
|
16
|
-
= form.input property, **polymorphic_association_params(**input_params.merge(value: value))
|
17
|
-
- else
|
18
|
-
= form.input property, **else_params(**input_params.merge(type: type))
|
19
|
-
- else
|
20
|
-
- property_value = form_object.model.values.present? && form_object.model.values[property.to_s]
|
21
|
-
= render 'tramway/core/shared/input_extended', field: type[:extended_form_property], class_name: :record, value: property_value, f: form
|