decidim-proposals 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/admin/decidim_proposals_manifest.js +1 -0
  3. data/app/assets/images/decidim/gamification/badges/accepted_proposals.svg +1 -234
  4. data/app/assets/images/decidim/gamification/badges/proposal_votes.svg +1 -95
  5. data/app/assets/images/decidim/gamification/badges/proposals.svg +1 -229
  6. data/app/assets/images/decidim/proposals/icon.svg +1 -3
  7. data/app/assets/javascripts/decidim/proposals/admin/proposals_form.js.es6 +0 -5
  8. data/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 +35 -0
  9. data/app/cells/decidim/proposals/collaborative_draft_link_to_proposal_cell.rb +1 -1
  10. data/app/cells/decidim/proposals/collaborative_draft_m/footer.erb +1 -1
  11. data/app/cells/decidim/proposals/collaborative_draft_m_cell.rb +1 -1
  12. data/app/cells/decidim/proposals/highlighted_proposals_for_component/show.erb +3 -3
  13. data/app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb +1 -1
  14. data/app/cells/decidim/proposals/irreversible_action_modal/show.erb +2 -2
  15. data/app/cells/decidim/proposals/irreversible_action_modal_cell.rb +1 -1
  16. data/app/cells/decidim/proposals/participatory_text_proposal/buttons.erb +1 -1
  17. data/app/cells/decidim/proposals/participatory_text_proposal_cell.rb +1 -1
  18. data/app/cells/decidim/proposals/proposal_m/footer.erb +4 -1
  19. data/app/cells/decidim/proposals/proposal_m_cell.rb +28 -8
  20. data/app/cells/decidim/proposals/proposal_tags/show.erb +8 -2
  21. data/app/cells/decidim/proposals/proposals_picker/proposals.erb +12 -0
  22. data/app/cells/decidim/proposals/proposals_picker/show.erb +14 -0
  23. data/app/cells/decidim/proposals/proposals_picker_cell.rb +72 -0
  24. data/app/commands/decidim/proposals/admin/create_proposal.rb +1 -1
  25. data/app/commands/decidim/proposals/admin/create_proposal_note.rb +15 -0
  26. data/app/commands/decidim/proposals/admin/update_proposal.rb +1 -1
  27. data/app/commands/decidim/proposals/create_collaborative_draft.rb +1 -1
  28. data/app/commands/decidim/proposals/create_proposal.rb +1 -1
  29. data/app/commands/decidim/proposals/gallery_methods.rb +2 -51
  30. data/app/commands/decidim/proposals/update_proposal.rb +1 -1
  31. data/app/controllers/concerns/decidim/proposals/admin/picker.rb +21 -0
  32. data/app/controllers/concerns/decidim/proposals/orderable.rb +1 -1
  33. data/app/controllers/decidim/proposals/proposals_controller.rb +4 -5
  34. data/app/controllers/decidim/proposals/versions_controller.rb +8 -18
  35. data/app/events/decidim/proposals/admin/proposal_note_created_event.rb +27 -0
  36. data/app/forms/decidim/proposals/admin/participatory_text_proposal_form.rb +13 -0
  37. data/app/forms/decidim/proposals/admin/preview_participatory_text_form.rb +2 -2
  38. data/app/forms/decidim/proposals/admin/proposal_base_form.rb +129 -0
  39. data/app/forms/decidim/proposals/admin/proposal_form.rb +2 -120
  40. data/app/forms/decidim/proposals/proposal_form.rb +4 -0
  41. data/app/forms/decidim/proposals/proposal_wizard_create_step_form.rb +5 -1
  42. data/app/helpers/decidim/proposals/admin/filterable_helper.rb +2 -2
  43. data/app/helpers/decidim/proposals/admin/proposal_rankings_helper.rb +2 -2
  44. data/app/helpers/decidim/proposals/admin/proposals_picker_helper.rb +30 -0
  45. data/app/helpers/decidim/proposals/application_helper.rb +6 -6
  46. data/app/helpers/decidim/proposals/control_version_helper.rb +1 -37
  47. data/app/helpers/decidim/proposals/proposal_endorsements_helper.rb +0 -145
  48. data/app/helpers/decidim/proposals/proposal_votes_helper.rb +2 -2
  49. data/app/helpers/decidim/proposals/proposal_wizard_helper.rb +24 -7
  50. data/app/helpers/decidim/proposals/proposals_helper.rb +6 -0
  51. data/app/models/decidim/proposals/proposal.rb +4 -14
  52. data/app/permissions/decidim/proposals/permissions.rb +1 -22
  53. data/app/presenters/decidim/proposals/proposal_presenter.rb +14 -2
  54. data/app/queries/decidim/proposals/metrics/accepted_proposals_metric_manage.rb +1 -2
  55. data/app/queries/decidim/proposals/metrics/endorsements_metric_manage.rb +15 -12
  56. data/app/queries/decidim/proposals/metrics/proposal_participants_metric_measure.rb +5 -4
  57. data/app/queries/decidim/proposals/metrics/proposals_metric_manage.rb +2 -8
  58. data/app/queries/decidim/proposals/metrics/votes_metric_manage.rb +3 -9
  59. data/app/services/decidim/proposals/diff_renderer.rb +2 -0
  60. data/app/services/decidim/proposals/proposal_builder.rb +1 -1
  61. data/app/services/decidim/proposals/proposal_search.rb +2 -2
  62. data/app/types/decidim/proposals/proposal_input_sort.rb +1 -7
  63. data/app/types/decidim/proposals/proposal_type.rb +1 -11
  64. data/app/types/decidim/proposals/proposals_type.rb +10 -0
  65. data/app/validators/proposal_length_validator.rb +38 -0
  66. data/app/views/decidim/proposals/admin/participatory_texts/index.html.erb +9 -1
  67. data/app/views/decidim/proposals/admin/proposal_notes/_proposal_notes.html.erb +2 -2
  68. data/app/views/decidim/proposals/admin/proposals/_form.html.erb +3 -23
  69. data/app/views/decidim/proposals/admin/proposals/index.html.erb +1 -1
  70. data/app/views/decidim/proposals/admin/proposals/show.html.erb +1 -1
  71. data/app/views/decidim/proposals/collaborative_drafts/_edit_form_fields.html.erb +6 -4
  72. data/app/views/decidim/proposals/collaborative_drafts/_filters.html.erb +9 -7
  73. data/app/views/decidim/proposals/collaborative_drafts/_new_collaborative_draft_button.html.erb +4 -4
  74. data/app/views/decidim/proposals/collaborative_drafts/_reject_request_access_form.html.erb +1 -1
  75. data/app/views/decidim/proposals/collaborative_drafts/_wizard_aside.html.erb +4 -2
  76. data/app/views/decidim/proposals/collaborative_drafts/compare.html.erb +2 -0
  77. data/app/views/decidim/proposals/collaborative_drafts/complete.html.erb +2 -0
  78. data/app/views/decidim/proposals/collaborative_drafts/edit.html.erb +3 -1
  79. data/app/views/decidim/proposals/collaborative_drafts/index.html.erb +4 -2
  80. data/app/views/decidim/proposals/collaborative_drafts/new.html.erb +4 -0
  81. data/app/views/decidim/proposals/collaborative_drafts/show.html.erb +29 -30
  82. data/app/views/decidim/proposals/proposals/_edit_form_fields.html.erb +5 -3
  83. data/app/views/decidim/proposals/proposals/_endorsements_card_row.html.erb +0 -16
  84. data/app/views/decidim/proposals/proposals/_filters.html.erb +12 -10
  85. data/app/views/decidim/proposals/proposals/_proposal_preview.html.erb +1 -11
  86. data/app/views/decidim/proposals/proposals/_proposal_similar.html.erb +2 -2
  87. data/app/views/decidim/proposals/proposals/_proposals.html.erb +14 -0
  88. data/app/views/decidim/proposals/proposals/_vote_button.html.erb +13 -6
  89. data/app/views/decidim/proposals/proposals/_wizard_aside.html.erb +4 -2
  90. data/app/views/decidim/proposals/proposals/_wizard_header.html.erb +4 -3
  91. data/app/views/decidim/proposals/proposals/compare.html.erb +2 -0
  92. data/app/views/decidim/proposals/proposals/complete.html.erb +2 -0
  93. data/app/views/decidim/proposals/proposals/edit.html.erb +3 -1
  94. data/app/views/decidim/proposals/proposals/edit_draft.html.erb +2 -0
  95. data/app/views/decidim/proposals/proposals/index.html.erb +5 -10
  96. data/app/views/decidim/proposals/proposals/new.html.erb +5 -1
  97. data/app/views/decidim/proposals/proposals/participatory_texts/_index.html.erb +1 -1
  98. data/app/views/decidim/proposals/proposals/participatory_texts/_proposal_vote_button.html.erb +10 -3
  99. data/app/views/decidim/proposals/proposals/participatory_texts/_view_index.html.erb +1 -1
  100. data/app/views/decidim/proposals/proposals/preview.html.erb +7 -8
  101. data/app/views/decidim/proposals/proposals/show.html.erb +52 -34
  102. data/app/views/decidim/proposals/versions/index.html.erb +14 -32
  103. data/app/views/decidim/proposals/versions/show.html.erb +16 -34
  104. data/config/locales/ar.yml +8 -64
  105. data/config/locales/bg-BG.yml +237 -0
  106. data/config/locales/ca.yml +68 -61
  107. data/config/locales/cs.yml +78 -68
  108. data/config/locales/da-DK.yml +1 -0
  109. data/config/locales/de.yml +142 -58
  110. data/config/locales/el.yml +875 -0
  111. data/config/locales/en.yml +74 -67
  112. data/config/locales/es-MX.yml +68 -61
  113. data/config/locales/es-PY.yml +68 -61
  114. data/config/locales/es.yml +68 -61
  115. data/config/locales/et-EE.yml +1 -0
  116. data/config/locales/eu.yml +5 -43
  117. data/config/locales/fi-plain.yml +68 -61
  118. data/config/locales/fi.yml +109 -102
  119. data/config/locales/fr-CA.yml +876 -0
  120. data/config/locales/fr.yml +128 -60
  121. data/config/locales/ga-IE.yml +1 -0
  122. data/config/locales/gl.yml +5 -43
  123. data/config/locales/hr-HR.yml +1 -0
  124. data/config/locales/hu.yml +38 -61
  125. data/config/locales/id-ID.yml +5 -42
  126. data/config/locales/is-IS.yml +1 -27
  127. data/config/locales/it.yml +136 -76
  128. data/config/locales/ja-JP.yml +886 -0
  129. data/config/locales/lt-LT.yml +1 -0
  130. data/config/locales/lv-LV.yml +858 -0
  131. data/config/locales/mt-MT.yml +1 -0
  132. data/config/locales/nl.yml +114 -59
  133. data/config/locales/no.yml +11 -64
  134. data/config/locales/pl.yml +170 -60
  135. data/config/locales/pt-BR.yml +6 -47
  136. data/config/locales/pt.yml +419 -331
  137. data/config/locales/ro-RO.yml +840 -0
  138. data/config/locales/ru.yml +1 -40
  139. data/config/locales/sk-SK.yml +896 -0
  140. data/config/locales/sk.yml +869 -0
  141. data/config/locales/sl.yml +26 -0
  142. data/config/locales/sr-CS.yml +126 -0
  143. data/config/locales/sv.yml +228 -156
  144. data/config/locales/tr-TR.yml +5 -43
  145. data/config/locales/uk.yml +1 -40
  146. data/db/migrate/20181003074440_fix_user_groups_ids_in_proposals_endorsements.rb +4 -0
  147. data/db/migrate/20191206154128_add_endorsements_counter_cache_to_proposals.rb +7 -0
  148. data/db/migrate/20200120215928_move_proposal_endorsements_to_core_endorsements.rb +52 -0
  149. data/db/migrate/20200730131631_move_proposal_endorsed_event_notifications_to_resource_endorsed_event.rb +20 -0
  150. data/lib/decidim/proposals/component.rb +8 -4
  151. data/lib/decidim/proposals/engine.rb +1 -5
  152. data/lib/decidim/proposals/test/capybara_proposals_picker.rb +49 -0
  153. data/lib/decidim/proposals/test/factories.rb +3 -12
  154. data/lib/decidim/proposals/version.rb +1 -1
  155. metadata +55 -34
  156. data/app/assets/javascripts/decidim/proposals/identity_selector_dialog.js.es6 +0 -56
  157. data/app/cells/decidim/proposals/endorsers_list/show.erb +0 -17
  158. data/app/cells/decidim/proposals/endorsers_list_cell.rb +0 -31
  159. data/app/commands/decidim/proposals/attachment_methods.rb +0 -43
  160. data/app/commands/decidim/proposals/endorse_proposal.rb +0 -59
  161. data/app/commands/decidim/proposals/unendorse_proposal.rb +0 -40
  162. data/app/controllers/decidim/proposals/proposal_endorsements_controller.rb +0 -60
  163. data/app/models/decidim/proposals/proposal_endorsement.rb +0 -37
  164. data/app/views/decidim/proposals/proposal_endorsements/_identity.html.erb +0 -9
  165. data/app/views/decidim/proposals/proposal_endorsements/identities.html.erb +0 -12
  166. data/app/views/decidim/proposals/proposal_endorsements/update_buttons_and_counters.js.erb +0 -20
  167. data/app/views/decidim/proposals/proposals/_endorsement_button.html.erb +0 -11
  168. data/app/views/decidim/proposals/proposals/_endorsement_identities_cabin.html.erb +0 -13
  169. data/app/views/decidim/proposals/versions/_version.html.erb +0 -20
@@ -1,3 +1 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35 35">
2
- <path d="M17.5 35A17.5 17.5 0 1 1 35 17.5 17.52 17.52 0 0 1 17.5 35zm0-33.06A15.56 15.56 0 1 0 33.06 17.5 15.57 15.57 0 0 0 17.5 1.94zm9.5 13.7H8a1 1 0 0 1 0-1.94h19a1 1 0 0 1 0 1.94zm0 3.68H8a1 1 0 0 1 0-1.94h19a1 1 0 0 1 0 1.94zM22.26 23H8a1 1 0 0 1 0-1.94h14.26a1 1 0 0 1 0 1.94z"/>
3
- </svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35 35"><path d="M17.5 35A17.5 17.5 0 1 1 35 17.5 17.52 17.52 0 0 1 17.5 35zm0-33.06A15.56 15.56 0 1 0 33.06 17.5 15.57 15.57 0 0 0 17.5 1.94zm9.5 13.7H8a1 1 0 0 1 0-1.94h19a1 1 0 0 1 0 1.94zm0 3.68H8a1 1 0 0 1 0-1.94h19a1 1 0 0 1 0 1.94zM22.26 23H8a1 1 0 0 1 0-1.94h14.26a1 1 0 0 1 0 1.94z"/></svg>
@@ -20,9 +20,4 @@ $(() => {
20
20
  toggleDisabledHiddenFields();
21
21
 
22
22
  }
23
-
24
- $(document).on("closed.zf.callout", (event) => {
25
- $(event.target).remove();
26
- });
27
-
28
23
  });
@@ -0,0 +1,35 @@
1
+ $(() => {
2
+ const $content = $(".picker-content"),
3
+ pickerMore = $content.data("picker-more"),
4
+ pickerPath = $content.data("picker-path"),
5
+ toggleNoProposals = () => {
6
+ const showNoProposals = $("#proposals_list li:visible").length === 0
7
+ $("#no_proposals").toggle(showNoProposals)
8
+ }
9
+
10
+ let jqxhr = null
11
+
12
+ toggleNoProposals()
13
+
14
+ $(".data_picker-modal-content").on("change keyup", "#proposals_filter", (event) => {
15
+ const filter = event.target.value.toLowerCase()
16
+
17
+ if (pickerMore) {
18
+ if (jqxhr !== null) {
19
+ jqxhr.abort()
20
+ }
21
+
22
+ $content.html("<div class='loading-spinner'></div>")
23
+ jqxhr = $.get(`${pickerPath}?q=${filter}`, (data) => {
24
+ $content.html(data)
25
+ jqxhr = null
26
+ toggleNoProposals()
27
+ })
28
+ } else {
29
+ $("#proposals_list li").each((index, li) => {
30
+ $(li).toggle(li.textContent.toLowerCase().indexOf(filter) > -1)
31
+ })
32
+ toggleNoProposals()
33
+ }
34
+ })
35
+ })
@@ -23,7 +23,7 @@ module Decidim
23
23
  end
24
24
 
25
25
  def link_header
26
- content_tag :strong, class: "text-large text-uppercase" do
26
+ content_tag :strong, class: "text-large" do
27
27
  t("final_proposal", scope: "decidim.proposals.collaborative_drafts.show")
28
28
  end
29
29
  end
@@ -1,6 +1,6 @@
1
1
  <div class="card__footer">
2
2
  <div class="card__support">
3
3
  <div class="card__support__data"></div>
4
- <%= link_to t("decidim.proposals.collaborative_drafts.collaborative_draft.view_collaborative_draft"), resource_path, class: "card__button button small secondary" %>
4
+ <%= link_to t("decidim.proposals.collaborative_drafts.collaborative_draft.view_collaborative_draft"), resource_path, class: "card__button button--sc light button small" %>
5
5
  </div>
6
6
  </div>
@@ -23,7 +23,7 @@ module Decidim
23
23
  end
24
24
 
25
25
  def description
26
- strip_tags(present(model).body).truncate(100, separator: /\s/)
26
+ decidim_sanitize(present(model).body.truncate(100, separator: /\s/))
27
27
  end
28
28
 
29
29
  def has_badge?
@@ -1,7 +1,7 @@
1
1
  <section class="section row collapse highlighted_proposals">
2
- <h4 class="section-heading">
2
+ <h3 class="section-heading">
3
3
  <%= translated_attribute(model.name) %> <a href="<%= main_component_path(model) %>" class="text-small"><%= t("decidim.participatory_spaces.highlighted_proposals.see_all", count: proposals_count) %></a>
4
- </h4>
4
+ </h3>
5
5
 
6
6
  <%= cell(
7
7
  "decidim/collapsible_list",
@@ -14,6 +14,6 @@
14
14
  <%= link_to(
15
15
  t("decidim.participatory_spaces.highlighted_proposals.see_all", count: proposals_count),
16
16
  main_component_path(model),
17
- class: "button button--sc light secondary button--right"
17
+ class: "button button--sc hollow button--right"
18
18
  ) %>
19
19
  </section>
@@ -23,7 +23,7 @@ module Decidim
23
23
  end
24
24
 
25
25
  def proposals_to_render
26
- @proposals_to_render ||= proposals.limit(Decidim::Proposals.config.participatory_space_highlighted_proposals_limit)
26
+ @proposals_to_render ||= proposals.includes([:amendable, :category, :component, :scope]).limit(Decidim::Proposals.config.participatory_space_highlighted_proposals_limit)
27
27
  end
28
28
 
29
29
  def proposals_count
@@ -1,8 +1,8 @@
1
1
  <%= button_reveal_modal %>
2
2
 
3
- <div id="<%= modal_id %>" class="reveal" data-reveal aria-labelledby="<%= modal_title %>" aria-hidden="true" role="dialog">
3
+ <div id="<%= modal_id %>" class="reveal" data-reveal aria-labelledby="<%= modal_id %>-title" aria-hidden="true" role="dialog">
4
4
  <div class="reveal__header">
5
- <h3 class="reveal__title">
5
+ <h3 id="<%= modal_id %>-title" class="reveal__title">
6
6
  <%= modal_title %>
7
7
  </h3>
8
8
 
@@ -29,7 +29,7 @@ module Decidim
29
29
  end
30
30
 
31
31
  def modal_id
32
- "#{action}-irreversible-action-modal"
32
+ @modal_id ||= "#{SecureRandom.uuid}-#{action}-irreversible-action-modal"
33
33
  end
34
34
 
35
35
  def button_reveal_modal
@@ -14,7 +14,7 @@
14
14
  <% if component_settings.comments_enabled? %>
15
15
  <div class="button-group button-group--collapse row collapse comment-buttons">
16
16
  <% if current_settings.comments_blocked? %>
17
- <%= content_tag :button, class: "column medium-4 button light secondary", title: t("endorse", scope: "decidim.proposals.participatory_text_proposal.buttons") do %>
17
+ <%= content_tag :button, class: "column medium-4 button light secondary" do %>
18
18
  <%= icon "comment-square", class: "icon--small", aria_label: t("comments", scope: "decidim.proposals.participatory_text_proposal.buttons"), role: "img" %>
19
19
  <%= model.comments.count %>
20
20
  <% end %>
@@ -21,7 +21,7 @@ module Decidim
21
21
  def title
22
22
  case model.participatory_text_level
23
23
  when "section"
24
- "<h5><strong class='text-uppercase'>#{section_title}</strong></h5>"
24
+ "<h5><strong>#{section_title}</strong></h5>"
25
25
  else
26
26
  "<h6><strong>#{section_title}</strong></h6>"
27
27
  end
@@ -16,7 +16,10 @@
16
16
  <%= render partial: "decidim/proposals/proposals/vote_button.html", locals: { proposal: model, from_proposals_list: true } %>
17
17
  <% elsif has_footer? %>
18
18
  <div class="card__support__data"></div>
19
- <%= link_to t("decidim.proposals.proposals.proposal.view_proposal"), resource_path, class: "card__button button--sc light button small secondary" %>
19
+ <%= link_to resource_path, class: "card__button button--sc light button small" do %>
20
+ <%= t("decidim.proposals.proposals.proposal.view_proposal") %>
21
+ <span class="show-for-sr"><%= title %></span>
22
+ <% end %>
20
23
  <% end %>
21
24
  </div>
22
25
  </div>
@@ -14,12 +14,16 @@ module Decidim
14
14
 
15
15
  private
16
16
 
17
+ def preview?
18
+ options[:preview]
19
+ end
20
+
17
21
  def title
18
22
  decidim_html_escape(present(model).title)
19
23
  end
20
24
 
21
25
  def body
22
- present(model).body
26
+ decidim_sanitize(present(model).body)
23
27
  end
24
28
 
25
29
  def has_state?
@@ -50,28 +54,40 @@ module Decidim
50
54
  state_classes.concat(["label", "proposal-status"]).join(" ")
51
55
  end
52
56
 
57
+ def base_statuses
58
+ @base_statuses ||= begin
59
+ if endorsements_visible?
60
+ [:endorsements_count, :comments_count]
61
+ else
62
+ [:comments_count]
63
+ end
64
+ end
65
+ end
66
+
53
67
  def statuses
54
- return [:endorsements_count, :comments_count] if model.draft?
55
- return [:creation_date, :endorsements_count, :comments_count] if !has_link_to_resource? || !can_be_followed?
68
+ return [] if preview?
69
+ return base_statuses if model.draft?
70
+ return [:creation_date] + base_statuses if !has_link_to_resource? || !can_be_followed?
56
71
 
57
- [:creation_date, :follow, :endorsements_count, :comments_count]
72
+ [:creation_date, :follow] + base_statuses
58
73
  end
59
74
 
60
75
  def creation_date_status
61
- l(model.published_at.to_date, format: :decidim_short)
76
+ explanation = content_tag(:strong, t("activemodel.attributes.common.created_at"))
77
+ "#{explanation}<br>#{l(model.published_at.to_date, format: :decidim_short)}"
62
78
  end
63
79
 
64
80
  def endorsements_count_status
65
81
  return endorsements_count unless has_link_to_resource?
66
82
 
67
- link_to resource_path do
83
+ link_to resource_path, "aria-label" => "#{t("decidim.endorsable.endorsements_count")}: #{model.endorsements_count}", title: t("decidim.endorsable.endorsements_count") do
68
84
  endorsements_count
69
85
  end
70
86
  end
71
87
 
72
88
  def endorsements_count
73
- with_tooltip t("decidim.proposals.models.proposal.fields.endorsements") do
74
- icon("bullhorn", class: "icon--small") + " " + model.proposal_endorsements_count.to_s
89
+ with_tooltip t("decidim.endorsable.endorsements") do
90
+ icon("bullhorn", class: "icon--small") + " " + model.endorsements_count.to_s
75
91
  end
76
92
  end
77
93
 
@@ -95,6 +111,10 @@ module Decidim
95
111
  !model.withdrawn?
96
112
  end
97
113
 
114
+ def endorsements_visible?
115
+ model.component.current_settings.endorsements_enabled?
116
+ end
117
+
98
118
  def has_image?
99
119
  model.attachments.first.present? && model.attachments.first.file.content_type.start_with?("image") && model.component.settings.allow_card_image
100
120
  end
@@ -2,7 +2,10 @@
2
2
  <ul class="tags tags--proposal tags--list">
3
3
  <% if category.present? %>
4
4
  <li>
5
- <%= link_to translated_attribute(category.name), resource_locator(model).index(filter: { category_id: [category.id.to_s] }) %>
5
+ <%= link_to resource_locator(model).index(filter: { category_id: [category.id.to_s] }), title: t("decidim.tags.filter_results_for_category", resource: translated_attribute(category.name)) do %>
6
+ <span class="show-for-sr"><%= t "decidim.tags.filter_results_for_category", resource: translated_attribute(category.name) %></span>
7
+ <span aria-hidden="true"><%= translated_attribute(category.name) %></span>
8
+ <% end %>
6
9
  <% if previous_category.present? && show_previous_category? %>
7
10
  &nbsp;
8
11
  <small class="text-small">
@@ -14,7 +17,10 @@
14
17
 
15
18
  <% if has_visible_scopes?(model) %>
16
19
  <li>
17
- <%= link_to translated_attribute(scope.name), resource_locator(model).index(filter: { scope_id: [scope.id] }) %>
20
+ <%= link_to resource_locator(model).index(filter: { scope_id: [scope.id] }), title: t("decidim.tags.filter_results_for_scope", resource: translated_attribute(scope.name)) do %>
21
+ <span class="show-for-sr"><%= t "decidim.tags.filter_results_for_scope", resource: translated_attribute(scope.name) %></span>
22
+ <span aria-hidden="true"><%= translated_attribute(scope.name) %></span>
23
+ <% end %>
18
24
  <% if previous_scope.present? && show_previous_scope? %>
19
25
  &nbsp;
20
26
  <small class="text-small">
@@ -0,0 +1,12 @@
1
+ <ul id="proposals_list">
2
+ <% decorated_proposals do |proposal| %>
3
+ <li>
4
+ <label><input type="checkbox" data-picker-text="<%= proposal.id_and_title(html_escape: true) %>" data-picker-url="<%= picker_path %>" value="<%= proposal.id %>" data-picker-choose> <%= proposal.id_and_title(html_escape: true) %> (<%= proposal.reference %>)</label>
5
+ </li>
6
+ <% end %>
7
+ <% if more_proposals? %>
8
+ <li><div class="callout warning"><%= t("proposals_picker.more_proposals", scope: "decidim.proposals", number: more_proposals_count) %></div>
9
+ </li>
10
+ <% end %>
11
+ </ul>
12
+ <div id="no_proposals" class="callout warning"><%= t("proposals_picker.no_proposals", scope: "decidim.proposals") %></div>
@@ -0,0 +1,14 @@
1
+ <div class="picker-header">
2
+ <h1><%= t("proposals_picker.choose_proposals", scope: "decidim.proposals") %></h1>
3
+ <input type="text" name="proposals-filter" id="proposals_filter" placeholder="<%= t("decidim.admin.filters.search_placeholder.id_string_or_title_cont", collection: proposals_collection_name) %>">
4
+ </div>
5
+ <div class="picker-content picker-list" data-picker-path="<%= picker_path %>" data-picker-more="<%= more_proposals? %>">
6
+ <%= render :proposals %>
7
+ </div>
8
+ <div class="picker-footer">
9
+ <div class="buttons button--double">
10
+ <a class="button" data-close=""><%= t("proposals_picker.close", scope: "decidim.proposals") %></a>
11
+ </div>
12
+ </div>
13
+
14
+ <%= javascript_include_tag "decidim/proposals/admin/proposals_picker" %>
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cell/partial"
4
+
5
+ module Decidim
6
+ module Proposals
7
+ # This cell renders a proposals picker.
8
+ class ProposalsPickerCell < Decidim::ViewModel
9
+ MAX_PROPOSALS = 1000
10
+
11
+ def show
12
+ if filtered?
13
+ render :proposals
14
+ else
15
+ render
16
+ end
17
+ end
18
+
19
+ alias component model
20
+
21
+ def filtered?
22
+ !search_text.nil?
23
+ end
24
+
25
+ def picker_path
26
+ request.path
27
+ end
28
+
29
+ def search_text
30
+ params[:q]
31
+ end
32
+
33
+ def more_proposals?
34
+ @more_proposals ||= more_proposals_count.positive?
35
+ end
36
+
37
+ def more_proposals_count
38
+ @more_proposals_count ||= proposals_count - MAX_PROPOSALS
39
+ end
40
+
41
+ def proposals_count
42
+ @proposals_count ||= filtered_proposals.count
43
+ end
44
+
45
+ def decorated_proposals
46
+ filtered_proposals.limit(MAX_PROPOSALS).each do |proposal|
47
+ yield Decidim::Proposals::ProposalPresenter.new(proposal)
48
+ end
49
+ end
50
+
51
+ def filtered_proposals
52
+ @filtered_proposals ||= if filtered?
53
+ proposals.where("title ILIKE ?", "%#{search_text}%")
54
+ .or(proposals.where("reference ILIKE ?", "%#{search_text}%"))
55
+ .or(proposals.where("id::text ILIKE ?", "%#{search_text}%"))
56
+ else
57
+ proposals
58
+ end
59
+ end
60
+
61
+ def proposals
62
+ @proposals ||= Decidim.find_resource_manifest(:proposals).try(:resource_scope, component)
63
+ &.published
64
+ &.order(id: :asc)
65
+ end
66
+
67
+ def proposals_collection_name
68
+ Decidim::Proposals::Proposal.model_name.human(count: 2)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -5,7 +5,7 @@ module Decidim
5
5
  module Admin
6
6
  # A command with all the business logic when a user creates a new proposal.
7
7
  class CreateProposal < Rectify::Command
8
- include AttachmentMethods
8
+ include ::Decidim::AttachmentMethods
9
9
  include GalleryMethods
10
10
  include HashtagsMethods
11
11
 
@@ -24,6 +24,7 @@ module Decidim
24
24
  return broadcast(:invalid) if form.invalid?
25
25
 
26
26
  create_proposal_note
27
+ notify_admins_and_valuators
27
28
 
28
29
  broadcast(:ok, proposal_note)
29
30
  end
@@ -46,6 +47,20 @@ module Decidim
46
47
  }
47
48
  )
48
49
  end
50
+
51
+ def notify_admins_and_valuators
52
+ affected_users = Decidim::User.org_admins_except_me(form.current_user).all
53
+ affected_users += Decidim::Proposals::ValuationAssignment.includes(valuator_role: :user).where.not(id: form.current_user.id).where(proposal: proposal).map(&:valuator)
54
+
55
+ data = {
56
+ event: "decidim.events.proposals.admin.proposal_note_created",
57
+ event_class: Decidim::Proposals::Admin::ProposalNoteCreatedEvent,
58
+ resource: proposal,
59
+ affected_users: affected_users
60
+ }
61
+
62
+ Decidim::EventsManager.publish(data)
63
+ end
49
64
  end
50
65
  end
51
66
  end
@@ -5,7 +5,7 @@ module Decidim
5
5
  module Admin
6
6
  # A command with all the business logic when a user updates a proposal.
7
7
  class UpdateProposal < Rectify::Command
8
- include AttachmentMethods
8
+ include ::Decidim::AttachmentMethods
9
9
  include GalleryMethods
10
10
  include HashtagsMethods
11
11
 
@@ -4,7 +4,7 @@ module Decidim
4
4
  module Proposals
5
5
  # A command with all the business logic when a user creates a new collaborative draft.
6
6
  class CreateCollaborativeDraft < Rectify::Command
7
- include AttachmentMethods
7
+ include ::Decidim::AttachmentMethods
8
8
  include HashtagsMethods
9
9
 
10
10
  # Public: Initializes the command.
@@ -4,7 +4,7 @@ module Decidim
4
4
  module Proposals
5
5
  # A command with all the business logic when a user creates a new proposal.
6
6
  class CreateProposal < Rectify::Command
7
- include AttachmentMethods
7
+ include ::Decidim::AttachmentMethods
8
8
  include HashtagsMethods
9
9
 
10
10
  # Public: Initializes the command.
@@ -6,62 +6,13 @@ module Decidim
6
6
  # and collaborative draft commands.
7
7
  # Allows to create several image attachments at once
8
8
  module GalleryMethods
9
- private
10
-
11
- def build_gallery
12
- @gallery = []
13
- @form.add_photos.each do |photo|
14
- next unless image? photo
15
-
16
- @gallery << Attachment.new(
17
- title: photo.original_filename,
18
- file: photo,
19
- attached_to: @attached_to
20
- )
21
- end
22
- end
9
+ include ::Decidim::GalleryMethods
23
10
 
24
- def image?(image)
25
- return unless image.respond_to? :content_type
26
-
27
- image.content_type.start_with? "image"
28
- end
29
-
30
- def gallery_invalid?
31
- gallery.each do |photo|
32
- if photo.invalid? && photo.errors.has_key?(:file)
33
- @form.errors.add(:add_photos, photo.errors[:file])
34
- return true
35
- end
36
- end
37
- false
38
- end
39
-
40
- def create_gallery
41
- @gallery.map! do |photo|
42
- photo.attached_to = @attached_to
43
- photo.save!
44
- @form.photos << photo.id.to_s
45
- end
46
- end
47
-
48
- def photo_cleanup!
49
- @attached_to.photos.each do |photo|
50
- photo.destroy! if @form.photos.exclude? photo.id.to_s
51
- end
52
- # manually reset cached photos
53
- @attached_to.reload
54
- @attached_to.instance_variable_set(:@photos, nil)
55
- end
11
+ private
56
12
 
57
- # maybe a custom settings options would be nice
58
13
  def gallery_allowed?
59
14
  @form.current_component.settings.attachments_allowed?
60
15
  end
61
-
62
- def process_gallery?
63
- gallery_allowed? && @form.add_photos.any?
64
- end
65
16
  end
66
17
  end
67
18
  end