widget_list 1.3.7 → 2.0.1

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.
Files changed (35) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +143 -696
  3. data/app/views/widget_list/administration/_button_row.html.erb +2 -2
  4. data/app/views/widget_list/administration/_field_row.html.erb +2 -2
  5. data/app/views/widget_list/administration/_output.html.erb +89 -55
  6. data/checkin_gem.sh +10 -10
  7. data/docs/legacy-readme.md +757 -0
  8. data/docs/screenshots/admin1.jpg +0 -0
  9. data/docs/screenshots/admin2.jpg +0 -0
  10. data/docs/screenshots/admin3.jpg +0 -0
  11. data/docs/screenshots/admin4.jpg +0 -0
  12. data/docs/screenshots/admin5.png +0 -0
  13. data/docs/screenshots/admin6.png +0 -0
  14. data/docs/screenshots/filtered.png +0 -0
  15. data/docs/screenshots/main.png +0 -0
  16. data/docs/screenshots/ransack1.png +0 -0
  17. data/docs/screenshots/ransack2.png +0 -0
  18. data/docs/screenshots/ransack3.png +0 -0
  19. data/docs/screenshots/search.png +0 -0
  20. data/docs/screenshots/theme_blue_sky_basin.png +0 -0
  21. data/docs/widget-list-demo-thumbnail.png +0 -0
  22. data/lib/extensions/action_controller_base.rb +22 -29
  23. data/lib/widget_list/engine.rb +1 -4
  24. data/lib/widget_list/railtie.rb +10 -33
  25. data/lib/widget_list/request_context.rb +5 -0
  26. data/lib/widget_list/sequel.rb +17 -41
  27. data/lib/widget_list/utils.rb +7 -7
  28. data/lib/widget_list/version.rb +1 -1
  29. data/lib/widget_list/widgets.rb +1 -2
  30. data/lib/widget_list.rb +267 -269
  31. data/publish_gem.sh +14 -35
  32. data/vendor/assets/stylesheets/{widget_list.css → widget_list.css.erb} +21 -21
  33. data/vendor/assets/stylesheets/{widgets.css → widgets.css.erb} +9 -9
  34. data/widget_list.gemspec +8 -10
  35. metadata +58 -32
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,33 +1,26 @@
1
1
  require 'action_controller'
2
2
 
3
- ActionController::Base.class_eval {
4
- private
5
- def globalize_request
6
- # Create super global PHP variables
7
- $_SESSION = self.session
8
- $_SERVER = self.env
9
- $_REQUEST = self.request.filtered_parameters
3
+ module WidgetList
4
+ module ControllerContext
5
+ private
6
+
7
+ def with_widget_list_request_context
8
+ RequestContext.session = session.to_h.deep_dup
9
+ RequestContext.server = request.env
10
+ RequestContext.request = request.filtered_parameters
11
+ RequestContext.csrf_token = form_authenticity_token
12
+
13
+ yield
14
+ ensure
15
+ if RequestContext.used && RequestContext.session
16
+ %w[pageDisplayLimit DRILL_DOWNS CURRENT_GROUPING ROW_LIMIT list_checks SEARCH_FILTER LIST_SEQUENCE LIST_COL_SORT list_count DRILL_DOWN_FILTERS].each do |key|
17
+ session[key] = RequestContext.session[key] if RequestContext.session.key?(key)
18
+ end
19
+ end
20
+ RequestContext.reset
10
21
  end
22
+ end
23
+ end
11
24
 
12
- private
13
- def store_session
14
- # Store pre-defined widget_list session items to the actual session
15
-
16
- %w(pageDisplayLimit DRILL_DOWNS CURRENT_GROUPING ROW_LIMIT list_checks SEARCH_FILTER LIST_SEQUENCE LIST_COL_SORT list_count DRILL_DOWN_FILTERS).each { |key|
17
- self.session[key] = $_SESSION[key]
18
- }
19
-
20
- test= 1
21
- end
22
- }
23
-
24
- ActionController::Base.instance_eval {
25
- helper_method :globalize_request
26
-
27
- helper_method :store_session
28
-
29
- before_filter :globalize_request
30
-
31
- after_filter :store_session
32
- }
33
-
25
+ ActionController::Base.include(WidgetList::ControllerContext)
26
+ ActionController::Base.around_action :with_widget_list_request_context
@@ -1,8 +1,5 @@
1
1
  module WidgetList
2
2
  class Engine < Rails::Engine
3
- # auto wire
4
- initializer 'widget_list.load_static_assets' do |app|
5
- app.middleware.use ::ActionDispatch::Static, "#{root}/vendor"
6
- end
3
+ # Rails discovers gem assets in vendor/assets through its asset pipeline.
7
4
  end
8
5
  end
@@ -1,42 +1,19 @@
1
1
  module WidgetList
2
2
  class Railtie < Rails::Railtie
3
-
4
- config.before_configuration do
5
- config_file = Rails.root.join("config", "widget-list.yml")
6
- if config_file.file?
7
- # WidgetList::List::connect
8
- else
9
- puts "\nWidget List config not found. Creating config/widget-list.yml. \n\nPlease configure it with the appropriate connections"
10
- File.open(Rails.root.join("config", "widget-list.yml"), 'w') { |file|
11
- file.write("#For connection examples see: http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html\n\n")
12
- file.write("development:\n")
13
- file.write(" :primary: sqlite:/\n")
14
- file.write(" :secondary: sqlite:/\n")
15
- file.write("\n")
16
- file.write("test:\n")
17
- file.write(" :primary: sqlite:/\n")
18
- file.write(" :secondary: sqlite:/\n")
19
- file.write("\n")
20
- file.write("release:\n")
21
- file.write(" :primary: sqlite:/\n")
22
- file.write(" :secondary: sqlite:/\n")
23
- file.write("\n")
24
- file.write("production:\n")
25
- file.write(" :primary: sqlite:/\n")
26
- file.write(" :secondary: sqlite:/\n")
27
- }
28
- end
29
- end
30
-
31
- initializer "Include widget_list" do
3
+ initializer 'widget_list.database_adapters' do
32
4
  ActiveSupport.on_load(:action_controller) do
33
- if WidgetList::List::is_sequel(true) || WidgetList::List::is_sequel(false)
34
- require 'sequel'
35
- end
5
+ require 'sequel'
36
6
  require 'widget_list/sequel'
37
7
  end
38
8
  end
39
9
 
40
-
10
+ initializer 'widget_list.assets' do |app|
11
+ if defined?(Sprockets::Railtie) && app.config.respond_to?(:assets)
12
+ image_root = Pathname.new(__dir__).join('../..', 'vendor/assets/images').expand_path
13
+ images = Dir[image_root.join('**/*')].select { |path| File.file?(path) && %w[.gif .jpg .jpeg .png].include?(File.extname(path).downcase) }
14
+ app.config.assets.precompile += images.map { |path| Pathname.new(path).relative_path_from(image_root).to_s }
15
+ app.config.assets.precompile += %w[widget_list.css widgets.css widget_list.js]
16
+ end
17
+ end
41
18
  end
42
19
  end
@@ -0,0 +1,5 @@
1
+ module WidgetList
2
+ class RequestContext < ActiveSupport::CurrentAttributes
3
+ attribute :request, :server, :session, :used, :csrf_token
4
+ end
5
+ end
@@ -111,32 +111,14 @@ module Sequel
111
111
  # or
112
112
  # if get_database._select(get_database[:items].filter(:name => 'abc')) > 0
113
113
  #
114
- sql = ''
115
114
  sql = _determine_type(sql_or_obj)
116
-
117
- if self.class.name != 'WidgetListActiveRecord'
118
-
119
- # build csv of bind to eval below (arguments need to be like this for raw SQL passed with bind in Sequel)
120
- #
121
- parameters = _convert_bind(bind)
122
-
123
- # escape anything incoming in raw SQL such as bound items to create the ruby string to pass
124
- #
125
- sql.gsub!(/'/,"\\\\'")
126
- else
127
-
128
- _convert_active_record_bind(sql, bind)
129
-
130
- end
131
-
132
115
  sql = _bind(sql,replace_in_query)
133
116
 
134
117
  # build rows array['COLUMN'][0] = 1234;
135
118
  #
136
- first = 1
137
119
  cnt = 0
138
- tmp = nil
139
120
  @final_results = {}
121
+ @errors = false
140
122
  if Rails.env == 'development'
141
123
  Rails.logger.info(sql)
142
124
  end
@@ -194,7 +176,7 @@ module Sequel
194
176
  results = active_record_model.all.to_a if active_record_model.respond_to?('all')
195
177
  results = active_record_model.to_a if active_record_model.respond_to?('to_a') && !group_match.nil?
196
178
  else
197
- results = active_record_model.find_by_sql(sql)
179
+ results = active_record_model.find_by_sql(bind.empty? ? sql : [sql, *bind])
198
180
  end
199
181
 
200
182
  (results||[]).each { |row|
@@ -232,27 +214,21 @@ module Sequel
232
214
  @last_sql = sql_or_obj
233
215
  end
234
216
  else
235
- eval("
236
- begin
237
- @errors = false
238
- self['" + sql + "' " + parameters + "].each { |row|
239
- cnt += 1
240
- row.each { |k,v|
241
- if first == 1
242
- @final_results[k.to_s.upcase] = []
243
- end
244
- @final_results[k.to_s.upcase] << v
245
- }
246
- first = 0
247
- }
248
- @last_sql = self['" + sql + "' " + parameters + "].get_sql
249
- rescue Exception => e
250
- Rails.logger.info(e)
251
- @errors = true
252
- @last_error = e.to_s
253
- @last_sql = '" + sql + "' + \"\n\n\n\" + ' With Bind => ' + bind.inspect + ' And BindLegacy => ' + replace_in_query.inspect
217
+ begin
218
+ dataset = sql_or_obj.is_a?(Sequel::Dataset) ? sql_or_obj : fetch(sql, *bind)
219
+ dataset.each do |row|
220
+ cnt += 1
221
+ row.each do |key, value|
222
+ (@final_results[key.to_s.upcase] ||= []) << value
223
+ end
254
224
  end
255
- ")
225
+ @last_sql = dataset.sql
226
+ rescue StandardError => e
227
+ Rails.logger.info(e)
228
+ @errors = true
229
+ @last_error = e.to_s
230
+ @last_sql = "#{sql}\nWith Bind => #{bind.inspect} And BindLegacy => #{replace_in_query.inspect}"
231
+ end
256
232
  end
257
233
  @final_count = cnt
258
234
  return cnt
@@ -285,4 +261,4 @@ class WidgetListActiveRecord < Sequel::Database
285
261
 
286
262
  @last_sql = ''
287
263
  attr_accessor :last_sql
288
- end
264
+ end
@@ -25,10 +25,10 @@ module WidgetList
25
25
  def self.build_query_string(args)
26
26
  q = []
27
27
  args.each { |k,v|
28
- if v.class.name == 'Hash'
29
- q << {k => v}.to_params
28
+ if v.is_a?(Hash) || v.respond_to?(:to_unsafe_h)
29
+ q << {k => (v.respond_to?(:to_unsafe_h) ? v.to_unsafe_h : v)}.to_query
30
30
  else
31
- q << k.to_s + '=' + CGI.escape(URI.decode(v.to_s))
31
+ q << k.to_s + '=' + CGI.escape(v.to_s)
32
32
  end
33
33
  }
34
34
  q.join('&')
@@ -39,8 +39,8 @@ module WidgetList
39
39
  def self.build_url(page='',args = {}, append_get=false)
40
40
  qs = build_query_string(args)
41
41
  getvars = ''
42
- if append_get && $_REQUEST
43
- getvars = build_query_string($_REQUEST)
42
+ if append_get && WidgetList::RequestContext.request
43
+ getvars = build_query_string(WidgetList::RequestContext.request)
44
44
  end
45
45
 
46
46
  unless page =~ /\?/
@@ -54,7 +54,7 @@ module WidgetList
54
54
  def self.fill(tags = {}, template = '')
55
55
  tpl = template.dup
56
56
  tags.each { |k,v|
57
- tpl = tpl.gsub(k.to_s,v.to_s)
57
+ tpl = tpl.gsub(k.to_s) { v.to_s }
58
58
  }
59
59
  tpl
60
60
  end
@@ -92,4 +92,4 @@ module WidgetList
92
92
 
93
93
  end
94
94
 
95
- end
95
+ end
@@ -1,3 +1,3 @@
1
1
  module WidgetList
2
- VERSION = "1.3.7"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -62,7 +62,6 @@ module WidgetList
62
62
  '<!--VALUE-->' => items['value'],
63
63
  '<!--REQUIRED-->' => items['template_required'],
64
64
  '<!--CHECKED-->' => items['checked'],
65
- '<!--VALUE-->' => items['value'],
66
65
  '<!--DISABLED-->' => items['disabled']
67
66
  }
68
67
 
@@ -761,4 +760,4 @@ end
761
760
  # require 'widget_list/utils'
762
761
  # require 'widget_list/hash'
763
762
  # require 'widget_list/tpl'
764
- # puts WidgetList::Widgets.test_all
763
+ # puts WidgetList::Widgets.test_all