decidim-proposals 0.19.1 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/config/admin/decidim_proposals_manifest.js +1 -0
- data/app/assets/images/decidim/gamification/badges/accepted_proposals.svg +1 -234
- data/app/assets/images/decidim/gamification/badges/proposal_votes.svg +1 -95
- data/app/assets/images/decidim/gamification/badges/proposals.svg +1 -229
- data/app/assets/images/decidim/proposals/icon.svg +1 -3
- data/app/assets/javascripts/decidim/proposals/add_proposal.js.es6 +6 -0
- data/app/assets/javascripts/decidim/proposals/admin/proposals.es6 +24 -11
- data/app/assets/javascripts/decidim/proposals/admin/proposals_form.js.es6 +3 -5
- data/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 +35 -0
- data/app/cells/decidim/proposals/collaborative_draft_cell.rb +1 -1
- data/app/cells/decidim/proposals/collaborative_draft_link_to_proposal_cell.rb +1 -1
- data/app/cells/decidim/proposals/collaborative_draft_m/footer.erb +1 -1
- data/app/cells/decidim/proposals/collaborative_draft_m_cell.rb +1 -1
- data/app/cells/decidim/proposals/cost_report/show.erb +35 -0
- data/app/cells/decidim/proposals/cost_report_cell.rb +42 -0
- data/app/cells/decidim/proposals/highlighted_proposals_for_component/show.erb +3 -3
- data/app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb +1 -1
- data/app/cells/decidim/proposals/irreversible_action_modal/show.erb +2 -2
- data/app/cells/decidim/proposals/irreversible_action_modal_cell.rb +1 -1
- data/app/cells/decidim/proposals/participatory_text_proposal/buttons.erb +3 -3
- data/app/cells/decidim/proposals/participatory_text_proposal_cell.rb +2 -2
- data/app/cells/decidim/proposals/proposal_cell.rb +1 -1
- data/app/cells/decidim/proposals/proposal_m/footer.erb +4 -1
- data/app/cells/decidim/proposals/proposal_m_cell.rb +37 -9
- data/app/cells/decidim/proposals/proposal_tags/show.erb +18 -10
- data/app/cells/decidim/proposals/proposal_tags_cell.rb +5 -0
- data/app/cells/decidim/proposals/proposals_picker/proposals.erb +12 -0
- data/app/cells/decidim/proposals/proposals_picker/show.erb +14 -0
- data/app/cells/decidim/proposals/proposals_picker_cell.rb +72 -0
- data/app/commands/decidim/proposals/admin/answer_proposal.rb +24 -46
- data/app/commands/decidim/proposals/admin/assign_proposals_to_valuator.rb +61 -0
- data/app/commands/decidim/proposals/admin/create_proposal.rb +10 -3
- data/app/commands/decidim/proposals/admin/create_proposal_note.rb +15 -0
- data/app/commands/decidim/proposals/admin/notify_proposal_answer.rb +85 -0
- data/app/commands/decidim/proposals/admin/publish_answers.rb +67 -0
- data/app/commands/decidim/proposals/admin/publish_participatory_text.rb +6 -1
- data/app/commands/decidim/proposals/admin/unassign_proposals_from_valuator.rb +62 -0
- data/app/commands/decidim/proposals/admin/update_participatory_text.rb +10 -2
- data/app/commands/decidim/proposals/admin/update_proposal.rb +5 -3
- data/app/commands/decidim/proposals/admin/update_proposal_scope.rb +75 -0
- data/app/commands/decidim/proposals/create_collaborative_draft.rb +1 -1
- data/app/commands/decidim/proposals/create_proposal.rb +7 -3
- data/app/commands/decidim/proposals/gallery_methods.rb +2 -51
- data/app/commands/decidim/proposals/publish_collaborative_draft.rb +2 -2
- data/app/commands/decidim/proposals/update_proposal.rb +25 -9
- data/app/controllers/concerns/decidim/proposals/admin/filterable.rb +82 -0
- data/app/controllers/concerns/decidim/proposals/admin/picker.rb +21 -0
- data/app/controllers/concerns/decidim/proposals/orderable.rb +13 -2
- data/app/controllers/decidim/proposals/admin/proposal_answers_controller.rb +16 -6
- data/app/controllers/decidim/proposals/admin/proposal_notes_controller.rb +8 -9
- data/app/controllers/decidim/proposals/admin/proposals_controller.rb +107 -31
- data/app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb +58 -0
- data/app/controllers/decidim/proposals/collaborative_drafts_controller.rb +10 -3
- data/app/controllers/decidim/proposals/proposals_controller.rb +31 -11
- data/app/controllers/decidim/proposals/versions_controller.rb +9 -16
- data/app/controllers/decidim/proposals/{proposal_widgets_controller.rb → widgets_controller.rb} +2 -2
- data/app/events/decidim/proposals/admin/proposal_note_created_event.rb +27 -0
- data/app/events/decidim/proposals/admin/update_proposal_scope_event.rb +11 -0
- data/app/forms/decidim/proposals/admin/import_participatory_text_form.rb +3 -1
- data/app/forms/decidim/proposals/admin/participatory_text_proposal_form.rb +20 -0
- data/app/forms/decidim/proposals/admin/preview_participatory_text_form.rb +2 -2
- data/app/forms/decidim/proposals/admin/proposal_answer_form.rb +27 -2
- data/app/forms/decidim/proposals/admin/proposal_base_form.rb +136 -0
- data/app/forms/decidim/proposals/admin/proposal_form.rb +6 -117
- data/app/forms/decidim/proposals/admin/valuation_assignment_form.rb +37 -0
- data/app/forms/decidim/proposals/proposal_form.rb +25 -12
- data/app/forms/decidim/proposals/proposal_wizard_create_step_form.rb +13 -1
- data/app/helpers/decidim/proposals/admin/filterable_helper.rb +17 -0
- data/app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb +35 -0
- data/app/helpers/decidim/proposals/admin/proposal_rankings_helper.rb +63 -0
- data/app/helpers/decidim/proposals/admin/proposals_helper.rb +124 -0
- data/app/helpers/decidim/proposals/admin/proposals_picker_helper.rb +30 -0
- data/app/helpers/decidim/proposals/application_helper.rb +64 -38
- data/app/helpers/decidim/proposals/collaborative_draft_helper.rb +9 -9
- data/app/helpers/decidim/proposals/control_version_helper.rb +1 -37
- data/app/helpers/decidim/proposals/proposal_cells_helper.rb +1 -1
- data/app/helpers/decidim/proposals/proposal_endorsements_helper.rb +0 -145
- data/app/helpers/decidim/proposals/proposal_votes_helper.rb +2 -2
- data/app/helpers/decidim/proposals/proposal_wizard_helper.rb +24 -7
- data/app/helpers/decidim/proposals/proposals_helper.rb +66 -0
- data/app/models/decidim/proposals/collaborative_draft.rb +2 -2
- data/app/models/decidim/proposals/participatory_text.rb +3 -0
- data/app/models/decidim/proposals/proposal.rb +153 -42
- data/app/models/decidim/proposals/valuation_assignment.rb +24 -0
- data/app/permissions/decidim/proposals/admin/permissions.rb +77 -11
- data/app/permissions/decidim/proposals/permissions.rb +1 -22
- data/app/presenters/decidim/proposals/admin_log/proposal_presenter.rb +1 -1
- data/app/presenters/decidim/proposals/admin_log/valuation_assignment_presenter.rb +51 -0
- data/app/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter.rb +6 -1
- data/app/presenters/decidim/proposals/admin_log/value_types/valuator_role_user_presenter.rb +19 -0
- data/app/presenters/decidim/proposals/collaborative_draft_presenter.rb +2 -28
- data/app/presenters/decidim/proposals/log/valuation_assignment_presenter.rb +22 -0
- data/app/presenters/decidim/proposals/official_author_presenter.rb +1 -29
- data/app/presenters/decidim/proposals/proposal_presenter.rb +80 -12
- data/app/queries/decidim/proposals/metrics/accepted_proposals_metric_manage.rb +1 -2
- data/app/queries/decidim/proposals/metrics/endorsements_metric_manage.rb +15 -12
- data/app/queries/decidim/proposals/metrics/proposal_participants_metric_measure.rb +5 -4
- data/app/queries/decidim/proposals/metrics/proposals_metric_manage.rb +2 -8
- data/app/queries/decidim/proposals/metrics/votes_metric_manage.rb +3 -9
- data/app/queries/decidim/proposals/similar_proposals.rb +4 -4
- data/app/services/decidim/proposals/collaborative_draft_search.rb +8 -10
- data/app/services/decidim/proposals/diff_renderer.rb +17 -5
- data/app/services/decidim/proposals/proposal_builder.rb +9 -3
- data/app/services/decidim/proposals/proposal_search.rb +17 -70
- data/app/types/decidim/proposals/proposal_input_filter.rb +29 -0
- data/app/types/decidim/proposals/proposal_input_sort.rb +22 -0
- data/app/types/decidim/proposals/proposal_type.rb +34 -13
- data/app/types/decidim/proposals/proposals_type.rb +22 -15
- data/app/validators/proposal_length_validator.rb +38 -0
- data/app/views/decidim/proposals/admin/participatory_texts/index.html.erb +9 -1
- data/app/views/decidim/proposals/admin/proposal_answers/_form.html.erb +35 -0
- data/app/views/decidim/proposals/admin/proposal_notes/_form.html.erb +1 -1
- data/app/views/decidim/proposals/admin/proposal_notes/_proposal_notes.html.erb +3 -3
- data/app/views/decidim/proposals/admin/proposals/_bulk-actions.html.erb +8 -2
- data/app/views/decidim/proposals/admin/proposals/_form.html.erb +8 -28
- data/app/views/decidim/proposals/admin/proposals/_proposal-tr.html.erb +26 -27
- data/app/views/decidim/proposals/admin/proposals/bulk_actions/_assign_to_valuator.html.erb +15 -0
- data/app/views/decidim/proposals/admin/proposals/bulk_actions/_dropdown.html.erb +21 -1
- data/app/views/decidim/proposals/admin/proposals/bulk_actions/_publish_answers.html.erb +14 -0
- data/app/views/decidim/proposals/admin/proposals/bulk_actions/_scope-change.html.erb +25 -0
- data/app/views/decidim/proposals/admin/proposals/bulk_actions/_unassign_from_valuator.html.erb +15 -0
- data/app/views/decidim/proposals/admin/proposals/index.html.erb +18 -9
- data/app/views/decidim/proposals/admin/proposals/publish_answers.js.erb +12 -0
- data/app/views/decidim/proposals/admin/proposals/show.html.erb +186 -0
- data/app/views/decidim/proposals/admin/proposals/update_category.js.erb +3 -2
- data/app/views/decidim/proposals/admin/proposals/update_scope.js.erb +27 -0
- data/app/views/decidim/proposals/collaborative_drafts/_edit_form_fields.html.erb +11 -9
- data/app/views/decidim/proposals/collaborative_drafts/_filters.html.erb +10 -8
- data/app/views/decidim/proposals/collaborative_drafts/_new_collaborative_draft_button.html.erb +4 -4
- data/app/views/decidim/proposals/collaborative_drafts/_reject_request_access_form.html.erb +1 -1
- data/app/views/decidim/proposals/collaborative_drafts/_wizard_aside.html.erb +4 -2
- data/app/views/decidim/proposals/collaborative_drafts/compare.html.erb +2 -0
- data/app/views/decidim/proposals/collaborative_drafts/complete.html.erb +2 -0
- data/app/views/decidim/proposals/collaborative_drafts/edit.html.erb +3 -1
- data/app/views/decidim/proposals/collaborative_drafts/index.html.erb +4 -2
- data/app/views/decidim/proposals/collaborative_drafts/new.html.erb +4 -0
- data/app/views/decidim/proposals/collaborative_drafts/show.html.erb +29 -30
- data/app/views/decidim/proposals/proposals/_edit_form_fields.html.erb +52 -22
- data/app/views/decidim/proposals/proposals/_endorsements_card_row.html.erb +0 -16
- data/app/views/decidim/proposals/proposals/_filters.html.erb +19 -17
- data/app/views/decidim/proposals/proposals/_proposal_badge.html.erb +1 -4
- data/app/views/decidim/proposals/proposals/_proposal_preview.html.erb +1 -11
- data/app/views/decidim/proposals/proposals/_proposal_similar.html.erb +2 -2
- data/app/views/decidim/proposals/proposals/_proposals.html.erb +14 -0
- data/app/views/decidim/proposals/proposals/_vote_button.html.erb +14 -7
- data/app/views/decidim/proposals/proposals/_wizard_aside.html.erb +4 -2
- data/app/views/decidim/proposals/proposals/_wizard_header.html.erb +4 -3
- data/app/views/decidim/proposals/proposals/compare.html.erb +2 -0
- data/app/views/decidim/proposals/proposals/complete.html.erb +2 -0
- data/app/views/decidim/proposals/proposals/edit.html.erb +3 -1
- data/app/views/decidim/proposals/proposals/edit_draft.html.erb +2 -0
- data/app/views/decidim/proposals/proposals/index.html.erb +7 -14
- data/app/views/decidim/proposals/proposals/new.html.erb +6 -2
- data/app/views/decidim/proposals/proposals/participatory_texts/_index.html.erb +1 -1
- data/app/views/decidim/proposals/proposals/participatory_texts/_proposal_vote_button.html.erb +10 -3
- data/app/views/decidim/proposals/proposals/participatory_texts/_view_index.html.erb +1 -1
- data/app/views/decidim/proposals/proposals/preview.html.erb +7 -8
- data/app/views/decidim/proposals/proposals/show.html.erb +62 -71
- data/app/views/decidim/proposals/versions/index.html.erb +14 -32
- data/app/views/decidim/proposals/versions/show.html.erb +16 -34
- data/config/locales/am-ET.yml +1 -0
- data/config/locales/ar.yml +73 -67
- data/config/locales/bg-BG.yml +237 -0
- data/config/locales/bg.yml +237 -0
- data/config/locales/ca.yml +183 -67
- data/config/locales/cs.yml +196 -80
- data/config/locales/da-DK.yml +1 -0
- data/config/locales/da.yml +1 -0
- data/config/locales/de.yml +269 -162
- data/config/locales/el-GR.yml +1 -0
- data/config/locales/el.yml +876 -0
- data/config/locales/en.yml +187 -71
- data/config/locales/eo.yml +1 -0
- data/config/locales/es-MX.yml +181 -65
- data/config/locales/es-PY.yml +181 -65
- data/config/locales/es.yml +186 -70
- data/config/locales/et-EE.yml +1 -0
- data/config/locales/et.yml +1 -0
- data/config/locales/eu.yml +28 -63
- data/config/locales/fi-plain.yml +181 -65
- data/config/locales/fi.yml +219 -103
- data/config/locales/fr-CA.yml +906 -0
- data/config/locales/fr.yml +184 -68
- data/config/locales/ga-IE.yml +1 -0
- data/config/locales/gl.yml +28 -63
- data/config/locales/hr-HR.yml +1 -0
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +148 -70
- data/config/locales/id-ID.yml +28 -62
- data/config/locales/is-IS.yml +274 -0
- data/config/locales/is.yml +274 -0
- data/config/locales/it.yml +177 -85
- data/config/locales/ja-JP.yml +865 -0
- data/config/locales/ja.yml +889 -0
- data/config/locales/ko-KR.yml +1 -0
- data/config/locales/ko.yml +1 -0
- data/config/locales/lt-LT.yml +1 -0
- data/config/locales/lt.yml +1 -0
- data/config/locales/lv.yml +858 -0
- data/config/locales/mt-MT.yml +1 -0
- data/config/locales/mt.yml +1 -0
- data/config/locales/nl.yml +282 -188
- data/config/locales/no.yml +586 -19
- data/config/locales/om-ET.yml +1 -0
- data/config/locales/pl.yml +524 -393
- data/config/locales/pt-BR.yml +29 -67
- data/config/locales/pt.yml +438 -331
- data/config/locales/ro-RO.yml +841 -0
- data/config/locales/ru.yml +14 -47
- data/config/locales/sk-SK.yml +896 -0
- data/config/locales/sk.yml +869 -0
- data/config/locales/sl.yml +26 -0
- data/config/locales/so-SO.yml +1 -0
- data/config/locales/sr-CS.yml +126 -0
- data/config/locales/sv.yml +285 -171
- data/config/locales/ti-ER.yml +1 -0
- data/config/locales/tr-TR.yml +28 -63
- data/config/locales/uk.yml +14 -47
- data/config/locales/vi-VN.yml +1 -0
- data/config/locales/vi.yml +1 -0
- data/config/locales/zh-CN.yml +885 -0
- data/config/locales/zh-TW.yml +1 -0
- data/db/migrate/20181003074440_fix_user_groups_ids_in_proposals_endorsements.rb +4 -0
- data/db/migrate/20191206154128_add_endorsements_counter_cache_to_proposals.rb +7 -0
- data/db/migrate/20200120215928_move_proposal_endorsements_to_core_endorsements.rb +54 -0
- data/db/migrate/20200120230130_drop_proposal_endorsements.rb +8 -0
- data/db/migrate/20200203111239_add_proposal_valuation_assignments.rb +12 -0
- data/db/migrate/20200210135152_add_costs_to_proposals.rb +9 -0
- data/db/migrate/20200212120110_sync_proposals_state_with_amendments_state.rb +28 -0
- data/db/migrate/20200227175922_add_state_published_at_to_proposals.rb +7 -0
- data/db/migrate/20200306123652_publish_existing_proposals_state.rb +15 -0
- data/db/migrate/20200708091228_move_proposals_fields_to_i18n.rb +80 -0
- data/db/migrate/20200730131631_move_proposal_endorsed_event_notifications_to_resource_endorsed_event.rb +20 -0
- data/db/migrate/20200827154156_add_commentable_counter_cache_to_proposals.rb +12 -0
- data/db/migrate/20200915151348_fix_proposals_data_to_ensure_title_and_body_are_hashes.rb +37 -0
- data/db/migrate/20201002085508_fix_proposals_data.rb +37 -0
- data/lib/decidim/content_renderers/proposal_renderer.rb +3 -1
- data/lib/decidim/proposals.rb +1 -0
- data/lib/decidim/proposals/admin_engine.rb +7 -3
- data/lib/decidim/proposals/component.rb +55 -28
- data/lib/decidim/proposals/engine.rb +3 -7
- data/lib/decidim/proposals/markdown_to_proposals.rb +2 -2
- data/lib/decidim/proposals/proposal_serializer.rb +3 -3
- data/lib/decidim/proposals/test/capybara_proposals_picker.rb +49 -0
- data/lib/decidim/proposals/test/factories.rb +100 -28
- data/lib/decidim/proposals/valuatable.rb +21 -0
- data/lib/decidim/proposals/version.rb +1 -1
- metadata +119 -54
- data/app/assets/javascripts/decidim/proposals/identity_selector_dialog.js.es6 +0 -56
- data/app/cells/decidim/proposals/endorsers_list/show.erb +0 -17
- data/app/cells/decidim/proposals/endorsers_list_cell.rb +0 -31
- data/app/commands/decidim/proposals/attachment_methods.rb +0 -43
- data/app/commands/decidim/proposals/endorse_proposal.rb +0 -59
- data/app/commands/decidim/proposals/unendorse_proposal.rb +0 -40
- data/app/controllers/decidim/proposals/proposal_endorsements_controller.rb +0 -60
- data/app/models/decidim/proposals/proposal_endorsement.rb +0 -37
- data/app/views/decidim/proposals/admin/proposal_answers/edit.html.erb +0 -22
- data/app/views/decidim/proposals/admin/proposal_notes/index.html.erb +0 -3
- data/app/views/decidim/proposals/admin/shared/_info_proposal.html.erb +0 -20
- data/app/views/decidim/proposals/proposal_endorsements/_identity.html.erb +0 -9
- data/app/views/decidim/proposals/proposal_endorsements/identities.html.erb +0 -12
- data/app/views/decidim/proposals/proposal_endorsements/update_buttons_and_counters.js.erb +0 -20
- data/app/views/decidim/proposals/proposal_widgets/show.html.erb +0 -4
- data/app/views/decidim/proposals/proposals/_endorsement_button.html.erb +0 -11
- data/app/views/decidim/proposals/proposals/_endorsement_identities_cabin.html.erb +0 -13
- data/app/views/decidim/proposals/versions/_version.html.erb +0 -20
@@ -4,126 +4,15 @@ module Decidim
|
|
4
4
|
module Proposals
|
5
5
|
module Admin
|
6
6
|
# A form object to be used when admin users want to create a proposal.
|
7
|
-
class ProposalForm < Decidim::
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
attribute :title, String
|
12
|
-
attribute :body, String
|
13
|
-
attribute :address, String
|
14
|
-
attribute :latitude, Float
|
15
|
-
attribute :longitude, Float
|
16
|
-
attribute :category_id, Integer
|
17
|
-
attribute :scope_id, Integer
|
18
|
-
attribute :attachment, AttachmentForm
|
19
|
-
attribute :position, Integer
|
20
|
-
attribute :created_in_meeting, Boolean
|
21
|
-
attribute :meeting_id, Integer
|
22
|
-
attribute :suggested_hashtags, Array[String]
|
23
|
-
attribute :photos, Array[String]
|
24
|
-
attribute :add_photos, Array
|
25
|
-
|
26
|
-
validates :title, :body, presence: true
|
27
|
-
validates :title, length: { maximum: 150 }
|
28
|
-
validates :address, geocoding: true, if: -> { current_component.settings.geocoding_enabled? }
|
29
|
-
validates :category, presence: true, if: ->(form) { form.category_id.present? }
|
30
|
-
validates :scope, presence: true, if: ->(form) { form.scope_id.present? }
|
31
|
-
validates :meeting_as_author, presence: true, if: ->(form) { form.created_in_meeting? }
|
32
|
-
|
33
|
-
validate :scope_belongs_to_participatory_space_scope
|
34
|
-
|
35
|
-
validate :notify_missing_attachment_if_errored
|
36
|
-
|
37
|
-
delegate :categories, to: :current_component
|
38
|
-
|
39
|
-
def map_model(model)
|
40
|
-
return unless model.categorization
|
41
|
-
|
42
|
-
self.category_id = model.categorization.decidim_category_id
|
43
|
-
self.scope_id = model.decidim_scope_id
|
44
|
-
|
45
|
-
@suggested_hashtags = Decidim::ContentRenderers::HashtagRenderer.new(model.body).extra_hashtags.map(&:name).map(&:downcase)
|
46
|
-
end
|
47
|
-
|
48
|
-
alias component current_component
|
49
|
-
|
50
|
-
# Finds the Category from the category_id.
|
51
|
-
#
|
52
|
-
# Returns a Decidim::Category
|
53
|
-
def category
|
54
|
-
@category ||= categories.find_by(id: category_id)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Finds the Scope from the given decidim_scope_id, uses participatory space scope if missing.
|
58
|
-
#
|
59
|
-
# Returns a Decidim::Scope
|
60
|
-
def scope
|
61
|
-
@scope ||= @scope_id ? current_participatory_space.scopes.find_by(id: @scope_id) : current_participatory_space.scope
|
62
|
-
end
|
63
|
-
|
64
|
-
# Scope identifier
|
65
|
-
#
|
66
|
-
# Returns the scope identifier related to the proposal
|
67
|
-
def scope_id
|
68
|
-
@scope_id || scope&.id
|
69
|
-
end
|
70
|
-
|
71
|
-
# Finds the Meetings of the current participatory space
|
72
|
-
def meetings
|
73
|
-
@meetings ||= Decidim.find_resource_manifest(:meetings).try(:resource_scope, current_component)
|
74
|
-
&.order(title: :asc)
|
75
|
-
end
|
76
|
-
|
77
|
-
# Return the meeting as author
|
78
|
-
def meeting_as_author
|
79
|
-
@meeting_as_author ||= meetings.find_by(id: meeting_id)
|
7
|
+
class ProposalForm < Decidim::Proposals::Admin::ProposalBaseForm
|
8
|
+
translatable_attribute :title, String do |field, _locale|
|
9
|
+
validates field, length: { in: 15..150 }, if: proc { |resource| resource.send(field).present? }
|
80
10
|
end
|
11
|
+
translatable_attribute :body, String
|
81
12
|
|
82
|
-
|
83
|
-
return current_organization unless created_in_meeting?
|
13
|
+
validates :title, :body, translatable_presence: true
|
84
14
|
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
def extra_hashtags
|
89
|
-
@extra_hashtags ||= (component_automatic_hashtags + suggested_hashtags).uniq
|
90
|
-
end
|
91
|
-
|
92
|
-
def suggested_hashtags
|
93
|
-
downcased_suggested_hashtags = Array(@suggested_hashtags&.map(&:downcase)).to_set
|
94
|
-
component_suggested_hashtags.select { |hashtag| downcased_suggested_hashtags.member?(hashtag.downcase) }
|
95
|
-
end
|
96
|
-
|
97
|
-
def suggested_hashtag_checked?(hashtag)
|
98
|
-
suggested_hashtags.member?(hashtag)
|
99
|
-
end
|
100
|
-
|
101
|
-
def component_automatic_hashtags
|
102
|
-
@component_automatic_hashtags ||= ordered_hashtag_list(current_component.current_settings.automatic_hashtags)
|
103
|
-
end
|
104
|
-
|
105
|
-
def component_suggested_hashtags
|
106
|
-
@component_suggested_hashtags ||= ordered_hashtag_list(current_component.current_settings.suggested_hashtags)
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
def scope_belongs_to_participatory_space_scope
|
112
|
-
errors.add(:scope_id, :invalid) if current_participatory_space.out_of_scope?(scope)
|
113
|
-
end
|
114
|
-
|
115
|
-
# This method will add an error to the `attachment` field only if there's
|
116
|
-
# any error in any other field. This is needed because when the form has
|
117
|
-
# an error, the attachment is lost, so we need a way to inform the user of
|
118
|
-
# this problem.
|
119
|
-
def notify_missing_attachment_if_errored
|
120
|
-
errors.add(:attachment, :needs_to_be_reattached) if errors.any? && attachment.present?
|
121
|
-
errors.add(:add_photos, :needs_to_be_reattached) if errors.any? && add_photos.present?
|
122
|
-
end
|
123
|
-
|
124
|
-
def ordered_hashtag_list(string)
|
125
|
-
string.to_s.split.reject(&:blank?).uniq.sort_by(&:parameterize)
|
126
|
-
end
|
15
|
+
validate :notify_missing_attachment_if_errored
|
127
16
|
end
|
128
17
|
end
|
129
18
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Proposals
|
5
|
+
module Admin
|
6
|
+
class ValuationAssignmentForm < Decidim::Form
|
7
|
+
mimic :valuator_role
|
8
|
+
|
9
|
+
attribute :id, Integer
|
10
|
+
attribute :proposal_ids, Array
|
11
|
+
|
12
|
+
validates :valuator_role, :proposals, :current_component, presence: true
|
13
|
+
validate :same_participatory_space
|
14
|
+
|
15
|
+
def proposals
|
16
|
+
@proposals ||= Decidim::Proposals::Proposal.where(component: current_component, id: proposal_ids).uniq
|
17
|
+
end
|
18
|
+
|
19
|
+
def valuator_role
|
20
|
+
@valuator_role ||= current_component.participatory_space.user_roles(:valuator).find_by(id: id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def valuator_user
|
24
|
+
return unless valuator_role
|
25
|
+
|
26
|
+
@valuator_user ||= valuator_role.user
|
27
|
+
end
|
28
|
+
|
29
|
+
def same_participatory_space
|
30
|
+
return if !valuator_role || !current_component
|
31
|
+
|
32
|
+
errors.add(:id, :invalid) if current_component.participatory_space != valuator_role.participatory_space
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -4,6 +4,8 @@ module Decidim
|
|
4
4
|
module Proposals
|
5
5
|
# A form object to be used when public users want to create a proposal.
|
6
6
|
class ProposalForm < Decidim::Proposals::ProposalWizardCreateStepForm
|
7
|
+
include Decidim::TranslatableAttributes
|
8
|
+
|
7
9
|
mimic :proposal
|
8
10
|
|
9
11
|
attribute :address, String
|
@@ -14,14 +16,16 @@ module Decidim
|
|
14
16
|
attribute :has_address, Boolean
|
15
17
|
attribute :attachment, AttachmentForm
|
16
18
|
attribute :suggested_hashtags, Array[String]
|
19
|
+
attribute :photos, Array[String]
|
20
|
+
attribute :add_photos, Array
|
21
|
+
attribute :documents, Array[String]
|
22
|
+
attribute :add_documents, Array
|
17
23
|
|
18
|
-
validates :address, geocoding: true, if: ->(form) {
|
24
|
+
validates :address, geocoding: true, if: ->(form) { form.has_address? && !form.geocoded? }
|
19
25
|
validates :address, presence: true, if: ->(form) { form.has_address? }
|
20
26
|
validates :category, presence: true, if: ->(form) { form.category_id.present? }
|
21
27
|
validates :scope, presence: true, if: ->(form) { form.scope_id.present? }
|
22
|
-
|
23
|
-
validate :scope_belongs_to_participatory_space_scope
|
24
|
-
|
28
|
+
validates :scope_id, scope_belongs_to_component: true, if: ->(form) { form.scope_id.present? }
|
25
29
|
validate :notify_missing_attachment_if_errored
|
26
30
|
|
27
31
|
delegate :categories, to: :current_component
|
@@ -29,7 +33,12 @@ module Decidim
|
|
29
33
|
def map_model(model)
|
30
34
|
super
|
31
35
|
|
32
|
-
|
36
|
+
body = translated_attribute(model.body)
|
37
|
+
@suggested_hashtags = Decidim::ContentRenderers::HashtagRenderer.new(body).extra_hashtags.map(&:name).map(&:downcase)
|
38
|
+
|
39
|
+
# The scope attribute is with different key (decidim_scope_id), so it
|
40
|
+
# has to be manually mapped.
|
41
|
+
self.scope_id = model.scope.id if model.scope
|
33
42
|
end
|
34
43
|
|
35
44
|
# Finds the Category from the category_id.
|
@@ -39,11 +48,11 @@ module Decidim
|
|
39
48
|
@category ||= categories.find_by(id: category_id)
|
40
49
|
end
|
41
50
|
|
42
|
-
# Finds the Scope from the given
|
51
|
+
# Finds the Scope from the given scope_id, uses participatory space scope if missing.
|
43
52
|
#
|
44
53
|
# Returns a Decidim::Scope
|
45
54
|
def scope
|
46
|
-
@scope ||= @scope_id ?
|
55
|
+
@scope ||= @scope_id ? current_component.scopes.find_by(id: @scope_id) : current_component.scope
|
47
56
|
end
|
48
57
|
|
49
58
|
# Scope identifier
|
@@ -53,8 +62,16 @@ module Decidim
|
|
53
62
|
@scope_id || scope&.id
|
54
63
|
end
|
55
64
|
|
65
|
+
def geocoding_enabled?
|
66
|
+
Decidim::Map.available?(:geocoding) && current_component.settings.geocoding_enabled?
|
67
|
+
end
|
68
|
+
|
56
69
|
def has_address?
|
57
|
-
|
70
|
+
geocoding_enabled? && has_address
|
71
|
+
end
|
72
|
+
|
73
|
+
def geocoded?
|
74
|
+
latitude.present? && longitude.present?
|
58
75
|
end
|
59
76
|
|
60
77
|
def extra_hashtags
|
@@ -80,10 +97,6 @@ module Decidim
|
|
80
97
|
|
81
98
|
private
|
82
99
|
|
83
|
-
def scope_belongs_to_participatory_space_scope
|
84
|
-
errors.add(:scope_id, :invalid) if current_participatory_space.out_of_scope?(scope)
|
85
|
-
end
|
86
|
-
|
87
100
|
# This method will add an error to the `attachment` field only if there's
|
88
101
|
# any error in any other field. This is needed because when the form has
|
89
102
|
# an error, the attachment is lost, so we need a way to inform the user of
|
@@ -8,12 +8,18 @@ module Decidim
|
|
8
8
|
|
9
9
|
attribute :title, String
|
10
10
|
attribute :body, String
|
11
|
+
attribute :body_template, String
|
11
12
|
attribute :user_group_id, Integer
|
12
13
|
|
13
14
|
validates :title, :body, presence: true, etiquette: true
|
14
|
-
validates :title, length: {
|
15
|
+
validates :title, length: { in: 15..150 }
|
16
|
+
validates :body, proposal_length: {
|
17
|
+
minimum: 15,
|
18
|
+
maximum: ->(record) { record.component.settings.proposal_length }
|
19
|
+
}
|
15
20
|
|
16
21
|
validate :proposal_length
|
22
|
+
validate :body_is_not_bare_template
|
17
23
|
|
18
24
|
alias component current_component
|
19
25
|
|
@@ -32,6 +38,12 @@ module Decidim
|
|
32
38
|
length = current_component.settings.proposal_length
|
33
39
|
errors.add(:body, :too_long, count: length) if body.length > length
|
34
40
|
end
|
41
|
+
|
42
|
+
def body_is_not_bare_template
|
43
|
+
return if body_template.blank?
|
44
|
+
|
45
|
+
errors.add(:body, :cant_be_equal_to_template) if body.presence == body_template.presence
|
46
|
+
end
|
35
47
|
end
|
36
48
|
end
|
37
49
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Proposals
|
5
|
+
module Admin
|
6
|
+
module FilterableHelper
|
7
|
+
def extra_dropdown_submenu_options_items(filter, i18n_scope)
|
8
|
+
options = case filter
|
9
|
+
when :state_eq
|
10
|
+
content_tag(:li, filter_link_value(:state_null, true, i18n_scope))
|
11
|
+
end
|
12
|
+
[options].compact
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Proposals
|
5
|
+
module Admin
|
6
|
+
module ProposalBulkActionsHelper
|
7
|
+
# Public: Generates a select field with the valuators of the given participatory space.
|
8
|
+
#
|
9
|
+
# participatory_space - A participatory space instance.
|
10
|
+
# prompt - An i18n string to show as prompt
|
11
|
+
#
|
12
|
+
# Returns a String.
|
13
|
+
def bulk_valuators_select(participatory_space, prompt)
|
14
|
+
options_for_select = find_valuators_for_select(participatory_space)
|
15
|
+
select(:valuator_role, :id, options_for_select, prompt: prompt)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Internal: A method to cache to queries to find the valuators for the
|
19
|
+
# current space.
|
20
|
+
def find_valuators_for_select(participatory_space)
|
21
|
+
return @valuators_for_select if @valuators_for_select
|
22
|
+
|
23
|
+
valuator_roles = participatory_space.user_roles(:valuator)
|
24
|
+
valuators = Decidim::User.where(id: valuator_roles.pluck(:decidim_user_id)).to_a
|
25
|
+
|
26
|
+
@valuators_for_select = valuator_roles.map do |role|
|
27
|
+
valuator = valuators.find { |user| user.id == role.decidim_user_id }
|
28
|
+
|
29
|
+
[valuator.name, role.id]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Proposals
|
5
|
+
module Admin
|
6
|
+
# This class contains helpers needed to get rankings for a given proposal
|
7
|
+
# ordered by some given criteria.
|
8
|
+
#
|
9
|
+
module ProposalRankingsHelper
|
10
|
+
# Public: Gets the ranking for a given proposal, ordered by some given
|
11
|
+
# criteria. Proposal is sorted amongst its own siblings.
|
12
|
+
#
|
13
|
+
# Returns a Hash with two keys:
|
14
|
+
# :ranking - an Integer representing the ranking for the given proposal.
|
15
|
+
# Ranking starts with 1.
|
16
|
+
# :total - an Integer representing the total number of ranked proposals.
|
17
|
+
#
|
18
|
+
# Examples:
|
19
|
+
# ranking_for(proposal, proposal_votes_count: :desc)
|
20
|
+
# ranking_for(proposal, endorsements_count: :desc)
|
21
|
+
def ranking_for(proposal, order = {})
|
22
|
+
siblings = Decidim::Proposals::Proposal.where(component: proposal.component)
|
23
|
+
ranked = siblings.order([order, id: :asc])
|
24
|
+
ranked_ids = ranked.pluck(:id)
|
25
|
+
|
26
|
+
{ ranking: ranked_ids.index(proposal.id) + 1, total: ranked_ids.count }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Public: Gets the ranking for a given proposal, ordered by endorsements.
|
30
|
+
def endorsements_ranking_for(proposal)
|
31
|
+
ranking_for(proposal, endorsements_count: :desc)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Public: Gets the ranking for a given proposal, ordered by votes.
|
35
|
+
def votes_ranking_for(proposal)
|
36
|
+
ranking_for(proposal, proposal_votes_count: :desc)
|
37
|
+
end
|
38
|
+
|
39
|
+
def i18n_endorsements_ranking_for(proposal)
|
40
|
+
rankings = endorsements_ranking_for(proposal)
|
41
|
+
|
42
|
+
I18n.t(
|
43
|
+
"ranking",
|
44
|
+
scope: "decidim.proposals.admin.proposals.show",
|
45
|
+
ranking: rankings[:ranking],
|
46
|
+
total: rankings[:total]
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def i18n_votes_ranking_for(proposal)
|
51
|
+
rankings = votes_ranking_for(proposal)
|
52
|
+
|
53
|
+
I18n.t(
|
54
|
+
"ranking",
|
55
|
+
scope: "decidim.proposals.admin.proposals.show",
|
56
|
+
ranking: rankings[:ranking],
|
57
|
+
total: rankings[:total]
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -7,6 +7,8 @@ module Decidim
|
|
7
7
|
# in order to use them in select forms for Proposals.
|
8
8
|
#
|
9
9
|
module ProposalsHelper
|
10
|
+
include Decidim::Admin::ResourceScopeHelper
|
11
|
+
|
10
12
|
# Public: A formatted collection of Meetings to be used
|
11
13
|
# in forms.
|
12
14
|
def meetings_as_authors_selected
|
@@ -14,6 +16,128 @@ module Decidim
|
|
14
16
|
|
15
17
|
@meetings_as_authors_selected ||= @proposal.authors.pluck(:id)
|
16
18
|
end
|
19
|
+
|
20
|
+
def coauthor_presenters_for(proposal)
|
21
|
+
proposal.authors.map do |identity|
|
22
|
+
if identity.is_a?(Decidim::Organization)
|
23
|
+
Decidim::Proposals::OfficialAuthorPresenter.new
|
24
|
+
else
|
25
|
+
present(identity)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def endorsers_presenters_for(proposal)
|
31
|
+
proposal.endorsements.for_listing.map { |identity| present(identity.normalized_author) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def proposal_complete_state(proposal)
|
35
|
+
state = humanize_proposal_state(proposal.state)
|
36
|
+
state += " (#{humanize_proposal_state(proposal.internal_state)})" if proposal.answered? && !proposal.published_state?
|
37
|
+
state.html_safe
|
38
|
+
end
|
39
|
+
|
40
|
+
def proposals_admin_filter_tree
|
41
|
+
{
|
42
|
+
t("proposals.filters.type", scope: "decidim.proposals") => {
|
43
|
+
link_to(t("proposals", scope: "decidim.proposals.application_helper.filter_type_values"), q: ransak_params_for_query(is_emendation_true: "0"),
|
44
|
+
per_page: per_page) => nil,
|
45
|
+
link_to(t("amendments", scope: "decidim.proposals.application_helper.filter_type_values"), q: ransak_params_for_query(is_emendation_true: "1"),
|
46
|
+
per_page: per_page) => nil
|
47
|
+
},
|
48
|
+
t("models.proposal.fields.state", scope: "decidim.proposals") =>
|
49
|
+
Decidim::Proposals::Proposal::POSSIBLE_STATES.each_with_object({}) do |state, hash|
|
50
|
+
if state == "not_answered"
|
51
|
+
hash[link_to((humanize_proposal_state state), q: ransak_params_for_query(state_null: 1), per_page: per_page)] = nil
|
52
|
+
else
|
53
|
+
hash[link_to((humanize_proposal_state state), q: ransak_params_for_query(state_eq: state), per_page: per_page)] = nil
|
54
|
+
end
|
55
|
+
end,
|
56
|
+
t("models.proposal.fields.category", scope: "decidim.proposals") => admin_filter_categories_tree(categories.first_class),
|
57
|
+
t("proposals.filters.scope", scope: "decidim.proposals") => admin_filter_scopes_tree(current_component.organization.id)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def proposals_admin_search_hidden_params
|
62
|
+
return unless params[:q]
|
63
|
+
|
64
|
+
tags = ""
|
65
|
+
tags += hidden_field_tag "per_page", params[:per_page] if params[:per_page]
|
66
|
+
tags += hidden_field_tag "q[is_emendation_true]", params[:q][:is_emendation_true] if params[:q][:is_emendation_true]
|
67
|
+
tags += hidden_field_tag "q[state_eq]", params[:q][:state_eq] if params[:q][:state_eq]
|
68
|
+
tags += hidden_field_tag "q[category_id_eq]", params[:q][:category_id_eq] if params[:q][:category_id_eq]
|
69
|
+
tags += hidden_field_tag "q[scope_id_eq]", params[:q][:scope_id_eq] if params[:q][:scope_id_eq]
|
70
|
+
tags.html_safe
|
71
|
+
end
|
72
|
+
|
73
|
+
def proposals_admin_filter_applied_filters
|
74
|
+
html = []
|
75
|
+
if params[:q][:is_emendation_true].present?
|
76
|
+
html << content_tag(:span, class: "label secondary") do
|
77
|
+
tag = "#{t("filters.type", scope: "decidim.proposals.proposals")}: "
|
78
|
+
tag += if params[:q][:is_emendation_true].to_s == "1"
|
79
|
+
t("amendments", scope: "decidim.proposals.application_helper.filter_type_values")
|
80
|
+
else
|
81
|
+
t("proposals", scope: "decidim.proposals.application_helper.filter_type_values")
|
82
|
+
end
|
83
|
+
tag += icon_link_to("circle-x", url_for(q: ransak_params_for_query_without(:is_emendation_true), per_page: per_page), t("decidim.admin.actions.cancel"),
|
84
|
+
class: "action-icon--remove")
|
85
|
+
tag.html_safe
|
86
|
+
end
|
87
|
+
end
|
88
|
+
if params[:q][:state_null]
|
89
|
+
html << content_tag(:span, class: "label secondary") do
|
90
|
+
tag = "#{t("models.proposal.fields.state", scope: "decidim.proposals")}: "
|
91
|
+
tag += humanize_proposal_state "not_answered"
|
92
|
+
tag += icon_link_to("circle-x", url_for(q: ransak_params_for_query_without(:state_null), per_page: per_page), t("decidim.admin.actions.cancel"),
|
93
|
+
class: "action-icon--remove")
|
94
|
+
tag.html_safe
|
95
|
+
end
|
96
|
+
end
|
97
|
+
if params[:q][:state_eq]
|
98
|
+
html << content_tag(:span, class: "label secondary") do
|
99
|
+
tag = "#{t("models.proposal.fields.state", scope: "decidim.proposals")}: "
|
100
|
+
tag += humanize_proposal_state params[:q][:state_eq]
|
101
|
+
tag += icon_link_to("circle-x", url_for(q: ransak_params_for_query_without(:state_eq), per_page: per_page), t("decidim.admin.actions.cancel"),
|
102
|
+
class: "action-icon--remove")
|
103
|
+
tag.html_safe
|
104
|
+
end
|
105
|
+
end
|
106
|
+
if params[:q][:category_id_eq]
|
107
|
+
html << content_tag(:span, class: "label secondary") do
|
108
|
+
tag = "#{t("models.proposal.fields.category", scope: "decidim.proposals")}: "
|
109
|
+
tag += translated_attribute categories.find(params[:q][:category_id_eq]).name
|
110
|
+
tag += icon_link_to("circle-x", url_for(q: ransak_params_for_query_without(:category_id_eq), per_page: per_page), t("decidim.admin.actions.cancel"),
|
111
|
+
class: "action-icon--remove")
|
112
|
+
tag.html_safe
|
113
|
+
end
|
114
|
+
end
|
115
|
+
if params[:q][:scope_id_eq]
|
116
|
+
html << content_tag(:span, class: "label secondary") do
|
117
|
+
tag = "#{t("models.proposal.fields.scope", scope: "decidim.proposals")}: "
|
118
|
+
tag += translated_attribute Decidim::Scope.where(decidim_organization_id: current_component.organization.id).find(params[:q][:scope_id_eq]).name
|
119
|
+
tag += icon_link_to("circle-x", url_for(q: ransak_params_for_query_without(:scope_id_eq), per_page: per_page), t("decidim.admin.actions.cancel"),
|
120
|
+
class: "action-icon--remove")
|
121
|
+
tag.html_safe
|
122
|
+
end
|
123
|
+
end
|
124
|
+
html.join(" ").html_safe
|
125
|
+
end
|
126
|
+
|
127
|
+
def icon_with_link_to_proposal(proposal)
|
128
|
+
icon, tooltip = if allowed_to?(:create, :proposal_answer, proposal: proposal) && !proposal.emendation?
|
129
|
+
[
|
130
|
+
"comment-square",
|
131
|
+
t(:answer_proposal, scope: "decidim.proposals.actions")
|
132
|
+
]
|
133
|
+
else
|
134
|
+
[
|
135
|
+
"info",
|
136
|
+
t(:show, scope: "decidim.proposals.actions")
|
137
|
+
]
|
138
|
+
end
|
139
|
+
icon_link_to(icon, proposal_path(proposal), tooltip, class: "icon--small action-icon--show-proposal")
|
140
|
+
end
|
17
141
|
end
|
18
142
|
end
|
19
143
|
end
|