forest_liana 1.6.4 → 1.6.5

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
  SHA1:
3
- metadata.gz: be7e0cdd4e20fd9429e3432ce2b2e7a47c18791f
4
- data.tar.gz: 5d24a288485b23ac6d9deb6f395025dd3fb2e4e9
3
+ metadata.gz: 65bc0a94633ab9554e51ace04fb84e302b2afb0b
4
+ data.tar.gz: f026a0b61db387f8045b4f50a48ba54288e75b20
5
5
  SHA512:
6
- metadata.gz: 4345b6f83549d7f2528a58c42ab1b9f4cc88e68701ebc309940c15b51ecc74e9dfd2e67c0406b2994aca9d3d76fe2f08462eb1acc962a385b4e35e769c50d12d
7
- data.tar.gz: 20336271af11919fab0c756f0fb32e349e900b7feaa80207f5bb6b2f2802ace847e4449ea6843af2121c843422e411a36b5d4f1f71f110d82bf84594aba2c578
6
+ metadata.gz: 80fd90903e69868ed3132c6b5a49b9526922ca38a7961b415fcf977db027c03589f3142ed77b39511921aef38061b6928cd774322d7981ac10eb260197ebd739
7
+ data.tar.gz: c818a6da4a756d1deafbb07caef9299866fea4d72fb85aa20ae49d68017abc5f25d626a6c39970e48e355bb9d150fe628f69caf21a8ce791aa2d6e9bec48149d
@@ -34,6 +34,16 @@ module ForestLiana
34
34
  ForestLiana::AdapterHelper.format_column_name(table_name, column_name)
35
35
  end
36
36
 
37
+ def acts_as_taggable_query(tagged_records)
38
+ ids = tagged_records
39
+ .map {|t| t[@resource.primary_key]}
40
+ .join(',')
41
+
42
+ if ids.present?
43
+ return "#{@resource.primary_key} IN (#{ids})"
44
+ end
45
+ end
46
+
37
47
  def search_param
38
48
  if @params[:search]
39
49
  conditions = []
@@ -60,6 +70,15 @@ module ForestLiana
60
70
  end
61
71
  end
62
72
 
73
+ # ActsAsTaggable
74
+ if @resource.respond_to?(:acts_as_taggable)
75
+ @resource.acts_as_taggable.each do |field|
76
+ tagged_records = @records.tagged_with(@params[:search].downcase)
77
+ condition = acts_as_taggable_query(tagged_records)
78
+ conditions << condition if condition
79
+ end
80
+ end
81
+
63
82
  SchemaUtils.one_associations(@resource).map(&:name).each do |association|
64
83
  if @includes.include? association.to_sym
65
84
  resource = @resource.reflect_on_association(association.to_sym)
@@ -84,13 +103,25 @@ module ForestLiana
84
103
  def filter_param
85
104
  if @params[:filterType] && @params[:filter]
86
105
  conditions = []
106
+
87
107
  @params[:filter].each do |field, values|
88
- next if association?(field)
108
+ # ActsAsTaggable
109
+ if acts_as_taggable?(field)
110
+ tagged_records = @records.tagged_with(values.tr('*', ''))
111
+
112
+ if @params[:filterType] == 'and'
113
+ @records = tagged_records
114
+ elsif @params[:filterType] == 'or'
115
+ conditions << acts_as_taggable_query(tagged_records)
116
+ end
117
+ else
118
+ next if association?(field)
89
119
 
90
- values.split(',').each do |value|
91
- operator, value = OperatorValueParser.parse(value)
92
- conditions << OperatorValueParser.get_condition(field, operator,
93
- value, @resource, @params[:timezone])
120
+ values.split(',').each do |value|
121
+ operator, value = OperatorValueParser.parse(value)
122
+ conditions << OperatorValueParser.get_condition(field, operator,
123
+ value, @resource, @params[:timezone])
124
+ end
94
125
  end
95
126
  end
96
127
 
@@ -113,10 +144,15 @@ module ForestLiana
113
144
  [:has_many, :has_and_belongs_to_many].include?(association.try(:macro))
114
145
  end
115
146
 
147
+ def acts_as_taggable?(field)
148
+ @resource.respond_to?(:acts_as_taggable) &&
149
+ @resource.acts_as_taggable.include?(field)
150
+ end
151
+
116
152
  def has_many_filter
117
153
  if @params[:filter]
118
154
  @params[:filter].each do |field, values|
119
- next unless has_many_association?(field)
155
+ next if !has_many_association?(field) || acts_as_taggable?(field)
120
156
 
121
157
  values.split(',').each do |value|
122
158
  if field.include?(':')
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "1.6.4"
2
+ VERSION = "1.6.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-09 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails