decidim-forms 0.29.1 → 0.30.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) 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 +2 -11
  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_option.rb +1 -1
  19. data/app/models/decidim/forms/question.rb +10 -0
  20. data/app/packs/entrypoints/decidim_forms.js +0 -1
  21. data/app/packs/entrypoints/decidim_forms_admin.js +6 -0
  22. data/app/packs/src/decidim/forms/admin/publish_answers_buttons.js +72 -0
  23. data/app/packs/src/decidim/forms/forms.js +22 -18
  24. data/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb +1 -1
  25. data/app/presenters/decidim/forms/admin_log/question_presenter.rb +31 -0
  26. data/app/queries/decidim/forms/questionnaire_user_answers.rb +1 -1
  27. data/app/views/decidim/forms/admin/questionnaires/_answer_option_template.html.erb +1 -1
  28. data/app/views/decidim/forms/admin/questionnaires/_display_condition_template.html.erb +1 -1
  29. data/app/views/decidim/forms/admin/questionnaires/_form.html.erb +0 -89
  30. data/app/views/decidim/forms/admin/questionnaires/_matrix_row_template.html.erb +1 -1
  31. data/app/views/decidim/forms/admin/questionnaires/_question.html.erb +3 -3
  32. data/app/views/decidim/forms/admin/questionnaires/_questions_form.html.erb +80 -0
  33. data/app/views/decidim/forms/admin/questionnaires/edit.html.erb +0 -20
  34. data/app/views/decidim/forms/admin/questionnaires/edit_questions.html.erb +47 -0
  35. data/app/views/decidim/forms/questionnaires/_answer.html.erb +11 -1
  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/ar.yml +3 -2
  43. data/config/locales/bg.yml +0 -7
  44. data/config/locales/bn-BD.yml +1 -0
  45. data/config/locales/bs-BA.yml +1 -0
  46. data/config/locales/ca.yml +46 -6
  47. data/config/locales/cs.yml +45 -5
  48. data/config/locales/de.yml +47 -7
  49. data/config/locales/el.yml +0 -7
  50. data/config/locales/en.yml +45 -5
  51. data/config/locales/es-MX.yml +45 -5
  52. data/config/locales/es-PY.yml +45 -5
  53. data/config/locales/es.yml +45 -5
  54. data/config/locales/eu.yml +50 -10
  55. data/config/locales/fi-plain.yml +45 -5
  56. data/config/locales/fi.yml +45 -5
  57. data/config/locales/fr-CA.yml +37 -5
  58. data/config/locales/fr.yml +37 -5
  59. data/config/locales/gl.yml +0 -3
  60. data/config/locales/hu.yml +0 -3
  61. data/config/locales/id-ID.yml +0 -2
  62. data/config/locales/it.yml +0 -4
  63. data/config/locales/ja.yml +1 -6
  64. data/config/locales/lb.yml +0 -4
  65. data/config/locales/lt.yml +0 -7
  66. data/config/locales/lv.yml +0 -3
  67. data/config/locales/nl.yml +0 -5
  68. data/config/locales/no.yml +0 -5
  69. data/config/locales/pl.yml +0 -7
  70. data/config/locales/pt-BR.yml +0 -5
  71. data/config/locales/pt.yml +0 -4
  72. data/config/locales/ro-RO.yml +8 -7
  73. data/config/locales/sk.yml +0 -2
  74. data/config/locales/sv.yml +0 -5
  75. data/config/locales/tr-TR.yml +0 -4
  76. data/config/locales/val-ES.yml +0 -2
  77. data/config/locales/zh-CN.yml +0 -4
  78. data/config/locales/zh-TW.yml +0 -7
  79. data/db/migrate/20190315203056_add_session_token_to_decidim_forms_answers.rb +1 -1
  80. data/db/migrate/20241122142230_add_survey_answers_published_at_to_questions.rb +7 -0
  81. data/decidim-forms.gemspec +2 -7
  82. data/lib/decidim/api/answer_option_type.rb +1 -1
  83. data/lib/decidim/api/question_type.rb +4 -4
  84. data/lib/decidim/api/questionnaire_type.rb +4 -4
  85. data/lib/decidim/exporters/form_pdf.rb +114 -11
  86. data/lib/decidim/forms/download_your_data_user_answers_serializer.rb +0 -4
  87. data/lib/decidim/forms/test/factories.rb +2 -2
  88. data/lib/decidim/forms/test/shared_examples/has_questionnaire.rb +70 -4
  89. data/lib/decidim/forms/test/shared_examples/manage_questionnaire_answers.rb +17 -17
  90. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_display_conditions.rb +19 -21
  91. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_questions.rb +70 -94
  92. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_display_conditions.rb +15 -18
  93. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_questions.rb +90 -125
  94. data/lib/decidim/forms/test/shared_examples/manage_questionnaires.rb +4 -25
  95. data/lib/decidim/forms/user_answers_serializer.rb +1 -1
  96. data/lib/decidim/forms/version.rb +1 -1
  97. data/lib/decidim/forms.rb +0 -1
  98. metadata +21 -47
  99. data/app/packs/entrypoints/decidim_questionnaire_answers_pdf.js +0 -1
  100. data/app/packs/entrypoints/decidim_questionnaire_answers_pdf.scss +0 -1
  101. data/app/packs/stylesheets/decidim/forms/questionnaire-answers-pdf.scss +0 -69
  102. data/app/views/decidim/forms/admin/questionnaires/answers/export/_answer.html.erb +0 -31
  103. data/app/views/decidim/forms/admin/questionnaires/answers/export/pdf.html.erb +0 -13
  104. data/app/views/layouts/decidim/forms/admin/questionnaires/questionnaire_answers.html.erb +0 -12
  105. data/config/initializers/wicked_pdf.rb +0 -27
  106. data/lib/decidim/exporters/form_pdf_controller_helper.rb +0 -13
@@ -22,13 +22,12 @@ ro:
22
22
  too_long: este prea lung
23
23
  choices:
24
24
  missing: nu sunt completate
25
- questionnaire:
26
- request_invalid: A apărut o eroare la procesarea cererii. Te rugăm să încerci din nou.
27
25
  decidim:
28
26
  forms:
29
27
  admin:
30
28
  models:
31
29
  components:
30
+ allow_editing_answers: Permiteți utilizatorilor înregistrați să modifice propriile răspunsuri la sondaj
32
31
  description: Descriere
33
32
  tos: Condiţii de utilizare
34
33
  questionnaires:
@@ -80,14 +79,10 @@ ro:
80
79
  title: Editare chestionar
81
80
  form:
82
81
  add_question: Adaugă întrebare
83
- add_separator: Adaugă separator
84
- add_title_and_description: Adaugați titlu și descriere
85
- already_answered_warning: Au fost înregistrare deja câteva răspunsuri de la utilizatori pentru acest chestionar. De aceea, nu mai puteți modifica întrebările.
86
82
  collapse: Restrânge toate întrebările
87
83
  expand: Extinde toate întrebările
88
84
  preview: Previzualizează
89
85
  title: Actualizați chestionarul pentru %{questionnaire_for}
90
- unpublished_warning: Chestionarul nu este publicat. Poți modifica întrebările, dar această acțiune va duce la stergerea automată a răspunsurilor curente.
91
86
  matrix_row:
92
87
  matrix_row: Rând
93
88
  remove: Elimină
@@ -165,6 +160,9 @@ ro:
165
160
  questionnaire_answered:
166
161
  body: Ai completat deja la acest chestionar.
167
162
  title: Un răspuns a fost deja trimis
163
+ questionnaire_answered_edit:
164
+ body: Ați răspuns deja la acest sondaj. %{link}
165
+ edit: Modificați răspunsurile
168
166
  questionnaire_closed:
169
167
  body: Chestionarul este închis și nu mai poate fi completat.
170
168
  title: Formular închis
@@ -179,9 +177,12 @@ ro:
179
177
  tos_agreement: Prin participare accepți Termenii și condițiile sale de utilizare
180
178
  step_navigation:
181
179
  show:
182
- are_you_sure: Această acțiune nu poate fi anulată și nu vei putea să îți editezi răspunsurile. Sigur dorești asta?
180
+ are_you_sure_edit: Veți putea să modificați răspunsurile. Sunteți sigur?
181
+ are_you_sure_edit_guest: Dacă doriți să modificați răspunsurile după ce veți răspunde, atunci trebuie să vă autentificați sau să creați un cont.
182
+ are_you_sure_no_edit: Această acțiune nu poate fi anulată și nu veți putea să vă modificați răspunsurile. Sunteți sigur?
183
183
  back: Înapoi
184
184
  continue: Continuă
185
+ disallowed: Nu aveți permisiunea să vă modificați răspunsurile.
185
186
  submit: Trimite
186
187
  user_answers_serializer:
187
188
  body: Răspuns
@@ -32,7 +32,6 @@ sk:
32
32
  save: Uložiť
33
33
  form:
34
34
  add_question: Pridať otázku
35
- already_answered_warning: Na formulár už niekto odpovedal, takže nemôžete meniť jeho otázky.
36
35
  matrix_row:
37
36
  remove: Odstrániť
38
37
  statement: Prehlásenie
@@ -74,7 +73,6 @@ sk:
74
73
  tos_agreement: Účasťou súhlasíte s našimi Podmienkami použitia
75
74
  step_navigation:
76
75
  show:
77
- are_you_sure: Táto akcia sa nedá vrátiť späť, a nebudete môcť upraviť svoje odpovede. Ste si istí?
78
76
  submit: Poslať
79
77
  user_answers_serializer:
80
78
  created_at: Odpovedané na
@@ -81,14 +81,10 @@ sv:
81
81
  title: Redigera enkät
82
82
  form:
83
83
  add_question: Lägg till fråga
84
- add_separator: Lägg till avgränsare
85
- add_title_and_description: Lägg till titel och beskrivning
86
- already_answered_warning: Frågeformuläret har redan besvarats av användare och du kan inte längre ändra frågorna.
87
84
  collapse: Dölj alla frågor
88
85
  expand: Visa alla frågor
89
86
  preview: Förhandsgranska
90
87
  title: Redigera formulär för %{questionnaire_for}
91
- unpublished_warning: Formuläret har inte publicerats. Du kan ändra frågorna, men det kommer att göra att befintliga svar raderas.
92
88
  matrix_row:
93
89
  matrix_row: Rad
94
90
  remove: Ta bort
@@ -181,7 +177,6 @@ sv:
181
177
  tos_agreement: Genom att delta godkänner du användarvillkoren
182
178
  step_navigation:
183
179
  show:
184
- are_you_sure: Den här åtgärden kan inte ångras och du kommer inte att kunna redigera dina svar. Är du säker?
185
180
  back: Tillbaka
186
181
  continue: Fortsätt
187
182
  submit: Skicka in
@@ -71,13 +71,10 @@ tr:
71
71
  title: Anketi düzenleyin
72
72
  form:
73
73
  add_question: Soru ekle
74
- add_separator: Ayırıcı ekle
75
- already_answered_warning: Form, bazı kullanıcılar tarafından zaten yanıtlandı, bu nedenle sorularını değiştiremezsiniz.
76
74
  collapse: Tüm soruları daraltın
77
75
  expand: Tüm soruları genişletin
78
76
  preview: Önizleme
79
77
  title: '%{questionnaire_for} için formu düzenleyin'
80
- unpublished_warning: Form yayınlanmadı. Sorularını değiştirebilirsiniz, ancak bunu yapmak mevcut cevapları silecektir.
81
78
  matrix_row:
82
79
  matrix_row: Satır
83
80
  remove: Kaldır
@@ -144,7 +141,6 @@ tr:
144
141
  tos_agreement: Katılarak Hizmet Şartlarını kabul etmiş olursunuz.
145
142
  step_navigation:
146
143
  show:
147
- are_you_sure: Bu işlem geri alınamaz ve cevaplarınızı düzenleyemezsiniz. Emin misiniz?
148
144
  back: Geri
149
145
  continue: Devam et
150
146
  submit: Gönder
@@ -4,8 +4,6 @@ val:
4
4
  forms:
5
5
  admin:
6
6
  questionnaires:
7
- form:
8
- add_title_and_description: Afig títol i descripció
9
7
  title_and_description:
10
8
  collapse: Redueix
11
9
  description: Descripció
@@ -71,12 +71,9 @@ zh-CN:
71
71
  title: 编辑问题单
72
72
  form:
73
73
  add_question: 添加问题
74
- add_separator: 添加分隔符
75
- already_answered_warning: 某些用户已经回答了表单,因此您不能修改其问题。
76
74
  collapse: 收起所有问题
77
75
  expand: 展开所有问题
78
76
  preview: 预览
79
- unpublished_warning: 表单未发布。您可以修改它的问题,但这样做将删除当前答案。
80
77
  matrix_row:
81
78
  matrix_row: 行
82
79
  remove: 删除
@@ -142,7 +139,6 @@ zh-CN:
142
139
  tos_agreement: 通过参与您接受其服务条款
143
140
  step_navigation:
144
141
  show:
145
- are_you_sure: 此操作不能撤消,您将无法编辑您的答案。您确定吗?
146
142
  back: 后退
147
143
  continue: 继续
148
144
  submit: 提交
@@ -22,8 +22,6 @@ zh-TW:
22
22
  too_long: 太長
23
23
  choices:
24
24
  missing: 尚未完成
25
- questionnaire:
26
- request_invalid: 處理請求時發生錯誤。請再試一次。
27
25
  decidim:
28
26
  forms:
29
27
  admin:
@@ -80,14 +78,10 @@ zh-TW:
80
78
  title: 編輯問卷內容
81
79
  form:
82
80
  add_question: 新增問題
83
- add_separator: 新增分隔線
84
- add_title_and_description: 新增標題與描述
85
- already_answered_warning: 已有使用者回答此表單,因此您無法修改問題。
86
81
  collapse: 收起所有問題
87
82
  expand: 展開所有問題
88
83
  preview: 預覽
89
84
  title: 編輯問卷表單%{questionnaire_for}
90
- unpublished_warning: 此表單尚未發佈。您可以修改其問題,但這樣做將刪除目前的回答。
91
85
  matrix_row:
92
86
  matrix_row: 列
93
87
  remove: 移除
@@ -178,7 +172,6 @@ zh-TW:
178
172
  tos_agreement: 透過參與,您同意其服務條款
179
173
  step_navigation:
180
174
  show:
181
- are_you_sure: 此操作無法撤消,您將無法編輯您的答案。您確定嗎?
182
175
  back: 返回
183
176
  continue: 繼續
184
177
  submit: 提交
@@ -10,7 +10,7 @@ class AddSessionTokenToDecidimFormsAnswers < ActiveRecord::Migration[5.2]
10
10
  add_index :decidim_forms_answers, :session_token
11
11
 
12
12
  Answer.find_each do |answer|
13
- answer.session_token = Digest::MD5.hexdigest("#{answer.decidim_user_id}-#{Rails.application.secrets.secret_key_base}")
13
+ answer.session_token = Digest::MD5.hexdigest("#{answer.decidim_user_id}-#{Rails.application.secret_key_base}")
14
14
  answer.save!
15
15
  end
16
16
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddSurveyAnswersPublishedAtToQuestions < ActiveRecord::Migration[7.0]
4
+ def change
5
+ add_column :decidim_forms_questions, :survey_answers_published_at, :datetime, index: true
6
+ end
7
+ end
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.version = Decidim::Forms.version
11
11
  s.authors = ["Josep Jaume Rey Peroy", "Marc Riera Casals", "Oriol Gual Oliva", "Rubén González Valero"]
12
12
  s.email = ["josepjaume@gmail.com", "mrc2407@gmail.com", "oriolgual@gmail.com", "rbngzlv@gmail.com"]
13
- s.license = "AGPL-3.0"
13
+ s.license = "AGPL-3.0-or-later"
14
14
  s.homepage = "https://decidim.org"
15
15
  s.metadata = {
16
16
  "bug_tracker_uri" => "https://github.com/decidim/decidim/issues",
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  "homepage_uri" => "https://decidim.org",
20
20
  "source_code_uri" => "https://github.com/decidim/decidim"
21
21
  }
22
- s.required_ruby_version = "~> 3.2.0"
22
+ s.required_ruby_version = "~> 3.3.0"
23
23
 
24
24
  s.name = "decidim-forms"
25
25
  s.summary = "Decidim forms"
@@ -33,11 +33,6 @@ Gem::Specification.new do |s|
33
33
  end
34
34
 
35
35
  s.add_dependency "decidim-core", Decidim::Forms.version
36
- s.add_dependency "wicked_pdf", "~> 2.1"
37
- # Latest version of wkhtmltopdf-binary downloads more versions of the binary
38
- # This brings problems with deployment in certain environments, as Heroku
39
- # Hopefully they will fix this situation soon
40
- s.add_dependency "wkhtmltopdf-binary", "= 0.12.6.6"
41
36
 
42
37
  s.add_development_dependency "decidim-admin", Decidim::Forms.version
43
38
  s.add_development_dependency "decidim-dev", Decidim::Forms.version
@@ -5,9 +5,9 @@ module Decidim
5
5
  class AnswerOptionType < Decidim::Api::Types::BaseObject
6
6
  description "An answer option for a multi-choice question in a questionnaire"
7
7
 
8
- field :id, GraphQL::Types::ID, "ID of this answer option", null: false
9
8
  field :body, Decidim::Core::TranslatedFieldType, "The text answer response option.", null: false
10
9
  field :free_text, GraphQL::Types::Boolean, "Whether if this answer accepts any free text from the user.", null: false
10
+ field :id, GraphQL::Types::ID, "ID of this answer option", null: false
11
11
  end
12
12
  end
13
13
  end
@@ -7,15 +7,15 @@ module Decidim
7
7
 
8
8
  implements Decidim::Core::TimestampsInterface
9
9
 
10
- field :id, GraphQL::Types::ID, "ID of this question", null: false
10
+ field :answer_options, [AnswerOptionType, { null: true }], "List of answer options in multi-choice questions.", null: false
11
11
  field :body, Decidim::Core::TranslatedFieldType, "What is being asked in this question.", null: false
12
12
  field :description, Decidim::Core::TranslatedFieldType, "The description of this question.", null: true
13
+ field :id, GraphQL::Types::ID, "ID of this question", null: false
13
14
  field :mandatory, GraphQL::Types::Boolean, "Whether if this question is mandatory.", null: false
14
- field :position, GraphQL::Types::Int, "Order position of the question in the questionnaire", null: true
15
- field :max_choices, GraphQL::Types::Int, "On questions with answer options, maximum number of choices the user has", null: true
16
15
  field :max_characters, GraphQL::Types::Int, "On questions with free text answers, maximum number of characters the answer can have (0 if no limit)", null: false
16
+ field :max_choices, GraphQL::Types::Int, "On questions with answer options, maximum number of choices the user has", null: true
17
+ field :position, GraphQL::Types::Int, "Order position of the question in the questionnaire", null: true
17
18
  field :question_type, GraphQL::Types::String, "Type of question.", null: true
18
- field :answer_options, [AnswerOptionType, { null: true }], "List of answer options in multi-choice questions.", null: false
19
19
  end
20
20
  end
21
21
  end
@@ -7,13 +7,13 @@ module Decidim
7
7
 
8
8
  implements Decidim::Core::TimestampsInterface
9
9
 
10
- field :id, GraphQL::Types::ID, "ID of this questionnaire", null: false
11
- field :title, Decidim::Core::TranslatedFieldType, "The title of this questionnaire.", null: false
12
10
  field :description, Decidim::Core::TranslatedFieldType, "The description of this questionnaire.", null: true
13
- field :tos, Decidim::Core::TranslatedFieldType, "The Terms of Service for this questionnaire.", null: true
14
- field :for_type, GraphQL::Types::String, "Type of entity using this questionnaire.", method: :questionnaire_for_type, null: true
15
11
  field :for_entity, QuestionnaireEntityInterface, "Entity using this questionnaire.", method: :questionnaire_for, null: true
12
+ field :for_type, GraphQL::Types::String, "Type of entity using this questionnaire.", method: :questionnaire_for_type, null: true
13
+ field :id, GraphQL::Types::ID, "ID of this questionnaire", null: false
16
14
  field :questions, [Decidim::Forms::QuestionType, { null: true }], "Questions in this questionnaire.", null: false
15
+ field :title, Decidim::Core::TranslatedFieldType, "The title of this questionnaire.", null: false
16
+ field :tos, Decidim::Core::TranslatedFieldType, "The Terms of Service for this questionnaire.", null: true
17
17
  end
18
18
  end
19
19
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "wicked_pdf"
4
-
5
3
  module Decidim
6
4
  module Exporters
7
5
  # Inherits from abstract PDF exporter. This class is used to set
@@ -9,25 +7,130 @@ module Decidim
9
7
  #
10
8
  class FormPDF < PDF
11
9
  # i18n-tasks-use t('decidim.admin.exports.formats.FormPDF')
10
+ include ActionView::Helpers::NumberHelper
11
+ include Decidim::Forms::Admin::QuestionnaireAnswersHelper
12
+
13
+ class QuestionnaireAnswerPresenter < Decidim::Forms::Admin::QuestionnaireAnswerPresenter
14
+ def choice(choice_hash)
15
+ render_body_for choice_hash
16
+ end
17
+
18
+ delegate :attachments, to: :answer
19
+
20
+ def body
21
+ return { string: answer.body } if answer.body.present?
22
+ return { attachments: answer.attachments } if answer.attachments.any?
23
+ return { string: "-" } if answer.choices.empty?
24
+
25
+ choices = answer.choices.map do |choice|
26
+ {
27
+ answer_option_body: choice.try(:answer_option).try(:translated_body),
28
+ choice_body: body_or_custom_body(choice)
29
+ }
30
+ end
31
+
32
+ return { single_option: choice(choices.first) } if answer.question.question_type == "single_option"
12
33
 
13
- def controller
14
- @controller ||= FormPDFControllerHelper.new
34
+ { multiple_option: choices.map { |c| choice(c) } }
35
+ end
15
36
  end
16
37
 
17
- def template
18
- "decidim/forms/admin/questionnaires/answers/export/pdf"
38
+ class ParticipantPresenter < Decidim::Forms::Admin::QuestionnaireParticipantPresenter
39
+ def answers
40
+ siblings.map { |answer| QuestionnaireAnswerPresenter.new(answer:) }
41
+ end
19
42
  end
20
43
 
21
- def layout
22
- "decidim/forms/admin/questionnaires/questionnaire_answers"
44
+ protected
45
+
46
+ def add_data!
47
+ composer.text(decidim_sanitize(translated_attribute(questionnaire.title), strip_tags: true), style: :h1)
48
+ composer.text(decidim_sanitize(translated_attribute(questionnaire.description), strip_tags: true), style: :description)
49
+ composer.text(I18n.t("title", scope: "decidim.forms.admin.questionnaires.answers.index", total: collection.count), style: :section_title)
50
+
51
+ local_collection = collection.map { |answer| ParticipantPresenter.new(participant: answer.first) }
52
+
53
+ local_collection.each_with_index do |record, index|
54
+ add_response_box(record, index)
55
+ end
23
56
  end
24
57
 
25
- def locals
58
+ def questionnaire = collection.first.first.questionnaire
59
+
60
+ def styles
26
61
  {
27
- questionnaire: collection.first.first.questionnaire,
28
- collection: collection.map { |answer| Decidim::Forms::Admin::QuestionnaireParticipantPresenter.new(participant: answer.first) }
62
+ h1: { font: bold_font, font_size: 18, margin: [0, 0, 10, 0] },
63
+ th: { font: bold_font, font_size: 10, margin: [0, 0, 10, 0] },
64
+ td: { font:, font_size: 10, margin: [0, 0, 10, 0] },
65
+ description: { font:, margin: [0, 0, 10, 0], font_size: 10 },
66
+ section_title: { font: bold_font, margin: [15, 0, 15, 0], font_size: 16 },
67
+ question_title: { font: bold_font, margin: [10, 0, 10, 0], font_size: 12 },
68
+ question_answer: { font:, margin: [10, 0, 10, 0], font_size: 10 },
69
+ file_info: { font:, margin: [10, 0, 10, 0], font_size: 8 },
70
+ link: { font:, margin: [10, 0, 10, 0], font_size: 10, underline: true }
29
71
  }
30
72
  end
73
+
74
+ def header
75
+ [
76
+ layout.text(I18n.t("session_token", scope: "decidim.forms.user_answers_serializer"), style: :th),
77
+ layout.text(I18n.t("user_status", scope: "decidim.forms.user_answers_serializer"), style: :th),
78
+ layout.text(I18n.t("ip_hash", scope: "decidim.forms.user_answers_serializer"), style: :th),
79
+ layout.text(I18n.t("completion", scope: "decidim.forms.user_answers_serializer"), style: :th),
80
+ layout.text(I18n.t("created_at", scope: "decidim.forms.user_answers_serializer"), style: :th)
81
+ ]
82
+ end
83
+
84
+ def add_user_data(record)
85
+ cells = [
86
+ layout.text(record.session_token, style: :td),
87
+ layout.text(record.status, style: :td),
88
+ layout.text(record.ip_hash, style: :td),
89
+ layout.text(display_percentage(record.completion), style: :td),
90
+ layout.text(I18n.l(record.answered_at, format: :short), style: :td)
91
+ ]
92
+ composer.table([cells], header: ->(_table) { [header] }, cell_style: { border: { width: 0 } })
93
+ end
94
+
95
+ def add_response_box(record, index)
96
+ composer.text(I18n.t("title", number: index + 1, scope: "decidim.forms.admin.questionnaires.answers.export.answer"), style: :section_title)
97
+ add_user_data(record)
98
+
99
+ record.answers.each do |answer|
100
+ composer.text(answer.question, style: :question_title)
101
+ add_answer_body(answer)
102
+ end
103
+ end
104
+
105
+ def add_answer_body(answer)
106
+ return composer.text(answer.body[:string], style: :question_answer) if answer.body.has_key?(:string)
107
+
108
+ if answer.attachments.any?
109
+ composer.list(marker_type: :disc) do |sub_list|
110
+ answer.attachments.each do |attachment|
111
+ sub_list.formatted_text(
112
+ [{ link: attachment.url,
113
+ text: translated_attribute(attachment.title).presence ||
114
+ I18n.t("download_attachment", scope: "decidim.forms.questionnaire_answer_presenter"),
115
+ style: :link },
116
+ " (#{attachment.file_type} #{number_to_human_size(attachment.file_size)})"],
117
+ style: :file_info
118
+ )
119
+ end
120
+ end
121
+ return
122
+ end
123
+
124
+ if answer.body.has_key?(:single_option)
125
+ composer.list(marker_type: :disc) do |sub_list|
126
+ sub_list.text(answer.body[:single_option], style: :question_answer)
127
+ end
128
+ else
129
+ composer.list(marker_type: :disc) do |sub_list|
130
+ answer.body[:multiple_option].map { |choice| sub_list.text(choice, style: :question_answer) }
131
+ end
132
+ end
133
+ end
31
134
  end
32
135
  end
33
136
  end
@@ -8,10 +8,6 @@ module Decidim
8
8
  def serialize
9
9
  {
10
10
  id: resource.id,
11
- user: {
12
- name: resource.user.name,
13
- email: resource.user.email
14
- },
15
11
  questionnaire: {
16
12
  id: resource.question.questionnaire.id,
17
13
  title: translated_attribute(resource.question.questionnaire.title),
@@ -149,8 +149,8 @@ FactoryBot.define do
149
149
 
150
150
  trait :with_attachments do
151
151
  after(:create) do |answer, evaluator|
152
- create :attachment, :with_image, attached_to: answer, skip_injection: evaluator.skip_injection
153
- create :attachment, :with_pdf, attached_to: answer, skip_injection: evaluator.skip_injection
152
+ create(:attachment, :with_image, attached_to: answer, skip_injection: evaluator.skip_injection)
153
+ create(:attachment, :with_pdf, attached_to: answer, skip_injection: evaluator.skip_injection)
154
154
  end
155
155
  end
156
156
  end