decidim-forms 0.29.2 → 0.30.0.rc2

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 (87) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/forms/step_navigation_cell.rb +18 -5
  3. data/app/commands/decidim/forms/admin/update_questionnaire.rb +1 -82
  4. data/app/commands/decidim/forms/admin/update_questions.rb +109 -0
  5. data/app/commands/decidim/forms/answer_questionnaire.rb +10 -3
  6. data/app/controllers/decidim/forms/admin/concerns/has_questionnaire.rb +39 -3
  7. data/app/controllers/decidim/forms/admin/concerns/has_questionnaire_answers.rb +2 -2
  8. data/app/controllers/decidim/forms/concerns/has_questionnaire.rb +12 -4
  9. data/app/forms/decidim/forms/admin/display_condition_form.rb +1 -1
  10. data/app/forms/decidim/forms/admin/questionnaire_form.rb +0 -9
  11. data/app/forms/decidim/forms/admin/questions_form.rb +18 -0
  12. data/app/forms/decidim/forms/answer_choice_form.rb +5 -0
  13. data/app/forms/decidim/forms/answer_form.rb +1 -0
  14. data/app/forms/decidim/forms/questionnaire_form.rb +7 -0
  15. data/app/helpers/decidim/forms/admin/concerns/has_questionnaire_answers_pagination_helper.rb +1 -1
  16. data/app/helpers/decidim/forms/admin/concerns/has_questionnaire_answers_url_helper.rb +5 -5
  17. data/app/jobs/decidim/forms/export_questionnaire_answers_job.rb +5 -1
  18. data/app/models/decidim/forms/answer_choice.rb +0 -2
  19. data/app/models/decidim/forms/answer_option.rb +1 -1
  20. data/app/models/decidim/forms/question.rb +10 -0
  21. data/app/packs/entrypoints/decidim_forms.js +0 -1
  22. data/app/packs/entrypoints/decidim_forms_admin.js +6 -0
  23. data/app/packs/src/decidim/forms/admin/publish_answers_buttons.js +72 -0
  24. data/app/packs/src/decidim/forms/forms.js +22 -18
  25. data/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb +1 -1
  26. data/app/presenters/decidim/forms/admin_log/question_presenter.rb +31 -0
  27. data/app/queries/decidim/forms/questionnaire_user_answers.rb +1 -1
  28. data/app/views/decidim/forms/admin/questionnaires/_answer_option_template.html.erb +1 -1
  29. data/app/views/decidim/forms/admin/questionnaires/_display_condition_template.html.erb +1 -1
  30. data/app/views/decidim/forms/admin/questionnaires/_form.html.erb +0 -89
  31. data/app/views/decidim/forms/admin/questionnaires/_matrix_row_template.html.erb +1 -1
  32. data/app/views/decidim/forms/admin/questionnaires/_question.html.erb +3 -3
  33. data/app/views/decidim/forms/admin/questionnaires/_questions_form.html.erb +80 -0
  34. data/app/views/decidim/forms/admin/questionnaires/edit.html.erb +0 -20
  35. data/app/views/decidim/forms/admin/questionnaires/edit_questions.html.erb +47 -0
  36. data/app/views/decidim/forms/questionnaires/_questionnaire.html.erb +8 -1
  37. data/app/views/decidim/forms/questionnaires/answers/_files.html.erb +1 -1
  38. data/app/views/decidim/forms/questionnaires/answers/_sorting.html.erb +12 -6
  39. data/app/views/decidim/forms/questionnaires/edit.html.erb +47 -0
  40. data/app/views/decidim/forms/questionnaires/show.html.erb +13 -2
  41. data/config/assets.rb +1 -2
  42. data/config/locales/bg.yml +0 -2
  43. data/config/locales/ca.yml +46 -6
  44. data/config/locales/cs.yml +45 -5
  45. data/config/locales/de.yml +45 -5
  46. data/config/locales/el.yml +0 -2
  47. data/config/locales/en.yml +45 -5
  48. data/config/locales/es-MX.yml +45 -5
  49. data/config/locales/es-PY.yml +45 -5
  50. data/config/locales/es.yml +45 -5
  51. data/config/locales/eu.yml +45 -5
  52. data/config/locales/fi-plain.yml +45 -5
  53. data/config/locales/fi.yml +45 -5
  54. data/config/locales/fr-CA.yml +37 -5
  55. data/config/locales/fr.yml +37 -5
  56. data/config/locales/ja.yml +46 -1
  57. data/config/locales/lt.yml +0 -2
  58. data/config/locales/pl.yml +0 -2
  59. data/config/locales/ro-RO.yml +22 -17
  60. data/config/locales/zh-TW.yml +0 -2
  61. data/db/migrate/20190315203056_add_session_token_to_decidim_forms_answers.rb +1 -1
  62. data/db/migrate/20241122142230_add_survey_answers_published_at_to_questions.rb +7 -0
  63. data/decidim-forms.gemspec +1 -2
  64. data/lib/decidim/api/answer_option_type.rb +1 -1
  65. data/lib/decidim/api/question_type.rb +4 -4
  66. data/lib/decidim/api/questionnaire_type.rb +4 -4
  67. data/lib/decidim/exporters/form_pdf.rb +114 -11
  68. data/lib/decidim/forms/download_your_data_user_answers_serializer.rb +0 -4
  69. data/lib/decidim/forms/test/factories.rb +2 -2
  70. data/lib/decidim/forms/test/shared_examples/has_questionnaire.rb +44 -4
  71. data/lib/decidim/forms/test/shared_examples/manage_questionnaire_answers.rb +17 -17
  72. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_display_conditions.rb +19 -21
  73. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_questions.rb +70 -94
  74. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_display_conditions.rb +15 -18
  75. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_questions.rb +90 -125
  76. data/lib/decidim/forms/test/shared_examples/manage_questionnaires.rb +4 -25
  77. data/lib/decidim/forms/version.rb +1 -1
  78. data/lib/decidim/forms.rb +0 -1
  79. metadata +18 -32
  80. data/app/packs/entrypoints/decidim_questionnaire_answers_pdf.js +0 -1
  81. data/app/packs/entrypoints/decidim_questionnaire_answers_pdf.scss +0 -1
  82. data/app/packs/stylesheets/decidim/forms/questionnaire-answers-pdf.scss +0 -69
  83. data/app/views/decidim/forms/admin/questionnaires/answers/export/_answer.html.erb +0 -31
  84. data/app/views/decidim/forms/admin/questionnaires/answers/export/pdf.html.erb +0 -13
  85. data/app/views/layouts/decidim/forms/admin/questionnaires/questionnaire_answers.html.erb +0 -12
  86. data/config/initializers/wicked_pdf.rb +0 -26
  87. data/lib/decidim/exporters/form_pdf_controller_helper.rb +0 -13
@@ -37,29 +37,26 @@ shared_examples_for "add questions" do
37
37
 
38
38
  it "adds a few questions and separators to the questionnaire" do
39
39
  fields_body = ["This is the first question", "This is the second question", "This is the first title and description"]
40
+ click_on "Add question"
41
+ click_on "Add separator"
42
+ click_on "Add title and description"
43
+ click_on "Add question"
40
44
 
41
- within "form.edit_questionnaire" do
42
- click_on "Add question"
43
- click_on "Add separator"
44
- click_on "Add title and description"
45
- click_on "Add question"
46
-
47
- expect(page).to have_css(".questionnaire-question", count: 4)
45
+ expect(page).to have_css(".questionnaire-question", count: 4)
48
46
 
49
- expand_all_questions
47
+ expand_all_questions
50
48
 
51
- page.all(".questionnaire-question .collapsible").each_with_index do |field, idx|
52
- within field do
53
- fill_in find_nested_form_field_locator("body_en"), with: fields_body[idx]
54
- end
49
+ page.all(".questionnaire-question .collapsible").each_with_index do |field, idx|
50
+ within field do
51
+ fill_in find_nested_form_field_locator("body_en"), with: fields_body[idx]
55
52
  end
56
-
57
- click_on "Save"
58
53
  end
59
54
 
55
+ click_on "Save"
56
+
60
57
  expect(page).to have_admin_callout("successfully")
61
58
 
62
- visit_questionnaire_edit_path_and_expand_all
59
+ visit_manage_questions_and_expand_all
63
60
 
64
61
  expect(page).to have_css("input[value='This is the first question']")
65
62
  expect(page).to have_css("input[value='This is the second question']")
@@ -68,59 +65,45 @@ shared_examples_for "add questions" do
68
65
  end
69
66
 
70
67
  it "adds a question with a rich text description" do
71
- within "form.edit_questionnaire" do
72
- click_on "Add question"
73
- expand_all_questions
74
-
75
- within ".questionnaire-question" do
76
- fill_in find_nested_form_field_locator("body_en"), with: "Body"
68
+ click_on "Add question"
69
+ expand_all_questions
77
70
 
78
- fill_in_editor find_nested_form_field_locator("description_en", visible: false), with: "<p>\n<strong>Superkalifragilistic description</strong>\n</p>"
79
- end
71
+ within ".questionnaire-question" do
72
+ fill_in find_nested_form_field_locator("body_en"), with: "Body"
80
73
 
81
- click_on "Save"
74
+ fill_in_editor find_nested_form_field_locator("description_en", visible: false), with: "<p>\n<strong>Superkalifragilistic description</strong>\n</p>"
82
75
  end
83
76
 
77
+ click_on "Save"
78
+
84
79
  expect(page).to have_admin_callout("successfully")
85
80
 
86
- component.update!(
87
- step_settings: {
88
- component.participatory_space.active_step.id => {
89
- allow_answers: true
90
- }
91
- }
92
- )
81
+ update_component_settings_or_attributes
93
82
 
94
83
  visit questionnaire_public_path
84
+ see_questionnaire_questions
95
85
 
96
86
  expect(page).to have_css("strong", text: "Superkalifragilistic description")
97
87
  end
98
88
 
99
89
  it "adds a title-and-description" do
100
- within "form.edit_questionnaire" do
101
- click_on "Add title and description"
102
- expand_all_questions
90
+ click_on "Add title and description"
91
+ expand_all_questions
103
92
 
104
- within ".questionnaire-question" do
105
- fill_in find_nested_form_field_locator("body_en"), with: "Body"
93
+ within ".questionnaire-question" do
94
+ fill_in find_nested_form_field_locator("body_en"), with: "Body"
106
95
 
107
- fill_in_editor find_nested_form_field_locator("description_en", visible: false), with: "<p>\n<strong>Superkalifragilistic description</strong>\n</p>"
108
- end
109
-
110
- click_on "Save"
96
+ fill_in_editor find_nested_form_field_locator("description_en", visible: false), with: "<p>\n<strong>Superkalifragilistic description</strong>\n</p>"
111
97
  end
112
98
 
99
+ click_on "Save"
100
+
113
101
  expect(page).to have_admin_callout("successfully")
114
102
 
115
- component.update!(
116
- step_settings: {
117
- component.participatory_space.active_step.id => {
118
- allow_answers: true
119
- }
120
- }
121
- )
103
+ update_component_settings_or_attributes
122
104
 
123
105
  visit questionnaire_public_path
106
+ see_questionnaire_questions
124
107
 
125
108
  expect(page).to have_css("strong", text: "Superkalifragilistic description")
126
109
  end
@@ -140,40 +123,38 @@ shared_examples_for "add questions" do
140
123
  ]
141
124
  ]
142
125
 
143
- within "form.edit_questionnaire" do
144
- click_on "Add question"
145
- click_on "Add question"
146
- expand_all_questions
126
+ click_on "Add question"
127
+ click_on "Add question"
128
+ expand_all_questions
147
129
 
148
- page.all(".questionnaire-question").each_with_index do |question, idx|
149
- within question do
150
- fill_in find_nested_form_field_locator("body_en"), with: question_body[idx]
151
- end
130
+ page.all(".questionnaire-question").each_with_index do |question, idx|
131
+ within question do
132
+ fill_in find_nested_form_field_locator("body_en"), with: question_body[idx]
152
133
  end
134
+ end
153
135
 
154
- expect(page).to have_no_content "Add answer option"
136
+ expect(page).to have_no_content "Add answer option"
155
137
 
156
- page.all(".questionnaire-question").each do |question|
157
- within question do
158
- select "Single option", from: "Type"
159
- click_on "Add answer option"
160
- end
138
+ page.all(".questionnaire-question").each do |question|
139
+ within question do
140
+ select "Single option", from: "Type"
141
+ click_on "Add answer option"
161
142
  end
143
+ end
162
144
 
163
- page.all(".questionnaire-question").each_with_index do |question, question_idx|
164
- question.all(".questionnaire-question-answer-option").each_with_index do |question_answer_option, answer_option_idx|
165
- within question_answer_option do
166
- fill_in find_nested_form_field_locator("body_en"), with: answer_options_body[question_idx][answer_option_idx]
167
- end
145
+ page.all(".questionnaire-question").each_with_index do |question, question_idx|
146
+ question.all(".questionnaire-question-answer-option").each_with_index do |question_answer_option, answer_option_idx|
147
+ within question_answer_option do
148
+ fill_in find_nested_form_field_locator("body_en"), with: answer_options_body[question_idx][answer_option_idx]
168
149
  end
169
150
  end
170
-
171
- click_on "Save"
172
151
  end
173
152
 
153
+ click_on "Save"
154
+
174
155
  expect(page).to have_admin_callout("successfully")
175
156
 
176
- visit_questionnaire_edit_path_and_expand_all
157
+ visit_manage_questions_and_expand_all
177
158
 
178
159
  expect(page).to have_css("input[value='This is the first question']")
179
160
  expect(page).to have_css("input[value='This is the Q1 first option']")
@@ -278,11 +259,12 @@ shared_examples_for "add questions" do
278
259
  click_on "Add question"
279
260
  expand_all_questions
280
261
 
262
+ expect(page).to have_text("Type")
281
263
  select "Long answer", from: "Type"
282
264
  click_on "Save"
283
265
 
284
266
  expand_all_questions
285
- expect(page).to have_select("Type", selected: "Long answer")
267
+ expect(page).to have_select("Type", selected: "Long answer", wait: 10)
286
268
  end
287
269
 
288
270
  it "does not preserve spurious answer options from previous type selections" do
@@ -300,6 +282,7 @@ shared_examples_for "add questions" do
300
282
  click_on "Save"
301
283
  expand_all_questions
302
284
 
285
+ expect(page).to have_text("Type")
303
286
  select "Single option", from: "Type"
304
287
 
305
288
  within ".questionnaire-question-answer-option:first-of-type" do
@@ -322,6 +305,7 @@ shared_examples_for "add questions" do
322
305
  click_on "Save"
323
306
  expand_all_questions
324
307
 
308
+ expect(page).to have_text("Type")
325
309
  select "Matrix (Single option)", from: "Type"
326
310
 
327
311
  within ".questionnaire-question-matrix-row:first-of-type" do
@@ -350,6 +334,7 @@ shared_examples_for "add questions" do
350
334
  click_on "Save"
351
335
  expand_all_questions
352
336
 
337
+ expect(page).to have_css(".questionnaire-question-answer-option")
353
338
  within ".questionnaire-question-answer-option:first-of-type" do
354
339
  expect(page).to have_nested_field("body_en", with: "Something")
355
340
  end
@@ -383,7 +368,6 @@ shared_examples_for "add questions" do
383
368
 
384
369
  it "allows switching translated field tabs after form failures" do
385
370
  click_on "Add question"
386
- click_on "Save"
387
371
 
388
372
  expand_all_questions
389
373
 
@@ -405,20 +389,16 @@ shared_examples_for "add questions" do
405
389
  let(:single_option_string) { "Single option" }
406
390
 
407
391
  before do
408
- visit questionnaire_edit_path
409
-
410
- within "form.edit_questionnaire" do
411
- click_on "Add question"
412
-
413
- expand_all_questions
392
+ click_on "Add question"
414
393
 
415
- within ".questionnaire-question" do
416
- fill_in find_nested_form_field_locator("body_en"), with: "This is the first question"
417
- end
394
+ expand_all_questions
418
395
 
419
- expect(page).to have_no_content "Add answer option"
420
- expect(page).to have_no_select("Maximum number of choices")
396
+ within ".questionnaire-question" do
397
+ fill_in find_nested_form_field_locator("body_en"), with: "This is the first question"
421
398
  end
399
+
400
+ expect(page).to have_no_content "Add answer option"
401
+ expect(page).to have_no_select("Maximum number of choices")
422
402
  end
423
403
 
424
404
  it "updates the free text option selector according to the selected question type" do
@@ -442,20 +422,16 @@ shared_examples_for "add questions" do
442
422
  let(:single_option_string) { "Matrix (Single option)" }
443
423
 
444
424
  before do
445
- visit questionnaire_edit_path
446
-
447
- within "form.edit_questionnaire" do
448
- click_on "Add question"
449
- expand_all_questions
450
-
451
- within ".questionnaire-question" do
452
- fill_in find_nested_form_field_locator("body_en"), with: "This is the first question"
453
- end
425
+ click_on "Add question"
426
+ expand_all_questions
454
427
 
455
- expect(page).to have_no_content "Add answer option"
456
- expect(page).to have_no_content "Add row"
457
- expect(page).to have_no_select("Maximum number of choices")
428
+ within ".questionnaire-question" do
429
+ fill_in find_nested_form_field_locator("body_en"), with: "This is the first question"
458
430
  end
431
+
432
+ expect(page).to have_no_content "Add answer option"
433
+ expect(page).to have_no_content "Add row"
434
+ expect(page).to have_no_select("Maximum number of choices")
459
435
  end
460
436
 
461
437
  it "updates the free text option selector according to the selected question type" do
@@ -19,7 +19,8 @@ shared_examples_for "update display conditions" do
19
19
  end
20
20
 
21
21
  before do
22
- visit_questionnaire_edit_path_and_expand_all
22
+ click_on "Save"
23
+ visit_manage_questions_and_expand_all
23
24
  end
24
25
 
25
26
  it "the related form appears" do
@@ -59,35 +60,31 @@ shared_examples_for "update display conditions" do
59
60
 
60
61
  click_on "Save"
61
62
 
62
- visit_questionnaire_edit_path_and_expand_all
63
+ visit_manage_questions_and_expand_all
63
64
 
64
65
  expect(page).to have_css(".questionnaire-question-display-condition", count: 0)
65
66
  end
66
67
 
67
68
  it "still removes the question even if previous editions rendered the conditions invalid" do
68
- within "form.edit_questionnaire" do
69
- expect(page).to have_css(".questionnaire-question", count: 2)
70
-
71
- within ".questionnaire-question-display-condition:first-of-type" do
72
- select condition_question.body["en"], from: "Question"
73
- select "Includes text", from: "Condition"
74
- fill_in find_nested_form_field_locator("condition_value_en"), with: ""
75
- end
69
+ expect(page).to have_css(".questionnaire-question", count: 2)
76
70
 
77
- within ".questionnaire-question:last-of-type" do
78
- click_on "Remove", match: :first
79
- end
71
+ within ".questionnaire-question-display-condition:first-of-type" do
72
+ select condition_question.body["en"], from: "Question"
73
+ select "Includes text", from: "Condition"
74
+ fill_in find_nested_form_field_locator("condition_value_en"), with: ""
75
+ end
80
76
 
81
- click_on "Save"
77
+ within ".questionnaire-question:last-of-type" do
78
+ click_on "Remove", match: :first
82
79
  end
83
80
 
81
+ click_on "Save"
82
+
84
83
  expect(page).to have_admin_callout("successfully")
85
84
 
86
- visit_questionnaire_edit_path_and_expand_all
85
+ visit_manage_questions_and_expand_all
87
86
 
88
- within "form.edit_questionnaire" do
89
- expect(page).to have_css(".questionnaire-question", count: 1)
90
- end
87
+ expect(page).to have_css(".questionnaire-question", count: 1)
91
88
  end
92
89
  end
93
90
  end