tabulatr2 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +71 -27
  4. data/app/assets/javascripts/tabulatr/application.js +130 -133
  5. data/app/assets/stylesheets/tabulatr/application.css.scss +153 -0
  6. data/app/assets/stylesheets/tabulatr/bootstrap2_fixes.css.scss +24 -0
  7. data/app/views/tabulatr/_tabulatr_actual_table.html.slim +35 -0
  8. data/app/views/tabulatr/_tabulatr_batch_actions_menu.html.slim +34 -0
  9. data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +84 -0
  10. data/app/views/tabulatr/_tabulatr_filter_menu.html.slim +30 -0
  11. data/app/views/tabulatr/_tabulatr_fuzzy_search_field.html.slim +24 -0
  12. data/app/views/tabulatr/_tabulatr_info_string.html.slim +23 -0
  13. data/app/views/tabulatr/_tabulatr_paginator.html.slim +24 -0
  14. data/app/views/tabulatr/_tabulatr_static_table.html.slim +33 -0
  15. data/app/views/tabulatr/_tabulatr_table.html.slim +45 -0
  16. data/lib/tabulatr/data/column_name_builder.rb +86 -0
  17. data/lib/tabulatr/data/data.rb +135 -0
  18. data/lib/tabulatr/data/dsl.rb +61 -0
  19. data/lib/tabulatr/data/filtering.rb +101 -0
  20. data/lib/tabulatr/data/formatting.rb +65 -0
  21. data/lib/tabulatr/data/invoker.rb +37 -0
  22. data/lib/tabulatr/data/pagination.rb +48 -0
  23. data/lib/tabulatr/data/proxy.rb +41 -0
  24. data/lib/tabulatr/{tabulatr/batch_actions.rb → data/sorting.rb} +20 -23
  25. data/lib/tabulatr/engine.rb +24 -1
  26. data/lib/tabulatr/generators/railtie.rb +33 -0
  27. data/lib/tabulatr/generators/resource_override.rb +35 -0
  28. data/lib/{generators → tabulatr/generators}/tabulatr/install_generator.rb +21 -3
  29. data/lib/{generators → tabulatr/generators}/tabulatr/templates/tabulatr.yml +3 -1
  30. data/lib/tabulatr/generators/tabulatr/templates/tabulatr_data.rb +18 -0
  31. data/lib/tabulatr/json_builder.rb +94 -0
  32. data/lib/tabulatr/rails/action_controller.rb +36 -0
  33. data/lib/{initializers → tabulatr/rails}/action_view.rb +6 -3
  34. data/lib/{initializers → tabulatr/rails}/active_record.rb +11 -19
  35. data/lib/tabulatr/renderer/action.rb +32 -0
  36. data/lib/tabulatr/{tabulatr/formattr.rb → renderer/association.rb} +19 -30
  37. data/lib/tabulatr/renderer/checkbox.rb +36 -0
  38. data/lib/tabulatr/renderer/column.rb +113 -0
  39. data/lib/{initializers/mark_as_localizable.rb → tabulatr/renderer/columns.rb} +13 -15
  40. data/lib/tabulatr/renderer/columns_from_block.rb +56 -0
  41. data/lib/tabulatr/renderer/renderer.rb +96 -0
  42. data/lib/tabulatr/utility/utility.rb +46 -0
  43. data/lib/tabulatr/version.rb +25 -2
  44. data/lib/tabulatr.rb +45 -4
  45. data/lib/tabulatr2.rb +1 -0
  46. data/spec/dummy/app/assets/stylesheets/application.css.scss +2 -2
  47. data/spec/dummy/app/controllers/products_controller.rb +27 -3
  48. data/spec/dummy/app/models/vendor.rb +1 -0
  49. data/spec/dummy/app/tabulatr_data/product_tabulatr_data.rb +29 -0
  50. data/spec/dummy/app/views/products/implicit_columns.html.erb +1 -0
  51. data/spec/dummy/app/views/products/one_item_per_page.html.erb +1 -1
  52. data/spec/dummy/app/views/products/simple_index.html.erb +6 -4
  53. data/spec/dummy/app/views/products/stupid_array.html.erb +1 -1
  54. data/spec/dummy/app/views/products/with_batch_actions.html.erb +10 -0
  55. data/spec/dummy/config/locales/tabulatr.yml +22 -1
  56. data/spec/dummy/config/routes.rb +3 -1
  57. data/spec/features/tabulatrs_spec.rb +53 -11
  58. data/tabulatr.gemspec +1 -1
  59. metadata +50 -42
  60. data/app/assets/images/tabulatr/buttons_lite_background.png +0 -0
  61. data/app/assets/images/tabulatr/pager_arrow_left.gif +0 -0
  62. data/app/assets/images/tabulatr/pager_arrow_left_off.gif +0 -0
  63. data/app/assets/images/tabulatr/pager_arrow_right.gif +0 -0
  64. data/app/assets/images/tabulatr/pager_arrow_right_off.gif +0 -0
  65. data/app/assets/images/tabulatr/sort_arrow_down.gif +0 -0
  66. data/app/assets/images/tabulatr/sort_arrow_down_off.gif +0 -0
  67. data/app/assets/images/tabulatr/sort_arrow_up.gif +0 -0
  68. data/app/assets/images/tabulatr/sort_arrow_up_off.gif +0 -0
  69. data/app/assets/stylesheets/tabulatr/application.css +0 -40
  70. data/lib/initializers/action_controller.rb +0 -13
  71. data/lib/tabulatr/tabulatr/adapter/active_record.rb +0 -84
  72. data/lib/tabulatr/tabulatr/adapter.rb +0 -55
  73. data/lib/tabulatr/tabulatr/data_cell.rb +0 -132
  74. data/lib/tabulatr/tabulatr/dummy_record.rb +0 -40
  75. data/lib/tabulatr/tabulatr/empty_cell.rb +0 -44
  76. data/lib/tabulatr/tabulatr/filter_cell.rb +0 -145
  77. data/lib/tabulatr/tabulatr/filter_icon.rb +0 -6
  78. data/lib/tabulatr/tabulatr/finder/find_for_table.rb +0 -187
  79. data/lib/tabulatr/tabulatr/finder.rb +0 -64
  80. data/lib/tabulatr/tabulatr/header_cell.rb +0 -146
  81. data/lib/tabulatr/tabulatr/json_builder.rb +0 -57
  82. data/lib/tabulatr/tabulatr/paginator.rb +0 -76
  83. data/lib/tabulatr/tabulatr/row_builder.rb +0 -128
  84. data/lib/tabulatr/tabulatr/security.rb +0 -21
  85. data/lib/tabulatr/tabulatr/settings.rb +0 -158
  86. data/lib/tabulatr/tabulatr.rb +0 -343
  87. data/spec/lib/tabulatr/tabulatr/finder/find_for_table_spec.rb +0 -187
  88. /data/lib/{generators → tabulatr/generators}/tabulatr/templates/tabulatr.rb +0 -0
@@ -1,187 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- class Example
5
- end
6
-
7
- describe Tabulatr::Finder do
8
- describe '.find_for_table' do
9
- before(:each) do
10
- Tabulatr::Security.stub(:validate!){ true }
11
- end
12
-
13
- context 'descends_from_activerecord' do
14
- it 'works fine' do
15
- expect{ subject.find_for_table(Product, {})}.to_not raise_error
16
- end
17
- end
18
-
19
- context 'doesn\'t descend_from_activerecord' do
20
- it 'raises an exception' do
21
- expect{ subject.find_for_table(Example, {})}.to raise_error
22
- end
23
- end
24
-
25
- it 'defines some methods' do
26
- result = subject.find_for_table(Product, {})
27
- result.should respond_to :__pagination
28
- result.should respond_to :to_tabulatr_json
29
- end
30
-
31
- it 'orders the result' do
32
- p1 = Product.create!(title: 'abc')
33
- p2 = Product.create!(title: 'mno')
34
- result = subject.find_for_table(Product, {
35
- sort_by: :title,
36
- orientation: :asc,
37
- arguments: 'id,title'
38
- }).to_tabulatr_json
39
- result[:data].length.should eq 2
40
- result[:data].first['id'].should eq p1.id
41
- result[:data].last['id'].should eq p2.id
42
- result = subject.find_for_table(Product, {
43
- sort_by: :title,
44
- orientation: :desc,
45
- arguments: 'id,title'
46
- }).to_tabulatr_json
47
- result[:data].length.should eq 2
48
- result[:data].first['id'].should eq p2.id
49
- result[:data].last['id'].should eq p1.id
50
- end
51
-
52
- it 'limits the result' do
53
- 3.times do |p|
54
- Product.create!
55
- end
56
- result = subject.find_for_table(Product, {
57
- arguments: 'id',
58
- pagesize: 2
59
- }).to_tabulatr_json
60
- Product.count.should eq 3
61
- result[:data].count.should eq 2
62
- end
63
-
64
- context 'page parameter not given' do
65
- it 'defaults to the first page' do
66
- result = subject.find_for_table(Product, {})
67
- result.__pagination[:page].should eq 1
68
- end
69
- end
70
-
71
- context 'page parameter is given' do
72
- it 'uses it' do
73
- result = subject.find_for_table(Product, {
74
- page: 3
75
- })
76
- result.__pagination[:page].should eq 3
77
- end
78
- end
79
-
80
- context 'append is "false"' do
81
- it 'converts from string to boolean' do
82
- result = subject.find_for_table(Product, {
83
- append: 'false',
84
- arguments: 'title'
85
- })
86
- result.__pagination[:append].should be_false
87
- end
88
- end
89
-
90
- context 'append is "true"' do
91
- it 'converts from string to boolean' do
92
- result = subject.find_for_table(Product, {
93
- append: 'true',
94
- arguments: 'title'
95
- })
96
- result.__pagination[:append].should be_true
97
- end
98
- end
99
-
100
- it 'filters the data' do
101
- # article_filter[body][like]:test
102
- p1 = Product.create!(title: 'foobar')
103
- p2 = Product.create!(title: 'buzz')
104
- result = subject.find_for_table(Product, {
105
- arguments: 'title',
106
- 'product_filter' => {
107
- 'title' => {
108
- like: 'buz'
109
- }
110
- }
111
- }).to_tabulatr_json
112
- Product.count.should eq 2
113
- result[:data].count.should eq 1
114
- expect(result[:data].first[:id]).to eq(p2.id)
115
- end
116
-
117
- it 'filters the data with belongs_to filter' do
118
- v = Vendor.create!(name: 'vnd')
119
- v2 = Vendor.create!(name: 'vnd_two')
120
- p1 = Product.create!(title: 'foobar', vendor: v)
121
- p2 = Product.create!(title: 'buzz', vendor: v2)
122
- result = subject.find_for_table(Product, {
123
- arguments: 'title,vendor:name',
124
- 'product_filter' => {
125
- '__association' => {
126
- 'vendor.name' => 'vnd'
127
- }
128
- }
129
- }).to_tabulatr_json
130
- Product.count.should eq 2
131
- Vendor.count.should eq 2
132
- result[:data].count.should eq 1
133
- expect(result[:data].first[:id]).to eq(p1.id)
134
- end
135
-
136
- it 'filters the data with has_many filter' do
137
- t = Tag.create!(title: 'keyword')
138
- t2 = Tag.create!(title: 'cloud')
139
- p1 = Product.create!(title: 'foobar')
140
- p2 = Product.create!(title: 'buzz')
141
- p1.tags << t
142
- p1.save!
143
- p2.tags << t2
144
- p2.save!
145
- result = subject.find_for_table(Product, {
146
- arguments: 'tags:title',
147
- 'product_filter' => {
148
- '__association' => {
149
- 'tags.title' => 'cloud'
150
- }
151
- }
152
- }).to_tabulatr_json
153
- Product.count.should eq 2
154
- Tag.count.should eq 2
155
- result[:data].count.should eq 1
156
- expect(result[:data].first[:id]).to eq(p2.id)
157
- end
158
-
159
- it 'invokes given batch actions' do
160
- p1 = Product.create!(title: 'foobar')
161
- p2 = Product.create!(title: 'buz')
162
- expect{ |b| subject.find_for_table(Product, {
163
- 'product_batch' => {
164
- foo: ''
165
- },
166
- 'tabulatr_checked' => {
167
- checked_ids: '1,2'
168
- }
169
- }, &b)
170
- }.to yield_control
171
- end
172
-
173
- it 'doesn\'t invoke when there are no batch actions' do
174
- p1 = Product.create!(title: 'foobar')
175
- p2 = Product.create!(title: 'buz')
176
- expect{ |b| subject.find_for_table(Product, {}, &b)}
177
- .to_not yield_control
178
- end
179
- end
180
-
181
- describe '.build_offset' do
182
- it 'figures the correct number of pages' do
183
- pages = Tabulatr::Finder.build_offset(1, 10, 302, {})
184
- expect(pages[:pages]).to eq 31
185
- end
186
- end
187
- end