decidim-core 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/decidim_core_manifest.js +1 -0
  3. data/app/assets/images/decidim/process.svg +10 -0
  4. data/app/assets/javascripts/decidim.js.es6 +2 -0
  5. data/app/assets/javascripts/decidim/editor.js.es6 +2 -2
  6. data/app/assets/javascripts/decidim/filters.js.es6 +1 -1
  7. data/app/assets/javascripts/decidim/form_filter.component.js.es6 +26 -5
  8. data/app/assets/javascripts/decidim/form_filter.component.test.js +1 -18
  9. data/app/assets/javascripts/decidim/foundation.js.es6 +1 -0
  10. data/app/assets/javascripts/decidim/history.js.es6 +35 -0
  11. data/app/assets/javascripts/decidim/orders.js.es6 +28 -0
  12. data/app/assets/stylesheets/decidim/_decidim.scss +1 -0
  13. data/app/assets/stylesheets/decidim/email.css +21 -3
  14. data/app/assets/stylesheets/decidim/extras/_leaflet.scss +4 -2
  15. data/app/assets/stylesheets/decidim/extras/_quill.scss +8 -0
  16. data/app/assets/stylesheets/decidim/extras/_register_form.scss +9 -0
  17. data/app/assets/stylesheets/decidim/modules/_buttons.scss +19 -3
  18. data/app/assets/stylesheets/decidim/utils/_mixins.scss +8 -4
  19. data/app/commands/decidim/authorize_user.rb +9 -4
  20. data/app/commands/decidim/create_omniauth_registration.rb +4 -2
  21. data/app/commands/decidim/create_registration.rb +4 -1
  22. data/app/commands/decidim/invite_user.rb +3 -1
  23. data/app/commands/decidim/update_notifications_settings.rb +31 -0
  24. data/app/constraints/decidim/current_feature.rb +16 -15
  25. data/app/controllers/concerns/decidim/action_authorization.rb +73 -0
  26. data/app/controllers/concerns/decidim/feature_settings.rb +2 -5
  27. data/app/controllers/concerns/decidim/needs_authorization.rb +5 -1
  28. data/app/controllers/concerns/decidim/user_profile.rb +1 -0
  29. data/app/controllers/decidim/application_controller.rb +12 -0
  30. data/app/controllers/decidim/authorizations_controller.rb +10 -12
  31. data/app/controllers/decidim/cookie_policy_controller.rb +15 -0
  32. data/app/controllers/decidim/devise/confirmations_controller.rb +4 -0
  33. data/app/controllers/decidim/devise/invitations_controller.rb +4 -0
  34. data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +10 -3
  35. data/app/controllers/decidim/devise/passwords_controller.rb +4 -0
  36. data/app/controllers/decidim/devise/registrations_controller.rb +21 -0
  37. data/app/controllers/decidim/devise/sessions_controller.rb +4 -0
  38. data/app/controllers/decidim/notifications_settings_controller.rb +31 -0
  39. data/app/controllers/decidim/pages_controller.rb +17 -6
  40. data/app/controllers/decidim/participatory_processes_controller.rb +5 -5
  41. data/app/forms/decidim/notifications_settings_form.rb +17 -0
  42. data/app/forms/decidim/registration_form.rb +2 -1
  43. data/app/helpers/decidim/action_authorization_helper.rb +82 -0
  44. data/app/helpers/decidim/application_helper.rb +2 -0
  45. data/app/helpers/decidim/authorization_form_helper.rb +1 -1
  46. data/app/helpers/decidim/cookies_helper.rb +11 -0
  47. data/app/helpers/decidim/decidim_form_helper.rb +18 -0
  48. data/app/helpers/decidim/language_chooser_helper.rb +18 -0
  49. data/app/helpers/decidim/layout_helper.rb +0 -5
  50. data/app/helpers/decidim/localized_locales_helper.rb +1 -1
  51. data/app/helpers/decidim/meta_tags_helper.rb +104 -0
  52. data/app/helpers/decidim/orders_helper.rb +28 -0
  53. data/app/helpers/decidim/resource_helper.rb +46 -6
  54. data/app/mailers/decidim/application_mailer.rb +2 -2
  55. data/app/mailers/decidim/decidim_devise_mailer.rb +0 -1
  56. data/app/mailers/decidim/newsletter_mailer.rb +24 -0
  57. data/app/models/decidim/abilities/everyone.rb +2 -0
  58. data/app/models/decidim/feature.rb +30 -0
  59. data/app/models/decidim/newsletter.rb +24 -0
  60. data/app/models/decidim/organization.rb +2 -0
  61. data/app/models/decidim/user.rb +3 -2
  62. data/app/queries/decidim/highlighted_participatory_processes.rb +10 -0
  63. data/app/queries/decidim/promoted_participatory_processes.rb +9 -0
  64. data/app/queries/decidim/public_participatory_processes.rb +10 -0
  65. data/app/services/decidim/action_authorizer.rb +102 -0
  66. data/app/services/decidim/resource_search.rb +1 -1
  67. data/app/uploaders/decidim/official_image_footer_uploader.rb +12 -0
  68. data/app/uploaders/decidim/official_image_header_uploader.rb +12 -0
  69. data/app/validators/etiquette_validator.rb +42 -0
  70. data/app/views/decidim/account/show.html.erb +1 -1
  71. data/app/views/decidim/authorizations/index.html.erb +4 -4
  72. data/app/views/decidim/authorizations/new.html.erb +2 -2
  73. data/app/views/decidim/cookie_policy/accept.js.erb +3 -0
  74. data/app/views/decidim/devise/confirmations/new.html.erb +3 -1
  75. data/app/views/decidim/devise/invitations/edit.html.erb +1 -1
  76. data/app/views/decidim/devise/omniauth_registrations/new.html.erb +1 -1
  77. data/app/views/decidim/devise/passwords/edit.html.erb +1 -1
  78. data/app/views/decidim/devise/passwords/new.html.erb +3 -1
  79. data/app/views/decidim/devise/registrations/edit.html.erb +2 -1
  80. data/app/views/decidim/devise/registrations/new.html.erb +13 -1
  81. data/app/views/decidim/devise/sessions/new.html.erb +3 -1
  82. data/app/views/decidim/newsletter_mailer/newsletter.html.erb +5 -0
  83. data/app/views/decidim/notifications_settings/show.html.erb +26 -0
  84. data/app/views/decidim/pages/index.html.erb +34 -0
  85. data/app/views/decidim/participatory_process_steps/index.html.erb +1 -1
  86. data/app/views/decidim/participatory_processes/_participatory_process.html.erb +4 -2
  87. data/app/views/decidim/participatory_processes/_promoted_process.html.erb +1 -1
  88. data/app/views/decidim/participatory_processes/index.html.erb +3 -3
  89. data/app/views/decidim/participatory_processes/show.html.erb +30 -9
  90. data/app/views/decidim/shared/_action_authorization_modal.html.erb +55 -0
  91. data/app/views/decidim/shared/_login_modal.html.erb +2 -3
  92. data/app/views/decidim/shared/_orders.html.erb +15 -0
  93. data/app/views/decidim/shared/_share_modal.html.erb +33 -0
  94. data/app/views/devise/mailer/organization_admin_invitation_instructions.html.erb +1 -1
  95. data/app/views/layouts/decidim/_application.html.erb +12 -0
  96. data/app/views/layouts/decidim/_cookie_warning.html.erb +8 -0
  97. data/app/views/layouts/decidim/_footer.html.erb +6 -0
  98. data/app/views/layouts/decidim/_header.html.erb +7 -9
  99. data/app/views/layouts/decidim/_language_chooser.html.erb +3 -3
  100. data/app/views/layouts/decidim/_logo.html.erb +1 -1
  101. data/app/views/layouts/decidim/_mailer_logo.html.erb +31 -0
  102. data/app/views/layouts/decidim/_main_nav.html.erb +11 -0
  103. data/app/views/layouts/decidim/_process_header.html.erb +9 -7
  104. data/app/views/layouts/decidim/_social_media_links.html.erb +39 -0
  105. data/app/views/layouts/decidim/_social_meta.html.erb +8 -8
  106. data/app/views/layouts/decidim/mailer.html.erb +110 -62
  107. data/app/views/layouts/decidim/participatory_process.html.erb +14 -3
  108. data/app/views/layouts/decidim/user_profile.html.erb +1 -0
  109. data/app/views/pages/decidim_page.html.erb +5 -0
  110. data/app/views/pages/home.html.erb +4 -0
  111. data/app/views/pages/home/_extended.html.erb +2 -2
  112. data/app/views/pages/home/_footer_sub_hero.html.erb +12 -0
  113. data/app/views/pages/home/_hero.html.erb +2 -2
  114. data/app/views/pages/home/_highlighted_processes.html.erb +2 -2
  115. data/config/i18n-tasks.yml +6 -2
  116. data/config/initializers/invisible_captcha.rb +10 -0
  117. data/config/initializers/mail_previews.rb +4 -0
  118. data/config/locales/ca.yml +129 -23
  119. data/config/locales/en.yml +98 -13
  120. data/config/locales/es.yml +128 -22
  121. data/config/locales/eu.yml +5 -0
  122. data/config/routes.rb +13 -5
  123. data/db/migrate/20170131134349_add_action_permissions_to_decidim_features.rb +5 -0
  124. data/db/migrate/20170202084913_add_comments_and_replies_notifications_to_users.rb +6 -0
  125. data/db/migrate/20170203150545_add_newsletter_notifications_to_users.rb +5 -0
  126. data/db/migrate/20170206083118_rename_extra_info_on_processes.rb +12 -0
  127. data/db/migrate/20170206142116_add_published_at_to_decidim_features.rb +6 -0
  128. data/db/migrate/20170207091021_add_social_media_handlers_to_organization.rb +8 -0
  129. data/db/migrate/20170207093048_add_organization_logo_and_url.rb +7 -0
  130. data/db/migrate/20170213081133_create_decidim_newsletters.rb +15 -0
  131. data/db/seeds.rb +29 -4
  132. data/lib/decidim/attributes.rb +6 -0
  133. data/lib/decidim/attributes/time_with_zone.rb +13 -0
  134. data/lib/decidim/authorable.rb +2 -2
  135. data/lib/decidim/core.rb +11 -0
  136. data/lib/decidim/core/api.rb +11 -0
  137. data/lib/decidim/core/api/author_interface.rb +11 -0
  138. data/lib/decidim/core/api/localized_string_type.rb +11 -0
  139. data/{app/types/decidim → lib/decidim/core/api}/process_step_type.rb +2 -2
  140. data/{app/types/decidim → lib/decidim/core/api}/process_type.rb +1 -1
  141. data/{app/types/decidim → lib/decidim/core/api}/session_type.rb +0 -0
  142. data/lib/decidim/core/api/translated_field_type.rb +42 -0
  143. data/{app/types/decidim → lib/decidim/core/api}/user_group_type.rb +1 -1
  144. data/{app/types/decidim → lib/decidim/core/api}/user_type.rb +1 -1
  145. data/lib/decidim/core/engine.rb +7 -1
  146. data/lib/decidim/core/test.rb +1 -0
  147. data/lib/decidim/core/test/factories.rb +41 -8
  148. data/lib/decidim/core/test/shared_examples/localised_email.rb +24 -0
  149. data/lib/decidim/core/version.rb +1 -1
  150. data/lib/decidim/feature_manifest.rb +11 -0
  151. data/{app/validators → lib/decidim}/feature_validator.rb +1 -3
  152. data/lib/decidim/features/base_controller.rb +6 -1
  153. data/lib/decidim/form_builder.rb +166 -1
  154. data/lib/decidim/has_feature.rb +2 -1
  155. data/lib/decidim/resourceable.rb +26 -0
  156. data/vendor/assets/javascripts/morphdom.js +679 -0
  157. metadata +174 -49
  158. data/lib/decidim/has_attachment.rb +0 -32
@@ -11,22 +11,33 @@ module Decidim
11
11
 
12
12
  authorize_resource :public_pages, class: false
13
13
  delegate :page, to: :page_finder
14
- helper_method :page, :participatory_processes, :promoted_participatory_processes, :users
14
+ helper_method :page, :promoted_participatory_processes, :highlighted_participatory_processes, :participatory_processes, :users
15
+
16
+ def index
17
+ @pages = current_organization.static_pages.all.to_a.sort do |a, b|
18
+ a.title[I18n.locale.to_s] <=> b.title[I18n.locale.to_s]
19
+ end
20
+ end
15
21
 
16
22
  def page_finder
17
23
  @page_finder ||= Decidim::PageFinder.new(params[:id], current_organization)
18
24
  end
19
25
 
20
- def promoted_participatory_processes
21
- @promoted_participatory_processes ||= participatory_processes.promoted
26
+ def users
27
+ @users ||= Decidim::User.where(organization: current_organization)
22
28
  end
23
29
 
30
+ # This should be deleted once the statistics are done properly.
24
31
  def participatory_processes
25
- @participatory_processes ||= current_organization.participatory_processes.includes(:active_step).published
32
+ @processes ||= OrganizationParticipatoryProcesses.new(current_organization) | PublicParticipatoryProcesses.new
26
33
  end
27
34
 
28
- def users
29
- @users ||= Decidim::User.where(organization: current_organization)
35
+ def promoted_participatory_processes
36
+ @promoted_processes ||= participatory_processes | PromotedParticipatoryProcesses.new
37
+ end
38
+
39
+ def highlighted_participatory_processes
40
+ @promoted_processes ||= OrganizationParticipatoryProcesses.new(current_organization) | HighlightedParticipatoryProcesses.new
30
41
  end
31
42
  end
32
43
  end
@@ -9,10 +9,10 @@ module Decidim
9
9
 
10
10
  layout "layouts/decidim/participatory_process", only: [:show]
11
11
 
12
- helper_method :participatory_processes, :promoted_processes
13
-
14
12
  skip_after_action :verify_participatory_process, only: [:index]
15
13
 
14
+ helper_method :participatory_processes, :promoted_participatory_processes
15
+
16
16
  def index
17
17
  authorize! :read, ParticipatoryProcess
18
18
  end
@@ -24,11 +24,11 @@ module Decidim
24
24
  private
25
25
 
26
26
  def participatory_processes
27
- @participatory_processes ||= current_organization.participatory_processes.includes(:active_step).published
27
+ @processes ||= OrganizationParticipatoryProcesses.new(current_organization) | PublicParticipatoryProcesses.new
28
28
  end
29
29
 
30
- def promoted_processes
31
- @promoted_processes ||= participatory_processes.promoted
30
+ def promoted_participatory_processes
31
+ @promoted_processes ||= participatory_processes | PromotedParticipatoryProcesses.new
32
32
  end
33
33
  end
34
34
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # The form object that handles the data behind updating a user's
5
+ # notifications settings in her profile page.
6
+ class NotificationsSettingsForm < Form
7
+ mimic :user
8
+
9
+ attribute :comments_notifications
10
+ attribute :replies_notifications
11
+ attribute :newsletter_notifications
12
+
13
+ validates :comments_notifications, presence: true
14
+ validates :replies_notifications, presence: true
15
+ validates :newsletter_notifications, presence: true
16
+ end
17
+ end
@@ -10,6 +10,7 @@ module Decidim
10
10
  attribute :email, String
11
11
  attribute :password, String
12
12
  attribute :password_confirmation, String
13
+ attribute :newsletter_notifications, Boolean
13
14
  attribute :tos_agreement, Boolean
14
15
 
15
16
  attribute :user_group_name, String
@@ -19,7 +20,7 @@ module Decidim
19
20
  validates :sign_up_as, inclusion: { in: %w(user user_group) }
20
21
  validates :name, presence: true
21
22
  validates :email, presence: true
22
- validates :password, presence: true, confirmation: true
23
+ validates :password, presence: true, confirmation: true, length: { in: Decidim::User.password_length }
23
24
  validates :tos_agreement, allow_nil: false, acceptance: true
24
25
 
25
26
  validates :user_group_name, presence: true, if: :is_user_group?
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+ module Decidim
4
+ module ActionAuthorizationHelper
5
+ # Public: Renders a modal that explains why she can't perform an action,
6
+ # if that's the case. The modal isn't shown by default, and it's usually
7
+ # triggered by `action_authorized_link_to` or `action_authorized_button_to`.
8
+ #
9
+ # action - The action to authenticate against.
10
+ #
11
+ # Returns a String with the modal.
12
+ def action_authorization_modal(action)
13
+ render partial: "decidim/shared/action_authorization_modal",
14
+ locals: { action: action.to_s }
15
+ end
16
+
17
+ # Public: Emulates a `link_to` but conditionally renders a popup modal
18
+ # blocking the action in case the user isn't allowed to perform it.
19
+ #
20
+ # action - The name of the action to authorize against.
21
+ # *arguments - A regular set of arguments that would be provided to
22
+ # `link_to`.
23
+ #
24
+ # Returns a String with the link.
25
+ def action_authorized_link_to(action, *arguments, &block)
26
+ if block_given?
27
+ body = block
28
+ url = arguments[0]
29
+ html_options = arguments[1]
30
+ else
31
+ body = arguments[0]
32
+ url = arguments[1]
33
+ html_options = arguments[2]
34
+ end
35
+
36
+ unless action_authorization(action).ok?
37
+ html_options ||= {}
38
+ html_options["onclick"] = "event.preventDefault();"
39
+ html_options["data-toggle"] = "#{action.to_s.underscore}AuthorizationModal"
40
+ url = ""
41
+ end
42
+
43
+ if block_given?
44
+ link_to(url, html_options, &body)
45
+ else
46
+ link_to(body, url, html_options)
47
+ end
48
+ end
49
+
50
+ # Public: Emulates a `button_to` but conditionally renders a popup modal
51
+ # blocking the action in case the user isn't allowed to perform it.
52
+ #
53
+ # action - The name of the action to authorize against.
54
+ # *arguments - A regular set of arguments that would be provided to
55
+ # `button_to`.
56
+ #
57
+ # Returns a String with the button.
58
+ def action_authorized_button_to(action, *arguments, &block)
59
+ if block_given?
60
+ body = block
61
+ url = arguments[0]
62
+ html_options = arguments[1] || {}
63
+ else
64
+ body = arguments[0]
65
+ url = arguments[1]
66
+ html_options = arguments[2] || {}
67
+ end
68
+
69
+ unless action_authorization(action).ok?
70
+ html_options["onclick"] = "event.preventDefault();"
71
+ html_options["data-toggle"] = "#{action.to_s.underscore}AuthorizationModal"
72
+ url = ""
73
+ end
74
+
75
+ if block_given?
76
+ button_to(url, html_options, &body)
77
+ else
78
+ button_to(body, url, html_options)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -3,6 +3,8 @@
3
3
  module Decidim
4
4
  # Main module to add application-wide helpers.
5
5
  module ApplicationHelper
6
+ include Decidim::MetaTagsHelper
7
+
6
8
  # Truncates a given text respecting its HTML tags.
7
9
  #
8
10
  # text - The String text to be truncated.
@@ -19,7 +19,7 @@ module Decidim
19
19
  }
20
20
 
21
21
  options = default_options.merge(options)
22
- form_for(record, options, &block)
22
+ decidim_form_for(record, options, &block)
23
23
  end
24
24
  end
25
25
  end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+ module Decidim
4
+ # This module includes helpers to verify the acceptance of the cookie policy
5
+ module CookiesHelper
6
+ # Public: Returns true if the cookie policy has been accepted
7
+ def cookies_accepted?
8
+ cookies["decidim-cc"].present?
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # A heper to expose an easy way to add authorization forms in a view.
4
+ module DecidimFormHelper
5
+ # A custom form for that injects client side validations with Abide.
6
+ #
7
+ # record - The object to build the form for.
8
+ # options - A Hash of options to pass to the form builder.
9
+ # &block - The block to execute as content of the form.
10
+ #
11
+ # Returns a String.
12
+ def decidim_form_for(record, options = {}, &block)
13
+ options[:data] ||= {}
14
+ options[:data].update(abide: true, "live-validate" => true, "validate-on-blur" => true)
15
+ form_for(record, options, &block)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # A Helper to render language names in their own language.
4
+ module LanguageChooserHelper
5
+ # Gets the name of the given locale, in that language.
6
+ #
7
+ # Example:
8
+ #
9
+ # locale_name(:es) => "Castellano"
10
+ #
11
+ # locale - a String representing the symbol of the locale. It will usually be 2 letters.
12
+ #
13
+ # Returns a String.
14
+ def locale_name(locale)
15
+ I18n.with_locale(locale) { I18n.t("name", scope: "locale") }
16
+ end
17
+ end
18
+ end
@@ -2,11 +2,6 @@
2
2
  module Decidim
3
3
  # View helpers related to the layout.
4
4
  module LayoutHelper
5
- def decidim_page_title
6
- title = content_for(:meta_title)
7
- title ? "#{title} - #{current_organization.name}" : current_organization.name
8
- end
9
-
10
5
  # Public: Generates a set of meta tags that generate the different favicon
11
6
  # versions for an organization.
12
7
  #
@@ -33,7 +33,7 @@ module Decidim
33
33
  end
34
34
 
35
35
  def name
36
- I18n.t(id, scope: "locales")
36
+ I18n.with_locale(@locale) { I18n.t("name", scope: "locale") }
37
37
  end
38
38
  end
39
39
 
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # Helper that provides convenient methods to deal with the page meta tags.
4
+ module MetaTagsHelper
5
+ # Public: Sets the given metatags for the page. It's a wrapper for the individual
6
+ # methods, so that you can set multiple values with a single call. See the docs for
7
+ # the other methods to see how they work.
8
+ #
9
+ # tags - A Hash containing the meta tag name as keys and its content as values.
10
+ #
11
+ # Returns nothing.
12
+ def add_decidim_meta_tags(tags)
13
+ add_decidim_page_title(tags[:title])
14
+ add_decidim_meta_description(tags[:description])
15
+ add_decidim_meta_url(tags[:url])
16
+ add_decidim_meta_twitter_handler(tags[:twitter_handler])
17
+ add_decidim_meta_image_url(tags[:image_url])
18
+ end
19
+
20
+ # Public: Accumulates the given `title` so that they can be chained. Since Rails views
21
+ # are rendered inside-out, `title` is appended to an array. This way the beggining of
22
+ # the title will be the most specific one. Use the `decidim_page_title` method to
23
+ # render the title whenever you need to (most surely, in the `<title>` tag in the HTML
24
+ # head and in some `title` metatags).
25
+ #
26
+ # Example:
27
+ # add_decidim_page_title("My Process")
28
+ # add_decidim_page_title("My Organization")
29
+ # decidim_page_title # => "My Process - My Organization"
30
+ #
31
+ # title - A String to be added to the title
32
+ #
33
+ # Returns an Array of Strings.
34
+ def add_decidim_page_title(title)
35
+ @decidim_page_title ||= []
36
+ return @decidim_page_title unless title.present?
37
+ @decidim_page_title << title
38
+ end
39
+
40
+ # Public: Renders the title for a page. Use the `add_decidim_page_title` method to
41
+ # accumulate elements for the title. Basically, it joins the elements of the title
42
+ # array with `" - "`.
43
+ #
44
+ # Returns a String.
45
+ def decidim_page_title
46
+ (@decidim_page_title || []).join(" - ")
47
+ end
48
+
49
+ attr_reader :decidim_meta_description, :decidim_meta_url, :decidim_meta_image_url,
50
+ :decidim_meta_twitter_handler
51
+
52
+ # Sets the meta description for the current page. We want to keep the most specific
53
+ # one, so you cannot replace the description if it is set by a view that has already
54
+ # been rendered. Remember that Rails's views are render inside-out, so the `layout`
55
+ # is the last one to be rendered. You can put there a basic content and override it
56
+ # in other layers.
57
+ #
58
+ # description - The String to be set as description
59
+ #
60
+ # Returns nothing.
61
+ def add_decidim_meta_description(description)
62
+ @decidim_meta_description ||= strip_tags(description)
63
+ end
64
+
65
+ # Sets the meta Twitter handler for the current page. We want to keep the most specific
66
+ # one, so you cannot replace the Twitter handler if it is set by a view that has already
67
+ # been rendered. Remember that Rails's views are render inside-out, so the `layout`
68
+ # is the last one to be rendered. You can put there a basic content and override it
69
+ # in other layers.
70
+ #
71
+ # twitter_handler - The String to be set as Twitter handler
72
+ #
73
+ # Returns nothing.
74
+ def add_decidim_meta_twitter_handler(twitter_handler)
75
+ @decidim_meta_twitter_handler ||= twitter_handler
76
+ end
77
+
78
+ # Sets the meta URL for the current page. We want to keep the most specific
79
+ # one, so you cannot replace the URL if it is set by a view that has already
80
+ # been rendered. Remember that Rails's views are render inside-out, so the `layout`
81
+ # is the last one to be rendered. You can put there a basic content and override it
82
+ # in other layers.
83
+ #
84
+ # url - The String to be set as URL
85
+ #
86
+ # Returns nothing.
87
+ def add_decidim_meta_url(url)
88
+ @decidim_meta_url ||= url
89
+ end
90
+
91
+ # Sets the meta image URL for the current page. We want to keep the most specific
92
+ # one, so you cannot replace the image URL if it is set by a view that has already
93
+ # been rendered. Remember that Rails's views are render inside-out, so the `layout`
94
+ # is the last one to be rendered. You can put there a basic content and override it
95
+ # in other layers.
96
+ #
97
+ # image_url - The String to be set as image URL
98
+ #
99
+ # Returns nothing.
100
+ def add_decidim_meta_image_url(image_url)
101
+ @decidim_meta_image_url ||= image_url
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # Helper that provides methods to render order selector and links
4
+ module OrdersHelper
5
+ # Public: It renders the order selector for the provided orders
6
+ # (Note) This method requires the javascript 'decidim/orders' to be
7
+ # present in the page.
8
+ #
9
+ # orders - An array of order criterias
10
+ # options - An optional hash of options
11
+ # * i18n_scope - The scope of the i18n translations
12
+ def order_selector(orders, options = {})
13
+ render partial: "decidim/shared/orders", locals: {
14
+ orders: orders,
15
+ i18n_scope: options[:i18n_scope]
16
+ }
17
+ end
18
+
19
+ # Public: Returns a resource url merging current params with order
20
+ #
21
+ # order - The name of the order criteria. i.e. 'random'
22
+ # options - An optional hash of options
23
+ # * i18n_scope - The scope of the i18n translations
24
+ def order_link(order, options = {})
25
+ link_to t("#{options[:i18n_scope]}.#{order}"), url_for(params.to_unsafe_h.merge(page: nil, order: order)), data: { order: order }, remote: true
26
+ end
27
+ end
28
+ end
@@ -6,20 +6,22 @@ module Decidim
6
6
  # another engine.
7
7
  #
8
8
  # resource - An object that is a valid resource exposed by some feature.
9
+ # options - An optional hash of options to pass to the Rails router
9
10
  #
10
11
  # Returns a String.
11
- def decidim_resource_path(resource)
12
- _decidim_resource_route(resource, "path")
12
+ def decidim_resource_path(resource, options = {})
13
+ _decidim_resource_route(resource, "path", options)
13
14
  end
14
15
 
15
16
  # Builds the url to a resource. Useful when linking to a resource from
16
17
  # another engine.
17
18
  #
18
19
  # resource - An object that is a valid resource exposed by some feature.
20
+ # options - An optional hash of options to pass to the Rails router
19
21
  #
20
22
  # Returns a String.
21
- def decidim_resource_url(resource)
22
- _decidim_resource_route(resource, "url")
23
+ def decidim_resource_url(resource, options = {})
24
+ _decidim_resource_route(resource, "url", options.merge(host: resource.organization.host))
23
25
  end
24
26
 
25
27
  # Renders a collection of linked resources for a resource.
@@ -45,10 +47,48 @@ module Decidim
45
47
  end)
46
48
  end
47
49
 
50
+ # Gets the classes linked to the given class for the `current_feature`, and formats
51
+ # them in a nice way so that they can be used in a form. Resulting format looks like
52
+ # this, considering the given class is related to `Decidim::Meetings::Meeting`:
53
+ #
54
+ # [["decidim/meetings/meeting", "Meetings"]]
55
+ #
56
+ # This method is intended to be used as a check to render the filter or not. Use the
57
+ # `linked_classes_filter_values_for(klass)` method to get the form filter collection
58
+ # values.
59
+ #
60
+ # klass - The class that will have its linked resources formatted.
61
+ #
62
+ # Returns an Array of Arrays of Strings.
63
+ # Returns an empty Array if no links are found.
64
+ def linked_classes_for(klass)
65
+ return [] unless klass.respond_to?(:linked_classes_for)
66
+
67
+ klass.linked_classes_for(current_feature).map do |klass|
68
+ [klass.underscore, t(klass.demodulize.downcase, scope: "decidim.filters.linked_classes")]
69
+ end
70
+ end
71
+
72
+ # Uses the `linked_classes_for(klass)` helper method to find the linked classes,
73
+ # and adds a default value to it so that it can be used directly in a form.
74
+ #
75
+ # Example:
76
+ #
77
+ # <% if linked_classes_for(klass).any? %>
78
+ # <%= form.collection_check_boxes :related_to, linked_classes_filter_values_for(klass), :first, :last %>
79
+ # <% end %>
80
+ #
81
+ # klass - The class that will have its linked resources formatted.
82
+ #
83
+ # Returns an Array of Arrays of Strings.
84
+ def linked_classes_filter_values_for(klass)
85
+ [["", t("all", scope: "decidim.filters.linked_classes")]] + linked_classes_for(klass)
86
+ end
87
+
48
88
  # Private: Build the route to a given resource.
49
89
  #
50
90
  # Returns a String.
51
- def _decidim_resource_route(resource, route_type)
91
+ def _decidim_resource_route(resource, route_type, options)
52
92
  manifest = resource.class.resource_manifest
53
93
  engine = send(manifest.mounted_engine_name)
54
94
 
@@ -58,7 +98,7 @@ module Decidim
58
98
  participatory_process_id: resource.feature.participatory_process.id
59
99
  }
60
100
 
61
- engine.send("#{manifest.route_name}_#{route_type}", url_params)
101
+ engine.send("#{manifest.route_name}_#{route_type}", url_params.merge(options))
62
102
  end
63
103
  end
64
104
  end