pwice_grid 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,73 @@
1
+ module Wice #:nodoc:
2
+ module BsCalendarHelpers #:nodoc:
3
+
4
+ # A struct containing all data for rendering a calendar
5
+ class CalendarData #:nodoc:
6
+
7
+ # :nodoc:
8
+ attr_accessor :name,
9
+ :date_string,
10
+ :dom_id,
11
+ :datepicker_placeholder_id,
12
+ :date_div_id,
13
+ :fire_event,
14
+ :close_calendar_event_name,
15
+ :the_other_datepicker_id_to,
16
+ :the_other_datepicker_id_from
17
+ end
18
+
19
+ def date_calendar_bs(calendar_data) #:nodoc:
20
+ placeholder =
21
+ if calendar_data.the_other_datepicker_id_to
22
+ I18n.t("wice_grid.date_selector_tooltip_from")
23
+ else
24
+ I18n.t("wice_grid.date_selector_tooltip_to")
25
+ end
26
+
27
+ text_field_tag_options = {
28
+ :id => calendar_data.dom_id,
29
+ 'data-provide' => 'datepicker',
30
+ 'data-date-language' => I18n.locale,
31
+ 'data-date-autoclose' => true,
32
+ 'data-date-format' => Wice::ConfigurationProvider.value_for(:DATE_FORMAT_BOOTSTRAP),
33
+ 'placeholder' => placeholder
34
+ }
35
+
36
+ text_field_tag_options['class'] = 'form-control input-sm'
37
+
38
+ if Rails.env.development?
39
+ text_field_tag_options['class'] += ' check-for-bsdatepicker'
40
+ end
41
+
42
+ if calendar_data.fire_event
43
+ text_field_tag_options['data-close-calendar-event-name'] = calendar_data.close_calendar_event_name
44
+ end
45
+
46
+ if calendar_data.the_other_datepicker_id_to
47
+ text_field_tag_options['data-the-other-bsdatepicker-id-to'] = calendar_data.the_other_datepicker_id_to
48
+ end
49
+
50
+ if calendar_data.the_other_datepicker_id_from
51
+ text_field_tag_options['data-the-other-bsdatepicker-id-from'] = calendar_data.the_other_datepicker_id_from
52
+ end
53
+
54
+ date_picker = text_field_tag(calendar_data.name, calendar_data.date_string, text_field_tag_options)
55
+
56
+ "<div id=\"#{calendar_data.datepicker_placeholder_id}\">#{date_picker}</div>"
57
+ end
58
+
59
+ def prepare_data_for_bscalendar(options) #:nodoc:
60
+ date_format = Wice::ConfigurationProvider.value_for(:DATE_FORMAT)
61
+
62
+ CalendarData.new.tap do |calendar_data|
63
+ calendar_data.name = options[:name]
64
+ calendar_data.date_string = options[:initial_date].nil? ? '' : options[:initial_date].strftime(date_format)
65
+ calendar_data.dom_id = options[:name].gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '').gsub(/\./, '_').gsub(/_+/, '_')
66
+ calendar_data.datepicker_placeholder_id = calendar_data.dom_id + '_date_placeholder'
67
+ calendar_data.date_div_id = calendar_data.dom_id + '_date_view'
68
+ calendar_data.close_calendar_event_name = "wg:calendarChanged_#{options[:grid_name]}"
69
+ calendar_data.fire_event = options[:fire_event]
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,82 @@
1
+ module Wice #:nodoc:
2
+ module JsCalendarHelpers #:nodoc:
3
+
4
+ # A struct containing all data for rendering a calendar
5
+ class CalendarData
6
+
7
+ # :nodoc:
8
+ attr_accessor :name,
9
+ :date_string,
10
+ :dom_id,
11
+ :datepicker_placeholder_id,
12
+ :date_span_id,
13
+ :close_calendar_event_name,
14
+ :title,
15
+ :fire_event,
16
+ :the_other_datepicker_id_to,
17
+ :the_other_datepicker_id_from
18
+ end
19
+
20
+ def date_calendar_jquery(calendar_data) #:nodoc:
21
+ hidden_field_tag_options = {
22
+ :id => calendar_data.dom_id,
23
+ 'data-locale' => I18n.locale,
24
+ 'data-date-format' => Wice::ConfigurationProvider.value_for(:DATE_FORMAT_JQUERY),
25
+ 'data-button-text' => calendar_data.title
26
+ }
27
+
28
+ if calendar_data.fire_event
29
+ hidden_field_tag_options['data-close-calendar-event-name'] = calendar_data.close_calendar_event_name
30
+ end
31
+
32
+ if Rails.env.development?
33
+ hidden_field_tag_options['class'] = 'check-for-datepicker'
34
+ end
35
+
36
+ if calendar_data.the_other_datepicker_id_to
37
+ hidden_field_tag_options['data-the-other-datepicker-id-to'] = calendar_data.the_other_datepicker_id_to
38
+ end
39
+
40
+ if calendar_data.the_other_datepicker_id_from
41
+ hidden_field_tag_options['data-the-other-datepicker-id-from'] = calendar_data.the_other_datepicker_id_from
42
+ end
43
+
44
+ if year_range = ConfigurationProvider.value_for(:DATEPICKER_YEAR_RANGE)
45
+ hidden_field_tag_options['data-date-year-range'] = year_range
46
+ end
47
+
48
+ date_picker = hidden_field_tag(calendar_data.name, calendar_data.date_string, hidden_field_tag_options) + ' ' +
49
+
50
+ link_to(
51
+ calendar_data.date_string,
52
+ '#',
53
+ :id => calendar_data.date_span_id,
54
+ :class => 'date-label',
55
+ :title => ::Wice::NlMessage['date_string_tooltip'],
56
+ 'data-dom-id' => calendar_data.dom_id
57
+ )
58
+
59
+ content_tag(
60
+ :span,
61
+ date_picker,
62
+ id: calendar_data.datepicker_placeholder_id,
63
+ class: 'jq-datepicker-container'
64
+ )
65
+ end
66
+
67
+ def prepare_data_for_calendar(options) #:nodoc:
68
+ date_format = Wice::ConfigurationProvider.value_for(:DATE_FORMAT)
69
+
70
+ CalendarData.new.tap do |calendar_data|
71
+ calendar_data.name = options[:name]
72
+ calendar_data.date_string = options[:initial_date].nil? ? '' : options[:initial_date].strftime(date_format)
73
+ calendar_data.dom_id = options[:name].gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '').gsub(/\./, '_').gsub(/_+/, '_')
74
+ calendar_data.datepicker_placeholder_id = calendar_data.dom_id + '_date_placeholder'
75
+ calendar_data.date_span_id = calendar_data.dom_id + '_date_view'
76
+ calendar_data.close_calendar_event_name = "wg:calendarChanged_#{options[:grid_name]}"
77
+ calendar_data.title = options[:title]
78
+ calendar_data.fire_event = options[:fire_event]
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,74 @@
1
+ module Wice
2
+
3
+ # Various grid related helpers
4
+ module GridViewHelper
5
+ # This method dumps all HTTP parameters related to filtering and ordering of a certain grid as hidden form fields.
6
+ # This might be required if you want to keep the state of a grid while reloading the page using other forms.
7
+ #
8
+ # The only parameter is a grid object returned by +initialize_grid+ in the controller.
9
+ def dump_filter_parameters_as_hidden_fields(grid)
10
+ unless grid.is_a? WiceGrid
11
+ raise WiceGridArgumentError.new('dump_filter_parameters_as_hidden_fields: the parameter must be a WiceGrid instance.')
12
+ end
13
+
14
+ grid.get_state_as_parameter_value_pairs(true).collect do|param_name, value|
15
+ hidden_field_tag(param_name, value, id: "hidden-#{param_name.gsub(/[\[\]]/, '-')}")
16
+ end.join("\n").html_safe
17
+ end
18
+
19
+ # This method dumps all HTTP parameters related to filtering of a certain grid in the form of a hash.
20
+ # This might be required if you want to keep the state of a grid while reloading the page using Rails routing helpers.
21
+ # Attention: this does not return parameters for ordering the grid, use +filter_and_order_state_as_hash+ if you
22
+ # need it.
23
+ #
24
+ # The only parameter is a grid object returned by +initialize_grid+ in the controller.
25
+ def filter_state_as_hash(grid)
26
+ { grid.name => { 'f' => grid.status[:f] } }
27
+ end
28
+
29
+ # This method dumps all HTTP parameters related to filtering and ordering of a certain grid in the form of a hash.
30
+ # This might be required if you want to keep the state of a grid while reloading the page using Rails routing helpers.
31
+ #
32
+ # The only parameter is a grid object returned by +initialize_grid+ in the controller.
33
+ def filter_and_order_state_as_hash(grid)
34
+ {
35
+ grid.name => {
36
+ 'f' => grid.status[:f],
37
+ 'order' => grid.status[:order],
38
+ 'order_direction' => grid.status[:order_direction]
39
+ }
40
+ }
41
+ end
42
+
43
+ # display the state of the grid
44
+ def dump_state(grid) #:nodoc:
45
+ debug(grid.get_state_as_parameter_value_pairs)
46
+ end
47
+
48
+ # secret but stupid weapon - takes an ActiveRecord and using reflection tries to build all the column clauses by itself.
49
+ # WiceGrid is not a scaffolding solution, I hate scaffolding and how certain idiots associate scaffolding with Rails,
50
+ # so I do not document this method to avoid contributing to this misunderstanding.
51
+ def scaffolded_grid(grid_obj, opts = {}) #:nodoc:
52
+ unless grid_obj.is_a? WiceGrid
53
+ raise WiceGridArgumentError.new('scaffolded_grid: the parameter must be a WiceGrid instance.')
54
+ end
55
+
56
+ # debug grid.klass.column_names
57
+ columns = grid_obj.klass.column_names
58
+ if opts[:reject_attributes].is_a? Proc
59
+ columns = columns.reject { |c| opts[:reject_attributes].call(c) }
60
+ opts.delete(:reject_attributes)
61
+ else
62
+ columns = columns.reject { |c| c =~ opts[:reject_attributes] }
63
+ opts.delete(:reject_attributes)
64
+ end
65
+ grid(grid_obj, opts) do |g|
66
+ columns.each do |column_name|
67
+ g.column name: column_name.humanize, attribute: column_name do |ar|
68
+ ar.send(column_name)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,94 @@
1
+ module Wice
2
+ module GridViewHelper
3
+ # View helper to render the list of saved queries and the form to create a new query.
4
+ # Parameters:
5
+ # * <tt>:extra_parameters</tt> - a hash of additional parameters to use when creating a new query object.
6
+ # * <tt>:confirm</tt> - A boolean value which turns on or off the JS confirm dialogs when deleting saved queries.
7
+ # Read section "Adding Application Specific Logic to Saving/Restoring Queries" in README for more details.
8
+ def saved_queries_panel(grid, opts = {})
9
+ unless grid.is_a? WiceGrid
10
+ raise WiceGridArgumentError.new('saved_queries_panel: the parameter must be a WiceGrid instance.')
11
+ end
12
+
13
+ options = { extra_parameters: {}, confirm: 1 }
14
+ opts.assert_valid_keys(options.keys)
15
+ options.merge!(opts)
16
+
17
+ grid_name = grid.name
18
+ input_field_name = "#{grid_name}_saved_query_name"
19
+ base_path_to_query_controller = create_serialized_query_url(grid_name: grid_name, confirm: options[:confirm])
20
+
21
+ parameters = grid.get_state_as_parameter_value_pairs
22
+
23
+ options[:extra_parameters].each do |k, v|
24
+ parameters << [CGI.unescape({ extra: { k => '' } }.to_query.sub(/=$/, '')), v.to_s]
25
+ end
26
+ parameters << ['authenticity_token', form_authenticity_token]
27
+ notification_messages_id = "#{grid_name}_notification_messages"
28
+ (%( <div class="wice-grid-query-panel well"><h3>#{NlMessage['saved_query_panel_title']}</h3>) +
29
+ saved_queries_list(grid_name, grid.saved_query, options[:extra_parameters], options[:confirm]) +
30
+ %(<div id="#{notification_messages_id}" ></div>) +
31
+ if block_given?
32
+ view, ids = yield
33
+ view
34
+ else
35
+ ''
36
+ end +
37
+
38
+ '<div class="form-horizontal"><div class="wg-saved-query-input-controls input-append">' + text_field_tag(input_field_name, '', onkeydown: '', class: 'wice-grid-save-query-field form-control ') +
39
+ button_tag(
40
+ NlMessage['save_query_button_label'],
41
+ class: 'wice-grid-save-query-button btn btn-primary',
42
+ 'data-grid-name' => grid_name,
43
+ 'data-base-path-to-query-controller' => base_path_to_query_controller,
44
+ 'data-parameters' => parameters.to_json,
45
+ 'data-ids' => ids.to_json
46
+ ) +
47
+ '</div></div></div>'
48
+ ).html_safe
49
+ end
50
+
51
+ def saved_queries_list(grid_name, saved_query = nil, extra_parameters = {}, confirm = 1) #:nodoc:
52
+ link_title = NlMessage['saved_query_link_title']
53
+ deletion_confirmation = confirm ? NlMessage['saved_query_deletion_confirmation'] : nil
54
+ deletion_link_title = NlMessage['saved_query_deletion_link_title']
55
+
56
+ query_store_model = ::Wice.get_query_store_model
57
+ currently_loaded_query_id = saved_query ? saved_query.id : nil
58
+ # with = extra_parameters.nil? ? nil : "'" + {extra: extra_parameters}.to_query + "'"
59
+
60
+ %(<ul id="#{grid_name}_query_list" class="query-list"> ) +
61
+ query_store_model.list(grid_name, controller).collect do |sq|
62
+ link_opts = {
63
+ class: 'wice-grid-query-load-link',
64
+ title: "#{link_title} #{sq.name}",
65
+ 'data-query-id' => sq.id,
66
+ 'data-grid-name' => grid_name
67
+ }
68
+ link_opts[:class] += ' current' if saved_query == sq
69
+ '<li>' + link_to(
70
+ content_tag(:i, '', class: 'fa fa-trash-o delete-icon'),
71
+ delete_serialized_query_path(
72
+ grid_name: grid_name,
73
+ id: sq.id,
74
+ current: currently_loaded_query_id,
75
+ extra: extra_parameters,
76
+ confirm: confirm
77
+ ),
78
+ class: 'wice-grid-delete-query',
79
+ 'data-wg-confirm' => deletion_confirmation,
80
+ 'data-grid-name' => grid_name,
81
+ title: "#{deletion_link_title} #{sq.name}"
82
+ ) + ' &nbsp; ' +
83
+ link_to(h(sq.name), '#', link_opts) +
84
+ if sq.respond_to? :description
85
+ desc = sq.description
86
+ desc.blank? ? '' : " <i>#{desc}</i>"
87
+ else
88
+ ''
89
+ end +
90
+ '</li>'
91
+ end.join('') + '</ul>'
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,719 @@
1
+ module Wice
2
+ module GridViewHelper
3
+ # View helper for rendering the grid.
4
+ #
5
+ # The first parameter is a grid object returned by +initialize_grid+ in the controller.
6
+ #
7
+ # The second parameter is a hash of options:
8
+ # * <tt>:html</tt> - a hash of HTML attributes to be included into the <tt>table</tt> tag.
9
+ # * <tt>:class</tt> - a shortcut for <tt>html: {class: 'css_class'}</tt>
10
+ # * <tt>:header_tr_html</tt> - a hash of HTML attributes to be included into the first <tt>tr</tt> tag
11
+ # (or two first <tt>tr</tt>'s if the filter row is present).
12
+ # * <tt>:show_filters</tt> - defines when the filter is shown. Possible values are:
13
+ # * <tt>:when_filtered</tt> - the filter is shown when the current table is the result of filtering
14
+ # * <tt>:always</tt> or <tt>true</tt> - show the filter always
15
+ # * <tt>:no</tt> or <tt>false</tt> - never show the filter
16
+ # * <tt>:upper_pagination_panel</tt> - a boolean value which defines whether there is an additional pagination
17
+ # panel on top of the table. By default it is false.
18
+ # * <tt>:extra_request_parameters</tt> - a hash which will be added as additional HTTP request parameters to all
19
+ # links generated by the grid, be it sorting links, filters, or the 'Reset Filter' icon.
20
+ # Please note that WiceGrid respects and retains all request parameters already present in the URL which
21
+ # formed the page, so there is no need to enumerate them in <tt>:extra_request_parameters</tt>. A typical
22
+ # usage of <tt>:extra_request_parameters</tt> is a page with javascript tabs - changing the active tab
23
+ # does not reload the page, but if one such tab contains a WiceGrid, it could be required that if the user
24
+ # orders or filters the grid, the result page should have the tab with the grid activated. For this we
25
+ # need to send an additional parameter specifying from which tab the request was generated.
26
+ # * <tt>:sorting_dependant_row_cycling</tt> - When set to true (by default it is false) the row styles +odd+
27
+ # and +even+ will be changed only when the content of the cell belonging to the sorted column changes.
28
+ # In other words, rows with identical values in the ordered column will have the same style (color).
29
+ # * <tt>:allow_showing_all_records</tt> - allow or prohibit the "All Records" mode.
30
+ # * <tt>:hide_reset_button</tt> - Do not show the default Filter Reset button.
31
+ # Useful when using a custom reset button.
32
+ # By default it is false.
33
+ # * <tt>:hide_submit_button</tt> - Do not show the default Filter Submit button.
34
+ # Useful when using a custom submit button
35
+ # By default it is false.
36
+ # * <tt>:hide_csv_button</tt> - a boolean value which defines whether the default Export To CSV button
37
+ # should be rendered. Useful when using a custom Export To CSV button.
38
+ # By default it is false.
39
+ # Please read README for more insights.
40
+ #
41
+ # The block contains definitions of grid columns using the +column+ method sent to the object yielded into
42
+ # the block. In other words, the value returned by each of the blocks defines the content of a cell, the
43
+ # first block is called for cells of the first column for each row (each ActiveRecord instance), the
44
+ # second block is called for cells of the second column, and so on. See the example:
45
+ #
46
+ # <%= grid(@accounts_grid, html: {class: 'grid_style', id: 'accounts_grid'}, header_tr_html: {class: 'grid_headers'}) do |g|
47
+ #
48
+ # g.column name: 'Username', attribute: 'username' do |account|
49
+ # account.username
50
+ # end
51
+ #
52
+ # g.column name: 'application_account.field.identity_id'._, attribute: 'firstname', model: Person do |account|
53
+ # link_to(account.identity.name, identity_path(account.identity))
54
+ # end
55
+ #
56
+ # g.column do |account|
57
+ # link_to('Edit', edit_account_path(account))
58
+ # end
59
+ #
60
+ # end -%>
61
+ #
62
+ #
63
+ # Defaults for parameters <tt>:show_filters</tt> and <tt>:upper_pagination_panel</tt>
64
+ # can be changed in <tt>lib/wice_grid_config.rb</tt> using constants <tt>Wice::Defaults::SHOW_FILTER</tt> and
65
+ # <tt>WiceGrid::Defaults::SHOW_UPPER_PAGINATION_PANEL</tt>, this is convenient if you want to set a project wide setting
66
+ # without having to repeat it for every grid instance.
67
+ #
68
+ # Pease read documentation about the +column+ method to achieve the enlightenment.
69
+
70
+ def grid(grid, opts = {}, &block)
71
+ raise WiceGridArgumentError.new('Missing block for the grid helper.' \
72
+ ' For detached filters use first define_grid with the same API as grid, ' \
73
+ 'then grid_filter to add filters, and then render_grid to actually show the grid') if block.nil?
74
+ define_grid(grid, opts, &block)
75
+ render_grid(grid)
76
+ end
77
+
78
+ # Has the same parameters as <tt>grid</tt> but does not output the grid. After <tt>define_grid</tt>
79
+ # <tt>render_grid</tt> can be used to output the grid HTML code.
80
+ # Usually used with detached filters: first <tt>define_grid</tt>, then <tt>grid_filter</tt>s, and then
81
+ # <tt>render_grid</tt>
82
+ def define_grid(grid, opts = {}, &block)
83
+ # strip the method from HTML stuff
84
+ unless grid.class == WiceGrid
85
+ raise WiceGridArgumentError.new('The first argument for the grid helper must be an instance of the WiceGrid class')
86
+ end
87
+
88
+ options = {
89
+ allow_showing_all_records: Defaults::ALLOW_SHOWING_ALL_RECORDS,
90
+ class: nil,
91
+ extra_request_parameters: {},
92
+ header_tr_html: {},
93
+ hide_reset_button: false,
94
+ hide_submit_button: false,
95
+ hide_csv_button: false,
96
+ show_filters: Defaults::SHOW_FILTER,
97
+ sorting_dependant_row_cycling: false,
98
+ html: {},
99
+ upper_pagination_panel: Defaults::SHOW_UPPER_PAGINATION_PANEL,
100
+ pagination_theme: ConfigurationProvider.value_for(:PAGINATION_THEME)
101
+ }
102
+
103
+ opts.assert_valid_keys(options.keys)
104
+
105
+ options.merge!(opts)
106
+
107
+ options[:show_filters] = :no if options[:show_filters] == false
108
+ options[:show_filters] = :always if options[:show_filters] == true
109
+
110
+ rendering = GridRenderer.new(grid, self)
111
+
112
+ block.call(rendering) # calling block containing column() calls
113
+
114
+ reuse_last_column_for_filter_buttons =
115
+ Defaults::REUSE_LAST_COLUMN_FOR_FILTER_ICONS && rendering.last_column_for_html.capable_of_hosting_filter_related_icons?
116
+
117
+ if grid.output_csv?
118
+ grid_csv(grid, rendering)
119
+ else
120
+ # If blank_slate is defined we don't show any grid at all
121
+ if rendering.blank_slate_handler && grid.resultset.size == 0 && !grid.filtering_on?
122
+ generate_blank_slate(grid, rendering)
123
+ else
124
+ grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons)
125
+ end
126
+ end
127
+
128
+ grid.view_helper_finished = true
129
+
130
+ grid.csv_tempfile ? grid.csv_tempfile.path : nil
131
+ end
132
+
133
+ # Used after <tt>define_grid</tt> to actually output the grid HTML code.
134
+ # Usually used with detached filters: first <tt>define_grid</tt>, then <tt>grid_filter</tt>s, and then
135
+ # <tt>render_grid</tt>
136
+ def render_grid(grid)
137
+ if grid.output_buffer
138
+ grid.output_buffer
139
+ elsif grid.csv_tempfile
140
+ grid.csv_tempfile.path
141
+ else
142
+ raise WiceGridException.new("Attempt to use 'render_grid' without 'define_grid' before.")
143
+ end
144
+ end
145
+
146
+ def generate_blank_slate(grid, rendering) #:nodoc:
147
+ grid.output_buffer = GridOutputBuffer.new
148
+
149
+ grid.output_buffer << if rendering.blank_slate_handler.is_a?(Proc)
150
+ call_block(rendering.blank_slate_handler, nil)
151
+ elsif rendering.blank_slate_handler.is_a?(Hash)
152
+ render(rendering.blank_slate_handler)
153
+ else
154
+ rendering.blank_slate_handler
155
+ end
156
+
157
+ # rubocop:disable Style/SymbolProc
158
+ if rendering.find_one_for(:in_html) { |column| column.detach_with_id }
159
+ grid.output_buffer.return_empty_strings_for_nonexistent_filters = true
160
+ end
161
+ # rubocop:enable Style/SymbolProc
162
+ end
163
+
164
+ def call_block(block, ar, extra_argument = nil) #:nodoc:
165
+ extra_argument ? block.call(ar, extra_argument) : block.call(ar)
166
+ end
167
+
168
+ def get_row_content(rendering, ar, sorting_dependant_row_cycling) #:nodoc:
169
+ cell_value_of_the_ordered_column = nil
170
+ row_content = ''
171
+ rendering.each_column(:in_html) do |column|
172
+ cell_block = column.cell_rendering_block
173
+
174
+ opts = column.html
175
+
176
+ opts = opts ? opts.clone : {}
177
+
178
+ column_block_output = if column.class == Columns.get_view_column_processor(:action)
179
+ cell_block.call(ar, params)
180
+ else
181
+ call_block(cell_block, ar)
182
+ end
183
+
184
+ if column_block_output.is_a?(Array)
185
+
186
+ unless column_block_output.size == 2
187
+ raise WiceGridArgumentError.new('When WiceGrid column block returns an array it is expected to contain 2 elements only - ' \
188
+ 'the first is the contents of the table cell and the second is a hash containing HTML attributes for the <td> tag.')
189
+ end
190
+
191
+ column_block_output, additional_opts = column_block_output
192
+
193
+ unless additional_opts.is_a?(Hash)
194
+ raise WiceGridArgumentError.new('When WiceGrid column block returns an array its second element is expected to be a ' \
195
+ "hash containing HTML attributes for the <td> tag. The returned value is #{additional_opts.inspect}. Read documentation.")
196
+ end
197
+
198
+ additional_css_class = nil
199
+ if additional_opts.key?(:class)
200
+ additional_css_class = additional_opts[:class]
201
+ additional_opts.delete(:class)
202
+ elsif additional_opts.key?('class')
203
+ additional_css_class = additional_opts['class']
204
+ additional_opts.delete('class')
205
+ end
206
+ opts.merge!(additional_opts)
207
+ Wice::WgHash.add_or_append_class_value!(opts, additional_css_class) unless additional_css_class.blank?
208
+ end
209
+
210
+ if sorting_dependant_row_cycling && column.attribute && grid.ordered_by?(column)
211
+ cell_value_of_the_ordered_column = column_block_output
212
+ end
213
+ row_content += content_tag(:td, column_block_output, opts)
214
+ end
215
+ [row_content, cell_value_of_the_ordered_column]
216
+ end
217
+
218
+ # the longest method? :(
219
+ def grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons) #:nodoc:
220
+ table_html_attrs, header_tr_html = options[:html], options[:header_tr_html]
221
+
222
+ Wice::WgHash.add_or_append_class_value!(table_html_attrs, 'wice-grid', true)
223
+
224
+ if Array === Defaults::DEFAULT_TABLE_CLASSES
225
+ Defaults::DEFAULT_TABLE_CLASSES.each do |default_class|
226
+ Wice::WgHash.add_or_append_class_value!(table_html_attrs, default_class, true)
227
+ end
228
+ end
229
+
230
+ if options[:class]
231
+ Wice::WgHash.add_or_append_class_value!(table_html_attrs, options[:class])
232
+ options.delete(:class)
233
+ end
234
+
235
+ cycle_class = nil
236
+ sorting_dependant_row_cycling = options[:sorting_dependant_row_cycling]
237
+
238
+ grid.output_buffer = GridOutputBuffer.new
239
+
240
+ # Ruby 1.9.x
241
+ grid.output_buffer.force_encoding('UTF-8') if grid.output_buffer.respond_to?(:force_encoding)
242
+
243
+ grid.output_buffer << %(<div class="wice-grid-container table-responsive" data-grid-name="#{grid.name}" id="#{grid.name}"><div id="#{grid.name}_title">)
244
+ grid.output_buffer << content_tag(:h3, grid.saved_query.name) if grid.saved_query
245
+ grid.output_buffer << "</div><table #{public_tag_options(table_html_attrs, true)}>"
246
+ grid.output_buffer << "<caption>#{rendering.kaption}</caption>" if rendering.kaption
247
+ grid.output_buffer << '<thead>'
248
+
249
+ no_filters_at_all = (options[:show_filters] == :no || rendering.no_filter_needed?)
250
+
251
+ if no_filters_at_all
252
+ no_rightmost_column = no_filter_row = no_filters_at_all
253
+ else
254
+ no_rightmost_column = no_filter_row = (options[:show_filters] == :no || rendering.no_filter_needed_in_main_table?) ? true : false
255
+ end
256
+
257
+ no_rightmost_column = true if reuse_last_column_for_filter_buttons
258
+
259
+ number_of_columns = rendering.number_of_columns(:in_html)
260
+ number_of_columns -= 1 if no_rightmost_column
261
+
262
+ number_of_columns_for_extra_rows = number_of_columns + 1
263
+
264
+ pagination_panel_content_html = nil
265
+ if options[:upper_pagination_panel]
266
+ grid.output_buffer << rendering.pagination_panel(number_of_columns, options[:hide_csv_button]) do
267
+ pagination_panel_content_html =
268
+ pagination_panel_content(grid, options[:extra_request_parameters], options[:allow_showing_all_records], options[:pagination_theme])
269
+ pagination_panel_content_html
270
+ end
271
+ end
272
+
273
+ title_row_attrs = header_tr_html.clone
274
+ Wice::WgHash.add_or_append_class_value!(title_row_attrs, 'wice-grid-title-row', true)
275
+
276
+ grid.output_buffer << %(<tr #{public_tag_options(title_row_attrs, true)}>)
277
+
278
+ filter_row_id = grid.name + '_filter_row'
279
+
280
+ # first row of column labels with sorting links
281
+
282
+ filter_shown = if options[:show_filters] == :when_filtered
283
+ grid.filtering_on?
284
+ elsif options[:show_filters] == :always
285
+ true
286
+ end
287
+
288
+ rendering.each_column_aware_of_one_last_one(:in_html) do |column, last|
289
+ column_name = column.name
290
+
291
+ opts = column.html
292
+
293
+ opts = opts ? opts.clone : {}
294
+
295
+ Wice::WgHash.add_or_append_class_value!(opts, column.css_class)
296
+
297
+ if column.attribute && (column.ordering || column.sort_by)
298
+
299
+ column.add_css_class('active-filter') if grid.filtered_by?(column)
300
+
301
+ direction = 'asc'
302
+ link_style = nil
303
+ arrow_class = nil
304
+
305
+ if grid.ordered_by?(column)
306
+ column.add_css_class('sorted')
307
+ Wice::WgHash.add_or_append_class_value!(opts, 'sorted')
308
+ link_style = grid.order_direction
309
+
310
+ case grid.order_direction
311
+ when 'asc'
312
+ direction = 'desc'
313
+ arrow_class = 'down'
314
+ when 'desc'
315
+ direction = 'asc'
316
+ arrow_class = 'up'
317
+ end
318
+ end
319
+
320
+ col_link = link_to(
321
+ (column_name +
322
+ if arrow_class
323
+ ' ' + content_tag(:i, '', class: "fa fa-arrow-#{arrow_class}")
324
+ else
325
+ ''
326
+ end).html_safe,
327
+
328
+ rendering.column_link(
329
+ column,
330
+ direction,
331
+ params,
332
+ options[:extra_request_parameters]
333
+ ),
334
+ class: link_style)
335
+
336
+ grid.output_buffer << content_tag(:th, col_link, opts)
337
+
338
+ else
339
+ if reuse_last_column_for_filter_buttons && last
340
+ grid.output_buffer << content_tag(:th,
341
+ hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering), opts
342
+ )
343
+ else
344
+ grid.output_buffer << content_tag(:th, column_name, opts)
345
+ end
346
+ end
347
+ end
348
+
349
+ grid.output_buffer << content_tag(:th,
350
+ hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering)
351
+ ) unless no_rightmost_column
352
+
353
+ grid.output_buffer << '</tr>'
354
+ # rendering first row end
355
+
356
+ unless no_filters_at_all # there are filters, we don't know where, in the table or detached
357
+ if no_filter_row # they are all detached
358
+ rendering.each_column(:in_html) do |column|
359
+ if column.filter_shown?
360
+ filter_html_code = column.render_filter.html_safe
361
+ grid.output_buffer.add_filter(column.detach_with_id, filter_html_code)
362
+ end
363
+ end
364
+
365
+ else # some filters are present in the table
366
+
367
+ filter_row_attrs = header_tr_html.clone
368
+ Wice::WgHash.add_or_append_class_value!(filter_row_attrs, 'wg-filter-row', true)
369
+ filter_row_attrs['id'] = filter_row_id
370
+
371
+ grid.output_buffer << %(<tr #{public_tag_options(filter_row_attrs, true)} )
372
+ grid.output_buffer << 'style="display:none"' unless filter_shown
373
+ grid.output_buffer << '>'
374
+
375
+ rendering.each_column_aware_of_one_last_one(:in_html) do |column, last|
376
+ opts = column.html ? column.html.clone : {}
377
+ Wice::WgHash.add_or_append_class_value!(opts, column.css_class)
378
+
379
+ if column.filter_shown?
380
+
381
+ filter_html_code = column.render_filter.html_safe
382
+ if column.detach_with_id
383
+ grid.output_buffer << content_tag(:th, '', opts)
384
+ grid.output_buffer.add_filter(column.detach_with_id, filter_html_code)
385
+ else
386
+ grid.output_buffer << content_tag(:th, filter_html_code, opts)
387
+ end
388
+ else
389
+ if reuse_last_column_for_filter_buttons && last
390
+ grid.output_buffer << content_tag(:th,
391
+ reset_submit_buttons(options, grid, rendering),
392
+ Wice::WgHash.add_or_append_class_value!(opts, 'filter_icons')
393
+ )
394
+ else
395
+ grid.output_buffer << content_tag(:th, '', opts)
396
+ end
397
+ end
398
+ end
399
+ unless no_rightmost_column
400
+ grid.output_buffer << content_tag(:th, reset_submit_buttons(options, grid, rendering), class: 'filter_icons')
401
+ end
402
+ grid.output_buffer << '</tr>'
403
+ end
404
+ end
405
+
406
+ grid.output_buffer << '</thead><tfoot>'
407
+ grid.output_buffer << rendering.pagination_panel(number_of_columns, options[:hide_csv_button]) do
408
+ if pagination_panel_content_html
409
+ pagination_panel_content_html
410
+ else
411
+ pagination_panel_content_html =
412
+ pagination_panel_content(grid, options[:extra_request_parameters], options[:allow_showing_all_records], options[:pagination_theme])
413
+ pagination_panel_content_html
414
+ end
415
+ end
416
+
417
+ grid.output_buffer << '</tfoot><tbody>'
418
+
419
+ # rendering rows
420
+ cell_value_of_the_ordered_column = nil
421
+ previous_cell_value_of_the_ordered_column = nil
422
+
423
+ grid.each do |ar| # rows
424
+ before_row_output = if rendering.before_row_handler
425
+ call_block(rendering.before_row_handler, ar, number_of_columns_for_extra_rows)
426
+ end
427
+
428
+ after_row_output = if rendering.after_row_handler
429
+ call_block(rendering.after_row_handler, ar, number_of_columns_for_extra_rows)
430
+ end
431
+
432
+ replace_row_output = if rendering.replace_row_handler
433
+ call_block(rendering.replace_row_handler, ar, number_of_columns_for_extra_rows)
434
+ end
435
+
436
+ row_content = if replace_row_output
437
+ no_rightmost_column = true
438
+ replace_row_output
439
+ else
440
+ row_content, tmp_cell_value_of_the_ordered_column = get_row_content(rendering, ar, sorting_dependant_row_cycling)
441
+ cell_value_of_the_ordered_column = tmp_cell_value_of_the_ordered_column if tmp_cell_value_of_the_ordered_column
442
+ row_content
443
+ end
444
+
445
+ row_attributes = rendering.get_row_attributes(ar)
446
+
447
+ if sorting_dependant_row_cycling
448
+ cycle_class = cycle('odd', 'even', name: grid.name) if cell_value_of_the_ordered_column != previous_cell_value_of_the_ordered_column
449
+ previous_cell_value_of_the_ordered_column = cell_value_of_the_ordered_column
450
+ else
451
+ cycle_class = cycle('odd', 'even', name: grid.name)
452
+ end
453
+
454
+ Wice::WgHash.add_or_append_class_value!(row_attributes, cycle_class)
455
+
456
+ grid.output_buffer << before_row_output if before_row_output
457
+ grid.output_buffer << "<tr #{public_tag_options(row_attributes)}>#{row_content}"
458
+ grid.output_buffer << content_tag(:td, '') unless no_rightmost_column
459
+ grid.output_buffer << '</tr>'
460
+ grid.output_buffer << after_row_output if after_row_output
461
+ end
462
+
463
+ last_row_output = if rendering.last_row_handler
464
+ call_block(rendering.last_row_handler, number_of_columns_for_extra_rows)
465
+ end
466
+
467
+ grid.output_buffer << last_row_output if last_row_output
468
+
469
+ grid.output_buffer << '</tbody></table>'
470
+
471
+ base_link_for_filter, base_link_for_show_all_records = rendering.base_link_for_filter(controller, options[:extra_request_parameters])
472
+
473
+ link_for_export = rendering.link_for_export(controller, 'csv', options[:extra_request_parameters])
474
+
475
+ parameter_name_for_query_loading = { grid.name => { q: '' } }.to_query
476
+ parameter_name_for_focus = { grid.name => { foc: '' } }.to_query
477
+
478
+ processor_initializer_arguments = [
479
+ base_link_for_filter,
480
+ base_link_for_show_all_records,
481
+ link_for_export,
482
+ parameter_name_for_query_loading,
483
+ parameter_name_for_focus,
484
+ Rails.env
485
+ ]
486
+
487
+ filter_declarations = if no_filters_at_all
488
+ []
489
+ else
490
+ rendering.select_for(:in_html) do |vc|
491
+ vc.attribute && vc.filter
492
+ end.collect(&:yield_declaration)
493
+ end
494
+
495
+ wg_data = {
496
+ 'data-processor-initializer-arguments' => processor_initializer_arguments.to_json,
497
+ 'data-filter-declarations' => filter_declarations.to_json,
498
+ :class => 'wg-data'
499
+ }
500
+
501
+ wg_data['data-foc'] = grid.status['foc'] if grid.status['foc']
502
+
503
+ grid.output_buffer << content_tag(:div, '', wg_data)
504
+
505
+ grid.output_buffer << '</div>'
506
+
507
+ if Rails.env.development?
508
+ grid.output_buffer << javascript_tag(%/ document.ready = function(){ \n/ +
509
+ %$ if (typeof(WiceGridProcessor) == "undefined"){\n$ +
510
+ %$ alert("wice_grid.js not loaded, WiceGrid cannot proceed!\\n" +\n$ +
511
+ %( "Make sure that you have loaded wice_grid.js.\\n" + ) +
512
+ %( "Add line //= require wice_grid.js " + ) +
513
+ %$ "to app/assets/javascripts/application.js")\n$ +
514
+ %( } ) +
515
+ %$ } $)
516
+ end
517
+
518
+ grid.output_buffer
519
+ end
520
+
521
+ def hide_show_icon(_filter_row_id, _grid, filter_shown, no_filter_row, show_filters, _rendering) #:nodoc:
522
+ no_filter_opening_closing_icon = (show_filters == :always) || no_filter_row
523
+
524
+ styles = ['display: block;', 'display: none;']
525
+ styles.reverse! unless filter_shown
526
+
527
+ if no_filter_opening_closing_icon
528
+ ''
529
+ else
530
+
531
+ content_tag(:div, content_tag(:i, '', class: 'fa fa-eye-slash'),
532
+ title: NlMessage['hide_filter_tooltip'],
533
+ style: styles[0],
534
+ class: 'clickable wg-hide-filter'
535
+ ) +
536
+
537
+ content_tag(:div, content_tag(:i, '', class: 'fa fa-eye'),
538
+ title: NlMessage['show_filter_tooltip'],
539
+ style: styles[1],
540
+ class: 'clickable wg-show-filter'
541
+ )
542
+
543
+ end
544
+ end
545
+
546
+ def reset_submit_buttons(options, grid, _rendering) #:nodoc:
547
+ if options[:hide_submit_button]
548
+ ''
549
+ else
550
+ content_tag(:div, content_tag(:i, '', class: 'fa fa-filter'),
551
+ title: NlMessage['filter_tooltip'],
552
+ id: grid.name + '_submit_grid_icon',
553
+ class: 'submit clickable'
554
+ )
555
+ end.html_safe + ' ' +
556
+ if options[:hide_reset_button]
557
+ ''
558
+ else
559
+
560
+ content_tag(:div, content_tag(:i, '', class: 'fa fa-table'),
561
+ title: NlMessage['reset_filter_tooltip'],
562
+ id: grid.name + '_reset_grid_icon',
563
+ class: 'reset clickable'
564
+ )
565
+ end.html_safe
566
+ end
567
+
568
+ # Renders a detached filter. The parameters are:
569
+ # * +grid+ the WiceGrid object
570
+ # * +filter_key+ an identifier of the filter specified in the column declaration by parameter +:detach_with_id+
571
+ def grid_filter(grid, filter_key)
572
+ unless grid.is_a? WiceGrid
573
+ raise WiceGridArgumentError.new('grid_filter: the parameter must be a WiceGrid instance.')
574
+ end
575
+ if grid.output_buffer.nil?
576
+ raise WiceGridArgumentError.new("grid_filter: You have attempted to run 'grid_filter' before 'grid'. Read about detached filters in the documentation.")
577
+ end
578
+ if grid.output_buffer == true
579
+ raise WiceGridArgumentError.new('grid_filter: You have defined no detached filters, or you try use detached filters with' \
580
+ ':show_filters => :no (set :show_filters to :always in this case). Read about detached filters in the documentation.')
581
+ end
582
+
583
+ content_tag :span,
584
+ grid.output_buffer.filter_for(filter_key),
585
+ class: "wg-detached-filter #{grid.name}_detached_filter",
586
+ 'data-grid-name' => grid.name
587
+ end
588
+
589
+ def grid_csv(grid, rendering) #:nodoc:
590
+ spreadsheet = ::Wice::Spreadsheet.new(grid.name, grid.csv_field_separator, grid.csv_encoding)
591
+
592
+ # columns
593
+ spreadsheet << rendering.column_labels(:in_csv)
594
+
595
+ # rendering rows
596
+ grid.each do |ar| # rows
597
+ row = []
598
+
599
+ rendering.each_column(:in_csv) do |column|
600
+ cell_block = column.cell_rendering_block
601
+
602
+ column_block_output = call_block(cell_block, ar)
603
+
604
+ if column_block_output.is_a?(Array)
605
+ column_block_output, _additional_opts = column_block_output
606
+ end
607
+
608
+ row << column_block_output
609
+ end
610
+ spreadsheet << row
611
+ end
612
+ grid.csv_tempfile = spreadsheet.tempfile
613
+ end
614
+
615
+ def pagination_panel_content(grid, extra_request_parameters, allow_showing_all_records, pagination_theme) #:nodoc:
616
+ extra_request_parameters = extra_request_parameters.clone
617
+ if grid.saved_query
618
+ extra_request_parameters["#{grid.name}[q]"] = grid.saved_query.id
619
+ end
620
+
621
+ html = pagination_info(grid, allow_showing_all_records)
622
+
623
+ paginate(grid.resultset,
624
+ theme: pagination_theme,
625
+ param_name: "#{grid.name}[page]",
626
+ params: extra_request_parameters,
627
+ inner_window: 4,
628
+ outer_window: 2
629
+ ) +
630
+ (' <div class="pagination_status">' + html + '</div>').html_safe
631
+ end
632
+
633
+ def show_all_link(collection_total_entries, parameters, _grid_name) #:nodoc:
634
+ message = NlMessage['all_queries_warning']
635
+ confirmation = collection_total_entries > Defaults::START_SHOWING_WARNING_FROM ? message : nil
636
+
637
+ html = content_tag(:a, NlMessage['show_all_records_label'],
638
+ href: '#',
639
+ title: NlMessage['show_all_records_tooltip'],
640
+ class: 'wg-show-all-link',
641
+ 'data-grid-state' => parameters.to_json,
642
+ 'data-confim-message' => confirmation
643
+ )
644
+
645
+ [html, '']
646
+ end
647
+
648
+ def back_to_pagination_link(parameters, grid_name) #:nodoc:
649
+ pagination_override_parameter_name = "#{grid_name}[pp]"
650
+ parameters = parameters.reject { |k, _v| k == pagination_override_parameter_name }
651
+
652
+ content_tag(:a, NlMessage['switch_back_to_paginated_mode_label'],
653
+ href: '#',
654
+ title: NlMessage['switch_back_to_paginated_mode_tooltip'],
655
+ class: 'wg-back-to-pagination-link',
656
+ 'data-grid-state' => parameters.to_json
657
+ )
658
+ end
659
+
660
+ def pagination_info(grid, allow_showing_all_records) #:nodoc:
661
+ collection = grid.resultset
662
+
663
+ if grid.all_record_mode?
664
+
665
+ collection_total_entries = collection.length
666
+
667
+ first = 1
668
+ last = collection.size
669
+
670
+ total_pages = 1
671
+
672
+ class << collection
673
+ def current_page
674
+ 1
675
+ end
676
+
677
+ def total_pages
678
+ 1
679
+ end
680
+ end
681
+
682
+ else
683
+ collection_total_entries = collection.total_count
684
+
685
+ first = collection.offset_value + 1
686
+ last = collection.last_page? ? collection.total_count : collection.offset_value + collection.limit_value
687
+
688
+ total_pages = collection.total_pages
689
+ end
690
+
691
+ parameters = grid.get_state_as_parameter_value_pairs
692
+
693
+ if total_pages < 2 && collection.length == 0
694
+ '0'
695
+ else
696
+ parameters << ["#{grid.name}[pp]", collection_total_entries]
697
+
698
+ show_all_records_link = allow_showing_all_records && collection_total_entries > collection.length
699
+
700
+ if show_all_records_link && limit = Wice::ConfigurationProvider.value_for(:SHOW_ALL_ALLOWED_UP_TO, strict: false)
701
+ show_all_records_link = limit > collection_total_entries
702
+ end
703
+
704
+ "#{first}-#{last} / #{collection_total_entries} " +
705
+ if show_all_records_link
706
+ res, _js = show_all_link(collection_total_entries, parameters, grid.name)
707
+ res
708
+ else
709
+ ''
710
+ end
711
+ end +
712
+ if grid.all_record_mode?
713
+ back_to_pagination_link(parameters, grid.name)
714
+ else
715
+ ''
716
+ end
717
+ end
718
+ end
719
+ end