decidim-forms 0.30.2 → 0.31.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -10
  3. data/app/cells/decidim/forms/matrix_readonly/show.erb +1 -1
  4. data/app/cells/decidim/forms/matrix_readonly_cell.rb +3 -3
  5. data/app/cells/decidim/forms/question_readonly/show.erb +5 -5
  6. data/app/cells/decidim/forms/question_readonly/title_and_description.erb +3 -3
  7. data/app/cells/decidim/forms/response_readonly_cell.rb +9 -0
  8. data/app/cells/decidim/forms/step_navigation/show.erb +3 -3
  9. data/app/cells/decidim/forms/step_navigation_cell.rb +3 -3
  10. data/app/commands/decidim/forms/admin/update_questions.rb +6 -6
  11. data/app/commands/decidim/forms/{answer_questionnaire.rb → response_questionnaire.rb} +35 -35
  12. data/app/controllers/decidim/forms/admin/concerns/has_questionnaire.rb +12 -12
  13. data/app/controllers/decidim/forms/admin/concerns/{has_questionnaire_answers.rb → has_questionnaire_responses.rb} +23 -19
  14. data/app/controllers/decidim/forms/concerns/has_questionnaire.rb +38 -33
  15. data/app/forms/decidim/forms/admin/display_condition_form.rb +14 -14
  16. data/app/forms/decidim/forms/admin/question_form.rb +3 -3
  17. data/app/forms/decidim/forms/admin/{answer_option_form.rb → response_option_form.rb} +3 -3
  18. data/app/forms/decidim/forms/questionnaire_form.rb +8 -9
  19. data/app/forms/decidim/forms/{answer_choice_form.rb → response_choice_form.rb} +5 -5
  20. data/app/forms/decidim/forms/{answer_form.rb → response_form.rb} +9 -9
  21. data/app/helpers/decidim/forms/admin/application_helper.rb +2 -2
  22. data/app/helpers/decidim/forms/admin/concerns/{has_questionnaire_answers_pagination_helper.rb → has_questionnaire_responses_pagination_helper.rb} +4 -4
  23. data/app/helpers/decidim/forms/admin/concerns/{has_questionnaire_answers_url_helper.rb → has_questionnaire_responses_url_helper.rb} +5 -5
  24. data/app/helpers/decidim/forms/admin/questionnaire_responses_helper.rb +32 -0
  25. data/app/helpers/decidim/forms/application_helper.rb +1 -2
  26. data/app/jobs/decidim/forms/{export_questionnaire_answers_job.rb → export_questionnaire_responses_job.rb} +5 -5
  27. data/app/models/decidim/forms/display_condition.rb +20 -20
  28. data/app/models/decidim/forms/question.rb +14 -13
  29. data/app/models/decidim/forms/question_matrix_row.rb +1 -1
  30. data/app/models/decidim/forms/questionnaire.rb +11 -6
  31. data/app/models/decidim/forms/{answer.rb → response.rb} +9 -9
  32. data/app/models/decidim/forms/response_choice.rb +22 -0
  33. data/app/models/decidim/forms/{answer_option.rb → response_option.rb} +5 -5
  34. data/app/packs/entrypoints/decidim_forms_admin.js +3 -3
  35. data/app/packs/src/decidim/forms/admin/collapsible_questions.js +12 -10
  36. data/app/packs/src/decidim/forms/admin/forms.js +35 -35
  37. data/app/packs/src/decidim/forms/admin/{publish_answers_buttons.js → publish_responses_buttons.js} +12 -12
  38. data/app/packs/src/decidim/forms/display_conditions.component.js +12 -12
  39. data/app/packs/src/decidim/forms/forms.js +4 -4
  40. data/app/packs/stylesheets/decidim/forms/forms.scss +2 -2
  41. data/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb +13 -13
  42. data/app/presenters/decidim/forms/admin/{questionnaire_answer_presenter.rb → questionnaire_response_presenter.rb} +15 -15
  43. data/app/presenters/decidim/forms/admin_log/question_presenter.rb +3 -3
  44. data/app/presenters/decidim/forms/{answer_option_presenter.rb → response_option_presenter.rb} +2 -2
  45. data/app/queries/decidim/forms/questionnaire_participant.rb +5 -5
  46. data/app/queries/decidim/forms/questionnaire_participants.rb +6 -6
  47. data/app/queries/decidim/forms/questionnaire_user_responses.rb +32 -0
  48. data/app/views/decidim/forms/admin/questionnaires/_display_condition.html.erb +9 -9
  49. data/app/views/decidim/forms/admin/questionnaires/_form.html.erb +2 -2
  50. data/app/views/decidim/forms/admin/questionnaires/_matrix_row.html.erb +3 -3
  51. data/app/views/decidim/forms/admin/questionnaires/_question.html.erb +16 -16
  52. data/app/views/decidim/forms/admin/questionnaires/_questions_form.html.erb +11 -10
  53. data/app/views/decidim/forms/admin/questionnaires/{_answer_option.html.erb → _response_option.html.erb} +7 -7
  54. data/app/views/decidim/forms/admin/questionnaires/_response_option_template.html.erb +7 -0
  55. data/app/views/decidim/forms/admin/questionnaires/_separator.html.erb +10 -7
  56. data/app/views/decidim/forms/admin/questionnaires/_title_and_description.html.erb +7 -7
  57. data/app/views/decidim/forms/admin/questionnaires/edit.html.erb +1 -1
  58. data/app/views/decidim/forms/admin/questionnaires/edit_questions.html.erb +8 -8
  59. data/app/views/decidim/forms/admin/questionnaires/responses/index.html.erb +80 -0
  60. data/app/views/decidim/forms/admin/questionnaires/responses/show.html.erb +43 -0
  61. data/app/views/decidim/forms/questionnaires/_questionnaire.html.erb +22 -26
  62. data/app/views/decidim/forms/questionnaires/_questionnaire_readonly.html.erb +8 -3
  63. data/app/views/decidim/forms/questionnaires/_response.html.erb +61 -0
  64. data/app/views/decidim/forms/questionnaires/edit.html.erb +2 -2
  65. data/app/views/decidim/forms/questionnaires/responses/_files.html.erb +1 -0
  66. data/app/views/decidim/forms/questionnaires/responses/_long_response.html.erb +3 -0
  67. data/app/views/decidim/forms/questionnaires/{answers → responses}/_matrix_multiple.html.erb +16 -15
  68. data/app/views/decidim/forms/questionnaires/{answers → responses}/_matrix_single.html.erb +17 -16
  69. data/app/views/decidim/forms/questionnaires/responses/_multiple_option.html.erb +26 -0
  70. data/app/views/decidim/forms/questionnaires/responses/_separator.html.erb +1 -0
  71. data/app/views/decidim/forms/questionnaires/responses/_short_response.html.erb +3 -0
  72. data/app/views/decidim/forms/questionnaires/responses/_single_option.html.erb +33 -0
  73. data/app/views/decidim/forms/questionnaires/responses/_sorting.html.erb +26 -0
  74. data/app/views/decidim/forms/questionnaires/responses/_title_and_description.html.erb +1 -0
  75. data/app/views/decidim/forms/questionnaires/show.html.erb +10 -10
  76. data/config/assets.rb +2 -2
  77. data/config/locales/ar.yml +0 -22
  78. data/config/locales/bg.yml +3 -36
  79. data/config/locales/ca-IT.yml +73 -73
  80. data/config/locales/ca.yml +73 -73
  81. data/config/locales/cs.yml +72 -75
  82. data/config/locales/de.yml +72 -72
  83. data/config/locales/el.yml +3 -36
  84. data/config/locales/en.yml +83 -83
  85. data/config/locales/es-MX.yml +75 -75
  86. data/config/locales/es-PY.yml +75 -75
  87. data/config/locales/es.yml +73 -73
  88. data/config/locales/eu.yml +71 -71
  89. data/config/locales/fi-plain.yml +71 -71
  90. data/config/locales/fi.yml +69 -69
  91. data/config/locales/fr-CA.yml +70 -67
  92. data/config/locales/fr.yml +70 -67
  93. data/config/locales/ga-IE.yml +0 -7
  94. data/config/locales/gl.yml +0 -22
  95. data/config/locales/hu.yml +0 -22
  96. data/config/locales/id-ID.yml +0 -22
  97. data/config/locales/it.yml +3 -40
  98. data/config/locales/ja.yml +80 -80
  99. data/config/locales/lb.yml +3 -36
  100. data/config/locales/lt.yml +3 -36
  101. data/config/locales/lv.yml +0 -22
  102. data/config/locales/nl.yml +3 -36
  103. data/config/locales/no.yml +3 -36
  104. data/config/locales/pl.yml +3 -36
  105. data/config/locales/pt-BR.yml +3 -36
  106. data/config/locales/pt.yml +3 -36
  107. data/config/locales/ro-RO.yml +22 -51
  108. data/config/locales/ru.yml +0 -9
  109. data/config/locales/sk.yml +0 -22
  110. data/config/locales/sl.yml +0 -5
  111. data/config/locales/sv.yml +82 -54
  112. data/config/locales/tr-TR.yml +3 -36
  113. data/config/locales/zh-CN.yml +3 -36
  114. data/config/locales/zh-TW.yml +3 -36
  115. data/db/migrate/20190315203056_add_session_token_to_decidim_forms_answers.rb +1 -1
  116. data/db/migrate/20250314150250_rename_answer_to_response_in_decidim_forms.rb +30 -0
  117. data/db/migrate/20250319130003_change_question_types_in_questions.rb +14 -0
  118. data/lib/decidim/api/question_matrix_row_type.rb +13 -0
  119. data/lib/decidim/api/question_type.rb +4 -3
  120. data/lib/decidim/api/questionnaire_type.rb +1 -0
  121. data/lib/decidim/api/response_option_type.rb +13 -0
  122. data/lib/decidim/exporters/form_pdf.rb +33 -33
  123. data/lib/decidim/forms/api.rb +2 -1
  124. data/lib/decidim/forms/{download_your_data_user_answers_serializer.rb → download_your_data_user_responses_serializer.rb} +3 -3
  125. data/lib/decidim/forms/engine.rb +2 -2
  126. data/lib/decidim/forms/test/factories.rb +24 -24
  127. data/lib/decidim/forms/test/shared_examples/has_questionnaire.rb +176 -176
  128. data/lib/decidim/forms/test/shared_examples/manage_questionnaire_responses.rb +159 -0
  129. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_display_conditions.rb +19 -19
  130. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_questions.rb +44 -44
  131. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_display_conditions.rb +10 -10
  132. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_questions.rb +18 -18
  133. data/lib/decidim/forms/test/shared_examples/manage_questionnaires.rb +4 -4
  134. data/lib/decidim/forms/test.rb +1 -1
  135. data/lib/decidim/forms/user_responses_serializer.rb +110 -0
  136. data/lib/decidim/forms/version.rb +1 -1
  137. data/lib/decidim/forms.rb +2 -2
  138. metadata +48 -45
  139. data/app/cells/decidim/forms/answer_readonly_cell.rb +0 -9
  140. data/app/helpers/decidim/forms/admin/questionnaire_answers_helper.rb +0 -30
  141. data/app/models/decidim/forms/answer_choice.rb +0 -22
  142. data/app/queries/decidim/forms/questionnaire_user_answers.rb +0 -32
  143. data/app/views/decidim/forms/admin/questionnaires/_answer_option_template.html.erb +0 -7
  144. data/app/views/decidim/forms/admin/questionnaires/answers/index.html.erb +0 -49
  145. data/app/views/decidim/forms/admin/questionnaires/answers/show.html.erb +0 -43
  146. data/app/views/decidim/forms/questionnaires/_answer.html.erb +0 -61
  147. data/app/views/decidim/forms/questionnaires/answers/_files.html.erb +0 -1
  148. data/app/views/decidim/forms/questionnaires/answers/_long_answer.html.erb +0 -3
  149. data/app/views/decidim/forms/questionnaires/answers/_multiple_option.html.erb +0 -25
  150. data/app/views/decidim/forms/questionnaires/answers/_separator.html.erb +0 -1
  151. data/app/views/decidim/forms/questionnaires/answers/_short_answer.html.erb +0 -3
  152. data/app/views/decidim/forms/questionnaires/answers/_single_option.html.erb +0 -32
  153. data/app/views/decidim/forms/questionnaires/answers/_sorting.html.erb +0 -26
  154. data/app/views/decidim/forms/questionnaires/answers/_title_and_description.html.erb +0 -1
  155. data/lib/decidim/api/answer_option_type.rb +0 -13
  156. data/lib/decidim/forms/test/shared_examples/manage_questionnaire_answers.rb +0 -149
  157. data/lib/decidim/forms/user_answers_serializer.rb +0 -105
  158. /data/app/cells/decidim/forms/{answer_readonly → response_readonly}/show.erb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1a8b24f27a5fe27e2a6ebf4799b2f59683f3da639198b0e7a346c60dcd28561
4
- data.tar.gz: 7c4caea9fc78e3515c2d2f95bb31db886e96a091f51f248d2939eaf03ecb2b6b
3
+ metadata.gz: 05af3125cda32c7d53951e708a287eb891e0461c260db0d8d153412af721be38
4
+ data.tar.gz: b5d48ab5cbb0f1fbb6e970b874f1283cc827053a4d8c8251d46ab575183f7c68
5
5
  SHA512:
6
- metadata.gz: 5c3946e36ebcc2261912001d51c32363e77fda1a3949d3d0c12ec5c794fa75211b958ded800bc860ffdefab777ec96d89f964e1f1e7bc294af4afc1ca0953cbb
7
- data.tar.gz: 70eef05c6c7bb3cb7000f1659db5c6249962754a0add45ccd7f6f1dcf88e583b8852c0e2b77ebd7131c2ef365ededf5fb8e8182a91acfdd41c5e69466a804f78
6
+ metadata.gz: b161e3aa8dfc6ac31403c294b7e0bbe9f204bff581a081b7941c7e5d79e3f0d8bfe9c05d8977b96245b303c6faaca4de97f6fe5262f21a5b59bd5d844ac6f9ed
7
+ data.tar.gz: 4a0f3aeb5702e008483a90afea735eba581c53bd9d949a7447178c40c67d263705573b91012aa0c6f94234537123abb87ebe6b401482754cc0170718930a0c26
data/README.md CHANGED
@@ -4,8 +4,8 @@ This gem encapsulates the logic to create and manage forms, so it can be reused
4
4
 
5
5
  A `Decidim::Forms::Question` must be of one of the types:
6
6
 
7
- - short_answer
8
- - long_answer
7
+ - short_response
8
+ - long_response
9
9
  - single_option
10
10
  - multiple_option
11
11
  - sorting
@@ -13,15 +13,15 @@ A `Decidim::Forms::Question` must be of one of the types:
13
13
  Here are the relations between the classes of a `Decidim::Questionnaire`:
14
14
 
15
15
  ```plantuml
16
- 1..* +----------+ 1..* +--------------+
17
- +------------->| Question |------------->| AnswerOption |
18
- | +-----+----+ +------+-------+
16
+ 1..* +----------+ 1..* +----------------+
17
+ +------------->| Question |------------->| ResponseOption |
18
+ | +-----+----+ +-------+--------+
19
19
  | ^ 1..1 ^ 1..*
20
20
  | | |
21
21
  | | |
22
- +-------+-------+ 1..* +---+----+ 1..* +------+-------+
23
- | Questionnaire +------->| Answer |<-------------+ AnswerChoice |
24
- +---------------+ +---+----+ +--------------+
22
+ +-------+-------+ 1..* +----+-----+ 1..* +--------+-------+
23
+ | Questionnaire +------->| Response |<-------------+ ResponseChoice |
24
+ +---------------+ +----+0----+ +----------------+
25
25
  |
26
26
  |
27
27
  v 1..1
@@ -71,7 +71,7 @@ Decidim::Forms::Questionnaire.new(
71
71
 
72
72
  Decidim::Surveys::Survey.create!(component: component, questionnaire: questionnaire)
73
73
 
74
- %w(short_answer long_answer).each do |text_question_type|
74
+ %w(short_response long_response).each do |text_question_type|
75
75
  Decidim::Forms::Question.create!(
76
76
  questionnaire: questionnaire,
77
77
  body: Decidim::Faker::Localized.paragraph,
@@ -87,7 +87,7 @@ end
87
87
  )
88
88
 
89
89
  3.times do
90
- question.answer_options.create!(body: Decidim::Faker::Localized.sentence)
90
+ question.response_options.create!(body: Decidim::Faker::Localized.sentence)
91
91
  end
92
92
  end
93
93
  ```
@@ -1,5 +1,5 @@
1
1
  <li>
2
2
  <%= translated_attribute(model.body) %>
3
3
 
4
- (<%= answer_options %>)
4
+ (<%= response_options %>)
5
5
  </li>
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Decidim
4
4
  module Forms
5
- # This cell renders a possible matrix answer of a question (readonly)
5
+ # This cell renders a possible matrix response of a question (readonly)
6
6
  class MatrixReadonlyCell < Decidim::ViewModel
7
- def answer_options
8
- model.question.answer_options.map { |option| translated_attribute(option.body) }.join(" / ")
7
+ def response_options
8
+ model.question.response_options.map { |option| translated_attribute(option.body) }.join(" / ")
9
9
  end
10
10
  end
11
11
  end
@@ -1,18 +1,18 @@
1
- <li class="answer-questionnaire__question" data-question-readonly>
2
- <p class="answer-questionnaire__question-label" data-answer-idx="<%= position %>">
1
+ <li class="response-questionnaire__question" data-question-readonly>
2
+ <p class="response-questionnaire__question-label" data-response-idx="<%= position %>">
3
3
  <%= decidim_escape_translated(model.body) %>
4
4
  </p>
5
5
 
6
- <p class="answer-questionnaire__question-description">
6
+ <p class="response-questionnaire__question-description">
7
7
  <em><%= t(model.question_type, scope: "decidim.forms.question_types") %></em>
8
8
  </p>
9
9
 
10
10
  <% if model.multiple_choice? %>
11
- <ul class="answer-questionnaire__question-description space-y-4">
11
+ <ul class="response-questionnaire__question-description space-y-4">
12
12
  <% if model.matrix? %>
13
13
  <%= cell("decidim/forms/matrix_readonly", collection: model.matrix_rows) %>
14
14
  <% else %>
15
- <%= cell("decidim/forms/answer_readonly", collection: model.answer_options) %>
15
+ <%= cell("decidim/forms/response_readonly", collection: model.response_options) %>
16
16
  <% end %>
17
17
  </ul>
18
18
  <% end %>
@@ -1,7 +1,7 @@
1
- <li class="answer-questionnaire__question" data-question-readonly>
2
- <div class="answer-questionnaire__step-heading">
1
+ <li class="response-questionnaire__question" data-question-readonly>
2
+ <div class="response-questionnaire__step-heading">
3
3
  <h3 class="h3"><%= decidim_escape_translated(model.body) %></h3>
4
- <p class="answer-questionnaire__question-description">
4
+ <p class="response-questionnaire__question-description">
5
5
  <em><%= t(model.question_type, scope: "decidim.forms.question_types") %></em>
6
6
  </p>
7
7
  </div>
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Forms
5
+ # This cell renders a possible response of a question (readonly)
6
+ class ResponseReadonlyCell < Decidim::ViewModel
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,6 @@
1
- <div class="answer-questionnaire__submit layout-aside__ctas-buttons survey-section-buttons" data-sticky-buttons>
1
+ <div class="response-questionnaire__submit layout-aside__ctas-buttons survey-section-buttons" data-controller="sticky-buttons">
2
2
  <% if !first_step? %>
3
- <button type="button" class="button button__sm button__transparent-secondary" data-toggle="<%= [previous_step_dom_id, current_step_dom_id].join(" ") %>" data-survey-buttons>
3
+ <button type="button" class="button button__sm button__transparent-secondary" data-controller="toggle" data-toggle-toggle-value="<%= [previous_step_dom_id, current_step_dom_id].join(" ") %>" data-survey-buttons>
4
4
  <%= icon "arrow-left-line", class: "fill-current" %>
5
5
  <%= t("decidim.forms.step_navigation.show.back") %>
6
6
  </button>
@@ -14,7 +14,7 @@
14
14
  **confirm_data
15
15
  ) %>
16
16
  <% else %>
17
- <button type="button" class="button button__sm button__secondary" data-toggle="<%= [next_step_dom_id, current_step_dom_id].join(" ") %>" data-survey-buttons>
17
+ <button type="button" class="button button__sm button__secondary" data-controller="toggle" data-toggle-toggle-value="<%= [next_step_dom_id, current_step_dom_id].join(" ") %>" data-survey-buttons>
18
18
  <%= t("decidim.forms.step_navigation.show.continue") %>
19
19
  <%= icon "arrow-right-line", class: "fill-current" %>
20
20
  </button>
@@ -40,12 +40,12 @@ module Decidim
40
40
  "step-#{current_step_index}"
41
41
  end
42
42
 
43
- def allow_editing_answers?
44
- options[:allow_editing_answers]
43
+ def allow_editing_responses?
44
+ options[:allow_editing_responses]
45
45
  end
46
46
 
47
47
  def confirm_data
48
- return {} if allow_editing_answers? && current_user
48
+ return {} if allow_editing_responses? && current_user
49
49
 
50
50
  {
51
51
  data: {
@@ -52,13 +52,13 @@ module Decidim
52
52
  }
53
53
 
54
54
  update_nested_model(form_question, question_attributes, @questionnaire.questions) do |question|
55
- form_question.answer_options.each do |form_answer_option|
56
- answer_option_attributes = {
57
- body: form_answer_option.body,
58
- free_text: form_answer_option.free_text
55
+ form_question.response_options.each do |form_response_option|
56
+ response_option_attributes = {
57
+ body: form_response_option.body,
58
+ free_text: form_response_option.free_text
59
59
  }
60
60
 
61
- update_nested_model(form_answer_option, answer_option_attributes, question.answer_options)
61
+ update_nested_model(form_response_option, response_option_attributes, question.response_options)
62
62
  end
63
63
 
64
64
  form_question.display_conditions.each do |form_display_condition|
@@ -68,7 +68,7 @@ module Decidim
68
68
  condition_question: form_display_condition.condition_question,
69
69
  condition_type: form_display_condition.condition_type,
70
70
  condition_value: type == "match" ? form_display_condition.condition_value : nil,
71
- answer_option: %w(equal not_equal).include?(type) ? form_display_condition.answer_option : nil,
71
+ response_option: %w(equal not_equal).include?(type) ? form_display_condition.response_option : nil,
72
72
  mandatory: form_display_condition.mandatory
73
73
  }
74
74
 
@@ -2,31 +2,31 @@
2
2
 
3
3
  module Decidim
4
4
  module Forms
5
- # This command is executed when the user answers a Questionnaire.
6
- class AnswerQuestionnaire < Decidim::Command
5
+ # This command is executed when the user responds a Questionnaire.
6
+ class ResponseQuestionnaire < Decidim::Command
7
7
  delegate :current_user, to: :form
8
8
  include ::Decidim::MultipleAttachmentsMethods
9
9
 
10
- # Initializes a AnswerQuestionnaire Command.
10
+ # Initializes a ResponseQuestionnaire Command.
11
11
  #
12
12
  # form - The form from which to get the data.
13
- # questionnaire - The current instance of the questionnaire to be answered.
14
- # allow_editing_answers - Flag that ensures a form can or cannot be editable after the questionnaire's answers have been provided.
15
- def initialize(form, questionnaire, allow_editing_answers: false)
13
+ # questionnaire - The current instance of the questionnaire to be responded.
14
+ # allow_editing_responses - Flag that ensures a form can or cannot be editable after the questionnaire's responses have been provided.
15
+ def initialize(form, questionnaire, allow_editing_responses: false)
16
16
  @form = form
17
17
  @questionnaire = questionnaire
18
- @allow_editing_answers = allow_editing_answers
18
+ @allow_editing_responses = allow_editing_responses
19
19
  end
20
20
 
21
- # Answers a questionnaire if it is valid
21
+ # Responds a questionnaire if it is valid
22
22
  #
23
23
  # Broadcasts :ok if successful, :invalid otherwise.
24
24
  def call
25
- return broadcast(:invalid) if @form.invalid? || (user_already_answered? && !allow_editing_answers)
25
+ return broadcast(:invalid) if @form.invalid? || (user_already_responded? && !allow_editing_responses)
26
26
 
27
27
  with_events do
28
- clear_answers! if allow_editing_answers
29
- answer_questionnaire
28
+ clear_responses! if allow_editing_responses
29
+ response_questionnaire
30
30
  end
31
31
 
32
32
  if @errors
@@ -37,7 +37,7 @@ module Decidim
37
37
  end
38
38
  end
39
39
 
40
- attr_reader :form, :questionnaire, :allow_editing_answers
40
+ attr_reader :form, :questionnaire, :allow_editing_responses
41
41
 
42
42
  private
43
43
 
@@ -53,60 +53,60 @@ module Decidim
53
53
  end
54
54
 
55
55
  # This method will add an error to the `add_documents` field only if there is
56
- # any error in any other field or an error in another answer in the
56
+ # any error in any other field or an error in another response in the
57
57
  # questionnaire. This is needed because when the form has
58
58
  # an error, the attachments are lost, so we need a way to inform the user
59
59
  # of this problem.
60
60
  def reset_form_attachments
61
- @form.responses.each do |answer|
62
- answer.errors.add(:add_documents, :needs_to_be_reattached) if answer.has_attachments? || answer.has_error_in_attachments?
61
+ @form.responses.each do |response|
62
+ response.errors.add(:add_documents, :needs_to_be_reattached) if response.has_attachments? || response.has_error_in_attachments?
63
63
  end
64
64
  end
65
65
 
66
- def build_choices(answer, form_answer)
67
- use_position = form_answer.sorting?
66
+ def build_choices(response, form_response)
67
+ use_position = form_response.sorting?
68
68
 
69
- form_answer.selected_choices.each_with_index do |choice, idx|
69
+ form_response.selected_choices.each_with_index do |choice, idx|
70
70
  choice_position = use_position ? choice.position.presence || idx : choice.position
71
- answer.choices.build(
71
+ response.choices.build(
72
72
  body: choice.body,
73
73
  custom_body: choice.custom_body,
74
- decidim_answer_option_id: choice.answer_option_id,
74
+ decidim_response_option_id: choice.response_option_id,
75
75
  decidim_question_matrix_row_id: choice.matrix_row_id,
76
76
  position: choice_position
77
77
  )
78
78
  end
79
79
  end
80
80
 
81
- def clear_answers!
82
- Answer.where(questionnaire: questionnaire, user: current_user, session_token: form.context.session_token, ip_hash: form.context.ip_hash).destroy_all
81
+ def clear_responses!
82
+ Response.where(questionnaire: questionnaire, user: current_user, session_token: form.context.session_token, ip_hash: form.context.ip_hash).destroy_all
83
83
  end
84
84
 
85
- def answer_questionnaire
85
+ def response_questionnaire
86
86
  @main_form = @form
87
87
  @errors = nil
88
88
 
89
- Answer.transaction(requires_new: true) do
90
- form.responses_by_step.flatten.select(&:display_conditions_fulfilled?).each do |form_answer|
91
- answer = Answer.new(
89
+ Response.transaction(requires_new: true) do
90
+ form.responses_by_step.flatten.select(&:display_conditions_fulfilled?).each do |form_response|
91
+ response = Response.new(
92
92
  user: current_user,
93
93
  questionnaire: @questionnaire,
94
- question: form_answer.question,
95
- body: form_answer.body,
94
+ question: form_response.question,
95
+ body: form_response.body,
96
96
  session_token: form.context.session_token,
97
97
  ip_hash: form.context.ip_hash
98
98
  )
99
99
 
100
- build_choices(answer, form_answer)
100
+ build_choices(response, form_response)
101
101
 
102
- answer.save!
102
+ response.save!
103
103
 
104
- next unless form_answer.question.has_attachments?
104
+ next unless form_response.question.has_attachments?
105
105
 
106
106
  # The attachments module expects `@form` to be the form with the
107
107
  # attachments
108
- @form = form_answer
109
- @attached_to = answer
108
+ @form = form_response
109
+ @attached_to = response
110
110
 
111
111
  build_attachments
112
112
 
@@ -124,8 +124,8 @@ module Decidim
124
124
  end
125
125
  end
126
126
 
127
- def user_already_answered?
128
- questionnaire.answered_by?(current_user || form.context.session_token)
127
+ def user_already_responded?
128
+ questionnaire.responded_by?(current_user || form.context.session_token)
129
129
  end
130
130
  end
131
131
  end
@@ -17,8 +17,8 @@ module Decidim
17
17
  helper Decidim::Forms::Admin::ApplicationHelper
18
18
  include Decidim::TranslatableAttributes
19
19
 
20
- helper_method :questionnaire_for, :questionnaire, :blank_question, :blank_answer_option, :blank_matrix_row,
21
- :blank_display_condition, :question_types, :display_condition_types, :update_url, :public_url, :answer_options_url, :edit_questionnaire_title
20
+ helper_method :questionnaire_for, :questionnaire, :blank_question, :blank_response_option, :blank_matrix_row,
21
+ :blank_display_condition, :question_types, :display_condition_types, :update_url, :public_url, :response_options_url, :edit_questionnaire_title
22
22
 
23
23
  if defined?(Decidim::Templates::Admin::Concerns::Templatable)
24
24
  include Decidim::Templates::Admin::Concerns::Templatable
@@ -56,7 +56,7 @@ module Decidim
56
56
  on(:invalid) do
57
57
  # i18n-tasks-use t("decidim.forms.admin.questionnaires.update.invalid")
58
58
  flash.now[:alert] = I18n.t("update.invalid", scope: i18n_flashes_scope)
59
- render template: edit_template
59
+ render template: edit_template, status: :unprocessable_entity
60
60
  end
61
61
  end
62
62
  end
@@ -79,17 +79,17 @@ module Decidim
79
79
 
80
80
  on(:invalid) do
81
81
  flash.now[:alert] = I18n.t("update.invalid", scope: i18n_flashes_scope)
82
- render template: edit_questions_template
82
+ render template: edit_questions_template, status: :unprocessable_entity
83
83
  end
84
84
  end
85
85
  end
86
86
 
87
- def answer_options
87
+ def response_options
88
88
  respond_to do |format|
89
89
  format.json do
90
90
  question_id = params["id"]
91
91
  question = Question.find_by(id: question_id)
92
- render json: question.answer_options.map { |answer_option| AnswerOptionPresenter.new(answer_option).as_json } if question.present?
92
+ render json: question.response_options.map { |response_option| ResponseOptionPresenter.new(response_option).as_json } if question.present?
93
93
  end
94
94
  end
95
95
  end
@@ -113,7 +113,7 @@ module Decidim
113
113
  end
114
114
 
115
115
  # Implement this method in your controller to set the URL
116
- # where the questionnaire can be answered.
116
+ # where the questionnaire can be responded.
117
117
  def public_url
118
118
  raise "#{self.class.name} is expected to implement #public_url"
119
119
  end
@@ -124,10 +124,10 @@ module Decidim
124
124
  "decidim/forms/admin/questionnaires/edit_questions"
125
125
  end
126
126
 
127
- # Returns the url to get the answer options json (for the display conditions form)
127
+ # Returns the url to get the response options json (for the display conditions form)
128
128
  # for the question with id = params[:id]
129
- def answer_options_url(params)
130
- url_for([questionnaire.questionnaire_for, { action: :answer_options, format: :json, **params }])
129
+ def response_options_url(params)
130
+ url_for([questionnaire.questionnaire_for, { action: :response_options, format: :json, **params }])
131
131
  end
132
132
 
133
133
  # Implement this method in your controller to set the title
@@ -158,8 +158,8 @@ module Decidim
158
158
  @blank_question ||= Admin::QuestionForm.new
159
159
  end
160
160
 
161
- def blank_answer_option
162
- @blank_answer_option ||= Admin::AnswerOptionForm.new
161
+ def blank_response_option
162
+ @blank_response_option ||= Admin::ResponseOptionForm.new
163
163
  end
164
164
 
165
165
  def blank_display_condition
@@ -5,7 +5,7 @@ module Decidim
5
5
  module Admin
6
6
  module Concerns
7
7
  # Questionnaires can be related to any class in Decidim. In order to
8
- # manage the questionnaires answers for a given type, you should create a new
8
+ # manage the questionnaires responses for a given type, you should create a new
9
9
  # controller and include the HasQuestionnaire concern as well as this one.
10
10
  #
11
11
  # In the controller that includes this concern, you should define a
@@ -14,50 +14,50 @@ module Decidim
14
14
  # `index_<model>_url` and `export_<model>_url` as well as
15
15
  # `show_<model>_url` and `export_response_<model>_url` (which are passed
16
16
  # a `:session_token` parameter)
17
- module HasQuestionnaireAnswers
17
+ module HasQuestionnaireResponses
18
18
  extend ActiveSupport::Concern
19
19
 
20
20
  included do
21
21
  include Decidim::Paginable
22
- include Decidim::Forms::Admin::Concerns::HasQuestionnaireAnswersUrlHelper
23
- include Decidim::Forms::Admin::Concerns::HasQuestionnaireAnswersPaginationHelper
22
+ include Decidim::Forms::Admin::Concerns::HasQuestionnaireResponsesUrlHelper
23
+ include Decidim::Forms::Admin::Concerns::HasQuestionnaireResponsesPaginationHelper
24
24
 
25
- helper Decidim::Forms::Admin::QuestionnaireAnswersHelper
25
+ helper Decidim::Forms::Admin::QuestionnaireResponsesHelper
26
26
 
27
27
  def index
28
- enforce_permission_to :index, :questionnaire_answers
28
+ enforce_permission_to :index, permission_subject
29
29
 
30
30
  @query = paginate(collection)
31
31
  @participants = participants(@query)
32
32
  @total = questionnaire.count_participants
33
33
 
34
- render template: "decidim/forms/admin/questionnaires/answers/index"
34
+ render template: "decidim/forms/admin/questionnaires/responses/index"
35
35
  end
36
36
 
37
37
  def show
38
- enforce_permission_to :show, :questionnaire_answers
38
+ enforce_permission_to :show, permission_subject
39
39
 
40
40
  @participant = participant(participants_query.participant(params[:id]))
41
41
 
42
- render template: "decidim/forms/admin/questionnaires/answers/show"
42
+ render template: "decidim/forms/admin/questionnaires/responses/show"
43
43
  end
44
44
 
45
45
  def export_response
46
- enforce_permission_to :export_response, :questionnaire_answers
46
+ enforce_permission_to :export_response, permission_subject
47
47
 
48
48
  session_token = params[:id]
49
- answers = QuestionnaireUserAnswers.for(questionnaire)
49
+ responses = QuestionnaireUserResponses.for(questionnaire)
50
50
 
51
- # i18n-tasks-use t("decidim.forms.admin.questionnaires.answers.export_response.title")
51
+ # i18n-tasks-use t("decidim.forms.admin.questionnaires.responses.export_response.title")
52
52
  file_name = t("export_response.title", scope: i18n_scope, token: session_token)
53
53
 
54
- selected_response = answers.select { |a| a.first.session_token == session_token }
54
+ selected_response = responses.select { |a| a.first.session_token == session_token }
55
55
 
56
- Decidim::Forms::ExportQuestionnaireAnswersJob.perform_later(current_user, file_name, selected_response, :survey_user_answers)
56
+ Decidim::Forms::ExportQuestionnaireResponsesJob.perform_later(current_user, file_name, selected_response, :survey_user_responses)
57
57
 
58
58
  flash[:notice] = t("decidim.admin.exports.notice")
59
59
 
60
- redirect_back(fallback_location: questionnaire_participant_answers_url(session_token))
60
+ redirect_back(fallback_location: questionnaire_participant_responses_url(session_token))
61
61
  end
62
62
 
63
63
  # Public: The only method to be implemented at the controller. You need to
@@ -68,8 +68,12 @@ module Decidim
68
68
 
69
69
  private
70
70
 
71
+ def permission_subject
72
+ :questionnaire_responses
73
+ end
74
+
71
75
  def i18n_scope
72
- "decidim.forms.admin.questionnaires.answers"
76
+ "decidim.forms.admin.questionnaires.responses"
73
77
  end
74
78
 
75
79
  def questionnaire
@@ -84,12 +88,12 @@ module Decidim
84
88
  @collection ||= participants_query.participants
85
89
  end
86
90
 
87
- def participant(answer)
88
- Decidim::Forms::Admin::QuestionnaireParticipantPresenter.new(participant: answer)
91
+ def participant(response)
92
+ Decidim::Forms::Admin::QuestionnaireParticipantPresenter.new(participant: response)
89
93
  end
90
94
 
91
95
  def participants(query)
92
- query.map { |answer| participant(answer) }
96
+ query.map { |response| participant(response) }
93
97
  end
94
98
  end
95
99
  end