decidim-core 0.22.0 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim-core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/config/decidim_core_manifest.js +5 -0
- data/app/assets/javascripts/decidim.js.es6 +2 -0
- data/app/assets/javascripts/decidim/ajax_modals.js.es6 +3 -3
- data/app/assets/javascripts/decidim/confirm.js.es6 +3 -2
- data/app/assets/javascripts/decidim/core/bundle.js +1 -1
- data/app/assets/javascripts/decidim/core/bundle.js.map +1 -1
- data/app/assets/javascripts/decidim/diff_mode_dropdown.js.es6 +18 -4
- data/app/assets/javascripts/decidim/editor.js.es6 +3 -3
- data/app/assets/javascripts/decidim/geocoding.js.es6 +60 -0
- data/app/assets/javascripts/decidim/geocoding/attach_input.js.es6 +106 -0
- data/app/assets/javascripts/decidim/geocoding/format_address.js.es6 +29 -0
- data/app/assets/javascripts/decidim/geocoding/provider/here.js.es6 +107 -0
- data/app/assets/javascripts/decidim/geocoding/provider/photon.js.es6 +77 -0
- data/app/assets/javascripts/decidim/map.js.es6 +34 -124
- data/app/assets/javascripts/decidim/map/controller.js.es6 +92 -0
- data/app/assets/javascripts/decidim/map/controller/markers.js.es6 +65 -0
- data/app/assets/javascripts/decidim/map/controller/static.es6 +48 -0
- data/app/assets/javascripts/decidim/map/factory.js.es6 +51 -0
- data/app/assets/javascripts/decidim/map/icon.js.es6 +31 -0
- data/app/assets/javascripts/decidim/map/legacy.js.es6 +87 -0
- data/app/assets/javascripts/decidim/map/provider/default.js.es6 +22 -0
- data/app/assets/javascripts/decidim/map/provider/here.js.es6 +22 -0
- data/app/assets/javascripts/decidim/security/selfxss_warning.js.es6 +19 -0
- data/app/assets/stylesheets/decidim/_decidim.scss +2 -0
- data/app/assets/stylesheets/decidim/modules/_cards.scss +15 -0
- data/app/assets/stylesheets/decidim/modules/_forms.scss +14 -0
- data/app/assets/stylesheets/decidim/modules/_layout.scss +11 -3
- data/app/assets/stylesheets/decidim/modules/_map.scss +35 -0
- data/app/assets/stylesheets/decidim/modules/_progress-bar.scss +4 -0
- data/app/assets/stylesheets/decidim/modules/_reveal.scss +5 -0
- data/app/assets/stylesheets/decidim/modules/_status-labels.scss +2 -1
- data/app/cells/decidim/author/flag.erb +1 -1
- data/app/cells/decidim/author/profile_inline.erb +2 -2
- data/app/cells/decidim/author_cell.rb +5 -2
- data/app/cells/decidim/card_cell.rb +21 -7
- data/app/cells/decidim/card_m/show.erb +1 -1
- data/app/cells/decidim/card_m_cell.rb +6 -4
- data/app/cells/decidim/collapsible_authors_cell.rb +1 -1
- data/app/cells/decidim/diff/diff_mode_html.erb +5 -5
- data/app/cells/decidim/follow_button/show.erb +6 -6
- data/app/cells/decidim/follow_button_cell.rb +8 -0
- data/app/cells/decidim/progress_bar/show.erb +11 -4
- data/app/cells/decidim/progress_bar_cell.rb +20 -1
- data/app/cells/decidim/translation_bar/show.erb +6 -0
- data/app/cells/decidim/translation_bar_cell.rb +52 -0
- data/app/cells/decidim/version_cell.rb +1 -1
- data/app/cells/decidim/versions_list_cell.rb +1 -1
- data/app/commands/decidim/amendable/accept.rb +9 -3
- data/app/commands/decidim/amendable/create_draft.rb +2 -0
- data/app/commands/decidim/amendable/update_draft.rb +2 -0
- data/app/commands/decidim/attachment_methods.rb +12 -5
- data/app/commands/decidim/destroy_account.rb +1 -0
- data/app/commands/decidim/gallery_methods.rb +16 -9
- data/app/commands/decidim/messaging/reply_to_conversation.rb +1 -1
- data/app/commands/decidim/multiple_attachments_methods.rb +56 -0
- data/app/controllers/concerns/decidim/devise_controllers.rb +1 -0
- data/app/controllers/concerns/decidim/filter_resource.rb +24 -6
- data/app/controllers/concerns/decidim/flaggable.rb +20 -0
- data/app/controllers/concerns/decidim/force_authentication.rb +1 -0
- data/app/controllers/concerns/decidim/impersonate_users.rb +1 -1
- data/app/controllers/concerns/decidim/needs_snippets.rb +20 -0
- data/app/controllers/concerns/decidim/paginable.rb +5 -1
- data/app/controllers/concerns/decidim/withdrawable.rb +20 -0
- data/app/controllers/decidim/application_controller.rb +16 -0
- data/app/controllers/decidim/components/base_controller.rb +6 -1
- data/app/controllers/decidim/cookie_policy_controller.rb +6 -3
- data/app/controllers/decidim/messaging/conversations_controller.rb +5 -2
- data/app/forms/decidim/account_form.rb +5 -1
- data/app/forms/decidim/amendable/create_form.rb +1 -1
- data/app/forms/decidim/amendable/form.rb +44 -3
- data/app/forms/decidim/attachment_form.rb +5 -1
- data/app/forms/decidim/user_group_form.rb +5 -1
- data/app/helpers/decidim/cells_helper.rb +3 -15
- data/app/helpers/decidim/check_boxes_tree_helper.rb +21 -12
- data/app/helpers/decidim/cookies_helper.rb +1 -1
- data/app/helpers/decidim/decidim_form_helper.rb +1 -1
- data/app/helpers/decidim/filter_params_helper.rb +30 -0
- data/app/helpers/decidim/map_helper.rb +86 -23
- data/app/helpers/decidim/orders_helper.rb +6 -1
- data/app/helpers/decidim/paginate_helper.rb +3 -1
- data/app/helpers/decidim/scopes_helper.rb +4 -4
- data/app/helpers/decidim/translations_helper.rb +7 -1
- data/app/jobs/decidim/machine_translation_fields_job.rb +30 -0
- data/app/jobs/decidim/machine_translation_resource_job.rb +113 -0
- data/app/jobs/decidim/machine_translation_save_job.rb +33 -0
- data/app/mailers/decidim/reported_mailer.rb +8 -1
- data/app/models/decidim/action_log.rb +1 -1
- data/app/models/decidim/area.rb +3 -0
- data/app/models/decidim/area_type.rb +4 -0
- data/app/models/decidim/attachment.rb +30 -2
- data/app/models/decidim/attachment_collection.rb +3 -0
- data/app/models/decidim/authorization.rb +3 -0
- data/app/models/decidim/category.rb +4 -0
- data/app/models/decidim/component.rb +7 -0
- data/app/models/decidim/content_block.rb +11 -1
- data/app/models/decidim/contextual_help_section.rb +4 -0
- data/app/models/decidim/follow.rb +3 -1
- data/app/models/decidim/messaging/message.rb +1 -1
- data/app/models/decidim/moderation.rb +1 -1
- data/app/models/decidim/newsletter.rb +3 -0
- data/app/models/decidim/oauth_application.rb +2 -0
- data/app/models/decidim/organization.rb +53 -9
- data/app/models/decidim/scope.rb +4 -1
- data/app/models/decidim/scope_type.rb +3 -0
- data/app/models/decidim/share_token.rb +49 -0
- data/app/models/decidim/static_page.rb +4 -1
- data/app/models/decidim/static_page_topic.rb +3 -0
- data/app/models/decidim/user_base_entity.rb +6 -2
- data/app/permissions/decidim/permissions.rb +9 -0
- data/app/presenters/decidim/log/base_presenter.rb +1 -1
- data/app/presenters/decidim/log/value_types/default_presenter.rb +1 -1
- data/app/presenters/decidim/official_author_presenter.rb +36 -0
- data/app/presenters/decidim/resource_locator_presenter.rb +63 -12
- data/app/queries/decidim/similar_emendations.rb +4 -4
- data/app/scrubbers/decidim/user_input_scrubber.rb +1 -1
- data/app/serializers/decidim/importers/participatory_space_components_importer.rb +1 -1
- data/app/services/decidim/base_diff_renderer.rb +17 -0
- data/app/services/decidim/open_data_exporter.rb +2 -0
- data/app/services/decidim/resource_search.rb +95 -6
- data/app/services/decidim/static_map_generator.rb +10 -26
- data/app/uploaders/decidim/application_uploader.rb +15 -1
- data/app/uploaders/decidim/attachment_uploader.rb +23 -17
- data/app/uploaders/decidim/banner_image_uploader.rb +1 -1
- data/app/uploaders/decidim/hero_image_uploader.rb +1 -1
- data/app/uploaders/decidim/homepage_image_uploader.rb +1 -1
- data/app/uploaders/decidim/image_uploader.rb +6 -2
- data/app/uploaders/decidim/oauth_application_logo_uploader.rb +1 -1
- data/app/uploaders/decidim/official_image_footer_uploader.rb +1 -1
- data/app/uploaders/decidim/official_image_header_uploader.rb +1 -1
- data/app/uploaders/decidim/organization_logo_uploader.rb +1 -1
- data/app/uploaders/decidim/record_image_uploader.rb +15 -0
- data/app/validators/etiquette_validator.rb +0 -7
- data/app/validators/geocoding_validator.rb +9 -4
- data/app/validators/passthru_validator.rb +111 -0
- data/app/validators/scope_belongs_to_component_validator.rb +16 -0
- data/app/validators/uploader_content_type_validator.rb +44 -0
- data/app/views/decidim/authorization_modals/_content.html.erb +2 -2
- data/app/views/decidim/devise/registrations/new.html.erb +3 -1
- data/app/views/decidim/devise/sessions/new.html.erb +3 -1
- data/app/views/decidim/messaging/conversations/_error_modal.html.erb +21 -0
- data/app/views/decidim/messaging/conversations/error.js.erb +10 -0
- data/app/views/decidim/notification_mailer/event_received.html.erb +2 -2
- data/app/views/decidim/reported_mailer/report.html.erb +49 -3
- data/app/views/decidim/scopes/_scopes_picker_input.html.erb +15 -14
- data/app/views/decidim/searches/_filters.html.erb +1 -0
- data/app/views/decidim/shared/_login_modal.html.erb +14 -3
- data/app/views/decidim/shared/_static_map.html.erb +1 -1
- data/app/views/layouts/decidim/_head.html.erb +2 -0
- data/app/views/layouts/decidim/_js_configuration.html.erb +7 -1
- data/config/locales/am-ET.yml +1 -0
- data/config/locales/ar.yml +3 -4
- data/config/locales/bg.yml +1508 -0
- data/config/locales/ca.yml +35 -8
- data/config/locales/cs.yml +34 -7
- data/config/locales/da.yml +1 -0
- data/config/locales/de.yml +23 -4
- data/config/locales/el.yml +0 -4
- data/config/locales/en.yml +30 -3
- data/config/locales/eo.yml +92 -0
- data/config/locales/es-MX.yml +28 -1
- data/config/locales/es-PY.yml +28 -1
- data/config/locales/es.yml +44 -17
- data/config/locales/et.yml +1 -0
- data/config/locales/eu.yml +3 -4
- data/config/locales/fi-plain.yml +28 -1
- data/config/locales/fi.yml +29 -2
- data/config/locales/fr-CA.yml +32 -4
- data/config/locales/fr.yml +61 -33
- data/config/locales/ga-IE.yml +0 -8
- data/config/locales/gl.yml +3 -4
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +7 -4
- data/config/locales/id-ID.yml +3 -4
- data/config/locales/is-IS.yml +3 -9
- data/config/locales/is.yml +463 -0
- data/config/locales/it.yml +36 -8
- data/config/locales/ja-JP.yml +25 -16
- data/config/locales/ja.yml +1605 -0
- data/config/locales/ko-KR.yml +1 -0
- data/config/locales/ko.yml +1 -0
- data/config/locales/lt.yml +1 -0
- data/config/locales/{lv-LV.yml → lv.yml} +0 -4
- data/config/locales/mt.yml +1 -0
- data/config/locales/nl.yml +25 -3
- data/config/locales/no.yml +133 -6
- data/config/locales/om-ET.yml +1 -0
- data/config/locales/pl.yml +88 -71
- data/config/locales/pt-BR.yml +3 -4
- data/config/locales/pt.yml +10 -4
- data/config/locales/ro-RO.yml +10 -4
- data/config/locales/ru.yml +3 -10
- data/config/locales/sk.yml +3 -4
- data/config/locales/sl.yml +8 -7
- data/config/locales/so-SO.yml +1 -0
- data/config/locales/sr-CS.yml +0 -7
- data/config/locales/sv.yml +17 -6
- data/config/locales/ti-ER.yml +1 -0
- data/config/locales/tr-TR.yml +3 -4
- data/config/locales/uk.yml +3 -11
- data/config/locales/vi-VN.yml +1 -0
- data/config/locales/vi.yml +1 -0
- data/config/locales/zh-CN.yml +1584 -0
- data/config/locales/zh-TW.yml +1 -0
- data/db/migrate/20200525184143_add_enable_machine_translation_to_decidim_organizations.rb +7 -0
- data/db/migrate/20200702073419_create_decidim_share_tokens.rb +16 -0
- data/db/migrate/20200707132401_add_comments_max_length_to_decidim_organization.rb +7 -0
- data/db/migrate/20200730142511_add_file_upload_settings_to_decidim_organizations.rb +36 -0
- data/db/migrate/20200806092109_add_machine_translation_display_priority_to_organizations.rb +17 -0
- data/db/migrate/20201004160335_remove_notifications_with_continuity_badge.rb +9 -0
- data/db/seeds.rb +5 -4
- data/lib/decidim/authorable.rb +22 -1
- data/lib/decidim/authorization_form_builder.rb +7 -0
- data/lib/decidim/coauthorable.rb +22 -0
- data/lib/decidim/component_manifest.rb +1 -1
- data/lib/decidim/content_processor.rb +52 -29
- data/lib/decidim/content_renderers/base_renderer.rb +1 -1
- data/lib/decidim/content_renderers/hashtag_renderer.rb +2 -0
- data/lib/decidim/content_renderers/link_renderer.rb +4 -1
- data/lib/decidim/content_renderers/user_group_renderer.rb +3 -1
- data/lib/decidim/content_renderers/user_renderer.rb +3 -1
- data/lib/decidim/core.rb +67 -12
- data/lib/decidim/core/engine.rb +60 -21
- data/lib/decidim/core/test.rb +6 -0
- data/lib/decidim/core/test/factories.rb +34 -8
- data/lib/decidim/core/test/shared_examples/amendable/accept_amendment_examples.rb +4 -4
- data/lib/decidim/core/test/shared_examples/amendable_proposals_interface_examples.rb +8 -8
- data/lib/decidim/core/test/shared_examples/comments_examples.rb +52 -1
- data/lib/decidim/core/test/shared_examples/embed_resource_examples.rb +49 -0
- data/lib/decidim/core/test/shared_examples/follows_examples.rb +3 -3
- data/lib/decidim/core/test/shared_examples/manage_component_share_tokens.rb +83 -0
- data/lib/decidim/core/test/shared_examples/map_examples.rb +186 -0
- data/lib/decidim/core/test/shared_examples/preview_component_with_share_token_examples.rb +55 -0
- data/lib/decidim/core/test/shared_examples/resource_search_examples.rb +200 -0
- data/lib/decidim/core/test/shared_examples/scopable_resource_examples.rb +43 -0
- data/lib/decidim/core/test/shared_examples/scope_helper_examples.rb +12 -1
- data/lib/decidim/core/test/shared_examples/searchable_participatory_space_examples.rb +2 -2
- data/lib/decidim/core/test/shared_examples/searchable_results_examples.rb +15 -2
- data/lib/decidim/core/test/shared_examples/simple_event.rb +7 -0
- data/lib/decidim/core/test/shared_examples/system_endorse_resource_examples.rb +1 -0
- data/lib/decidim/core/test/shared_examples/traceable_interface_examples.rb +1 -1
- data/lib/decidim/core/test/shared_examples/uncommentable_component_examples.rb +1 -1
- data/lib/decidim/core/version.rb +1 -1
- data/lib/decidim/diffy_extension.rb +21 -0
- data/lib/decidim/events/base_event.rb +11 -9
- data/lib/decidim/exporters.rb +7 -0
- data/lib/decidim/exporters/csv.rb +15 -1
- data/lib/decidim/exporters/excel.rb +1 -1
- data/lib/decidim/exporters/export_manifest.rb +29 -0
- data/lib/decidim/exporters/pdf.rb +56 -0
- data/lib/decidim/file_validator_humanizer.rb +98 -0
- data/lib/decidim/form_builder.rb +65 -54
- data/lib/decidim/geocodable.rb +79 -0
- data/lib/decidim/has_attachments.rb +10 -0
- data/lib/decidim/has_upload_validations.rb +36 -0
- data/lib/decidim/map.rb +214 -0
- data/lib/decidim/map/autocomplete.rb +67 -0
- data/lib/decidim/map/dynamic_map.rb +89 -0
- data/lib/decidim/map/frontend.rb +97 -0
- data/lib/decidim/map/geocoding.rb +115 -0
- data/lib/decidim/map/provider.rb +12 -0
- data/lib/decidim/map/provider/autocomplete/here.rb +20 -0
- data/lib/decidim/map/provider/autocomplete/osm.rb +20 -0
- data/lib/decidim/map/provider/dynamic_map/here.rb +51 -0
- data/lib/decidim/map/provider/dynamic_map/osm.rb +13 -0
- data/lib/decidim/map/provider/geocoding/here.rb +58 -0
- data/lib/decidim/map/provider/geocoding/osm.rb +30 -0
- data/lib/decidim/map/provider/here.rb +21 -0
- data/lib/decidim/map/provider/osm.rb +22 -0
- data/lib/decidim/map/provider/static_map/here.rb +35 -0
- data/lib/decidim/map/provider/static_map/osm.rb +29 -0
- data/lib/decidim/map/static_map.rb +133 -0
- data/lib/decidim/map/utility.rb +38 -0
- data/lib/decidim/organization_settings.rb +267 -0
- data/lib/decidim/resource_manifest.rb +1 -1
- data/lib/decidim/scopable.rb +9 -6
- data/lib/decidim/scopable_component.rb +29 -1
- data/lib/decidim/scopable_participatory_space.rb +19 -0
- data/lib/decidim/scopable_resource.rb +21 -0
- data/lib/decidim/search_resource_fields_mapper.rb +15 -2
- data/lib/decidim/searchable.rb +4 -0
- data/lib/decidim/settings_manifest.rb +2 -1
- data/lib/decidim/shareable_with_token.rb +27 -0
- data/lib/decidim/snippets.rb +30 -0
- data/lib/decidim/translatable_attributes.rb +42 -4
- data/lib/decidim/translatable_resource.rb +78 -0
- data/lib/decidim/view_model.rb +1 -0
- data/lib/tasks/decidim_locales_tasks.rake +35 -0
- data/lib/tasks/decidim_tasks.rake +1 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.bg.js +14 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.da.js +14 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.eo.js +17 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.et.js +18 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.fr-CA.js +16 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ga.js +15 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.hr.js +13 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.is.js +14 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ja.js +16 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.lt.js +16 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.lv.js +17 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.mt.js +15 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.sl.js +14 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.sr.js +16 -0
- metadata +138 -26
- data/app/helpers/decidim/multi_translation_helper.rb +0 -0
- data/lib/decidim/hashtaggable.rb +0 -24
@@ -40,17 +40,10 @@ module Decidim
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
# Overwrite this method in your component helper to define
|
44
|
+
# origin values.
|
43
45
|
def filter_origin_values
|
44
|
-
|
45
|
-
origin_values << TreePoint.new("official", t("decidim.proposals.application_helper.filter_origin_values.official")) if component_settings.official_proposals_enabled
|
46
|
-
origin_values << TreePoint.new("citizens", t("decidim.proposals.application_helper.filter_origin_values.citizens"))
|
47
|
-
origin_values << TreePoint.new("user_group", t("decidim.proposals.application_helper.filter_origin_values.user_groups")) if current_organization.user_groups_enabled?
|
48
|
-
origin_values << TreePoint.new("meeting", t("decidim.proposals.application_helper.filter_origin_values.meetings"))
|
49
|
-
|
50
|
-
TreeNode.new(
|
51
|
-
TreePoint.new("", t("decidim.proposals.application_helper.filter_origin_values.all")),
|
52
|
-
origin_values
|
53
|
-
)
|
46
|
+
raise StandardError, "Not implemented"
|
54
47
|
end
|
55
48
|
|
56
49
|
def filter_categories_values
|
@@ -81,10 +74,26 @@ module Decidim
|
|
81
74
|
)
|
82
75
|
end
|
83
76
|
|
77
|
+
def resource_filter_scope_values(resource)
|
78
|
+
if resource.is_a?(Scope)
|
79
|
+
filter_scopes_values_from([resource])
|
80
|
+
else
|
81
|
+
filter_scopes_values
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
84
85
|
def filter_scopes_values
|
85
|
-
main_scopes =
|
86
|
+
main_scopes = if current_component.scope.present?
|
87
|
+
[current_component.scope]
|
88
|
+
else
|
89
|
+
current_participatory_space.scopes.top_level
|
90
|
+
.includes(:scope_type, :children)
|
91
|
+
end
|
92
|
+
filter_scopes_values_from(main_scopes)
|
93
|
+
end
|
86
94
|
|
87
|
-
|
95
|
+
def filter_scopes_values_from(scopes)
|
96
|
+
scopes_values = scopes.compact.flat_map do |scope|
|
88
97
|
TreeNode.new(
|
89
98
|
TreePoint.new(scope.id.to_s, translated_attribute(scope.name, current_participatory_space.organization)),
|
90
99
|
scope_children_to_tree(scope)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# A helper to allow only Decidim params to be added to a link.
|
5
|
+
# This is useful when we want to preserve the params from a search, ordering
|
6
|
+
# or paginating results. Using this, we can link back to where the user was
|
7
|
+
# at the show page.
|
8
|
+
module FilterParamsHelper
|
9
|
+
# Public: Builds a hash to be added to a _path or _url method with only
|
10
|
+
# allowed params.
|
11
|
+
#
|
12
|
+
# params - An optional Hash with the values of the params. It will try to
|
13
|
+
# get them from the controller if none are present.
|
14
|
+
#
|
15
|
+
# Returns a Hash.
|
16
|
+
def filter_link_params(params = nil)
|
17
|
+
return {} if params.blank? && (!respond_to?(:controller) || !controller.respond_to?(:params))
|
18
|
+
|
19
|
+
params = controller.params.to_unsafe_h if params.blank?
|
20
|
+
|
21
|
+
params.stringify_keys.slice(
|
22
|
+
"order",
|
23
|
+
"filter",
|
24
|
+
"page",
|
25
|
+
"per_page",
|
26
|
+
"locale"
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -9,42 +9,91 @@ module Decidim
|
|
9
9
|
# resource - A geolocalizable resource
|
10
10
|
# options - An optional hash of options (default: { zoom: 17 })
|
11
11
|
# * zoom: A number to represent the zoom value of the map
|
12
|
-
def static_map_link(resource, options = {})
|
12
|
+
def static_map_link(resource, options = {}, map_html_options = {}, &block)
|
13
13
|
return unless resource.geocoded?
|
14
|
-
|
15
|
-
zoom = options[:zoom] || 17
|
16
|
-
latitude = resource.latitude
|
17
|
-
longitude = resource.longitude
|
14
|
+
return unless map_utility_static || map_utility_dynamic
|
18
15
|
|
19
16
|
address_text = resource.try(:address)
|
20
17
|
address_text ||= t("latlng_text", latitude: latitude, longitude: longitude, scope: "decidim.map.static")
|
21
18
|
map_service_brand = t("map_service_brand", scope: "decidim.map.static")
|
22
19
|
|
23
|
-
|
20
|
+
if map_utility_static
|
21
|
+
map_url = map_utility_static.link(
|
22
|
+
latitude: resource.latitude,
|
23
|
+
longitude: resource.longitude,
|
24
|
+
options: options
|
25
|
+
)
|
26
|
+
|
27
|
+
# Check that the static map utility actually returns a URL before
|
28
|
+
# creating the static map utility. If it does not, the image would be
|
29
|
+
# otherwise blank.
|
30
|
+
if map_utility_static.url(latitude: resource.latitude, longitude: resource.longitude)
|
31
|
+
return link_to map_url, target: "_blank", rel: "noopener" do
|
32
|
+
image_tag decidim.static_map_path(sgid: resource.to_sgid.to_s), alt: "#{map_service_brand} - #{address_text}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Fall back to the dynamic map utility in case static maps are not
|
38
|
+
# provided.
|
39
|
+
builder = map_utility_dynamic.create_builder(self, {
|
40
|
+
type: :static,
|
41
|
+
latitude: resource.latitude,
|
42
|
+
longitude: resource.longitude,
|
43
|
+
zoom: 15,
|
44
|
+
title: "#{map_service_brand} - #{address_text}",
|
45
|
+
link: map_url
|
46
|
+
}.merge(options))
|
47
|
+
|
48
|
+
unless snippets.any?(:map)
|
49
|
+
snippets.add(:map, builder.stylesheet_snippets)
|
50
|
+
snippets.add(:map, builder.javascript_snippets)
|
24
51
|
|
25
|
-
|
26
|
-
|
52
|
+
# This will display the snippets in the <head> part of the page.
|
53
|
+
snippets.add(:head, snippets.for(:map))
|
27
54
|
end
|
55
|
+
|
56
|
+
builder.map_element(
|
57
|
+
{ class: "static-map", tabindex: "0" }.merge(map_html_options),
|
58
|
+
&block
|
59
|
+
)
|
28
60
|
end
|
29
61
|
|
30
|
-
def dynamic_map_for(
|
31
|
-
return
|
62
|
+
def dynamic_map_for(options_or_markers = {}, html_options = {}, &block)
|
63
|
+
return unless map_utility_dynamic
|
32
64
|
|
33
|
-
|
34
|
-
|
35
|
-
id: "map",
|
36
|
-
"data-markers-data" => markers_data.to_json
|
65
|
+
options = {
|
66
|
+
popup_template_id: "marker-popup"
|
37
67
|
}
|
38
|
-
|
39
|
-
|
40
|
-
map_html_options["data-here-api-key"] = Decidim.geocoder[:here_api_key]
|
68
|
+
if options_or_markers.is_a?(Array)
|
69
|
+
options[:markers] = options_or_markers
|
41
70
|
else
|
42
|
-
|
43
|
-
map_html_options["data-here-app-id"] = Decidim.geocoder[:here_app_id]
|
44
|
-
map_html_options["data-here-app-code"] = Decidim.geocoder[:here_app_code]
|
71
|
+
options = options.merge(options_or_markers)
|
45
72
|
end
|
46
73
|
|
47
|
-
|
74
|
+
builder = map_utility_dynamic.create_builder(self, options)
|
75
|
+
|
76
|
+
# The map snippets are stored to the snippets utility in order to ensure
|
77
|
+
# that they are only loaded once during each page load. In case they were
|
78
|
+
# loaded multiple times, the maps would break. We store the map assets to
|
79
|
+
# a special "map" snippets category in order to avoid displaying them
|
80
|
+
# multiple times. Then we inject them to the "head" category during the
|
81
|
+
# first load which will actually display them in the <head> section of the
|
82
|
+
# view.
|
83
|
+
#
|
84
|
+
# Ideally we would use Rails' native content_for here (which is exactly
|
85
|
+
# for this purpose) but unfortunately it does not work in the cells which
|
86
|
+
# also need to display maps.
|
87
|
+
unless snippets.any?(:map)
|
88
|
+
snippets.add(:map, builder.stylesheet_snippets)
|
89
|
+
snippets.add(:map, builder.javascript_snippets)
|
90
|
+
|
91
|
+
# This will display the snippets in the <head> part of the page.
|
92
|
+
snippets.add(:head, snippets.for(:map))
|
93
|
+
end
|
94
|
+
|
95
|
+
map_html_options = { id: "map", class: "google-map" }.merge(html_options)
|
96
|
+
|
48
97
|
help = content_tag(:div, class: "map__help") do
|
49
98
|
sr_content = content_tag(:p, t("screen_reader_explanation", scope: "decidim.map.dynamic"), class: "show-for-sr")
|
50
99
|
link = link_to(t("skip_button", scope: "decidim.map.dynamic"), "#map_bottom", class: "skip")
|
@@ -52,11 +101,25 @@ module Decidim
|
|
52
101
|
sr_content + link
|
53
102
|
end
|
54
103
|
content_tag :div, class: "row column" do
|
55
|
-
map =
|
104
|
+
map = builder.map_element(map_html_options, &block)
|
56
105
|
link = link_to("", "#", id: "map_bottom")
|
57
106
|
|
58
|
-
help + map +
|
107
|
+
help + map + link
|
59
108
|
end
|
60
109
|
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def map_utility_dynamic
|
114
|
+
@map_utility_dynamic ||= Decidim::Map.dynamic(
|
115
|
+
organization: current_organization
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
def map_utility_static
|
120
|
+
@map_utility_static ||= Decidim::Map.static(
|
121
|
+
organization: current_organization
|
122
|
+
)
|
123
|
+
end
|
61
124
|
end
|
62
125
|
end
|
@@ -27,7 +27,12 @@ module Decidim
|
|
27
27
|
|
28
28
|
link_to(
|
29
29
|
t("#{i18n_scope}.#{order}"),
|
30
|
-
url_for(params.to_unsafe_h.
|
30
|
+
url_for(params.to_unsafe_h.except(
|
31
|
+
"component_id",
|
32
|
+
"participatory_process_slug",
|
33
|
+
"assembly_slug",
|
34
|
+
"initiative_slug"
|
35
|
+
).merge(page: nil, order: order)),
|
31
36
|
{
|
32
37
|
data: { order: order },
|
33
38
|
remote: true
|
@@ -12,7 +12,9 @@ module Decidim
|
|
12
12
|
# Kaminari uses url_for to generate the url, but this doesn't play nice with our engine system
|
13
13
|
# and unless we remove these params they are added again as query string :(
|
14
14
|
default_params = {
|
15
|
-
|
15
|
+
participatory_process_slug: nil,
|
16
|
+
assembly_slug: nil,
|
17
|
+
initiative_slug: nil,
|
16
18
|
component_id: nil
|
17
19
|
}
|
18
20
|
|
@@ -13,9 +13,9 @@ module Decidim
|
|
13
13
|
#
|
14
14
|
# Returns boolean.
|
15
15
|
def has_visible_scopes?(resource)
|
16
|
-
resource.
|
16
|
+
resource.component.scopes_enabled? &&
|
17
17
|
resource.scope.present? &&
|
18
|
-
resource.
|
18
|
+
resource.component.scope != resource.scope
|
19
19
|
end
|
20
20
|
|
21
21
|
# Retrieves the translated name and type for an scope.
|
@@ -35,7 +35,7 @@ module Decidim
|
|
35
35
|
# form - FormBuilder object
|
36
36
|
# name - attribute name
|
37
37
|
# options - An optional Hash with options:
|
38
|
-
# - checkboxes_on_top - Show checked picker values on top (default) or below the picker prompt
|
38
|
+
# - checkboxes_on_top - Show checked picker values on top (default) or below the picker prompt (only for multiple pickers)
|
39
39
|
#
|
40
40
|
# Returns nothing.
|
41
41
|
def scopes_picker_field(form, name, root: false, options: { checkboxes_on_top: true })
|
@@ -64,7 +64,7 @@ module Decidim
|
|
64
64
|
# Renders a scopes picker field in a filter form.
|
65
65
|
# form - FilterFormBuilder object
|
66
66
|
# name - attribute name
|
67
|
-
# checkboxes_on_top - Show picker values on top (default) or below the picker prompt
|
67
|
+
# checkboxes_on_top - Show picker values on top (default) or below the picker prompt (only for multiple pickers)
|
68
68
|
#
|
69
69
|
# Returns nothing.
|
70
70
|
def scopes_picker_filter(form, name, checkboxes_on_top = true)
|
@@ -54,6 +54,12 @@ module Decidim
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
def translated_in_current_locale?(attribute)
|
58
|
+
return false if attribute.nil?
|
59
|
+
|
60
|
+
attribute[I18n.locale.to_s].present?
|
61
|
+
end
|
62
|
+
|
63
|
+
module_function :multi_translation, :empty_translatable, :ensure_translatable, :translated_in_current_locale?
|
58
64
|
end
|
59
65
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# This job is part of the machine translation flow. This one specifically
|
5
|
+
# delegates the arguments to the translation service, if any.
|
6
|
+
class MachineTranslationFieldsJob < ApplicationJob
|
7
|
+
queue_as :default
|
8
|
+
|
9
|
+
# Performs the job. It won't perform anything if the
|
10
|
+
# `Decidim.machine_translation_service` config is not set.
|
11
|
+
#
|
12
|
+
# resource - Any kind of `Decidim::TranslatableResource` model instance
|
13
|
+
# field_name - A Symbol representing the name of the field being translated
|
14
|
+
# field_value - A String with the value of the field to translate
|
15
|
+
# target_locale - A Symbol representing the target locale for the translation
|
16
|
+
# source_locale - A Symbol representing the source locale for the translation
|
17
|
+
def perform(resource, field_name, field_value, target_locale, source_locale)
|
18
|
+
klass = Decidim.machine_translation_service_klass
|
19
|
+
return unless klass
|
20
|
+
|
21
|
+
klass.new(
|
22
|
+
resource,
|
23
|
+
field_name,
|
24
|
+
field_value,
|
25
|
+
target_locale,
|
26
|
+
source_locale
|
27
|
+
).translate
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# This job is part of the machine translation flow. This one is fired every
|
5
|
+
# time a `Decidim::TranslatableResource` is created or updated. If any of the
|
6
|
+
# attributes defines as translatable is modified, then for each of those
|
7
|
+
# attributes this job will schedule a `Decidim::MachineTranslationFieldsJob`.
|
8
|
+
class MachineTranslationResourceJob < ApplicationJob
|
9
|
+
queue_as :default
|
10
|
+
|
11
|
+
# Performs the job.
|
12
|
+
#
|
13
|
+
# resource - Any kind of `Decidim::TranslatableResource` model instance
|
14
|
+
# previous_changes - A Hash with the set fo changes. This is intended to be
|
15
|
+
# taken from `resource.previous_changes`, but we need to manually pass
|
16
|
+
# them to the job because the value gets lost when serializing the
|
17
|
+
# resource.
|
18
|
+
# source_locale - A Symbol representing the source locale for the translation
|
19
|
+
def perform(resource, previous_changes, source_locale)
|
20
|
+
return unless Decidim.machine_translation_service_klass
|
21
|
+
|
22
|
+
@resource = resource
|
23
|
+
@locales_to_be_translated = []
|
24
|
+
translatable_fields = @resource.class.translatable_fields_list.map(&:to_s)
|
25
|
+
translatable_fields.each do |field|
|
26
|
+
next unless @resource[field].is_a?(Hash) && previous_changes.keys.include?(field)
|
27
|
+
|
28
|
+
translated_locales = translated_locales_list(field)
|
29
|
+
remove_duplicate_translations(field, translated_locales) if @resource[field]["machine_translations"].present?
|
30
|
+
|
31
|
+
next unless default_locale_changed_or_translation_removed(previous_changes, field)
|
32
|
+
|
33
|
+
@locales_to_be_translated += pending_locales(translated_locales) if @locales_to_be_translated.blank?
|
34
|
+
|
35
|
+
@locales_to_be_translated.each do |target_locale|
|
36
|
+
MachineTranslationFieldsJob.perform_later(
|
37
|
+
resource,
|
38
|
+
field,
|
39
|
+
resource_field_value(
|
40
|
+
previous_changes,
|
41
|
+
field
|
42
|
+
),
|
43
|
+
target_locale,
|
44
|
+
source_locale
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def default_locale_changed_or_translation_removed(previous_changes, field)
|
51
|
+
default_locale = default_locale(@resource)
|
52
|
+
values = previous_changes[field]
|
53
|
+
old_value = values.first
|
54
|
+
new_value = values.last
|
55
|
+
return true unless old_value.is_a?(Hash)
|
56
|
+
|
57
|
+
return true if old_value[default_locale] != new_value[default_locale]
|
58
|
+
|
59
|
+
# In a case where the default locale isn't changed
|
60
|
+
# but a translation of a different locale is deleted
|
61
|
+
# We trigger a job to translate only for that locale
|
62
|
+
if old_value[default_locale] == new_value[default_locale]
|
63
|
+
locales_present = old_value.keys
|
64
|
+
locales_present.each do |locale|
|
65
|
+
@locales_to_be_translated << locale if old_value[locale] != new_value[locale] && new_value[locale] == ""
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
@locales_to_be_translated.present?
|
70
|
+
end
|
71
|
+
|
72
|
+
def resource_field_value(previous_changes, field)
|
73
|
+
values = previous_changes[field]
|
74
|
+
new_value = values.last
|
75
|
+
return new_value[default_locale(@resource)] if new_value.is_a?(Hash)
|
76
|
+
|
77
|
+
new_value
|
78
|
+
end
|
79
|
+
|
80
|
+
def default_locale(resource)
|
81
|
+
if resource.respond_to? :organization
|
82
|
+
resource.organization.default_locale.to_s
|
83
|
+
else
|
84
|
+
Decidim.available_locales.first.to_s
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def translated_locales_list(field)
|
89
|
+
return nil unless @resource[field].is_a? Hash
|
90
|
+
|
91
|
+
translated_locales = []
|
92
|
+
existing_locales = @resource[field].keys - ["machine_translations"]
|
93
|
+
existing_locales.each do |locale|
|
94
|
+
translated_locales << locale if @resource[field][locale].present?
|
95
|
+
end
|
96
|
+
|
97
|
+
translated_locales
|
98
|
+
end
|
99
|
+
|
100
|
+
def remove_duplicate_translations(field, translated_locales)
|
101
|
+
machine_translated_locale = @resource[field]["machine_translations"].keys
|
102
|
+
unless (translated_locales & machine_translated_locale).nil?
|
103
|
+
(translated_locales & machine_translated_locale).each { |key| @resource[field]["machine_translations"].delete key }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def pending_locales(translated_locales)
|
108
|
+
available_locales = @resource.organization.available_locales.map(&:to_s) if @resource.respond_to? :organization
|
109
|
+
available_locales ||= Decidim.available_locales.map(&:to_s)
|
110
|
+
available_locales - translated_locales
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|