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
@@ -0,0 +1,96 @@
1
+ #--
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ class Tabulatr::Renderer
25
+
26
+ def initialize(klass, view,
27
+ filter: true, # false for no filter row at all
28
+ search: true, # show fuzzy search field
29
+ paginate: false, # true to show paginator
30
+ pagesize: 20, # default pagesize
31
+ sortable: true, # true to allow sorting (can be specified for every sortable column)
32
+ batch_actions: false, # :name => value hash of batch action stuff
33
+ footer_content: false, # if given, add a <%= content_for <footer_content> %> before the </table>
34
+ path: '#') # where to send the AJAX-requests to
35
+ @klass = klass
36
+ @view = view
37
+ @table_options = {
38
+ filter: filter,
39
+ search: search,
40
+ paginate: paginate,
41
+ pagesize: pagesize,
42
+ sortable: sortable,
43
+ batch_actions: batch_actions,
44
+ footer_content: footer_content,
45
+ path: path
46
+ }
47
+ @classname = @klass.name.underscore
48
+ end
49
+
50
+ def build_table(&block)
51
+ if block_given?
52
+ @columns = ColumnsFromBlock.process @klass, &block
53
+ else
54
+ tdc = "#{@klass.name}TabulatrData".constantize.new(@klass)
55
+ @columns = tdc.table_columns
56
+ end
57
+
58
+ @view.render(partial: '/tabulatr/tabulatr_table', locals: {
59
+ columns: @columns,
60
+ table_options: @table_options,
61
+ klass: @klass,
62
+ classname: @classname
63
+ })
64
+ end
65
+
66
+ def build_static_table(records, &block)
67
+ @columns = ColumnsFromBlock.process @klass, &block
68
+
69
+ @view.render(partial: '/tabulatr/tabulatr_static_table', locals: {
70
+ columns: @columns,
71
+ table_options: @table_options,
72
+ klass: @klass,
73
+ classname: @classname,
74
+ records: records
75
+ })
76
+ end
77
+
78
+ def self.build_static_table(records, view, toptions={}, &block)
79
+ return '' unless records.present?
80
+ klass = records.first.class
81
+ new(klass, view, toptions).build_static_table(records, &block)
82
+ end
83
+
84
+ def self.build_table(klass, view, toptions={}, &block)
85
+ new(klass, view, toptions).build_table(&block)
86
+ end
87
+
88
+ end
89
+
90
+ require_relative './column'
91
+ require_relative './association'
92
+ require_relative './action'
93
+ require_relative './checkbox'
94
+ require_relative './columns'
95
+ require_relative './columns_from_block'
96
+
@@ -0,0 +1,46 @@
1
+ #--
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ module Tabulatr::Utility
25
+ def self.like_statement
26
+ case ActiveRecord::Base.connection.class.to_s
27
+ when "ActiveRecord::ConnectionAdapters::MysqlAdapter",
28
+ "ActiveRecord::ConnectionAdapters::Mysql2Adapter",
29
+ "ActiveRecord::ConnectionAdapters::SQLiteAdapter",
30
+ "ActiveRecord::ConnectionAdapters::SQLite3Adapter"
31
+ then 'LIKE'
32
+ when "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter" then 'ILIKE'
33
+ else
34
+ warn("Tabulatr Warning: Don't know which LIKE operator to use for the ConnectionAdapter '#{ActiveRecord::Base.connection.class}'.\n")
35
+ 'LIKE'
36
+ end
37
+ end
38
+
39
+ def self.string_to_boolean str
40
+ if str.downcase == 'true'
41
+ true
42
+ elsif str.downcase == 'false'
43
+ false
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,26 @@
1
- class Tabulatr
2
- VERSION = "0.6.0"
1
+ #--
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ module Tabulatr
25
+ VERSION = "0.8.0"
3
26
  end
data/lib/tabulatr.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Peter Horn, Provideal GmbH
2
+ # Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -21,14 +21,55 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- require 'tabulatr/tabulatr'
24
+ module Tabulatr
25
+ def self.config &block
26
+ yield self
27
+ end
28
+
29
+ mattr_accessor :bootstrap_paginator, instance_accessor: false do
30
+ 'create_ul_paginator'
31
+ end
32
+
33
+ def self.secret_tokens=(secret_tokens)
34
+ @@secret_tokens = secret_tokens
35
+ end
36
+
37
+ def self.secret_tokens
38
+ @@secret_tokens ||= []
39
+ end
40
+ end
41
+
25
42
  require 'tabulatr/engine'
26
- require 'whiny_hash'
43
+ require 'tabulatr/renderer/renderer'
44
+ require 'tabulatr/data/data'
45
+ require 'tabulatr/json_builder'
46
+ require 'tabulatr/generators/railtie' if defined?(Rails)
27
47
 
28
48
  #--
29
49
  # Mainly Monkey Patching...
30
50
  #--
31
- Dir[File.join(File.dirname(__FILE__), "initializers", "*.rb")].each do |file|
51
+ Dir[File.join(File.dirname(__FILE__), "tabulatr", "rails", "*.rb")].each do |file|
52
+ require file
53
+ end
54
+
55
+ #---
56
+ # Utility methods
57
+ #--
58
+ Dir[File.join(File.dirname(__FILE__), "tabulatr", "utility", "*.rb")].each do |file|
59
+ require file
60
+ end
61
+
62
+
63
+ #--
64
+ # Renderer methods
65
+ #--
66
+ #---
67
+ # Utility methods
68
+ #--
69
+ # Dir[File.join(File.dirname(__FILE__), "tabulatr", "renderer", "row_builder.rb")].each do |file|
70
+ # require file
71
+ # end
72
+ Dir[File.join(File.dirname(__FILE__), "tabulatr", "renderer", "*.rb")].each do |file|
32
73
  require file
33
74
  end
34
75
 
data/lib/tabulatr2.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative './tabulatr'
@@ -9,7 +9,7 @@
9
9
  * compiled file, but it's generally better to create a new file per style scope.
10
10
  *
11
11
  *= require_self
12
- *= require_tree .
12
+ *= require tabulatr
13
13
  */
14
14
 
15
- @import "bootstrap";
15
+ @import "bootstrap";
@@ -1,17 +1,22 @@
1
1
  class ProductsController < ApplicationController
2
2
 
3
3
  def simple_index
4
- tabulatr_for Product
4
+ begin
5
+ tabulatr_for Product
6
+ rescue Exception => e
7
+ puts e.backtrace
8
+ raise e
9
+ end
5
10
  end
6
11
 
7
12
  def one_item_per_page_with_pagination
8
13
  @pagination = true
9
- tabulatr_for Product, {action: 'one_item_per_page'}
14
+ tabulatr_for Product, render_action: 'one_item_per_page'
10
15
  end
11
16
 
12
17
  def one_item_per_page_without_pagination
13
18
  @pagination = false
14
- tabulatr_for Product, {action: 'one_item_per_page'}
19
+ tabulatr_for Product, render_action: 'one_item_per_page'
15
20
  end
16
21
 
17
22
  def count_tags
@@ -21,4 +26,23 @@ class ProductsController < ApplicationController
21
26
  def stupid_array
22
27
  @products = Product.order('price asc').limit(11).to_a
23
28
  end
29
+
30
+ def with_batch_actions
31
+ begin
32
+ tabulatr_for Product, render_action: 'with_batch_actions' do |batch_actions|
33
+ batch_actions.destroy do |ids|
34
+ ids.each do |id|
35
+ Product.find(id).destroy
36
+ end
37
+ end
38
+ end
39
+ rescue Exception => e
40
+ puts e.backtrace
41
+ raise e
42
+ end
43
+ end
44
+
45
+ def implicit_columns
46
+ tabulatr_for Product
47
+ end
24
48
  end
@@ -1,2 +1,3 @@
1
1
  class Vendor < ActiveRecord::Base
2
+ has_many :products
2
3
  end
@@ -0,0 +1,29 @@
1
+ class ProductTabulatrData < Tabulatr::Data
2
+
3
+ search :vendor_product_name, :price, :title
4
+
5
+ # search do |query|
6
+ # "products.title LIKE '#{query}'"
7
+ # end
8
+
9
+ column :title
10
+ column :id
11
+ column :price do "#{record.price} EUR" end # <- Block evaluiert im Kontext EINES Records
12
+ column :edit_link do link_to "edit #{record.title}", product_path(record) end
13
+ # column :name,
14
+ # sort: "firstname || ' ' || lastname"
15
+ # filter: "firstname || ' ' || lastname"
16
+ # do
17
+ # "#{firstname} #{lastname}"
18
+ # end
19
+ column :vendor_product_name, sort_sql: "products.title || '' || vendors.name", filter_sql: "products.title || '' || vendors.name" do
20
+ "#{record.title} from #{record.vendor.try(:name)}"
21
+ end
22
+ column :active
23
+ column :updated_at, table_column_options: { filter: :date } do "#{record.updated_at.strftime('%H:%M %d.%m.%Y')}" end
24
+ association :vendor, :name
25
+ association :tags, :title do |r|
26
+ "'#{r.tags.map(&:title).map(&:upcase).join(', ')}'"
27
+ end
28
+
29
+ end
@@ -0,0 +1 @@
1
+ <%= table_for Product, :paginate => true %>
@@ -1,4 +1,4 @@
1
- <%= table_for Product, :paginate => @pagination, :default_pagesize => 1 do |t|
1
+ <%= table_for Product, :paginate => @pagination, :pagesize => 1 do |t|
2
2
  t.checkbox
3
3
  t.column :title
4
4
  t.column :price, filter: :range
@@ -1,9 +1,11 @@
1
- <%= table_for Product, :paginate => @pagination do |t|
1
+ <%= table_for Product, :paginate => true,
2
+ batch_actions: {a: "Hallo", b: "Du da!"} do |t|
2
3
  t.checkbox
3
- t.column :title
4
+ t.column :title, sortable: true
4
5
  t.column :price, filter: :range
5
- t.column :active
6
- t.column :updated_at
6
+ t.column :active, sortable: false
7
+ t.column :vendor_product_name, header: 'Product by vendor'
8
+ t.column :updated_at, filter: :date
7
9
  t.association :vendor, :name, filter: :exact
8
10
  t.association :tags, :title
9
11
  end %>
@@ -1,4 +1,4 @@
1
- <%= table_for @products do |t|
1
+ <%= static_table_for @products do |t|
2
2
  t.column :title
3
3
  t.column :title, format: :foo_me
4
4
  t.column :title, format: ->(a) { bar_me(a) }
@@ -0,0 +1,10 @@
1
+ <%= table_for Product, batch_actions: {'destroy' => "Delete"}, :paginate => @pagination do |t|
2
+ t.checkbox
3
+ t.column :title, sortable: true
4
+ t.column :price, filter: :range
5
+ t.column :active
6
+ t.column :vendor_product_name, header: 'Product by vendor'
7
+ t.column :updated_at
8
+ t.association :vendor, :name, filter: :exact
9
+ t.association :tags, :title
10
+ end %>
@@ -5,10 +5,31 @@ en:
5
5
  batch_actions: 'Batch actions'
6
6
  count: 'Showing: %{current} of total %{total}. %{per_page} items per page.'
7
7
  apply_filters: 'Apply'
8
+ search: 'Search'
9
+ date_filter:
10
+ none: ''
11
+ today: "Today"
12
+ yesterday: Yesterday
13
+ this_week: This Week
14
+ last_7_days: Last 7 Days
15
+ this_month: This Month
16
+ last_30_days: Last 30 Days
17
+ from_to: From - To
18
+
8
19
  de:
9
20
  tabulatr:
10
21
  rows_per_page: 'Ergebnisse pro Seite'
11
22
  filter: 'Filter'
12
23
  batch_actions: 'Batch-Aktionen'
13
24
  count: 'Zeige %{current} von insgesamt %{total}. %{per_page} pro Seite.'
14
- apply_filters: 'Anwenden'
25
+ apply_filters: 'Anwenden'
26
+ search: 'Suche'
27
+ date_filter:
28
+ none: ''
29
+ today: "Heute"
30
+ yesterday: Gestern
31
+ this_week: Diese Woche
32
+ last_7_days: Letzte 7 Tage
33
+ this_month: Dieser Monat
34
+ last_30_days: Letzte 30 Tage
35
+ from_to: Von - Bis
@@ -1,11 +1,13 @@
1
1
  Rails.application.routes.draw do
2
- resources :products, only: [:index] do
2
+ resources :products, only: [:index, :show] do
3
3
  collection do
4
4
  get :simple_index
5
5
  get :one_item_per_page_with_pagination
6
6
  get :one_item_per_page_without_pagination
7
7
  get :count_tags
8
8
  get :stupid_array
9
+ get :with_batch_actions
10
+ get :implicit_columns
9
11
  end
10
12
  end
11
13
 
@@ -53,7 +53,7 @@ describe "Tabulatr" do
53
53
  product.tags << tag
54
54
  product.save
55
55
  visit simple_index_products_path
56
- page.should have_content tag.title
56
+ page.should have_content tag.title.upcase
57
57
  end
58
58
  end
59
59
 
@@ -128,17 +128,22 @@ describe "Tabulatr" do
128
128
  Product.create!(:title => n, :active => true, :price => 10.0)
129
129
  end
130
130
  visit simple_index_products_path
131
- find('.icon-filter').trigger('click')
132
- fill_in("product_filter[title][like]", :with => "ore")
131
+ find("a[href='#tabulatr_filter_dialog_product']").click()
132
+ within("#tabulatr_filter_dialog_product") do
133
+ fill_in("product_filter[title][like]", :with => "ore")
134
+ end
133
135
  click_button("Apply")
134
- sleep(2)
135
136
  page.should have_content("lorem")
136
137
  page.should have_content("labore")
137
138
  page.should have_content("dolore")
138
- find('.icon-filter').trigger('click')
139
- fill_in("product_filter[title][like]", :with => "loreem")
139
+ find("a[href='#tabulatr_filter_dialog_product']").click()
140
+ within("#tabulatr_filter_dialog_product") do
141
+ fill_in("product_filter[title][like]", :with => "loreem")
142
+ end
140
143
  click_button("Apply")
141
144
  page.should_not have_content("lorem")
145
+ page.should_not have_content("labore")
146
+ page.should_not have_content("dolore")
142
147
  end
143
148
 
144
149
  it "filters" do
@@ -157,7 +162,6 @@ describe "Tabulatr" do
157
162
  Product.create!([{title: 'foo', price: 5}, {title: 'bar', price: 17}])
158
163
  visit simple_index_products_path
159
164
  find('.icon-filter').trigger('click')
160
- page.save_screenshot('/Users/crunch/Desktop/file.png')
161
165
  within('form.tabulatr_filter_form') do
162
166
  fill_in("product_filter[price][from]", :with => 4)
163
167
  fill_in("product_filter[price][to]", :with => 10)
@@ -184,14 +188,14 @@ describe "Tabulatr" do
184
188
  (1..10).each do |i|
185
189
  page.should have_content names[i-1]
186
190
  end
187
- find("#product_sort_title").trigger('click')
191
+ find("#product_sort_title").click
188
192
  snames = names.sort
189
193
  (1..10).each do |i|
190
- page.should have_content snames[-i]
194
+ page.should have_content snames[i-1]
191
195
  end
192
- find("#product_sort_title").trigger('click')
196
+ find("#product_sort_title").click
193
197
  (1..10).each do |i|
194
- page.should have_content snames[i-1]
198
+ page.should have_content snames[-i]
195
199
  end
196
200
  end
197
201
  end
@@ -224,4 +228,42 @@ describe "Tabulatr" do
224
228
  end
225
229
  end
226
230
  end
231
+
232
+ describe "Batch actions", js: true do
233
+ it "shows the actions" do
234
+ visit with_batch_actions_products_path
235
+ find(".tabulatr-wrench").should have_content('Batch actions')
236
+ end
237
+
238
+ it "hides the actions if there are none" do
239
+ visit simple_index_products_path
240
+ page.should have_no_selector('.tabulatr-wrench')
241
+ end
242
+
243
+ it 'is initially not active' do
244
+ visit with_batch_actions_products_path
245
+ page.should have_selector('.tabulatr-wrench.disabled')
246
+ end
247
+
248
+ it 'becomes active when a checkbox is checked' do
249
+ product = Product.create!(:title => names[0], :active => true, :price => 10.0)
250
+ visit with_batch_actions_products_path
251
+ find('.tabulatr-checkbox').trigger('click')
252
+ page.should have_no_selector('.tabulatr-wrench.disabled')
253
+ page.should have_selector('.tabulatr-wrench')
254
+ end
255
+
256
+ it 'executes the action when clicked' do
257
+ product1 = Product.create!(:title => names[0], :active => true, :price => 10.0)
258
+ product2 = Product.create!(:title => names[1], :active => true, :price => 10.0)
259
+ product3 = Product.create!(:title => names[2], :active => true, :price => 10.0)
260
+ page.has_css?(".tabulatr_table tbody tr", :count => 3)
261
+ visit with_batch_actions_products_path
262
+ find(".tabulatr-checkbox[value='#{product1.id}']").trigger('click')
263
+ find(".tabulatr-checkbox[value='#{product3.id}']").trigger('click')
264
+ find('.tabulatr-wrench').trigger('click')
265
+ find("a[name='product_batch\\[destroy\\]']").trigger('click')
266
+ page.has_css?(".tabulatr_table tbody tr", :count => 1)
267
+ end
268
+ end
227
269
  end
data/tabulatr.gemspec CHANGED
@@ -24,6 +24,6 @@ Gem::Specification.new do |s|
24
24
 
25
25
 
26
26
  s.add_runtime_dependency('rails', '>= 4.0.0')
27
- s.add_dependency('whiny_hash', '>= 0.0.2')
27
+ s.add_dependency('slim', '>= 2.0.1')
28
28
  s.add_runtime_dependency('activerecord_outer_joins', '~> 0.0.1')
29
29
  end