pwice_grid 5.0.0

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 (389) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +68 -0
  3. data/.circleci/run-build-locally.sh +7 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +32 -0
  5. data/.gitignore +22 -0
  6. data/.inch.yml +3 -0
  7. data/.rspec +3 -0
  8. data/.rubocop.yml +186 -0
  9. data/Appraisals +11 -0
  10. data/CHANGELOG.md +758 -0
  11. data/Gemfile +3 -0
  12. data/Gemfile.lock +298 -0
  13. data/MIT-LICENSE +20 -0
  14. data/README.md +1561 -0
  15. data/Rakefile +49 -0
  16. data/SAVED_QUERIES_HOWTO.md +113 -0
  17. data/app/views/kaminari/wice_grid/_gap.html.erb +1 -0
  18. data/app/views/kaminari/wice_grid/_next_page.html.erb +1 -0
  19. data/app/views/kaminari/wice_grid/_page.html.erb +1 -0
  20. data/app/views/kaminari/wice_grid/_paginator.html.erb +19 -0
  21. data/app/views/kaminari/wice_grid/_prev_page.html.erb +1 -0
  22. data/config/locales/cz.yml +40 -0
  23. data/config/locales/de.yml +42 -0
  24. data/config/locales/en.yml +42 -0
  25. data/config/locales/es.yml +42 -0
  26. data/config/locales/fr.yml +40 -0
  27. data/config/locales/is.yml +41 -0
  28. data/config/locales/it.yml +33 -0
  29. data/config/locales/ja.yml +42 -0
  30. data/config/locales/nl.yml +40 -0
  31. data/config/locales/pt-BR.yml +31 -0
  32. data/config/locales/pt.yml +40 -0
  33. data/config/locales/ru.yml +40 -0
  34. data/config/locales/sk.yml +40 -0
  35. data/config/locales/uk.yml +40 -0
  36. data/config/locales/zh.yml +40 -0
  37. data/gemfiles/rails_5.0.gemfile +7 -0
  38. data/gemfiles/rails_5.0.gemfile.lock +299 -0
  39. data/gemfiles/rails_5.1.gemfile +7 -0
  40. data/gemfiles/rails_5.1.gemfile.lock +299 -0
  41. data/gemfiles/rails_5.2.gemfile +7 -0
  42. data/gemfiles/rails_5.2.gemfile.lock +307 -0
  43. data/lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb +19 -0
  44. data/lib/generators/wice_grid/install_generator.rb +13 -0
  45. data/lib/generators/wice_grid/templates/create_wice_grid_serialized_queries.rb +13 -0
  46. data/lib/generators/wice_grid/templates/wice_grid_config.rb +191 -0
  47. data/lib/wice/active_record_column_wrapper.rb +122 -0
  48. data/lib/wice/columns.rb +282 -0
  49. data/lib/wice/columns/column_action.rb +51 -0
  50. data/lib/wice/columns/column_boolean.rb +39 -0
  51. data/lib/wice/columns/column_bootstrap_datepicker.rb +47 -0
  52. data/lib/wice/columns/column_custom_dropdown.rb +114 -0
  53. data/lib/wice/columns/column_float.rb +8 -0
  54. data/lib/wice/columns/column_html5_datepicker.rb +30 -0
  55. data/lib/wice/columns/column_integer.rb +87 -0
  56. data/lib/wice/columns/column_jquery_datepicker.rb +48 -0
  57. data/lib/wice/columns/column_processor_index.rb +22 -0
  58. data/lib/wice/columns/column_rails_date_helper.rb +40 -0
  59. data/lib/wice/columns/column_rails_datetime_helper.rb +40 -0
  60. data/lib/wice/columns/column_range.rb +73 -0
  61. data/lib/wice/columns/column_string.rb +91 -0
  62. data/lib/wice/columns/common_date_datetime_mixin.rb +19 -0
  63. data/lib/wice/columns/common_js_date_datetime_conditions_generator_mixin.rb +38 -0
  64. data/lib/wice/columns/common_js_date_datetime_mixin.rb +14 -0
  65. data/lib/wice/columns/common_rails_date_datetime_conditions_generator_mixin.rb +25 -0
  66. data/lib/wice/columns/common_standard_helper_date_datetime_mixin.rb +21 -0
  67. data/lib/wice/grid_output_buffer.rb +48 -0
  68. data/lib/wice/grid_renderer.rb +624 -0
  69. data/lib/wice/helpers/bs_calendar_helpers.rb +73 -0
  70. data/lib/wice/helpers/js_calendar_helpers.rb +82 -0
  71. data/lib/wice/helpers/wice_grid_misc_view_helpers.rb +74 -0
  72. data/lib/wice/helpers/wice_grid_serialized_queries_view_helpers.rb +94 -0
  73. data/lib/wice/helpers/wice_grid_view_helpers.rb +719 -0
  74. data/lib/wice/kaminari_monkey_patching.rb +12 -0
  75. data/lib/wice/table_column_matrix.rb +64 -0
  76. data/lib/wice/wice_grid_controller.rb +174 -0
  77. data/lib/wice/wice_grid_core_ext.rb +145 -0
  78. data/lib/wice/wice_grid_misc.rb +208 -0
  79. data/lib/wice/wice_grid_serialized_queries_controller.rb +86 -0
  80. data/lib/wice/wice_grid_serialized_query.rb +13 -0
  81. data/lib/wice/wice_grid_spreadsheet.rb +19 -0
  82. data/lib/wice_grid.rb +702 -0
  83. data/spec/acceptance_helper.rb +59 -0
  84. data/spec/features/action_column_request_spec.rb +280 -0
  85. data/spec/features/adding_rows_request_spec.rb +21 -0
  86. data/spec/features/all_records_request_spec.rb +18 -0
  87. data/spec/features/auto_reloads2_request_spec.rb +366 -0
  88. data/spec/features/auto_reloads3_request_spec.rb +130 -0
  89. data/spec/features/auto_reloads_request_spec.rb +364 -0
  90. data/spec/features/basics1_request_spec.rb +11 -0
  91. data/spec/features/basics2_request_spec.rb +10 -0
  92. data/spec/features/basics3_request_spec.rb +29 -0
  93. data/spec/features/basics4_request_spec.rb +19 -0
  94. data/spec/features/basics5_request_spec.rb +13 -0
  95. data/spec/features/basics6_request_spec.rb +22 -0
  96. data/spec/features/blockless_column_definition_spec.rb +27 -0
  97. data/spec/features/buttons_request_spec.rb +172 -0
  98. data/spec/features/csv_and_detached_filters_spec.rb +10 -0
  99. data/spec/features/csv_export_request_spec.rb +13 -0
  100. data/spec/features/custom_filter_params_request_spec.rb +29 -0
  101. data/spec/features/custom_filters1_request_spec.rb +136 -0
  102. data/spec/features/custom_filters2_request_spec.rb +31 -0
  103. data/spec/features/custom_filters3_request_spec.rb +34 -0
  104. data/spec/features/custom_filters4_request_spec.rb +13 -0
  105. data/spec/features/custom_ordering_on_calculated_request_spec.rb +30 -0
  106. data/spec/features/custom_ordering_request_spec.rb +36 -0
  107. data/spec/features/custom_ordering_with_arel_request_spec.rb +36 -0
  108. data/spec/features/custom_ordering_with_proc_request_spec.rb +44 -0
  109. data/spec/features/custom_ordering_with_ruby_request_spec.rb +30 -0
  110. data/spec/features/dates_request_spec.rb +56 -0
  111. data/spec/features/detached_filters_spec.rb +10 -0
  112. data/spec/features/detached_filters_two_grids_spec.rb +135 -0
  113. data/spec/features/disable_all_filters_spec.rb +22 -0
  114. data/spec/features/hiding_checkboxes_in_action_column_request_spec.rb +294 -0
  115. data/spec/features/integration_with_application_view_request_spec.rb +43 -0
  116. data/spec/features/integration_with_forms_request_spec.rb +141 -0
  117. data/spec/features/joining_tables_spec.rb +40 -0
  118. data/spec/features/localization_request_spec.rb +24 -0
  119. data/spec/features/many_grids_on_page_request_spec.rb +104 -0
  120. data/spec/features/negation_request_spec.rb +25 -0
  121. data/spec/features/no_records_request_spec.rb +26 -0
  122. data/spec/features/numeric_filters_request_spec.rb +10 -0
  123. data/spec/features/resultset_processings2_request_spec.rb +27 -0
  124. data/spec/features/resultset_processings_request_spec.rb +30 -0
  125. data/spec/features/saved_queries_request_spec.rb +120 -0
  126. data/spec/features/shared.rb +1005 -0
  127. data/spec/features/shared_detached_filters.rb +175 -0
  128. data/spec/features/styling_spec.rb +15 -0
  129. data/spec/features/two_associations_spec.rb +48 -0
  130. data/spec/features/upper_pagination_panel_request_spec.rb +23 -0
  131. data/spec/features/when_filtered_spec.rb +209 -0
  132. data/spec/fixtures/.gitkeep +0 -0
  133. data/spec/fixtures/companies.yml +21 -0
  134. data/spec/fixtures/priorities.yml +31 -0
  135. data/spec/fixtures/project_roles.yml +25 -0
  136. data/spec/fixtures/projects.yml +22 -0
  137. data/spec/fixtures/statuses.yml +55 -0
  138. data/spec/fixtures/tasks.yml +751 -0
  139. data/spec/fixtures/tasks_users.yml +2089 -0
  140. data/spec/fixtures/users.yml +61 -0
  141. data/spec/fixtures/versions.yml +78 -0
  142. data/spec/models/company_spec.rb +6 -0
  143. data/spec/models/priority_spec.rb +6 -0
  144. data/spec/models/project_spec.rb +11 -0
  145. data/spec/models/status_spec.rb +6 -0
  146. data/spec/models/task_spec.rb +12 -0
  147. data/spec/models/user_project_participation_spec.rb +7 -0
  148. data/spec/models/user_spec.rb +12 -0
  149. data/spec/models/version_spec.rb +5 -0
  150. data/spec/rails_helper.rb +15 -0
  151. data/spec/schema.rb +8 -0
  152. data/spec/spec_helper.rb +75 -0
  153. data/spec/support/active_record.rb +10 -0
  154. data/spec/support/test_app/Rakefile +3 -0
  155. data/spec/support/test_app/app/assets/javascripts/application.js +20 -0
  156. data/spec/support/test_app/app/assets/javascripts/common.js.coffee +6 -0
  157. data/spec/support/test_app/app/assets/javascripts/jquery.ui.datepicker.locales.js +56 -0
  158. data/spec/support/test_app/app/assets/stylesheets/adding_rows.scss +3 -0
  159. data/spec/support/test_app/app/assets/stylesheets/application.scss +46 -0
  160. data/spec/support/test_app/app/assets/stylesheets/csv_and_detached_filters.scss +3 -0
  161. data/spec/support/test_app/app/assets/stylesheets/many_grids_on_page.scss +3 -0
  162. data/spec/support/test_app/app/controllers/action_column_controller.rb +15 -0
  163. data/spec/support/test_app/app/controllers/adding_rows_controller.rb +14 -0
  164. data/spec/support/test_app/app/controllers/all_records_controller.rb +14 -0
  165. data/spec/support/test_app/app/controllers/application_controller.rb +99 -0
  166. data/spec/support/test_app/app/controllers/auto_reloads2_controller.rb +14 -0
  167. data/spec/support/test_app/app/controllers/auto_reloads3_controller.rb +20 -0
  168. data/spec/support/test_app/app/controllers/auto_reloads_controller.rb +14 -0
  169. data/spec/support/test_app/app/controllers/basics1_controller.rb +6 -0
  170. data/spec/support/test_app/app/controllers/basics2_controller.rb +6 -0
  171. data/spec/support/test_app/app/controllers/basics3_controller.rb +6 -0
  172. data/spec/support/test_app/app/controllers/basics4_controller.rb +6 -0
  173. data/spec/support/test_app/app/controllers/basics5_controller.rb +6 -0
  174. data/spec/support/test_app/app/controllers/basics6_controller.rb +11 -0
  175. data/spec/support/test_app/app/controllers/blockless_column_definition_controller.rb +6 -0
  176. data/spec/support/test_app/app/controllers/buttons_controller.rb +6 -0
  177. data/spec/support/test_app/app/controllers/csv_and_detached_filters_controller.rb +13 -0
  178. data/spec/support/test_app/app/controllers/csv_export_controller.rb +28 -0
  179. data/spec/support/test_app/app/controllers/custom_filter_params_controller.rb +6 -0
  180. data/spec/support/test_app/app/controllers/custom_filters1_controller.rb +9 -0
  181. data/spec/support/test_app/app/controllers/custom_filters2_controller.rb +14 -0
  182. data/spec/support/test_app/app/controllers/custom_filters3_controller.rb +12 -0
  183. data/spec/support/test_app/app/controllers/custom_filters4_controller.rb +12 -0
  184. data/spec/support/test_app/app/controllers/custom_ordering_controller.rb +18 -0
  185. data/spec/support/test_app/app/controllers/custom_ordering_on_calculated_controller.rb +6 -0
  186. data/spec/support/test_app/app/controllers/custom_ordering_with_arel_controller.rb +18 -0
  187. data/spec/support/test_app/app/controllers/custom_ordering_with_proc_controller.rb +11 -0
  188. data/spec/support/test_app/app/controllers/custom_ordering_with_ruby_controller.rb +6 -0
  189. data/spec/support/test_app/app/controllers/dates_controller.rb +8 -0
  190. data/spec/support/test_app/app/controllers/detached_filters_controller.rb +6 -0
  191. data/spec/support/test_app/app/controllers/detached_filters_two_grids_controller.rb +7 -0
  192. data/spec/support/test_app/app/controllers/disable_all_filters_controller.rb +6 -0
  193. data/spec/support/test_app/app/controllers/hiding_checkboxes_in_action_column_controller.rb +13 -0
  194. data/spec/support/test_app/app/controllers/home_controller.rb +3 -0
  195. data/spec/support/test_app/app/controllers/integration_with_application_view_controller.rb +16 -0
  196. data/spec/support/test_app/app/controllers/integration_with_forms_controller.rb +11 -0
  197. data/spec/support/test_app/app/controllers/joining_tables_controller.rb +11 -0
  198. data/spec/support/test_app/app/controllers/localization_controller.rb +26 -0
  199. data/spec/support/test_app/app/controllers/many_grids_on_page_controller.rb +7 -0
  200. data/spec/support/test_app/app/controllers/negation_controller.rb +14 -0
  201. data/spec/support/test_app/app/controllers/no_records_controller.rb +8 -0
  202. data/spec/support/test_app/app/controllers/null_values_controller.rb +10 -0
  203. data/spec/support/test_app/app/controllers/numeric_filters_controller.rb +6 -0
  204. data/spec/support/test_app/app/controllers/queries_controller.rb +4 -0
  205. data/spec/support/test_app/app/controllers/resultset_processings2_controller.rb +29 -0
  206. data/spec/support/test_app/app/controllers/resultset_processings_controller.rb +30 -0
  207. data/spec/support/test_app/app/controllers/saved_queries_controller.rb +14 -0
  208. data/spec/support/test_app/app/controllers/styling_controller.rb +7 -0
  209. data/spec/support/test_app/app/controllers/tasks_controller.rb +14 -0
  210. data/spec/support/test_app/app/controllers/two_associations_controller.rb +6 -0
  211. data/spec/support/test_app/app/controllers/upper_pagination_panel_controller.rb +6 -0
  212. data/spec/support/test_app/app/controllers/when_filtered_controller.rb +6 -0
  213. data/spec/support/test_app/app/helpers/application_helper.rb +82 -0
  214. data/spec/support/test_app/app/mailers/.gitkeep +0 -0
  215. data/spec/support/test_app/app/models/.gitkeep +0 -0
  216. data/spec/support/test_app/app/models/company.rb +5 -0
  217. data/spec/support/test_app/app/models/populate.rb +84 -0
  218. data/spec/support/test_app/app/models/priority.rb +10 -0
  219. data/spec/support/test_app/app/models/project.rb +14 -0
  220. data/spec/support/test_app/app/models/project_role.rb +3 -0
  221. data/spec/support/test_app/app/models/status.rb +10 -0
  222. data/spec/support/test_app/app/models/task.rb +11 -0
  223. data/spec/support/test_app/app/models/to_dropdown_mixin.rb +16 -0
  224. data/spec/support/test_app/app/models/user.rb +8 -0
  225. data/spec/support/test_app/app/models/user_project_participation.rb +6 -0
  226. data/spec/support/test_app/app/models/version.rb +6 -0
  227. data/spec/support/test_app/app/views/action_column/_grid.html.erb +35 -0
  228. data/spec/support/test_app/app/views/action_column/index.html.haml +45 -0
  229. data/spec/support/test_app/app/views/adding_rows/_grid.html.erb +58 -0
  230. data/spec/support/test_app/app/views/adding_rows/index.html.haml +37 -0
  231. data/spec/support/test_app/app/views/all_records/_grid.html.erb +30 -0
  232. data/spec/support/test_app/app/views/all_records/index.html.haml +12 -0
  233. data/spec/support/test_app/app/views/auto_reloads/_grid.html.erb +32 -0
  234. data/spec/support/test_app/app/views/auto_reloads/index.html.haml +15 -0
  235. data/spec/support/test_app/app/views/auto_reloads2/_grid.html.erb +32 -0
  236. data/spec/support/test_app/app/views/auto_reloads2/index.html.haml +65 -0
  237. data/spec/support/test_app/app/views/auto_reloads3/_grid.html.erb +25 -0
  238. data/spec/support/test_app/app/views/auto_reloads3/index.html.haml +78 -0
  239. data/spec/support/test_app/app/views/basics1/_grid.html.erb +26 -0
  240. data/spec/support/test_app/app/views/basics1/index.html.haml +13 -0
  241. data/spec/support/test_app/app/views/basics2/_grid.html.erb +27 -0
  242. data/spec/support/test_app/app/views/basics2/index.html.haml +12 -0
  243. data/spec/support/test_app/app/views/basics3/_grid.html.erb +28 -0
  244. data/spec/support/test_app/app/views/basics3/index.html.haml +13 -0
  245. data/spec/support/test_app/app/views/basics4/_grid.html.erb +21 -0
  246. data/spec/support/test_app/app/views/basics4/index.html.haml +12 -0
  247. data/spec/support/test_app/app/views/basics5/_grid.html.erb +19 -0
  248. data/spec/support/test_app/app/views/basics5/index.html.haml +12 -0
  249. data/spec/support/test_app/app/views/basics6/_grid.html.erb +19 -0
  250. data/spec/support/test_app/app/views/basics6/index.html.haml +23 -0
  251. data/spec/support/test_app/app/views/blockless_column_definition/_grid.html.erb +19 -0
  252. data/spec/support/test_app/app/views/blockless_column_definition/index.html.haml +15 -0
  253. data/spec/support/test_app/app/views/buttons/_grid.html.erb +20 -0
  254. data/spec/support/test_app/app/views/buttons/index.html.haml +30 -0
  255. data/spec/support/test_app/app/views/csv_and_detached_filters/_grid.html.erb +23 -0
  256. data/spec/support/test_app/app/views/csv_and_detached_filters/index.html.haml +58 -0
  257. data/spec/support/test_app/app/views/csv_export/_projects_grid.html.erb +17 -0
  258. data/spec/support/test_app/app/views/csv_export/_tasks_grid.html.erb +43 -0
  259. data/spec/support/test_app/app/views/csv_export/index.html.haml +90 -0
  260. data/spec/support/test_app/app/views/custom_filter_params/_grid.html.erb +12 -0
  261. data/spec/support/test_app/app/views/custom_filter_params/index.html.haml +12 -0
  262. data/spec/support/test_app/app/views/custom_filters1/_g1.html.erb +8 -0
  263. data/spec/support/test_app/app/views/custom_filters1/_g2.html.erb +9 -0
  264. data/spec/support/test_app/app/views/custom_filters1/_g3.html.erb +9 -0
  265. data/spec/support/test_app/app/views/custom_filters1/_g4.html.erb +8 -0
  266. data/spec/support/test_app/app/views/custom_filters1/index.html.haml +30 -0
  267. data/spec/support/test_app/app/views/custom_filters2/_grid.html.erb +30 -0
  268. data/spec/support/test_app/app/views/custom_filters2/index.html.haml +41 -0
  269. data/spec/support/test_app/app/views/custom_filters3/_grid.html.erb +18 -0
  270. data/spec/support/test_app/app/views/custom_filters3/index.html.haml +16 -0
  271. data/spec/support/test_app/app/views/custom_filters4/_grid.html.erb +20 -0
  272. data/spec/support/test_app/app/views/custom_filters4/index.html.haml +12 -0
  273. data/spec/support/test_app/app/views/custom_ordering/_grid.html.erb +10 -0
  274. data/spec/support/test_app/app/views/custom_ordering/index.html.haml +24 -0
  275. data/spec/support/test_app/app/views/custom_ordering_on_calculated/_grid.html.erb +14 -0
  276. data/spec/support/test_app/app/views/custom_ordering_on_calculated/index.html.haml +23 -0
  277. data/spec/support/test_app/app/views/custom_ordering_with_arel/_grid.html.erb +10 -0
  278. data/spec/support/test_app/app/views/custom_ordering_with_arel/index.html.haml +24 -0
  279. data/spec/support/test_app/app/views/custom_ordering_with_proc/_grid.html.erb +10 -0
  280. data/spec/support/test_app/app/views/custom_ordering_with_proc/index.html.haml +21 -0
  281. data/spec/support/test_app/app/views/custom_ordering_with_ruby/_grid.html.erb +10 -0
  282. data/spec/support/test_app/app/views/custom_ordering_with_ruby/index.html.haml +23 -0
  283. data/spec/support/test_app/app/views/dates/_grid.html.erb +25 -0
  284. data/spec/support/test_app/app/views/dates/index.html.haml +52 -0
  285. data/spec/support/test_app/app/views/detached_filters/_grid.html.erb +23 -0
  286. data/spec/support/test_app/app/views/detached_filters/index.html.haml +79 -0
  287. data/spec/support/test_app/app/views/detached_filters_two_grids/_grid.html.erb +23 -0
  288. data/spec/support/test_app/app/views/detached_filters_two_grids/index.html.haml +85 -0
  289. data/spec/support/test_app/app/views/disable_all_filters/_grid.html.erb +21 -0
  290. data/spec/support/test_app/app/views/disable_all_filters/index.html.haml +14 -0
  291. data/spec/support/test_app/app/views/hiding_checkboxes_in_action_column/_grid.html.erb +34 -0
  292. data/spec/support/test_app/app/views/hiding_checkboxes_in_action_column/index.html.haml +32 -0
  293. data/spec/support/test_app/app/views/integration_with_application_view/_grid.html.erb +27 -0
  294. data/spec/support/test_app/app/views/integration_with_application_view/index.html.haml +33 -0
  295. data/spec/support/test_app/app/views/integration_with_forms/_grid.html.erb +23 -0
  296. data/spec/support/test_app/app/views/integration_with_forms/index.html.haml +18 -0
  297. data/spec/support/test_app/app/views/joining_tables/_grid.html.erb +23 -0
  298. data/spec/support/test_app/app/views/joining_tables/index.html.haml +26 -0
  299. data/spec/support/test_app/app/views/layouts/application.html.haml +61 -0
  300. data/spec/support/test_app/app/views/localization/_grid.html.erb +36 -0
  301. data/spec/support/test_app/app/views/localization/index.html.haml +20 -0
  302. data/spec/support/test_app/app/views/many_grids_on_page/_tasks_grid1.html.erb +12 -0
  303. data/spec/support/test_app/app/views/many_grids_on_page/_tasks_grid2.html.erb +12 -0
  304. data/spec/support/test_app/app/views/many_grids_on_page/index.html.haml +26 -0
  305. data/spec/support/test_app/app/views/negation/_grid.html.erb +30 -0
  306. data/spec/support/test_app/app/views/negation/index.html.haml +15 -0
  307. data/spec/support/test_app/app/views/no_records/_empty_grid.html.haml +1 -0
  308. data/spec/support/test_app/app/views/no_records/_grid1.html.erb +11 -0
  309. data/spec/support/test_app/app/views/no_records/_grid2.html.erb +9 -0
  310. data/spec/support/test_app/app/views/no_records/_grid3.html.erb +9 -0
  311. data/spec/support/test_app/app/views/no_records/index.html.haml +24 -0
  312. data/spec/support/test_app/app/views/null_values/_grid.html.erb +17 -0
  313. data/spec/support/test_app/app/views/null_values/index.html.haml +21 -0
  314. data/spec/support/test_app/app/views/numeric_filters/_grid.html.erb +19 -0
  315. data/spec/support/test_app/app/views/numeric_filters/index.html.haml +12 -0
  316. data/spec/support/test_app/app/views/resultset_processings/_grid.html.erb +27 -0
  317. data/spec/support/test_app/app/views/resultset_processings/index.html.haml +50 -0
  318. data/spec/support/test_app/app/views/resultset_processings2/_grid.html.erb +27 -0
  319. data/spec/support/test_app/app/views/resultset_processings2/index.html.haml +48 -0
  320. data/spec/support/test_app/app/views/saved_queries/_grid.html.erb +30 -0
  321. data/spec/support/test_app/app/views/saved_queries/index.html.haml +15 -0
  322. data/spec/support/test_app/app/views/styling/_grid1.html.erb +12 -0
  323. data/spec/support/test_app/app/views/styling/_grid2.html.erb +31 -0
  324. data/spec/support/test_app/app/views/styling/index.html.haml +65 -0
  325. data/spec/support/test_app/app/views/tasks/_grid.html.erb +19 -0
  326. data/spec/support/test_app/app/views/tasks/index.html.haml +1 -0
  327. data/spec/support/test_app/app/views/two_associations/_grid.html.erb +13 -0
  328. data/spec/support/test_app/app/views/two_associations/index.html.haml +13 -0
  329. data/spec/support/test_app/app/views/upper_pagination_panel/_grid.html.erb +27 -0
  330. data/spec/support/test_app/app/views/upper_pagination_panel/index.html.haml +14 -0
  331. data/spec/support/test_app/app/views/when_filtered/_grid.html.erb +19 -0
  332. data/spec/support/test_app/app/views/when_filtered/index.html.haml +15 -0
  333. data/spec/support/test_app/bin/rails +4 -0
  334. data/spec/support/test_app/bin/rake +4 -0
  335. data/spec/support/test_app/config.ru +5 -0
  336. data/spec/support/test_app/config/application.rb +70 -0
  337. data/spec/support/test_app/config/boot.rb +7 -0
  338. data/spec/support/test_app/config/database.travis.yml +27 -0
  339. data/spec/support/test_app/config/database.yml +16 -0
  340. data/spec/support/test_app/config/database.yml.mysql +19 -0
  341. data/spec/support/test_app/config/database.yml.postgresql +18 -0
  342. data/spec/support/test_app/config/environment.rb +6 -0
  343. data/spec/support/test_app/config/environments/development.rb +34 -0
  344. data/spec/support/test_app/config/environments/production.rb +66 -0
  345. data/spec/support/test_app/config/environments/test.rb +34 -0
  346. data/spec/support/test_app/config/initializers/backtrace_silencers.rb +8 -0
  347. data/spec/support/test_app/config/initializers/inflections.rb +16 -0
  348. data/spec/support/test_app/config/initializers/mime_types.rb +6 -0
  349. data/spec/support/test_app/config/initializers/secret_token.rb +12 -0
  350. data/spec/support/test_app/config/initializers/session_store.rb +9 -0
  351. data/spec/support/test_app/config/initializers/wice_grid_config.rb +163 -0
  352. data/spec/support/test_app/config/initializers/wrap_parameters.rb +15 -0
  353. data/spec/support/test_app/config/locales/en.yml +5 -0
  354. data/spec/support/test_app/config/locales/wice_grid.yml +550 -0
  355. data/spec/support/test_app/config/puma.rb +15 -0
  356. data/spec/support/test_app/config/routes.rb +125 -0
  357. data/spec/support/test_app/db/migrate/20120224193505_create_tasks.rb +27 -0
  358. data/spec/support/test_app/db/migrate/20120224193517_create_users.rb +12 -0
  359. data/spec/support/test_app/db/migrate/20120224193522_create_projects.rb +14 -0
  360. data/spec/support/test_app/db/migrate/20120224193529_create_priorities.rb +13 -0
  361. data/spec/support/test_app/db/migrate/20120224193537_create_statuses.rb +13 -0
  362. data/spec/support/test_app/db/migrate/20120224193543_create_versions.rb +15 -0
  363. data/spec/support/test_app/db/migrate/20120224193550_create_project_roles.rb +12 -0
  364. data/spec/support/test_app/db/migrate/20120224193610_create_companies.rb +12 -0
  365. data/spec/support/test_app/db/migrate/20120224195351_create_user_project_participations.rb +16 -0
  366. data/spec/support/test_app/db/migrate/20120224195521_add_tasks_users.rb +11 -0
  367. data/spec/support/test_app/db/migrate/20120610091944_create_wice_grid_serialized_queries.rb +14 -0
  368. data/spec/support/test_app/db/schema.rb +139 -0
  369. data/spec/support/test_app/db/seeds.rb +10 -0
  370. data/spec/support/test_app/lib/ar_fixtures.rb +100 -0
  371. data/spec/support/test_app/lib/assets/.gitkeep +0 -0
  372. data/spec/support/test_app/lib/tasks/.gitkeep +0 -0
  373. data/spec/support/test_app/lib/tasks/ar_fixtures.rake +45 -0
  374. data/spec/support/test_app/public/404.html +26 -0
  375. data/spec/support/test_app/public/422.html +26 -0
  376. data/spec/support/test_app/public/500.html +25 -0
  377. data/spec/support/test_app/public/favicon.ico +0 -0
  378. data/spec/support/test_app/public/robots.txt +5 -0
  379. data/spec/wice/grid_output_buffer_spec.rb +39 -0
  380. data/spec/wice/table_column_matrix_spec.rb +36 -0
  381. data/spec/wice/wice_grid_misc_spec.rb +157 -0
  382. data/spec/wice/wice_grid_spreadsheet_spec.rb +12 -0
  383. data/vendor/assets/javascripts/wice_grid.js +3 -0
  384. data/vendor/assets/javascripts/wice_grid_init.js.coffee +351 -0
  385. data/vendor/assets/javascripts/wice_grid_processor.js.coffee +133 -0
  386. data/vendor/assets/javascripts/wice_grid_saved_queries_init.js.coffee +104 -0
  387. data/vendor/assets/stylesheets/wice_grid.scss +81 -0
  388. data/wice_grid.gemspec +54 -0
  389. metadata +861 -0
@@ -0,0 +1,19 @@
1
+ module WiceGrid #:nodoc:
2
+ module Generators #:nodoc:
3
+ class AddMigrationForSerializedQueriesGenerator < Rails::Generators::Base #:nodoc:
4
+ include Rails::Generators::Migration
5
+
6
+ desc 'Add a migration which creates a table for serialized queries'
7
+
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ def self.next_migration_number(_path)
11
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
12
+ end
13
+
14
+ def create_model_file
15
+ migration_template 'create_wice_grid_serialized_queries.rb', 'db/migrate/create_wice_grid_serialized_queries.rb'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module WiceGrid #:nodoc:
2
+ module Generators #:nodoc:
3
+ class InstallGenerator < Rails::Generators::Base #:nodoc:
4
+ desc 'Copy WiceGrid wice_grid_config.rb to config/initializers'
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def copy_stuff #:nodoc:
9
+ template 'wice_grid_config.rb', 'config/initializers/wice_grid_config.rb'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class CreateWiceGridSerializedQueries < ::ActiveRecord::Migration #:nodoc:
2
+ def change #:nodoc:
3
+ create_table :wice_grid_serialized_queries do |t|
4
+ t.column :name, :string
5
+ t.column :grid_name, :string
6
+ t.column :query, :text
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :wice_grid_serialized_queries, :grid_name
11
+ add_index :wice_grid_serialized_queries, [:grid_name, :id]
12
+ end
13
+ end
@@ -0,0 +1,191 @@
1
+ if defined?(Wice::Defaults)
2
+
3
+ # Default number of rows to show per page.
4
+ Wice::Defaults::PER_PAGE = 20
5
+
6
+ # Default order direction
7
+ Wice::Defaults::ORDER_DIRECTION = 'asc'
8
+
9
+ # Default name for a grid. A grid name is the basis for a lot of
10
+ # names including parameter names, DOM IDs, etc
11
+ # The shorter the name is the shorter the request URI will be.
12
+ Wice::Defaults::GRID_NAME = 'grid'
13
+
14
+ # If REUSE_LAST_COLUMN_FOR_FILTER_ICONS is true and the last column doesn't have any filter and column name, it will be used
15
+ # for filter related icons (filter icon, reset icon, show/hide icon), otherwise an additional table column is added.
16
+ Wice::Defaults::REUSE_LAST_COLUMN_FOR_FILTER_ICONS = true
17
+
18
+ # The label of the first option of a custom dropdown list meaning 'All items'
19
+ Wice::Defaults::CUSTOM_FILTER_ALL_LABEL = '--'
20
+
21
+ # A list of classes for the table tag of the grid
22
+ Wice::Defaults::DEFAULT_TABLE_CLASSES = ['table', 'table-bordered', 'table-striped']
23
+
24
+ # Allow switching between a single and multiple selection modes in custom filters (dropdown boxes)
25
+ Wice::Defaults::ALLOW_MULTIPLE_SELECTION = true
26
+
27
+ # Show the upper pagination panel by default or not
28
+ Wice::Defaults::SHOW_UPPER_PAGINATION_PANEL = false
29
+
30
+ # Disabling CSV export by default
31
+ Wice::Defaults::ENABLE_EXPORT_TO_CSV = false
32
+
33
+ # Default CSV field separator
34
+ Wice::Defaults::CSV_FIELD_SEPARATOR = ','
35
+
36
+ # Default CSV encoding (p.e. 'CP1252:UTF-8' to make Microsoft Excel(tm) happy)
37
+ Wice::Defaults::CSV_ENCODING = nil
38
+
39
+ # The strategy when to show the filter.
40
+ # * <tt>:when_filtered</tt> - when the table is the result of filtering
41
+ # * <tt>:always</tt> - show the filter always
42
+ # * <tt>:no</tt> - never show the filter
43
+ Wice::Defaults::SHOW_FILTER = :always
44
+
45
+ # A boolean value specifying if a change in a filter triggers reloading of the grid.
46
+ Wice::Defaults::AUTO_RELOAD = false
47
+
48
+ # SQL operator used for matching strings in string filters.
49
+ Wice::Defaults::STRING_MATCHING_OPERATOR = 'LIKE'
50
+ # STRING_MATCHING_OPERATOR = 'ILIKE' # Use this for Postgresql case-insensitive matching.
51
+
52
+ # Defining one string matching operator globally for the whole application turns is not enough
53
+ # when you connect to two databases one of which is MySQL and the other is Postgresql.
54
+ # If the key for an adapter is missing it will fall back to Wice::Defaults::STRING_MATCHING_OPERATOR.
55
+ #
56
+ # 'CI_LIKE' is a special value. Setting a value in STRING_MATCHING_OPERATORS to CI_LIKE will result in the following SQL:
57
+ #
58
+ # UPPER(table.field) LIKE UPPER(?)"
59
+ Wice::Defaults::STRING_MATCHING_OPERATORS = {
60
+ 'ActiveRecord::ConnectionAdapters::MysqlAdapter' => 'LIKE',
61
+ 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' => 'ILIKE'
62
+ }
63
+
64
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
65
+ # Advanced Filters #
66
+
67
+ # Switch of the negation checkbox in all text filters
68
+ Wice::Defaults::NEGATION_IN_STRING_FILTERS = false
69
+
70
+ # Each WiceGrid filter column is defined in two classes, one used for rendering the filter, the other
71
+ # for generating query conditions. All these columns are in lib/wice/columns/*.rb .
72
+ # File lib/wice/columns/column_processor_index.rb lists all predefined processors.
73
+ # In most cases a processor is chosen automatically based on the DB column type,
74
+ # for example, integer columns
75
+ # can have two of processors, the default one with one input field, and a processor called "range",
76
+ # with 2 input fields. In this case it is possible to specify a processor in the column definition:
77
+ #
78
+ # g.column filter_type: :range
79
+ #
80
+ # It is also possible to define you own processors:
81
+ #
82
+ # Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS = {
83
+ # some_key_identifying_new_column_type: ['AViewColumnProcessorClass', 'ConditionsGeneratorClass'],
84
+ # another_key_identifying_new_column_type: ['AnotherViewColumnProcessorClass', 'AnotherConditionsGeneratorClass']
85
+ # }
86
+ #
87
+ # Column processor keys/names should not coincide with the existing keys/names (see lib/wice/columns/column_processor_index.rb)
88
+ # the value is a 2-element array with 2 strings, the first should be a name of view processor class inherited from
89
+ # Wice::Columns::ViewColumn, the second should be a name of conditions generator class inherited from
90
+ # Wice::Columns::ConditionsGeneratorColumn .
91
+
92
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
93
+ # Showing All Records #
94
+
95
+ # Enable or disable showing all records (non-paginated table)
96
+ Wice::Defaults::ALLOW_SHOWING_ALL_RECORDS = true
97
+
98
+ # If number of all queries is more than this value, the user will be given a warning message
99
+ Wice::Defaults::START_SHOWING_WARNING_FROM = 100
100
+
101
+ # Hide the "show all" link if the number of all records is more than...
102
+ # Force-resets back to pagination starting from this value.
103
+ # Set to nil to always show it
104
+ Wice::Defaults::SHOW_ALL_ALLOWED_UP_TO = nil
105
+
106
+ #
107
+ # set to nil to skip the check
108
+ Wice::Defaults::SWITCH_BACK_TO_PAGINATION_FROM = nil
109
+
110
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
111
+ # Saving Queries #
112
+
113
+ # ActiveRecord model to store queries. Read the documentation for details
114
+ # QUERY_STORE_MODEL = 'WiceGridSerializedQuery'
115
+ Wice::Defaults::QUERY_STORE_MODEL = 'WiceGridSerializedQuery'
116
+
117
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
118
+ # Here go settings related to the date/datetime filters #
119
+
120
+ # Default column filters
121
+ # Possible values:
122
+ # * <tt>:jquery_datepicker</tt> - Jquery datepicker (works for datetime, too)
123
+ # * <tt>:bootstrap_datepicker</tt> - Bootstrap datepicker (works for datetime, too)
124
+ # * <tt>:rails_date_helper</tt> - standard Rails date helper
125
+ # * <tt>:rails_datetime_helper</tt> - standard Rails datetime helper
126
+
127
+ Wice::Defaults::DEFAULT_FILTER_FOR_DATE = :jquery_datepicker
128
+ Wice::Defaults::DEFAULT_FILTER_FOR_DATETIME = :jquery_datepicker
129
+
130
+ # Format of the datetime displayed.
131
+ # If you change the format, make sure to check if +DATETIME_PARSER+ can still parse this string.
132
+ Wice::Defaults::DATETIME_FORMAT = '%Y-%m-%d %H:%M'
133
+
134
+ # Format of the date displayed.
135
+ # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
136
+ Wice::Defaults::DATE_FORMAT = '%Y-%m-%d'
137
+
138
+ # Format of the date displayed in jQuery's Datepicker
139
+ # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
140
+ Wice::Defaults::DATE_FORMAT_JQUERY = 'yy-mm-dd'
141
+
142
+ # Format of the date displayed in Bootstrap's Datepicker
143
+ # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
144
+ Wice::Defaults::DATE_FORMAT_BOOTSTRAP = 'yyyy-mm-dd'
145
+
146
+ # With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the
147
+ # format defined by +DATETIME_FORMAT+ and must generate a DateTime object.
148
+ # In many cases <tt>Time.zone.parse</tt> is enough, for instance, <tt>%Y-%m-%d</tt>. If you change the format, make sure to check this code
149
+ # and modify it if needed.
150
+ Wice::Defaults::DATETIME_PARSER = lambda do|datetime_string|
151
+ if datetime_string.blank?
152
+ nil
153
+ elsif Time.zone
154
+ Time.zone.parse(datetime_string)
155
+ else
156
+ Time.parse(datetime_string)
157
+ end
158
+ end
159
+
160
+ # The range of years to display in jQuery Datepicker.
161
+ # It can always be changed dynamically with the following javascript:
162
+ # $( ".hasDatepicker" ).datepicker( "option", "yearRange", "2000:2042" );
163
+ Wice::Defaults::DATEPICKER_YEAR_RANGE = (from = Date.current.year - 10).to_s + ':' + (from + 15).to_s
164
+
165
+ # With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the
166
+ # format defined by +DATETIME+ and must generate a Date object.
167
+ # In many cases <tt>Date.parse</tt> is enough, for instance, <tt>%Y-%m-%d</tt>. If you change the format, make sure to check this code
168
+ # and modify it if needed.
169
+ Wice::Defaults::DATE_PARSER = lambda do|date_string|
170
+ if date_string.blank?
171
+ nil
172
+ else
173
+ begin
174
+ Date.parse(date_string)
175
+ rescue ArgumentError
176
+ nil
177
+ end
178
+ end
179
+ end
180
+
181
+ # The name of the page method (should correspond to Kaminari.config.page_method_name)
182
+ Wice::Defaults::PAGE_METHOD_NAME = :page
183
+
184
+ # The name of the theme to use for the pagination with Kaminari
185
+ Wice::Defaults::PAGINATION_THEME = :wice_grid
186
+
187
+ # By default ActiveRecord calls are always executed inside Model.unscoped{}.
188
+ # Setting <tt>USE_DEFAULT_SCOPE</tt> to true will use the default scope for all queries.
189
+ Wice::Defaults::USE_DEFAULT_SCOPE = false
190
+
191
+ end
@@ -0,0 +1,122 @@
1
+ module Wice
2
+ # to be mixed in into ActiveRecord::ConnectionAdapters::Column
3
+ module WiceGridExtentionToActiveRecordColumn #:nodoc:
4
+ # reference to the ActiveRecord model class
5
+ attr_accessor :model
6
+ end
7
+
8
+ class ActiveRecordColumnWrapper #:nodoc:
9
+ def initialize(column, all_filter_params, main_table, table_alias, custom_filter_active, filter_type) #:nodoc:
10
+ @column = column
11
+
12
+ # nil | Symbol
13
+ @filter_type = filter_type
14
+
15
+ # Hash { String => String | Array[String]}
16
+ @all_filter_params = all_filter_params
17
+
18
+ # nil | Boolean
19
+ @main_table = main_table
20
+
21
+ # nil | String
22
+ @table_alias = table_alias
23
+
24
+ # nil | Array[String] | Array[Array[...]] | Array[Symbol]
25
+ @custom_filter_active = custom_filter_active
26
+ end
27
+
28
+ def wg_initialize_request_parameters #:nodoc:
29
+ @request_params = nil
30
+ return if @all_filter_params.nil?
31
+
32
+ # if the parameter does not specify the table name we only allow columns in the default table to use these parameters
33
+ if @main_table && @request_params = @all_filter_params[@column.name]
34
+ current_parameter_name = @column.name
35
+ elsif @request_params = @all_filter_params[alias_or_table_name(@table_alias) + '.' + @column.name]
36
+ current_parameter_name = alias_or_table_name(@table_alias) + '.' + @column.name
37
+ end
38
+
39
+ # Preprocess incoming parameters for datetime, if what's coming in is
40
+ # a datetime (with custom_filter it can be anything else, and not
41
+ # the datetime hash {fr: ..., to: ...})
42
+ if @request_params
43
+
44
+ if (@column.type == :datetime || @column.type == :timestamp) && @request_params.is_a?(Hash)
45
+ [:fr, :to].each do |sym|
46
+ if @request_params[sym]
47
+ if @request_params[sym].is_a?(String)
48
+ @request_params[sym] = Wice::ConfigurationProvider.value_for(:DATETIME_PARSER).call(@request_params[sym])
49
+ elsif @request_params[sym].is_a?(Hash)
50
+ @request_params[sym] = Wice::GridTools.params_2_datetime(@request_params[sym])
51
+ end
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ # Preprocess incoming parameters for date, if what's coming in is
58
+ # a date (with custom_filter it can be anything else, and not
59
+ # the date hash {fr: ..., to: ...})
60
+ if @column.type == :date && @request_params.is_a?(Hash)
61
+
62
+ [:fr, :to].each do |sym|
63
+ if @request_params[sym]
64
+ if @request_params[sym].is_a?(String)
65
+ @request_params[sym] = Wice::ConfigurationProvider.value_for(:DATE_PARSER).call(@request_params[sym])
66
+ elsif @request_params[sym].is_a?(Hash)
67
+ @request_params[sym] = ::Wice::GridTools.params_2_date(@request_params[sym])
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+
75
+ [wg_generate_conditions, current_parameter_name]
76
+ end
77
+
78
+ def wg_generate_conditions #:nodoc:
79
+ return nil if @request_params.nil?
80
+
81
+ if @custom_filter_active
82
+ custom_processor_klass = ::Wice::Columns.get_conditions_generator_column_processor(:custom)
83
+ custom_processor = custom_processor_klass.new(self)
84
+ return custom_processor.generate_conditions(@table_alias, @request_params)
85
+ end
86
+
87
+ column_type = @filter_type || @column.type.to_s.intern
88
+
89
+ filter_type = case column_type
90
+ when :date
91
+ ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATE)
92
+ when :datetime
93
+ ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATETIME)
94
+ when :timestamp
95
+ ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATETIME)
96
+ else
97
+ column_type
98
+ end
99
+
100
+ processor_class = ::Wice::Columns.get_conditions_generator_column_processor(filter_type)
101
+
102
+ if processor_class
103
+ return processor_class.new(self, column_type).generate_conditions(@table_alias, @request_params)
104
+ else
105
+ Wice.log("No processor for database type #{column_type}!!!")
106
+ nil
107
+ end
108
+ end
109
+
110
+ def name #:nodoc:
111
+ @column.name
112
+ end
113
+
114
+ def model #:nodoc:
115
+ @column.model
116
+ end
117
+
118
+ def alias_or_table_name(table_alias) #:nodoc:
119
+ table_alias || @column.model.table_name
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,282 @@
1
+ module Wice #:nodoc:
2
+ module Columns #:nodoc:
3
+ mattr_reader :handled_type_view, :handled_type_conditions_generator
4
+
5
+ class << self #:nodoc:
6
+ def load_column_processors #:nodoc:
7
+ require_columns
8
+
9
+ @@handled_type_view = build_table_of_processors 'view'
10
+ @@handled_type_conditions_generator = build_table_of_processors 'conditions_generator'
11
+
12
+ if Wice::Defaults.const_defined?(:ADDITIONAL_COLUMN_PROCESSORS)
13
+
14
+ common_error_prefix = 'Error loading Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS. '
15
+
16
+ Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS.each do |key, value|
17
+ unless key.is_a?(Symbol)
18
+ raise common_error_prefix + 'A key of Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS should be a Symbol!'
19
+ end
20
+
21
+ if @@handled_type_view.key?(key)
22
+ raise common_error_prefix +
23
+ "Column with key \"#{key}\" already exists in WiceGrid, overwriting existing columns is forbidden, please choose another key!"
24
+ end
25
+
26
+ if !value.is_a?(Array) || value.size != 2
27
+ ail common_error_prefix +
28
+ 'A value of Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS should be a a 2-element array!'
29
+ end
30
+
31
+ view_processor, conditions_generator = value.map(&:to_s).map do |klass|
32
+ begin
33
+ eval(klass)
34
+ rescue NameError
35
+ raise common_error_prefix + "Class #{klass} is not defined!"
36
+ end
37
+ end
38
+
39
+ unless view_processor.ancestors.include?(::Wice::Columns::ViewColumn)
40
+ raise common_error_prefix +
41
+ "#{view_processor} should be inherited from Wice::Columns::ViewColumn!"
42
+ end
43
+
44
+ unless conditions_generator.ancestors.include?(::Wice::Columns::ConditionsGeneratorColumn)
45
+ raise common_error_prefix +
46
+ "#{conditions_generator} should be inherited from Wice::Columns::ConditionsGeneratorColumn!"
47
+ end
48
+
49
+ @@handled_type_view[key] = view_processor
50
+ @@handled_type_conditions_generator[key] = conditions_generator
51
+ end
52
+ end
53
+ end
54
+
55
+ def get_view_column_processor(column_type) #:nodoc:
56
+ @@handled_type_view[column_type] || ViewColumn
57
+ end
58
+
59
+ def get_conditions_generator_column_processor(column_type) #:nodoc:
60
+ column_type = column_type.intern if column_type.is_a? String
61
+ @@handled_type_conditions_generator[column_type] || raise("Could not find conditions generator processor for column_type #{column_type}")
62
+ end
63
+
64
+ private
65
+
66
+ def build_table_of_processors(prefix)
67
+ {}.tap do |processor_table|
68
+ loaded_processors = {}
69
+
70
+ Wice::Columns::COLUMN_PROCESSOR_INDEX.each do |column_type, column_source_file|
71
+ unless loaded_processors[column_source_file]
72
+ processor_class_name = "#{prefix}_#{column_source_file}".classify
73
+
74
+ unless Wice::Columns.const_defined?(processor_class_name.intern)
75
+ raise "#{column_source_file}.rb is expected to define #{processor_class_name}!"
76
+ end
77
+ processor_class = eval("Wice::Columns::#{processor_class_name}")
78
+
79
+ loaded_processors[column_source_file] = processor_class
80
+ end
81
+
82
+ processor_table[column_type] = loaded_processors[column_source_file]
83
+ end
84
+ end
85
+ end
86
+
87
+ def require_columns
88
+ Wice::Columns::COLUMN_PROCESSOR_INDEX.values.uniq do |column_source_file|
89
+ require "wice/columns/#{column_source_file}.rb"
90
+ end
91
+ end
92
+ end
93
+
94
+ class ViewColumn #:nodoc:
95
+ include ActionView::Helpers::FormTagHelper
96
+ include ActionView::Helpers::TagHelper
97
+ include ActionView::Helpers::JavaScriptHelper
98
+ include ActionView::Helpers::AssetTagHelper
99
+
100
+ # fields defined from the options parameter
101
+ FIELDS = [:attribute, :name, :html, :filter, :model, :allow_multiple_selection,
102
+ :in_html, :in_csv, :table_alias, :custom_order, :detach_with_id, :ordering, :auto_reload,
103
+ :filter_control_options, :sort_by]
104
+
105
+ attr_accessor(*FIELDS)
106
+
107
+ # a Proc object which would return contents of one cell
108
+ attr_accessor :cell_rendering_block
109
+
110
+ # reference to the WiceGrid instance
111
+ attr_accessor :grid
112
+
113
+ # name of the table
114
+ attr_accessor :table_name
115
+
116
+ # name of the main table (first argument to initialize_grid)
117
+ attr_accessor :main_table
118
+
119
+ # attr_accessor :model
120
+
121
+ # specification for a custom filter: an array of option label + option value pairs for the select, or a Proc object which returns this array.
122
+ # Or nil if it is not a custom filter
123
+ attr_accessor :custom_filter
124
+
125
+ # A boolean flag: whether a column has a text input or not
126
+ attr_reader :contains_a_text_input
127
+
128
+ # options for rendering filter controls. Supported options are specific to the type.
129
+ attr_accessor :filter_control_options
130
+
131
+ def initialize(block, options, grid_obj, tname, mtable, cfilter, view) #:nodoc:
132
+ self.cell_rendering_block = block
133
+ self.grid = grid_obj
134
+ self.table_name = tname
135
+ self.main_table = mtable
136
+ self.custom_filter = cfilter
137
+ @view = view
138
+
139
+ FIELDS.each do |field|
140
+ self.send(field.to_s + '=', options[field])
141
+ end
142
+ end
143
+
144
+ def add_css_class(klass_value) #:nodoc:
145
+ self.html ||= {}
146
+ if html[:class].nil?
147
+ html[:class] = klass_value
148
+ else
149
+ html[:class] << ' ' unless html[:class].empty?
150
+ html[:class] << klass_value
151
+ end
152
+ end
153
+
154
+ def css_class #:nodoc:
155
+ if html && html[:class]
156
+ html[:class]
157
+ else
158
+ ''
159
+ end
160
+ end
161
+
162
+ def yield_declaration_of_column_filter #:nodoc:
163
+ nil
164
+ end
165
+
166
+ def detachness #:nodoc:
167
+ (!detach_with_id.blank?).to_s
168
+ end
169
+
170
+ def yield_declaration #:nodoc:
171
+ declaration = yield_declaration_of_column_filter
172
+ if declaration
173
+ {
174
+ filterName: self.name,
175
+ detached: detachness,
176
+ declaration: declaration
177
+ }
178
+ end
179
+ end
180
+
181
+ def config #:nodoc:
182
+ @view.config
183
+ end
184
+
185
+ def controller #:nodoc:
186
+ @view.controller
187
+ end
188
+
189
+ def render_filter #:nodoc:
190
+ params = @grid.filter_params(self)
191
+ render_filter_internal(params)
192
+ end
193
+
194
+ def render_filter_internal(_params) #:nodoc:
195
+ '<!-- implement me! -->'
196
+ end
197
+
198
+ def form_parameter_name_id_and_query(v) #:nodoc:
199
+ query = form_parameter_template(v)
200
+ query_without_equals_sign = query.sub(/=$/, '')
201
+ parameter_name = CGI.unescape(query_without_equals_sign)
202
+ dom_id = id_out_of_name(parameter_name)
203
+ [query, query_without_equals_sign, parameter_name, dom_id.tr('.', '_')]
204
+ end
205
+
206
+ # Returns a reference to the column in the form: "table_name.column_name", unless it is a column in the main
207
+ # table, in which case it will return just "column_name",
208
+ def attribute_name_fully_qualified_for_all_but_main_table_columns
209
+ return attribute if main_table
210
+ return fully_qualified_attribute_name
211
+ end
212
+
213
+ # Returns a reference to the column in the form: "table_name.column_name".
214
+ def fully_qualified_attribute_name
215
+ table_alias_or_table_name ? (table_alias_or_table_name + '.' + attribute) : nil
216
+ end
217
+
218
+ def filter_shown? #:nodoc:
219
+ self.attribute && self.filter
220
+ end
221
+
222
+ def filter_shown_in_main_table? #:nodoc:
223
+ filter_shown? && !self.detach_with_id
224
+ end
225
+
226
+ def table_alias_or_table_name #:nodoc:
227
+ table_alias || table_name
228
+ end
229
+
230
+ def capable_of_hosting_filter_related_icons? #:nodoc:
231
+ self.attribute.blank? && self.name.blank? && !self.filter_shown?
232
+ end
233
+
234
+ def has_auto_reloading_input? #:nodoc:
235
+ false
236
+ end
237
+
238
+ def auto_reloading_input_with_negation_checkbox? #:nodoc:
239
+ false
240
+ end
241
+
242
+ def has_auto_reloading_select? #:nodoc:
243
+ false
244
+ end
245
+
246
+ def has_auto_reloading_calendar? #:nodoc:
247
+ false
248
+ end
249
+
250
+ protected
251
+
252
+ def form_parameter_template(v) #:nodoc:
253
+ { @grid.name => { f: { self.attribute_name_fully_qualified_for_all_but_main_table_columns => v } } }.to_query
254
+ end
255
+
256
+ def form_parameter_name(v) #:nodoc:
257
+ form_parameter_template_hash(v).to_query
258
+ end
259
+
260
+ def name_out_of_template(s) #:nodoc:
261
+ CGI.unescape(s).sub(/=$/, '')
262
+ end
263
+
264
+ def id_out_of_name(s) #:nodoc:
265
+ s.gsub(/[\[\]]+/, '_').sub(/_+$/, '')
266
+ end
267
+ end
268
+
269
+ class ConditionsGeneratorColumn #:nodoc:
270
+ def initialize(column_wrapper, column_type = nil) #:nodoc:
271
+ # Wice::ActiveRecordColumnWrapper
272
+ @column_wrapper = column_wrapper
273
+ @column_type = column_type
274
+ end
275
+
276
+ def generate_conditions(_table_alias, _opts) #:nodoc:
277
+ raise('implement me')
278
+ end
279
+
280
+ end
281
+ end
282
+ end