avo 1.4.0.pre.1 → 1.4.4.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

Files changed (347) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +10 -4
  4. data/README.md +5 -4
  5. data/app/components/avo/fields/badge_field/index_component.html.erb +3 -0
  6. data/app/components/avo/fields/badge_field/index_component.rb +4 -0
  7. data/app/components/avo/fields/badge_field/show_component.html.erb +3 -0
  8. data/app/components/avo/fields/badge_field/show_component.rb +4 -0
  9. data/app/components/avo/{edit/fields/belongs_to_field_component.html.erb → fields/belongs_to_field/edit_component.html.erb} +0 -0
  10. data/app/components/avo/{edit/fields/belongs_to_field_component.rb → fields/belongs_to_field/edit_component.rb} +1 -1
  11. data/app/components/avo/{index/fields/belongs_to_field_component.html.erb → fields/belongs_to_field/index_component.html.erb} +0 -0
  12. data/app/components/avo/fields/belongs_to_field/index_component.rb +4 -0
  13. data/app/components/avo/{show/fields/belongs_to_field_component.html.erb → fields/belongs_to_field/show_component.html.erb} +0 -0
  14. data/app/components/avo/fields/belongs_to_field/show_component.rb +4 -0
  15. data/app/components/avo/{edit/fields/boolean_field_component.html.erb → fields/boolean_field/edit_component.html.erb} +0 -0
  16. data/app/components/avo/fields/boolean_field/edit_component.rb +4 -0
  17. data/app/components/avo/fields/boolean_field/index_component.html.erb +3 -0
  18. data/app/components/avo/fields/boolean_field/index_component.rb +4 -0
  19. data/app/components/avo/{show/fields/boolean_field_component.html.erb → fields/boolean_field/show_component.html.erb} +1 -1
  20. data/app/components/avo/fields/boolean_field/show_component.rb +4 -0
  21. data/app/components/avo/{edit/fields/boolean_group_field_component.html.erb → fields/boolean_group_field/edit_component.html.erb} +0 -0
  22. data/app/components/avo/fields/boolean_group_field/edit_component.rb +4 -0
  23. data/app/components/avo/fields/boolean_group_field/index_component.html.erb +3 -0
  24. data/app/components/avo/fields/boolean_group_field/index_component.rb +4 -0
  25. data/app/components/avo/fields/boolean_group_field/show_component.html.erb +3 -0
  26. data/app/components/avo/fields/boolean_group_field/show_component.rb +4 -0
  27. data/app/components/avo/{edit/fields/code_field_component.html.erb → fields/code_field/edit_component.html.erb} +0 -0
  28. data/app/components/avo/fields/code_field/edit_component.rb +4 -0
  29. data/app/components/avo/{show/fields/code_field_component.html.erb → fields/code_field/show_component.html.erb} +0 -0
  30. data/app/components/avo/fields/code_field/show_component.rb +4 -0
  31. data/app/components/avo/{common → fields/common}/badge_viewer_component.html.erb +0 -0
  32. data/app/components/avo/{common → fields/common}/badge_viewer_component.rb +1 -1
  33. data/app/components/avo/{common → fields/common}/boolean_check_component.html.erb +0 -0
  34. data/app/components/avo/{common → fields/common}/boolean_check_component.rb +1 -1
  35. data/app/components/avo/{common → fields/common}/boolean_group_component.html.erb +1 -1
  36. data/app/components/avo/{common → fields/common}/boolean_group_component.rb +1 -1
  37. data/app/components/avo/fields/common/files_list_viewer_component.html.erb +5 -0
  38. data/app/components/avo/{common → fields/common}/files_list_viewer_component.rb +1 -1
  39. data/app/components/avo/{common → fields/common}/gravatar_viewer_component.html.erb +0 -0
  40. data/app/components/avo/{common → fields/common}/gravatar_viewer_component.rb +1 -1
  41. data/app/components/avo/{common → fields/common}/heading_component.html.erb +0 -0
  42. data/app/components/avo/{common → fields/common}/heading_component.rb +1 -1
  43. data/app/components/avo/{common → fields/common}/key_value_component.html.erb +0 -0
  44. data/app/components/avo/{common → fields/common}/key_value_component.rb +1 -1
  45. data/app/components/avo/{common → fields/common}/multiple_file_viewer_component.html.erb +0 -0
  46. data/app/components/avo/{common → fields/common}/multiple_file_viewer_component.rb +1 -1
  47. data/app/components/avo/{common → fields/common}/single_file_viewer_component.html.erb +0 -0
  48. data/app/components/avo/{common → fields/common}/single_file_viewer_component.rb +1 -1
  49. data/app/components/avo/fields/common/status_viewer_component.html.erb +18 -0
  50. data/app/components/avo/{common → fields/common}/status_viewer_component.rb +1 -1
  51. data/app/components/avo/{edit/fields/country_field_component.html.erb → fields/country_field/edit_component.html.erb} +0 -0
  52. data/app/components/avo/fields/country_field/edit_component.rb +4 -0
  53. data/app/components/avo/{index/fields/country_field_component.html.erb → fields/country_field/index_component.html.erb} +0 -0
  54. data/app/components/avo/fields/country_field/index_component.rb +4 -0
  55. data/app/components/avo/{show/fields/country_field_component.html.erb → fields/country_field/show_component.html.erb} +0 -0
  56. data/app/components/avo/fields/country_field/show_component.rb +4 -0
  57. data/app/components/avo/{edit/fields/date_field_component.html.erb → fields/date_field/edit_component.html.erb} +0 -0
  58. data/app/components/avo/fields/date_field/edit_component.rb +4 -0
  59. data/app/components/avo/{index/fields/date_field_component.html.erb → fields/date_field/index_component.html.erb} +0 -0
  60. data/app/components/avo/fields/date_field/index_component.rb +4 -0
  61. data/app/components/avo/{show/fields/date_field_component.html.erb → fields/date_field/show_component.html.erb} +0 -0
  62. data/app/components/avo/fields/date_field/show_component.rb +4 -0
  63. data/app/components/avo/{edit/fields/date_time_field_component.html.erb → fields/date_time_field/edit_component.html.erb} +0 -0
  64. data/app/components/avo/fields/date_time_field/edit_component.rb +4 -0
  65. data/app/components/avo/{index/fields/date_time_field_component.html.erb → fields/date_time_field/index_component.html.erb} +0 -0
  66. data/app/components/avo/fields/date_time_field/index_component.rb +4 -0
  67. data/app/components/avo/{show/fields/date_time_field_component.html.erb → fields/date_time_field/show_component.html.erb} +0 -0
  68. data/app/components/avo/fields/date_time_field/show_component.rb +4 -0
  69. data/app/components/avo/{edit/fields/field_component.rb → fields/edit_component.rb} +1 -1
  70. data/app/components/avo/{edit/fields/external_image_field_component.html.erb → fields/external_image_field/edit_component.html.erb} +0 -0
  71. data/app/components/avo/fields/external_image_field/edit_component.rb +4 -0
  72. data/app/components/avo/{index/fields/external_image_field_component.html.erb → fields/external_image_field/index_component.html.erb} +0 -0
  73. data/app/components/avo/fields/external_image_field/index_component.rb +4 -0
  74. data/app/components/avo/{show/fields/external_image_field_component.html.erb → fields/external_image_field/show_component.html.erb} +0 -0
  75. data/app/components/avo/fields/external_image_field/show_component.rb +4 -0
  76. data/app/components/avo/{edit/fields/file_field_component.html.erb → fields/file_field/edit_component.html.erb} +1 -1
  77. data/app/components/avo/fields/file_field/edit_component.rb +4 -0
  78. data/app/components/avo/{index/fields/file_field_component.html.erb → fields/file_field/index_component.html.erb} +1 -1
  79. data/app/components/avo/fields/file_field/index_component.rb +4 -0
  80. data/app/components/avo/fields/file_field/show_component.html.erb +3 -0
  81. data/app/components/avo/fields/file_field/show_component.rb +4 -0
  82. data/app/components/avo/{edit/fields/files_field_component.html.erb → fields/files_field/edit_component.html.erb} +1 -1
  83. data/app/components/avo/fields/files_field/edit_component.rb +4 -0
  84. data/app/components/avo/{index/fields/files_field_component.html.erb → fields/files_field/index_component.html.erb} +0 -0
  85. data/app/components/avo/fields/files_field/index_component.rb +4 -0
  86. data/app/components/avo/fields/files_field/show_component.html.erb +3 -0
  87. data/app/components/avo/fields/files_field/show_component.rb +4 -0
  88. data/app/components/avo/{index/fields/gravatar_field_component.html.erb → fields/gravatar_field/index_component.html.erb} +2 -2
  89. data/app/components/avo/fields/gravatar_field/index_component.rb +4 -0
  90. data/app/components/avo/{show/fields/gravatar_field_component.html.erb → fields/gravatar_field/show_component.html.erb} +1 -1
  91. data/app/components/avo/fields/gravatar_field/show_component.rb +4 -0
  92. data/app/components/avo/{show/fields/has_many_field_component.html.erb → fields/has_many_field/show_component.html.erb} +0 -0
  93. data/app/components/avo/fields/has_many_field/show_component.rb +4 -0
  94. data/app/components/avo/{index/fields/has_one_field_component.html.erb → fields/has_one_field/index_component.html.erb} +0 -0
  95. data/app/components/avo/fields/has_one_field/index_component.rb +4 -0
  96. data/app/components/avo/{show/fields/has_one_field_component.html.erb → fields/has_one_field/show_component.html.erb} +0 -0
  97. data/app/components/avo/fields/has_one_field/show_component.rb +5 -0
  98. data/app/components/avo/{show/fields/heading_field_component.html.erb → fields/heading_field/edit_component.html.erb} +1 -1
  99. data/app/components/avo/fields/heading_field/edit_component.rb +4 -0
  100. data/app/components/avo/{edit/fields/heading_field_component.html.erb → fields/heading_field/show_component.html.erb} +1 -1
  101. data/app/components/avo/fields/heading_field/show_component.rb +4 -0
  102. data/app/components/avo/{edit/fields/hidden_field_component.html.erb → fields/hidden_field/edit_component.html.erb} +0 -0
  103. data/app/components/avo/fields/hidden_field/edit_component.rb +4 -0
  104. data/app/components/avo/{edit/fields/id_field_component.html.erb → fields/id_field/edit_component.html.erb} +0 -0
  105. data/app/components/avo/fields/id_field/edit_component.rb +4 -0
  106. data/app/components/avo/fields/id_field/index_component.html.erb +3 -0
  107. data/app/components/avo/fields/id_field/index_component.rb +4 -0
  108. data/app/components/avo/{show/fields/id_field_component.html.erb → fields/id_field/show_component.html.erb} +0 -0
  109. data/app/components/avo/fields/id_field/show_component.rb +4 -0
  110. data/app/components/avo/fields/index_component.rb +20 -0
  111. data/app/components/avo/{edit/fields/key_value_field_component.html.erb → fields/key_value_field/edit_component.html.erb} +1 -1
  112. data/app/components/avo/fields/key_value_field/edit_component.rb +4 -0
  113. data/app/components/avo/{show/fields/key_value_field_component.html.erb → fields/key_value_field/show_component.html.erb} +1 -1
  114. data/app/components/avo/fields/key_value_field/show_component.rb +4 -0
  115. data/app/components/avo/{edit/fields/markdown_field_component.html.erb → fields/markdown_field/edit_component.html.erb} +0 -0
  116. data/app/components/avo/fields/markdown_field/edit_component.rb +4 -0
  117. data/app/components/avo/{show/fields/markdown_field_component.html.erb → fields/markdown_field/show_component.html.erb} +1 -1
  118. data/app/components/avo/fields/markdown_field/show_component.rb +4 -0
  119. data/app/components/avo/{edit/fields/number_field_component.html.erb → fields/number_field/edit_component.html.erb} +3 -3
  120. data/app/components/avo/fields/number_field/edit_component.rb +4 -0
  121. data/app/components/avo/{index/fields/number_field_component.html.erb → fields/number_field/index_component.html.erb} +0 -0
  122. data/app/components/avo/fields/number_field/index_component.rb +4 -0
  123. data/app/components/avo/{show/fields/number_field_component.html.erb → fields/number_field/show_component.html.erb} +0 -0
  124. data/app/components/avo/fields/number_field/show_component.rb +4 -0
  125. data/app/components/avo/{edit/fields/password_field_component.html.erb → fields/password_field/edit_component.html.erb} +0 -0
  126. data/app/components/avo/fields/password_field/edit_component.rb +4 -0
  127. data/app/components/avo/fields/progress_bar_field/edit_component.html.erb +26 -0
  128. data/app/components/avo/fields/progress_bar_field/edit_component.rb +4 -0
  129. data/app/components/avo/fields/progress_bar_field/index_component.html.erb +8 -0
  130. data/app/components/avo/fields/progress_bar_field/index_component.rb +4 -0
  131. data/app/components/avo/fields/progress_bar_field/show_component.html.erb +8 -0
  132. data/app/components/avo/fields/progress_bar_field/show_component.rb +4 -0
  133. data/app/components/avo/{edit/fields/select_field_component.html.erb → fields/select_field/edit_component.html.erb} +0 -0
  134. data/app/components/avo/fields/select_field/edit_component.rb +4 -0
  135. data/app/components/avo/{index/fields/select_field_component.html.erb → fields/select_field/index_component.html.erb} +0 -0
  136. data/app/components/avo/fields/select_field/index_component.rb +4 -0
  137. data/app/components/avo/{show/fields/select_field_component.html.erb → fields/select_field/show_component.html.erb} +0 -0
  138. data/app/components/avo/fields/select_field/show_component.rb +4 -0
  139. data/app/components/avo/{show/fields/field_component.rb → fields/show_component.rb} +1 -1
  140. data/app/components/avo/{edit/fields/status_field_component.html.erb → fields/status_field/edit_component.html.erb} +0 -0
  141. data/app/components/avo/fields/status_field/edit_component.rb +4 -0
  142. data/app/components/avo/fields/status_field/index_component.html.erb +3 -0
  143. data/app/components/avo/fields/status_field/index_component.rb +4 -0
  144. data/app/components/avo/fields/status_field/show_component.html.erb +3 -0
  145. data/app/components/avo/fields/status_field/show_component.rb +4 -0
  146. data/app/components/avo/{edit/fields/text_field_component.html.erb → fields/text_field/edit_component.html.erb} +0 -0
  147. data/app/components/avo/fields/text_field/edit_component.rb +4 -0
  148. data/app/components/avo/fields/text_field/index_component.html.erb +3 -0
  149. data/app/components/avo/fields/text_field/index_component.rb +4 -0
  150. data/app/components/avo/{show/fields/text_field_component.html.erb → fields/text_field/show_component.html.erb} +0 -0
  151. data/app/components/avo/fields/text_field/show_component.rb +4 -0
  152. data/app/components/avo/{edit/fields/textarea_field_component.html.erb → fields/textarea_field/edit_component.html.erb} +1 -1
  153. data/app/components/avo/fields/textarea_field/edit_component.rb +4 -0
  154. data/app/components/avo/{show/fields/textarea_field_component.html.erb → fields/textarea_field/show_component.html.erb} +0 -0
  155. data/app/components/avo/fields/textarea_field/show_component.rb +4 -0
  156. data/app/components/avo/{edit/fields/trix_field_component.html.erb → fields/trix_field/edit_component.html.erb} +1 -2
  157. data/app/components/avo/fields/trix_field/edit_component.rb +4 -0
  158. data/app/components/avo/{show/fields/trix_field_component.html.erb → fields/trix_field/show_component.html.erb} +0 -0
  159. data/app/components/avo/fields/trix_field/show_component.rb +4 -0
  160. data/app/components/avo/index/resource_controls_component.html.erb +2 -3
  161. data/app/components/avo/index/table_row_component.html.erb +1 -1
  162. data/app/components/avo/panel_component.html.erb +1 -1
  163. data/app/components/avo/panel_component.rb +4 -4
  164. data/app/components/avo/views/resource_edit_component.html.erb +2 -2
  165. data/app/components/avo/views/resource_index_component.html.erb +6 -6
  166. data/app/components/avo/views/resource_new_component.html.erb +2 -2
  167. data/app/components/avo/views/resource_show_component.html.erb +5 -5
  168. data/app/controllers/avo/application_controller.rb +14 -7
  169. data/app/controllers/avo/base_controller.rb +26 -2
  170. data/app/controllers/avo/home_controller.rb +1 -1
  171. data/app/controllers/avo/relations_controller.rb +1 -1
  172. data/app/controllers/avo/search_controller.rb +50 -35
  173. data/app/helpers/avo/resources_helper.rb +0 -44
  174. data/app/packs/entrypoints/application.css +3 -1
  175. data/app/packs/entrypoints/application.js +3 -0
  176. data/app/packs/js/controllers/fields/key_value_controller.js +0 -1
  177. data/app/packs/js/controllers/search_controller.js +120 -0
  178. data/app/packs/js/helpers/debounce_promise.js +13 -0
  179. data/app/packs/stylesheets/components/progress.css +13 -0
  180. data/app/packs/stylesheets/components/status.css +31 -20
  181. data/app/packs/stylesheets/search.css +79 -0
  182. data/app/packs/svgs/check-circle-sm.svg +3 -0
  183. data/app/packs/svgs/x-circle-sm.svg +3 -0
  184. data/app/views/avo/actions/show.html.erb +1 -1
  185. data/app/views/avo/partials/_global_search.html.erb +17 -0
  186. data/app/views/avo/partials/_profile_dropdown.html.erb +19 -0
  187. data/app/views/avo/partials/_resource_search.html.erb +10 -0
  188. data/app/views/layouts/avo/application.html.erb +7 -6
  189. data/avo.gemspec +2 -1
  190. data/config/routes.rb +2 -6
  191. data/db/factories.rb +3 -0
  192. data/db/migrate/20210421064037_add_color_to_teams.rb +5 -0
  193. data/db/migrate/20210423075924_add_progress_to_projects.rb +5 -0
  194. data/lib/avo/app.rb +12 -21
  195. data/lib/avo/base_resource.rb +91 -7
  196. data/lib/avo/configuration.rb +3 -1
  197. data/lib/avo/engine.rb +1 -0
  198. data/lib/avo/fields/badge_field.rb +4 -6
  199. data/lib/avo/fields/base_field.rb +68 -83
  200. data/lib/avo/fields/belongs_to_field.rb +11 -11
  201. data/lib/avo/fields/boolean_field.rb +2 -7
  202. data/lib/avo/fields/boolean_group_field.rb +2 -7
  203. data/lib/avo/fields/code_field.rb +3 -7
  204. data/lib/avo/fields/country_field.rb +3 -6
  205. data/lib/avo/fields/currency_field.rb +4 -13
  206. data/lib/avo/fields/date_field.rb +2 -8
  207. data/lib/avo/fields/date_time_field.rb +2 -3
  208. data/lib/avo/fields/external_image_field.rb +3 -7
  209. data/lib/avo/fields/file_field.rb +8 -8
  210. data/lib/avo/fields/files_field.rb +6 -8
  211. data/lib/avo/fields/gravatar_field.rb +6 -9
  212. data/lib/avo/fields/has_and_belongs_to_many_field.rb +6 -7
  213. data/lib/avo/fields/has_many_field.rb +3 -9
  214. data/lib/avo/fields/has_one_field.rb +3 -8
  215. data/lib/avo/fields/heading_field.rb +10 -8
  216. data/lib/avo/fields/hidden_field.rb +2 -6
  217. data/lib/avo/fields/id_field.rb +5 -17
  218. data/lib/avo/fields/key_value_field.rb +4 -6
  219. data/lib/avo/fields/markdown_field.rb +3 -5
  220. data/lib/avo/fields/number_field.rb +8 -11
  221. data/lib/avo/fields/password_field.rb +2 -6
  222. data/lib/avo/fields/progress_bar_field.rb +19 -0
  223. data/lib/avo/fields/select_field.rb +13 -12
  224. data/lib/avo/fields/status_field.rb +2 -6
  225. data/lib/avo/fields/text_field.rb +3 -6
  226. data/lib/avo/fields/textarea_field.rb +4 -7
  227. data/lib/avo/fields/trix_field.rb +5 -9
  228. data/lib/avo/fields_collector.rb +47 -11
  229. data/lib/avo/licensing/license.rb +10 -0
  230. data/lib/avo/licensing/pro_license.rb +4 -1
  231. data/lib/avo/services/authorization_service.rb +1 -1
  232. data/lib/avo/version.rb +1 -1
  233. data/lib/generators/avo/eject_generator.rb +1 -0
  234. data/lib/generators/avo/field_generator.rb +17 -0
  235. data/lib/generators/avo/filter_generator.rb +1 -1
  236. data/lib/generators/avo/templates/field/%singular_name%_field.rb.tt +5 -0
  237. data/lib/generators/avo/templates/field/components/edit_component.html.erb.tt +6 -0
  238. data/lib/generators/avo/templates/field/components/edit_component.rb.tt +4 -0
  239. data/lib/generators/avo/templates/field/components/index_component.html.erb.tt +3 -0
  240. data/lib/generators/avo/templates/field/components/index_component.rb.tt +4 -0
  241. data/lib/generators/avo/templates/field/components/show_component.html.erb.tt +3 -0
  242. data/lib/generators/avo/templates/field/components/show_component.rb.tt +4 -0
  243. data/lib/generators/avo/templates/initializer/avo.tt +1 -0
  244. data/lib/generators/avo/templates/resource/resource.tt +3 -0
  245. data/lib/generators/avo/templates/tool/view.tt +1 -1
  246. data/public/avo-packs/css/{application-5bdca030.css → application-d69fe930.css} +303 -50
  247. data/public/avo-packs/css/application-d69fe930.css.br +0 -0
  248. data/public/avo-packs/css/application-d69fe930.css.gz +0 -0
  249. data/public/avo-packs/css/application-d69fe930.css.map +1 -0
  250. data/public/avo-packs/css/application-d69fe930.css.map.br +0 -0
  251. data/public/avo-packs/css/application-d69fe930.css.map.gz +0 -0
  252. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js +26 -0
  253. data/public/avo-packs/js/{application-16a456a2b7cb56b01153.js.LICENSE.txt → application-7b3d507875f4bc1f6677.js.LICENSE.txt} +0 -0
  254. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.br +0 -0
  255. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.gz +0 -0
  256. data/public/avo-packs/js/{application-16a456a2b7cb56b01153.js.map → application-7b3d507875f4bc1f6677.js.map} +1 -1
  257. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.map.br +0 -0
  258. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.map.gz +0 -0
  259. data/public/avo-packs/manifest.json +15 -15
  260. metadata +206 -173
  261. data/app/components/avo/common/files_list_viewer_component.html.erb +0 -5
  262. data/app/components/avo/common/status_viewer_component.html.erb +0 -10
  263. data/app/components/avo/edit/fields/boolean_field_component.rb +0 -4
  264. data/app/components/avo/edit/fields/boolean_group_field_component.rb +0 -4
  265. data/app/components/avo/edit/fields/code_field_component.rb +0 -4
  266. data/app/components/avo/edit/fields/country_field_component.rb +0 -4
  267. data/app/components/avo/edit/fields/date_field_component.rb +0 -4
  268. data/app/components/avo/edit/fields/date_time_field_component.rb +0 -4
  269. data/app/components/avo/edit/fields/external_image_field_component.rb +0 -4
  270. data/app/components/avo/edit/fields/file_field_component.rb +0 -4
  271. data/app/components/avo/edit/fields/files_field_component.rb +0 -4
  272. data/app/components/avo/edit/fields/heading_field_component.rb +0 -4
  273. data/app/components/avo/edit/fields/hidden_field_component.rb +0 -4
  274. data/app/components/avo/edit/fields/id_field_component.rb +0 -4
  275. data/app/components/avo/edit/fields/key_value_field_component.rb +0 -4
  276. data/app/components/avo/edit/fields/markdown_field_component.rb +0 -4
  277. data/app/components/avo/edit/fields/number_field_component.rb +0 -4
  278. data/app/components/avo/edit/fields/password_field_component.rb +0 -4
  279. data/app/components/avo/edit/fields/select_field_component.rb +0 -4
  280. data/app/components/avo/edit/fields/status_field_component.rb +0 -4
  281. data/app/components/avo/edit/fields/text_field_component.rb +0 -4
  282. data/app/components/avo/edit/fields/textarea_field_component.rb +0 -4
  283. data/app/components/avo/edit/fields/trix_field_component.rb +0 -4
  284. data/app/components/avo/index/fields/badge_field_component.html.erb +0 -3
  285. data/app/components/avo/index/fields/badge_field_component.rb +0 -4
  286. data/app/components/avo/index/fields/belongs_to_field_component.rb +0 -4
  287. data/app/components/avo/index/fields/boolean_field_component.html.erb +0 -3
  288. data/app/components/avo/index/fields/boolean_field_component.rb +0 -4
  289. data/app/components/avo/index/fields/boolean_group_field_component.html.erb +0 -3
  290. data/app/components/avo/index/fields/boolean_group_field_component.rb +0 -4
  291. data/app/components/avo/index/fields/country_field_component.rb +0 -4
  292. data/app/components/avo/index/fields/date_field_component.rb +0 -4
  293. data/app/components/avo/index/fields/date_time_field_component.rb +0 -4
  294. data/app/components/avo/index/fields/external_image_field_component.rb +0 -4
  295. data/app/components/avo/index/fields/field_component.html.erb +0 -1
  296. data/app/components/avo/index/fields/field_component.rb +0 -11
  297. data/app/components/avo/index/fields/file_field_component.rb +0 -4
  298. data/app/components/avo/index/fields/files_field_component.rb +0 -4
  299. data/app/components/avo/index/fields/gravatar_field_component.rb +0 -4
  300. data/app/components/avo/index/fields/has_one_field_component.rb +0 -4
  301. data/app/components/avo/index/fields/id_field_component.html.erb +0 -10
  302. data/app/components/avo/index/fields/id_field_component.rb +0 -4
  303. data/app/components/avo/index/fields/number_field_component.rb +0 -4
  304. data/app/components/avo/index/fields/select_field_component.rb +0 -4
  305. data/app/components/avo/index/fields/status_field_component.html.erb +0 -3
  306. data/app/components/avo/index/fields/status_field_component.rb +0 -4
  307. data/app/components/avo/index/fields/text_field_component.html.erb +0 -3
  308. data/app/components/avo/index/fields/text_field_component.rb +0 -4
  309. data/app/components/avo/show/fields/badge_field_component.html.erb +0 -3
  310. data/app/components/avo/show/fields/badge_field_component.rb +0 -4
  311. data/app/components/avo/show/fields/belongs_to_field_component.rb +0 -4
  312. data/app/components/avo/show/fields/boolean_field_component.rb +0 -4
  313. data/app/components/avo/show/fields/boolean_group_field_component.html.erb +0 -3
  314. data/app/components/avo/show/fields/boolean_group_field_component.rb +0 -4
  315. data/app/components/avo/show/fields/code_field_component.rb +0 -4
  316. data/app/components/avo/show/fields/country_field_component.rb +0 -4
  317. data/app/components/avo/show/fields/date_field_component.rb +0 -4
  318. data/app/components/avo/show/fields/date_time_field_component.rb +0 -4
  319. data/app/components/avo/show/fields/external_image_field_component.rb +0 -4
  320. data/app/components/avo/show/fields/file_field_component.html.erb +0 -3
  321. data/app/components/avo/show/fields/file_field_component.rb +0 -4
  322. data/app/components/avo/show/fields/files_field_component.html.erb +0 -3
  323. data/app/components/avo/show/fields/files_field_component.rb +0 -4
  324. data/app/components/avo/show/fields/gravatar_field_component.rb +0 -4
  325. data/app/components/avo/show/fields/has_many_field_component.rb +0 -4
  326. data/app/components/avo/show/fields/has_one_field_component.rb +0 -5
  327. data/app/components/avo/show/fields/heading_field_component.rb +0 -4
  328. data/app/components/avo/show/fields/id_field_component.rb +0 -4
  329. data/app/components/avo/show/fields/key_value_field_component.rb +0 -4
  330. data/app/components/avo/show/fields/markdown_field_component.rb +0 -4
  331. data/app/components/avo/show/fields/number_field_component.rb +0 -4
  332. data/app/components/avo/show/fields/select_field_component.rb +0 -4
  333. data/app/components/avo/show/fields/status_field_component.html.erb +0 -3
  334. data/app/components/avo/show/fields/status_field_component.rb +0 -4
  335. data/app/components/avo/show/fields/text_field_component.rb +0 -4
  336. data/app/components/avo/show/fields/textarea_field_component.rb +0 -4
  337. data/app/components/avo/show/fields/trix_field_component.rb +0 -4
  338. data/public/avo-packs/css/application-5bdca030.css.br +0 -0
  339. data/public/avo-packs/css/application-5bdca030.css.gz +0 -0
  340. data/public/avo-packs/css/application-5bdca030.css.map +0 -1
  341. data/public/avo-packs/css/application-5bdca030.css.map.br +0 -0
  342. data/public/avo-packs/css/application-5bdca030.css.map.gz +0 -0
  343. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js +0 -26
  344. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js.br +0 -0
  345. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js.gz +0 -0
  346. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js.map.br +0 -0
  347. data/public/avo-packs/js/application-16a456a2b7cb56b01153.js.map.gz +0 -0
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::SelectField::IndexComponent < Avo::Fields::IndexComponent
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::SelectField::ShowComponent < Avo::Fields::ShowComponent
4
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Avo::Show::Fields::FieldComponent < ViewComponent::Base
3
+ class Avo::Fields::ShowComponent < ViewComponent::Base
4
4
  include Avo::ResourcesHelper
5
5
 
6
6
  def initialize(field: nil, resource: nil, index: 0)
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::StatusField::EditComponent < Avo::Fields::EditComponent
4
+ end
@@ -0,0 +1,3 @@
1
+ <%= index_field_wrapper field: @field do %>
2
+ <%= render Avo::Fields::Common::StatusViewerComponent.new label: @field.value, status: @field.status %>
3
+ <% end %>
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::StatusField::IndexComponent < Avo::Fields::IndexComponent
4
+ end
@@ -0,0 +1,3 @@
1
+ <%= show_field_wrapper field: @field, index: @index do %>
2
+ <%= render Avo::Fields::Common::StatusViewerComponent.new label: @field.value, status: @field.status %>
3
+ <% end %>
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::StatusField::ShowComponent < Avo::Fields::ShowComponent
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::TextField::EditComponent < Avo::Fields::EditComponent
4
+ end
@@ -0,0 +1,3 @@
1
+ <%= index_field_wrapper field: @field do %>
2
+ <%= link_to_if @field.link_to_resource, @field.value, resource_path %>
3
+ <% end %>
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::TextField::IndexComponent < Avo::Fields::IndexComponent
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::TextField::ShowComponent < Avo::Fields::ShowComponent
4
+ end
@@ -3,5 +3,5 @@
3
3
  class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
4
4
  placeholder: @field.placeholder,
5
5
  disabled: @field.readonly,
6
- rows: @field.meta[:rows] %>
6
+ rows: @field.rows %>
7
7
  <% end %>
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::TextareaField::EditComponent < Avo::Fields::EditComponent
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::TextareaField::ShowComponent < Avo::Fields::ShowComponent
4
+ end
@@ -13,8 +13,7 @@
13
13
  id: trix_id,
14
14
  class: helpers.input_classes('w-full hidden', has_error: (@resource.model.present? and @resource.model.errors.include?(@field.id))),
15
15
  placeholder: @field.placeholder,
16
- disabled: @field.readonly,
17
- rows: @field.meta[:rows]
16
+ disabled: @field.readonly
18
17
  %>
19
18
  </div>
20
19
  <% end %>
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::TrixField::EditComponent < Avo::Fields::EditComponent
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::Fields::TrixField::ShowComponent < Avo::Fields::ShowComponent
4
+ end
@@ -36,9 +36,8 @@
36
36
  'tippy': 'tooltip',
37
37
  }
38
38
  %>
39
- <%= hidden_field_tag :turbo_frame, params[:turbo_frame], id: "turbo_frame_destroy_#{@resource.model.id}" if params[:turbo_frame] %>
40
- <%= hidden_field_tag :referrer, request.fullpath, id: "referrer_destroy_#{@resource.model.id}" if params[:turbo_frame] %>
41
- <%#= hidden_field_tag :referrer, request.fullpath, id: "referrer_detach_#{@resource.model.id}" if params[:via_resource_class] %>
39
+ <%= hidden_field_tag :turbo_frame, params[:turbo_frame], id: "turbo_frame_detach_#{@resource.model.id}" if params[:turbo_frame] %>
40
+ <%= hidden_field_tag :referrer, request.fullpath, id: "referrer_detach_#{@resource.model.id}" if params[:turbo_frame] %>
42
41
  <% end %>
43
42
  <% end %>
44
43
 
@@ -8,7 +8,7 @@
8
8
  </div>
9
9
  </td>
10
10
  <% @resource.get_fields(reflection: @reflection).each_with_index do |field, index| %>
11
- <%= index_field field, index, @resource %>
11
+ <%= render field.component_for_view(:index).new(field: field, resource: @resource, index: index, parent_model: @parent_model) %>
12
12
  <% end %>
13
13
  <td class="text-right whitespace-nowrap px-2">
14
14
  <div class="flex items-center justify-end flex-grow-0 h-full w-full">
@@ -1,7 +1,7 @@
1
1
  <div <%== data_attributes %>>
2
2
  <div class="mb-6">
3
3
  <div>
4
- <% if show_breadcrumbs? %>
4
+ <% if display_breadcrumbs? %>
5
5
  <div class="breadcrumbs">
6
6
  <%= helpers.render_breadcrumbs(separator: helpers.svg('chevron-right', class: 'inline-block h-3 stroke-current relative top-[-1px] ml-1' )) if Avo.configuration.display_breadcrumbs %>
7
7
  </div>
@@ -6,11 +6,11 @@ class Avo::PanelComponent < ViewComponent::Base
6
6
  renders_one :bare_content
7
7
  renders_one :footer
8
8
 
9
- def initialize(title: nil, body_classes: nil, data: {}, show_breadcrumbs: true)
9
+ def initialize(title: nil, body_classes: nil, data: {}, display_breadcrumbs: false)
10
10
  @title = title
11
11
  @body_classes = body_classes
12
12
  @data = data
13
- @show_breadcrumbs = show_breadcrumbs
13
+ @display_breadcrumbs = display_breadcrumbs
14
14
  end
15
15
 
16
16
  private
@@ -23,7 +23,7 @@ class Avo::PanelComponent < ViewComponent::Base
23
23
  end.join
24
24
  end
25
25
 
26
- def show_breadcrumbs?
27
- @show_breadcrumbs
26
+ def display_breadcrumbs?
27
+ @display_breadcrumbs
28
28
  end
29
29
  end
@@ -3,7 +3,7 @@
3
3
  <%= form_with model: @resource.model, url: helpers.resource_path(@resource.model), method: :put, multipart: true do |form| %>
4
4
  <%= hidden_field_tag :referrer, back_path if params[:via_resource_class] %>
5
5
 
6
- <%= render Avo::PanelComponent.new(title: resource_panel[:name]) do |c| %>
6
+ <%= render Avo::PanelComponent.new(title: resource_panel[:name], display_breadcrumbs: true) do |c| %>
7
7
  <% c.tools do %>
8
8
  <div class="flex justify-end space-x-2">
9
9
  <%= a_link back_path do %>
@@ -20,7 +20,7 @@
20
20
 
21
21
  <% c.body do %>
22
22
  <% @resource.get_fields.each_with_index do |field, index| %>
23
- <%= edit_field field, index, @resource, form unless field.computed %>
23
+ <%= render field.component_for_view(:edit).new(field: field, resource: @resource, index: index, form: form) unless field.computed %>
24
24
  <% end %>
25
25
  <% end %>
26
26
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= render Avo::PanelComponent.new title: title, body_classes: 'py-4', data: { component: 'resources-index' }, show_breadcrumbs: @reflection.blank? do |c| %>
1
+ <%= render Avo::PanelComponent.new(title: title, body_classes: 'py-4', data: { component: 'resources-index' }, display_breadcrumbs: @reflection.blank?) do |c| %>
2
2
  <% c.tools do %>
3
3
  <%= render 'actions' if @actions.present? %>
4
4
 
@@ -22,12 +22,12 @@
22
22
  <% end %>
23
23
 
24
24
  <% c.body do %>
25
- <div class="flex justify-between py-6 min-h-24"
25
+ <div class="flex justify-between pt-2 pb-2 min-h-16"
26
26
  data-selected-resources-name="<%= @resource.plural_name.downcase %>"
27
27
  data-selected-resources="[]"
28
28
  >
29
29
  <div class="flex items-center px-6 w-64">
30
- <%# search %>
30
+ <%= render partial: 'avo/partials/resource_search', locals: {resource: @resource.route_key} if @resource.search_query.present? %>
31
31
  </div>
32
32
  <div class="flex justify-end items-center px-6 space-x-3">
33
33
  <%= render partial: 'avo/partials/view_toggle_button', locals: { available_view_types: available_view_types, view_type: view_type, turbo_frame: @turbo_frame } if @models.present? %>
@@ -36,7 +36,7 @@
36
36
  </div>
37
37
 
38
38
  <% if view_type.to_sym == :table %>
39
- <div class="w-full overflow-auto flex flex-col">
39
+ <div class="w-full overflow-auto flex flex-col mt-4">
40
40
  <div class="relative flex-1 flex">
41
41
  <%= render(Avo::Index::ResourceTableComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_model: @parent_model)) %>
42
42
  </div>
@@ -50,8 +50,8 @@
50
50
  <% end %>
51
51
  <% end %>
52
52
 
53
- <% if view_type.to_sym == :grid %>
54
- <% c.bare_content do %>
53
+ <% c.bare_content do %>
54
+ <% if view_type.to_sym == :grid %>
55
55
  <%= render Avo::Index::ResourceGridComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_model: @parent_model) %>
56
56
 
57
57
  <div class="bg-white rounded-xl shadow-xl mt-8 py-6">
@@ -1,7 +1,7 @@
1
1
  <div>
2
2
  <% @resource.panels.each do |resource_panel| %>
3
3
  <%= form_with model: @resource.model, url: helpers.resources_path(@resource.model, via_relation_class: params[:via_relation_class], via_resource_id: params[:via_resource_id]), local: true, multipart: true do |form| %>
4
- <%= render Avo::PanelComponent.new(title: resource_panel[:name]) do |c| %>
4
+ <%= render Avo::PanelComponent.new(title: resource_panel[:name], display_breadcrumbs: true) do |c| %>
5
5
  <% c.tools do %>
6
6
  <div class="flex justify-end space-x-2">
7
7
  <%= a_link back_path do %>
@@ -16,7 +16,7 @@
16
16
 
17
17
  <% c.body do %>
18
18
  <% @resource.get_fields.each_with_index do |field, index| %>
19
- <%= edit_field field, index, @resource, form unless field.computed %>
19
+ <%= render field.component_for_view(:edit).new(field: field, resource: @resource, index: index, form: form) unless field.computed %>
20
20
  <% end %>
21
21
  <% end %>
22
22
  <% end %>
@@ -3,7 +3,7 @@
3
3
  data-selected-resources="[<%= @resource.model.id %>]"
4
4
  >
5
5
  <% @resource.panels.each do |resource_panel| %>
6
- <%= render Avo::PanelComponent.new(title: resource_panel[:name], show_breadcrumbs: @reflection.blank?) do |c| %>
6
+ <%= render Avo::PanelComponent.new(title: resource_panel[:name], display_breadcrumbs: @reflection.blank?) do |c| %>
7
7
  <% c.tools do %>
8
8
  <% if resource_panel[:name] == @resource.default_panel_name %>
9
9
  <%= render 'actions' %>
@@ -47,7 +47,7 @@
47
47
  <% c.body do %>
48
48
  <% if fields_by_panel[resource_panel[:name]].present? %>
49
49
  <% fields_by_panel[resource_panel[:name]].each_with_index do |field, index| %>
50
- <%= show_field field, index, @resource %>
50
+ <%= render field.component_for_view(:show).new(field: field, resource: @resource, index: index) %>
51
51
  <% end %>
52
52
  <% end %>
53
53
  <% end %>
@@ -57,19 +57,19 @@
57
57
  <% if @reflection.blank? %>
58
58
  <% if has_one_panels.present? %>
59
59
  <% has_one_panels.each_with_index do |field, index| %>
60
- <%= show_field field, index, @resource %>
60
+ <%= render field.component_for_view(:show).new(field: field, resource: @resource, index: index) %>
61
61
  <% end %>
62
62
  <% end %>
63
63
 
64
64
  <% if has_many_panels.present? %>
65
65
  <% has_many_panels.each_with_index do |field, index| %>
66
- <%= show_field field, index, @resource %>
66
+ <%= render field.component_for_view(:show).new(field: field, resource: @resource, index: index) %>
67
67
  <% end %>
68
68
  <% end %>
69
69
 
70
70
  <% if has_as_belongs_to_many_panels.present? %>
71
71
  <% has_as_belongs_to_many_panels.each_with_index do |field, index| %>
72
- <%= show_field field, index, @resource %>
72
+ <%= render field.component_for_view(:show).new(field: field, resource: @resource, index: index) %>
73
73
  <% end %>
74
74
  <% end %>
75
75
  <% end %>
@@ -17,7 +17,7 @@ module Avo
17
17
  add_flash_types :info, :warning, :success, :error
18
18
 
19
19
  def init_app
20
- Avo::App.init request: request, context: context
20
+ Avo::App.init request: request, context: context, current_user: _current_user
21
21
 
22
22
  @license = Avo::App.license
23
23
  end
@@ -38,18 +38,25 @@ module Avo
38
38
  def render(*args)
39
39
  raise Avo::LicenseVerificationTemperedError, "License verification mechanism tempered with." unless method(:check_avo_license).source_location.first.match?(/.*\/app\/controllers\/avo\/application_controller\.rb/)
40
40
 
41
+ if params[:controller] == "avo/search" && params[:action] == "index"
42
+ raise Avo::LicenseVerificationTemperedError, "License verification mechanism tempered with." unless method(:index).source_location.first.match?(/.*\/app\/controllers\/avo\/search_controller\.rb/)
43
+ end
44
+
41
45
  super(*args)
42
46
  end
43
47
 
44
48
  def check_avo_license
49
+ # Check to see if the path is on a custom tool
45
50
  unless on_root_path || on_resources_path || on_api_path
46
- if @license.invalid? || @license.lacks(:custom_tools)
47
- if Rails.env.development?
51
+ # Display alert on custom tool page if in development.
52
+ if @license.lacks(:custom_tools) || @license.invalid?
53
+ if Rails.env.development? || Rails.env.test?
48
54
  @custom_tools_alert_visible = true
49
- else
50
- raise Avo::LicenseInvalidError, "Your license is invalid or doesn't support custom tools."
51
55
  end
52
56
  end
57
+
58
+ # Raise error in non-development environments.
59
+ raise Avo::LicenseInvalidError, "Your license is invalid or doesn't support custom tools." if @license.lacks_with_trial(:custom_tools)
53
60
  end
54
61
  end
55
62
 
@@ -157,9 +164,9 @@ module Avo
157
164
 
158
165
  def authorize_action
159
166
  if @model.present?
160
- @authorization.set_record(@model).authorize_action :index
167
+ @authorization.set_record(@model).authorize_action action_name.to_sym
161
168
  else
162
- @authorization.set_record(@resource.model_class).authorize_action :index
169
+ @authorization.set_record(@resource.model_class).authorize_action action_name.to_sym
163
170
  end
164
171
  end
165
172
 
@@ -53,7 +53,19 @@ module Avo
53
53
  @resource = @resource.hydrate(model: @model, view: :show, user: _current_user, params: params)
54
54
 
55
55
  @page_title = @resource.default_panel_name
56
- add_breadcrumb resource_name.humanize, resources_path(@resource.model_class)
56
+
57
+ # If we're accessing this resource via another resource add the parent to the breadcrumbs.
58
+ if params[:via_resource_class].present? && params[:via_resource_id].present?
59
+ via_resource = Avo::App.get_resource_by_model_name params[:via_resource_class]
60
+ via_model = via_resource.model_class.find params[:via_resource_id]
61
+ via_resource.hydrate model: via_model
62
+
63
+ add_breadcrumb via_resource.plural_name, resources_path(via_resource.model_class)
64
+ add_breadcrumb via_resource.model_title, resource_path(via_model)
65
+ else
66
+ add_breadcrumb resource_name.humanize, resources_path(@resource.model_class)
67
+ end
68
+
57
69
  add_breadcrumb @resource.model_title
58
70
  end
59
71
 
@@ -70,7 +82,19 @@ module Avo
70
82
  @resource = @resource.hydrate(model: @model, view: :edit, user: _current_user)
71
83
 
72
84
  @page_title = @resource.default_panel_name
73
- add_breadcrumb resource_name.humanize, resources_path(@resource.model_class)
85
+
86
+ # If we're accessing this resource via another resource add the parent to the breadcrumbs.
87
+ if params[:via_resource_class].present? && params[:via_resource_id].present?
88
+ via_resource = Avo::App.get_resource_by_model_name params[:via_resource_class]
89
+ via_model = via_resource.model_class.find params[:via_resource_id]
90
+ via_resource.hydrate model: via_model
91
+
92
+ add_breadcrumb via_resource.plural_name, resources_path(via_resource.model_class)
93
+ add_breadcrumb via_resource.model_title, resource_path(via_model)
94
+ else
95
+ add_breadcrumb resource_name.humanize, resources_path(@resource.model_class)
96
+ end
97
+
74
98
  add_breadcrumb @resource.model_title, resource_path(@resource.model)
75
99
  add_breadcrumb t("avo.edit").humanize
76
100
  end
@@ -7,7 +7,7 @@ module Avo
7
7
  redirect_to Avo.configuration.home_path
8
8
  elsif !Rails.env.development?
9
9
  @page_title = "Get started"
10
- redirect_to resources_path Avo::App.get_resources.min_by { |resource| resource.route_key }.model_class
10
+ redirect_to resources_path Avo::App.resources.min_by { |resource| resource.route_key }.model_class
11
11
  end
12
12
  end
13
13
  end
@@ -17,7 +17,7 @@ module Avo
17
17
  @resource = @related_resource
18
18
  @parent_model = @parent_resource.model_class.find(params[:id])
19
19
  @parent_resource.hydrate(model: @parent_model)
20
- @query = @parent_model.public_send(params[:related_name])
20
+ @query = @authorization.apply_policy @parent_model.public_send(params[:related_name])
21
21
 
22
22
  super
23
23
  end
@@ -2,56 +2,71 @@ require_dependency "avo/application_controller"
2
2
 
3
3
  module Avo
4
4
  class SearchController < ApplicationController
5
- # before_action :authorize_user
5
+ before_action :set_resource_name, only: [:show]
6
+ before_action :set_resource, only: [:show]
6
7
 
7
8
  def index
8
- @authorization.set_record(resource_model).authorize_action :index
9
- resources = []
10
-
11
- App.get_resources
12
- .select { |resource| resource.search.present? }
13
- .select { |resource| AuthorizationService.authorize_action _current_user, resource.model, "index" }
14
- .each do |resource_model|
15
- found_resources = add_link_to_search_results(search_resource(resource_model), resource_model)
16
- resources.push({
17
- label: resource_model.name,
18
- resources: found_resources
19
- })
20
- end
9
+ raise ActionController::BadRequest.new("This feature requires the pro license https://avohq.io/purchase/pro") if App.license.lacks_with_trial(:global_search)
21
10
 
22
- render json: {
23
- resources: resources
24
- }
11
+ render json: search_resources(Avo::App.resources)
25
12
  end
26
13
 
27
- def resource
28
- render json: {
29
- resources: add_link_to_search_results(search_resource(avo_resource), avo_resource)
30
- }
14
+ def show
15
+ render json: search_resources([resource])
31
16
  end
32
17
 
33
18
  private
34
19
 
35
- def add_link_to_search_results(resources, avo_resource)
36
- resources.map do |model|
37
- {
38
- id: model.id,
39
- search_label: model.send(avo_resource.class.title),
40
- link: "/resources/#{model.class.to_s.singularize.underscore}/#{model.id}"
41
- }
20
+ def search_resources(resources)
21
+ resources.map do |resource|
22
+ # Apply authorization
23
+ next unless @authorization.set_record(resource.model_class).authorize_action(:index, raise_exception: false)
24
+ # Filter out the models without a search_query
25
+ next if resource.search_query.nil?
26
+
27
+ search_resource resource
42
28
  end
29
+ .select do |payload|
30
+ payload.present?
31
+ end
32
+ .sort do |payload|
33
+ payload.last[:count]
34
+ end
35
+ .reverse
36
+ .to_h
43
37
  end
44
38
 
45
- def search_resource(avo_resource)
46
- avo_resource.query_search(query: params[:q], via_resource_name: params[:via_resource_name], via_resource_id: params[:via_resource_id], user: _current_user)
39
+ def search_resource(resource)
40
+ results = apply_search_metadata(resource.search_query.call(params: params).limit(8), resource)
41
+
42
+ result_object = {
43
+ header: resource.name.pluralize,
44
+ results: results,
45
+ count: results.length
46
+ }
47
+
48
+ [resource.name.pluralize.downcase, result_object]
47
49
  end
48
50
 
49
- # def authorize_user
50
- # return if params[:action] == 'index'
51
+ def apply_search_metadata(models, avo_resource)
52
+ models.map do |model|
53
+ resource = avo_resource.dup.hydrate(model: model).hydrate_fields(model: model)
51
54
 
52
- # action = params[:action] == 'resource' ? :index : params[:action]
55
+ result = {
56
+ _id: model.id,
57
+ _label: resource.label,
58
+ _url: resource.avo_path,
59
+ model: model
60
+ }
53
61
 
54
- # return render_unauthorized unless AuthorizationService::authorize_action _current_user, avo_resource.model, action
55
- # end
62
+ if App.license.has_with_trial(:enhanced_search_results)
63
+ result[:_description] = resource.description
64
+ result[:_avatar] = resource.avatar
65
+ result[:_avatar_type] = resource.avatar_type
66
+ end
67
+
68
+ result
69
+ end
70
+ end
56
71
  end
57
72
  end