decidim-debates 0.22.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/debates/debate_activity_cell.rb +4 -0
  3. data/app/cells/decidim/debates/debate_m/data.erb +10 -8
  4. data/app/cells/decidim/debates/debate_m/footer.erb +5 -0
  5. data/app/cells/decidim/debates/debate_m_cell.rb +24 -2
  6. data/app/commands/decidim/debates/admin/close_debate.rb +54 -0
  7. data/app/commands/decidim/debates/admin/create_debate.rb +4 -2
  8. data/app/commands/decidim/debates/admin/update_debate.rb +5 -2
  9. data/app/commands/decidim/debates/close_debate.rb +58 -0
  10. data/app/commands/decidim/debates/create_debate.rb +17 -12
  11. data/app/commands/decidim/debates/update_debate.rb +56 -0
  12. data/app/controllers/decidim/debates/admin/debate_closes_controller.rb +43 -0
  13. data/app/controllers/decidim/debates/admin/debates_controller.rb +4 -2
  14. data/app/controllers/decidim/debates/debates_controller.rb +70 -9
  15. data/app/controllers/decidim/debates/orderable.rb +41 -0
  16. data/app/controllers/decidim/debates/versions_controller.rb +16 -0
  17. data/app/controllers/decidim/debates/widgets_controller.rb +19 -0
  18. data/app/events/decidim/debates/close_debate_event.rb +15 -0
  19. data/app/forms/decidim/debates/admin/close_debate_form.rb +34 -0
  20. data/app/forms/decidim/debates/admin/debate_form.rb +5 -1
  21. data/app/forms/decidim/debates/close_debate_form.rb +39 -0
  22. data/app/forms/decidim/debates/debate_form.rb +27 -1
  23. data/app/helpers/decidim/debates/admin/application_helper.rb +13 -0
  24. data/app/helpers/decidim/debates/application_helper.rb +37 -1
  25. data/app/models/decidim/debates/debate.rb +60 -8
  26. data/app/permissions/decidim/debates/admin/permissions.rb +3 -1
  27. data/app/permissions/decidim/debates/permissions.rb +28 -0
  28. data/app/presenters/decidim/debates/admin_log/debate_presenter.rb +6 -2
  29. data/app/presenters/decidim/debates/admin_log/value_types/debate_title_description_presenter.rb +20 -0
  30. data/app/presenters/decidim/debates/debate_presenter.rb +62 -7
  31. data/app/presenters/decidim/debates/log/resource_presenter.rb +18 -0
  32. data/app/presenters/decidim/debates/official_author_presenter.rb +1 -29
  33. data/app/services/decidim/debates/debate_search.rb +13 -23
  34. data/app/services/decidim/debates/diff_renderer.rb +27 -0
  35. data/app/views/decidim/debates/admin/debate_closes/edit.html.erb +17 -0
  36. data/app/views/decidim/debates/admin/debates/_form.html.erb +4 -4
  37. data/app/views/decidim/debates/admin/debates/index.html.erb +7 -1
  38. data/app/views/decidim/debates/debates/_close_debate_modal.html.erb +13 -0
  39. data/app/views/decidim/debates/debates/_debates.html.erb +7 -0
  40. data/app/views/decidim/debates/debates/_filters.html.erb +15 -13
  41. data/app/views/decidim/debates/debates/_form.html.erb +19 -0
  42. data/app/views/decidim/debates/debates/edit.html.erb +22 -0
  43. data/app/views/decidim/debates/debates/new.html.erb +1 -22
  44. data/app/views/decidim/debates/debates/show.html.erb +81 -11
  45. data/app/views/decidim/debates/versions/index.html.erb +8 -0
  46. data/app/views/decidim/debates/versions/show.html.erb +10 -0
  47. data/config/locales/am-ET.yml +1 -0
  48. data/config/locales/ar.yml +2 -1
  49. data/config/locales/bg.yml +15 -0
  50. data/config/locales/ca.yml +70 -1
  51. data/config/locales/cs.yml +70 -1
  52. data/config/locales/da.yml +1 -0
  53. data/config/locales/de.yml +48 -1
  54. data/config/locales/el.yml +2 -1
  55. data/config/locales/en.yml +70 -1
  56. data/config/locales/eo.yml +1 -0
  57. data/config/locales/es-MX.yml +70 -1
  58. data/config/locales/es-PY.yml +70 -1
  59. data/config/locales/es.yml +70 -1
  60. data/config/locales/et.yml +1 -0
  61. data/config/locales/eu.yml +2 -1
  62. data/config/locales/fi-plain.yml +70 -1
  63. data/config/locales/fi.yml +70 -1
  64. data/config/locales/fr-CA.yml +70 -1
  65. data/config/locales/fr.yml +70 -1
  66. data/config/locales/gl.yml +2 -1
  67. data/config/locales/hr.yml +1 -0
  68. data/config/locales/hu.yml +24 -1
  69. data/config/locales/id-ID.yml +2 -1
  70. data/config/locales/is-IS.yml +2 -1
  71. data/config/locales/is.yml +102 -0
  72. data/config/locales/it.yml +33 -1
  73. data/config/locales/ja-JP.yml +63 -20
  74. data/config/locales/ja.yml +221 -0
  75. data/config/locales/ko-KR.yml +1 -0
  76. data/config/locales/ko.yml +1 -0
  77. data/config/locales/lt.yml +1 -0
  78. data/config/locales/{lv-LV.yml → lv.yml} +0 -0
  79. data/config/locales/mt.yml +1 -0
  80. data/config/locales/nl.yml +46 -1
  81. data/config/locales/no.yml +42 -1
  82. data/config/locales/om-ET.yml +1 -0
  83. data/config/locales/pl.yml +58 -6
  84. data/config/locales/pt-BR.yml +2 -1
  85. data/config/locales/pt.yml +18 -1
  86. data/config/locales/ro-RO.yml +18 -1
  87. data/config/locales/ru.yml +2 -1
  88. data/config/locales/sk.yml +2 -1
  89. data/config/locales/sl.yml +13 -1
  90. data/config/locales/so-SO.yml +1 -0
  91. data/config/locales/sv.yml +51 -1
  92. data/config/locales/ti-ER.yml +1 -0
  93. data/config/locales/tr-TR.yml +2 -1
  94. data/config/locales/uk.yml +2 -1
  95. data/config/locales/vi-VN.yml +1 -0
  96. data/config/locales/vi.yml +1 -0
  97. data/config/locales/zh-CN.yml +218 -0
  98. data/config/locales/zh-TW.yml +1 -0
  99. data/db/migrate/20200703134657_close_debates.rb +9 -0
  100. data/db/migrate/20200708072042_fix_debates_i18n_fields.rb +48 -0
  101. data/db/migrate/20200716143929_add_endorsable_to_debates.rb +8 -0
  102. data/db/migrate/20200827154116_add_commentable_counter_cache_to_debates.rb +14 -0
  103. data/db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb +23 -0
  104. data/lib/decidim/debates/admin_engine.rb +3 -1
  105. data/lib/decidim/debates/component.rb +44 -1
  106. data/lib/decidim/debates/engine.rb +7 -1
  107. data/lib/decidim/debates/test/factories.rb +62 -6
  108. data/lib/decidim/debates/version.rb +1 -1
  109. metadata +57 -13
@@ -15,14 +15,18 @@ module Decidim
15
15
  class DebatePresenter < Decidim::Log::BasePresenter
16
16
  private
17
17
 
18
+ def resource_presenter
19
+ @resource_presenter ||= Decidim::Debates::Log::ResourcePresenter.new(action_log.resource, h, action_log.extra["resource"])
20
+ end
21
+
18
22
  def diff_fields_mapping
19
23
  {
20
- description: :i18n,
24
+ description: "Decidim::Debates::AdminLog::ValueTypes::DebateTitleDescriptionPresenter",
21
25
  end_date: :date,
22
26
  information_updates: :i18n,
23
27
  instructions: :i18n,
24
28
  start_date: :date,
25
- title: :i18n
29
+ title: "Decidim::Debates::AdminLog::ValueTypes::DebateTitleDescriptionPresenter"
26
30
  }
27
31
  end
28
32
 
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Debates
5
+ module AdminLog
6
+ module ValueTypes
7
+ # This class presents the given value as a Decidim::Debates::DebateTitleBody. Check
8
+ # the `DefaultPresenter` for more info on how value presenters work.
9
+ class DebateTitleDescriptionPresenter < Decidim::Log::ValueTypes::DefaultPresenter
10
+ def present
11
+ return unless value
12
+
13
+ renderer = Decidim::ContentRenderers::HashtagRenderer.new(h.translated_attribute(value))
14
+ renderer.render(links: false).html_safe
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -6,8 +6,11 @@ module Decidim
6
6
  # Decorator for debates
7
7
  #
8
8
  class DebatePresenter < SimpleDelegator
9
+ include Decidim::TranslationsHelper
10
+ include Decidim::ResourceHelper
9
11
  include Decidim::SanitizeHelper
10
12
  include Decidim::TranslatableAttributes
13
+ include ActionView::Helpers::DateHelper
11
14
 
12
15
  def debate
13
16
  __getobj__
@@ -23,15 +26,67 @@ module Decidim
23
26
  end
24
27
  end
25
28
 
26
- def title
27
- content = translated_attribute(debate.title)
28
- decidim_html_escape(content)
29
+ def title(links: false, all_locales: false)
30
+ return unless debate
31
+
32
+ handle_locales(debate.title, all_locales) do |content|
33
+ renderer = Decidim::ContentRenderers::HashtagRenderer.new(decidim_html_escape(content))
34
+ renderer.render(links: links).html_safe
35
+ end
36
+ end
37
+
38
+ def description(strip_tags: false, links: false, all_locales: false)
39
+ return unless debate
40
+
41
+ handle_locales(debate.description, all_locales) do |content|
42
+ content = strip_tags(content) if strip_tags
43
+ renderer = Decidim::ContentRenderers::HashtagRenderer.new(content)
44
+ content = renderer.render(links: links).html_safe
45
+ content = Decidim::ContentRenderers::LinkRenderer.new(content).render if links
46
+ content
47
+ end
48
+ end
49
+
50
+ def handle_locales(content, all_locales, &block)
51
+ if all_locales
52
+ content.each_with_object({}) do |(key, value), parsed_content|
53
+ parsed_content[key] = if key == "machine_translations"
54
+ handle_locales(value, all_locales, &block)
55
+ else
56
+ block.call(value)
57
+ end
58
+ end
59
+ else
60
+ yield(translated_attribute(content))
61
+ end
62
+ end
63
+
64
+ def last_comment_at
65
+ return unless debate.last_comment_at
66
+
67
+ time_ago_in_words(debate.last_comment_at)
68
+ end
69
+
70
+ def last_comment_by
71
+ debate.last_comment_by&.presenter
72
+ end
73
+
74
+ def participants_count
75
+ comments_authors.count do |author|
76
+ author.is_a?(Decidim::User)
77
+ end
78
+ end
79
+
80
+ def groups_count
81
+ comments_authors.count do |author|
82
+ author.is_a?(Decidim::UserGroup)
83
+ end
29
84
  end
30
85
 
31
- def description(strip_tags: false)
32
- content = translated_attribute(debate.description)
33
- content = strip_tags(content) if strip_tags
34
- content
86
+ private
87
+
88
+ def comments_authors
89
+ @comments_authors ||= debate.comments.includes(:author, :user_group).map(&:normalized_author).uniq
35
90
  end
36
91
  end
37
92
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Debates
5
+ module Log
6
+ class ResourcePresenter < Decidim::Log::ResourcePresenter
7
+ private
8
+
9
+ # Private: Presents resource name.
10
+ #
11
+ # Returns an HTML-safe String.
12
+ def present_resource_name
13
+ Decidim::Debates::DebatePresenter.new(resource).title
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,38 +5,10 @@ module Decidim
5
5
  #
6
6
  # A dummy presenter to abstract out the author of an official debate.
7
7
  #
8
- class OfficialAuthorPresenter
8
+ class OfficialAuthorPresenter < Decidim::OfficialAuthorPresenter
9
9
  def name
10
10
  I18n.t("decidim.debates.models.debate.fields.official_debate")
11
11
  end
12
-
13
- def nickname
14
- ""
15
- end
16
-
17
- def badge
18
- ""
19
- end
20
-
21
- def profile_path
22
- ""
23
- end
24
-
25
- def avatar_url
26
- ActionController::Base.helpers.asset_path("decidim/default-avatar.svg")
27
- end
28
-
29
- def deleted?
30
- false
31
- end
32
-
33
- def can_be_contacted?
34
- false
35
- end
36
-
37
- def has_tooltip?
38
- false
39
- end
40
12
  end
41
13
  end
42
14
  end
@@ -6,41 +6,31 @@ module Decidim
6
6
  # `current_component` param with a `Decidim::Component` in order to
7
7
  # find the debates.
8
8
  class DebateSearch < ResourceSearch
9
+ text_search_fields :title, :description
10
+
9
11
  # Public: Initializes the service.
10
12
  # component - A Decidim::Component to get the debates from.
11
13
  # page - The page number to paginate the results.
12
- # per_page - The number of proposals to return per page.
14
+ # per_page - The number of debates to return per page.
13
15
  def initialize(options = {})
14
16
  super(Debate.not_hidden, options)
15
17
  end
16
18
 
17
- # Handle the search_text filter. We have to cast the JSONB columns
18
- # into a `text` type so that we can search.
19
- def search_search_text
20
- query
21
- .where("decidim_debates_debates.title::text ILIKE ?", "%#{search_text}%")
22
- .or(query.where("decidim_debates_debates.description::text ILIKE ?", "%#{search_text}%"))
23
- end
24
-
25
- # Handle the origin filter
26
- def search_origin
27
- if origin == "official"
28
- query.where(author: component.organization)
29
- elsif origin == "citizens"
30
- query.where.not(decidim_author_type: "Decidim::Organization")
19
+ # Handle the activity filter
20
+ def search_activity
21
+ case activity
22
+ when "commented"
23
+ query.commented_by(user)
24
+ when "my_debates"
25
+ query.authored_by(user)
31
26
  else # Assume 'all'
32
27
  query
33
28
  end
34
29
  end
35
30
 
36
- def search_order_start_time
37
- if order_start_time == "asc"
38
- query.order("start_time ASC")
39
- elsif order_start_time == "desc"
40
- query.order("start_time DESC")
41
- else
42
- query.order("start_time ASC")
43
- end
31
+ # Handle the state filter
32
+ def search_state
33
+ apply_scopes(%w(open closed), state)
44
34
  end
45
35
  end
46
36
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Debates
5
+ class DiffRenderer < BaseDiffRenderer
6
+ private
7
+
8
+ # Lists which attributes will be diffable and how they should be rendered.
9
+ def attribute_types
10
+ {
11
+ title: :i18n,
12
+ description: :i18n,
13
+ information_updates: :i18n,
14
+ instructions: :i18n,
15
+ start_time: :string,
16
+ end_time: :string,
17
+ conclusions: :i18n,
18
+ closed_at: :string
19
+ }
20
+ end
21
+
22
+ def debate
23
+ @debate ||= Debate.find_by(id: version.item_id)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ <%= decidim_form_for(@form, url: debate_debate_close_path(debate, @form), html: { class: "form edit_close_debate" }) do |f| %>
2
+ <div class="card">
3
+ <div class="card-divider">
4
+ <h2 class="card-title"><%= t(".title") %></h2>
5
+ </div>
6
+
7
+ <div class="card-section">
8
+ <div class="row column">
9
+ <%= f.translated :editor, :conclusions, autofocus: true, rows: 15 %>
10
+ </div>
11
+ </div>
12
+ </div>
13
+
14
+ <div class="button--double form-general-submit">
15
+ <%= f.submit t(".close") %>
16
+ </div>
17
+ <% end %>
@@ -4,12 +4,12 @@
4
4
  </div>
5
5
 
6
6
  <div class="card-section">
7
- <div class="row column">
8
- <%= form.translated :text_field, :title, autofocus: true %>
7
+ <div class="row column hashtags__container">
8
+ <%= form.translated :text_field, :title, autofocus: true, class: "js-hashtags", hashtaggable: true %>
9
9
  </div>
10
10
 
11
- <div class="row column">
12
- <%= form.translated :editor, :description %>
11
+ <div class="row column hashtags__container">
12
+ <%= form.translated :editor, :description, hashtaggable: true %>
13
13
  </div>
14
14
 
15
15
  <div class="row column">
@@ -15,6 +15,7 @@
15
15
  <th><%= t("models.debate.fields.title", scope: "decidim.debates") %></th>
16
16
  <th><%= t("models.debate.fields.start_time", scope: "decidim.debates") %></th>
17
17
  <th><%= t("models.debate.fields.end_time", scope: "decidim.debates") %></th>
18
+ <%= th_resource_scope_label %>
18
19
  <th class="actions"><%= t("actions.title", scope: "decidim.debates") %></th>
19
20
  </tr>
20
21
  </thead>
@@ -22,7 +23,7 @@
22
23
  <% debates.each do |debate| %>
23
24
  <tr data-id="<%= debate.id %>">
24
25
  <td>
25
- <%= link_to translated_attribute(debate.title), resource_locator(debate).path, target: :blank %><br>
26
+ <%= link_to present(debate).title, resource_locator(debate).path, target: :blank %><br>
26
27
  </td>
27
28
  <td>
28
29
  <% if debate.start_time %>
@@ -34,11 +35,16 @@
34
35
  <%= l debate.end_time, format: :long %>
35
36
  <% end %>
36
37
  </td>
38
+ <%= td_resource_scope_for(debate.scope) %>
37
39
  <td class="table-list__actions">
38
40
  <% if allowed_to? :update, :debate, debate: debate %>
39
41
  <%= icon_link_to "pencil", edit_debate_path(debate), t("actions.edit", scope: "decidim.debates"), class: "action-icon--edit" %>
40
42
  <% end %>
41
43
 
44
+ <% if allowed_to? :close, :debate, debate: debate %>
45
+ <%= icon_link_to "lock-locked", edit_debate_debate_close_path(debate_id: debate.id, id: debate.id), t("actions.close", scope: "decidim.debates"), class: "action-icon--close" %>
46
+ <% end %>
47
+
42
48
  <% if allowed_to? :delete, :debate, debate: debate %>
43
49
  <%= icon_link_to "circle-x", debate_path(debate), t("actions.destroy", scope: "decidim.debates"), method: :delete, class: "action-icon--remove", data: { confirm: t("actions.confirm_destroy", scope: "decidim.debates") } %>
44
50
  <% end %>
@@ -0,0 +1,13 @@
1
+ <div class="reveal close-debate-modal" id="closeDebateModal" data-reveal>
2
+ <div class="reveal__header">
3
+ <h3 class="reveal__title"><%= t("decidim.debates.debates.show.close_debate") %></h3>
4
+ <button class="close-button" data-close aria-label="<%= t(".close") %>" type="button">
5
+ <span aria-hidden="true">&times;</span>
6
+ </button>
7
+ </div>
8
+ <p><%= t(".description") %></p>
9
+ <%= decidim_form_for form, url: close_debate_path(debate), method: :post do |f| %>
10
+ <%= f.text_area :conclusions, rows: 10 %>
11
+ <%= f.submit t(".send") %>
12
+ <% end %>
13
+ </div>
@@ -1,4 +1,11 @@
1
+ <div class="collection-sort-controls row small-up-1 medium-up-3 card-grid">
2
+ <div class="column">
3
+ <%= order_selector available_orders, i18n_scope: "decidim.debates.debates.orders" %>
4
+ </div>
5
+ </div>
6
+
1
7
  <div class="row small-up-1 medium-up-2 card-grid">
2
8
  <%= render paginated_debates %>
3
9
  </div>
10
+
4
11
  <%= decidim_paginate paginated_debates %>
@@ -14,19 +14,21 @@
14
14
  </div>
15
15
  </div>
16
16
 
17
- <%= form.collection_radio_buttons :origin, [["all", t(".all")], ["official", t(".official")], ["citizens", t(".citizens")]], :first, :last, { legend_title: t(".origin") }, "aria-controls": "debates" %>
17
+ <%= form.check_boxes_tree :state, filter_debates_state_values, legend_title: t(".state"), "aria-controls": "debates" %>
18
18
 
19
- <% if current_component.categories.any? %>
20
- <%= form.categories_select :category_id,
21
- current_component.categories,
22
- {
23
- legend_title: t(".category"),
24
- disable_parents: false,
25
- label: "",
26
- include_blank: t(".category_prompt"),
27
- aria_label: t(".category")
28
- },
29
- "aria-label": t(".category"),
30
- "aria-controls": "debates" %>
19
+ <% if current_participatory_space.has_subscopes? %>
20
+ <%= form.check_boxes_tree :scope_id, filter_scopes_values, legend_title: t(".scope"), "aria-controls": "debates" %>
31
21
  <% end %>
22
+
23
+ <% if current_participatory_space.categories.any? %>
24
+ <%= form.check_boxes_tree :category_id, filter_categories_values, legend_title: t(".category"), "aria-controls": "debates" %>
25
+ <% end %>
26
+
27
+ <%= form.check_boxes_tree :origin, filter_origin_values, legend_title: t(".origin"), "aria-controls": "debates" %>
28
+
29
+ <% if current_user %>
30
+ <%= form.collection_radio_buttons :activity, activity_filter_values, :first, :last, { legend_title: t(".activity") }, "aria-controls": "debates" %>
31
+ <% end %>
32
+
33
+ <%= hidden_field_tag :order, order, id: nil, class: "order_filter" %>
32
34
  <% end %>
@@ -0,0 +1,19 @@
1
+ <div class="field">
2
+ <%= form.text_field :title %>
3
+ </div>
4
+
5
+ <div class="field">
6
+ <%= text_editor_for_debate_description(form) %>
7
+ </div>
8
+
9
+ <% if current_participatory_space.categories&.any? %>
10
+ <div class="field">
11
+ <%= form.categories_select :category_id, current_participatory_space.categories, include_blank: t(".select_a_category"), disable_parents: false %>
12
+ </div>
13
+ <% end %>
14
+
15
+ <% if @form.id.blank? && Decidim::UserGroups::ManageableUserGroups.for(current_user).verified.any? %>
16
+ <div class="field">
17
+ <%= form.select :user_group_id, Decidim::UserGroups::ManageableUserGroups.for(current_user).verified.map{|g| [g.name, g.id]}, prompt: current_user.name %>
18
+ </div>
19
+ <% end %>
@@ -0,0 +1,22 @@
1
+ <div class="row columns">
2
+ <%= link_to :back, class: "muted-link" do %>
3
+ <%= icon "chevron-left", class: "icon--small", role: "img" %>
4
+ <%= t(".back") %>
5
+ <% end %>
6
+ <h2 class="section-heading"><%= t(".title") %></h2>
7
+ </div>
8
+
9
+ <div class="row">
10
+ <div class="columns large-6 medium-centered">
11
+ <div class="card">
12
+ <div class="card__content">
13
+ <%= decidim_form_for(@form) do |form| %>
14
+ <%= render partial: "form", locals: { form: form } %>
15
+ <div class="actions">
16
+ <%= form.submit t(".save"), class: "button expanded", data: { disable: true } %>
17
+ </div>
18
+ <% end %>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ </div>