rao-query 0.0.10.pre → 0.0.11.pre
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 701230b194df896ecad0d3c8d97992a780dc2ff4
|
4
|
+
data.tar.gz: 2a2f775ffe426e9fb3243703e05e5bfce8cd516c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 564988704e3c7cab85150fed4d1b0a7828fa474a9e55303a29af16c8aff2bca652569fae5ff59e52990f4e7afd64df19fb72a4e2da39571eede4755a1972e0e6
|
7
|
+
data.tar.gz: 99bb315ceba2c7ade86aeb4363d58742760fed756778b857eae74f89f417b0b364f85c004f4d130d0762d88441598e59d43dfe06cc5759c476f98c9418c99223
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Rao
|
2
|
+
module Query
|
3
|
+
class FormBuilder < SimpleForm::FormBuilder
|
4
|
+
def boolean(name, options = {})
|
5
|
+
translated_label = translate_label_for_boolean(name)
|
6
|
+
options.reverse_merge!(collection: [[I18n.t("rao.query.form_builder.yes"), 1], [I18n.t("rao.query.form_builder.no"), 0]], include_blank: true, label: translated_label)
|
7
|
+
input name, options
|
8
|
+
end
|
9
|
+
|
10
|
+
def input(name, options = {})
|
11
|
+
if association = options.delete(:association)
|
12
|
+
translated_label = translate_label(name, association)
|
13
|
+
input_name = "#{association}.#{name}"
|
14
|
+
else
|
15
|
+
translated_label = translate_label(name)
|
16
|
+
input_name = name
|
17
|
+
end
|
18
|
+
super(input_name, options.reverse_merge(label: translated_label))
|
19
|
+
end
|
20
|
+
|
21
|
+
def submit(title = nil, options = {})
|
22
|
+
title ||= I18n.t('rao.query.form_builder.submit')
|
23
|
+
super(title, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def reset(title = nil, options = {})
|
27
|
+
title ||= I18n.t('rao.query.form_builder.reset')
|
28
|
+
link_html = options.delete(:link_html) || {}
|
29
|
+
template.link_to(title, template.url_for(), link_html)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def translate_label(name, association = nil)
|
35
|
+
splitted_name = name.to_s.split('_')
|
36
|
+
attribute_name = splitted_name[0..-2].join('_')
|
37
|
+
predicate = splitted_name.last
|
38
|
+
translated_attribute_name = if association.nil?
|
39
|
+
klass_name = object.original_model_class_name
|
40
|
+
klass_name.constantize.human_attribute_name(attribute_name)
|
41
|
+
else
|
42
|
+
klass_name = object.original_model_class.reflect_on_association(association).klass.name
|
43
|
+
klass = klass_name.constantize
|
44
|
+
"#{klass.model_name.human} #{klass.human_attribute_name(attribute_name)}"
|
45
|
+
end
|
46
|
+
I18n.t("rao.query.form_builder.predicates.#{predicate}", attribute_name: translated_attribute_name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def translate_label_for_boolean(name)
|
50
|
+
splitted_name = name.to_s.split('_')
|
51
|
+
attribute_name = splitted_name[0..-2].join('_')
|
52
|
+
predicate = splitted_name.last
|
53
|
+
if association.nil?
|
54
|
+
klass_name = object.original_model_class_name
|
55
|
+
else
|
56
|
+
klass_name = object.original_model_class.reflect_on_association(association).klass
|
57
|
+
end
|
58
|
+
translated_attribute_name = klass_name.constantize.human_attribute_name(attribute_name)
|
59
|
+
I18n.t("rao.query.form_builder.boolean_label", attribute_name: translated_attribute_name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -14,6 +14,7 @@ module Rao
|
|
14
14
|
#
|
15
15
|
# # app/views/posts/index.html.haml
|
16
16
|
# = query_helper(self).form_for(@posts, url: posts_path, method: :get) do |f|
|
17
|
+
# = f.input :email_cont, association: :author
|
17
18
|
# = f.input :title_cont
|
18
19
|
# = f.input :body_cont
|
19
20
|
# = f.boolean :published_eq
|
@@ -34,67 +35,7 @@ module Rao
|
|
34
35
|
def form_for(collection, options = {}, &block)
|
35
36
|
handle_simple_form_missing unless c.respond_to?(:simple_form_for)
|
36
37
|
wrapped_collection = SearchableCollection.new(collection, c.params[:q])
|
37
|
-
c.simple_form_for(wrapped_collection, options.reverse_merge(as: :q, url: c.collection_path, method: :get, builder:
|
38
|
-
end
|
39
|
-
|
40
|
-
class SearchFormBuilder < SimpleForm::FormBuilder
|
41
|
-
def boolean(name, options = {})
|
42
|
-
translated_label = translate_label_for_boolean(name)
|
43
|
-
options.reverse_merge!(collection: [[I18n.t("search_form_builder.yes"), 1], [I18n.t("search_form_builder.no"), 0]], include_blank: true, label: translated_label)
|
44
|
-
input name, options
|
45
|
-
end
|
46
|
-
|
47
|
-
def input(name, options = {})
|
48
|
-
if association = options.delete(:association)
|
49
|
-
translated_label = translate_label(name, association)
|
50
|
-
input_name = "#{association}.#{name}"
|
51
|
-
else
|
52
|
-
translated_label = translate_label(name)
|
53
|
-
input_name = name
|
54
|
-
end
|
55
|
-
super(input_name, options.reverse_merge(label: translated_label))
|
56
|
-
end
|
57
|
-
|
58
|
-
def submit(title = nil, options = {})
|
59
|
-
title ||= I18n.t('search_form_builder.submit')
|
60
|
-
super(title, options)
|
61
|
-
end
|
62
|
-
|
63
|
-
def reset(title = nil, options = {})
|
64
|
-
title ||= I18n.t('search_form_builder.reset')
|
65
|
-
link_html = options.delete(:link_html) || {}
|
66
|
-
template.link_to(title, template.url_for(), link_html)
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def translate_label(name, association = nil)
|
72
|
-
splitted_name = name.to_s.split('_')
|
73
|
-
attribute_name = splitted_name[0..-2].join('_')
|
74
|
-
predicate = splitted_name.last
|
75
|
-
translated_attribute_name = if association.nil?
|
76
|
-
klass_name = object.original_model_class_name
|
77
|
-
klass_name.constantize.human_attribute_name(attribute_name)
|
78
|
-
else
|
79
|
-
klass_name = object.original_model_class.reflect_on_association(association).klass.name
|
80
|
-
klass = klass_name.constantize
|
81
|
-
"#{klass.model_name.human} #{klass.human_attribute_name(attribute_name)}"
|
82
|
-
end
|
83
|
-
I18n.t("search_form_builder.predicates.#{predicate}", attribute_name: translated_attribute_name)
|
84
|
-
end
|
85
|
-
|
86
|
-
def translate_label_for_boolean(name)
|
87
|
-
splitted_name = name.to_s.split('_')
|
88
|
-
attribute_name = splitted_name[0..-2].join('_')
|
89
|
-
predicate = splitted_name.last
|
90
|
-
if association.nil?
|
91
|
-
klass_name = object.original_model_class_name
|
92
|
-
else
|
93
|
-
klass_name = object.original_model_class.reflect_on_association(association).klass
|
94
|
-
end
|
95
|
-
translated_attribute_name = klass_name.constantize.human_attribute_name(attribute_name)
|
96
|
-
I18n.t("search_form_builder.boolean_label", attribute_name: translated_attribute_name)
|
97
|
-
end
|
38
|
+
c.simple_form_for(wrapped_collection, options.reverse_merge(as: :q, url: c.collection_path, method: :get, builder: Rao::Query::FormBuilder), &block)
|
98
39
|
end
|
99
40
|
|
100
41
|
class SearchableCollection
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rao-query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -134,8 +134,11 @@ files:
|
|
134
134
|
- Rakefile
|
135
135
|
- app/concerns/rao/query/controller/query_concern.rb
|
136
136
|
- app/concerns/rao/query/controller/query_form_concern.rb~
|
137
|
+
- app/form_builders/rao/query/form_builder.rb
|
137
138
|
- app/parsers/rao/query/condition_parser.rb
|
138
139
|
- app/view_helpers/rao/query/application_helper.rb
|
140
|
+
- config/locales/de.yml
|
141
|
+
- config/locales/en.yml
|
139
142
|
- lib/rao-query.rb
|
140
143
|
- lib/rao/query.rb
|
141
144
|
- lib/rao/query/configuration.rb
|