agile_rails 0.0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +285 -0
  5. data/Rakefile +39 -0
  6. data/agile_rails.gemspec +36 -0
  7. data/app/assets/fonts/ibm-plex-sans-300.woff2 +0 -0
  8. data/app/assets/fonts/ibm-plex-sans-400.woff2 +0 -0
  9. data/app/assets/fonts/ibm-plex-sans-500.woff2 +0 -0
  10. data/app/assets/fonts/ibm-plex-sans-600.woff2 +0 -0
  11. data/app/assets/fonts/ibm-plex-sans-700.woff2 +0 -0
  12. data/app/assets/fonts/ibm-plex-sans-italic.woff2 +0 -0
  13. data/app/assets/images/32px.png +0 -0
  14. data/app/assets/images/throbber.gif +0 -0
  15. data/app/assets/javascripts/agile/agile.js +1489 -0
  16. data/app/assets/javascripts/agile/jquery-migrate.js +702 -0
  17. data/app/assets/javascripts/agile/jquery.bpopup.js +372 -0
  18. data/app/assets/javascripts/agile/jquery.datetimepicker.js +1353 -0
  19. data/app/assets/javascripts/agile/jstree.min.js +6 -0
  20. data/app/assets/javascripts/agile/select-multiple.js +459 -0
  21. data/app/assets/javascripts/agile/some_scripts.js +33 -0
  22. data/app/assets/javascripts/agile.js +22 -0
  23. data/app/assets/javascripts/agile_application.js +22 -0
  24. data/app/assets/javascripts/agile_editor.js +22 -0
  25. data/app/assets/stylesheets/agile/agile.css +1882 -0
  26. data/app/assets/stylesheets/agile/agile_apps.css +149 -0
  27. data/app/assets/stylesheets/agile/jquery.datetimepicker.css +304 -0
  28. data/app/assets/stylesheets/agile/jstree.css +1107 -0
  29. data/app/assets/stylesheets/agile/select-multiple.css +110 -0
  30. data/app/assets/stylesheets/agile/th-bg.png +0 -0
  31. data/app/assets/stylesheets/agile/theme.css +49 -0
  32. data/app/assets/stylesheets/agile.css +21 -0
  33. data/app/assets/stylesheets/agile_application.css +20 -0
  34. data/app/assets/stylesheets/agile_editor.css +19 -0
  35. data/app/controllers/agile_application_controller.rb +735 -0
  36. data/app/controllers/agile_common_controller.rb +345 -0
  37. data/app/controllers/agile_controller.rb +977 -0
  38. data/app/controllers/agile_main_controller.rb +36 -0
  39. data/app/controls/agile_control.rb +120 -0
  40. data/app/controls/agile_report.rb +364 -0
  41. data/app/controls/ar_category_control.rb +39 -0
  42. data/app/controls/ar_help_control.rb +139 -0
  43. data/app/controls/ar_image_control.rb +180 -0
  44. data/app/controls/ar_journal_control.rb +47 -0
  45. data/app/controls/ar_menu_item_control.rb +55 -0
  46. data/app/controls/ar_page_control.rb +64 -0
  47. data/app/controls/ar_poll_result_control.rb +84 -0
  48. data/app/controls/ar_setup_control.rb +62 -0
  49. data/app/controls/belongs_to_control.rb +61 -0
  50. data/app/controls/browse_models_control.rb +98 -0
  51. data/app/controls/settings_form_control.rb +137 -0
  52. data/app/forms/agile_help.yml +112 -0
  53. data/app/forms/agile_menu.yml +140 -0
  54. data/app/forms/agile_report_defaults.yml +39 -0
  55. data/app/forms/all_options.yml +810 -0
  56. data/app/forms/ar_ad.yml +121 -0
  57. data/app/forms/ar_big_table.yml +60 -0
  58. data/app/forms/ar_big_table_value.yml +52 -0
  59. data/app/forms/ar_browse_fields.yml +35 -0
  60. data/app/forms/ar_browse_models.yml +48 -0
  61. data/app/forms/ar_category.yml +73 -0
  62. data/app/forms/ar_category_as_tree.yml +31 -0
  63. data/app/forms/ar_design.yml +75 -0
  64. data/app/forms/ar_filter.yml +52 -0
  65. data/app/forms/ar_folder_permission.yml +56 -0
  66. data/app/forms/ar_folder_rule.yml +48 -0
  67. data/app/forms/ar_gallery.yml +55 -0
  68. data/app/forms/ar_image.yml +126 -0
  69. data/app/forms/ar_image_search.yml +83 -0
  70. data/app/forms/ar_journal.yml +76 -0
  71. data/app/forms/ar_json_ld.yml +56 -0
  72. data/app/forms/ar_key_value.yml +33 -0
  73. data/app/forms/ar_key_value_store.yml +33 -0
  74. data/app/forms/ar_link.yml +60 -0
  75. data/app/forms/ar_menu.yml +67 -0
  76. data/app/forms/ar_menu_item.yml +141 -0
  77. data/app/forms/ar_page.yml +187 -0
  78. data/app/forms/ar_part.yml +91 -0
  79. data/app/forms/ar_permission.yml +52 -0
  80. data/app/forms/ar_permission_rule.yml +40 -0
  81. data/app/forms/ar_piece.yml +106 -0
  82. data/app/forms/ar_policy.yml +64 -0
  83. data/app/forms/ar_policy_rule.yml +42 -0
  84. data/app/forms/ar_policy_rule_nocms.yml +40 -0
  85. data/app/forms/ar_poll.yml +118 -0
  86. data/app/forms/ar_poll_item.yml +78 -0
  87. data/app/forms/ar_poll_result.yml +88 -0
  88. data/app/forms/ar_poll_result_export.yml +35 -0
  89. data/app/forms/ar_removed_url.yml +41 -0
  90. data/app/forms/ar_role.yml +43 -0
  91. data/app/forms/ar_seo.yml +32 -0
  92. data/app/forms/ar_setup.yml +45 -0
  93. data/app/forms/ar_site.yml +149 -0
  94. data/app/forms/ar_steps_template.yml +51 -0
  95. data/app/forms/ar_user.yml +140 -0
  96. data/app/forms/ar_user_role.yml +57 -0
  97. data/app/forms/help/dc_category_as_tree.en +4 -0
  98. data/app/forms/help/dc_category_as_tree.sl +5 -0
  99. data/app/forms/json_ld_schema.yml +168 -0
  100. data/app/helpers/agile_application_helper.rb +1162 -0
  101. data/app/helpers/agile_category_helper.rb +128 -0
  102. data/app/helpers/agile_common_helper.rb +308 -0
  103. data/app/helpers/agile_edit_helper.rb +645 -0
  104. data/app/helpers/agile_helper.rb +509 -0
  105. data/app/helpers/agile_index_helper.rb +677 -0
  106. data/app/helpers/ar_image_helper.rb +128 -0
  107. data/app/models/agile_form_fields/action.rb +61 -0
  108. data/app/models/agile_form_fields/agile_form_field.rb +322 -0
  109. data/app/models/agile_form_fields/belongs_to.rb +112 -0
  110. data/app/models/agile_form_fields/check_box.rb +73 -0
  111. data/app/models/agile_form_fields/comment.rb +62 -0
  112. data/app/models/agile_form_fields/date_picker.rb +104 -0
  113. data/app/models/agile_form_fields/date_select.rb +68 -0
  114. data/app/models/agile_form_fields/datetime_picker.rb +88 -0
  115. data/app/models/agile_form_fields/datetime_select.rb +73 -0
  116. data/app/models/agile_form_fields/file_field.rb +52 -0
  117. data/app/models/agile_form_fields/file_select.rb +69 -0
  118. data/app/models/agile_form_fields/hidden_field.rb +51 -0
  119. data/app/models/agile_form_fields/html_field.rb +69 -0
  120. data/app/models/agile_form_fields/journal_diff.rb +62 -0
  121. data/app/models/agile_form_fields/link_to.rb +69 -0
  122. data/app/models/agile_form_fields/method.rb +66 -0
  123. data/app/models/agile_form_fields/multitext_autocomplete.rb +215 -0
  124. data/app/models/agile_form_fields/number_field.rb +92 -0
  125. data/app/models/agile_form_fields/password_field.rb +63 -0
  126. data/app/models/agile_form_fields/radio_button.rb +95 -0
  127. data/app/models/agile_form_fields/readonly.rb +77 -0
  128. data/app/models/agile_form_fields/select.rb +281 -0
  129. data/app/models/agile_form_fields/submit_tag.rb +58 -0
  130. data/app/models/agile_form_fields/text_area.rb +61 -0
  131. data/app/models/agile_form_fields/text_autocomplete.rb +171 -0
  132. data/app/models/agile_form_fields/text_field.rb +55 -0
  133. data/app/models/agile_form_fields/text_with_select.rb +94 -0
  134. data/app/models/agile_form_fields/tree_select.rb +170 -0
  135. data/app/models/ar_big_table.rb +82 -0
  136. data/app/models/ar_big_table_value.rb +53 -0
  137. data/app/models/ar_category.rb +109 -0
  138. data/app/models/ar_design.rb +116 -0
  139. data/app/models/ar_filter.rb +200 -0
  140. data/app/models/ar_folder_permission.rb +50 -0
  141. data/app/models/ar_folder_rule.rb +47 -0
  142. data/app/models/ar_gallery.rb +53 -0
  143. data/app/models/ar_image.rb +198 -0
  144. data/app/models/ar_internals.rb +60 -0
  145. data/app/models/ar_journal.rb +46 -0
  146. data/app/models/ar_json_ld.rb +131 -0
  147. data/app/models/ar_key_value_store.rb +128 -0
  148. data/app/models/ar_link.rb +48 -0
  149. data/app/models/ar_memory.rb +172 -0
  150. data/app/models/ar_menu.rb +144 -0
  151. data/app/models/ar_menu_item.rb +106 -0
  152. data/app/models/ar_page.rb +74 -0
  153. data/app/models/ar_part.rb +66 -0
  154. data/app/models/ar_permission.rb +180 -0
  155. data/app/models/ar_permission_rule.rb +65 -0
  156. data/app/models/ar_policy.rb +78 -0
  157. data/app/models/ar_policy_rule.rb +65 -0
  158. data/app/models/ar_poll.rb +74 -0
  159. data/app/models/ar_poll_item.rb +47 -0
  160. data/app/models/ar_poll_result.rb +38 -0
  161. data/app/models/ar_removed_url.rb +42 -0
  162. data/app/models/ar_role.rb +84 -0
  163. data/app/models/ar_setup.rb +115 -0
  164. data/app/models/ar_site.rb +68 -0
  165. data/app/models/ar_temp.rb +150 -0
  166. data/app/models/ar_user.rb +72 -0
  167. data/app/models/ar_user_group.rb +38 -0
  168. data/app/models/ar_user_role.rb +54 -0
  169. data/app/models/ar_visit.rb +41 -0
  170. data/app/models/concerns/ar_page_concern.rb +128 -0
  171. data/app/models/concerns/ar_part_concern.rb +48 -0
  172. data/app/models/concerns/ar_piece_concern.rb +48 -0
  173. data/app/models/concerns/ar_policy_rule_concern.rb +87 -0
  174. data/app/models/concerns/ar_seo_concern.rb +66 -0
  175. data/app/models/concerns/ar_site_concern.rb +103 -0
  176. data/app/models/concerns/ar_user_concern.rb +195 -0
  177. data/app/renderers/agile_common_renderer.rb +93 -0
  178. data/app/renderers/agile_renderer.rb +59 -0
  179. data/app/renderers/ar_ad_renderer.rb +219 -0
  180. data/app/renderers/ar_captcha_renderer.rb +113 -0
  181. data/app/renderers/ar_common_renderer.rb +90 -0
  182. data/app/renderers/ar_gallery_renderer.rb +107 -0
  183. data/app/renderers/ar_menu_renderer.rb +195 -0
  184. data/app/renderers/ar_page_renderer.rb +147 -0
  185. data/app/renderers/ar_part_renderer.rb +235 -0
  186. data/app/renderers/ar_piece_renderer.rb +119 -0
  187. data/app/renderers/ar_poll_renderer.rb +272 -0
  188. data/app/views/agile/_edit_stuff.html.erb +57 -0
  189. data/app/views/agile/_form.html.erb +24 -0
  190. data/app/views/agile/_result.html.erb +28 -0
  191. data/app/views/agile/edit.html.erb +13 -0
  192. data/app/views/agile/error.html.erb +2 -0
  193. data/app/views/agile/index.html.erb +14 -0
  194. data/app/views/agile/login.html.erb +19 -0
  195. data/app/views/agile/new.html.erb +12 -0
  196. data/app/views/agile_common/_help.html.erb +18 -0
  197. data/app/views/agile_common/_iframe_edit.html.erb +2 -0
  198. data/app/views/agile_common/paste_clipboard.html.erb +17 -0
  199. data/app/views/layouts/agile.html.erb +17 -0
  200. data/app/views/layouts/content.html.erb +20 -0
  201. data/app/views/models/dump_models.html.erb +47 -0
  202. data/config/initializers/kaminari_patch.rb +56 -0
  203. data/config/locales/agile_de.yml +138 -0
  204. data/config/locales/agile_en.yml +162 -0
  205. data/config/locales/agile_sl.yml +163 -0
  206. data/config/locales/datetimepicker.yml +19 -0
  207. data/config/locales/de.yml +231 -0
  208. data/config/locales/en.yml +13 -0
  209. data/config/locales/kaminari.yml +26 -0
  210. data/config/locales/models_en.yml +1032 -0
  211. data/config/locales/models_sl.yml +1065 -0
  212. data/config/locales/sl.yml +211 -0
  213. data/db/migrate/20240120160001_add_sessions_table.rb +12 -0
  214. data/db/migrate/20240120160002_ar_big_table.rb +17 -0
  215. data/db/migrate/20240120160003_ar_big_table_value.rb +18 -0
  216. data/db/migrate/20240120160004_ar_category.rb +22 -0
  217. data/db/migrate/20240120160005_ar_design.rb +20 -0
  218. data/db/migrate/20240120160006_ar_filter.rb +17 -0
  219. data/db/migrate/20240120160007_ar_gallery.rb +21 -0
  220. data/db/migrate/20240120160008_ar_journal.rb +19 -0
  221. data/db/migrate/20240120160009_ar_key_value_store.rb +11 -0
  222. data/db/migrate/20240120160010_ar_link.rb +19 -0
  223. data/db/migrate/20240120160011_ar_memory.rb +8 -0
  224. data/db/migrate/20240120160012_ar_menu.rb +21 -0
  225. data/db/migrate/20240120160013_ar_menu_item.rb +28 -0
  226. data/db/migrate/20240120160014_ar_page.rb +50 -0
  227. data/db/migrate/20240120160015_ar_part.rb +33 -0
  228. data/db/migrate/20240120160016_ar_permission.rb +16 -0
  229. data/db/migrate/20240120160017_ar_permission_rule.rb +17 -0
  230. data/db/migrate/20240120160018_ar_piece.rb +28 -0
  231. data/db/migrate/20240120160019_ar_policy.rb +21 -0
  232. data/db/migrate/20240120160020_ar_policy_rule.rb +18 -0
  233. data/db/migrate/20240120160021_ar_poll.rb +27 -0
  234. data/db/migrate/20240120160022_ar_poll_item.rb +23 -0
  235. data/db/migrate/20240120160023_ar_poll_result.rb +14 -0
  236. data/db/migrate/20240120160024_ar_removed_url.rb +16 -0
  237. data/db/migrate/20240120160025_ar_role.rb +17 -0
  238. data/db/migrate/20240120160026_ar_site.rb +37 -0
  239. data/db/migrate/20240120160027_ar_temp.rb +11 -0
  240. data/db/migrate/20240120160028_ar_user.rb +42 -0
  241. data/db/migrate/20240120160029_ar_user_group.rb +12 -0
  242. data/db/migrate/20240120160030_ar_user_role.rb +18 -0
  243. data/db/migrate/20240120160031_ar_visit.rb +15 -0
  244. data/db/migrate/20240703016001_ar_setup.rb +16 -0
  245. data/db/migrate/20240703016002_ar_folder_permission.rb +15 -0
  246. data/db/migrate/20240703016003_ar_folder_rule.rb +14 -0
  247. data/db/migrate/20250115000001_ar_image.rb +25 -0
  248. data/lib/agile/configuration.rb +43 -0
  249. data/lib/agile/engine.rb +29 -0
  250. data/lib/agile/version.rb +27 -0
  251. data/lib/agile.rb +282 -0
  252. data/lib/agile_rails.rb +1 -0
  253. data/lib/generators/agile/USAGE +11 -0
  254. data/lib/generators/agile/new_form_generator.rb +369 -0
  255. data/lib/generators/convert_to_ar/convert_to_ar_generator.rb +158 -0
  256. data/lib/tasks/agile_db_clone.rake +132 -0
  257. data/lib/tasks/agile_db_export_to_yaml.rake +37 -0
  258. data/lib/tasks/agile_db_migrate.rake +35 -0
  259. metadata +414 -0
@@ -0,0 +1,139 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ######################################################################
25
+ # Controls for creating help files
26
+ ######################################################################
27
+ module ArHelpControl
28
+
29
+ ######################################################################
30
+ # Will fill ar_temp with help documents found in a defined project directory.
31
+ ######################################################################
32
+ def project_refresh
33
+ ArTemp.clear(temp_key)
34
+
35
+ if params[:record][:select_project].present?
36
+ # far less complicated if saved to session
37
+ session[:help_project] = params[:record][:select_project]
38
+ session[:help_lang] = params[:record][:lang_1]
39
+ help_dir_name = "#{session[:help_project]}/help/"
40
+ # create help directory if not yet exists
41
+ FileUtils.mkdir(help_dir_name) unless File.exist?(help_dir_name)
42
+ Dir["#{help_dir_name}*"].each do |file_name|
43
+ lang = File.extname(file_name).sub('.', '')
44
+ next unless lang == session[:help_lang]
45
+
46
+ ArTemp.new(key: temp_key,
47
+ project: session[:help_project],
48
+ form_name: File.basename(file_name, '.*'),
49
+ lang: lang,
50
+ updated_at: File.mtime(file_name)).save
51
+ end
52
+ end
53
+ render json: { url: url_for(controller: :agile, table: :ar_temp, form_name: :agile_help) }
54
+ end
55
+
56
+ ######################################################################
57
+ # Will populate fields with default values
58
+ ######################################################################
59
+ def new_record
60
+ @record.project = session[:help_project]
61
+ @record.lang = session[:help_lang]
62
+ end
63
+
64
+ ######################################################################
65
+ # Will read data from help file
66
+ ######################################################################
67
+ def before_edit
68
+ file_name = "#{session[:help_project]}/help/#{@record.form_name}.#{session[:help_lang]}"
69
+ data = YAML.load_file(file_name)
70
+ @record.index = data['index']
71
+ @record.form = data['form']
72
+ flash[:warning] = "Use only in development!" unless Rails.env.development?
73
+ end
74
+
75
+ ######################################################################
76
+ # Will save data to help file
77
+ ######################################################################
78
+ def before_save
79
+ rec = params[:record]
80
+ file_name = "#{session[:help_project]}/help/#{@record.form_name}.#{@record.lang}"
81
+ data = { 'index' => @record.index, 'form' => @record.form }
82
+ File.write(file_name, data.to_yaml)
83
+ end
84
+
85
+ ######################################################################
86
+ # Will return query to report data
87
+ ######################################################################
88
+ def data_filter
89
+ ArTemp.where(key: temp_key).order(:order)
90
+ end
91
+
92
+ private
93
+
94
+ ######################################################################
95
+ # Will return choices for select project input field on a form
96
+ ######################################################################
97
+ def self.choices_for_project
98
+ r = Agile.paths(:forms).map do |path|
99
+ path = path.to_s
100
+ a = path.split('/')
101
+ project = a[a.size - 3]
102
+ project = if project == 'app'
103
+ a[a.size - 4] + ' : ' + a.last(2).join('/')
104
+ else
105
+ project + ' : ' + a.last
106
+ end
107
+ [project, path]
108
+ end
109
+ [[I18n.t('agile.ar_help.project'), nil]] + r.sort
110
+ end
111
+
112
+ ######################################################################
113
+ # Will return choices for selecting help file name, based on forms already
114
+ # present in forms directory.
115
+ ######################################################################
116
+ def self.choices_for_form_name(session)
117
+ Dir["#{session[:help_project]}/*.yml"].map { |file_name| File.basename(file_name,'.*') }.sort
118
+ end
119
+
120
+ ######################################################################
121
+ # Will return choices for language select on form. Choices can be either set by ar_locales document in ar_big_table
122
+ # or can be acquired from Rails default locale
123
+ ######################################################################
124
+ def self.choices_for_locales
125
+ choices = ArBigTable.choices_for('ar_locales')
126
+ return choices unless choices[0, 0] == I18n.t('agile.error')
127
+
128
+ choices = [I18n.default_locale] + I18n.fallbacks.map(&:first)
129
+ choices.map(&:to_s).uniq
130
+ end
131
+
132
+ ######################################################################
133
+ # Will return temp key for data saved in ar_temp file
134
+ ######################################################################
135
+ def temp_key
136
+ "ar-help-#{session[:user_id]}"
137
+ end
138
+
139
+ end
@@ -0,0 +1,180 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ ######################################################################
25
+ # Controls for ArImage image management module
26
+ ######################################################################
27
+ module ArImageControl
28
+
29
+ ######################################################################
30
+ #
31
+ ######################################################################
32
+ def search_filter
33
+ flash[:record] ||= {}
34
+
35
+ created_by = flash[:record][:created_by]
36
+ qry = created_by.present? ? ArImage.where(created_by: created_by) : ArImage.all
37
+
38
+ short_name = flash[:record][:short]
39
+ qry = qry.where("short LIKE ?", "#{ArImage.sanitize_sql_like(short_name)}%") if short_name.present?
40
+
41
+ keyword = flash[:record][:keyword]
42
+ qry = qry.where("keywords LIKE ?", "%#{ArImage.sanitize_sql_like(keyword)}%") if keyword.present?
43
+ qry.limit(30).order(created_at: 'desc')
44
+ end
45
+
46
+ ######################################################################
47
+ # Invoke images search. Just forward parameters and reload form. Filter parameters will
48
+ # be taken into account on reload.
49
+ ######################################################################
50
+ def images_search
51
+ flash[:record] = {}
52
+ flash[:record][:short] = params[:record][:short]
53
+ flash[:record][:created_by] = params[:record][:created_by]
54
+ flash[:record][:keyword] = params[:record][:keyword]
55
+
56
+ url = url_for(controller: :agile, table: :ar_image, form_name: :ar_image_search, field_name: params[:field_name])
57
+ render json: { url: url }
58
+ end
59
+
60
+ ######################################################################
61
+ # Set some default values when new record
62
+ ######################################################################
63
+ def new_record
64
+ default_sizes = agile_get_site.params.dig('ar_image', 'sizes').to_s.split(',')
65
+ @record.size_ls = default_sizes.shift
66
+ @record.size_ms = default_sizes.shift
67
+ @record.size_ss = default_sizes.shift
68
+ end
69
+
70
+ ######################################################################
71
+ # Save uploaded file if selected and extract properties data
72
+ ######################################################################
73
+ def before_save
74
+ return if @record.size_o.present? || !params[:upload_file]
75
+
76
+ input_file_name = params[:upload_file].original_filename
77
+ type = File.extname(input_file_name).to_s.downcase.gsub('.', '').strip
78
+ unless %w[jpg jpeg png gif svg webp].include?(type)
79
+ flash[:error] = t 'agile.ar_image.wrong_type'
80
+ return false
81
+ end
82
+ name = File.basename(input_file_name)
83
+ path = File.dirname(params[:upload_file].tempfile)
84
+
85
+ @record.img_type = agile_get_site.params.dig('ar_image', 'img_type') || type
86
+ @record.short = File.basename(input_file_name, '.*') if @record.short.blank?
87
+ @record.name = File.join(path, name)
88
+ FileUtils.mv(params[:upload_file].tempfile, @record.name, force: nil)
89
+ end
90
+
91
+ ######################################################################
92
+ # Prepare additional images
93
+ ######################################################################
94
+ def after_save
95
+ %w[l m s o].each { |size| image_convert(size) }
96
+ end
97
+
98
+ private
99
+
100
+ ######################################################################
101
+ #
102
+ ######################################################################
103
+ def image_convert(which)
104
+ new_file_name = "#{@record.id}-#{which}.#{@record.img_type}"
105
+ new_file_name = Rails.root.join('public', images_location, new_file_name)
106
+ new_size = @record["size_#{which}"]
107
+ # remove file if not needed
108
+ if new_size.blank?
109
+ FileUtils.rm(new_file_name) if File.exist?(new_file_name)
110
+ return
111
+ end
112
+
113
+ original_file_name = Rails.root.join('public', images_location, "#{@record.id}-o.#{@record.img_type}")
114
+ @record.name = original_file_name unless @record.name.present? && File.exist?(@record.name)
115
+ unless File.exist?(@record.name)
116
+ flash[:warning] = t 'agile.ar_image.no_file'
117
+ return
118
+ end
119
+
120
+ image_magick_do(new_size, new_file_name)
121
+ end
122
+
123
+ ######################################################################
124
+ # Crop and resize image
125
+ #
126
+ # @new_size [String] new_size widthxheight+offsetx+offsety 300x200+1000+0
127
+ # @file_name [String] Image file name
128
+ ######################################################################
129
+ def image_magick_do(new_size, file_name)
130
+ image = MiniMagick::Image.open(@record.name)
131
+
132
+ a = new_size.split(/x|\+/).map(&:to_i)
133
+ a += [0, 0] if a.size < 4
134
+ image_offset(image, a[2, 2]) if a[2, 2] != [0, 0]
135
+
136
+ img_w, img_h = image.width, image.height
137
+ new_w, new_h = a[0, 2]
138
+ img_ratio = img_w.to_f / img_h
139
+ new_ratio = new_w.to_f / new_h
140
+ formula = if new_ratio > img_ratio
141
+ "#{img_w}x#{img_w/new_ratio}+0+0"
142
+ else
143
+ "#{img_h*new_ratio}x#{img_h}+0+0"
144
+ end
145
+ image.crop(formula)
146
+
147
+ image.resize("#{new_w}x#{new_h}")
148
+ image.write(file_name)
149
+ image_reduce(file_name)
150
+ end
151
+
152
+ ######################################################################
153
+ # Reduce image quality of image
154
+ ######################################################################
155
+ def image_reduce(file_name)
156
+ if (quality = agile_get_site.params.dig('ar_image', 'quality').to_i) > 0
157
+ convert = MiniMagick::Tool::Convert.new
158
+ convert << file_name
159
+ convert.quality(quality)
160
+ convert << file_name
161
+ convert.call
162
+ end
163
+ end
164
+
165
+ ######################################################################
166
+ # Offset image if requested
167
+ ######################################################################
168
+ def image_offset(image, offset)
169
+ img_w, img_h = image.width - offset[0], image.height - offset[1]
170
+ image.crop("#{img_w}x#{img_h}+#{offset[0]}+#{offset[1]}")
171
+ end
172
+
173
+ ######################################################################
174
+ # Returns location of images files relative to public directory
175
+ ######################################################################
176
+ def images_location
177
+ agile_get_site.params.dig('ar_image', 'location') || 'images'
178
+ end
179
+
180
+ end
@@ -0,0 +1,47 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ######################################################################
25
+ # Controls for displaying journal table.
26
+ ######################################################################
27
+ module ArJournalControl
28
+
29
+ ######################################################################
30
+ # Default filter for journal.
31
+ # If filter value is delimited with ; then filter is called from info
32
+ ######################################################################
33
+ def default_filter
34
+ order = agile_sort_options(ArJournal) || { id: :desc }
35
+ filter = session.dig(:filters, 'ar_journal', :filter)
36
+ if filter
37
+ if filter[:value].match(';')
38
+ table, id = filter[:value].split(';')
39
+ return ArJournal.where(tables: table, record_id: id.to_i)
40
+ else
41
+ return agile_filter_options(ArJournal).order(order)
42
+ end
43
+ end
44
+ ArJournal.all.order(order)
45
+ end
46
+
47
+ end
@@ -0,0 +1,55 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ######################################################################
25
+ # Controls for ArMenuItem Form field.
26
+ ######################################################################
27
+ module ArMenuItemControl
28
+
29
+ ######################################################################
30
+ # Default filter for selecting menu items records
31
+ ######################################################################
32
+ def default_filter
33
+ ArMenuItem.where(ar_menu_id: ids().first, parent_id: ids().last).order(:order)
34
+ end
35
+
36
+ ######################################################################
37
+ # Called when new empty record is created
38
+ ######################################################################
39
+ def new_record
40
+ @record.ar_menu_id = ids().first
41
+ @record.parent_id = ids().last
42
+ end
43
+
44
+ private
45
+
46
+ ######################################################################
47
+ # Split ids parameter into array
48
+ ######################################################################
49
+ def ids
50
+ ids = params[:ids].split(';')
51
+ ids << 0 if ids.size == 1
52
+ ids
53
+ end
54
+
55
+ end
@@ -0,0 +1,64 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ######################################################################
25
+ # AgileRails controls for ArPage model.
26
+ ######################################################################
27
+ module ArPageControl
28
+
29
+ ######################################################################
30
+ # Called when new empty record is created
31
+ ######################################################################
32
+ def new_record
33
+ # Called from menu. Fill in values, that could be obtained from menu
34
+ if params[:from_menu]
35
+ menu_item_klass = (agile_get_site.menu_klass.to_s + 'Item').classify.constantize
36
+ menu = menu_item_klass.find(params[:id])
37
+ # Fill values for form
38
+ @record.subject = menu.caption
39
+ @record.ar_site_id = agile_get_site.id
40
+ @record.menu_id = params[:id]
41
+ # set update_menu on save parameter
42
+ params['p__update_menu'] = '1'
43
+ else
44
+ @record.design_id = params[:design_id] if params[:design_id]
45
+ return unless params[:page_id]
46
+ # inherit some values from currently active page
47
+ if page = ArPage.find(params[:page_id])
48
+ @record.design_id = page.design_id
49
+ @record.menu = page.menu
50
+ @record.ar_site_id = page.ar_site_id
51
+ end
52
+ end
53
+ end
54
+
55
+ ######################################################################
56
+ # Called just after record is saved to DB.
57
+ ######################################################################
58
+ def after_save
59
+ if params.dig(:_record,:_update_menu).to_s == '1'
60
+ agile_get_site.menu_klass.menu_item_link_update(@record)
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,84 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #+
23
+
24
+ ######################################################################
25
+ # AgileRails controls for ArPollResult model.
26
+ ######################################################################
27
+ module ArPollResultControl
28
+
29
+ ######################################################################
30
+ # Default data_set filter
31
+ ######################################################################
32
+ def default_filter
33
+ get_query
34
+ end
35
+
36
+ ######################################################################
37
+ # Filter action called. Update url to reflect filter conditions and reload form.
38
+ ######################################################################
39
+ def set_filter
40
+ url = url_for(controller: :agile, action: :index, table: :ar_poll_result,
41
+ 'record[poll_id]' => params[:record][:poll_id],
42
+ 'record[start_date]' => params[:record][:start_date],
43
+ 'record[end_date]' => params[:record][:end_date])
44
+ render json: { url: url }
45
+ end
46
+
47
+ ######################################################################
48
+ # Export data to CSV file.
49
+ ######################################################################
50
+ def do_export
51
+ c, keys = '', []
52
+ get_query.to_a.each do |doc|
53
+ # ensure, that fields are always in same order
54
+ data = YAML.load(doc.data)
55
+ if c.blank?
56
+ data.each { |k, v| keys << k }
57
+ c += "#{I18n.t('helpers.label.ar_poll_result.created_at')}\t"
58
+ c += "#{keys.join("\t")}\n"
59
+ end
60
+ c += "#{doc.created_at.strftime(I18n.t('date.formats.default'))}\t"
61
+ keys.each { |k| c += "#{data[k]}\t" }
62
+ c += "\n"
63
+ end
64
+ File.write(Rails.root.join('public','export.csv'), c)
65
+ render json: { window: 'export.csv' } # will download file
66
+ end
67
+
68
+ private
69
+ ######################################################################
70
+ # Creates query for Poll results
71
+ ######################################################################
72
+ def get_query
73
+ return ArPollResult.all if params[:record].blank? # initial call
74
+
75
+ start_date = (AgileFormFields::DatePicker.get_data(params,'start_date') || Time.now).beginning_of_day
76
+ end_date = (AgileFormFields::DatePicker.get_data(params,'end_date') || start_date).end_of_day
77
+ poll_id = params.dig(:record, :poll_id)
78
+ qry = ArPollResult.where('created_at >= ? and created_at <= ?', start_date, end_date)
79
+ return qry if poll_id.nil?
80
+
81
+ qry.where(ar_poll_id: poll_id)
82
+ end
83
+
84
+ end
@@ -0,0 +1,62 @@
1
+ #--
2
+ # Copyright (c) 2024+ Damjan Rems
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ ################################################################################
25
+ # Controls for ar_setup edit form.
26
+ ################################################################################
27
+ module ArSetupControl
28
+
29
+ ################################################################################
30
+ # Update edit form. Admin sees everything while user sees only setup fields.
31
+ ################################################################################
32
+ def update_form
33
+ if params[:application_name]
34
+ if params[:application_name] == '*'
35
+ save_filter_value(nil, 'ar_setup', :filter)
36
+ else
37
+ filter = { field: 'name', operation: 'eq', value: params[:application_name], table: 'ar_setup', no_off: true }
38
+ save_filter_value(filter, 'ar_setup', :filter)
39
+ end
40
+ end
41
+
42
+ return unless params[:id]
43
+
44
+ record = if params[:id].to_i.to_s == params[:id]
45
+ ArSetup.find(params[:id])
46
+ else
47
+ ArSetup.find_by(name: params[:id])
48
+ end
49
+
50
+ unless agile_user_has_role?('admin')
51
+ @form['form'].delete('tabs')
52
+ @form['readonly'] = true unless record.editors.include?(session[:user_id])
53
+ end
54
+
55
+ form = YAML.load(record.form) #rescue nil
56
+ if form.present?
57
+ @form['form']['tabs'] ||= {}
58
+ @form['form']['tabs'].merge!(form)
59
+ end
60
+ end
61
+
62
+ end