datatable 0.1.0alpha2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. data/.bundle/config +3 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +9 -0
  5. data/Gemfile.lock +83 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +135 -0
  8. data/Rakefile +27 -0
  9. data/TODO +71 -0
  10. data/datatable.gemspec +20 -0
  11. data/example_app/.DS_Store +0 -0
  12. data/example_app/.gitignore +6 -0
  13. data/example_app/.rspec +1 -0
  14. data/example_app/Gemfile +35 -0
  15. data/example_app/Gemfile.lock +126 -0
  16. data/example_app/Rakefile +7 -0
  17. data/example_app/app/controllers/application_controller.rb +3 -0
  18. data/example_app/app/controllers/orders_controller.rb +13 -0
  19. data/example_app/app/datatables/orders_index.rb +31 -0
  20. data/example_app/app/helpers/application_helper.rb +2 -0
  21. data/example_app/app/models/customer.rb +4 -0
  22. data/example_app/app/models/item.rb +4 -0
  23. data/example_app/app/models/order.rb +5 -0
  24. data/example_app/app/models/order_item.rb +4 -0
  25. data/example_app/app/models/sales_rep.rb +3 -0
  26. data/example_app/app/views/layouts/application.html.erb +12 -0
  27. data/example_app/app/views/orders/index.html.erb +14 -0
  28. data/example_app/config/application.rb +41 -0
  29. data/example_app/config/boot.rb +6 -0
  30. data/example_app/config/database.yml.mysql +20 -0
  31. data/example_app/config/database.yml.pg +20 -0
  32. data/example_app/config/environment.rb +5 -0
  33. data/example_app/config/environments/development.rb +28 -0
  34. data/example_app/config/environments/production.rb +49 -0
  35. data/example_app/config/environments/test.rb +35 -0
  36. data/example_app/config/initializers/backtrace_silencers.rb +7 -0
  37. data/example_app/config/initializers/datatable.rb +6 -0
  38. data/example_app/config/initializers/inflections.rb +10 -0
  39. data/example_app/config/initializers/mime_types.rb +5 -0
  40. data/example_app/config/initializers/secret_token.rb +9 -0
  41. data/example_app/config/initializers/session_store.rb +8 -0
  42. data/example_app/config/locales/en.yml +5 -0
  43. data/example_app/config/routes.rb +6 -0
  44. data/example_app/config.ru +4 -0
  45. data/example_app/db/migrate/20110429185712_create_customers.rb +15 -0
  46. data/example_app/db/migrate/20110429185742_create_sales_reps.rb +14 -0
  47. data/example_app/db/migrate/20110429185807_create_items.rb +15 -0
  48. data/example_app/db/migrate/20110429185913_create_orders.rb +15 -0
  49. data/example_app/db/migrate/20110429190005_create_order_items.rb +14 -0
  50. data/example_app/db/schema.rb +53 -0
  51. data/example_app/db/seeds.rb +49 -0
  52. data/example_app/lib/tasks/.gitkeep +0 -0
  53. data/example_app/lib/tasks/setup.rake +12 -0
  54. data/example_app/public/404.html +26 -0
  55. data/example_app/public/422.html +26 -0
  56. data/example_app/public/500.html +26 -0
  57. data/example_app/public/datatable/css/demo_page.css +99 -0
  58. data/example_app/public/datatable/css/demo_table.css +539 -0
  59. data/example_app/public/datatable/css/demo_table_jui.css +521 -0
  60. data/example_app/public/datatable/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  61. data/example_app/public/datatable/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  62. data/example_app/public/datatable/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  63. data/example_app/public/datatable/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  64. data/example_app/public/datatable/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  65. data/example_app/public/datatable/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  66. data/example_app/public/datatable/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  67. data/example_app/public/datatable/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  68. data/example_app/public/datatable/css/smoothness/images/ui-icons_222222_256x240.png +0 -0
  69. data/example_app/public/datatable/css/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  70. data/example_app/public/datatable/css/smoothness/images/ui-icons_454545_256x240.png +0 -0
  71. data/example_app/public/datatable/css/smoothness/images/ui-icons_888888_256x240.png +0 -0
  72. data/example_app/public/datatable/css/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  73. data/example_app/public/datatable/css/smoothness/jquery-ui-1.8.14.custom.css +568 -0
  74. data/example_app/public/datatable/images/back_disabled.jpg +0 -0
  75. data/example_app/public/datatable/images/back_enabled.jpg +0 -0
  76. data/example_app/public/datatable/images/favicon.ico +0 -0
  77. data/example_app/public/datatable/images/forward_disabled.jpg +0 -0
  78. data/example_app/public/datatable/images/forward_enabled.jpg +0 -0
  79. data/example_app/public/datatable/images/sort_asc.png +0 -0
  80. data/example_app/public/datatable/images/sort_asc_disabled.png +0 -0
  81. data/example_app/public/datatable/images/sort_both.png +0 -0
  82. data/example_app/public/datatable/images/sort_desc.png +0 -0
  83. data/example_app/public/datatable/images/sort_desc_disabled.png +0 -0
  84. data/example_app/public/datatable/js/jquery-ui-1.8.14.custom.min.js +789 -0
  85. data/example_app/public/datatable/js/jquery.dataTables.js +7347 -0
  86. data/example_app/public/datatable/js/jquery.dataTables.min.js +151 -0
  87. data/example_app/public/favicon.ico +0 -0
  88. data/example_app/public/flash/copy_cvs_xls.swf +0 -0
  89. data/example_app/public/flash/copy_cvs_xls_pdf.swf +0 -0
  90. data/example_app/public/images/rails.png +0 -0
  91. data/example_app/public/javascripts/application.js +2 -0
  92. data/example_app/public/javascripts/jquery.js +8936 -0
  93. data/example_app/public/javascripts/jquery.min.js +18 -0
  94. data/example_app/public/javascripts/jquery_ujs.js +316 -0
  95. data/example_app/public/robots.txt +5 -0
  96. data/example_app/public/stylesheets/.gitkeep +0 -0
  97. data/example_app/script/rails +6 -0
  98. data/example_app/spec/datatables/active_record_dsl_spec.rb +59 -0
  99. data/example_app/spec/datatables/active_record_link_to_spec.rb +22 -0
  100. data/example_app/spec/datatables/active_record_pagination_spec.rb +94 -0
  101. data/example_app/spec/datatables/active_record_table_operations_spec.rb +180 -0
  102. data/example_app/spec/datatables/config_spec.rb +10 -0
  103. data/example_app/spec/datatables/query_params_spec.rb +73 -0
  104. data/example_app/spec/datatables/sql_default_spec.rb +22 -0
  105. data/example_app/spec/datatables/sql_pagination_spec.rb +177 -0
  106. data/example_app/spec/datatables/sql_search_cast_spec.rb +6 -0
  107. data/example_app/spec/datatables/sql_search_global_spec.rb +107 -0
  108. data/example_app/spec/datatables/sql_search_individual_spec.rb +113 -0
  109. data/example_app/spec/datatables/sql_search_where_spec.rb +87 -0
  110. data/example_app/spec/datatables/sql_sorting_spec.rb +80 -0
  111. data/example_app/spec/datatables/sql_variables_spec.rb +104 -0
  112. data/example_app/spec/factories/customer_factory.rb +4 -0
  113. data/example_app/spec/factories/item_factory.rb +2 -0
  114. data/example_app/spec/factories/order_factory.rb +7 -0
  115. data/example_app/spec/factories/order_item_factory.rb +2 -0
  116. data/example_app/spec/factories/sales_rep_factory.rb +4 -0
  117. data/example_app/spec/helpers/aocolumn_spec.rb +239 -0
  118. data/example_app/spec/helpers/data_table_helper_spec.rb +148 -0
  119. data/example_app/spec/helpers/headings_spec.rb +71 -0
  120. data/example_app/spec/spec_helper.rb +29 -0
  121. data/generators.txt +6 -0
  122. data/images/datatable_screenshot.png +0 -0
  123. data/lib/datatable/active_record_dsl.rb +49 -0
  124. data/lib/datatable/errors.rb +5 -0
  125. data/lib/datatable/helper.rb +199 -0
  126. data/lib/datatable/railtie.rb +17 -0
  127. data/lib/datatable/version.rb +4 -0
  128. data/lib/datatable.rb +341 -0
  129. data/lib/generators/datatable/install_generator.rb +58 -0
  130. data/lib/generators/datatable/new_generator.rb +46 -0
  131. data/lib/generators/templates/datatable.rb +33 -0
  132. data/lib/generators/templates/datatable_initializer.rb +6 -0
  133. data/vendor/datatable/Readme.txt +11 -0
  134. data/vendor/datatable/extras/TableTools/media/css/TableTools.css +264 -0
  135. data/vendor/datatable/extras/TableTools/media/css/TableTools_JUI.css +182 -0
  136. data/vendor/datatable/extras/TableTools/media/images/background.png +0 -0
  137. data/vendor/datatable/extras/TableTools/media/images/collection.png +0 -0
  138. data/vendor/datatable/extras/TableTools/media/images/collection_hover.png +0 -0
  139. data/vendor/datatable/extras/TableTools/media/images/copy.png +0 -0
  140. data/vendor/datatable/extras/TableTools/media/images/copy_hover.png +0 -0
  141. data/vendor/datatable/extras/TableTools/media/images/csv.png +0 -0
  142. data/vendor/datatable/extras/TableTools/media/images/csv_hover.png +0 -0
  143. data/vendor/datatable/extras/TableTools/media/images/pdf.png +0 -0
  144. data/vendor/datatable/extras/TableTools/media/images/pdf_hover.png +0 -0
  145. data/vendor/datatable/extras/TableTools/media/images/print.png +0 -0
  146. data/vendor/datatable/extras/TableTools/media/images/print_hover.png +0 -0
  147. data/vendor/datatable/extras/TableTools/media/images/xls.png +0 -0
  148. data/vendor/datatable/extras/TableTools/media/images/xls_hover.png +0 -0
  149. data/vendor/datatable/extras/TableTools/media/js/TableTools.js +2410 -0
  150. data/vendor/datatable/extras/TableTools/media/js/TableTools.min.js +78 -0
  151. data/vendor/datatable/extras/TableTools/media/js/TableTools.min.js.gz +0 -0
  152. data/vendor/datatable/extras/TableTools/media/js/ZeroClipboard.js +365 -0
  153. data/vendor/datatable/extras/TableTools/media/swf/copy_cvs_xls.swf +0 -0
  154. data/vendor/datatable/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf +0 -0
  155. data/vendor/datatable/license-bsd.txt +10 -0
  156. data/vendor/datatable/license-gpl2.txt +339 -0
  157. data/vendor/datatable/media/css/demo_page.css +99 -0
  158. data/vendor/datatable/media/css/demo_table.css +539 -0
  159. data/vendor/datatable/media/css/demo_table_jui.css +521 -0
  160. data/vendor/datatable/media/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  161. data/vendor/datatable/media/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  162. data/vendor/datatable/media/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  163. data/vendor/datatable/media/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  164. data/vendor/datatable/media/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  165. data/vendor/datatable/media/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  166. data/vendor/datatable/media/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  167. data/vendor/datatable/media/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  168. data/vendor/datatable/media/css/smoothness/images/ui-icons_222222_256x240.png +0 -0
  169. data/vendor/datatable/media/css/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  170. data/vendor/datatable/media/css/smoothness/images/ui-icons_454545_256x240.png +0 -0
  171. data/vendor/datatable/media/css/smoothness/images/ui-icons_888888_256x240.png +0 -0
  172. data/vendor/datatable/media/css/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  173. data/vendor/datatable/media/css/smoothness/jquery-ui-1.8.14.custom.css +568 -0
  174. data/vendor/datatable/media/images/back_disabled.jpg +0 -0
  175. data/vendor/datatable/media/images/back_enabled.jpg +0 -0
  176. data/vendor/datatable/media/images/favicon.ico +0 -0
  177. data/vendor/datatable/media/images/forward_disabled.jpg +0 -0
  178. data/vendor/datatable/media/images/forward_enabled.jpg +0 -0
  179. data/vendor/datatable/media/images/sort_asc.png +0 -0
  180. data/vendor/datatable/media/images/sort_asc_disabled.png +0 -0
  181. data/vendor/datatable/media/images/sort_both.png +0 -0
  182. data/vendor/datatable/media/images/sort_desc.png +0 -0
  183. data/vendor/datatable/media/images/sort_desc_disabled.png +0 -0
  184. data/vendor/datatable/media/js/jquery-ui-1.8.14.custom.min.js +789 -0
  185. data/vendor/datatable/media/js/jquery.dataTables.js +7347 -0
  186. data/vendor/datatable/media/js/jquery.dataTables.min.js +151 -0
  187. metadata +270 -0
data/.bundle/config ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_PATH: vendor
3
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .idea
2
+ docs
3
+ *.gem
4
+ vendor/ruby
5
+ example_app/config/database.yml
6
+ */**/.DS_Store
7
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -c -f d
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ # all the runtime dependencies are listed in the gemspec
4
+ gemspec
5
+
6
+ # all the develpment dependencies are listed here
7
+ gem 'rake'
8
+ gem 'rdoc'
9
+ gem 'gemcutter'
data/Gemfile.lock ADDED
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ datatable (0.1.0alpha2)
5
+ rails (>= 3.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.9)
12
+ actionpack (= 3.0.9)
13
+ mail (~> 2.2.19)
14
+ actionpack (3.0.9)
15
+ activemodel (= 3.0.9)
16
+ activesupport (= 3.0.9)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.5.0)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.14)
22
+ rack-test (~> 0.5.7)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.9)
25
+ activesupport (= 3.0.9)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.5.0)
28
+ activerecord (3.0.9)
29
+ activemodel (= 3.0.9)
30
+ activesupport (= 3.0.9)
31
+ arel (~> 2.0.10)
32
+ tzinfo (~> 0.3.23)
33
+ activeresource (3.0.9)
34
+ activemodel (= 3.0.9)
35
+ activesupport (= 3.0.9)
36
+ activesupport (3.0.9)
37
+ arel (2.0.10)
38
+ builder (2.1.2)
39
+ erubis (2.6.6)
40
+ abstract (>= 1.0.0)
41
+ gemcutter (0.7.0)
42
+ i18n (0.5.0)
43
+ mail (2.2.19)
44
+ activesupport (>= 2.3.6)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.16)
49
+ polyglot (0.3.1)
50
+ rack (1.2.3)
51
+ rack-mount (0.6.14)
52
+ rack (>= 1.0.0)
53
+ rack-test (0.5.7)
54
+ rack (>= 1.0)
55
+ rails (3.0.9)
56
+ actionmailer (= 3.0.9)
57
+ actionpack (= 3.0.9)
58
+ activerecord (= 3.0.9)
59
+ activeresource (= 3.0.9)
60
+ activesupport (= 3.0.9)
61
+ bundler (~> 1.0)
62
+ railties (= 3.0.9)
63
+ railties (3.0.9)
64
+ actionpack (= 3.0.9)
65
+ activesupport (= 3.0.9)
66
+ rake (>= 0.8.7)
67
+ rdoc (~> 3.4)
68
+ thor (~> 0.14.4)
69
+ rake (0.9.2)
70
+ rdoc (3.8)
71
+ thor (0.14.6)
72
+ treetop (1.4.9)
73
+ polyglot (>= 0.3.1)
74
+ tzinfo (0.3.29)
75
+
76
+ PLATFORMS
77
+ ruby
78
+
79
+ DEPENDENCIES
80
+ datatable!
81
+ gemcutter
82
+ rake
83
+ rdoc
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Michael A. Greenly
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,135 @@
1
+ Datatable
2
+ =========
3
+
4
+ This is a [Rails 3.0](http://rubyonrails.org) plugin that provides server-side processing for the [Datatables](http://datatables.net) javascript library. The screenshot below
5
+ contains an example with global search, per column search, infinite scrolling and the optional table tools plugin installed using the jquery ui them 'smoothness'.
6
+
7
+
8
+ ![Alt text](https://github.com/logic-refinery/datatable/raw/master/images/datatable_screenshot.png "optional title")
9
+
10
+
11
+ WARNING!!!
12
+ ==========
13
+
14
+ This gem is not ready for primetime but if you're feeling adventurous read on....
15
+
16
+
17
+ Introduction
18
+ ============
19
+
20
+ It's likely the code base will experience significant churn in the next few releases as we search for the best way deliver the desired
21
+ functionality. If you think this may be a problem you should most likely avoid using it for now. On the other hand if you're not afraid
22
+ of diving into the code to help us improve it we will certiainly do what we can to make sure it works
23
+ for you in return.
24
+
25
+ Setup
26
+ ======
27
+
28
+ Because of the fast moving nature of this project for the time being I recomend using bundler and pulling from git. If you
29
+ intend to deploy an application using this gem I'd recomend locking your dependency to a specific well tested commit.
30
+
31
+ Add the following to you Gemfile
32
+
33
+ ```ruby
34
+ gem "datatable", :git => "git://github.com/logic-refinery/datatable.git" :ref => "500a5f"
35
+ ```
36
+
37
+ Then run bundle install
38
+
39
+ ```sh
40
+ bundle
41
+ ```
42
+
43
+ Then run the generator to create the javascript files and code templates
44
+
45
+ ```sh
46
+ rails generate datatable:install
47
+ ```
48
+
49
+ The generator will have added some javascript files to your public/javascript folder that need to be added after jquery using a helper.
50
+
51
+ ```erb
52
+ <%= javascript_include_tag :defaults %>
53
+ <%= datatable_javascript %>
54
+ ```
55
+
56
+ If you want to use the jquery ui be sure to include those style sheets.
57
+
58
+ ```erb
59
+ <%= stylesheet_link_tag :all %>
60
+ <%= stylesheet_link_tag 'smoothness/jquery-ui-1.8.14.custom' %>
61
+ ```
62
+
63
+ The generator created a template in app/config/initializers/datatable.rb that you can modify as needed.
64
+
65
+ ```ruby
66
+ Datatable::Base.config do |config|
67
+ config.style = true
68
+ config.sql_like = 'ILIKE'
69
+ config.table_tools = true
70
+ end
71
+ ```
72
+
73
+ Usage
74
+ =====
75
+
76
+ Imagine that you have an 'Order' that belongs to a 'Customer' and has many 'Item'
77
+
78
+ In app/controllers/orders_controller.rb you would add something like this:
79
+
80
+ ```ruby
81
+ def index
82
+ @datatable = OrdersIndex
83
+ respond_to do |format|
84
+ format.html
85
+ format.js { render :json => @datatable.query(params).to_json }
86
+ end
87
+ end
88
+ ```
89
+
90
+ In app/views/orders/index.html.erb you would add something like this:
91
+
92
+ ```erb
93
+ <%= datatable %>
94
+ ```
95
+
96
+ In app/datatables/orders_index.rb you would need to define the datatable. In the future this hopefully will be a DSL that's easier to use.
97
+ Right now it mostly just exposes the internal datastructures so the necessary information can be defined. See the [wiki](https://github.com/logic-refinery/datatable/wiki)
98
+ for more detailed information.
99
+
100
+ ```ruby
101
+ class OrdersIndex < Datatable::Base
102
+ sql <<-SQL
103
+ SELECT
104
+ orders.id,
105
+ orders.order_number,
106
+ customers.first_name,
107
+ customers.last_name,
108
+ orders.memo
109
+ FROM
110
+ orders
111
+ JOIN
112
+ customers ON customers.id = orders.customer_id
113
+ SQL
114
+
115
+ columns(
116
+ {"orders.id" => {:type => :integer, :heading => "Id", :sWidth => '50px'}},
117
+ {"orders.order_number" => {:type => :integer, :link_to => link_to('{{1}}', order_path('{{0}}')),:heading => 'Order Number', :sWidth => '125px' }},
118
+ {"customers.first_name" => {:type => :string, :link_to => link_to('{{2}}', order_path('{{0}}')),:sWidth => '200px' }},
119
+ {"customers.last_name" => {:type => :string,:sWidth => '200px'}},
120
+ {"orders.memo" => {:type => :string }})
121
+
122
+ option('bJQueryUI', true)
123
+ option('individual_column_searching', true)
124
+ option('sDom', '<"clear"><"H"Trf>t<"F"i>')
125
+ option('bScrollInfinite', true)
126
+ option('bScrollCollapse', true)
127
+ option('sScrollY', '200px')
128
+ end
129
+ ```
130
+
131
+
132
+ Limitations
133
+ ==========
134
+
135
+ * It only supports MySQL and PostgreSLQ through ActiveRecord.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require 'rake/clean'
2
+ require 'rdoc/task'
3
+
4
+ CLOBBER.include('*.gem')
5
+
6
+ task :default do
7
+ puts 'Run "rake spec" in the "example_app" directory to perform tests.'
8
+ end
9
+
10
+ desc 'Generate documentation for the datatable plugin.'
11
+ Rake::RDocTask.new(:rdoc => 'rdoc', :clobber_rdoc => "rdoc:clobber", :rerdoc => 'rdoc:force') do |rdoc|
12
+ rdoc.rdoc_dir = 'docs'
13
+ rdoc.title = 'Datatable'
14
+ rdoc.options << "--all"
15
+ rdoc.rdoc_files.include('README.md')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
19
+ desc "build gem"
20
+ task :build do
21
+ system "gem build datatable.gemspec"
22
+ end
23
+
24
+ desc "publish gem"
25
+ task :release => :build do
26
+ system "gem push datatable-#{Datatable::VERSION}.gem"
27
+ end
data/TODO ADDED
@@ -0,0 +1,71 @@
1
+ Update the config initializer
2
+
3
+ BUG: search column count doesn't include unsearchable columns and this
4
+ isn't taken into account.
5
+
6
+ SECURITY: don't rely on iColumns being meaningful or correct us our internal
7
+ definition of the table to determine the number of columns. using
8
+ the parameter allows the caller to make our code operate out of
9
+ bounds
10
+
11
+ PERFORMANCE: if the search string is empty leave that search out of the SQL
12
+ don't search for '%%'
13
+
14
+ #) replace haeding w/ sTitle
15
+
16
+
17
+
18
+
19
+ --------
20
+
21
+ #) Provide example of fnRender in the tests for example: It needs to be possible to turn
22
+ a boolean field into 'done' or 'not done'.
23
+
24
+ #) write a script that puts the most recent files into the gem root. it should not include the files that we don't want (e.g. demo_page.css)
25
+
26
+ #) Need to be able to define default sort ordefault sort orders
27
+
28
+ #) provide a reset link in so that all the search inputs are cleared
29
+ would be nice if it was easily hooked to a keystroke for example
30
+ ESC when any of the inputs have the focus
31
+
32
+ #) allow multiple space separated search values in global search the OR the result
33
+ together for each value and each column. So for example having "alice bob" in the search input
34
+ would generate a where clause like this...
35
+
36
+ WHERE (first_name LIKE 'alice' OR first_name LIKE 'bob') OR (other_column LIKE 'alice' OR other_column LIKE 'bob') OR ...
37
+
38
+
39
+ #) release 0.1 (support for rails 3.0)
40
+
41
+ THE FUTURE
42
+ Advanced search
43
+ Date search
44
+ TYPECASTING
45
+ #) make it so both global search and individual column searches
46
+ support typcasting so that those columns can be searched as
47
+ strings, example:
48
+
49
+ SELECT order_number FROM orders WHERE CAST(order_number as text) LIKE '%123%';
50
+
51
+ column({'orders.order_number' => {:type => :string, :cast => :text }})
52
+
53
+ having :cast present would force it to build any where clauses using a type cast
54
+ Move all tests into root directory so there can be multiple versions of the example application
55
+ Rails 3.1
56
+ printing
57
+ download as csv/excel
58
+ search date ranges
59
+ support internationalization (http://www.datatables.net/usage/i18n)
60
+ support callbacks (http://www.datatables.net/usage/callbacks)
61
+ support all datatable options (http://www.datatables.net/usage/options)
62
+ make config more robust (https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/uploader/configuration.rb)
63
+ reordering columns
64
+ lightbox editing
65
+ maybe parse the sql?
66
+ maybe build the sql from the column definitions?
67
+ focus on active relation version
68
+
69
+
70
+
71
+ http://docs.codehaus.org/display/JPARSEC/SQL+parser+in+rparsec
data/datatable.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "datatable/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "datatable"
7
+ s.version = Datatable::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Michael Greenly", 'Mischa Fierer']
10
+ s.email = ["michaelgreenly@logic-refinery.com"]
11
+ s.homepage = "https://github.com/logic-refinery/datatable"
12
+ s.summary = %q{A Rails plugin for the jquery.datatables library}
13
+ s.description = %q{A Rails plugin for the jquery.datatables library}
14
+ s.add_dependency('rails', '>= 3.0')
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
Binary file
@@ -0,0 +1,6 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/
5
+ vendor/ruby
6
+ .DS_Store
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,35 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '3.0.7'
4
+ gem 'pg'
5
+ gem 'mysql'
6
+ gem 'datatable', :path => "../"
7
+ gem "jquery-rails"
8
+
9
+
10
+ #
11
+ # ruby-debug can't be installed using bundler on Linx under rvm with Ruby 1.9 because it
12
+ # tries to download header files to folders not owned by the current user. The easiest
13
+ # way to work around this is to put ruby-debug in an optional group and that can be
14
+ # excluded when bundle install is run.
15
+ #
16
+ # bundle install --exclude=debug
17
+ #
18
+ # If you want you can install ruby-debug manually in this situation
19
+ #
20
+ # gem install ruby-debug19 -- --with-ruby-include=$rvm_path/src/$RUBY_VERSION/
21
+ #
22
+ group :test, :development do
23
+ gem 'require_relative'
24
+ gem 'ruby-debug', :platform => :ruby_18
25
+ gem 'rake', '0.8.7'
26
+ gem "i18n"
27
+ gem "webrat"
28
+ gem "activesupport"
29
+ gem "rspec"
30
+ gem "rspec-rails"
31
+ gem "factory_girl_rails"
32
+ gem "webrat"
33
+ end
34
+
35
+
@@ -0,0 +1,126 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ datatable (0.1.0alpha2)
5
+ rails (>= 3.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.7)
12
+ actionpack (= 3.0.7)
13
+ mail (~> 2.2.15)
14
+ actionpack (3.0.7)
15
+ activemodel (= 3.0.7)
16
+ activesupport (= 3.0.7)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.5.0)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.14)
22
+ rack-test (~> 0.5.7)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.7)
25
+ activesupport (= 3.0.7)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.5.0)
28
+ activerecord (3.0.7)
29
+ activemodel (= 3.0.7)
30
+ activesupport (= 3.0.7)
31
+ arel (~> 2.0.2)
32
+ tzinfo (~> 0.3.23)
33
+ activeresource (3.0.7)
34
+ activemodel (= 3.0.7)
35
+ activesupport (= 3.0.7)
36
+ activesupport (3.0.7)
37
+ arel (2.0.10)
38
+ builder (2.1.2)
39
+ columnize (0.3.3)
40
+ diff-lcs (1.1.2)
41
+ erubis (2.6.6)
42
+ abstract (>= 1.0.0)
43
+ factory_girl (1.3.3)
44
+ factory_girl_rails (1.0.1)
45
+ factory_girl (~> 1.3)
46
+ railties (>= 3.0.0)
47
+ i18n (0.5.0)
48
+ jquery-rails (1.0.11)
49
+ railties (~> 3.0)
50
+ thor (~> 0.14)
51
+ linecache (0.45)
52
+ mail (2.2.19)
53
+ activesupport (>= 2.3.6)
54
+ i18n (>= 0.4.0)
55
+ mime-types (~> 1.16)
56
+ treetop (~> 1.4.8)
57
+ mime-types (1.16)
58
+ mysql (2.8.1)
59
+ nokogiri (1.4.5)
60
+ pg (0.11.0)
61
+ polyglot (0.3.1)
62
+ rack (1.2.3)
63
+ rack-mount (0.6.14)
64
+ rack (>= 1.0.0)
65
+ rack-test (0.5.7)
66
+ rack (>= 1.0)
67
+ rails (3.0.7)
68
+ actionmailer (= 3.0.7)
69
+ actionpack (= 3.0.7)
70
+ activerecord (= 3.0.7)
71
+ activeresource (= 3.0.7)
72
+ activesupport (= 3.0.7)
73
+ bundler (~> 1.0)
74
+ railties (= 3.0.7)
75
+ railties (3.0.7)
76
+ actionpack (= 3.0.7)
77
+ activesupport (= 3.0.7)
78
+ rake (>= 0.8.7)
79
+ thor (~> 0.14.4)
80
+ rake (0.8.7)
81
+ require_relative (1.0.2)
82
+ rspec (2.6.0)
83
+ rspec-core (~> 2.6.0)
84
+ rspec-expectations (~> 2.6.0)
85
+ rspec-mocks (~> 2.6.0)
86
+ rspec-core (2.6.4)
87
+ rspec-expectations (2.6.0)
88
+ diff-lcs (~> 1.1.2)
89
+ rspec-mocks (2.6.0)
90
+ rspec-rails (2.6.1)
91
+ actionpack (~> 3.0)
92
+ activesupport (~> 3.0)
93
+ railties (~> 3.0)
94
+ rspec (~> 2.6.0)
95
+ ruby-debug (0.10.4)
96
+ columnize (>= 0.1)
97
+ ruby-debug-base (~> 0.10.4.0)
98
+ ruby-debug-base (0.10.4)
99
+ linecache (>= 0.3)
100
+ thor (0.14.6)
101
+ treetop (1.4.9)
102
+ polyglot (>= 0.3.1)
103
+ tzinfo (0.3.28)
104
+ webrat (0.7.3)
105
+ nokogiri (>= 1.2.0)
106
+ rack (>= 1.0)
107
+ rack-test (>= 0.5.3)
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ activesupport
114
+ datatable!
115
+ factory_girl_rails
116
+ i18n
117
+ jquery-rails
118
+ mysql
119
+ pg
120
+ rails (= 3.0.7)
121
+ rake (= 0.8.7)
122
+ require_relative
123
+ rspec
124
+ rspec-rails
125
+ ruby-debug
126
+ webrat
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ RailsApp::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,13 @@
1
+ class OrdersController < ApplicationController
2
+
3
+ def index
4
+ @datatable = OrdersIndex
5
+ respond_to do |format|
6
+ format.html
7
+ format.js { render :json => @datatable.query(params).to_json }
8
+ end
9
+ end
10
+
11
+ end
12
+
13
+
@@ -0,0 +1,31 @@
1
+ class OrdersIndex < Datatable::Base
2
+
3
+ sql <<-SQL
4
+ SELECT
5
+ orders.id,
6
+ orders.order_number,
7
+ customers.first_name,
8
+ customers.last_name,
9
+ orders.memo
10
+ FROM
11
+ orders
12
+ JOIN
13
+ customers ON customers.id = orders.customer_id
14
+ SQL
15
+
16
+ columns(
17
+ {"orders.id" => {:type => :integer, :sTitle => "Id", :sWidth => '50px'}},
18
+ {"orders.order_number" => {:type => :integer, :link_to => link_to('{{1}}', order_path('{{0}}')),:sTitle => 'Order Number', :sWidth => '125px' }},
19
+ {"customers.first_name" => {:type => :string, :link_to => link_to('{{2}}', order_path('{{0}}')),:sWidth => '200px' }},
20
+ {"customers.last_name" => {:type => :string,:sWidth => '200px'}},
21
+ {"orders.memo" => {:type => :string }}
22
+ )
23
+ option('individual_column_searching', true)
24
+ #option('sDom', '<"H"lrf>t<"F"ip>') # use with pagination
25
+
26
+ # to use pagination comment out following and enable previous line
27
+ option('sDom', '<"clear"><"H"Trf>t<"F"i>')
28
+ option('bScrollInfinite', true)
29
+ option('bScrollCollapse', true)
30
+ option('sScrollY', '200px')
31
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class Customer < ActiveRecord::Base
2
+ belongs_to :sales_rep
3
+ has_many :orders
4
+ end
@@ -0,0 +1,4 @@
1
+ class Item < ActiveRecord::Base
2
+ has_many :order_items
3
+ has_many :orders, :through => :order_items
4
+ end
@@ -0,0 +1,5 @@
1
+ class Order < ActiveRecord::Base
2
+ has_many :order_items
3
+ has_many :items, :through => :order_items
4
+ belongs_to :customer
5
+ end
@@ -0,0 +1,4 @@
1
+ class OrderItem < ActiveRecord::Base
2
+ belongs_to :item
3
+ belongs_to :order
4
+ end
@@ -0,0 +1,3 @@
1
+ class SalesRep < ActiveRecord::Base
2
+ has_many :customers
3
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Datatable App</title>
5
+ <%= csrf_meta_tag %>
6
+ <%= stylesheet_link_tag :all %>
7
+ <%= javascript_include_tag :defaults %>
8
+ </head>
9
+ <body>
10
+ <%= yield %>
11
+ </body>
12
+ </html>