decidim-proposals 0.23.6 → 0.24.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/proposals/add_proposal.js.es6 +4 -1
  3. data/app/assets/stylesheets/decidim/proposals/_proposals.css.scss +1 -0
  4. data/app/assets/stylesheets/decidim/proposals/proposals/_preview.css.scss +3 -0
  5. data/app/cells/decidim/proposals/collaborative_draft_link_to_proposal_cell.rb +3 -3
  6. data/app/cells/decidim/proposals/collaborative_drafts/reported_content/show.erb +3 -0
  7. data/app/cells/decidim/proposals/collaborative_drafts/reported_content_cell.rb +15 -0
  8. data/app/cells/decidim/proposals/content_blocks/highlighted_proposals/elements.erb +5 -0
  9. data/app/cells/decidim/proposals/content_blocks/highlighted_proposals/heading.erb +1 -0
  10. data/app/cells/decidim/proposals/content_blocks/highlighted_proposals_cell.rb +19 -0
  11. data/app/cells/decidim/proposals/irreversible_action_modal_cell.rb +1 -1
  12. data/app/cells/decidim/proposals/proposal_activity_cell.rb +5 -13
  13. data/app/cells/decidim/proposals/proposal_m_cell.rb +23 -2
  14. data/app/cells/decidim/proposals/proposals_picker_cell.rb +1 -1
  15. data/app/cells/decidim/proposals/reported_content/show.erb +4 -0
  16. data/app/cells/decidim/proposals/reported_content_cell.rb +13 -0
  17. data/app/commands/decidim/proposals/hashtags_methods.rb +1 -1
  18. data/app/controllers/decidim/proposals/admin/proposals_controller.rb +6 -4
  19. data/app/controllers/decidim/proposals/collaborative_drafts_controller.rb +1 -30
  20. data/app/controllers/decidim/proposals/proposals_controller.rb +9 -12
  21. data/app/events/decidim/proposals/publish_proposal_event.rb +1 -1
  22. data/app/forms/decidim/proposals/access_to_collaborative_draft_form.rb +1 -3
  23. data/app/forms/decidim/proposals/admin/proposal_base_form.rb +3 -2
  24. data/app/forms/decidim/proposals/proposal_form.rb +15 -5
  25. data/app/forms/decidim/proposals/proposal_wizard_create_step_form.rb +1 -1
  26. data/app/helpers/decidim/proposals/admin/filterable_helper.rb +1 -1
  27. data/app/helpers/decidim/proposals/admin/proposal_rankings_helper.rb +1 -1
  28. data/app/helpers/decidim/proposals/admin/proposals_helper.rb +8 -8
  29. data/app/helpers/decidim/proposals/application_helper.rb +5 -2
  30. data/app/helpers/decidim/proposals/map_helper.rb +25 -8
  31. data/app/helpers/decidim/proposals/proposal_wizard_helper.rb +14 -44
  32. data/app/helpers/decidim/proposals/proposals_helper.rb +3 -6
  33. data/app/models/decidim/proposals/collaborative_draft.rb +10 -0
  34. data/app/models/decidim/proposals/proposal.rb +18 -10
  35. data/app/permissions/decidim/proposals/admin/permissions.rb +2 -2
  36. data/app/permissions/decidim/proposals/permissions.rb +3 -2
  37. data/app/presenters/decidim/proposals/proposal_presenter.rb +4 -4
  38. data/app/queries/decidim/proposals/metrics/proposal_followers_metric_measure.rb +4 -4
  39. data/app/queries/decidim/proposals/metrics/proposal_participants_metric_measure.rb +6 -6
  40. data/app/services/decidim/proposals/collaborative_draft_search.rb +1 -1
  41. data/app/services/decidim/proposals/diff_renderer.rb +7 -11
  42. data/app/services/decidim/proposals/proposal_builder.rb +2 -3
  43. data/app/views/decidim/proposals/admin/proposals/_bulk-actions.html.erb +8 -1
  44. data/app/views/decidim/proposals/admin/proposals/_proposal-tr.html.erb +5 -1
  45. data/app/views/decidim/proposals/admin/proposals_imports/new.html.erb +1 -1
  46. data/app/views/decidim/proposals/collaborative_drafts/_wizard_aside.html.erb +2 -7
  47. data/app/views/decidim/proposals/collaborative_drafts/_wizard_header.html.erb +14 -0
  48. data/app/views/decidim/proposals/collaborative_drafts/edit.html.erb +1 -3
  49. data/app/views/decidim/proposals/collaborative_drafts/new.html.erb +5 -13
  50. data/app/views/decidim/proposals/collaborative_drafts/show.html.erb +1 -7
  51. data/app/views/decidim/proposals/proposals/_dynamic_map_instructions.html.erb +3 -0
  52. data/app/views/decidim/proposals/proposals/_edit_form_fields.html.erb +2 -2
  53. data/app/views/decidim/proposals/proposals/_filters.html.erb +34 -32
  54. data/app/views/decidim/proposals/proposals/_wizard_header.html.erb +21 -11
  55. data/app/views/decidim/proposals/proposals/edit.html.erb +1 -3
  56. data/app/views/decidim/proposals/proposals/index.html.erb +1 -1
  57. data/app/views/decidim/proposals/proposals/preview.html.erb +50 -2
  58. data/app/views/decidim/proposals/proposals/show.html.erb +2 -8
  59. data/config/locales/ar.yml +2 -23
  60. data/config/locales/bg.yml +0 -4
  61. data/config/locales/ca.yml +9 -32
  62. data/config/locales/cs.yml +49 -56
  63. data/config/locales/de.yml +23 -30
  64. data/config/locales/el.yml +2 -29
  65. data/config/locales/en.yml +23 -30
  66. data/config/locales/es-MX.yml +3 -31
  67. data/config/locales/es-PY.yml +3 -31
  68. data/config/locales/es.yml +3 -31
  69. data/config/locales/eu.yml +2 -23
  70. data/config/locales/fi-plain.yml +18 -29
  71. data/config/locales/fi.yml +18 -29
  72. data/config/locales/fr-CA.yml +19 -30
  73. data/config/locales/fr.yml +19 -30
  74. data/config/locales/gl.yml +4 -97
  75. data/config/locales/hu.yml +2 -23
  76. data/config/locales/id-ID.yml +2 -23
  77. data/config/locales/is-IS.yml +0 -8
  78. data/config/locales/it.yml +4 -29
  79. data/config/locales/ja.yml +2 -29
  80. data/config/locales/lv.yml +2 -22
  81. data/config/locales/nl.yml +13 -30
  82. data/config/locales/no.yml +2 -23
  83. data/config/locales/pl.yml +13 -33
  84. data/config/locales/pt-BR.yml +2 -22
  85. data/config/locales/pt.yml +2 -29
  86. data/config/locales/ro-RO.yml +2 -84
  87. data/config/locales/ru.yml +0 -8
  88. data/config/locales/sk.yml +5 -23
  89. data/config/locales/sv.yml +7 -38
  90. data/config/locales/tr-TR.yml +17 -29
  91. data/config/locales/uk.yml +0 -8
  92. data/config/locales/zh-CN.yml +2 -29
  93. data/db/migrate/20200915151348_fix_proposals_data_to_ensure_title_and_body_are_hashes.rb +37 -0
  94. data/{app/types/decidim/proposals → lib/decidim/api}/proposal_input_filter.rb +0 -0
  95. data/{app/types/decidim/proposals → lib/decidim/api}/proposal_input_sort.rb +3 -5
  96. data/lib/decidim/api/proposal_type.rb +56 -0
  97. data/lib/decidim/api/proposals_type.rb +43 -0
  98. data/lib/decidim/content_renderers/proposal_renderer.rb +1 -1
  99. data/lib/decidim/proposals/api.rb +10 -0
  100. data/lib/decidim/proposals/component.rb +30 -19
  101. data/lib/decidim/proposals/engine.rb +6 -27
  102. data/lib/decidim/proposals/proposal_creator.rb +98 -0
  103. data/lib/decidim/proposals/test/factories.rb +22 -8
  104. data/lib/decidim/proposals/version.rb +1 -1
  105. data/lib/decidim/proposals.rb +2 -0
  106. metadata +50 -38
  107. data/app/commands/decidim/proposals/create_proposal_export.rb +0 -37
  108. data/app/helpers/decidim/proposals/proposal_endorsements_helper.rb +0 -0
  109. data/app/queries/decidim/proposals/similar_collaborative_drafts.rb +0 -52
  110. data/app/types/decidim/proposals/proposal_type.rb +0 -70
  111. data/app/types/decidim/proposals/proposals_type.rb +0 -41
  112. data/app/views/decidim/participatory_processes/participatory_process_groups/_highlighted_proposals.html.erb +0 -13
  113. data/app/views/decidim/proposals/collaborative_drafts/compare.html.erb +0 -21
  114. data/app/views/decidim/proposals/collaborative_drafts/complete.html.erb +0 -24
  115. data/app/views/decidim/proposals/proposals/_proposal_preview.html.erb +0 -1
  116. data/db/migrate/20210318082934_fix_counters_for_copied_proposals.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9bf25b623709eab1b21a1fb192f79de33e0d372384d67435e7e945d0e40fe7b0
4
- data.tar.gz: a05a461559454ad127097d7344f5fb8d50e6fc2c9537319e711bb7e09c3f6355
3
+ metadata.gz: 67cf84b4e45cd888f61855ec0cf7b6f8bdc7ac95436dbb26f210d8208d6b14ea
4
+ data.tar.gz: f6948e12bbea3e8cb7a260657ff242a19e4c79c4d1d7784531d3e2a5978b0e4f
5
5
  SHA512:
6
- metadata.gz: e5ea130360aadb726c4a03b283f542bffed6c5b55eb1451115cddd26e07ef4ac85f26ed3c2da83a07a53abf68b4dce404f144614beb6e4074f2ab0d2b8a3230b
7
- data.tar.gz: 16db0fb106633338d4253fa0c92cade541a68894c92807d89839004de283e27e41b0d2472dd1cc6e646f41c78b90acf6b06efc4126f46ac59b342561e19ccc79
6
+ metadata.gz: 3827d2e0bcf65100d5ece6725335fe3b5cea50199edb951d4fa8356ad7d326c330342af4df0260cf69bf712d8c33473d059976602268c7a57e2763e8a34da532
7
+ data.tar.gz: bc2419606befb1ca8a7cff9817b2d4b4bce0612e320e36b389c0257cb3bbca72bc3f603b52f783ea342285ec82b2fb6d97c42bafb3575e72fae4d27fcbc51a69
@@ -6,13 +6,16 @@ $(() => {
6
6
  window.DecidimProposals.bindProposalAddress = () => {
7
7
  const $checkbox = $("input:checkbox[name$='[has_address]']");
8
8
  const $addressInput = $("#address_input");
9
+ const $addressInputField = $("input", $addressInput);
9
10
 
10
11
  if ($checkbox.length > 0) {
11
12
  const toggleInput = () => {
12
13
  if ($checkbox[0].checked) {
13
14
  $addressInput.show();
15
+ $addressInputField.prop("disabled", false);
14
16
  } else {
15
17
  $addressInput.hide();
18
+ $addressInputField.prop("disabled", true);
16
19
  }
17
20
  }
18
21
  toggleInput();
@@ -20,7 +23,7 @@ $(() => {
20
23
  }
21
24
 
22
25
  if ($addressInput.length > 0) {
23
- attachGeocoding($("input", $addressInput));
26
+ attachGeocoding($addressInputField);
24
27
  }
25
28
  };
26
29
 
@@ -0,0 +1 @@
1
+ @import "proposals/*";
@@ -0,0 +1,3 @@
1
+ .preview--form__hidden{
2
+ display: none;
3
+ }
@@ -23,13 +23,13 @@ module Decidim
23
23
  end
24
24
 
25
25
  def link_header
26
- content_tag :strong, class: "text-large" do
26
+ tag.strong(class: "text-large") do
27
27
  t("final_proposal", scope: "decidim.proposals.collaborative_drafts.show")
28
28
  end
29
29
  end
30
30
 
31
31
  def link_help_text
32
- content_tag :span, class: "text-medium" do
32
+ tag.span(class: "text-medium") do
33
33
  t("final_proposal_help_text", scope: "decidim.proposals.collaborative_drafts.show")
34
34
  end
35
35
  end
@@ -39,7 +39,7 @@ module Decidim
39
39
  collaborative_draft_id: model.id
40
40
  )
41
41
  link_to @path, class: "text-medium" do
42
- content_tag :u do
42
+ tag.u do
43
43
  t("version_history", scope: "decidim.proposals.collaborative_drafts.show")
44
44
  end
45
45
  end
@@ -0,0 +1,3 @@
1
+ <blockquote>
2
+ <p><%= render_value model.body %></p>
3
+ </blockquote>
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module CollaborativeDrafts
6
+ # This cells renders a small preview of the `CollaborativeDraft` that is
7
+ # used in the moderations panel.
8
+ class ReportedContentCell < Decidim::ReportedContentCell
9
+ def show
10
+ render :show
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ <div class="row small-up-1 medium-up-2 mediumlarge-up-3 large-up-3 card-grid">
2
+ <% elements.each do |element| %>
3
+ <%= card_for element, context: { show_space: true } %>
4
+ <% end %>
5
+ </div>
@@ -0,0 +1 @@
1
+ <h2 class="section-heading"><%= t("decidim.proposals.content_blocks.highlighted_proposals.proposals") %></h2>
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ module ContentBlocks
6
+ class HighlightedProposalsCell < Decidim::ContentBlocks::HighlightedElementsCell
7
+ def base_relation
8
+ @base_relation ||= Decidim::Proposals::Proposal.published.not_hidden.except_withdrawn.where(component: published_components)
9
+ end
10
+
11
+ private
12
+
13
+ def limit
14
+ Decidim::Proposals.config.process_group_highlighted_proposals_limit
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -60,7 +60,7 @@ module Decidim
60
60
  end
61
61
 
62
62
  def button_cancel
63
- content_tag :div, class: "columns medium-6" do
63
+ tag.div(class: "columns medium-6") do
64
64
  button_tag type: "button", class: "clear button secondary expanded", "data-close": "" do
65
65
  close_label
66
66
  end
@@ -2,21 +2,13 @@
2
2
 
3
3
  module Decidim
4
4
  module Proposals
5
- # A cell to display when actions happen on a proposal.
5
+ # A cell to display when a proposal has been published.
6
6
  class ProposalActivityCell < ActivityCell
7
7
  def title
8
- case action
9
- when "update"
10
- I18n.t(
11
- "decidim.proposals.last_activity.proposal_updated_at_html",
12
- link: participatory_space_link
13
- )
14
- else
15
- I18n.t(
16
- "decidim.proposals.last_activity.new_proposal_at_html",
17
- link: participatory_space_link
18
- )
19
- end
8
+ I18n.t(
9
+ "decidim.proposals.last_activity.new_proposal_at_html",
10
+ link: participatory_space_link
11
+ )
20
12
  end
21
13
 
22
14
  def resource_link_text
@@ -8,6 +8,8 @@ module Decidim
8
8
  class ProposalMCell < Decidim::CardMCell
9
9
  include ProposalCellsHelper
10
10
 
11
+ delegate :current_locale, to: :controller
12
+
11
13
  def badge
12
14
  render if has_badge?
13
15
  end
@@ -73,7 +75,7 @@ module Decidim
73
75
  end
74
76
 
75
77
  def creation_date_status
76
- explanation = content_tag(:strong, t("activemodel.attributes.common.created_at"))
78
+ explanation = tag.strong(t("activemodel.attributes.common.created_at"))
77
79
  "#{explanation}<br>#{l(model.published_at.to_date, format: :decidim_short)}"
78
80
  end
79
81
 
@@ -87,7 +89,7 @@ module Decidim
87
89
 
88
90
  def endorsements_count
89
91
  with_tooltip t("decidim.endorsable.endorsements") do
90
- icon("bullhorn", class: "icon--small") + " " + model.endorsements_count.to_s
92
+ "#{icon("bullhorn", class: "icon--small")} #{model.endorsements_count}"
91
93
  end
92
94
  end
93
95
 
@@ -122,6 +124,25 @@ module Decidim
122
124
  def resource_image_path
123
125
  @resource_image_path ||= has_image? ? model.attachments.find_by("content_type like '%image%'").url : nil
124
126
  end
127
+
128
+ def cache_hash
129
+ hash = []
130
+ hash << "decidim/proposals/proposal_m"
131
+ hash << I18n.locale.to_s
132
+ hash << model.cache_version
133
+ hash << model.proposal_votes_count
134
+ hash << model.endorsements_count
135
+ hash << Digest::MD5.hexdigest(model.component.settings.to_json)
136
+ hash << Digest::MD5.hexdigest(resource_image_path) if resource_image_path
137
+ if current_user
138
+ hash << current_user.cache_version
139
+ hash << current_user.follows?(model) ? 1 : 0
140
+ end
141
+ hash << Digest::MD5.hexdigest(model.followers.to_json)
142
+ hash << Digest::MD5.hexdigest(model.coauthorships.map(&:cache_version).to_s)
143
+
144
+ hash.join("/")
145
+ end
125
146
  end
126
147
  end
127
148
  end
@@ -50,7 +50,7 @@ module Decidim
50
50
 
51
51
  def filtered_proposals
52
52
  @filtered_proposals ||= if filtered?
53
- proposals.where("title::text ILIKE ?", "%#{search_text}%")
53
+ proposals.where("title ILIKE ?", "%#{search_text}%")
54
54
  .or(proposals.where("reference ILIKE ?", "%#{search_text}%"))
55
55
  .or(proposals.where("id::text ILIKE ?", "%#{search_text}%"))
56
56
  else
@@ -0,0 +1,4 @@
1
+ <blockquote>
2
+ <h5><%= render_value model.title %></h5>
3
+ <p><%= render_value model.body %></p>
4
+ </blockquote>
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ # This cells renders a small preview of the `Proposal` that is
6
+ # used in the moderations panel.
7
+ class ReportedContentCell < Decidim::ReportedContentCell
8
+ def show
9
+ render :show
10
+ end
11
+ end
12
+ end
13
+ end
@@ -14,7 +14,7 @@ module Decidim
14
14
  def body_with_hashtags
15
15
  @body_with_hashtags ||= begin
16
16
  ret = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.body, current_organization: form.current_organization).rewrite.strip
17
- ret += "\n" + body_extra_hashtags.strip unless body_extra_hashtags.empty?
17
+ ret += "\n#{body_extra_hashtags.strip}" unless body_extra_hashtags.empty?
18
18
  ret
19
19
  end
20
20
  end
@@ -165,14 +165,15 @@ module Decidim
165
165
  def update_proposals_bulk_response_successful(response, subject)
166
166
  return if response[:successful].blank?
167
167
 
168
- if subject == :category
168
+ case subject
169
+ when :category
169
170
  t(
170
171
  "proposals.update_category.success",
171
172
  subject_name: response[:subject_name],
172
173
  proposals: response[:successful].to_sentence,
173
174
  scope: "decidim.proposals.admin"
174
175
  )
175
- elsif subject == :scope
176
+ when :scope
176
177
  t(
177
178
  "proposals.update_scope.success",
178
179
  subject_name: response[:subject_name],
@@ -185,14 +186,15 @@ module Decidim
185
186
  def update_proposals_bulk_response_errored(response, subject)
186
187
  return if response[:errored].blank?
187
188
 
188
- if subject == :category
189
+ case subject
190
+ when :category
189
191
  t(
190
192
  "proposals.update_category.invalid",
191
193
  subject_name: response[:subject_name],
192
194
  proposals: response[:errored].to_sentence,
193
195
  scope: "decidim.proposals.admin"
194
196
  )
195
- elsif subject == :scope
197
+ when :scope
196
198
  t(
197
199
  "proposals.update_scope.invalid",
198
200
  subject_name: response[:subject_name],
@@ -19,7 +19,7 @@ module Decidim
19
19
 
20
20
  helper_method :geocoded_collaborative_draft, :collaborative_draft
21
21
  before_action :collaborative_drafts_enabled?
22
- before_action :authenticate_user!, only: [:new, :create, :complete]
22
+ before_action :authenticate_user!, only: [:new, :create]
23
23
  before_action :retrieve_collaborative_draft, only: [:show, :edit, :update, :withdraw, :publish]
24
24
 
25
25
  def index
@@ -36,7 +36,6 @@ module Decidim
36
36
  def show
37
37
  raise ActionController::RoutingError, "Not Found" unless retrieve_collaborative_draft
38
38
 
39
- @report_form = form(Decidim::ReportForm).from_params(reason: "spam")
40
39
  @request_access_form = form(RequestAccessToCollaborativeDraftForm).from_params({})
41
40
  @accept_request_form = form(AcceptAccessToCollaborativeDraftForm).from_params({})
42
41
  @reject_request_form = form(RejectAccessToCollaborativeDraftForm).from_params({})
@@ -44,42 +43,14 @@ module Decidim
44
43
 
45
44
  def new
46
45
  enforce_permission_to :create, :collaborative_draft
47
- @step = :step_1
48
46
 
49
47
  @form = form(CollaborativeDraftForm).from_params(
50
48
  attachment: form(AttachmentForm).from_params({})
51
49
  )
52
50
  end
53
51
 
54
- def compare
55
- @step = :step_2
56
- @similar_collaborative_drafts ||= Decidim::Proposals::SimilarCollaborativeDrafts
57
- .for(current_component, params[:collaborative_draft])
58
- .all
59
- @form = form(CollaborativeDraftForm).from_params(params)
60
-
61
- if @similar_collaborative_drafts.blank?
62
- flash[:notice] = I18n.t("proposals.collaborative_drafts.compare.no_similars_found", scope: "decidim")
63
- redirect_to complete_collaborative_drafts_path(collaborative_draft: { title: @form.title, body: @form.body })
64
- end
65
- end
66
-
67
- def complete
68
- enforce_permission_to :create, :collaborative_draft
69
- @step = :step_3
70
- if params[:collaborative_draft].present?
71
- params[:collaborative_draft][:attachment] = form(AttachmentForm).from_params({})
72
- @form = form(CollaborativeDraftForm).from_params(params)
73
- else
74
- @form = form(CollaborativeDraftForm).from_params(
75
- attachment: form(AttachmentForm).from_params({})
76
- )
77
- end
78
- end
79
-
80
52
  def create
81
53
  enforce_permission_to :create, :collaborative_draft
82
- @step = :step_3
83
54
  @form = form(CollaborativeDraftForm).from_params(params)
84
55
 
85
56
  CreateCollaborativeDraft.call(@form, current_user) do
@@ -35,13 +35,11 @@ module Decidim
35
35
  .order(position: :asc)
36
36
  render "decidim/proposals/proposals/participatory_texts/participatory_text"
37
37
  else
38
- @base_query = search
39
- .results
40
- .published
41
- .not_hidden
42
-
43
- @proposals = @base_query.includes(:amendable, :category, :component, :resource_permission, :scope)
44
- @all_geocoded_proposals = @base_query.geocoded
38
+ @proposals = search
39
+ .results
40
+ .published
41
+ .not_hidden
42
+ .includes(:component, :coauthorships)
45
43
 
46
44
  @voted_proposals = if current_user
47
45
  ProposalVote.where(
@@ -58,8 +56,6 @@ module Decidim
58
56
 
59
57
  def show
60
58
  raise ActionController::RoutingError, "Not Found" if @proposal.blank? || !can_show_proposal?
61
-
62
- @report_form = form(Decidim::ReportForm).from_params(reason: "spam")
63
59
  end
64
60
 
65
61
  def new
@@ -81,7 +77,7 @@ module Decidim
81
77
  on(:ok) do |proposal|
82
78
  flash[:notice] = I18n.t("proposals.create.success", scope: "decidim")
83
79
 
84
- redirect_to Decidim::ResourceLocatorPresenter.new(proposal).path + "/compare"
80
+ redirect_to "#{Decidim::ResourceLocatorPresenter.new(proposal).path}/compare"
85
81
  end
86
82
 
87
83
  on(:invalid) do
@@ -99,7 +95,7 @@ module Decidim
99
95
 
100
96
  if @similar_proposals.blank?
101
97
  flash[:notice] = I18n.t("proposals.proposals.compare.no_similars_found", scope: "decidim")
102
- redirect_to Decidim::ResourceLocatorPresenter.new(@proposal).path + "/complete"
98
+ redirect_to "#{Decidim::ResourceLocatorPresenter.new(@proposal).path}/complete"
103
99
  end
104
100
  end
105
101
 
@@ -114,6 +110,7 @@ module Decidim
114
110
 
115
111
  def preview
116
112
  @step = :step_4
113
+ @form = form(ProposalForm).from_model(@proposal)
117
114
  end
118
115
 
119
116
  def publish
@@ -144,7 +141,7 @@ module Decidim
144
141
  UpdateProposal.call(@form, current_user, @proposal) do
145
142
  on(:ok) do |proposal|
146
143
  flash[:notice] = I18n.t("proposals.update_draft.success", scope: "decidim")
147
- redirect_to Decidim::ResourceLocatorPresenter.new(proposal).path + "/preview"
144
+ redirect_to "#{Decidim::ResourceLocatorPresenter.new(proposal).path}/preview"
148
145
  end
149
146
 
150
147
  on(:invalid) do
@@ -18,7 +18,7 @@ module Decidim
18
18
  end
19
19
 
20
20
  def participatory_space_event?
21
- extra.dig(:participatory_space)
21
+ extra[:participatory_space]
22
22
  end
23
23
  end
24
24
  end
@@ -26,9 +26,7 @@ module Decidim
26
26
  private
27
27
 
28
28
  def existence_of_requester_in_requesters
29
- if collaborative_draft
30
- errors.add(:requester_user_id, :invalid) unless collaborative_draft.requesters.exists? requester_user_id
31
- end
29
+ errors.add(:requester_user_id, :invalid) if collaborative_draft && !collaborative_draft.requesters.exists?(requester_user_id)
32
30
  end
33
31
  end
34
32
  end
@@ -6,6 +6,7 @@ module Decidim
6
6
  # A form object to be used when admin users want to create a proposal.
7
7
  class ProposalBaseForm < Decidim::Form
8
8
  include Decidim::TranslatableAttributes
9
+ include Decidim::AttachmentAttributes
9
10
  include Decidim::ApplicationHelper
10
11
 
11
12
  mimic :proposal
@@ -20,8 +21,8 @@ module Decidim
20
21
  attribute :created_in_meeting, Boolean
21
22
  attribute :meeting_id, Integer
22
23
  attribute :suggested_hashtags, Array[String]
23
- attribute :photos, Array[String]
24
- attribute :add_photos, Array
24
+
25
+ attachments_attribute :photos
25
26
 
26
27
  validates :address, geocoding: true, if: ->(form) { form.has_address? && !form.geocoded? }
27
28
  validates :category, presence: true, if: ->(form) { form.category_id.present? }
@@ -5,6 +5,7 @@ module Decidim
5
5
  # A form object to be used when public users want to create a proposal.
6
6
  class ProposalForm < Decidim::Proposals::ProposalWizardCreateStepForm
7
7
  include Decidim::TranslatableAttributes
8
+ include Decidim::AttachmentAttributes
8
9
 
9
10
  mimic :proposal
10
11
 
@@ -16,10 +17,9 @@ module Decidim
16
17
  attribute :has_address, Boolean
17
18
  attribute :attachment, AttachmentForm
18
19
  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
20
+
21
+ attachments_attribute :photos
22
+ attachments_attribute :documents
23
23
 
24
24
  validates :address, geocoding: true, if: ->(form) { form.has_address? && !form.geocoded? }
25
25
  validates :address, presence: true, if: ->(form) { form.has_address? }
@@ -39,6 +39,8 @@ module Decidim
39
39
  # The scope attribute is with different key (decidim_scope_id), so it
40
40
  # has to be manually mapped.
41
41
  self.scope_id = model.scope.id if model.scope
42
+
43
+ self.has_address = true if model.address.present?
42
44
  end
43
45
 
44
46
  # Finds the Category from the category_id.
@@ -66,8 +68,16 @@ module Decidim
66
68
  Decidim::Map.available?(:geocoding) && current_component.settings.geocoding_enabled?
67
69
  end
68
70
 
71
+ def address
72
+ return unless has_address
73
+
74
+ super
75
+ end
76
+
69
77
  def has_address?
70
- geocoding_enabled? && has_address
78
+ return unless has_address
79
+
80
+ geocoding_enabled? && address.present?
71
81
  end
72
82
 
73
83
  def geocoded?
@@ -7,7 +7,7 @@ module Decidim
7
7
  mimic :proposal
8
8
 
9
9
  attribute :title, String
10
- attribute :body, String
10
+ attribute :body, Decidim::Attributes::CleanString
11
11
  attribute :body_template, String
12
12
  attribute :user_group_id, Integer
13
13
 
@@ -7,7 +7,7 @@ module Decidim
7
7
  def extra_dropdown_submenu_options_items(filter, i18n_scope)
8
8
  options = case filter
9
9
  when :state_eq
10
- content_tag(:li, filter_link_value(:state_null, true, i18n_scope))
10
+ tag.li(filter_link_value(:state_null, true, i18n_scope))
11
11
  end
12
12
  [options].compact
13
13
  end
@@ -20,7 +20,7 @@ module Decidim
20
20
  # ranking_for(proposal, endorsements_count: :desc)
21
21
  def ranking_for(proposal, order = {})
22
22
  siblings = Decidim::Proposals::Proposal.where(component: proposal.component)
23
- ranked = siblings.order([order, id: :asc])
23
+ ranked = siblings.order([order, { id: :asc }])
24
24
  ranked_ids = ranked.pluck(:id)
25
25
 
26
26
  { ranking: ranked_ids.index(proposal.id) + 1, total: ranked_ids.count }
@@ -32,9 +32,9 @@ module Decidim
32
32
  end
33
33
 
34
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
35
+ return humanize_proposal_state(proposal.internal_state).html_safe if proposal.answered? && !proposal.published_state?
36
+
37
+ humanize_proposal_state(proposal.state).html_safe
38
38
  end
39
39
 
40
40
  def proposals_admin_filter_tree
@@ -73,7 +73,7 @@ module Decidim
73
73
  def proposals_admin_filter_applied_filters
74
74
  html = []
75
75
  if params[:q][:is_emendation_true].present?
76
- html << content_tag(:span, class: "label secondary") do
76
+ html << tag.span(class: "label secondary") do
77
77
  tag = "#{t("filters.type", scope: "decidim.proposals.proposals")}: "
78
78
  tag += if params[:q][:is_emendation_true].to_s == "1"
79
79
  t("amendments", scope: "decidim.proposals.application_helper.filter_type_values")
@@ -86,7 +86,7 @@ module Decidim
86
86
  end
87
87
  end
88
88
  if params[:q][:state_null]
89
- html << content_tag(:span, class: "label secondary") do
89
+ html << tag.span(class: "label secondary") do
90
90
  tag = "#{t("models.proposal.fields.state", scope: "decidim.proposals")}: "
91
91
  tag += humanize_proposal_state "not_answered"
92
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"),
@@ -95,7 +95,7 @@ module Decidim
95
95
  end
96
96
  end
97
97
  if params[:q][:state_eq]
98
- html << content_tag(:span, class: "label secondary") do
98
+ html << tag.span(class: "label secondary") do
99
99
  tag = "#{t("models.proposal.fields.state", scope: "decidim.proposals")}: "
100
100
  tag += humanize_proposal_state params[:q][:state_eq]
101
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"),
@@ -104,7 +104,7 @@ module Decidim
104
104
  end
105
105
  end
106
106
  if params[:q][:category_id_eq]
107
- html << content_tag(:span, class: "label secondary") do
107
+ html << tag.span(class: "label secondary") do
108
108
  tag = "#{t("models.proposal.fields.category", scope: "decidim.proposals")}: "
109
109
  tag += translated_attribute categories.find(params[:q][:category_id_eq]).name
110
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"),
@@ -113,7 +113,7 @@ module Decidim
113
113
  end
114
114
  end
115
115
  if params[:q][:scope_id_eq]
116
- html << content_tag(:span, class: "label secondary") do
116
+ html << tag.span(class: "label secondary") do
117
117
  tag = "#{t("models.proposal.fields.scope", scope: "decidim.proposals")}: "
118
118
  tag += translated_attribute Decidim::Scope.where(decidim_organization_id: current_component.organization.id).find(params[:q][:scope_id_eq]).name
119
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"),
@@ -30,10 +30,13 @@ module Decidim
30
30
 
31
31
  # Public: The css class applied based on the proposal state.
32
32
  #
33
- # state - The String state of the proposal.
33
+ # proposal - The proposal to evaluate.
34
34
  #
35
35
  # Returns a String.
36
- def proposal_state_css_class(state)
36
+ def proposal_state_css_class(proposal)
37
+ state = proposal.state
38
+ state = proposal.internal_state if proposal.answered? && !proposal.published_state?
39
+
37
40
  case state
38
41
  when "accepted"
39
42
  "text-success"
@@ -10,16 +10,33 @@ module Decidim
10
10
  # geocoded_proposals - A collection of geocoded proposals
11
11
  def proposals_data_for_map(geocoded_proposals)
12
12
  geocoded_proposals.map do |proposal|
13
- proposal
14
- .slice(:latitude, :longitude, :address)
15
- .merge(
16
- title: decidim_html_escape(present(proposal).title),
17
- body: html_truncate(decidim_sanitize(present(proposal).body), length: 100),
18
- icon: icon("proposals", width: 40, height: 70, remove_icon_class: true),
19
- link: proposal_path(proposal)
20
- )
13
+ proposal_data_for_map(proposal)
21
14
  end
22
15
  end
16
+
17
+ def proposal_data_for_map(proposal)
18
+ proposal.slice(:latitude, :longitude, :address).merge(title: proposal.title,
19
+ body: truncate(translated_attribute(proposal.body), length: 100),
20
+ icon: icon("proposals", width: 40, height: 70, remove_icon_class: true),
21
+ link: proposal_path(proposal))
22
+ end
23
+
24
+ def proposal_preview_data_for_map(proposal)
25
+ [
26
+ proposal.slice(
27
+ :latitude,
28
+ :longitude,
29
+ :address
30
+ ).merge(
31
+ icon: icon("proposals", width: 40, height: 70, remove_icon_class: true),
32
+ draggable: true
33
+ )
34
+ ]
35
+ end
36
+
37
+ def has_position?(proposal)
38
+ proposal.latitude.present? && proposal.longitude.present?
39
+ end
23
40
  end
24
41
  end
25
42
  end