data_tables 0.1.9 → 0.1.10
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.
- data/data_tables.gemspec +1 -1
- data/lib/data_tables.rb +35 -29
- data/lib/data_tables/data_tables_helper.rb +47 -0
- metadata +2 -2
data/data_tables.gemspec
CHANGED
data/lib/data_tables.rb
CHANGED
@@ -44,7 +44,7 @@ module DataTablesController
|
|
44
44
|
scope = options[:scope] || :domain
|
45
45
|
named_scope = options[:named_scope]
|
46
46
|
named_scope_args = options[:named_scope_args]
|
47
|
-
except = options[:except]
|
47
|
+
except = options[:except] || []
|
48
48
|
es_block = options[:es_block]
|
49
49
|
|
50
50
|
#
|
@@ -79,20 +79,23 @@ module DataTablesController
|
|
79
79
|
elastic_index_name = "#{Tire::Model::Search.index_prefix}#{modelCls.to_s.underscore}"
|
80
80
|
logger.debug "*** (datatable:#{__LINE__}) Using tire for search #{modelCls} (#{elastic_index_name})"
|
81
81
|
|
82
|
-
search_condition = elasticsearch_sanitation(search_condition, except)
|
83
|
-
just_excepts = except ? elasticsearch_sanitation(nil, except) : "*"
|
84
|
-
logger.debug "*** search_condition = #{search_condition}; sort by #{column_name_sym}:#{sort_dir}; domain=`#{domain.inspect}'"
|
85
|
-
|
86
82
|
retried = 0
|
87
83
|
if Tire.index(elastic_index_name){exists?}.response.code != 404
|
88
84
|
begin
|
89
85
|
controller_instance = self
|
90
86
|
results = Tire.search(elastic_index_name) do
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
87
|
+
query do
|
88
|
+
boolean do
|
89
|
+
if search_condition && retried < 2
|
90
|
+
must { match :_all, search_condition, type: 'phrase_prefix' }
|
91
|
+
else
|
92
|
+
must { all }
|
93
|
+
end
|
94
|
+
|
95
|
+
except.each do |expt|
|
96
|
+
must_not { term expt[0].to_sym, expt[1].to_s }
|
97
|
+
end
|
98
|
+
end
|
96
99
|
end
|
97
100
|
|
98
101
|
# retry #1 exclude sorting from search query
|
@@ -111,9 +114,15 @@ module DataTablesController
|
|
111
114
|
objects = results.map{ |r| modelCls[r._id] }.compact
|
112
115
|
total_display_records = results.total
|
113
116
|
|
114
|
-
|
115
117
|
total_records = Tire.search(elastic_index_name, search_type: 'count') do
|
116
|
-
query
|
118
|
+
query do
|
119
|
+
boolean do
|
120
|
+
must { all }
|
121
|
+
except.each do |expt|
|
122
|
+
must_not { term expt[0].to_sym, expt[1].to_s }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
117
126
|
filter(:term, domain: domain) unless domain.blank?
|
118
127
|
es_block.call(self) if es_block.respond_to?(:call)
|
119
128
|
end.results.total
|
@@ -181,10 +190,10 @@ module DataTablesController
|
|
181
190
|
#
|
182
191
|
define_method action.to_sym do
|
183
192
|
domain_name = ActiveRecord::Base.connection.schema_search_path.to_s.split(",")[0]
|
184
|
-
logger.debug "*** Using ElasticSearch for #{modelCls.name}"
|
193
|
+
logger.debug "*** (datatables:#{__LINE__}) Using ElasticSearch for #{modelCls.name}"
|
185
194
|
objects = []
|
186
195
|
|
187
|
-
condstr =
|
196
|
+
condstr = nil
|
188
197
|
unless params[:sSearch].blank?
|
189
198
|
sort_column_id = params[:iSortCol_0].to_i
|
190
199
|
sort_column_id = 1 if sort_column_id == 0
|
@@ -200,11 +209,20 @@ module DataTablesController
|
|
200
209
|
column_name = columns[sort_column][:name] || 'message'
|
201
210
|
sort_dir = params[:sSortDir_0] || 'desc'
|
202
211
|
|
203
|
-
condstr = elasticsearch_sanitation(condstr, except)
|
204
|
-
|
205
212
|
begin
|
206
213
|
query = Proc.new do
|
207
|
-
query
|
214
|
+
query do
|
215
|
+
boolean do
|
216
|
+
if condstr
|
217
|
+
must { match :_all, condstr, type: 'phrase_prefix' }
|
218
|
+
else
|
219
|
+
must { all }
|
220
|
+
end
|
221
|
+
except.each do |expt|
|
222
|
+
must_not { term expt[0].to_sym, expt[1].to_s }
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
208
226
|
filter(:term, domain: domain_name) unless domain_name.blank?
|
209
227
|
es_block.call(self) if es_block.respond_to?(:call)
|
210
228
|
end
|
@@ -355,18 +373,6 @@ module DataTablesController
|
|
355
373
|
end
|
356
374
|
end
|
357
375
|
|
358
|
-
def elasticsearch_sanitation(search_string, except)
|
359
|
-
logger.debug "*** elasticsearch_sanitation.before = `#{search_string}'"
|
360
|
-
search_string = '*' if search_string.blank?
|
361
|
-
search_string.strip!
|
362
|
-
numerical_search = (search_string.split.count > 1) ? "" : "OR *#{search_string.gsub(":","\\:")}*"
|
363
|
-
search_string = "(\"*#{search_string}*\" #{numerical_search}) " unless search_string =~ /(\*|\")/
|
364
|
-
exceptions = except.map { |f| "NOT #{f[0]}:\"#{f[1]}\""}.join(" AND ") if except
|
365
|
-
search_string += " AND " + exceptions if exceptions
|
366
|
-
logger.debug "*** elasticsearch_sanitation.after = `#{search_string}'"
|
367
|
-
search_string
|
368
|
-
end
|
369
|
-
|
370
376
|
# gets the value for a column and row
|
371
377
|
def datatables_instance_get_value(instance, column)
|
372
378
|
if column[:special]
|
@@ -7,6 +7,12 @@ module DataTablesHelper
|
|
7
7
|
options[:bServerSide] = true unless options.has_key?(:bServerSide)
|
8
8
|
options[:bAutoWidth] = false unless options.has_key?(:bAutoWidth)
|
9
9
|
options[:bStateSave] = true unless options.has_key?(:bStateSave)
|
10
|
+
options[:sScrollY] = "200px"
|
11
|
+
options[:sScrollX] = '100%'
|
12
|
+
options[:bScrollCollapse] = true
|
13
|
+
options[:bDeferRender] = true
|
14
|
+
options[:bScrollInfinite] = true
|
15
|
+
options[:iDisplayLength] = 100
|
10
16
|
options[:oColVis] ||= {}
|
11
17
|
options[:bFilter] = true
|
12
18
|
options[:oColVis][:aiExclude] ||= []
|
@@ -22,6 +28,25 @@ module DataTablesHelper
|
|
22
28
|
}
|
23
29
|
}"
|
24
30
|
|
31
|
+
options[:fnServerData] ||= "function ( sSource, aoData, fnCallback ) {
|
32
|
+
var init_sSearch = $('#init_sSearch');
|
33
|
+
if(init_sSearch != undefined && init_sSearch.val() != '' && init_sSearch.size() != 0) {
|
34
|
+
$('.dataTables_filter input').val(init_sSearch.val());
|
35
|
+
aoData.push( { name:'sSearch', value: init_sSearch.val() });
|
36
|
+
$('#init_sSearch').remove();
|
37
|
+
}
|
38
|
+
$.ajax( {
|
39
|
+
'dataType': 'json',
|
40
|
+
'url': sSource,
|
41
|
+
'data': aoData,
|
42
|
+
'success': fnCallback
|
43
|
+
});
|
44
|
+
}"
|
45
|
+
|
46
|
+
options[:fnDrawCallback] = "function() {
|
47
|
+
change_scrollY();
|
48
|
+
}"
|
49
|
+
|
25
50
|
sdom = options[:bFilter] ? '<"#datatables_search_hint">lfrtip' : 'lrtip'
|
26
51
|
sdom = "C<\"clear\">" + sdom if options[:oColVis]
|
27
52
|
sdom = 'T' + sdom if options[:oTableTools]
|
@@ -71,6 +96,28 @@ $(document).ready(function() {
|
|
71
96
|
} );
|
72
97
|
|
73
98
|
});
|
99
|
+
|
100
|
+
function change_scrollY() {
|
101
|
+
resize_column_width();
|
102
|
+
h = $('##{source}').height();
|
103
|
+
if( h > $(window).height() *55/100 )
|
104
|
+
{
|
105
|
+
$('.dataTables_scrollBody').css('height', ($(window).height() *55/100));
|
106
|
+
}
|
107
|
+
else
|
108
|
+
{
|
109
|
+
$('.dataTables_scrollBody').css('height', h+20);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
function resize_column_width() {
|
114
|
+
$('.dataTables_scrollHeadInner').width('100%');
|
115
|
+
$('.dataTable').width('100%');
|
116
|
+
$('##{datatable[:action]}').dataTable().fnAdjustColumnSizing(false);
|
117
|
+
}
|
118
|
+
|
119
|
+
$(window).resize(change_scrollY);
|
120
|
+
|
74
121
|
</script>
|
75
122
|
<table id=\"#{datatable[:action]}\" #{html_opts}>
|
76
123
|
<thead>
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: data_tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Duane Compton
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-07-
|
16
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
type: :development
|