widget_list 1.0.6 → 1.0.7

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.
@@ -4,7 +4,7 @@ module WidgetList
4
4
  config.before_configuration do
5
5
  config_file = Rails.root.join("config", "widget-list.yml")
6
6
  if config_file.file?
7
- WidgetList::List::connect
7
+ # WidgetList::List::connect
8
8
  else
9
9
  puts "\nWidget List config not found. Creating config/widget-list.yml. \n\nPlease configure it with the appropriate connections"
10
10
  File.open(Rails.root.join("config", "widget-list.yml"), 'w') { |file|
@@ -28,5 +28,15 @@ module WidgetList
28
28
  end
29
29
  end
30
30
 
31
+ initializer "Include widget_list" do
32
+ ActiveSupport.on_load(:action_controller) do
33
+ if WidgetList::List::is_sequel(true) || WidgetList::List::is_sequel(false)
34
+ require 'sequel'
35
+ end
36
+ require 'widget_list/sequel'
37
+ end
38
+ end
39
+
40
+
31
41
  end
32
42
  end
@@ -34,27 +34,35 @@ module Sequel
34
34
  parameters
35
35
  end
36
36
 
37
+ def _convert_active_record_bind(sql='',bind=[])
38
+ unless bind.empty?
39
+ (bind||{}).each { |v|
40
+ sql.sub!(/\?/,v.to_s)
41
+ }
42
+ end
43
+ end
44
+
37
45
  # _exec, pass a block and iterate the total rows
38
46
  #
39
47
  # example
40
48
  #
41
49
  =begin
42
50
  $DATABASE._exec {|i|
43
- asdf = "#{WidgetList::List.get_database.final_results['NAME'][i]}"
51
+ asdf = "#{@final_results['NAME'][i]}"
44
52
  }
45
53
  =end
46
54
  #
47
55
  # Alternatively you could
48
56
  =begin
49
- WidgetList::List.get_database.final_results['ID'].each_with_index { |id,k|
50
- name = WidgetList::List.get_database.final_results['NAME'][k]
51
- price = WidgetList::List.get_database.final_results['PRICE'][k]
57
+ @final_results['ID'].each_with_index { |id,k|
58
+ name = @final_results['NAME'][k]
59
+ price = @final_results['PRICE'][k]
52
60
  }
53
61
  =end
54
62
 
55
63
  def _exec
56
64
  if block_given?
57
- WidgetList::List.get_database.final_count.times {|i|
65
+ @final_count.times {|i|
58
66
  yield i
59
67
  }
60
68
  end
@@ -93,22 +101,29 @@ module Sequel
93
101
  # @param [Hash] replace_in_query
94
102
  # will be a traditional php bind hash {'BIND'=>'value'}. which will replace :BIND in the query. thanks mwild
95
103
 
96
- def _select(sql_or_obj, bind=[], replace_in_query={})
104
+ def _select(sql_or_obj, bind=[], replace_in_query={}, active_record_model=false)
97
105
  # supporting either
98
- # if WidgetList::List.get_database._select('select * from items where name = ? AND price > ?', ['abc', 37]) > 0
106
+ # if get_database._select('select * from items where name = ? AND price > ?', ['abc', 37]) > 0
99
107
  # or
100
- # if WidgetList::List.get_database._select(WidgetList::List.get_database[:items].filter(:name => 'abc')) > 0
108
+ # if get_database._select(get_database[:items].filter(:name => 'abc')) > 0
101
109
  #
102
110
  sql = ''
103
111
  sql = _determine_type(sql_or_obj)
104
112
 
105
- # build csv of bind to eval below (arguments need to be like this for raw SQL passed with bind in Sequel)
106
- #
107
- parameters = _convert_bind(bind)
113
+ if self.class.name != 'WidgetListActiveRecord'
108
114
 
109
- # escape anything incoming in raw SQL such as bound items to create the ruby string to pass
110
- #
111
- sql.gsub!(/'/,"\\\\'")
115
+ # build csv of bind to eval below (arguments need to be like this for raw SQL passed with bind in Sequel)
116
+ #
117
+ parameters = _convert_bind(bind)
118
+
119
+ # escape anything incoming in raw SQL such as bound items to create the ruby string to pass
120
+ #
121
+ sql.gsub!(/'/,"\\\\'")
122
+ else
123
+
124
+ _convert_active_record_bind(sql, bind)
125
+
126
+ end
112
127
 
113
128
  sql = _bind(sql,replace_in_query)
114
129
 
@@ -116,32 +131,56 @@ module Sequel
116
131
  #
117
132
  first = 1
118
133
  cnt = 0
119
- WidgetList::List.get_database.final_results = {}
134
+ @final_results = {}
120
135
 
121
136
  Rails.logger.info(sql)
122
137
 
123
- eval("
124
- begin
125
- WidgetList::List.get_database.errors = false
126
- WidgetList::List.get_database['" + sql + "' " + parameters + "].each { |row|
127
- cnt += 1
128
- row.each { |k,v|
129
- if first == 1
130
- WidgetList::List.get_database.final_results[k.to_s.upcase] = []
131
- end
132
- WidgetList::List.get_database.final_results[k.to_s.upcase] << v
138
+ if self.class.name == 'WidgetListActiveRecord'
139
+ begin
140
+ results = active_record_model.find_by_sql(sql)
141
+ (results||[]).each { |row|
142
+ cnt += 1
143
+ row.attributes.keys.each { |fieldName|
144
+ if first == 1
145
+ @final_results[fieldName.to_s.upcase] = []
146
+ end
147
+ @final_results[fieldName.to_s.upcase] << ((row.send(fieldName).nil?) ? '' : row.send(fieldName))
148
+ }
149
+ first = 0
133
150
  }
134
- first = 0
135
- }
136
- WidgetList::List.get_database.last_sql = WidgetList::List.get_database['" + sql + "' " + parameters + "].get_sql
137
- rescue Exception => e
138
- Rails.logger.info(e)
139
- WidgetList::List.get_database.errors = true
140
- WidgetList::List.get_database.last_error = e.to_s
141
- WidgetList::List.get_database.last_sql = '" + sql + "' + \"\n\n\n\" + ' With Bind => ' + bind.inspect + ' And BindLegacy => ' + replace_in_query.inspect
151
+ @last_sql = sql_or_obj
152
+
153
+ rescue Exception => e
154
+ cnt = 0
155
+ Rails.logger.info(e)
156
+ @errors = true
157
+ @last_error = e.to_s
158
+ @last_sql = sql_or_obj
159
+ end
160
+ else
161
+ eval("
162
+ begin
163
+ @errors = false
164
+ self['" + sql + "' " + parameters + "].each { |row|
165
+ cnt += 1
166
+ row.each { |k,v|
167
+ if first == 1
168
+ @final_results[k.to_s.upcase] = []
169
+ end
170
+ @final_results[k.to_s.upcase] << v
171
+ }
172
+ first = 0
173
+ }
174
+ @last_sql = self['" + sql + "' " + parameters + "].get_sql
175
+ rescue Exception => e
176
+ Rails.logger.info(e)
177
+ @errors = true
178
+ @last_error = e.to_s
179
+ @last_sql = '" + sql + "' + \"\n\n\n\" + ' With Bind => ' + bind.inspect + ' And BindLegacy => ' + replace_in_query.inspect
180
+ end
181
+ ")
142
182
  end
143
- ")
144
- WidgetList::List.get_database.final_count = cnt
183
+ @final_count = cnt
145
184
  return cnt
146
185
  end
147
186
  end
@@ -151,4 +190,25 @@ module Sequel
151
190
  select_sql()
152
191
  end
153
192
  end
193
+ end
194
+
195
+
196
+ class WidgetListActiveRecord < Sequel::Database
197
+ @final_results = {}
198
+ attr_accessor :final_results
199
+
200
+ @errors = false
201
+ attr_accessor :errors
202
+
203
+ @last_error = ''
204
+ attr_accessor :last_error
205
+
206
+ @db_type = ''
207
+ attr_accessor :db_type
208
+
209
+ @final_count = 0
210
+ attr_accessor :final_count
211
+
212
+ @last_sql = ''
213
+ attr_accessor :last_sql
154
214
  end
@@ -1,3 +1,3 @@
1
1
  module WidgetList
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
data/publish_gem.sh CHANGED
@@ -19,7 +19,7 @@ echo 'Next Add *= require '$GEMNAME' to application.css in your rails applicatio
19
19
  echo 'module '$CAMELCASE > lib/$GEMNAME/engine.rb
20
20
  echo ' class Engine < Rails::Engine' >> lib/$GEMNAME/engine.rb
21
21
  echo ' # auto wire' >> lib/$GEMNAME/engine.rb
22
- echo " initializer 'static_assets.load_static_assets' do |app|" >> lib/$GEMNAME/engine.rb
22
+ echo " initializer '""$GEMNAME"".load_static_assets' do |app|" >> lib/$GEMNAME/engine.rb
23
23
  echo ' app.middleware.use ::ActionDispatch::Static, "#{root}/vendor"' >> lib/$GEMNAME/engine.rb
24
24
  echo ' end' >> lib/$GEMNAME/engine.rb
25
25
  echo ' end' >> lib/$GEMNAME/engine.rb
@@ -174,13 +174,17 @@ function ajaxStatus(eToHide, fadeInOut)
174
174
  }
175
175
 
176
176
 
177
- function ListChangeGrouping(listId)
177
+ function ListChangeGrouping(listId, obj, extra)
178
178
  {
179
+ if (typeof(extra) == 'undefined')
180
+ {
181
+ var extra = '';
182
+ }
179
183
  ajaxStatus(listId, 1);
180
184
  HideAdvancedSearch(jQuery('#' + listId + '-group'));
181
185
  jQuery('#list_search_id_' + listId ).val('');
182
186
  InitInfoFields(jQuery('#list_search_id_' + listId));
183
- ListJumpMin(jQuery('#' + listId + '_jump_url').val() + '&searchClear=1&switch_grouping=' + jQuery('#list_group_id_' + listId ).val(), listId);
187
+ ListJumpMin(jQuery('#' + listId + '_jump_url').val() + '&searchClear=1&switch_grouping=' + jQuery('#list_group_id_' + listId ).val() + '&group_row_id=' + jQuery(obj).attr('id') + extra , listId);
184
188
  }
185
189
 
186
190
  function ListHome(listId)
@@ -190,7 +194,7 @@ function ListHome(listId)
190
194
  });
191
195
  }
192
196
 
193
- function ListDrillDown(mode,data,listId)
197
+ function ListDrillDown(mode, data, listId, extra)
194
198
  {
195
199
  jQuery('#list_search_id_' + listId).val('');
196
200
  var grouping = '';
@@ -198,7 +202,7 @@ function ListDrillDown(mode,data,listId)
198
202
  {
199
203
  grouping = '&switch_grouping=' + jQuery('#list_group_id_' + listId).val();
200
204
  }
201
- ListJumpMin(jQuery('#' + listId + '_jump_url').val() + '&drill_down=' + mode + '&filter=' + data + grouping + '&search_filter=', listId, function(){
205
+ ListJumpMin(jQuery('#' + listId + '_jump_url').val() + '&drill_down=' + mode + '&filter=' + data + grouping + '&search_filter=' + extra, listId, function(){
202
206
  InitInfoFields(jQuery('#list_search_id_' + listId));
203
207
  });
204
208
  }
@@ -228,6 +232,67 @@ function ListJumpResponse(response)
228
232
  }
229
233
  }
230
234
 
235
+ /**
236
+ * ListMessagePopup()
237
+ */
238
+ function ListMessagePopup(id, html, hieght, width)
239
+ {
240
+ jQuery('.ajaxLoad,.ajaxLoad2').remove();
241
+ if (typeof(hieght) =="undefined")
242
+ {
243
+ var hieght = '200'
244
+ }
245
+ if (typeof(width) =="undefined")
246
+ {
247
+ var width = '400'
248
+ }
249
+
250
+ if(document.getElementById(id))
251
+ {
252
+ elmToHide = document.getElementById(id);
253
+ var overLay = '<div style="position:relative;top:0px;"><div id="loading' + id + '" class="ajaxLoad" style="height:' + jQuery(elmToHide).height() + 'px;width:' + jQuery(elmToHide).width() + 'px;top:-' + jQuery(elmToHide).height() + 'px;"></div></div><div class="ajaxLoad2" id="message' + id + '" style="height:' + hieght + 'px;width:' + width + 'px;left:100px;top:200px;left:250px;z-index: 1000;background-position: 50% 50%;position: absolute;display: block;border:2px solid #dadada;box-shadow:0 2px 4px #c0c0c0;text-align:center;background-color:#FFFFFF;padding:15px;">' + html + '</div>';
254
+
255
+ jQuery(elmToHide).append(overLay);
256
+
257
+ jQuery('#message' + id).children( ).each( function( index )
258
+ {
259
+ jQuery( this ).addClass( 'tmp-popup-class' );
260
+ });
261
+
262
+ jQuery('#loading' + id).fadeTo("fast", .20);
263
+
264
+ jQuery('html,body').animate({scrollTop: jQuery('#message' + id).offset().top - 100 }, 400);
265
+ }
266
+
267
+ jQuery("body").unbind('click');
268
+
269
+ setTimeout(function() {
270
+ jQuery("body").click
271
+ (
272
+ function(e)
273
+ {
274
+ if(e.target.id == 'message' + id || e.target.className == 'tmp-popup-class')
275
+ {
276
+ return false;
277
+ }
278
+ if (jQuery('#' + e.target.id).parents('#message' + id).length == 0 || (e.target.id != 'message' + id && jQuery('#' + e.target.id).parents('#message' + id).length != 1))
279
+ {
280
+ jQuery('#message' + id + ', #loading'+ id).remove();
281
+ }
282
+ }
283
+ );
284
+ }, 1000);
285
+ }
286
+
287
+ /**
288
+ * ListMessageClose()
289
+ */
290
+ function ListMessageClose()
291
+ {
292
+ jQuery('.ajaxLoad,.ajaxLoad2').remove();
293
+ }
294
+
295
+
231
296
  /**
232
297
  * ListJumpMin()
233
298
  */
@@ -1,7 +1,7 @@
1
1
  .widget_list_outer
2
2
  {
3
- padding-left: 15px;
4
- padding-right: 15px;
3
+ padding-left: 6px;
4
+ padding-right: 13px;
5
5
  }
6
6
 
7
7
  .horizontal_rule
@@ -768,10 +768,10 @@ ul#pagination li div.active
768
768
  */
769
769
  div#advanced-search-container ul.advanced-search-container-inline, div#advanced-search-container ul {list-style:none; margin:0px; padding:3px; height:51px; width:450px}
770
770
  div#advanced-search-container ul.advanced-search-container-inline input.info-input, div#advanced-search-container ul input.info-input {font-size:11px}
771
- div#advanced-search-container ul.advanced-search-container-inline li {display:inline-block;width:150px; margin-top:4px;}
771
+ div#advanced-search-container ul.advanced-search-container-inline li {display:inline-block;width:428px; margin-top:4px;}
772
772
  div#advanced-search-container ul.advanced-search-container-inline li#required_message_inline {font-size:10px}
773
773
  div#advanced-search-container ul.advanced-search-container-inline li#required_message_inline div.required {top:4px}
774
- div#advanced-search-container ul#search_columns li {width:190px}
774
+ div#advanced-search-container ul#search_columns li {width:428px}
775
775
 
776
776
 
777
777
  /**
data/widget_list.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{An Advanced and flexible ajax data grid. Outside of all of the RAILS Active record CRAP!}
12
12
  gem.summary = %q{In rails you have will_paginate and other gems like it using the ActiveRecord approach, but widget_list adds some awesome treats to standard boring pagers}
13
13
  gem.homepage = "https://github.com/davidrenne/widget_list"
14
- gem.add_dependency('sequel', '3.42.0')
14
+ gem.add_dependency('sequel', '3.42.0') # SEQUEL IS NOW OPTIONAL!! I am sure most people will be using ActiveRecord ORM
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: widget_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-21 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel