widget_list 1.0.5 → 1.0.6

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/README.md CHANGED
@@ -82,6 +82,9 @@ I recommend if you use widget_list in production that you use config.consider_al
82
82
 
83
83
  Add config/routes.rb if it is not in there:
84
84
  match ':controller(/:action)'
85
+
86
+ Ensure that sessions are loaded into active record because widget_list keeps track of several settings on each list for each session
87
+ config.session_store :active_record_store
85
88
 
86
89
  Add the example shown below to app/controllers/widget_list_examples_controller.rb#ruby_items
87
90
 
@@ -93,21 +96,22 @@ I recommend if you use widget_list in production that you use config.consider_al
93
96
  #
94
97
  # Load Sample "items" Data. Comment out in your first time executing a widgetlist to create the items table
95
98
  #
96
- begin
99
+ begin
97
100
  WidgetList::List.get_database.create_table :items do
98
101
  primary_key :id
99
102
  String :name
100
103
  Float :price
101
- Int :sku
104
+ Fixnum :sku
105
+ String :active
102
106
  Date :date_added
103
107
  end
104
108
  items = WidgetList::List.get_database[:items]
105
109
  100.times {
106
- items.insert(:name => 'abc', :price => rand * 100, :date_added => '2008-02-01', :sku => 12345)
107
- items.insert(:name => '123', :price => rand * 100, :date_added => '2008-02-02', :sku => 54321)
108
- items.insert(:name => 'asdf', :price => rand * 100, :date_added => '2008-02-03', :sku => 67895)
109
- items.insert(:name => 'qwerty', :price => rand * 100, :date_added => '2008-02-04', :sku => 66666)
110
- items.insert(:name => 'poop', :price => rand * 100, :date_added => '2008-02-05', :sku => 77777)
110
+ items.insert(:name => 'ab\'c_quoted_' + rand(35).to_s, :price => rand * 100, :date_added => '2008-02-01', :sku => rand(9999), :active => 'Yes')
111
+ items.insert(:name => '12"3_' + rand(35).to_s, :price => rand * 100, :date_added => '2008-02-02', :sku => rand(9999), :active => 'Yes')
112
+ items.insert(:name => 'asdf_' + rand(35).to_s, :price => rand * 100, :date_added => '2008-02-03', :sku => rand(9999), :active => 'Yes')
113
+ items.insert(:name => 'qwerty_' + rand(35).to_s, :price => rand * 100, :date_added => '2008-02-04', :sku => rand(9999), :active => 'No')
114
+ items.insert(:name => 'meow_' + rand(35).to_s, :price => rand * 100, :date_added => '2008-02-05', :sku => rand(9999), :active => 'No')
111
115
  }
112
116
  rescue Exception => e
113
117
  #
@@ -115,251 +119,268 @@ I recommend if you use widget_list in production that you use config.consider_al
115
119
  #
116
120
  logger.info "Test table in items already exists? " + e.to_s
117
121
  end
118
-
119
- list_parms = {}
120
122
 
121
- #
122
- # Give it a name, some SQL to feed widget_list and set a noDataMessage
123
- #
124
- list_parms['name'] = 'ruby_items_yum'
123
+ begin
125
124
 
126
- #
127
- # Handle Dynamic Filters
128
- #
129
- if $_REQUEST.key?('switch_grouping') && $_REQUEST['switch_grouping'] == 'Item Name'
130
- groupByFilter = 'item'
131
- countSQL = 'COUNT(1) as cnt,'
132
- groupBySQL = 'GROUP BY name'
133
- elsif $_REQUEST.key?('switch_grouping') && $_REQUEST['switch_grouping'] == 'Sku Number'
134
- groupByFilter = 'sku'
135
- countSQL = 'COUNT(1) as cnt,'
136
- groupBySQL = 'GROUP BY sku'
137
- else
138
- groupByFilter = 'none'
139
- countSQL = ''
140
- groupBySQL = ''
141
- end
125
+ list_parms = {}
142
126
 
143
- list_parms['filter'] = []
144
- drillDown, filterValue = WidgetList::List::get_filter_and_drilldown(list_parms['name'])
127
+ #
128
+ # Give it a name, some SQL to feed widget_list and set a noDataMessage
129
+ #
130
+ list_parms['name'] = 'ruby_items_yum'
145
131
 
146
- case drillDown
147
- when 'filter_by_name'
148
- list_parms['filter'] << " name = '" + filterValue + "'"
149
- when 'filter_by_sku'
150
- list_parms['filter'] << " sku = '" + filterValue + "'"
151
- end
132
+ #
133
+ # Handle Dynamic Filters
134
+ #
135
+ if $_REQUEST.key?('switch_grouping') && $_REQUEST['switch_grouping'] == 'Item Name'
136
+ groupByFilter = 'item'
137
+ countSQL = 'COUNT(1) as cnt,'
138
+ groupBySQL = 'GROUP BY name'
139
+ groupByDesc = ' (Grouped By Name)'
140
+ elsif $_REQUEST.key?('switch_grouping') && $_REQUEST['switch_grouping'] == 'Sku Number'
141
+ groupByFilter = 'sku'
142
+ countSQL = 'COUNT(1) as cnt,'
143
+ groupBySQL = 'GROUP BY sku'
144
+ groupByDesc = ' (Grouped By Sku Number)'
145
+ else
146
+ groupByFilter = 'none'
147
+ countSQL = ''
148
+ groupBySQL = ''
149
+ groupByDesc = ''
150
+ end
152
151
 
152
+ list_parms['filter'] = []
153
+ list_parms['bindVars'] = []
154
+ drillDown, filterValue = WidgetList::List::get_filter_and_drilldown(list_parms['name'])
155
+
156
+ case drillDown
157
+ when 'filter_by_name'
158
+ list_parms['filter'] << " name = ? "
159
+ list_parms['bindVars'] << filterValue
160
+ list_parms['listDescription'] = WidgetList::List::drill_down_back(list_parms['name']) + ' Filtered by Name (' + filterValue + ')' + groupByDesc
161
+ when 'filter_by_sku'
162
+ list_parms['filter'] << " sku = ? "
163
+ list_parms['bindVars'] << filterValue
164
+ list_parms['listDescription'] = WidgetList::List::drill_down_back(list_parms['name']) + ' Filtered by SKU (' + filterValue + ')' + groupByDesc
165
+ else
166
+ list_parms['listDescription'] = ''
167
+ list_parms['listDescription'] = WidgetList::List::drill_down_back(list_parms['name']) if !groupByDesc.empty?
168
+ list_parms['listDescription'] += 'Showing All Ruby Items' + groupByDesc
169
+ end
153
170
 
154
171
 
155
- #
156
- # Setup your first widget_list
157
- #
158
172
 
159
- button_column_name = 'actions'
173
+ #
174
+ # Setup your first widget_list
175
+ #
160
176
 
161
- #
162
- # action_buttons will add buttons to the bottom of the list.
163
- #
177
+ button_column_name = 'actions'
164
178
 
165
- action_buttons = WidgetList::Widgets::widget_button('Add New Item', {'page' => '/add/'} ) + WidgetList::Widgets::widget_button('Do something else', {'page' => '/else/'} )
179
+ #
180
+ # action_buttons will add buttons to the bottom of the list.
181
+ #
166
182
 
167
- #
168
- # Give some SQL to feed widget_list and set a noDataMessage
169
- #
170
- list_parms['searchIdCol'] = ['id','sku']
171
- list_parms['view'] = '(
172
- SELECT
173
- ' + countSQL + '
174
- ' + WidgetList::List::build_drill_down_link(list_parms['name'],'filter_by_name','a.name','a.name','name_linked') + '
175
- ' + WidgetList::List::build_drill_down_link(list_parms['name'],'filter_by_sku','a.sku','a.sku','sku_linked') + '
176
- \'\' AS checkbox,
177
- a.id AS id,
178
- a.name AS name,
179
- a.sku AS sku,
180
- a.price AS price,
181
- a.date_added AS date_added
182
- FROM
183
- items a
184
- ' + groupBySQL + '
185
- ) a'
186
- list_parms['noDataMessage'] = 'No Ruby Items Found'
187
- list_parms['title'] = 'Ruby Items!!!'
183
+ action_buttons = WidgetList::Widgets::widget_button('Add New Item', {'page' => '/add/'} ) + WidgetList::Widgets::widget_button('Do something else', {'page' => '/else/'} )
188
184
 
189
- #
190
- # Create small button array and pass to the buttons key
191
- #
185
+ #
186
+ # Give some SQL to feed widget_list and set a noDataMessage
187
+ #
188
+ list_parms['searchIdCol'] = ['id','sku']
189
+ list_parms['view'] = '(
190
+ SELECT
191
+ ' + countSQL + '
192
+ \'\' AS checkbox,
193
+ ' + WidgetList::List::build_drill_down_link(list_parms['name'],'filter_by_name','a.name','a.name','name_linked') + '
194
+ ' + WidgetList::List::build_drill_down_link(list_parms['name'],'filter_by_sku','a.sku','a.sku','sku_linked') + '
195
+ a.id AS id,
196
+ a.active AS active,
197
+ a.name AS name,
198
+ a.sku AS sku,
199
+ a.price AS price,
200
+ a.date_added AS date_added
201
+ FROM
202
+ items a
203
+ ' + groupBySQL + '
204
+ ) a'
205
+ list_parms['noDataMessage'] = 'No Ruby Items Found'
206
+ list_parms['title'] = 'Ruby Items!!!'
207
+
208
+ #
209
+ # Create small button array and pass to the buttons key
210
+ #
192
211
 
193
- mini_buttons = {}
194
- mini_buttons['button_edit'] = {'page' => '/edit',
195
- 'text' => 'Edit',
196
- 'function' => 'Redirect',
197
- #pass tags to pull from each column when building the URL
198
- 'tags' => {'my_key_name' => 'name','value_from_database'=>'price'}}
199
-
200
- mini_buttons['button_delete'] = {'page' => '/delete',
201
- 'text' => 'Delete',
202
- 'function' => 'alert',
203
- 'innerClass' => 'danger'}
204
- list_parms['buttons'] = {button_column_name => mini_buttons}
205
- list_parms['fieldFunction'] = {
206
- button_column_name => "''",
207
- 'date_added' => ['postgres','oracle'].include?(WidgetList::List.get_database.db_type) ? "TO_CHAR(date_added, 'MM/DD/YYYY')" : "date_added"
208
- }
209
- list_parms['groupByItems'] = ['All Records','Item Name', 'Sku Number']
212
+ mini_buttons = {}
213
+ mini_buttons['button_edit'] = {'page' => '/edit',
214
+ 'text' => 'Edit',
215
+ 'function' => 'Redirect',
216
+ #pass tags to pull from each column when building the URL
217
+ 'tags' => {'my_key_name' => 'name','value_from_database'=>'price'}}
218
+
219
+ mini_buttons['button_delete'] = {'page' => '/delete',
220
+ 'text' => 'Delete',
221
+ 'function' => 'alert',
222
+ 'innerClass' => 'danger'}
223
+ list_parms['buttons'] = {button_column_name => mini_buttons}
224
+ list_parms['fieldFunction'] = {
225
+ button_column_name => "''",
226
+ 'date_added' => ['postgres','oracle'].include?(WidgetList::List.get_database.db_type) ? "TO_CHAR(date_added, 'MM/DD/YYYY')" : "date_added"
227
+ }
228
+
229
+ list_parms['groupByItems'] = ['All Records', 'Item Name', 'Sku Number']
210
230
 
211
- #
212
- # Generate a template for the DOWN ARROW for CUSTOM FILTER
213
- #
231
+ #
232
+ # Generate a template for the DOWN ARROW for CUSTOM FILTER
233
+ #
234
+ input = {}
235
+
236
+ input['id'] = 'comments'
237
+ input['name'] = 'comments'
238
+ input['width'] = '170'
239
+ input['max_length'] = '500'
240
+ input['input_class'] = 'info-input'
241
+ input['title'] = 'Optional CSV list'
242
+
243
+ button_search = {}
244
+ button_search['onclick'] = "alert('This would search, but is not coded. That is for you to do')"
245
+
246
+ list_parms['list_search_form'] = WidgetList::Utils::fill( {
247
+ '<!--BUTTON_SEARCH-->' => WidgetList::Widgets::widget_button('Search', button_search),
248
+ '<!--COMMENTS-->' => WidgetList::Widgets::widget_input(input),
249
+ '<!--BUTTON_CLOSE-->' => "HideAdvancedSearch(this)" } ,
250
+ '
251
+ <div id="advanced-search-container">
252
+ <div class="widget-search-drilldown-close" onclick="<!--BUTTON_CLOSE-->">X</div>
253
+ <ul class="advanced-search-container-inline" id="search_columns">
254
+ <li>
255
+ <div>Search Comments</div>
256
+ <!--COMMENTS-->
257
+ </li>
258
+ </ul>
259
+ <br/>
260
+ <div style="text-align:right;width:100%;height:30px;" class="advanced-search-container-buttons"><!--BUTTON_RESET--><!--BUTTON_SEARCH--></div>
261
+ </div>')
214
262
 
215
- template = {}
216
- input = {}
217
-
218
- input['id'] = 'comments'
219
- input['name'] = 'comments'
220
- input['width'] = '170'
221
- input['max_length'] = '500'
222
- input['input_class'] = 'info-input'
223
- input['title'] = 'Optional CSV list'
224
-
225
- button_search = {}
226
- button_search['innerClass'] = "success btn-submit"
227
- button_search['onclick'] = "alert('This would search, but is not coded. That is for you to do')"
228
-
229
- list_parms['list_search_form'] = WidgetList::Utils::fill( {
230
- '<!--COMMENTS-->' => WidgetList::Widgets::widget_input(input),
231
- '<!--BUTTON_SEARCH-->' => WidgetList::Widgets::widget_button('Search', button_search),
232
- '<!--BUTTON_CLOSE-->' => "HideAdvancedSearch(this)" } ,
233
- '
234
- <div id="advanced-search-container">
235
- <div class="widget-search-drilldown-close" onclick="<!--BUTTON_CLOSE-->">X</div>
236
- <ul class="advanced-search-container-inline" id="search_columns">
237
- <li>
238
- <div>Search Comments</div>
239
- <!--COMMENTS-->
240
- </li>
241
- </ul>
242
- <br/>
243
- <div style="text-align:right;width:100%;height:30px;" class="advanced-search-container-buttons"><!--BUTTON_RESET--><!--BUTTON_SEARCH--></div>
244
- </div>')
263
+ #
264
+ # Control widths of special fields
265
+ #
245
266
 
246
- #
247
- # Map out the visible fields
248
- #
267
+ list_parms['columnWidth'] = {
268
+ 'date_added'=>'200px',
269
+ 'sku_linked'=>'20px',
270
+ }
249
271
 
250
- list_parms.deep_merge!({'fields' =>
251
- {
252
- 'checkbox'=> 'checkbox_header',
253
- }
254
- })
255
-
256
- list_parms.deep_merge!({'fields' =>
257
- {
258
- 'cnt'=> 'Total Items In Group',
259
- }
260
- }) if groupByFilter != 'none'
261
-
262
- list_parms.deep_merge!({'fields' =>
263
- {
264
- 'id'=> 'Item Id',
265
- }
266
- }) if groupByFilter == 'none'
267
-
268
- list_parms.deep_merge!({'fields' =>
269
- {
270
- 'name_linked'=> 'Name',
271
- }
272
- }) if groupByFilter == 'none' or groupByFilter == 'item'
273
-
274
- list_parms.deep_merge!({'fields' =>
275
- {
276
- 'price'=> 'Price of Item',
277
- }
278
- }) if groupByFilter == 'none'
279
-
280
- list_parms.deep_merge!({'fields' =>
281
- {
282
- 'sku_linked'=> 'Sku #',
283
- }
284
- }) if groupByFilter == 'none' or groupByFilter == 'sku'
285
-
286
- list_parms.deep_merge!({'fields' =>
287
- {
288
- 'date_added'=> 'Date Added',
289
- }
290
- }) if groupByFilter == 'none'
291
-
292
- list_parms.deep_merge!({'fields' =>
293
- {
294
- button_column_name => button_column_name.capitalize,
295
- }
296
- })
272
+ #
273
+ # If certain statuses of records are shown, visualize
274
+ #
297
275
 
298
- #
299
- # Setup a custom field for checkboxes stored into the session and reloaded when refresh occurs
300
- #
276
+ list_parms.deep_merge!({'rowStylesByStatus' =>
277
+ {'active'=>
278
+ {'Yes' => '' }
279
+ }
280
+ })
281
+ list_parms.deep_merge!({'rowStylesByStatus' =>
282
+ {'active'=>
283
+ {'No' => 'font-style:italic;color:red;' }
284
+ }
285
+ })
286
+
287
+ #
288
+ # Map out the visible fields
289
+ #
290
+ list_parms['fields'] = {}
291
+ list_parms['fields']['checkbox'] = 'checkbox_header'
292
+ list_parms['fields']['cnt'] = 'Total Items In Group' if groupByFilter != 'none'
293
+ list_parms['fields']['id'] = 'Item Id' if groupByFilter == 'none'
294
+ list_parms['fields']['name_linked'] = 'Name' if groupByFilter == 'none' or groupByFilter == 'item'
295
+ list_parms['fields']['price'] = 'Price of Item' if groupByFilter == 'none'
296
+ list_parms['fields']['sku_linked'] = 'Sku #' if groupByFilter == 'none' or groupByFilter == 'sku'
297
+ list_parms['fields']['date_added'] = 'Date Added' if groupByFilter == 'none'
298
+ list_parms['fields']['active'] = 'Active Item' if groupByFilter == 'none'
299
+ list_parms['fields'][button_column_name] = button_column_name.capitalize if groupByFilter == 'none'
300
+
301
+
302
+ list_parms['columnPopupTitle'] = {}
303
+ list_parms['columnPopupTitle']['checkbox'] = 'Select any record'
304
+ list_parms['columnPopupTitle']['cnt'] = 'Total Count'
305
+ list_parms['columnPopupTitle']['id'] = 'The primary key of the item'
306
+ list_parms['columnPopupTitle']['name_linked'] = 'Name (Click to drill down)'
307
+ list_parms['columnPopupTitle']['price'] = 'Price of item (not formatted)'
308
+ list_parms['columnPopupTitle']['sku_linked'] = 'Sku # (Click to drill down)'
309
+ list_parms['columnPopupTitle']['date_added'] = 'The date the item was added to the database'
310
+ list_parms['columnPopupTitle']['active'] = 'Is the item active?'
311
+ #
312
+ # Setup a custom field for checkboxes stored into the session and reloaded when refresh occurs
313
+ #
301
314
 
302
- list_parms.deep_merge!({'inputs' =>
303
- {'checkbox'=>
304
- {'type' => 'checkbox'
305
- }
306
- }
307
- })
308
-
309
- list_parms.deep_merge!({'inputs' =>
310
- {'checkbox'=>
311
- {'items' =>
312
- {
313
- 'name' => 'visible_checks[]',
314
- 'value' => 'id', #the value should be a column name mapping
315
- 'class_handle' => 'info_tables',
316
- }
317
- }
318
- }
319
- })
320
-
321
- list_parms.deep_merge!({'inputs' =>
322
- {'checkbox_header'=>
323
- {'type' => 'checkbox'
324
- }
325
- }
326
- })
327
-
328
- list_parms.deep_merge!({'inputs' =>
329
- {'checkbox_header'=>
330
- {'items' =>
331
- {
332
- 'check_all' => true,
333
- 'id' => 'info_tables_check_all',
334
- 'class_handle' => 'info_tables',
335
- }
336
- }
337
- }
338
- })
339
-
340
- list = WidgetList::List.new(list_parms)
315
+ list_parms.deep_merge!({'inputs' =>
316
+ {'checkbox'=>
317
+ {'type' => 'checkbox'
318
+ }
319
+ }
320
+ })
321
+
322
+ list_parms.deep_merge!({'inputs' =>
323
+ {'checkbox'=>
324
+ {'items' =>
325
+ {
326
+ 'name' => 'visible_checks[]',
327
+ 'value' => 'id', #the value should be a column name mapping
328
+ 'class_handle' => 'info_tables',
329
+ }
330
+ }
331
+ }
332
+ })
333
+
334
+ list_parms.deep_merge!({'inputs' =>
335
+ {'checkbox_header'=>
336
+ {'type' => 'checkbox'
337
+ }
338
+ }
339
+ })
340
+
341
+ list_parms.deep_merge!({'inputs' =>
342
+ {'checkbox_header'=>
343
+ {'items' =>
344
+ {
345
+ 'check_all' => true,
346
+ 'id' => 'info_tables_check_all',
347
+ 'class_handle' => 'info_tables',
348
+ }
349
+ }
350
+ }
351
+ })
352
+ list = WidgetList::List.new(list_parms)
341
353
 
342
- #
343
- # If AJAX, send back JSON
344
- #
345
- if $_REQUEST.key?('BUTTON_VALUE') && $_REQUEST['LIST_NAME'] == list_parms['name']
346
- if $_REQUEST.key?('export_widget_list')
347
- send_data(list.render(), :filename => list_parms['name'] + '.csv')
348
- return
349
- end
350
-
351
- ret = {}
352
- ret['list'] = WidgetList::Utils::fill({ '<!--CUSTOM_CONTENT-->' => action_buttons } , list.render() )
353
- ret['list_id'] = list_parms['name']
354
- ret['callback'] = 'ListSearchAheadResponse'
355
- return render :inline => WidgetList::Utils::json_encode(ret)
356
- else
357
354
  #
358
- # Else assign to variable for view
355
+ # If AJAX, send back JSON
359
356
  #
357
+ if $_REQUEST.key?('BUTTON_VALUE') && $_REQUEST['LIST_NAME'] == list_parms['name']
358
+
359
+ if $_REQUEST.key?('export_widget_list')
360
+ send_data(list.render(), :filename => list_parms['name'] + '.csv')
361
+ return
362
+ end
363
+
364
+ ret = {}
365
+ ret['list'] = WidgetList::Utils::fill({ '<!--CUSTOM_CONTENT-->' => action_buttons } , list.render() )
366
+ ret['list_id'] = list_parms['name']
367
+ ret['callback'] = 'ListSearchAheadResponse'
368
+ return render :inline => WidgetList::Utils::json_encode(ret)
369
+ else
370
+ #
371
+ # Else assign to variable for view
372
+ #
373
+ @output = WidgetList::Utils::fill({ '<!--CUSTOM_CONTENT-->' => action_buttons } , list.render() )
374
+ end
375
+
376
+ rescue Exception => e
377
+
378
+ list = WidgetList::List.new(list_parms)
360
379
  @output = WidgetList::Utils::fill({ '<!--CUSTOM_CONTENT-->' => action_buttons } , list.render() )
380
+
361
381
  end
362
382
 
383
+
363
384
  ## Contributing
364
385
 
365
386
  1. Fork it
@@ -1,7 +1,7 @@
1
1
  module WidgetList
2
2
  class Engine < Rails::Engine
3
3
  # auto wire
4
- initializer 'static_assets.load_static_assets' do |app|
4
+ initializer 'widget_list.load_static_assets' do |app|
5
5
  app.middleware.use ::ActionDispatch::Static, "#{root}/vendor"
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module WidgetList
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end