decidim-admin 0.21.0 → 0.23.2

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.

Potentially problematic release.


This version of decidim-admin might be problematic. Click here for more details.

Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/admin/application.js.es6 +7 -0
  3. data/app/assets/javascripts/decidim/admin/budget_rule_toggler.component.js.es6 +52 -0
  4. data/app/assets/javascripts/decidim/admin/bundle.js +26 -32
  5. data/app/assets/javascripts/decidim/admin/bundle.js.map +1 -1
  6. data/app/assets/javascripts/decidim/admin/choose_language.js +12 -0
  7. data/app/assets/javascripts/decidim/admin/dynamic_fields.component.js.es6 +24 -5
  8. data/app/assets/javascripts/decidim/admin/form.js.es6 +24 -10
  9. data/app/assets/javascripts/decidim/admin/gallery.js.es6 +5 -0
  10. data/app/assets/javascripts/decidim/admin/newsletters.js.es6 +4 -0
  11. data/app/assets/javascripts/decidim/admin/officializations.js.es6 +20 -0
  12. data/app/assets/javascripts/decidim/admin/scope_picker_enabler.component.js.es6 +14 -0
  13. data/app/assets/stylesheets/decidim/admin/_decidim.scss +2 -0
  14. data/app/assets/stylesheets/decidim/admin/_variables.scss +1 -1
  15. data/app/assets/stylesheets/decidim/admin/extra/_newsletter-templates-gallery.scss +3 -0
  16. data/app/assets/stylesheets/decidim/admin/extra/_organization-appearance.scss +141 -0
  17. data/app/assets/stylesheets/decidim/admin/extra/_show_email.scss +31 -0
  18. data/app/assets/stylesheets/decidim/admin/extra/_title_bar.scss +4 -0
  19. data/app/assets/stylesheets/decidim/admin/modules/_buttons.scss +11 -1
  20. data/app/assets/stylesheets/decidim/admin/modules/_callouts.scss +11 -0
  21. data/app/assets/stylesheets/decidim/admin/modules/_cards.scss +2 -2
  22. data/app/assets/stylesheets/decidim/admin/modules/_filters.scss +2 -2
  23. data/app/assets/stylesheets/decidim/admin/modules/_forms.scss +16 -2
  24. data/app/assets/stylesheets/decidim/admin/modules/_import_result.scss +10 -0
  25. data/app/assets/stylesheets/decidim/admin/modules/_loading-spinner.scss +19 -0
  26. data/app/assets/stylesheets/decidim/admin/modules/_main-nav.scss +0 -1
  27. data/app/assets/stylesheets/decidim/admin/modules/_modules.scss +5 -1
  28. data/app/assets/stylesheets/decidim/admin/modules/_process-header.scss +0 -1
  29. data/app/assets/stylesheets/decidim/admin/modules/_secondary-nav.scss +0 -1
  30. data/app/assets/stylesheets/decidim/admin/modules/_table-list.scss +0 -5
  31. data/app/assets/stylesheets/decidim/admin/modules/_tabs.scss +7 -0
  32. data/app/assets/stylesheets/decidim/admin/modules/_users_statistics.scss +18 -0
  33. data/app/assets/stylesheets/decidim/admin/utils/_mixins.scss +42 -0
  34. data/app/assets/stylesheets/decidim/admin/utils/_settings.scss +4 -1
  35. data/app/cells/decidim/admin/content_block/show.erb +2 -2
  36. data/app/commands/decidim/admin/create_attachment.rb +2 -2
  37. data/app/commands/decidim/admin/create_newsletter.rb +34 -9
  38. data/app/commands/decidim/admin/destroy_share_token.rb +46 -0
  39. data/app/commands/decidim/admin/reorder_content_blocks.rb +1 -1
  40. data/app/commands/decidim/admin/update_component.rb +27 -3
  41. data/app/commands/decidim/admin/update_content_block.rb +25 -1
  42. data/app/commands/decidim/admin/update_newsletter.rb +31 -9
  43. data/app/commands/decidim/admin/update_organization.rb +11 -0
  44. data/app/commands/decidim/admin/update_organization_appearance.rb +3 -1
  45. data/app/controllers/concerns/decidim/admin/participatory_space_export.rb +8 -2
  46. data/app/controllers/decidim/admin/application_controller.rb +1 -0
  47. data/app/controllers/decidim/admin/authorization_workflows_controller.rb +6 -0
  48. data/app/controllers/decidim/admin/components_controller.rb +17 -6
  49. data/app/controllers/decidim/admin/dashboard_controller.rb +33 -1
  50. data/app/controllers/decidim/admin/metrics_controller.rb +22 -0
  51. data/app/controllers/decidim/admin/newsletter_templates_controller.rb +41 -0
  52. data/app/controllers/decidim/admin/newsletters_controller.rb +32 -4
  53. data/app/controllers/decidim/admin/officializations_controller.rb +8 -0
  54. data/app/controllers/decidim/admin/organization_appearance_controller.rb +1 -0
  55. data/app/controllers/decidim/admin/organization_controller.rb +4 -3
  56. data/app/controllers/decidim/admin/organization_homepage_content_blocks_controller.rb +2 -1
  57. data/app/controllers/decidim/admin/share_tokens_controller.rb +30 -0
  58. data/app/forms/decidim/admin/attachment_form.rb +3 -0
  59. data/app/forms/decidim/admin/component_form.rb +5 -22
  60. data/app/forms/decidim/admin/newsletter_form.rb +15 -3
  61. data/app/forms/decidim/admin/organization_appearance_form.rb +7 -4
  62. data/app/forms/decidim/admin/organization_form.rb +20 -0
  63. data/app/forms/decidim/admin/participatory_space_private_user_csv_import_form.rb +13 -0
  64. data/app/forms/decidim/admin/participatory_space_private_user_form.rb +3 -2
  65. data/app/forms/decidim/admin/selective_newsletter_form.rb +6 -0
  66. data/app/frontend/components/autocomplete.component.test.tsx +2 -1
  67. data/app/frontend/components/autocomplete.component.tsx +29 -0
  68. data/app/helpers/decidim/admin/application_helper.rb +1 -0
  69. data/app/helpers/decidim/admin/filterable_helper.rb +35 -27
  70. data/app/helpers/decidim/admin/icon_link_helper.rb +1 -1
  71. data/app/helpers/decidim/admin/newsletters_helper.rb +3 -1
  72. data/app/helpers/decidim/admin/resource_scope_helper.rb +43 -0
  73. data/app/helpers/decidim/admin/settings_helper.rb +52 -59
  74. data/app/helpers/decidim/admin/uploader_image_dimensions_helper.rb +30 -0
  75. data/app/models/decidim/admin/fake_newsletter.rb +49 -0
  76. data/app/permissions/decidim/admin/permissions.rb +7 -1
  77. data/app/presenters/decidim/admin/dashboard_metric_charts_presenter.rb +57 -0
  78. data/app/queries/decidim/admin/active_users_counter.rb +35 -0
  79. data/app/queries/decidim/admin/newsletter_recipients.rb +5 -8
  80. data/app/views/decidim/admin/attachment_collections/index.html.erb +1 -1
  81. data/app/views/decidim/admin/authorization_workflows/index.html.erb +1 -0
  82. data/app/views/decidim/admin/categories/index.html.erb +1 -1
  83. data/app/views/decidim/admin/components/_component.html.erb +5 -0
  84. data/app/views/decidim/admin/components/_form.html.erb +4 -0
  85. data/app/views/decidim/admin/components/_settings_fields.html.erb +2 -2
  86. data/app/views/decidim/admin/components/index.html.erb +1 -0
  87. data/app/views/decidim/admin/dashboard/show.html.erb +35 -10
  88. data/app/views/decidim/admin/exports/_dropdown.html.erb +6 -2
  89. data/app/views/decidim/admin/impersonatable_users/index.html.erb +2 -2
  90. data/app/views/decidim/admin/metrics/_metrics.html.erb +21 -0
  91. data/app/views/decidim/admin/metrics/index.html.erb +7 -0
  92. data/app/views/decidim/admin/newsletter_templates/index.html.erb +28 -0
  93. data/app/views/decidim/admin/newsletter_templates/show.html.erb +12 -0
  94. data/app/views/decidim/admin/newsletters/_form.html.erb +1 -7
  95. data/app/views/decidim/admin/newsletters/edit.html.erb +1 -1
  96. data/app/views/decidim/admin/newsletters/index.html.erb +1 -1
  97. data/app/views/decidim/admin/newsletters/new.html.erb +1 -1
  98. data/app/views/decidim/admin/officializations/_show_email_modal.html.erb +31 -0
  99. data/app/views/decidim/admin/officializations/index.html.erb +7 -3
  100. data/app/views/decidim/admin/officializations/show_email.html.erb +2 -0
  101. data/app/views/decidim/admin/organization/_form.html.erb +21 -0
  102. data/app/views/decidim/admin/organization_appearance/_form.html.erb +2 -72
  103. data/app/views/decidim/admin/organization_appearance/form/_colors.html.erb +23 -0
  104. data/app/views/decidim/admin/organization_appearance/form/_images.html.erb +38 -0
  105. data/app/views/decidim/admin/organization_appearance/form/_minimap.html.erb +46 -0
  106. data/app/views/decidim/admin/resource_permissions/_options_form.html.erb +1 -1
  107. data/app/views/decidim/admin/share_tokens/_share_tokens.html.erb +57 -0
  108. data/app/views/decidim/admin/shared/_filters.html.erb +3 -3
  109. data/app/views/decidim/admin/shared/_gallery.html.erb +21 -0
  110. data/app/views/decidim/admin/static_pages/_form.html.erb +1 -1
  111. data/app/views/decidim/admin/user_groups/index.html.erb +4 -4
  112. data/app/views/decidim/admin/users_statistics/_users_count.html.erb +39 -0
  113. data/app/views/layouts/decidim/admin/_application.html.erb +1 -0
  114. data/app/views/layouts/decidim/admin/_header.html.erb +3 -0
  115. data/app/views/layouts/decidim/admin/_title_bar.html.erb +20 -10
  116. data/app/views/layouts/decidim/admin/newsletters.erb +1 -1
  117. data/config/locales/am-ET.yml +1 -0
  118. data/config/locales/ar.yml +12 -45
  119. data/config/locales/bg-BG.yml +16 -0
  120. data/config/locales/bg.yml +131 -0
  121. data/config/locales/ca.yml +84 -46
  122. data/config/locales/cs.yml +175 -137
  123. data/config/locales/da-DK.yml +1 -0
  124. data/config/locales/da.yml +1 -0
  125. data/config/locales/de.yml +150 -56
  126. data/config/locales/el.yml +814 -0
  127. data/config/locales/en.yml +84 -46
  128. data/config/locales/eo-UY.yml +0 -1
  129. data/config/locales/eo.yml +51 -0
  130. data/config/locales/es-MX.yml +84 -46
  131. data/config/locales/es-PY.yml +84 -46
  132. data/config/locales/es.yml +84 -46
  133. data/config/locales/et-EE.yml +1 -0
  134. data/config/locales/et.yml +1 -0
  135. data/config/locales/eu.yml +30 -59
  136. data/config/locales/fi-plain.yml +84 -46
  137. data/config/locales/fi.yml +98 -60
  138. data/config/locales/fr-CA.yml +847 -0
  139. data/config/locales/fr.yml +126 -51
  140. data/config/locales/ga-IE.yml +1 -0
  141. data/config/locales/gl.yml +156 -42
  142. data/config/locales/hr-HR.yml +1 -0
  143. data/config/locales/hr.yml +1 -0
  144. data/config/locales/hu.yml +55 -46
  145. data/config/locales/id-ID.yml +12 -41
  146. data/config/locales/is-IS.yml +10 -42
  147. data/config/locales/is.yml +568 -0
  148. data/config/locales/it.yml +106 -85
  149. data/config/locales/ja-JP.yml +855 -0
  150. data/config/locales/ja.yml +847 -0
  151. data/config/locales/ko-KR.yml +1 -0
  152. data/config/locales/ko.yml +1 -0
  153. data/config/locales/lt-LT.yml +1 -0
  154. data/config/locales/lt.yml +1 -0
  155. data/config/locales/lv.yml +795 -0
  156. data/config/locales/mt-MT.yml +1 -0
  157. data/config/locales/mt.yml +1 -0
  158. data/config/locales/nl.yml +74 -46
  159. data/config/locales/no.yml +108 -83
  160. data/config/locales/om-ET.yml +1 -0
  161. data/config/locales/pl.yml +354 -233
  162. data/config/locales/pt-BR.yml +13 -42
  163. data/config/locales/pt.yml +321 -231
  164. data/config/locales/ro-RO.yml +810 -0
  165. data/config/locales/ru.yml +11 -44
  166. data/config/locales/si-LK.yml +1 -0
  167. data/config/locales/sk-SK.yml +823 -0
  168. data/config/locales/sk.yml +802 -0
  169. data/config/locales/sl.yml +162 -0
  170. data/config/locales/so-SO.yml +1 -0
  171. data/config/locales/sr-CS.yml +586 -0
  172. data/config/locales/sv.yml +134 -54
  173. data/config/locales/sw-KE.yml +1 -0
  174. data/config/locales/ti-ER.yml +1 -0
  175. data/config/locales/tr-TR.yml +139 -50
  176. data/config/locales/uk.yml +10 -42
  177. data/config/locales/vi-VN.yml +1 -0
  178. data/config/locales/vi.yml +1 -0
  179. data/config/locales/zh-CN.yml +845 -0
  180. data/config/locales/zh-TW.yml +1 -0
  181. data/config/routes.rb +14 -3
  182. data/lib/decidim/admin/engine.rb +12 -9
  183. data/lib/decidim/admin/form_builder.rb +2 -2
  184. data/lib/decidim/admin/test/manage_attachment_collections_examples.rb +1 -1
  185. data/lib/decidim/admin/test/manage_component_permissions_examples.rb +15 -15
  186. data/lib/decidim/admin/version.rb +1 -1
  187. metadata +85 -33
  188. data/app/commands/decidim/admin/create_oauth_application.rb +0 -36
  189. data/app/commands/decidim/admin/destroy_oauth_application.rb +0 -39
  190. data/app/commands/decidim/admin/update_oauth_application.rb +0 -39
  191. data/app/controllers/decidim/admin/oauth_applications_controller.rb +0 -90
  192. data/app/forms/decidim/admin/oauth_application_form.rb +0 -32
  193. data/app/views/decidim/admin/oauth_applications/_form.html.erb +0 -19
  194. data/app/views/decidim/admin/oauth_applications/edit.html.erb +0 -13
  195. data/app/views/decidim/admin/oauth_applications/index.html.erb +0 -40
  196. data/app/views/decidim/admin/oauth_applications/new.html.erb +0 -13
  197. data/app/views/decidim/admin/oauth_applications/show.html.erb +0 -27
@@ -13,6 +13,7 @@ module Decidim
13
13
  include Decidim::MapHelper
14
14
  include Decidim::Admin::LogRenderHelper
15
15
  include Decidim::Admin::UserRolesHelper
16
+ include Decidim::Admin::ResourceScopeHelper
16
17
 
17
18
  def title
18
19
  current_organization.name
@@ -5,44 +5,46 @@ module Decidim
5
5
  # Helper that provides methods related to Decidim::Admin::Filterable concern.
6
6
  module FilterableHelper
7
7
  # Renders the filters selector with tags in the admin panel.
8
- def admin_filter_selector
9
- render partial: "decidim/admin/shared/filters"
8
+ def admin_filter_selector(i18n_ctx = nil)
9
+ render partial: "decidim/admin/shared/filters", locals: { i18n_ctx: i18n_ctx }
10
10
  end
11
11
 
12
12
  # Builds a tree of links from Decidim::Admin::Filterable::filters_with_values
13
- def submenu_options_tree
13
+ def submenu_options_tree(i18n_ctx = nil)
14
+ i18n_scope = filterable_i18n_scope_from_ctx(i18n_ctx)
15
+
14
16
  filters_with_values.each_with_object({}) do |(filter, values), hash|
15
- link = filter_link_label(filter)
17
+ link = filter_link_label(filter, i18n_scope)
16
18
  hash[link] = if values.is_a?(Array)
17
- build_submenu_options_tree_from_array(filter, values)
19
+ build_submenu_options_tree_from_array(filter, values, i18n_scope)
18
20
  elsif values.is_a?(Hash)
19
- build_submenu_options_tree_from_hash(filter, values)
21
+ build_submenu_options_tree_from_hash(filter, values, i18n_scope)
20
22
  end
21
23
  end
22
24
  end
23
25
 
24
26
  # Builds a tree of links from an array. The tree will have only one level.
25
- def build_submenu_options_tree_from_array(filter, values)
27
+ def build_submenu_options_tree_from_array(filter, values, i18n_scope)
26
28
  links = []
27
- links += extra_dropdown_submenu_options_items(filter)
28
- links += values.map { |value| filter_link_value(filter, value) }
29
+ links += extra_dropdown_submenu_options_items(filter, i18n_scope)
30
+ links += values.map { |value| filter_link_value(filter, value, i18n_scope) }
29
31
  links.each_with_object({}) { |link, hash| hash[link] = nil }
30
32
  end
31
33
 
32
34
  # To be overriden. Useful for adding links that do not match with the filter.
33
35
  # Must return an Array.
34
- def extra_dropdown_submenu_options_items(_filter)
36
+ def extra_dropdown_submenu_options_items(_filter, _i18n_scope)
35
37
  []
36
38
  end
37
39
 
38
40
  # Builds a tree of links from an Hash. The tree can have many levels.
39
- def build_submenu_options_tree_from_hash(filter, values)
41
+ def build_submenu_options_tree_from_hash(filter, values, i18n_scope)
40
42
  values.each_with_object({}) do |(key, value), hash|
41
- link = filter_link_value(filter, key)
43
+ link = filter_link_value(filter, key, i18n_scope)
42
44
  hash[link] = if value.nil?
43
45
  nil
44
46
  elsif value.is_a?(Hash)
45
- build_submenu_options_tree_from_hash(filter, value)
47
+ build_submenu_options_tree_from_hash(filter, value, i18n_scope)
46
48
  end
47
49
  end
48
50
  end
@@ -63,21 +65,21 @@ module Decidim
63
65
  end
64
66
  end
65
67
 
66
- def filter_link_label(filter)
67
- link_to(i18n_filter_label(filter), href: "#")
68
+ def filter_link_label(filter, i18n_scope)
69
+ link_to(i18n_filter_label(filter, i18n_scope), href: "#")
68
70
  end
69
71
 
70
- def filter_link_value(filter, value)
71
- link_to(i18n_filter_value(filter, value), query_params_with(filter => value))
72
+ def filter_link_value(filter, value, i18n_scope)
73
+ link_to(i18n_filter_value(filter, value, i18n_scope), query_params_with(filter => value))
72
74
  end
73
75
 
74
- def i18n_filter_label(filter)
75
- t("decidim.admin.filters.#{filter}.label")
76
+ def i18n_filter_label(filter, i18n_scope)
77
+ t("#{i18n_scope}.#{filter}.label")
76
78
  end
77
79
 
78
- def i18n_filter_value(filter, value)
79
- if I18n.exists?("decidim.admin.filters.#{filter}.values.#{value}")
80
- t(value, scope: "decidim.admin.filters.#{filter}.values")
80
+ def i18n_filter_value(filter, value, i18n_scope)
81
+ if I18n.exists?("#{i18n_scope}.#{filter}.values.#{value}")
82
+ t(value, scope: "#{i18n_scope}.#{filter}.values")
81
83
  else
82
84
  find_dynamic_translation(filter, value)
83
85
  end
@@ -94,16 +96,16 @@ module Decidim
94
96
  html.join.html_safe
95
97
  end
96
98
 
97
- def applied_filters_tags
99
+ def applied_filters_tags(i18n_ctx)
98
100
  ransack_params.slice(*filters).map do |filter, value|
99
- applied_filter_tag(filter, value)
101
+ applied_filter_tag(filter, value, filterable_i18n_scope_from_ctx(i18n_ctx))
100
102
  end.join.html_safe
101
103
  end
102
104
 
103
- def applied_filter_tag(filter, value)
105
+ def applied_filter_tag(filter, value, i18n_scope)
104
106
  content_tag(:span, class: "label secondary") do
105
- concat "#{i18n_filter_label(filter)}: "
106
- concat i18n_filter_value(filter, value)
107
+ concat "#{i18n_filter_label(filter, i18n_scope)}: "
108
+ concat i18n_filter_value(filter, value, i18n_scope)
107
109
  concat remove_filter_icon_link(filter)
108
110
  end
109
111
  end
@@ -116,6 +118,12 @@ module Decidim
116
118
  class: "action-icon--remove"
117
119
  )
118
120
  end
121
+
122
+ def filterable_i18n_scope_from_ctx(i18n_ctx)
123
+ i18n_scope = "decidim.admin.filters"
124
+ i18n_scope += ".#{i18n_ctx}" if i18n_ctx
125
+ i18n_scope
126
+ end
119
127
  end
120
128
  end
121
129
  end
@@ -23,7 +23,7 @@ module Decidim
23
23
  target: options[:target]) do
24
24
  content_tag(:span, data: { tooltip: true, disable_hover: false, click_open: false },
25
25
  title: title) do
26
- icon(icon_name)
26
+ icon(icon_name, aria_label: title, role: "img")
27
27
  end
28
28
  end
29
29
  end
@@ -141,9 +141,11 @@ module Decidim
141
141
  end
142
142
 
143
143
  def newsletter_recipients_count_callout_args
144
+ spinner = "<span id='recipients_count_spinner' class='loading-spinner hide'></span>"
145
+ body = "#{t("recipients_count", scope: "decidim.admin.newsletters.select_recipients_to_deliver", count: recipients_count_query)} #{spinner}"
144
146
  {
145
147
  announcement: {
146
- body: t("recipients_count", scope: "decidim.admin.newsletters.select_recipients_to_deliver", count: recipients_count_query)
148
+ body: body
147
149
  },
148
150
  callout_class: "warning"
149
151
  }
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This module includes helpers to show scopes in admin
6
+ module ResourceScopeHelper
7
+ # Public: This helper shows the th with the scope label.
8
+ #
9
+ # scope_label - I18n translation to show
10
+ #
11
+ def th_resource_scope_label(scope_label = t("decidim.admin.resources.index.headers.scope"))
12
+ return unless resource_with_scopes_enabled?
13
+
14
+ content_tag(:th, scope_label)
15
+ end
16
+
17
+ # Public: This helper shows the td for the given scope.
18
+ #
19
+ # current_scope - Scope object to show
20
+ #
21
+ def td_resource_scope_for(current_scope)
22
+ return unless resource_with_scopes_enabled?
23
+
24
+ scope_name = if current_scope
25
+ translated_attribute(current_scope.name)
26
+ else
27
+ t("decidim.scopes.global")
28
+ end
29
+ content_tag(:td, scope_name)
30
+ end
31
+
32
+ private
33
+
34
+ def resource_with_scopes_enabled?
35
+ if defined? current_component
36
+ current_component.scopes_enabled? || current_participatory_space.scopes_enabled?
37
+ else
38
+ current_participatory_space.scopes_enabled?
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -5,11 +5,15 @@ module Decidim
5
5
  # This class contains helpers needed in order for component settings to
6
6
  # properly render.
7
7
  module SettingsHelper
8
+ include Decidim::ScopesHelper
9
+
8
10
  TYPES = {
9
11
  boolean: :check_box,
10
12
  integer: :number_field,
11
13
  string: :text_field,
12
- text: :text_area
14
+ text: :text_area,
15
+ scope: :scope_field,
16
+ enum: :collection_radio_buttons
13
17
  }.freeze
14
18
 
15
19
  # Public: Renders a form field that matches a settings attribute's
@@ -22,67 +26,67 @@ module Decidim
22
26
  # options - Extra options to be passed to the field helper.
23
27
  #
24
28
  # Returns a rendered form field.
25
- def settings_attribute_input(form, attribute, name, options = {})
26
- if name == :amendments_visibility
27
- amendments_visibility_form_field(form, options)
28
- elsif attribute.translated?
29
- form_method = form_method_for_attribute(attribute)
30
- tab_options = { tabs_id: "#{options[:tabs_prefix]}-#{name}-tabs" }
31
- extra_options = tab_options.merge(extra_options_for_type(form_method))
32
- form.send(:translated, form_method, name, options.merge(extra_options))
33
- else
34
- form_method = form_method_for_attribute(attribute)
35
- extra_options = extra_options_for(name).merge(extra_options_for_type(form_method))
36
- form.send(form_method, name, options.merge(extra_options))
29
+ def settings_attribute_input(form, attribute, name, i18n_scope, options = {})
30
+ form_method = form_method_for_attribute(attribute)
31
+
32
+ container_class = "#{name}_container"
33
+ if options[:readonly]
34
+ container_class += " readonly_container"
35
+ help_text = text_for_setting(name, "readonly", i18n_scope)
37
36
  end
38
- end
37
+ help_text ||= text_for_setting(name, "help", i18n_scope)
38
+ help_text_options = help_text ? { help_text: help_text } : {}
39
39
 
40
- # Returns a translation or nil. If nil, ZURB Foundation won't add the help_text.
41
- def help_text_for_component_setting(field_name, settings_name, component_name)
42
- key = "decidim.components.#{component_name}.settings.#{settings_name}.#{field_name}_help"
43
- return t(key) if I18n.exists?(key)
40
+ options = { label: t(name, scope: i18n_scope) }
41
+ .merge(help_text_options)
42
+ .merge(extra_options_for_type(form_method))
43
+ .merge(options)
44
+
45
+ content_tag(:div, class: container_class) do
46
+ if attribute.translated?
47
+ options[:tabs_id] = "#{options.delete(:tabs_prefix)}-#{name}-tabs"
48
+ form.send(:translated, form_method, name, options)
49
+ elsif form_method == :collection_radio_buttons
50
+ render_enum_form_field(form, attribute, name, i18n_scope, options)
51
+ elsif form_method == :scope_field
52
+ scopes_picker_field(form, name)
53
+ else
54
+ form.send(form_method, name, options)
55
+ end
56
+ end.html_safe
44
57
  end
45
58
 
46
59
  private
47
60
 
48
- # Returns a radio buttons collection input for the component's step setting
49
- # :amendments_visibility; all wrap in a label tag and with help text.
50
- def amendments_visibility_form_field(form, options)
51
- html = label_tag(:amendments_visibility) do
61
+ # Returns a radio buttons collection input for the given attribute
62
+ def render_enum_form_field(form, attribute, name, i18n_scope, options)
63
+ html = label_tag(name) do
52
64
  concat options[:label]
53
65
  concat tag(:br)
54
- concat form.collection_radio_buttons(:amendments_visibility,
55
- Decidim::Amendment::VisibilityStepSetting.options,
66
+ concat form.collection_radio_buttons(name,
67
+ build_enum_choices(name, i18n_scope, attribute.build_choices),
56
68
  :last,
57
69
  :first,
58
- { checked: form.object.amendments_visibility },
59
- amendments_extra_options) { |b| b.label { b.radio_button + b.text } }
70
+ { checked: form.object.send(name) },
71
+ options) { |b| b.label { b.radio_button + b.text } }
60
72
  end
61
- html << content_tag(:p, help_text_for_component_setting(:amendments_visibility, :step, :proposals), class: "help-text")
62
- html.html_safe
73
+ html << content_tag(:p, options[:help_text], class: "help-text") if options[:help_text]
74
+ html
75
+ end
76
+
77
+ # Returns a translation or nil. If nil, ZURB Foundation won't add the help_text.
78
+ def text_for_setting(name, suffix, i18n_scope)
79
+ key = "#{i18n_scope}.#{name}_#{suffix}"
80
+ return t(key) if I18n.exists?(key)
63
81
  end
64
82
 
83
+ # Returns the FormBuilder's method used to render
65
84
  def form_method_for_attribute(attribute)
66
85
  return :editor if attribute.type.to_sym == :text && attribute.editor?
67
86
 
68
87
  TYPES[attribute.type.to_sym]
69
88
  end
70
89
 
71
- # Handles special cases.
72
- # Returns an empty Hash or a Hash with extra HTML options.
73
- def extra_options_for(field_name)
74
- case field_name
75
- when :participatory_texts_enabled
76
- participatory_texts_extra_options
77
- when :amendment_creation_enabled,
78
- :amendment_reaction_enabled,
79
- :amendment_promotion_enabled
80
- amendments_extra_options
81
- else
82
- {}
83
- end
84
- end
85
-
86
90
  # Handles special cases.
87
91
  # Returns an empty Hash or a Hash with extra HTML options.
88
92
  def extra_options_for_type(input_type)
@@ -94,22 +98,11 @@ module Decidim
94
98
  end
95
99
  end
96
100
 
97
- # Marks :participatory_texts_enabled setting with a CSS class if the
98
- # Proposals component has existing proposals, so it can be identified
99
- # in "decidim/admin/form.js". Also, adds a help_text.
100
- def participatory_texts_extra_options
101
- return {} unless Decidim::Proposals::Proposal.where(component: @component).any?
102
-
103
- {
104
- class: "participatory_texts_disabled",
105
- help_text: help_text_for_component_setting(:participatory_texts_disabled, :global, :proposals)
106
- }
107
- end
108
-
109
- # Marks component_step_settings related to amendments with a CSS class,
110
- # so they can be identified in "decidim/admin/form.js".
111
- def amendments_extra_options
112
- { class: "amendments_step_settings" }
101
+ # Build options for enum attributes
102
+ def build_enum_choices(name, i18n_scope, choices)
103
+ choices.map do |choice|
104
+ [t("#{name}_choices.#{choice}", scope: i18n_scope), choice]
105
+ end
113
106
  end
114
107
  end
115
108
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This class contains helpers needed to obtain information about
6
+ # image dimensions from the processors defined in the specific image's Uploader class
7
+ module UploaderImageDimensionsHelper
8
+ # Find the dimensions info of a model's image field and get the first value for dimensions ([w, h])
9
+ #
10
+ # model - The model to which the image belongs (An instance of `ActiveRecord`)
11
+ # image_name - The attribute name for the image (either a `symbol` or a `string`)
12
+ #
13
+ # Returns an integer array with [width, height]
14
+ def image_dimensions(model, image_name)
15
+ versions = model.send(image_name).dimensions_info
16
+ [:small, :medium, :default].map { |v| versions.dig(v, :dimensions) }.compact.first
17
+ end
18
+
19
+ # Find the first value for the processed image width
20
+ def image_width(model, image_name)
21
+ image_dimensions(model, image_name)[0]
22
+ end
23
+
24
+ # Find the first value for the processed image height
25
+ def image_height(model, image_name)
26
+ image_dimensions(model, image_name)[1]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This class is used to generate fake newsletters and data to preview
6
+ # newsletter templates.
7
+ class FakeNewsletter
8
+ def initialize(organization, manifest)
9
+ @organization = organization
10
+ @manifest = manifest
11
+ end
12
+
13
+ def id
14
+ 1
15
+ end
16
+
17
+ def template
18
+ @template ||= Decidim::ContentBlock.new(
19
+ in_preview: true,
20
+ manifest_name: manifest.name,
21
+ scope_name: :newsletter_template,
22
+ settings: manifest.settings.attributes.inject({}) do |acc, (name, attrs)|
23
+ value = if attrs.preview.respond_to?(:call)
24
+ attrs.preview.call
25
+ else
26
+ attrs.preview
27
+ end
28
+
29
+ acc.update(name => value)
30
+ end
31
+ )
32
+ end
33
+
34
+ def subject
35
+ organization.available_locales.inject({}) do |acc, locale|
36
+ acc.update(locale => "Lorem ipsum")
37
+ end
38
+ end
39
+
40
+ def sent_at
41
+ nil
42
+ end
43
+
44
+ private
45
+
46
+ attr_reader :organization, :manifest
47
+ end
48
+ end
49
+ end
@@ -31,6 +31,7 @@ module Decidim
31
31
 
32
32
  if user.admin? && admin_terms_accepted?
33
33
  allow! if read_admin_log_action?
34
+ allow! if read_metrics_action?
34
35
  allow! if static_page_action?
35
36
  allow! if organization_action?
36
37
  allow! if user_action?
@@ -44,13 +45,13 @@ module Decidim
44
45
  allow! if permission_action.subject == :scope_type
45
46
  allow! if permission_action.subject == :area
46
47
  allow! if permission_action.subject == :area_type
47
- allow! if permission_action.subject == :oauth_application
48
48
  allow! if permission_action.subject == :user_group
49
49
  allow! if permission_action.subject == :officialization
50
50
  allow! if permission_action.subject == :authorization
51
51
  allow! if permission_action.subject == :authorization_workflow
52
52
  allow! if permission_action.subject == :static_page_topic
53
53
  allow! if permission_action.subject == :help_sections
54
+ allow! if permission_action.subject == :share_token
54
55
  end
55
56
 
56
57
  permission_action
@@ -96,6 +97,11 @@ module Decidim
96
97
  end
97
98
  end
98
99
 
100
+ def read_metrics_action?
101
+ permission_action.subject == :metrics &&
102
+ permission_action.action == :read
103
+ end
104
+
99
105
  def read_admin_log_action?
100
106
  permission_action.subject == :admin_log &&
101
107
  permission_action.action == :read