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.
- checksums.yaml +4 -4
- data/README.md +10 -10
- data/app/cells/decidim/forms/matrix_readonly/show.erb +1 -1
- data/app/cells/decidim/forms/matrix_readonly_cell.rb +3 -3
- data/app/cells/decidim/forms/question_readonly/show.erb +5 -5
- data/app/cells/decidim/forms/question_readonly/title_and_description.erb +3 -3
- data/app/cells/decidim/forms/response_readonly_cell.rb +9 -0
- data/app/cells/decidim/forms/step_navigation/show.erb +3 -3
- data/app/cells/decidim/forms/step_navigation_cell.rb +3 -3
- data/app/commands/decidim/forms/admin/update_questions.rb +6 -6
- data/app/commands/decidim/forms/{answer_questionnaire.rb → response_questionnaire.rb} +35 -35
- data/app/controllers/decidim/forms/admin/concerns/has_questionnaire.rb +12 -12
- data/app/controllers/decidim/forms/admin/concerns/{has_questionnaire_answers.rb → has_questionnaire_responses.rb} +23 -19
- data/app/controllers/decidim/forms/concerns/has_questionnaire.rb +38 -33
- data/app/forms/decidim/forms/admin/display_condition_form.rb +14 -14
- data/app/forms/decidim/forms/admin/question_form.rb +3 -3
- data/app/forms/decidim/forms/admin/{answer_option_form.rb → response_option_form.rb} +3 -3
- data/app/forms/decidim/forms/questionnaire_form.rb +8 -9
- data/app/forms/decidim/forms/{answer_choice_form.rb → response_choice_form.rb} +5 -5
- data/app/forms/decidim/forms/{answer_form.rb → response_form.rb} +9 -9
- data/app/helpers/decidim/forms/admin/application_helper.rb +2 -2
- data/app/helpers/decidim/forms/admin/concerns/{has_questionnaire_answers_pagination_helper.rb → has_questionnaire_responses_pagination_helper.rb} +4 -4
- data/app/helpers/decidim/forms/admin/concerns/{has_questionnaire_answers_url_helper.rb → has_questionnaire_responses_url_helper.rb} +5 -5
- data/app/helpers/decidim/forms/admin/questionnaire_responses_helper.rb +32 -0
- data/app/helpers/decidim/forms/application_helper.rb +1 -2
- data/app/jobs/decidim/forms/{export_questionnaire_answers_job.rb → export_questionnaire_responses_job.rb} +5 -5
- data/app/models/decidim/forms/display_condition.rb +20 -20
- data/app/models/decidim/forms/question.rb +14 -13
- data/app/models/decidim/forms/question_matrix_row.rb +1 -1
- data/app/models/decidim/forms/questionnaire.rb +11 -6
- data/app/models/decidim/forms/{answer.rb → response.rb} +9 -9
- data/app/models/decidim/forms/response_choice.rb +22 -0
- data/app/models/decidim/forms/{answer_option.rb → response_option.rb} +5 -5
- data/app/packs/entrypoints/decidim_forms_admin.js +3 -3
- data/app/packs/src/decidim/forms/admin/collapsible_questions.js +12 -10
- data/app/packs/src/decidim/forms/admin/forms.js +35 -35
- data/app/packs/src/decidim/forms/admin/{publish_answers_buttons.js → publish_responses_buttons.js} +12 -12
- data/app/packs/src/decidim/forms/display_conditions.component.js +12 -12
- data/app/packs/src/decidim/forms/forms.js +4 -4
- data/app/packs/stylesheets/decidim/forms/forms.scss +2 -2
- data/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb +13 -13
- data/app/presenters/decidim/forms/admin/{questionnaire_answer_presenter.rb → questionnaire_response_presenter.rb} +15 -15
- data/app/presenters/decidim/forms/admin_log/question_presenter.rb +3 -3
- data/app/presenters/decidim/forms/{answer_option_presenter.rb → response_option_presenter.rb} +2 -2
- data/app/queries/decidim/forms/questionnaire_participant.rb +5 -5
- data/app/queries/decidim/forms/questionnaire_participants.rb +6 -6
- data/app/queries/decidim/forms/questionnaire_user_responses.rb +32 -0
- data/app/views/decidim/forms/admin/questionnaires/_display_condition.html.erb +9 -9
- data/app/views/decidim/forms/admin/questionnaires/_form.html.erb +2 -2
- data/app/views/decidim/forms/admin/questionnaires/_matrix_row.html.erb +3 -3
- data/app/views/decidim/forms/admin/questionnaires/_question.html.erb +16 -16
- data/app/views/decidim/forms/admin/questionnaires/_questions_form.html.erb +11 -10
- data/app/views/decidim/forms/admin/questionnaires/{_answer_option.html.erb → _response_option.html.erb} +7 -7
- data/app/views/decidim/forms/admin/questionnaires/_response_option_template.html.erb +7 -0
- data/app/views/decidim/forms/admin/questionnaires/_separator.html.erb +10 -7
- data/app/views/decidim/forms/admin/questionnaires/_title_and_description.html.erb +7 -7
- data/app/views/decidim/forms/admin/questionnaires/edit.html.erb +1 -1
- data/app/views/decidim/forms/admin/questionnaires/edit_questions.html.erb +8 -8
- data/app/views/decidim/forms/admin/questionnaires/responses/index.html.erb +80 -0
- data/app/views/decidim/forms/admin/questionnaires/responses/show.html.erb +43 -0
- data/app/views/decidim/forms/questionnaires/_questionnaire.html.erb +22 -26
- data/app/views/decidim/forms/questionnaires/_questionnaire_readonly.html.erb +8 -3
- data/app/views/decidim/forms/questionnaires/_response.html.erb +61 -0
- data/app/views/decidim/forms/questionnaires/edit.html.erb +2 -2
- data/app/views/decidim/forms/questionnaires/responses/_files.html.erb +1 -0
- data/app/views/decidim/forms/questionnaires/responses/_long_response.html.erb +3 -0
- data/app/views/decidim/forms/questionnaires/{answers → responses}/_matrix_multiple.html.erb +16 -15
- data/app/views/decidim/forms/questionnaires/{answers → responses}/_matrix_single.html.erb +17 -16
- data/app/views/decidim/forms/questionnaires/responses/_multiple_option.html.erb +26 -0
- data/app/views/decidim/forms/questionnaires/responses/_separator.html.erb +1 -0
- data/app/views/decidim/forms/questionnaires/responses/_short_response.html.erb +3 -0
- data/app/views/decidim/forms/questionnaires/responses/_single_option.html.erb +33 -0
- data/app/views/decidim/forms/questionnaires/responses/_sorting.html.erb +26 -0
- data/app/views/decidim/forms/questionnaires/responses/_title_and_description.html.erb +1 -0
- data/app/views/decidim/forms/questionnaires/show.html.erb +10 -10
- data/config/assets.rb +2 -2
- data/config/locales/ar.yml +0 -22
- data/config/locales/bg.yml +3 -36
- data/config/locales/ca-IT.yml +73 -73
- data/config/locales/ca.yml +73 -73
- data/config/locales/cs.yml +72 -75
- data/config/locales/de.yml +72 -72
- data/config/locales/el.yml +3 -36
- data/config/locales/en.yml +83 -83
- data/config/locales/es-MX.yml +75 -75
- data/config/locales/es-PY.yml +75 -75
- data/config/locales/es.yml +73 -73
- data/config/locales/eu.yml +71 -71
- data/config/locales/fi-plain.yml +71 -71
- data/config/locales/fi.yml +69 -69
- data/config/locales/fr-CA.yml +70 -67
- data/config/locales/fr.yml +70 -67
- data/config/locales/ga-IE.yml +0 -7
- data/config/locales/gl.yml +0 -22
- data/config/locales/hu.yml +0 -22
- data/config/locales/id-ID.yml +0 -22
- data/config/locales/it.yml +3 -40
- data/config/locales/ja.yml +80 -80
- data/config/locales/lb.yml +3 -36
- data/config/locales/lt.yml +3 -36
- data/config/locales/lv.yml +0 -22
- data/config/locales/nl.yml +3 -36
- data/config/locales/no.yml +3 -36
- data/config/locales/pl.yml +3 -36
- data/config/locales/pt-BR.yml +3 -36
- data/config/locales/pt.yml +3 -36
- data/config/locales/ro-RO.yml +22 -51
- data/config/locales/ru.yml +0 -9
- data/config/locales/sk.yml +0 -22
- data/config/locales/sl.yml +0 -5
- data/config/locales/sv.yml +82 -54
- data/config/locales/tr-TR.yml +3 -36
- data/config/locales/zh-CN.yml +3 -36
- data/config/locales/zh-TW.yml +3 -36
- data/db/migrate/20190315203056_add_session_token_to_decidim_forms_answers.rb +1 -1
- data/db/migrate/20250314150250_rename_answer_to_response_in_decidim_forms.rb +30 -0
- data/db/migrate/20250319130003_change_question_types_in_questions.rb +14 -0
- data/lib/decidim/api/question_matrix_row_type.rb +13 -0
- data/lib/decidim/api/question_type.rb +4 -3
- data/lib/decidim/api/questionnaire_type.rb +1 -0
- data/lib/decidim/api/response_option_type.rb +13 -0
- data/lib/decidim/exporters/form_pdf.rb +33 -33
- data/lib/decidim/forms/api.rb +2 -1
- data/lib/decidim/forms/{download_your_data_user_answers_serializer.rb → download_your_data_user_responses_serializer.rb} +3 -3
- data/lib/decidim/forms/engine.rb +2 -2
- data/lib/decidim/forms/test/factories.rb +24 -24
- data/lib/decidim/forms/test/shared_examples/has_questionnaire.rb +176 -176
- data/lib/decidim/forms/test/shared_examples/manage_questionnaire_responses.rb +159 -0
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_display_conditions.rb +19 -19
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_questions.rb +44 -44
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_display_conditions.rb +10 -10
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_questions.rb +18 -18
- data/lib/decidim/forms/test/shared_examples/manage_questionnaires.rb +4 -4
- data/lib/decidim/forms/test.rb +1 -1
- data/lib/decidim/forms/user_responses_serializer.rb +110 -0
- data/lib/decidim/forms/version.rb +1 -1
- data/lib/decidim/forms.rb +2 -2
- metadata +48 -45
- data/app/cells/decidim/forms/answer_readonly_cell.rb +0 -9
- data/app/helpers/decidim/forms/admin/questionnaire_answers_helper.rb +0 -30
- data/app/models/decidim/forms/answer_choice.rb +0 -22
- data/app/queries/decidim/forms/questionnaire_user_answers.rb +0 -32
- data/app/views/decidim/forms/admin/questionnaires/_answer_option_template.html.erb +0 -7
- data/app/views/decidim/forms/admin/questionnaires/answers/index.html.erb +0 -49
- data/app/views/decidim/forms/admin/questionnaires/answers/show.html.erb +0 -43
- data/app/views/decidim/forms/questionnaires/_answer.html.erb +0 -61
- data/app/views/decidim/forms/questionnaires/answers/_files.html.erb +0 -1
- data/app/views/decidim/forms/questionnaires/answers/_long_answer.html.erb +0 -3
- data/app/views/decidim/forms/questionnaires/answers/_multiple_option.html.erb +0 -25
- data/app/views/decidim/forms/questionnaires/answers/_separator.html.erb +0 -1
- data/app/views/decidim/forms/questionnaires/answers/_short_answer.html.erb +0 -3
- data/app/views/decidim/forms/questionnaires/answers/_single_option.html.erb +0 -32
- data/app/views/decidim/forms/questionnaires/answers/_sorting.html.erb +0 -26
- data/app/views/decidim/forms/questionnaires/answers/_title_and_description.html.erb +0 -1
- data/lib/decidim/api/answer_option_type.rb +0 -13
- data/lib/decidim/forms/test/shared_examples/manage_questionnaire_answers.rb +0 -149
- data/lib/decidim/forms/user_answers_serializer.rb +0 -105
- /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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05af3125cda32c7d53951e708a287eb891e0461c260db0d8d153412af721be38
|
4
|
+
data.tar.gz: b5d48ab5cbb0f1fbb6e970b874f1283cc827053a4d8c8251d46ab575183f7c68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
-
|
8
|
-
-
|
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 |------------->|
|
18
|
-
| +-----+----+
|
16
|
+
1..* +----------+ 1..* +----------------+
|
17
|
+
+------------->| Question |------------->| ResponseOption |
|
18
|
+
| +-----+----+ +-------+--------+
|
19
19
|
| ^ 1..1 ^ 1..*
|
20
20
|
| | |
|
21
21
|
| | |
|
22
|
-
+-------+-------+ 1..*
|
23
|
-
| Questionnaire +------->|
|
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(
|
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.
|
90
|
+
question.response_options.create!(body: Decidim::Faker::Localized.sentence)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
```
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
module Forms
|
5
|
-
# This cell renders a possible matrix
|
5
|
+
# This cell renders a possible matrix response of a question (readonly)
|
6
6
|
class MatrixReadonlyCell < Decidim::ViewModel
|
7
|
-
def
|
8
|
-
model.question.
|
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="
|
2
|
-
<p class="
|
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="
|
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="
|
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/
|
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="
|
2
|
-
<div class="
|
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="
|
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>
|
@@ -1,6 +1,6 @@
|
|
1
|
-
<div class="
|
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
|
44
|
-
options[:
|
43
|
+
def allow_editing_responses?
|
44
|
+
options[:allow_editing_responses]
|
45
45
|
end
|
46
46
|
|
47
47
|
def confirm_data
|
48
|
-
return {} if
|
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.
|
56
|
-
|
57
|
-
body:
|
58
|
-
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(
|
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
|
-
|
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
|
6
|
-
class
|
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
|
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
|
14
|
-
#
|
15
|
-
def initialize(form, questionnaire,
|
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
|
-
@
|
18
|
+
@allow_editing_responses = allow_editing_responses
|
19
19
|
end
|
20
20
|
|
21
|
-
#
|
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? || (
|
25
|
+
return broadcast(:invalid) if @form.invalid? || (user_already_responded? && !allow_editing_responses)
|
26
26
|
|
27
27
|
with_events do
|
28
|
-
|
29
|
-
|
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, :
|
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
|
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 |
|
62
|
-
|
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(
|
67
|
-
use_position =
|
66
|
+
def build_choices(response, form_response)
|
67
|
+
use_position = form_response.sorting?
|
68
68
|
|
69
|
-
|
69
|
+
form_response.selected_choices.each_with_index do |choice, idx|
|
70
70
|
choice_position = use_position ? choice.position.presence || idx : choice.position
|
71
|
-
|
71
|
+
response.choices.build(
|
72
72
|
body: choice.body,
|
73
73
|
custom_body: choice.custom_body,
|
74
|
-
|
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
|
82
|
-
|
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
|
85
|
+
def response_questionnaire
|
86
86
|
@main_form = @form
|
87
87
|
@errors = nil
|
88
88
|
|
89
|
-
|
90
|
-
form.responses_by_step.flatten.select(&:display_conditions_fulfilled?).each do |
|
91
|
-
|
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:
|
95
|
-
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(
|
100
|
+
build_choices(response, form_response)
|
101
101
|
|
102
|
-
|
102
|
+
response.save!
|
103
103
|
|
104
|
-
next unless
|
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 =
|
109
|
-
@attached_to =
|
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
|
128
|
-
questionnaire.
|
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, :
|
21
|
-
:blank_display_condition, :question_types, :display_condition_types, :update_url, :public_url, :
|
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
|
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.
|
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
|
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
|
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
|
130
|
-
url_for([questionnaire.questionnaire_for, { action: :
|
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
|
162
|
-
@
|
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
|
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
|
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::
|
23
|
-
include Decidim::Forms::Admin::Concerns::
|
22
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaireResponsesUrlHelper
|
23
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaireResponsesPaginationHelper
|
24
24
|
|
25
|
-
helper Decidim::Forms::Admin::
|
25
|
+
helper Decidim::Forms::Admin::QuestionnaireResponsesHelper
|
26
26
|
|
27
27
|
def index
|
28
|
-
enforce_permission_to :index,
|
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/
|
34
|
+
render template: "decidim/forms/admin/questionnaires/responses/index"
|
35
35
|
end
|
36
36
|
|
37
37
|
def show
|
38
|
-
enforce_permission_to :show,
|
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/
|
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,
|
46
|
+
enforce_permission_to :export_response, permission_subject
|
47
47
|
|
48
48
|
session_token = params[:id]
|
49
|
-
|
49
|
+
responses = QuestionnaireUserResponses.for(questionnaire)
|
50
50
|
|
51
|
-
# i18n-tasks-use t("decidim.forms.admin.questionnaires.
|
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 =
|
54
|
+
selected_response = responses.select { |a| a.first.session_token == session_token }
|
55
55
|
|
56
|
-
Decidim::Forms::
|
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:
|
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.
|
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(
|
88
|
-
Decidim::Forms::Admin::QuestionnaireParticipantPresenter.new(participant:
|
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 { |
|
96
|
+
query.map { |response| participant(response) }
|
93
97
|
end
|
94
98
|
end
|
95
99
|
end
|