decidim-core 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/append_redirect_url_to_modals.js.es6 +1 -1
  3. data/app/assets/javascripts/decidim/data_picker.js.es6 +32 -28
  4. data/app/assets/javascripts/decidim/form_filter.component.js.es6 +2 -2
  5. data/app/assets/javascripts/decidim/foundation.js.es6 +1 -2
  6. data/app/assets/stylesheets/decidim/_decidim.scss +6 -1
  7. data/app/assets/stylesheets/decidim/modules/_address.scss +4 -0
  8. data/app/assets/stylesheets/decidim/modules/_block-banner.scss +39 -0
  9. data/app/assets/stylesheets/decidim/modules/_buttons.scss +76 -1
  10. data/app/assets/stylesheets/decidim/modules/_callout.scss +4 -0
  11. data/app/assets/stylesheets/decidim/modules/_cards.scss +117 -16
  12. data/app/assets/stylesheets/decidim/modules/_collapsible-list.scss +19 -0
  13. data/app/assets/stylesheets/decidim/modules/_data-picker.scss +0 -1
  14. data/app/assets/stylesheets/decidim/modules/_docs-manager.scss +16 -0
  15. data/app/assets/stylesheets/decidim/modules/_icons.scss +13 -4
  16. data/app/assets/stylesheets/decidim/modules/_margins.scss +39 -0
  17. data/app/assets/stylesheets/decidim/modules/_modules.scss +4 -0
  18. data/app/assets/stylesheets/decidim/modules/_navbar.scss +26 -0
  19. data/app/assets/stylesheets/decidim/modules/_process-phase.scss +49 -0
  20. data/app/assets/stylesheets/decidim/modules/_reveal.scss +39 -0
  21. data/app/assets/stylesheets/decidim/modules/_typography.scss +45 -0
  22. data/app/assets/stylesheets/decidim/modules/_wizard-steps.scss +45 -0
  23. data/app/assets/stylesheets/decidim/utils/_helpers.scss +14 -0
  24. data/app/assets/stylesheets/decidim/utils/_mixins.scss +34 -0
  25. data/app/assets/stylesheets/decidim/utils/_settings.scss +6 -3
  26. data/app/commands/decidim/create_report.rb +2 -2
  27. data/app/controllers/decidim/devise/invitations_controller.rb +1 -1
  28. data/app/controllers/decidim/features/base_controller.rb +1 -1
  29. data/app/controllers/decidim/locales_controller.rb +1 -1
  30. data/app/forms/decidim/registration_form.rb +1 -1
  31. data/app/helpers/decidim/decidim_form_helper.rb +26 -1
  32. data/app/helpers/decidim/meta_tags_helper.rb +2 -0
  33. data/app/helpers/decidim/resource_reference_helper.rb +24 -0
  34. data/app/helpers/decidim/scopes_helper.rb +22 -4
  35. data/app/helpers/decidim/view_hooks_helper.rb +6 -3
  36. data/app/mailers/decidim/messaging/conversation_mailer.rb +2 -0
  37. data/app/models/decidim/abilities/base_ability.rb +1 -1
  38. data/app/models/decidim/action_log.rb +57 -0
  39. data/app/models/decidim/area.rb +25 -0
  40. data/app/models/decidim/area_type.rb +20 -0
  41. data/app/models/decidim/attachment.rb +3 -0
  42. data/app/models/decidim/attachment_collection.rb +16 -0
  43. data/app/models/decidim/authorization.rb +1 -0
  44. data/app/models/decidim/categorization.rb +2 -0
  45. data/app/models/decidim/category.rb +8 -0
  46. data/app/models/decidim/feature.rb +6 -1
  47. data/app/models/decidim/moderation.rb +7 -0
  48. data/app/models/decidim/newsletter.rb +7 -0
  49. data/app/models/decidim/organization.rb +9 -0
  50. data/app/models/decidim/participatory_process_user_role.rb +9 -0
  51. data/app/models/decidim/resource_link.rb +8 -1
  52. data/app/models/decidim/scope.rb +7 -0
  53. data/app/models/decidim/static_page.rb +7 -0
  54. data/app/models/decidim/user.rb +5 -1
  55. data/app/models/decidim/user_group.rb +7 -0
  56. data/app/presenters/decidim/admin_log/feature_presenter.rb +43 -0
  57. data/app/presenters/decidim/admin_log/moderation_presenter.rb +48 -0
  58. data/app/presenters/decidim/admin_log/newsletter_presenter.rb +47 -0
  59. data/app/presenters/decidim/admin_log/newsletter_resource_presenter.rb +18 -0
  60. data/app/presenters/decidim/admin_log/organization_presenter.rb +84 -0
  61. data/app/presenters/decidim/admin_log/scope_presenter.rb +54 -0
  62. data/app/presenters/decidim/admin_log/static_page_presenter.rb +48 -0
  63. data/app/presenters/decidim/admin_log/static_page_resource_presenter.rb +18 -0
  64. data/app/presenters/decidim/admin_log/user_group_presenter.rb +31 -0
  65. data/app/presenters/decidim/admin_log/user_presenter.rb +59 -0
  66. data/app/presenters/decidim/area_presenter.rb +14 -0
  67. data/app/presenters/decidim/area_type_presenter.rb +14 -0
  68. data/app/presenters/decidim/category_presenter.rb +14 -0
  69. data/app/presenters/decidim/log/base_presenter.rb +253 -0
  70. data/app/presenters/decidim/log/diff_presenter.rb +120 -0
  71. data/app/presenters/decidim/log/resource_presenter.rb +71 -0
  72. data/app/presenters/decidim/log/space_presenter.rb +63 -0
  73. data/app/presenters/decidim/log/user_presenter.rb +85 -0
  74. data/app/presenters/decidim/log/value_types/area_presenter.rb +28 -0
  75. data/app/presenters/decidim/log/value_types/date_presenter.rb +20 -0
  76. data/app/presenters/decidim/log/value_types/default_presenter.rb +43 -0
  77. data/app/presenters/decidim/log/value_types/locale_presenter.rb +20 -0
  78. data/app/presenters/decidim/log/value_types/percentage_presenter.rb +21 -0
  79. data/app/presenters/decidim/log/value_types/scope_presenter.rb +28 -0
  80. data/app/presenters/decidim/log/value_types/scope_type_presenter.rb +28 -0
  81. data/app/presenters/decidim/user_presenter.rb +1 -1
  82. data/app/services/decidim/action_authorizer.rb +1 -1
  83. data/app/services/decidim/action_logger.rb +108 -0
  84. data/app/services/decidim/events_manager.rb +1 -1
  85. data/app/services/decidim/log/diff_changeset_calculator.rb +135 -0
  86. data/app/services/decidim/resource_search.rb +2 -8
  87. data/app/services/decidim/settings_change.rb +31 -0
  88. data/app/services/decidim/traceability.rb +57 -11
  89. data/app/types/decidim/core/component_type.rb +12 -0
  90. data/app/types/decidim/core/date_time_type.rb +12 -0
  91. data/app/types/decidim/core/date_type.rb +13 -0
  92. data/app/types/decidim/core/decidim_type.rb +23 -0
  93. data/app/types/decidim/core/localized_string_type.rb +14 -0
  94. data/app/types/decidim/core/organization_type.rb +20 -0
  95. data/app/types/decidim/core/participatory_space_type.rb +12 -0
  96. data/app/types/decidim/core/session_type.rb +19 -0
  97. data/app/types/decidim/core/statistic_type.rb +22 -0
  98. data/app/types/decidim/core/translated_field_type.rb +45 -0
  99. data/app/types/decidim/core/user_group_type.rb +39 -0
  100. data/app/types/decidim/core/user_type.rb +41 -0
  101. data/app/validators/etiquette_validator.rb +1 -1
  102. data/app/views/decidim/application/_attachments.html.erb +4 -0
  103. data/app/views/decidim/application/_collection.html.erb +14 -0
  104. data/app/views/decidim/application/_document.html.erb +19 -0
  105. data/app/views/decidim/application/_documents.html.erb +8 -23
  106. data/app/views/decidim/shared/_announcement.html.erb +3 -2
  107. data/app/views/decidim/shared/_tags.html.erb +1 -0
  108. data/app/views/decidim/widgets/_data_picker.html.erb +6 -0
  109. data/app/views/layouts/decidim/mailer.html.erb +2 -2
  110. data/config/initializers/devise.rb +3 -3
  111. data/config/locales/ca.yml +65 -11
  112. data/config/locales/en.yml +64 -10
  113. data/config/locales/es.yml +66 -12
  114. data/config/locales/eu.yml +61 -10
  115. data/config/locales/fi.yml +64 -10
  116. data/config/locales/fr.yml +64 -10
  117. data/config/locales/gl.yml +64 -10
  118. data/config/locales/it.yml +64 -10
  119. data/config/locales/nl.yml +64 -10
  120. data/config/locales/pl.yml +60 -10
  121. data/config/locales/pt-BR.yml +64 -10
  122. data/config/locales/pt.yml +64 -10
  123. data/config/locales/sv.yml +64 -10
  124. data/config/locales/uk.yml +72 -0
  125. data/db/migrate/20170215115407_add_organization_custom_reference.rb +1 -1
  126. data/db/migrate/20170313095436_add_available_authorizations_to_organization.rb +1 -1
  127. data/db/migrate/20171207182729_create_decidim_attachment_collections.rb +12 -0
  128. data/db/migrate/20180130093153_add_action_log.rb +18 -0
  129. data/db/migrate/20180206143340_fix_reference_for_all_resources.rb +13 -0
  130. data/db/migrate/20180215104821_create_decidim_area_types.rb +11 -0
  131. data/db/migrate/20180215104945_create_decidim_areas.rb +12 -0
  132. data/db/migrate/20180221101934_fix_nickname_index.rb +1 -1
  133. data/db/migrate/20180226140756_add_version_to_action_logs.rb +19 -0
  134. data/db/migrate/20180314085339_rename_maximum_votes_per_proposal_to_threshold_per_proposal.rb +27 -0
  135. data/db/migrate/20180326075746_change_event_name_and_class_to_rename_to_publish_proposal_event.rb +17 -0
  136. data/db/seeds.rb +28 -0
  137. data/lib/decidim/abilities/participatory_process_role_ability.rb +2 -2
  138. data/lib/decidim/api/author_interface.rb +25 -0
  139. data/lib/decidim/api/component_interface.rb +16 -0
  140. data/lib/decidim/api/participatory_space_interface.rb +38 -0
  141. data/lib/decidim/authorable.rb +8 -0
  142. data/lib/decidim/core.rb +27 -9
  143. data/lib/decidim/core/engine.rb +3 -4
  144. data/lib/decidim/core/test.rb +2 -0
  145. data/lib/decidim/core/test/factories.rb +62 -6
  146. data/lib/decidim/core/test/shared_examples/announcements_examples.rb +1 -1
  147. data/lib/decidim/core/test/shared_examples/comments_examples.rb +47 -5
  148. data/lib/decidim/core/test/shared_examples/component_type.rb +7 -0
  149. data/lib/decidim/core/test/shared_examples/has_attachment_collections.rb +63 -0
  150. data/lib/decidim/core/test/shared_examples/has_attachments.rb +21 -0
  151. data/lib/decidim/core/test/shared_examples/has_reference.rb +1 -1
  152. data/lib/decidim/core/test/shared_examples/simple_event.rb +27 -1
  153. data/lib/decidim/core/version.rb +1 -1
  154. data/lib/decidim/events/author_event.rb +1 -1
  155. data/lib/decidim/events/base_event.rb +1 -1
  156. data/lib/decidim/events/simple_event.rb +21 -0
  157. data/lib/decidim/exporters/excel.rb +1 -1
  158. data/lib/decidim/feature_manifest.rb +2 -0
  159. data/lib/decidim/form_builder.rb +37 -3
  160. data/lib/decidim/has_attachment_collections.rb +18 -0
  161. data/lib/decidim/has_attachments.rb +14 -0
  162. data/lib/decidim/has_category.rb +5 -0
  163. data/lib/decidim/has_reference.rb +4 -4
  164. data/lib/decidim/loggable.rb +32 -0
  165. data/lib/decidim/participable.rb +0 -2
  166. data/lib/decidim/participatory_space_manifest.rb +2 -0
  167. data/lib/decidim/publicable.rb +2 -2
  168. data/lib/decidim/query_extensions.rb +46 -14
  169. data/lib/decidim/resourceable.rb +15 -6
  170. data/lib/decidim/scopable.rb +35 -1
  171. data/lib/decidim/scopable_feature.rb +16 -0
  172. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ca.js +0 -0
  173. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.es.js +0 -0
  174. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.eu.js +0 -0
  175. data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.fi.js +0 -0
  176. data/vendor/assets/javascripts/leaflet.markercluster.js +0 -0
  177. metadata +91 -38
  178. data/app/commands/decidim/remove_admin.rb +0 -25
  179. data/app/helpers/decidim/feature_reference_helper.rb +0 -25
  180. data/lib/decidim/core/api.rb +0 -13
  181. data/lib/decidim/core/api/author_interface.rb +0 -18
  182. data/lib/decidim/core/api/decidim_type.rb +0 -17
  183. data/lib/decidim/core/api/localized_string_type.rb +0 -12
  184. data/lib/decidim/core/api/process_step_type.rb +0 -19
  185. data/lib/decidim/core/api/process_type.rb +0 -17
  186. data/lib/decidim/core/api/session_type.rb +0 -17
  187. data/lib/decidim/core/api/translated_field_type.rb +0 -43
  188. data/lib/decidim/core/api/user_group_type.rb +0 -37
  189. data/lib/decidim/core/api/user_type.rb +0 -39
  190. data/lib/decidim/devise_failure_app.rb +0 -36
  191. data/lib/decidim/has_scope.rb +0 -25
  192. data/lib/decidim/i18n_exceptions.rb +0 -15
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Log
5
+ # This class holds the logic to present the diff for any activity log.
6
+ # The data needed for this class to work should be sent by
7
+ # `Decidim::Log::BasePresenter` or any of its children.
8
+ #
9
+ # In order to be able to use your own class to present a diff, you'll need to
10
+ # overwrite `BasePresenter#diff_presenter` to return your custom diff presenter.
11
+ # The only requirement for custom renderers is that they should respond to `present`.
12
+ class DiffPresenter
13
+ # Public: Initializes the presenter.
14
+ #
15
+ # changeset - An array of hashes
16
+ # view_helpers - An object holding the view helpers at the render time.
17
+ # Most probably should come automatically from the views.
18
+ # options - a Hash with options
19
+ def initialize(changeset, view_helpers, options = {})
20
+ @changeset = changeset
21
+ @view_helpers = view_helpers
22
+ @options = { show_previous_value?: true }.merge(options)
23
+ end
24
+
25
+ # Public: Renders the given diff.
26
+ #
27
+ # Returns an HTML-safe String.
28
+ def present
29
+ present_diff
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :changeset, :view_helpers, :options
35
+ alias h view_helpers
36
+
37
+ # Private: Presents the diff for this action. If the resource and the
38
+ # version are found in the database, it displays all changes.
39
+ #
40
+ # Returns an HTML-safe String.
41
+ def present_diff
42
+ return "".html_safe if changeset.blank?
43
+
44
+ h.content_tag(:div, class: "logs__log__diff") do
45
+ changeset.each do |attribute|
46
+ h.concat(present_new_value(attribute[:label], attribute[:new_value], attribute[:type]))
47
+ h.concat(present_previous_value(attribute[:previous_value], attribute[:type])) if options[:show_previous_value?]
48
+ end
49
+ end
50
+ end
51
+
52
+ # Private: Helper method to render the previous value.
53
+ #
54
+ # value - the value for the given attribute
55
+ # type - A symbol or String representing the type of the value.
56
+ # If it's a String, it should be the name of the presenter that will
57
+ # be in charge of presenting it.
58
+ #
59
+ # Returns an HTML-safe String.
60
+ def present_previous_value(value, type)
61
+ h.content_tag(:div, class: "logs__log__diff-row logs__log__diff-row--previous-value") do
62
+ h.concat(h.content_tag(:div, "before", class: "logs__log__diff-title"))
63
+ h.concat(h.content_tag(:div, present_value(value, type), class: "logs__log__diff-value"))
64
+ end
65
+ end
66
+
67
+ # Private: Helper method to render the new value.
68
+ #
69
+ # label - the label name
70
+ # value - the value for the given label
71
+ # type - A symbol or String representing the type of the value.
72
+ # If it's a String, it should be the name of the presenter that will
73
+ # be in charge of presenting it.
74
+ #
75
+ # Returns an HTML-safe String.
76
+ def present_new_value(label, value, type)
77
+ h.content_tag(:div, class: "logs__log__diff-row logs__log__diff-row--new-value") do
78
+ h.concat(h.content_tag(:div, label, class: "logs__log__diff-title"))
79
+ h.concat(h.content_tag(:div, present_value(value, type), class: "logs__log__diff-value"))
80
+ end
81
+ end
82
+
83
+ # Private: Presents the value with the its type presenter.
84
+ #
85
+ # value - the value to be presented, no specific type.
86
+ # type - A symbol or String representing the type of the value.
87
+ # If it's a String, it should be the name of the presenter that will
88
+ # be in charge of presenting it.
89
+ #
90
+ # Returns an HTML-safe String.
91
+ def present_value(value, type)
92
+ presenter_klass_for(type).new(value, view_helpers).present
93
+ end
94
+
95
+ # Private: Finds the presenter class for the given type.
96
+ #
97
+ # type - A symbol or String representing the type of the value.
98
+ # If it's a String, it should be the name of the presenter that will
99
+ # be in charge of presenting it.
100
+ #
101
+ # Returns a Class.
102
+ def presenter_klass_for(type)
103
+ default_klass = Decidim::Log::ValueTypes::DefaultPresenter
104
+ klass = ""
105
+
106
+ if type.is_a?(Symbol)
107
+ klass = "Decidim::Log::ValueTypes::#{type.to_s.camelize}Presenter"
108
+ elsif type.is_a?(String)
109
+ klass = type
110
+ end
111
+
112
+ begin
113
+ return klass.constantize
114
+ rescue NameError => _exception
115
+ default_klass
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Log
5
+ # This class holds the logic to present the resource for any activity log.
6
+ # The data needed for this class to work should be sent by
7
+ # `Decidim::Log::BasePresenter` or any of its children.
8
+ #
9
+ # In order to be able to use your own class to present a resource, you'll need to
10
+ # overwrite `BasePresenter#resource_presenter` to return your custom resource presenter.
11
+ # The only requirement for custom renderers is that they should respond to `present`.
12
+ class ResourcePresenter
13
+ # Public: Initializes the presenter.
14
+ #
15
+ # resource - An instance of a model that can be located by
16
+ # `Decidim::ResourceLocatorPresenter`
17
+ # view_helpers - An object holding the view helpers at the render time.
18
+ # Most probably should come automatically from the views.
19
+ # extra - a Hash with extra data, most likely coming from the
20
+ # `action_log` being presented
21
+ def initialize(resource, view_helpers, extra)
22
+ @resource = resource
23
+ @view_helpers = view_helpers
24
+ @extra = extra
25
+ end
26
+
27
+ # Public: Renders the given resource.
28
+ #
29
+ # Returns an HTML-safe String.
30
+ def present
31
+ present_resource
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :resource, :view_helpers, :extra
37
+ alias h view_helpers
38
+
39
+ # Private: Presents the resource of the action. If the resource and the
40
+ # space are found in the database, it links to it. Otherwise it only
41
+ # shows the resource name.
42
+ #
43
+ # Returns an HTML-safe String.
44
+ def present_resource
45
+ span = h.content_tag(:span, present_resource_name, class: "logs__log__resource")
46
+ return span if resource.blank? || resource_path.blank?
47
+
48
+ h.link_to(present_resource_name, resource_path, class: "logs__log__resource")
49
+ end
50
+
51
+ # Private: Finds the public link for the given resource.
52
+ #
53
+ # Returns an HTML-safe String. If the resource space is not
54
+ # present, it returns `nil`.
55
+ def resource_path
56
+ @resource_path ||= begin
57
+ Decidim::ResourceLocatorPresenter.new(resource).path
58
+ rescue NoMethodError
59
+ nil
60
+ end
61
+ end
62
+
63
+ # Private: Presents resource name.
64
+ #
65
+ # Returns an HTML-safe String.
66
+ def present_resource_name
67
+ h.translated_attribute extra["title"]
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Log
5
+ # This class holds the logic to present the space of the resource of any
6
+ # activity log. The data needed for this class to work should be sent by
7
+ # `Decidim::Log::BasePresenter` or any of its children.
8
+ #
9
+ # In order to be able to use your own class to present a space, you'll need to
10
+ # overwrite `BasePresenter#space_presenter` to return your custom space presenter.
11
+ # The only requirement for custom renderers is that they should respond to `present`.
12
+ class SpacePresenter
13
+ # Public: Initializes the presenter.
14
+ #
15
+ # space - An instance of a model implementing the Decidim::Participable concern
16
+ # view_helpers - An object holding the view helpers at the render time.
17
+ # Most probably should come automatically from the views.
18
+ # extra - a Hash with extra data, most likely coming from the
19
+ # `action_log` being presented
20
+ def initialize(space, view_helpers, extra)
21
+ @space = space
22
+ @view_helpers = view_helpers
23
+ @extra = extra
24
+ end
25
+
26
+ # Public: Renders the given space.
27
+ #
28
+ # Returns an HTML-safe String.
29
+ def present
30
+ present_space
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :space, :view_helpers, :extra
36
+ alias h view_helpers
37
+
38
+ # Private: Presents a space. If the space is found in the database, it
39
+ # links to it. Otherwise it only shows the name.
40
+ #
41
+ # Returns an HTML-safe String.
42
+ def present_space
43
+ return h.content_tag(:span, present_space_name, class: "logs__log__space") if space.blank?
44
+
45
+ h.link_to(present_space_name, space_path, class: "logs__log__space")
46
+ end
47
+
48
+ # Private: Finds the link for the given space.
49
+ #
50
+ # Returns an HTML-safe String.
51
+ def space_path
52
+ Decidim::ResourceLocatorPresenter.new(space).path
53
+ end
54
+
55
+ # Private: Presents the space name.
56
+ #
57
+ # Returns an HTML-safe String.
58
+ def present_space_name
59
+ h.translated_attribute extra["title"]
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Log
5
+ # This class holds the logic to present the author for any activity log.
6
+ # The data needed for this class to work should be sent by
7
+ # `Decidim::Log::BasePresenter` or any of its children.
8
+ #
9
+ # In order to be able to use your own class to present a user, you'll need to
10
+ # overwrite `BasePresenter#user_presenter` to return your custom user presenter.
11
+ # The only requirement for custom renderers is that they should respond to `present`.
12
+ class UserPresenter
13
+ # Public: Initializes the presenter.
14
+ #
15
+ # user - An instance of Decidim::User
16
+ # view_helpers - An object holding the view helpers at the render time.
17
+ # Most probably should come automatically from the views.
18
+ # extra - a Hash with extra data, most likely coming from the
19
+ # `action_log` being presented
20
+ def initialize(user, view_helpers, extra)
21
+ @user = user
22
+ @view_helpers = view_helpers
23
+ @extra = extra
24
+ end
25
+
26
+ # Public: Renders the resource associated to the given `action_log`.
27
+ #
28
+ # action_log - An instance of Decidim::ActionLog.last
29
+ # view_helpers - An object holding the view helpers at the render time.
30
+ # Most probably should come automatically from the views.
31
+ #
32
+ # Returns an HTML-safe String.
33
+ def present
34
+ present_user
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :user, :view_helpers, :extra
40
+ alias h view_helpers
41
+
42
+ # Private: Presents the given user. If the user is found in the database, it
43
+ # links to their profile, and shows their nickname as a tooltip.
44
+ # Otherwise it only shows the name.
45
+ #
46
+ # Returns an HTML-safe String.
47
+ def present_user
48
+ return h.content_tag(:span, present_user_name, class: "logs__log__author") if user.blank?
49
+
50
+ h.link_to(
51
+ present_user_name,
52
+ user_path,
53
+ class: "logs__log__author",
54
+ title: "@" + user.nickname,
55
+ data: {
56
+ tooltip: true,
57
+ "disable-hover": false
58
+ }
59
+ )
60
+ end
61
+
62
+ # Private: Presents the name of the user performing the action.
63
+ #
64
+ # Returns an HTML-safe String.
65
+ def present_user_name
66
+ extra["name"].html_safe
67
+ end
68
+
69
+ # Private: Presents the nickname of the user performing the action.
70
+ #
71
+ # Returns an HTML-safe String.
72
+ def present_user_nickname
73
+ extra["nickname"].html_safe
74
+ end
75
+
76
+ # Private: Calculates the path for the user. Returns the path of the
77
+ # user profile. It's a public link.
78
+ #
79
+ # Returns an HTML-safe String.
80
+ def user_path
81
+ h.decidim.profile_path(present_user_nickname)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Log
5
+ module ValueTypes
6
+ # This class presents the given value as a Decidim::Area. Check
7
+ # the `DefaultPresenter` for more info on how value
8
+ # presenters work.
9
+ class AreaPresenter < DefaultPresenter
10
+ # Public: Presents the value as a Decidim::Area. If the area can
11
+ # be found, it shows its title. Otherwise it shows its ID.
12
+ #
13
+ # Returns an HTML-safe String.
14
+ def present
15
+ return unless value
16
+ return h.translated_attribute(area.name) if area
17
+ I18n.t("not_found", id: value, scope: "decidim.log.value_types.area_presenter")
18
+ end
19
+
20
+ private
21
+
22
+ def area
23
+ @area ||= Decidim::Area.where(id: value).first
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Log
5
+ module ValueTypes
6
+ # This class presents the given value as a date. Check
7
+ # the `DefaultPresenter` for more info on how value
8
+ # presenters work.
9
+ class DatePresenter < DefaultPresenter
10
+ # Public: Presents the value as a date.
11
+ #
12
+ # Returns an HTML-safe String.
13
+ def present
14
+ return unless value
15
+ h.l(value, format: :long)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Log
5
+ module ValueTypes
6
+ # This class is used as a base for other value presenters,
7
+ # and as a default presenter when the presenter for the
8
+ # given value is not specified or is not found.
9
+ #
10
+ # Value presenters are dynamically found from the value type
11
+ # set in the `fields_mapping` method in the resource presenter.
12
+ # If the value is a symbol, the system will try to infer the
13
+ # correct presenter and use it. If it's a String, it will treat
14
+ # it as a class name, and will try to fetch that presenter.
15
+ # If the system fails in either case, it will use the `DefaultPresenter`.
16
+ #
17
+ # Check the other presenters in this folder for more examples.
18
+ class DefaultPresenter
19
+ # value - the vakue to render, can be of any type.
20
+ # view_helpers - an object encapsulating all the view helpers,
21
+ # it will most likely come from the top of the chain.
22
+ def initialize(value, view_helpers)
23
+ @value = value
24
+ @view_helpers = view_helpers
25
+ end
26
+
27
+ # Public: Presents the value in a specific format. In this method
28
+ # you can use any view helper you need, but it's important to return
29
+ # an HTML-safe String.
30
+ #
31
+ # Returns an HTML-safe String.
32
+ def present
33
+ value
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :value, :view_helpers
39
+ alias h view_helpers
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Log
5
+ module ValueTypes
6
+ # This class presents the given value as a locale. Check
7
+ # the `DefaultPresenter` for more info on how value
8
+ # presenters work.
9
+ class LocalePresenter < DefaultPresenter
10
+ # Public: Presents the value as a locale.
11
+ #
12
+ # Returns an HTML-safe String.
13
+ def present
14
+ return unless value
15
+ I18n.with_locale(value) { I18n.t("locale.name") }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end