tabulatr2 0.9.12 → 0.9.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a47c45c08c541dbbb460f8aa315f35db38c82c8
4
- data.tar.gz: e6fd77a9e25389bcfbbca3e82d8064842b421211
3
+ metadata.gz: 7c84d124ea6a79ae026aa59ba8a1365a1bc6ae16
4
+ data.tar.gz: 85d817921b527a2a5ab2f0427080b64d14830a86
5
5
  SHA512:
6
- metadata.gz: fbb8191710b05154d82532ba5b316c4914f95ea415bac16c0cc73bc6426381e3cdd5e11b7091564afd570553167639ea991b2dbcdaefaef439aea1ddc6baf086
7
- data.tar.gz: d28ea60364b7841bc1c1125402754d8f9920c17d4dd88af0a7eb775ed4e5c51321998de725598b731ba46731b354bc5e75078683c514b0c655292a927efbd080
6
+ metadata.gz: 8de26639ec20250a03e347ee476320bd9f7eddf964bd5893266828c77350d35ccebe99cc3f8ab4e9de82e04280235c8a932cc7b76a89d7ad5244a45313c97635
7
+ data.tar.gz: 7a003812abef8c87fbe511f3950c9d9d9d31312190a13720d7c996a3c1a8d4f5f760dd71d5e27a338b9691c9532fd9f080ff0fad68603469524dd3cb5dba50b7
data/Gemfile CHANGED
@@ -14,6 +14,7 @@ group :development, :test do
14
14
  gem 'sqlite3', :require => 'sqlite3'
15
15
  gem 'rspec', '~> 2.14.1'
16
16
  gem 'rspec-rails', '~> 2.14.0'
17
+ gem 'minitest'
17
18
  gem 'capybara'
18
19
  gem 'launchy'
19
20
  gem 'database_cleaner', '< 1.1.0'
data/README.md CHANGED
@@ -344,6 +344,7 @@ the columns in the block of `table_for`.
344
344
  wrap: nil,
345
345
  th_html: false,
346
346
  filter_html: false,
347
+ filter_label: nil,
347
348
  filter: true, # whether this column should be filterable
348
349
  sortable: true, # whethter this column should be sortable
349
350
  format: nil,
@@ -2,11 +2,11 @@ $(function(){
2
2
  Tabulatr.prototype.retrieveTableFromLocalStorage = function(response){
3
3
  var currentStorage = JSON.parse(localStorage[this.id]);
4
4
  if(currentStorage !== undefined){
5
- $('.pagination[data-table='+ this.id +'] a[data-page='+ response.meta.page +']');
5
+ $('.pagination[data-table='+ this.id +'] a[data-page='+ response.meta.page +']');
6
6
  var $table = $('#' + this.id);
7
7
  var tableName = this.id.split('_')[0];
8
- if(currentStorage[tableName +'_sort'] != ''){
9
- var sortParam = currentStorage[tableName +'_sort'];
8
+ var sortParam = currentStorage[tableName +'_sort'];
9
+ if(sortParam && sortParam != ''){
10
10
  var header = $table.find('th.tabulatr-sortable[data-tabulatr-column-name="'+ sortParam.split(' ')[0] +'"]');
11
11
  header.attr('data-sorted', sortParam.split(' ')[1]);
12
12
  header.addClass('sorted');
@@ -18,11 +18,11 @@ $(function(){
18
18
  for(var i = 0; i < objKeys.length; i++){
19
19
  elem = $('[name="'+ objKeys[i] +'"]');
20
20
  if(elem.length > 0){
21
- elem.val(currentStorage[objKeys[i]]);
21
+ var val = currentStorage[objKeys[i]];
22
+ elem.val(val);
22
23
  formParent = elem.parents('.form-group[data-filter-column-name]');
23
- if(formParent.length > 0){
24
- formParent.show();
25
- formParent.siblings('[data-filter-column-name="_submit"]').show();
24
+ if(formParent.length > 0 && val && val.length > 0){
25
+ $('.tabulatr-outer-wrapper[data-table-id="'+this.id+'"]').addClass('filtered')
26
26
  }
27
27
  }
28
28
  }
@@ -34,8 +34,8 @@ $(function(){
34
34
  localStorage.removeItem(this.id);
35
35
  $('table#'+ this.id).find('th.sorted').removeClass('sorted').removeAttr('data-sorted');
36
36
  $('form[data-table='+ this.id +'] input.search').val('');
37
- $('[data-table-id="'+ this.id +'"] [data-filter-column-name]').hide().find('input[type=text], input[type=hidden], select').val('');
37
+ $('[data-table-id="'+ this.id +'"] [data-filter-column-name]').find('input[type=text], input[type=hidden], select').val('');
38
38
  $('.tabulatr_filter_form[data-table='+ this.id +'] input[name="'+ tableName +'_sort"]').val('');
39
39
  this.updateTable({page: 1}, true);
40
40
  };
41
- });
41
+ });
@@ -357,6 +357,10 @@ $(document).on('ready page:load', function(){
357
357
  return false;
358
358
  });
359
359
 
360
+ $('form.tabulatr_filter_form input, form.tabulatr_filter_form select').change(function(){
361
+ $(this).parents('form.tabulatr_filter_form').submit();
362
+ });
363
+
360
364
  $('form.tabulatr_filter_form').submit(function(){
361
365
  var tableId = $(this).data('table');
362
366
  var table_obj;
@@ -369,32 +373,6 @@ $(document).on('ready page:load', function(){
369
373
  return false;
370
374
  });
371
375
 
372
- $('.tabulatr_table').on('click', 'i.tabulatr_remove_filter', function(){
373
- var $th = $(this).closest('th');
374
- var name = $th.data('tabulatr-form-name').
375
- replace(/\[(like|checkbox|from|to)\]/, '');
376
- name = name.replace(/(:|\.|\[|\])/g,'\\$1');
377
- $th.removeClass('tabulatr_filtered_column');
378
- if($('[name^='+ name +']').is(':checkbox')){
379
- $('[name^='+ name +']').prop('checked', false);
380
- }else{
381
- $('[name^='+ name +']').val('');
382
- }
383
- var tableId = $(this).closest('.tabulatr_table').attr('id');
384
- $(this).remove();
385
- var table_obj;
386
- for(var i = 0; i < tabulatr_tables.length; i++){
387
- if(tabulatr_tables[i].id == tableId){
388
- table_obj = tabulatr_tables[i];
389
- }
390
- }
391
- if(table_obj.hasInfiniteScrolling){
392
- $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
393
- }
394
- table_obj.updateTable({});
395
- return false;
396
- });
397
-
398
376
  $('.tabulatr_mark_all').click(function(){
399
377
  var tableId = $(this).parents('table').prop('id');
400
378
  var table_obj;
@@ -472,8 +450,10 @@ $(document).on('ready page:load', function(){
472
450
  });
473
451
 
474
452
  $(document).on('click', 'a[data-tabulatr-reset]',function(){
453
+ var a = $(this);
475
454
  var tableObj, tableName;
476
- var tableId = $(this).data('tabulatrReset');
455
+ var tableId = a.data('tabulatrReset');
456
+ a.parents('.tabulatr-outer-wrapper').removeClass('filtered')
477
457
  for(var i = 0; i < tabulatr_tables.length; i++){
478
458
  if(tabulatr_tables[i].id == tableId){
479
459
  tableObj = tabulatr_tables[i];
@@ -511,6 +491,12 @@ $(document).on('ready page:load', function(){
511
491
  tableObj.updateTable({}, false);
512
492
  });
513
493
  }
494
+
495
+ $(document).on('click', 'a[data-show-filters-for]', function(){
496
+ var a = $(this);
497
+ a.parents('.tabulatr-outer-wrapper').addClass('filtered');
498
+ });
499
+
514
500
  });
515
501
 
516
502
  $(document).on('click', '.pagination a[data-page]', function(){
@@ -533,52 +519,14 @@ $(document).on('click', '.pagination a[data-page]', function(){
533
519
  });
534
520
 
535
521
 
536
- // TODO: We absolutely need to clean that up!
537
-
538
- $(document).on('click', 'a[data-show-table-filter]', function(){
539
- var a = $(this);
540
- var name = a.data('show-table-filter');
541
- var tableId = a.parents('.tabulatr-filter-menu-wrapper').data('table-id');
542
- var filterForm = $('.tabulatr_filter_form[data-table="'+ tableId +'"]');
543
- filterForm.find($('div[data-filter-column-name="'+ name +'"]')).show('blind');
544
- filterForm.find($('div[data-filter-column-name="_submit"]')).show('blind');
545
-
546
- a.hide();
547
- return false;
548
- });
549
-
550
- $(document).on('click', 'a[data-hide-table-filter]', function(){
551
- var a = $(this);
552
- var nam = a.data('hide-table-filter');
553
- var filterForm = a.parents('.tabulatr_filter_form');
554
- var t = filterForm.find($('div[data-filter-column-name="'+nam+'"]'));
555
- t.hide();
556
- t.find('input[type=text]').val("");
557
- t.find('select').val('');
558
- var filterMenu = $('.tabulatr-filter-menu-wrapper[data-table-id="'+ filterForm.data('table') +'"]');
559
- filterMenu.find($('a[data-show-table-filter="'+nam+'"]')).show();
560
- if (filterForm.find($('div[data-filter-column-name]:visible')).length <= 2)
561
- filterForm.find($('div[data-filter-column-name="_submit"]')).hide('blind');
562
-
563
- var tableId = filterForm.data('table');
564
- var table_obj;
565
- for(var i = 0; i < tabulatr_tables.length; i++){
566
- if(tabulatr_tables[i].id == tableId){
567
- table_obj = tabulatr_tables[i];
568
- }
569
- }
570
- table_obj.submitFilterForm();
571
- return false;
572
- });
573
-
574
522
  $(document).on('change', 'select[data-tabulatr-date-filter]', function() {
575
523
  var select = $(this);
576
524
  var option = select.find('option:selected');
577
525
  var val = option.val();
578
526
  if (val === 'from_to') {
579
- select.parents('.controls').find(".from_to").show().removeClass('hidden');
527
+ select.parents('.tabulatr-filter-row').find(".from_to").show().removeClass('hidden');
580
528
  } else {
581
- select.parents('.controls').find(".from_to").hide().val('');
529
+ select.parents('.tabulatr-filter-row').find(".from_to").hide().val('');
582
530
  }
583
531
  });
584
532
 
@@ -601,4 +549,4 @@ var cbfn = function(event, isInView, visiblePartX, visiblePartY) {
601
549
  table_obj.updateTable({append: true});
602
550
  }
603
551
  }
604
- };
552
+ };
@@ -19,156 +19,177 @@
19
19
  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- .tabulatr-sort{
23
- opacity: 0.3;
24
- }
22
+ .tabulatr-outer-wrapper {
25
23
 
26
- .tabulatr-sort:hover{
27
- cursor: pointer;
28
- }
24
+ .tabulatr-filter-col {
25
+ display:none;
26
+ }
27
+ .tabulatr-table-col {
28
+ @extend .col-xs-12;
29
+ }
29
30
 
30
- .sorted{
31
- opacity: 1;
32
- }
31
+ &.filtered {
32
+ .tabulatr-filter-col {
33
+ display:block;
34
+ @extend .col-xs-4;
35
+ @extend .col-sm-3;
36
+ @extend .col-lg-2;
37
+ }
38
+ .tabulatr-table-col {
39
+ @extend .col-xs-8;
40
+ @extend .col-sm-9;
41
+ @extend .col-lg-10;
42
+ }
43
+ a[data-show-filters-for] {
44
+ display: none;
45
+ }
46
+ }
33
47
 
34
- i.tabulatr_remove_filter:hover{
35
- cursor: pointer;
36
- }
48
+ .tabulatr-sort{
49
+ opacity: 0.3;
50
+ }
37
51
 
38
- .tabulatr_filtered_column{
39
- text-decoration: underline;
40
- }
52
+ .tabulatr-sort:hover{
53
+ cursor: pointer;
54
+ }
41
55
 
42
- .tabulatr-per-page {
43
- margin: 20px 10px;
44
- a.active{
45
- background-color: red;
56
+ .sorted{
57
+ opacity: 1;
46
58
  }
47
- }
48
59
 
49
- .table-controls div{
50
- margin: 20px 10px;
51
- display: inline-block;
52
- vertical-align: middle;
53
- }
60
+ .popover .tabulatr_filter_form {
61
+ width: 400px;
62
+ }
54
63
 
55
- .table-controls i, .tabulatr_table i{
56
- margin-right: 5px;
57
- }
64
+ .tabulatr_filtered_column{
65
+ text-decoration: underline;
66
+ }
58
67
 
59
- .table-controls .form-inline{
60
- display: inline-block;
61
- position: relative;
62
- vertical-align: top;
63
- }
68
+ .tabulatr-per-page {
69
+ margin: 20px 10px;
70
+ a.active{
71
+ background-color: red;
72
+ }
73
+ }
64
74
 
65
- #tabulatr-wrench{
66
- margin-left: 10px;
67
- }
75
+ .table-controls div{
76
+ margin: 20px 10px;
77
+ display: inline-block;
78
+ vertical-align: middle;
79
+ }
68
80
 
81
+ .table-controls i, .tabulatr_table i{
82
+ margin-right: 5px;
83
+ }
69
84
 
85
+ .table-controls .form-inline{
86
+ display: inline-block;
87
+ position: relative;
88
+ vertical-align: top;
89
+ }
70
90
 
71
- div[data-filter-column-name] {
72
- display:none;
73
- }
91
+ #tabulatr-wrench{
92
+ margin-left: 10px;
93
+ }
74
94
 
75
- th.tabulatr-sortable {
76
- cursor: pointer;
95
+ th.tabulatr-sortable {
96
+ cursor: pointer;
77
97
 
78
- &.sorted {
98
+ &.sorted {
79
99
 
80
- &[data-sorted=asc] {
81
- &:after {
82
- content: " \25B2";
83
- margin-left: 5px;
100
+ &[data-sorted=asc] {
101
+ &:after {
102
+ content: " \25B2";
103
+ margin-left: 5px;
104
+ }
84
105
  }
85
- }
86
106
 
87
- &[data-sorted=desc] {
88
- &:after {
89
- content: " \25BC";
90
- margin-left: 5px;
107
+ &[data-sorted=desc] {
108
+ &:after {
109
+ content: " \25BC";
110
+ margin-left: 5px;
111
+ }
91
112
  }
92
113
  }
93
114
  }
94
- }
95
115
 
96
- table.tabulatr_table {
97
- td, th {
98
- &[align=right] {
99
- text-align: right;
100
- }
116
+ table.tabulatr_table {
117
+ td, th {
118
+ &[align=right] {
119
+ text-align: right;
120
+ }
101
121
 
102
- &[align=center] {
103
- text-align: center;
122
+ &[align=center] {
123
+ text-align: center;
124
+ }
125
+ }
126
+ tr.empty_row{
127
+ display: none;
104
128
  }
105
129
  }
106
- tr.empty_row{
107
- display: none;
108
- }
109
- }
110
130
 
111
- .tabulatr-table-controls-wrapper {
112
- display: block;
113
- padding-top: 10px;
131
+ .tabulatr-table-controls-wrapper {
132
+ display: block;
133
+ padding-top: 10px;
114
134
 
115
- .tabulatr-filter-menu-wrapper {
116
- display: inline-block;
117
- padding: 20px 0 20px 0;
118
- }
135
+ .tabulatr-filter-menu-wrapper {
136
+ display: inline-block;
137
+ padding: 20px 0 20px 0;
138
+ }
119
139
 
120
- .tabulatr-batch-actions-menu-wrapper {
121
- display: inline-block;
122
- padding: 20px 0 20px 20px;
123
- }
140
+ .tabulatr-batch-actions-menu-wrapper {
141
+ display: inline-block;
142
+ padding: 20px 0 20px 20px;
143
+ }
124
144
 
125
- .tabulatr-paginator-wrapper {
126
- display: inline-block;
127
- padding: 0;
128
- text-align: center;
145
+ .tabulatr-paginator-wrapper {
146
+ display: inline-block;
147
+ padding: 0;
148
+ text-align: center;
129
149
 
130
- .pagination{
131
- margin: 10px 0;
132
- vertical-align: middle;
133
- }
150
+ .pagination{
151
+ margin: 10px 0;
152
+ vertical-align: middle;
153
+ }
134
154
 
135
- .pagination_trigger{
136
- width: 1px;
137
- height: 1px;
138
- position: relative;
139
- float: left;
140
- opacity: 1;
155
+ .pagination_trigger{
156
+ width: 1px;
157
+ height: 1px;
158
+ position: relative;
159
+ float: left;
160
+ opacity: 1;
161
+ }
141
162
  }
142
- }
143
163
 
144
- .tabulatr-info-string-wrapper {
145
- display: inline-block;
146
- padding: 20px 20px 20px 0;
147
- }
164
+ .tabulatr-info-string-wrapper {
165
+ display: inline-block;
166
+ padding: 20px 20px 20px 0;
167
+ }
148
168
 
149
- .tabulatr-fuzzy-search-field-wrapper {
150
- display: inline-block;
151
- float: right;
152
- padding: 20px 0 20px 0;
153
- }
169
+ .tabulatr-fuzzy-search-field-wrapper {
170
+ display: inline-block;
171
+ float: right;
172
+ padding: 20px 0 20px 0;
173
+ }
154
174
 
155
- .tabulatr-filter-dialog-wrapper {
156
- display: block;
175
+ .tabulatr-filter-dialog-wrapper {
176
+ display: block;
157
177
 
158
- .submit-table{
159
- z-index: 2;
178
+ .submit-table{
179
+ z-index: 2;
180
+ }
160
181
  }
161
182
  }
162
- }
163
183
 
164
- .tabulatr-table-controls-wrapper.row{
165
- margin: 0;
166
- }
184
+ .tabulatr-table-controls-wrapper.row{
185
+ margin: 0;
186
+ }
167
187
 
168
- .tabulatr-spinner-box{
169
- width: 100%;
170
- height: 50px;
171
- display: none;
172
- position: relative;
173
- text-align: center;
188
+ .tabulatr-spinner-box{
189
+ width: 100%;
190
+ height: 50px;
191
+ display: none;
192
+ position: relative;
193
+ text-align: center;
194
+ }
174
195
  }
@@ -20,70 +20,74 @@
20
20
  / WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
 
23
- form.form.form-horizontal.tabulatr_filter_form data-table=table_id data-remote="true" role='form'
24
- input name="#{formatted_name}_sort" type="hidden" value=table_options[:order_by]
25
- - if table_options[:filter] && columns.select(&:filter).present?
26
- - columns.select(&:filter).each do |column|
27
- - name = column.full_name
28
- .control-group.form-group data-filter-column-name=name
29
- - iname = "#{formatted_name}_filter[#{name}]"
30
- - filter_name = "tabulatr_form_#{name}"
23
+ .tabulatr-filter-popover title="Filter" data-table=table_id
24
+ form.form.tabulatr_filter_form data-table=table_id data-remote="true" role='form'
25
+ .panel.panel-default
26
+ .panel-heading
27
+ = t('tabulatr.filter')
28
+ .btn-group.pull-right
29
+ a.tabulatr-reset-table.btn.btn-danger.btn-xs data-tabulatr-reset=table_id
30
+ = fa_icon :remove
31
+ a.tabulatr-submit-table.btn.btn-primary.btn-xs
32
+ = fa_icon 'arrow-right'
33
+ .panel-body
34
+ .wech style='text-indent: -2000px; height: 0px'
35
+ = submit_tag "Anwenden"
36
+ input name="#{formatted_name}_sort" type="hidden" value=table_options[:order_by]
37
+ - if table_options[:filter] && columns.select(&:filter).present?
38
+ - columns.select(&:filter).each do |column|
39
+ - name = column.full_name
40
+ .row.tabulatr-filter-row
41
+ .col-xs-12
42
+ .control-group.form-group data-filter-column-name=name
43
+ - iname = "#{formatted_name}_filter[#{name}]"
44
+ - filter_name = "tabulatr_form_#{name}"
31
45
 
32
- label.control-label.col-sm-3.col-xs-12 for=filter_name
33
- = column.human_name
46
+ label.control-label for=filter_name
47
+ = column.filter_label || column.human_name
34
48
 
35
- .controls.col-sm-9.col-xs-12.row
36
- - if column.filter.is_a?(Hash) || column.filter.is_a?(Array) || column.filter.is_a?(String)
37
- .col-sm-11
38
- select.form-control id=name name=iname
39
- - if column.filter.class.is_a?(String)
40
- = column.filter
41
- - else
42
- option
43
- = options_for_select(column.filter)
44
- - elsif column.filter == :range
45
- .col-sm-5
46
- input.tabulatr_filter.form-control type="text" id="#{name}_from" data-tabulatr-attribute="#{name}_from" name="#{iname}[from]"
47
- span.col-sm-1.text-center
48
- .col-sm-5
49
- input.tabulatr_filter.form-control type="text" id="#{name}_to" data-tabulatr-attribute="#{name}_to" name="#{iname}[to]"
50
- - elsif column.filter == :checkbox
51
- .col-sm-11
52
- = select_tag(iname, options_for_select([ \
53
- [t('tabulatr.boolean_filter.both'), ""],
54
- [t('tabulatr.boolean_filter.no'), "false"],
55
- [t('tabulatr.boolean_filter.yes'), "true"]] \
56
- ), class: 'form-control')
57
- - elsif column.filter == :exact
58
- .col-sm-11
59
- input.tabulatr_filter.form-control type="text" id="#{name}_exact" data-tabulatr-attribute="#{name}" name="#{iname}"
60
- - elsif column.filter == :date
61
- .col-sm-3
62
- select.form-control name="#{iname}[date][simple]" data-tabulatr-date-filter="#{formatted_name}_#{name}_filter"
63
- option= I18n.t("tabulatr.date_filter.none")
64
- option value="today"= I18n.t("tabulatr.date_filter.today")
65
- option value="yesterday"= I18n.t("tabulatr.date_filter.yesterday")
66
- option value="this_week"= I18n.t("tabulatr.date_filter.this_week")
67
- option value="last_7_days"= I18n.t("tabulatr.date_filter.last_7_days")
68
- option value="this_month"= I18n.t("tabulatr.date_filter.this_month")
69
- option value="last_30_days"= I18n.t("tabulatr.date_filter.last_30_days")
70
- option value="from_to"= I18n.t("tabulatr.date_filter.from_to")
71
- .col-sm-1
72
- .col-sm-3
73
- input.tabulatr_filter.form-control.date-picker.hidden.from_to type="text" id="#{formatted_name}_#{name}_filter_from" name="#{iname}[date][from]"
74
- .col-sm-1.text-center
75
- .span.from_to.hidden
76
- |&mdash;
77
- .col-sm-3
78
- input.tabulatr_filter.form-control.date-picker.from_to.hidden type="text" id="#{formatted_name}_#{name}_filter_to" name="#{iname}[date][to]"
79
- - else
80
- .col-sm-11
81
- input.tabulatr_filter.form-control type="text" data-tabulatr-attribute="#{name}" name="#{iname}[like]"
82
- .col-sm-1
83
- = link_to "✕", '#', 'data-hide-table-filter' => name, class: 'form-control btn btn-danger btn-mini'
84
-
85
- .control-group.form-group data-filter-column-name="_submit"
86
- label.control-label.col-md-3 for="_submit"
87
- |&nbsp;
88
- .controls.col-md-9
89
- input.submit-table.btn.btn-primary.btn-mini.btn-sm type='submit' value=I18n.t('tabulatr.apply_filters')
49
+ - if column.filter.is_a?(Hash) || column.filter.is_a?(Array) || column.filter.is_a?(String)
50
+ select.form-control.no-chosen id=name name=iname
51
+ - if column.filter.class.is_a?(String)
52
+ = column.filter
53
+ - else
54
+ option
55
+ = options_for_select(column.filter)
56
+ - elsif column.filter == :range
57
+ .col-sm-5
58
+ input.tabulatr_filter.form-control type="text" id="#{name}_from" data-tabulatr-attribute="#{name}_from" name="#{iname}[from]"
59
+ span.col-sm-1.text-center —
60
+ .col-sm-5
61
+ input.tabulatr_filter.form-control type="text" id="#{name}_to" data-tabulatr-attribute="#{name}_to" name="#{iname}[to]"
62
+ - elsif column.filter == :checkbox
63
+ .col-xs-12
64
+ = select_tag(iname, options_for_select([ \
65
+ [t('tabulatr.boolean_filter.both'), ""],
66
+ [t('tabulatr.boolean_filter.no'), "false"],
67
+ [t('tabulatr.boolean_filter.yes'), "true"]] \
68
+ ), class: 'form-control no-chosen')
69
+ - elsif column.filter == :exact
70
+ input.tabulatr_filter.form-control type="text" id="#{name}_exact" data-tabulatr-attribute="#{name}" name="#{iname}"
71
+ - elsif column.filter == :date
72
+ select.form-control.no-chosen name="#{iname}[date][simple]" data-tabulatr-date-filter="#{formatted_name}_#{name}_filter"
73
+ option= I18n.t("tabulatr.date_filter.none")
74
+ option value="today"= I18n.t("tabulatr.date_filter.today")
75
+ option value="yesterday"= I18n.t("tabulatr.date_filter.yesterday")
76
+ option value="this_week"= I18n.t("tabulatr.date_filter.this_week")
77
+ option value="last_7_days"= I18n.t("tabulatr.date_filter.last_7_days")
78
+ option value="this_month"= I18n.t("tabulatr.date_filter.this_month")
79
+ option value="last_30_days"= I18n.t("tabulatr.date_filter.last_30_days")
80
+ option value="from_to"= I18n.t("tabulatr.date_filter.from_to")
81
+ .row.from_to.hidden
82
+ .col-xs-6
83
+ .control-group
84
+ label.control-label for="#{formatted_name}_#{name}_filter_from"
85
+ = "Von"
86
+ input.tabulatr_filter.form-control.date-picker.hidden.from_to type="text" id="#{formatted_name}_#{name}_filter_from" name="#{iname}[date][from]"
87
+ .col-xs-6
88
+ .control-group
89
+ label.control-label for="#{formatted_name}_#{name}_filter_from"
90
+ = "Bis"
91
+ input.tabulatr_filter.form-control.date-picker.from_to.hidden type="text" id="#{formatted_name}_#{name}_filter_to" name="#{iname}[date][to]"
92
+ - else
93
+ input.tabulatr_filter.form-control type="text" data-tabulatr-attribute="#{name}" name="#{iname}[like]"
@@ -20,11 +20,6 @@
20
20
  / WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  - if table_options[:filter] && columns.select(&:filter).present?
23
- .dropdown
24
- a.btn.btn-default data-toggle="dropdown" href="#"
25
- i.icon-filter.glyphicon.glyphicon-filter.fa.fa-filter'
26
- i.icon-caret-down.glyphicon.glyphicon-chevron-down.fa.fa-caret-down
27
- ul.dropdown-menu role="menu" aria-labelledby="dLabel"
28
- - columns.select(&:filter).each do |column|
29
- li
30
- = link_to column.human_name, '#', "data-show-table-filter" => column.full_name
23
+ a.btn.btn-default data-show-filters-for=table_id href="#"
24
+ => t('tabulatr.filter')
25
+ i.icon-caret-right.glyphicon.glyphicon-chevron-right.fa.fa-caret-right
@@ -23,29 +23,30 @@
23
23
  klass: klass, classname: classname, table_id: table_id,
24
24
  formatted_name: formatted_name }
25
25
 
26
- .tabulatr-table-controls-wrapper.row data-table-id=table_id
27
- .tabulatr-filter-menu-wrapper.col-xs-3.col-sm-1 data-table-id=table_id
28
- = render '/tabulatr/tabulatr_filter_menu', opts
29
-
30
- .tabulatr-batch-actions-menu-wrapper.col-xs-3.col-sm-1 data-table-id=table_id
31
- = render '/tabulatr/tabulatr_batch_actions_menu', opts
32
-
33
- - if tabulatr_data.search?
34
- .tabulatr-fuzzy-search-field-wrapper.col-xs-6.col-sm-2 data-table-id=table_id
35
- = render '/tabulatr/tabulatr_fuzzy_search_field', opts
36
-
37
- - if table_options[:pagination_position].in?([:top, :both])
38
- .tabulatr-paginator-wrapper.col-xs-12.col-sm-8 data-table-id=table_id
39
- = render '/tabulatr/tabulatr_paginator', opts
40
-
41
- .tabulatr-filter-dialog-wrapper data-table-id=table_id
42
- = render '/tabulatr/tabulatr_filter_dialog', opts
43
-
44
- - if table_options[:counter_position].in?([:top, :both])
45
- .tabulatr-info-string-wrapper data-table-id=table_id
46
- = render '/tabulatr/tabulatr_info_string', opts
47
-
48
- = render '/tabulatr/tabulatr_actual_table', opts
26
+ .row.tabulatr-outer-wrapper data-table-id=table_id
27
+ .tabulatr-filter-col data-table-id=table_id
28
+ = render '/tabulatr/tabulatr_filter_dialog', opts
29
+ .tabulatr-table-col.col-xs-12 data-table-id=table_id
30
+ .tabulatr-table-controls-wrapper.row data-table-id=table_id
31
+ .tabulatr-filter-menu-wrapper.col-xs-3.col-sm-1 data-table-id=table_id
32
+ = render '/tabulatr/tabulatr_filter_menu', opts
33
+
34
+ .tabulatr-batch-actions-menu-wrapper.col-xs-3.col-sm-1 data-table-id=table_id
35
+ = render '/tabulatr/tabulatr_batch_actions_menu', opts
36
+
37
+ - if tabulatr_data.search?
38
+ .tabulatr-fuzzy-search-field-wrapper.col-xs-6.col-sm-2 data-table-id=table_id
39
+ = render '/tabulatr/tabulatr_fuzzy_search_field', opts
40
+
41
+ - if table_options[:pagination_position].in?([:top, :both])
42
+ .tabulatr-paginator-wrapper.col-xs-12.col-sm-8 data-table-id=table_id
43
+ = render '/tabulatr/tabulatr_paginator', opts
44
+
45
+
46
+ - if table_options[:counter_position].in?([:top, :both])
47
+ .tabulatr-info-string-wrapper data-table-id=table_id
48
+ = render '/tabulatr/tabulatr_info_string', opts
49
+ = render '/tabulatr/tabulatr_actual_table', opts
49
50
 
50
51
  - if table_options[:counter_position].in?([:bottom, :both])
51
52
  .tabulatr-info-string-wrapper data-table-id=table_id
@@ -46,12 +46,12 @@ module Tabulatr::Data::DSL
46
46
 
47
47
  def column(name, header: nil, sort_sql: nil, filter_sql: nil, sql: nil, table_column_options: {},
48
48
  classes: nil, width: false, align: false, valign: false, wrap: nil, th_html: false,
49
- filter_html: false, filter: true, sortable: true, format: nil, map: true, cell_style: {},
49
+ filter_html: false, filter_label: nil, filter: true, sortable: true, format: nil, map: true, cell_style: {},
50
50
  header_style: {},
51
51
  &block)
52
52
  @table_columns ||= []
53
53
  table_column_options = {classes: classes, width: width, align: align, valign: valign, wrap: wrap,
54
- th_html: th_html, filter_html: filter_html, filter: filter, sortable: sortable,
54
+ th_html: th_html, filter_html: filter_html, filter_label: filter_label, filter: filter, sortable: sortable,
55
55
  format: format, map: map, cell_style: cell_style, header_style: header_style,
56
56
  header: header
57
57
  }.merge(table_column_options)
@@ -59,8 +59,8 @@ module Tabulatr::Data::DSL
59
59
  table_column = Tabulatr::Renderer::Column.from(
60
60
  table_column_options.merge(name: name,
61
61
  klass: @base,
62
- sort_sql: sort_sql || sql || "#{table_name}.#{name}",
63
- filter_sql: filter_sql || sql || "#{table_name}.#{name}",
62
+ sort_sql: sort_sql || sql || "#{main_class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name(name)}",
63
+ filter_sql: filter_sql || sql || "#{main_class.quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name(name)}",
64
64
  table_name: table_name.to_sym,
65
65
  output: block_given? ? block : ->(record){record.send(name)}))
66
66
  @table_columns << table_column
@@ -68,35 +68,35 @@ module Tabulatr::Data::DSL
68
68
 
69
69
  def association(assoc, name, header: nil, sort_sql: nil, filter_sql: nil, sql: nil, table_column_options: {},
70
70
  classes: nil, width: false, align: false, valign: false, wrap: nil, th_html: false,
71
- filter_html: false, filter: true, sortable: true, format: nil, map: true, cell_style: {},
71
+ filter_html: false, filter_label: nil, filter: true, sortable: true, format: nil, map: true, cell_style: {},
72
72
  header_style: {},
73
73
  &block)
74
74
  @table_columns ||= []
75
75
  table_column_options = {classes: classes, width: width, align: align, valign: valign, wrap: wrap,
76
- th_html: th_html, filter_html: filter_html, filter: filter, sortable: sortable,
76
+ th_html: th_html, filter_html: filter_html, filter_label: filter_label, filter: filter, sortable: sortable,
77
77
  format: format, map: map, cell_style: cell_style, header_style: header_style,
78
78
  header: header
79
79
  }.merge(table_column_options)
80
80
  assoc_klass = main_class.reflect_on_association(assoc.to_sym)
81
- t_name = assoc_klass.try(:table_name)
81
+ t_name = assoc_klass.try(:quoted_table_name)
82
82
  table_column = Tabulatr::Renderer::Association.from(
83
83
  table_column_options.merge(name: name, table_name: assoc,
84
84
  klass: assoc_klass.try(:klass),
85
- sort_sql: sort_sql || sql || "#{t_name}.#{name}",
86
- filter_sql: filter_sql || sql || "#{t_name}.#{name}",
87
- output: block_given? ? block : ->(record){record.send(assoc).try(name)}))
85
+ sort_sql: sort_sql || sql || "#{t_name}.#{ActiveRecord::Base.connection.quote_column_name(name)}",
86
+ filter_sql: filter_sql || sql || "#{t_name}.#{ActiveRecord::Base.connection.quote_column_name(name)}",
87
+ output: block_given? ? block : ->(record){a=record.send(assoc); a.try(:read_attribute, name) || a.try(name)}))
88
88
  @table_columns << table_column
89
89
  end
90
90
 
91
91
  def actions(header: nil, name: nil, table_column_options: {},
92
92
  classes: nil, width: false, align: false, valign: false, wrap: nil, th_html: false,
93
- filter_html: false, filter: true, sortable: true, format: nil, map: true, cell_style: {},
93
+ filter_html: false, filter_label: nil, filter: true, sortable: true, format: nil, map: true, cell_style: {},
94
94
  header_style: {},
95
95
  &block)
96
96
  raise 'give a block to action column' unless block_given?
97
97
  @table_columns ||= []
98
98
  table_column_options = {classes: classes, width: width, align: align, valign: valign, wrap: wrap,
99
- th_html: th_html, filter_html: filter_html, filter: filter, sortable: sortable,
99
+ th_html: th_html, filter_html: filter_html, filter_label: filter_label, filter: filter, sortable: sortable,
100
100
  format: format, map: map, cell_style: cell_style, header_style: header_style
101
101
  }.merge(table_column_options)
102
102
  table_column = Tabulatr::Renderer::Action.from(
@@ -67,7 +67,7 @@ module Tabulatr::Data::Filtering
67
67
 
68
68
  def apply_condition(n,v)
69
69
  if ['true', 'false'].include?(v)
70
- @relation = @relation.where(:"#{n.filter_sql}" => Tabulatr::Utility.string_to_boolean(v))
70
+ @relation = @relation.where("#{n.filter_sql} = ?", Tabulatr::Utility.string_to_boolean(v))
71
71
  elsif v.is_a?(String)
72
72
  apply_string_condition("#{n.filter_sql} = ?", v)
73
73
  elsif v.is_a?(Hash)
@@ -25,7 +25,7 @@ class Tabulatr::Renderer::Column
25
25
  include ActiveModel::Model
26
26
 
27
27
  attr_accessor *%i{name header width align valign wrap type th_html filter_html
28
- filter filter_width range_filter_symbol
28
+ filter_label filter filter_width range_filter_symbol
29
29
  sortable table_name block klass format map classes cell_style header_style
30
30
  sort_sql filter_sql output}
31
31
 
@@ -40,6 +40,7 @@ class Tabulatr::Renderer::Column
40
40
  wrap: nil,
41
41
  th_html: false,
42
42
  filter_html: false,
43
+ filter_label: nil,
43
44
  filter: true,
44
45
  sortable: true,
45
46
  format: nil,
@@ -62,6 +63,7 @@ class Tabulatr::Renderer::Column
62
63
  wrap: wrap,
63
64
  th_html: th_html,
64
65
  filter_html: filter_html,
66
+ filter_label: filter_label,
65
67
  filter: filter,
66
68
  sortable: sortable,
67
69
  format: format,
@@ -85,6 +87,7 @@ class Tabulatr::Renderer::Column
85
87
  self.wrap = hash[:wrap] || self.wrap
86
88
  self.th_html = hash[:th_html] || self.th_html
87
89
  self.filter_html = hash[:filter_html] || self.filter_html
90
+ self.filter_label = hash[:filter_label] || self.filter_label
88
91
  self.filter = hash[:filter] || self.filter
89
92
  self.sortable = hash[:sortable] || self.sortable
90
93
  self.format = hash[:format] || self.format
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module Tabulatr
25
- VERSION = "0.9.12"
25
+ VERSION = "0.9.13"
26
26
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tabulatr::Data::DSL do
4
+ class DummySpecClass
5
+ extend Tabulatr::Data::DSL
6
+ end
7
+
8
+ before(:each) do
9
+ DummySpecClass.instance_variable_set('@table_columns', [])
10
+ end
11
+
12
+ describe '#column' do
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
17
+ expect(table_column.filter_sql).to match(/\"products\".\"active\"/)
18
+ expect(table_column.sort_sql).to match(/\"products\".\"active\"/)
19
+ end
20
+ end
21
+
22
+ describe '#association' do
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
27
+ expect(table_column.filter_sql).to match(/\"vendors\".\"name\"/)
28
+ expect(table_column.sort_sql).to match(/\"vendors\".\"name\"/)
29
+ end
30
+ end
31
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Tabulatr::Renderer do
4
4
 
5
5
  def double_view
6
- view = double(controller: double(controller_name: 'products', action_name: 'index'))
6
+ view = double(controller: double(controller_name: 'products', action_name: 'index'), render: '')
7
7
  view.instance_variable_set('@_tabulatr_table_index', 0)
8
8
  view
9
9
  end
@@ -24,4 +24,14 @@ describe Tabulatr::Renderer do
24
24
  expect(renderer.instance_variable_get('@table_options')[:persistent]).to eq true
25
25
  end
26
26
  end
27
+
28
+ describe '#build_table' do
29
+ it 'gets columns by their names' do
30
+ renderer = Tabulatr::Renderer.new(Product, double_view)
31
+ renderer.build_table(['_buttons'], 'ProductTabulatrData')
32
+ columns = renderer.instance_variable_get('@columns')
33
+ expect(columns.count).to be(1)
34
+ expect(columns.first).to be_instance_of(Tabulatr::Renderer::Buttons)
35
+ end
36
+ end
27
37
  end
data/tabulatr.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
 
25
25
 
26
26
  s.add_runtime_dependency('rails', '~> 4.0')
27
- s.add_dependency('slim', '~> 2.0.0', '>= 2.0.0')
27
+ s.add_dependency('slim', '~> 2.0')
28
28
  s.add_dependency('tilt', '~> 1.4', '>= 1.4.1')
29
29
  s.add_dependency('font-awesome-rails', '~> 4.0')
30
30
  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.12
4
+ version: 0.9.13
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-10-07 00:00:00.000000000 Z
13
+ date: 2014-11-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -32,20 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: 2.0.0
36
- - - ">="
37
- - !ruby/object:Gem::Version
38
- version: 2.0.0
35
+ version: '2.0'
39
36
  type: :runtime
40
37
  prerelease: false
41
38
  version_requirements: !ruby/object:Gem::Requirement
42
39
  requirements:
43
40
  - - "~>"
44
41
  - !ruby/object:Gem::Version
45
- version: 2.0.0
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: 2.0.0
42
+ version: '2.0'
49
43
  - !ruby/object:Gem::Dependency
50
44
  name: tilt
51
45
  requirement: !ruby/object:Gem::Requirement
@@ -213,6 +207,7 @@ files:
213
207
  - spec/dummy/public/favicon.ico
214
208
  - spec/features/tabulatrs_spec.rb
215
209
  - spec/lib/tabulatr/data/data_spec.rb
210
+ - spec/lib/tabulatr/data/dsl_spec.rb
216
211
  - spec/lib/tabulatr/data/filtering_spec.rb
217
212
  - spec/lib/tabulatr/data/formatting_spec.rb
218
213
  - spec/lib/tabulatr/data/pagination_spec.rb
@@ -311,6 +306,7 @@ test_files:
311
306
  - spec/dummy/public/favicon.ico
312
307
  - spec/features/tabulatrs_spec.rb
313
308
  - spec/lib/tabulatr/data/data_spec.rb
309
+ - spec/lib/tabulatr/data/dsl_spec.rb
314
310
  - spec/lib/tabulatr/data/filtering_spec.rb
315
311
  - spec/lib/tabulatr/data/formatting_spec.rb
316
312
  - spec/lib/tabulatr/data/pagination_spec.rb