tabulatr2 0.9.15 → 0.9.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +5 -1
  4. data/app/assets/javascripts/tabulatr/_tabulatr.js +79 -83
  5. data/app/assets/stylesheets/{tabulatr/application.css.scss → tabulatr.scss} +8 -4
  6. data/app/views/tabulatr/_tabulatr_batch_actions_menu.html.slim +1 -1
  7. data/app/views/tabulatr/_tabulatr_buttons.html.slim +0 -1
  8. data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +5 -0
  9. data/lib/tabulatr/generators/tabulatr/templates/tabulatr.yml +4 -0
  10. data/lib/tabulatr/renderer/column.rb +5 -1
  11. data/lib/tabulatr/version.rb +1 -1
  12. data/spec/dummy/app/assets/stylesheets/application.scss +2 -0
  13. data/spec/dummy/app/models/product.rb +3 -0
  14. data/spec/dummy/app/tabulatr_data/product_tabulatr_data.rb +2 -1
  15. data/spec/dummy/app/views/products/simple_index.html.erb +1 -1
  16. data/spec/dummy/config/locales/tabulatr.yml +4 -1
  17. data/spec/dummy/db/migrate/20141223164833_add_status_to_products.rb +5 -0
  18. data/spec/dummy/db/schema.rb +3 -1
  19. data/spec/features/tabulatrs_spec.rb +33 -10
  20. data/spec/lib/tabulatr/data/dsl_spec.rb +8 -8
  21. data/spec/lib/tabulatr/data/filtering_spec.rb +2 -2
  22. data/spec/lib/tabulatr/data/formatting_spec.rb +2 -2
  23. data/spec/lib/tabulatr/data/pagination_spec.rb +2 -2
  24. data/spec/lib/tabulatr/data/sorting_spec.rb +3 -2
  25. data/spec/lib/tabulatr/renderer/checkbox_spec.rb +3 -1
  26. data/spec/rails_helper.rb +2 -1
  27. data/spec/support/wait_for_ajax.rb +16 -0
  28. metadata +10 -7
  29. data/app/assets/stylesheets/tabulatr.css.scss +0 -2
  30. data/spec/dummy/app/assets/stylesheets/application.css.scss +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f23479a544dea98a12d51d712207eb073099c36a
4
- data.tar.gz: 5bc9a22c42eb5682f397c2b2906dd78665f7868e
3
+ metadata.gz: b70faeab636c745520f3c94de294232af0540e1d
4
+ data.tar.gz: b3feca6e1aeabdf69b5b5ada582b2a6a91834957
5
5
  SHA512:
6
- metadata.gz: 1bebe6ba5bf5ae4472fb13b18f679a00f31e1a3f31062945e535037483a44ad03c8fc93503a0a40a991e97dde628927b955ace7fd7299973735414e16bee2569
7
- data.tar.gz: 1c288d8b9da7f52c75689feb9eb4eafa32f876d6a46f9d86cc514909ad08ab9a83bb7dc64a418f6e461f90736f51700d2927d71e588eda2289c28a3de5c45fbc
6
+ metadata.gz: 44a287bc0b2493272e229cf0646b3829a2c9f79424e8ca5a5e1717531cb56bd9349774c4b69139b6423c672dfd3f04e180687e3a9399706d6e3ce8e47cf68ab0
7
+ data.tar.gz: 30052dc24ecf51e7975bd54fd5adcf75d1cbea36295bb1b100fc070fbffdda79cacd01a07defe1f91d98ae84dafa91caaeccc813cea0d538f50f98a365cf7d21
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
1
  ## 0.9.15
2
+ * Adds filter support for `enum`
3
+ If it detects an enum it creates a dropdown filter with the possible enum
4
+ values as options.
5
+
6
+ fixes #35
7
+
2
8
  * Removes bootstrap2 CSS modifications
3
9
 
4
10
  ## 0.9.6
data/README.md CHANGED
@@ -18,11 +18,15 @@ gem 'tabulatr2'
18
18
  After that run `bundle install`.
19
19
 
20
20
  Also add `//= require tabulatr` to your application js file and `*= require tabulatr` to your CSS asset
21
- pipeline.
21
+ pipeline. Make sure to add it after including the `bootstrap` assets.
22
22
 
23
23
  In order to get the provided `i18n` language files run
24
24
  `rails g tabulatr:install`
25
25
 
26
+ ## Example
27
+
28
+ ![example](https://cloud.githubusercontent.com/assets/570608/5580201/661c63c0-9047-11e4-9993-f71a0f1f4c00.png)
29
+
26
30
  ## The DSL
27
31
 
28
32
  `Tabulatr` provides an easy to use DSL to define the data to be used in your table. It is defined in `TabulatrData`
@@ -9,6 +9,19 @@ function Tabulatr(id){
9
9
  this.hasInfiniteScrolling = false;
10
10
  }
11
11
 
12
+ var cbfn = function(event, isInView, visiblePartX, visiblePartY) {
13
+ if (isInView && visiblePartY !== 'top' && visiblePartY !== 'bottom') {
14
+ var tableId = $(event.currentTarget).data('table');
15
+ var table_obj;
16
+ for(var i = 0; i < tabulatr_tables.length; i++){
17
+ if(tabulatr_tables[i].id === tableId){
18
+ table_obj = tabulatr_tables[i];
19
+ }
20
+ }
21
+ table_obj.updateTable({append: true});
22
+ }
23
+ };
24
+
12
25
  var tabulatr_tables;
13
26
  Tabulatr.prototype = {
14
27
  constructor: Tabulatr,
@@ -108,7 +121,6 @@ Tabulatr.prototype = {
108
121
  }
109
122
  if(this.locked){ return; }
110
123
  this.locked = true;
111
- var curTable = this;
112
124
  this.showLoadingSpinner();
113
125
  if(this.initialRequest && this.isAPersistedTable && localStorage[this.id]){
114
126
  data = JSON.parse(localStorage[this.id]);
@@ -150,7 +162,7 @@ Tabulatr.prototype = {
150
162
  }
151
163
  },
152
164
 
153
- handleError: function(foo, bar){
165
+ handleError: function(){
154
166
  if(this.isAPersistedTable && this.initialRequest){
155
167
  this.initialRequest = false;
156
168
  this.locked = false;
@@ -161,54 +173,36 @@ Tabulatr.prototype = {
161
173
  insertTabulatrData: function(response){
162
174
  var tableId = response.meta.table_id;
163
175
  var tbody = $('#'+ tableId +' tbody');
164
- if(!response.meta.append){
165
- if(this.storePage){
166
- $('#'+ tableId +' tbody tr').hide();
167
- }else{
168
- $('#'+ tableId +' tbody').html('');
169
- }
170
- }
171
- if(response.data.length === 0){
172
- this.moreResults = false;
173
- $('.pagination_trigger[data-table='+ tableId +']').unbind('inview');
174
- }else{
175
- if(this.currentCount() + response.data.length >= response.meta.count){
176
- this.moreResults = false;
177
- $('.pagination_trigger[data-table='+ tableId + ']').unbind('inview');
178
- }
179
-
180
- // insert the actual data
181
- for(var i = 0; i < response.data.length; i++){
182
- var data = response.data[i];
183
- var id = data.id;
184
- var tr = $('#'+ tableId +' tr.empty_row').clone();
185
- tr.removeClass('empty_row');
186
- if(data._row_config.data){
187
- tr.data(data._row_config.data);
188
- delete data._row_config.data;
176
+
177
+ this.prepareTableForInsert(tableId, response.meta.append, response.data.length, response.meta.count);
178
+
179
+
180
+ // insert the actual data
181
+ for(var i = 0; i < response.data.length; i++){
182
+ var data = response.data[i];
183
+ var id = data.id;
184
+ var tr = $('#'+ tableId +' tr.empty_row').clone();
185
+ tr.removeClass('empty_row');
186
+ if(data._row_config.data){
187
+ tr.data(data._row_config.data);
188
+ delete data._row_config.data;
189
+ }
190
+ tr.attr(data._row_config);
191
+ tr.attr('data-page', response.meta.page);
192
+ tr.attr('data-id', id);
193
+ tr.find('td').each(function(index,element) {
194
+ var td = $(element);
195
+ var coltype = td.data('tabulatr-type');
196
+ var name = td.data('tabulatr-column-name');
197
+ var cont = data[name];
198
+ if(coltype === 'checkbox') {
199
+ cont = $("<input>").attr('type', 'checkbox').val(id).addClass('tabulatr-checkbox');
189
200
  }
190
- tr.attr(data._row_config);
191
- tr.attr('data-page', response.meta.page);
192
- tr.attr('data-id', id);
193
- tr.find('td').each(function(index,element) {
194
- var td = $(element);
195
- var coltype = td.data('tabulatr-type');
196
- var name = td.data('tabulatr-column-name');
197
- var cont = data[name];
198
- if(coltype === 'checkbox') {
199
- cont = $("<input>").attr('type', 'checkbox').val(id).addClass('tabulatr-checkbox');
200
- }
201
- td.html(cont);
202
- });
203
- tbody.append(tr);
204
- }
201
+ td.html(cont);
202
+ });
203
+ tbody.append(tr);
205
204
  }
206
- var count_string = $('.tabulatr_count[data-table='+ tableId +']').data('format-string');
207
- count_string = count_string.replace(/%\{current\}/, response.meta.count);
208
- count_string = count_string.replace(/%\{total\}/, response.meta.total);
209
- count_string = count_string.replace(/%\{per_page\}/,
210
- response.meta.pagesize);
211
- $('.tabulatr_count[data-table='+ tableId +']').html(count_string);
205
+ this.updateInfoString(tableId, response);
212
206
 
213
207
  if(this.isAPersistedTable){
214
208
  this.retrieveTableFromLocalStorage(response);
@@ -216,7 +210,7 @@ Tabulatr.prototype = {
216
210
  },
217
211
 
218
212
 
219
- replacer: function(match, attribute, offset, string){
213
+ replacer: function(match, attribute){
220
214
  return this.currentData[attribute];
221
215
  },
222
216
 
@@ -267,7 +261,7 @@ Tabulatr.prototype = {
267
261
  return hash;
268
262
  },
269
263
 
270
- localDate: function(value, $td, $tr, obj){
264
+ localDate: function(value){
271
265
  return new Date(value).toLocaleString();
272
266
  },
273
267
 
@@ -279,6 +273,29 @@ Tabulatr.prototype = {
279
273
  this.initialRequest = false;
280
274
  this.locked = false;
281
275
  $('.tabulatr-spinner-box[data-table="'+ this.id +'"]').hide();
276
+ },
277
+
278
+ updateInfoString: function(tableId, response){
279
+ var count_string = $('.tabulatr_count[data-table='+ tableId +']').data('format-string');
280
+ count_string = count_string.replace(/%\{current\}/, response.meta.count);
281
+ count_string = count_string.replace(/%\{total\}/, response.meta.total);
282
+ count_string = count_string.replace(/%\{per_page\}/,
283
+ response.meta.pagesize);
284
+ $('.tabulatr_count[data-table='+ tableId +']').html(count_string);
285
+ },
286
+
287
+ prepareTableForInsert: function(tableId, append, dataCount, actualCount){
288
+ if(!append){
289
+ if(this.storePage){
290
+ $('#'+ tableId +' tbody tr').hide();
291
+ }else{
292
+ $('#'+ tableId +' tbody').html('');
293
+ }
294
+ }
295
+ if(dataCount === 0 || this.currentCount() + dataCount >= actualCount){
296
+ this.moreResults = false;
297
+ $('.pagination_trigger[data-table='+ tableId +']').unbind('inview');
298
+ }
282
299
  }
283
300
 
284
301
  };
@@ -294,7 +311,7 @@ $(document).on('ready page:load', function(){
294
311
  var tableId = table.attr('id');
295
312
  var table_obj;
296
313
  for(var i = 0; i < tabulatr_tables.length; i++){
297
- if(tabulatr_tables[i].id == tableId){
314
+ if(tabulatr_tables[i].id === tableId){
298
315
  table_obj = tabulatr_tables[i];
299
316
  }
300
317
  }
@@ -334,7 +351,7 @@ $(document).on('ready page:load', function(){
334
351
  $('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
335
352
  var table_obj;
336
353
  for(var i = 0; i < tabulatr_tables.length; i++){
337
- if(tabulatr_tables[i].id == tableId){
354
+ if(tabulatr_tables[i].id === tableId){
338
355
  table_obj = tabulatr_tables[i];
339
356
  }
340
357
  }
@@ -345,7 +362,7 @@ $(document).on('ready page:load', function(){
345
362
  var tableId = $(this).data('table');
346
363
  var table_obj;
347
364
  for(var i = 0; i < tabulatr_tables.length; i++){
348
- if(tabulatr_tables[i].id == tableId){
365
+ if(tabulatr_tables[i].id === tableId){
349
366
  table_obj = tabulatr_tables[i];
350
367
  }
351
368
  }
@@ -365,7 +382,7 @@ $(document).on('ready page:load', function(){
365
382
  var tableId = $(this).data('table');
366
383
  var table_obj;
367
384
  for(var i = 0; i < tabulatr_tables.length; i++){
368
- if(tabulatr_tables[i].id == tableId){
385
+ if(tabulatr_tables[i].id === tableId){
369
386
  table_obj = tabulatr_tables[i];
370
387
  }
371
388
  }
@@ -377,7 +394,7 @@ $(document).on('ready page:load', function(){
377
394
  var tableId = $(this).parents('table').prop('id');
378
395
  var table_obj;
379
396
  for(var i = 0; i < tabulatr_tables.length; i++){
380
- if(tabulatr_tables[i].id == tableId){
397
+ if(tabulatr_tables[i].id === tableId){
381
398
  table_obj = tabulatr_tables[i];
382
399
  }
383
400
  }
@@ -400,7 +417,7 @@ $(document).on('ready page:load', function(){
400
417
  var $markAllCheckbox = $table.find('.tabulatr_mark_all');
401
418
  var table_obj;
402
419
  for(var i = 0; i < tabulatr_tables.length; i++){
403
- if(tabulatr_tables[i].id == tableId){
420
+ if(tabulatr_tables[i].id === tableId){
404
421
  table_obj = tabulatr_tables[i];
405
422
  }
406
423
  }
@@ -435,7 +452,7 @@ $(document).on('ready page:load', function(){
435
452
  var tableId = $(this).closest('div').data('table');
436
453
  var table_obj;
437
454
  for(var i = 0; i < tabulatr_tables.length; i++){
438
- if(tabulatr_tables[i].id == tableId){
455
+ if(tabulatr_tables[i].id === tableId){
439
456
  table_obj = tabulatr_tables[i];
440
457
  }
441
458
  }
@@ -451,11 +468,11 @@ $(document).on('ready page:load', function(){
451
468
 
452
469
  $(document).on('click', 'a[data-tabulatr-reset]',function(){
453
470
  var a = $(this);
454
- var tableObj, tableName;
471
+ var tableObj;
455
472
  var tableId = a.data('tabulatrReset');
456
- a.parents('.tabulatr-outer-wrapper').removeClass('filtered')
473
+ a.parents('.tabulatr-outer-wrapper').removeClass('filtered');
457
474
  for(var i = 0; i < tabulatr_tables.length; i++){
458
- if(tabulatr_tables[i].id == tableId){
475
+ if(tabulatr_tables[i].id === tableId){
459
476
  tableObj = tabulatr_tables[i];
460
477
  tableObj.resetTable();
461
478
  return false;
@@ -484,7 +501,7 @@ $(document).on('ready page:load', function(){
484
501
  }
485
502
  tabulatr_tables.push(tabulatrTable);
486
503
  for(var i = 0; i < tabulatr_tables.length; i++){
487
- if(tabulatr_tables[i].id == tableId){
504
+ if(tabulatr_tables[i].id === tableId){
488
505
  tableObj = tabulatr_tables[i];
489
506
  }
490
507
  }
@@ -510,7 +527,7 @@ $(document).on('click', '.pagination a[data-page]', function(){
510
527
  $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
511
528
  var table_obj;
512
529
  for(var i = 0; i < tabulatr_tables.length; i++){
513
- if(tabulatr_tables[i].id == tableId){
530
+ if(tabulatr_tables[i].id === tableId){
514
531
  table_obj = tabulatr_tables[i];
515
532
  }
516
533
  }
@@ -529,24 +546,3 @@ $(document).on('change', 'select[data-tabulatr-date-filter]', function() {
529
546
  select.parents('.tabulatr-filter-row').find(".from_to").hide().val('');
530
547
  }
531
548
  });
532
-
533
-
534
- var cbfn = function(event, isInView, visiblePartX, visiblePartY) {
535
- if (isInView) {
536
- // element is now visible in the viewport
537
- if (visiblePartY == 'top') {
538
- // top part of element is visible
539
- } else if (visiblePartY == 'bottom') {
540
- // bottom part of element is visible
541
- } else {
542
- var tableId = $(event.currentTarget).data('table');
543
- var table_obj;
544
- for(var i = 0; i < tabulatr_tables.length; i++){
545
- if(tabulatr_tables[i].id == tableId){
546
- table_obj = tabulatr_tables[i];
547
- }
548
- }
549
- table_obj.updateTable({append: true});
550
- }
551
- }
552
- };
@@ -57,10 +57,6 @@
57
57
  opacity: 1;
58
58
  }
59
59
 
60
- .popover .tabulatr_filter_form {
61
- width: 400px;
62
- }
63
-
64
60
  .tabulatr_filtered_column{
65
61
  text-decoration: underline;
66
62
  }
@@ -192,4 +188,12 @@
192
188
  position: relative;
193
189
  text-align: center;
194
190
  }
191
+
192
+ .tabulatr-filter-row{
193
+ label{
194
+ display: block;
195
+ }
196
+ }
195
197
  }
198
+
199
+ @import 'font-awesome';
@@ -23,7 +23,7 @@
23
23
  - iname = "#{formatted_name}_batch"
24
24
  .dropdown
25
25
  a.btn.btn-default data-toggle="dropdown" href="#"
26
- i.icon-cog.glyphicon.glyphicon-cog.fa.fa-cog'
26
+ i.icon-cog.glyphicon.glyphicon-cog.fa.fa-cog>
27
27
  i.icon-caret-down.glyphicon.glyphicon-chevron-down.fa.fa-caret-down
28
28
  ul.dropdown-menu role="menu" aria-labelledby="dLabel"
29
29
  - table_options[:batch_actions].each do |key, label|
@@ -1,4 +1,3 @@
1
- //{:buttons=>[{:icon=>:"eye-open", :path=>"/products/1", :options=>{:class=>"btn-success"}}, {:icon=>:pencil, :path=>"/products/1/edit", :options=>{:class=>"btn-warning"}}], :submenu=>[{:icon=>:star, :path=>"/products/1", :label=>"Dolle Sache"}, :divider, {:icon=>:"trash-o", :path=>"/products/1", :label=>"Löschen", :options=>{:confirm=>"echt?", :class=>"btn-danger", :method=>:delete}}]}
2
1
  .btn-group
3
2
  - buttons[:buttons].each do |button|
4
3
  - o = (button[:options] || {}).merge(class: "btn btn-sm btn-default #{button[:options].try(:[], :class)}")
@@ -89,5 +89,10 @@
89
89
  label.control-label for="#{formatted_name}_#{name}_filter_from"
90
90
  = "Bis"
91
91
  input.tabulatr_filter.form-control.date-picker.from_to.hidden type="text" id="#{formatted_name}_#{name}_filter_to" name="#{iname}[date][to]"
92
+ - elsif column.filter == :enum
93
+ select.form-control name=iname data-tabulatr-attribute=name
94
+ option= I18n.t('tabulatr.enum_filter.none')
95
+ - column.klass.try(column.name.to_s.pluralize.to_sym).each do |key, value|
96
+ option value=value = key
92
97
  - else
93
98
  input.tabulatr_filter.form-control type="text" data-tabulatr-attribute="#{name}" name="#{iname}[like]"
@@ -19,6 +19,8 @@ en:
19
19
  both: All
20
20
  'yes': Yes
21
21
  'no': No
22
+ enum_filter:
23
+ none: ''
22
24
 
23
25
  de:
24
26
  tabulatr:
@@ -41,3 +43,5 @@ de:
41
43
  both: Alle
42
44
  'yes': Ja
43
45
  'no': Nein
46
+ enum_filter:
47
+ none: ''
@@ -182,7 +182,11 @@ class Tabulatr::Renderer::Column
182
182
  def determine_appropriate_filter!
183
183
  case self.klass.columns_hash[self.name.to_s].try(:type)
184
184
  when :integer, :float, :decimal
185
- self.filter = :exact
185
+ if self.klass.respond_to?(:defined_enums) && self.klass.defined_enums.keys.include?(self.name.to_s)
186
+ self.filter = :enum
187
+ else
188
+ self.filter = :exact
189
+ end
186
190
  when :string, :text
187
191
  self.filter = :like
188
192
  when :date, :time, :datetime, :timestamp
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module Tabulatr
25
- VERSION = "0.9.15"
25
+ VERSION = "0.9.16"
26
26
  end
@@ -0,0 +1,2 @@
1
+ @import "bootstrap";
2
+ @import "tabulatr";
@@ -1,4 +1,7 @@
1
1
  class Product < ActiveRecord::Base
2
+ if self.respond_to?(:enum)
3
+ enum status: [:in_stock, :short, :out_of_stock]
4
+ end
2
5
 
3
6
  belongs_to :vendor
4
7
  has_and_belongs_to_many :tags
@@ -8,6 +8,7 @@ class ProductTabulatrData < Tabulatr::Data
8
8
 
9
9
  column :title
10
10
  column :id
11
+ column :status
11
12
  column :price, table_column_options: {filter: :range} do "#{record.price} EUR" end # <- Block evaluiert im Kontext EINES Records
12
13
  column :edit_link do link_to "edit #{record.title}", product_path(record) end
13
14
  # column :name,
@@ -36,7 +37,7 @@ class ProductTabulatrData < Tabulatr::Data
36
37
  b.submenu do |s|
37
38
  s.button :star, product_path(r), label: 'Dolle Sache'
38
39
  s.divider
39
- s.button :'trash-o', product_path(r), label: 'Löschen', confirm: 'echt?', class: 'btn-danger', method: :delete
40
+ s.button :'trash-o', product_path(r), label: 'Löschen', class: 'btn-danger', method: :delete, data: {confirm: 'echt?'}
40
41
  end
41
42
  "haha!"
42
43
  end
@@ -1,4 +1,4 @@
1
1
  <%= table_for Product, paginate: true, persistent: false,
2
2
  batch_actions: {a: "Hallo", b: "Du da!"},
3
- columns: [:'_buttons', :title, :price, :active, :vendor_product_name, :updated_at,
3
+ columns: [:'_buttons', :title, :price, :active, :vendor_product_name, :updated_at, :status,
4
4
  {vendor: :name}, 'tags:title'] %>
@@ -19,7 +19,8 @@ en:
19
19
  both: All
20
20
  'yes': Yes
21
21
  'no': No
22
-
22
+ enum_filter:
23
+ none: ''
23
24
  de:
24
25
  tabulatr:
25
26
  rows_per_page: 'Ergebnisse pro Seite'
@@ -41,3 +42,5 @@ de:
41
42
  both: Alle
42
43
  'yes': Ja
43
44
  'no': Nein
45
+ enum_filter:
46
+ none: ''
@@ -0,0 +1,5 @@
1
+ class AddStatusToProducts < ActiveRecord::Migration
2
+ def change
3
+ add_column :products, :status, :integer, default: 0
4
+ end
5
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20140128140114) do
14
+ ActiveRecord::Schema.define(version: 20141223164833) do
15
15
 
16
16
  create_table "products", force: true do |t|
17
17
  t.integer "vendor_id"
@@ -21,6 +21,8 @@ ActiveRecord::Schema.define(version: 20140128140114) do
21
21
  t.datetime "created_at"
22
22
  t.datetime "updated_at"
23
23
  t.datetime "publish_at"
24
+ t.string "type"
25
+ t.integer "status", default: 0
24
26
  end
25
27
 
26
28
  add_index "products", ["vendor_id"], name: "index_products_on_vendor_id"
@@ -131,14 +131,12 @@ feature "Tabulatr" do
131
131
  visit simple_index_products_path
132
132
  click_link 'Filter'
133
133
  fill_in("product_filter[products:title][like]", with: "ore")
134
- find('.tabulatr-submit-table').click
135
134
  expect(page).to have_selector('td[data-tabulatr-column-name="products:title"]', text: 'lorem')
136
135
  expect(page).to have_selector('td[data-tabulatr-column-name="products:title"]', text: 'labore')
137
136
  expect(page).to have_selector('td[data-tabulatr-column-name="products:title"]', text: 'dolore')
138
137
 
139
138
  within(".tabulatr_filter_form") do
140
139
  fill_in("product_filter[products:title][like]", :with => "loreem")
141
- find('.tabulatr-submit-table').click
142
140
  end
143
141
  expect(page).not_to have_selector('td[data-tabulatr-column-name="products:title"]', text: 'lorem')
144
142
  expect(page).not_to have_selector('td[data-tabulatr-column-name="products:title"]', text: 'labore')
@@ -151,7 +149,6 @@ feature "Tabulatr" do
151
149
  visit simple_index_products_path
152
150
  click_link 'Filter'
153
151
  find('form.tabulatr_filter_form').fill_in("product_filter[vendor:name]", with: "producer")
154
- find('.tabulatr-submit-table').click
155
152
  expect(page).not_to have_selector('td[data-tabulatr-column-name="vendor:name"]', text: @vendor1.name)
156
153
  expect(page).to have_selector('td[data-tabulatr-column-name="vendor:name"]', text: @vendor2.name)
157
154
  end
@@ -164,18 +161,45 @@ feature "Tabulatr" do
164
161
  click_link 'Filter'
165
162
  within('.tabulatr_filter_form') do
166
163
  fill_in("product_filter[products:price][from]", :with => 4)
164
+ wait_for_ajax
167
165
  fill_in("product_filter[products:price][to]", :with => 10)
168
- find('.tabulatr-submit-table').click
166
+ wait_for_ajax
169
167
  end
170
- expect(page).to have_css(".tabulatr_table tbody tr[data-id='#{Product.first.id}']", text: 'foo')
171
- expect(page).to have_no_css(".tabulatr_table tbody tr[data-id='#{Product.last.id}']")
168
+ expect(page).to have_no_css('.tabulatr-spinner-box')
169
+ expect(page).to have_css(".tabulatr_table tbody tr", text: 'foo')
170
+ expect(page).to have_no_css(".tabulatr_table tbody tr", text: 'bar')
172
171
  within('.tabulatr_filter_form') do
173
172
  fill_in("product_filter[products:price][from]", :with => 12)
173
+ wait_for_ajax
174
174
  fill_in("product_filter[products:price][to]", :with => 19)
175
- find('.tabulatr-submit-table').click
175
+ wait_for_ajax
176
176
  end
177
- expect(page).to have_css(".tabulatr_table tbody tr[data-id='#{Product.last.id}']")
178
- expect(page).to have_no_css(".tabulatr_table tbody tr[data-id='#{Product.first.id}']")
177
+ expect(page).to have_no_css('.tabulatr-spinner-box')
178
+ expect(page).to have_css(".tabulatr_table tbody tr", text: 'bar')
179
+ expect(page).to have_no_css(".tabulatr_table tbody tr", text: 'foo')
180
+ end
181
+
182
+ scenario "filters enums", js: true do
183
+ skip unless Product.respond_to?(:enum)
184
+ Product.create!([{title: 'foo', price: 5, status: 'in_stock'},
185
+ {title: 'bar', price: 10, status: 'out_of_stock'}])
186
+ visit simple_index_products_path
187
+ expect(page).to have_css('.tabulatr_table tbody', text: 'foo')
188
+ expect(page).to have_css('.tabulatr_table tbody', text: 'bar')
189
+ click_link 'Filter'
190
+ within('.tabulatr_filter_form') do
191
+ select 'in_stock', from: 'product_filter[products:status]'
192
+ end
193
+ expect(page).to have_no_css('.tabulatr-spinner-box')
194
+ expect(page).to have_css('.tabulatr_table tbody', text: 'foo')
195
+ expect(page).to have_no_css('.tabulatr_table tbody', text: 'bar')
196
+ within('.tabulatr_filter_form') do
197
+ select 'out_of_stock', from: 'product_filter[products:status]'
198
+ end
199
+ expect(page).to have_no_css('.tabulatr-spinner-box')
200
+ expect(page).to have_css('.tabulatr_table tbody', text: 'bar')
201
+ expect(page).to have_no_css('.tabulatr_table tbody', text: 'foo')
202
+
179
203
  end
180
204
 
181
205
  scenario 'removes the filters', js: true do
@@ -184,7 +208,6 @@ feature "Tabulatr" do
184
208
  click_link 'Filter'
185
209
  within(".tabulatr_filter_form") do
186
210
  fill_in("product_filter[products:title][like]", with: "foo")
187
- find('.tabulatr-submit-table').click
188
211
  end
189
212
  expect(page).not_to have_selector('td[data-tabulatr-column-name="products:title"]', text: 'bar')
190
213
  expect(page).to have_selector('td[data-tabulatr-column-name="products:title"]', text: 'foo')
@@ -1,19 +1,19 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  describe Tabulatr::Data::DSL do
4
- class DummySpecClass
4
+ class DummyDSLClass
5
5
  extend Tabulatr::Data::DSL
6
6
  end
7
7
 
8
8
  before(:each) do
9
- DummySpecClass.instance_variable_set('@table_columns', [])
9
+ DummyDSLClass.instance_variable_set('@table_columns', [])
10
10
  end
11
11
 
12
12
  describe '#column' do
13
13
  it 'escapes table and column names' do
14
- allow(DummySpecClass).to receive(:main_class).and_return(Product)
15
- DummySpecClass.column(:active)
16
- table_column = DummySpecClass.instance_variable_get('@table_columns').first
14
+ allow(DummyDSLClass).to receive(:main_class).and_return(Product)
15
+ DummyDSLClass.column(:active)
16
+ table_column = DummyDSLClass.instance_variable_get('@table_columns').first
17
17
  expect(table_column.filter_sql).to match(/\"products\".\"active\"/)
18
18
  expect(table_column.sort_sql).to match(/\"products\".\"active\"/)
19
19
  end
@@ -21,9 +21,9 @@ describe Tabulatr::Data::DSL do
21
21
 
22
22
  describe '#association' do
23
23
  it 'escapes table and column names' do
24
- allow(DummySpecClass).to receive(:main_class).and_return(Product)
25
- DummySpecClass.association(:vendor, :name)
26
- table_column = DummySpecClass.instance_variable_get('@table_columns').first
24
+ allow(DummyDSLClass).to receive(:main_class).and_return(Product)
25
+ DummyDSLClass.association(:vendor, :name)
26
+ table_column = DummyDSLClass.instance_variable_get('@table_columns').first
27
27
  expect(table_column.filter_sql).to match(/\"vendors\".\"name\"/)
28
28
  expect(table_column.sort_sql).to match(/\"vendors\".\"name\"/)
29
29
  end
@@ -1,12 +1,12 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  describe Tabulatr::Data::Filtering do
4
- class DummySpecClass
4
+ class DummyFilteringClass
5
5
  include Tabulatr::Data::Filtering
6
6
  end
7
7
 
8
8
  before(:each) do
9
- @dummy = DummySpecClass.new
9
+ @dummy = DummyFilteringClass.new
10
10
  @dummy.instance_variable_set('@relation', Product.all)
11
11
  @yesterday = Product.create!(publish_at: DateTime.new(2013, 12, 31, 0, 0))
12
12
  @today = Product.create!(publish_at: DateTime.new(2014, 1, 1, 15, 0))
@@ -1,13 +1,13 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  describe Tabulatr::Data::Formatting do
4
- class DummySpecClass
4
+ class DummyFormattingClass
5
5
  include Tabulatr::Data::Formatting
6
6
  def table_columns; end
7
7
  end
8
8
 
9
9
  before(:each) do
10
- @dummy = DummySpecClass.new
10
+ @dummy = DummyFormattingClass.new
11
11
  @dummy.instance_variable_set('@relation', Product.all)
12
12
  column = Tabulatr::Renderer::Column.from(
13
13
  name: :title,
@@ -1,12 +1,12 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  describe Tabulatr::Data::Pagination do
4
- class DummySpecClass
4
+ class DummyPaginationClass
5
5
  include Tabulatr::Data::Pagination
6
6
  end
7
7
 
8
8
  before(:all) do
9
- @dummy = DummySpecClass.new
9
+ @dummy = DummyPaginationClass.new
10
10
  end
11
11
  describe '.compute_pagination' do
12
12
  it "computes an offset" do
@@ -1,12 +1,13 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  describe Tabulatr::Data::Sorting do
4
- class DummySpecClass
4
+ class DummySortingClass
5
5
  include Tabulatr::Data::Sorting
6
+ def table_columns; end
6
7
  end
7
8
 
8
9
  before(:each) do
9
- @dummy = DummySpecClass.new
10
+ @dummy = DummySortingClass.new
10
11
  @dummy.instance_variable_set('@relation', Product.all)
11
12
  @dummy.instance_variable_set('@table_name', 'products')
12
13
  @dummy.instance_variable_set('@base', Product)
@@ -6,7 +6,9 @@ describe Tabulatr::Renderer::Checkbox do
6
6
 
7
7
  it "generates a checkbox" do
8
8
  checkbox = Tabulatr::Renderer::Checkbox.new
9
- expect(checkbox.human_name).to eq('<input class="tabulatr_mark_all" id="mark_all" name="mark_all" type="checkbox" value="1" />')
9
+ expect(checkbox.human_name).to match(/\A<input.+\/>\z/)
10
+ expect(checkbox.human_name).to match(/class="tabulatr_mark_all"/)
11
+ expect(checkbox.human_name).to match(/type="checkbox"/)
10
12
  end
11
13
 
12
14
  end
data/spec/rails_helper.rb CHANGED
@@ -14,9 +14,10 @@ Capybara.register_driver :poltergeist do |app|
14
14
  Capybara::Poltergeist::Driver.new(app, {js_errors: true})
15
15
  end
16
16
 
17
+
17
18
  # Requires supporting ruby files with custom matchers and macros, etc,
18
19
  # in spec/support/ and its subdirectories.
19
- Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
20
+ Dir[Rails.root.join("../support/**/*.rb")].each { |f| require f }
20
21
 
21
22
  RSpec.configure do |config|
22
23
  config.use_transactional_fixtures = false
@@ -0,0 +1,16 @@
1
+ # from http://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
2
+ module WaitForAjax
3
+ def wait_for_ajax
4
+ Timeout.timeout(Capybara.default_wait_time) do
5
+ loop until finished_all_ajax_requests?
6
+ end
7
+ end
8
+
9
+ def finished_all_ajax_requests?
10
+ page.evaluate_script('jQuery.active').zero?
11
+ end
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.include WaitForAjax, type: :feature
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulatr2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.15
4
+ version: 0.9.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Horn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-12-29 00:00:00.000000000 Z
13
+ date: 2015-03-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -125,8 +125,7 @@ files:
125
125
  - app/assets/javascripts/tabulatr/_tabulatr.js
126
126
  - app/assets/javascripts/tabulatr/application.js
127
127
  - app/assets/javascripts/tabulatr/jquery.inview.min.js
128
- - app/assets/stylesheets/tabulatr.css.scss
129
- - app/assets/stylesheets/tabulatr/application.css.scss
128
+ - app/assets/stylesheets/tabulatr.scss
130
129
  - app/views/tabulatr/_tabulatr_actual_table.html.slim
131
130
  - app/views/tabulatr/_tabulatr_batch_actions_menu.html.slim
132
131
  - app/views/tabulatr/_tabulatr_buttons.html.slim
@@ -177,7 +176,7 @@ files:
177
176
  - spec/dummy/Rakefile
178
177
  - spec/dummy/app/assets/images/.keep
179
178
  - spec/dummy/app/assets/javascripts/application.js
180
- - spec/dummy/app/assets/stylesheets/application.css.scss
179
+ - spec/dummy/app/assets/stylesheets/application.scss
181
180
  - spec/dummy/app/controllers/application_controller.rb
182
181
  - spec/dummy/app/controllers/concerns/.keep
183
182
  - spec/dummy/app/controllers/products_controller.rb
@@ -225,6 +224,7 @@ files:
225
224
  - spec/dummy/db/migrate/20130730132321_create_products.rb
226
225
  - spec/dummy/db/migrate/20130730132348_create_tags.rb
227
226
  - spec/dummy/db/migrate/20140128140114_add_publish_at_to_products.rb
227
+ - spec/dummy/db/migrate/20141223164833_add_status_to_products.rb
228
228
  - spec/dummy/db/schema.rb
229
229
  - spec/dummy/lib/assets/.keep
230
230
  - spec/dummy/log/.keep
@@ -244,6 +244,7 @@ files:
244
244
  - spec/lib/tabulatr/renderer/renderer_spec.rb
245
245
  - spec/rails_helper.rb
246
246
  - spec/spec_helper.rb
247
+ - spec/support/wait_for_ajax.rb
247
248
  - tabulatr.gemspec
248
249
  homepage: http://github.com/metaminded/tabulatr2
249
250
  licenses:
@@ -266,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
267
  version: '0'
267
268
  requirements: []
268
269
  rubyforge_project:
269
- rubygems_version: 2.2.2
270
+ rubygems_version: 2.4.5
270
271
  signing_key:
271
272
  specification_version: 4
272
273
  summary: A tight DSL to build tables of ActiveRecord models with sorting, pagination,
@@ -277,7 +278,7 @@ test_files:
277
278
  - spec/dummy/Rakefile
278
279
  - spec/dummy/app/assets/images/.keep
279
280
  - spec/dummy/app/assets/javascripts/application.js
280
- - spec/dummy/app/assets/stylesheets/application.css.scss
281
+ - spec/dummy/app/assets/stylesheets/application.scss
281
282
  - spec/dummy/app/controllers/application_controller.rb
282
283
  - spec/dummy/app/controllers/concerns/.keep
283
284
  - spec/dummy/app/controllers/products_controller.rb
@@ -325,6 +326,7 @@ test_files:
325
326
  - spec/dummy/db/migrate/20130730132321_create_products.rb
326
327
  - spec/dummy/db/migrate/20130730132348_create_tags.rb
327
328
  - spec/dummy/db/migrate/20140128140114_add_publish_at_to_products.rb
329
+ - spec/dummy/db/migrate/20141223164833_add_status_to_products.rb
328
330
  - spec/dummy/db/schema.rb
329
331
  - spec/dummy/lib/assets/.keep
330
332
  - spec/dummy/log/.keep
@@ -344,3 +346,4 @@ test_files:
344
346
  - spec/lib/tabulatr/renderer/renderer_spec.rb
345
347
  - spec/rails_helper.rb
346
348
  - spec/spec_helper.rb
349
+ - spec/support/wait_for_ajax.rb
@@ -1,2 +0,0 @@
1
- @import 'tabulatr/application';
2
- @import 'font-awesome';
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require tabulatr
13
- */
14
-
15
- @import "bootstrap";