decidim-surveys 0.19.1 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/decidim/surveys/surveys.scss +20 -3
  3. data/app/controllers/decidim/surveys/admin/surveys_controller.rb +11 -0
  4. data/app/controllers/decidim/surveys/surveys_controller.rb +12 -1
  5. data/app/jobs/decidim/surveys/clean_survey_answers_job.rb +32 -0
  6. data/app/jobs/decidim/surveys/settings_change_job.rb +4 -0
  7. data/app/models/decidim/surveys/survey.rb +4 -0
  8. data/app/permissions/decidim/surveys/admin/permissions.rb +12 -6
  9. data/app/permissions/decidim/surveys/permissions.rb +1 -1
  10. data/app/queries/decidim/surveys/metrics/answers_metric_manage.rb +2 -8
  11. data/app/serializers/decidim/surveys/data_importer.rb +66 -0
  12. data/app/serializers/decidim/surveys/data_serializer.rb +46 -0
  13. data/app/types/decidim/surveys/survey_type.rb +15 -0
  14. data/app/types/decidim/surveys/surveys_type.rb +32 -0
  15. data/config/locales/am-ET.yml +1 -0
  16. data/config/locales/ar.yml +1 -0
  17. data/config/locales/bg-BG.yml +10 -0
  18. data/config/locales/bg.yml +10 -0
  19. data/config/locales/ca.yml +6 -0
  20. data/config/locales/cs.yml +6 -0
  21. data/config/locales/da-DK.yml +1 -0
  22. data/config/locales/da.yml +1 -0
  23. data/config/locales/de.yml +6 -0
  24. data/config/locales/el-GR.yml +1 -0
  25. data/config/locales/el.yml +59 -0
  26. data/config/locales/en.yml +6 -0
  27. data/config/locales/eo.yml +1 -0
  28. data/config/locales/es-MX.yml +6 -0
  29. data/config/locales/es-PY.yml +6 -0
  30. data/config/locales/es.yml +6 -0
  31. data/config/locales/et-EE.yml +1 -0
  32. data/config/locales/et.yml +1 -0
  33. data/config/locales/fi-plain.yml +6 -0
  34. data/config/locales/fi.yml +7 -1
  35. data/config/locales/fr-CA.yml +62 -0
  36. data/config/locales/fr.yml +6 -0
  37. data/config/locales/ga-IE.yml +1 -0
  38. data/config/locales/hr-HR.yml +1 -0
  39. data/config/locales/hr.yml +1 -0
  40. data/config/locales/hu.yml +3 -0
  41. data/config/locales/is-IS.yml +25 -0
  42. data/config/locales/is.yml +25 -0
  43. data/config/locales/it.yml +11 -7
  44. data/config/locales/ja-JP.yml +58 -0
  45. data/config/locales/ja.yml +60 -0
  46. data/config/locales/ko-KR.yml +1 -0
  47. data/config/locales/ko.yml +1 -0
  48. data/config/locales/lt-LT.yml +1 -0
  49. data/config/locales/lt.yml +1 -0
  50. data/config/locales/lv.yml +61 -0
  51. data/config/locales/mt-MT.yml +1 -0
  52. data/config/locales/mt.yml +1 -0
  53. data/config/locales/nl.yml +10 -4
  54. data/config/locales/no.yml +25 -0
  55. data/config/locales/om-ET.yml +1 -0
  56. data/config/locales/pl.yml +18 -12
  57. data/config/locales/pt-BR.yml +1 -1
  58. data/config/locales/pt.yml +27 -23
  59. data/config/locales/ro-RO.yml +62 -0
  60. data/config/locales/sk-SK.yml +63 -0
  61. data/config/locales/sk.yml +63 -0
  62. data/config/locales/sl.yml +8 -0
  63. data/config/locales/so-SO.yml +1 -0
  64. data/config/locales/sr-CS.yml +1 -0
  65. data/config/locales/sv.yml +5 -1
  66. data/config/locales/ti-ER.yml +1 -0
  67. data/config/locales/vi-VN.yml +1 -0
  68. data/config/locales/vi.yml +1 -0
  69. data/config/locales/zh-CN.yml +60 -0
  70. data/config/locales/zh-TW.yml +1 -0
  71. data/db/migrate/20200609090533_check_legacy_tables.rb +114 -0
  72. data/db/migrate/20200610090533_remove_survey_answer_choices.rb +7 -0
  73. data/db/migrate/20200610090650_remove_survey_answer_options.rb +7 -0
  74. data/db/migrate/20200610090725_remove_survey_answers.rb +7 -0
  75. data/db/migrate/20200610090845_remove_survey_questions.rb +7 -0
  76. data/db/migrate/20200610105927_remove_survey_columns.rb +10 -0
  77. data/lib/decidim/surveys/admin_engine.rb +10 -0
  78. data/lib/decidim/surveys/component.rb +38 -6
  79. data/lib/decidim/surveys/test/factories.rb +1 -1
  80. data/lib/decidim/surveys/version.rb +1 -1
  81. metadata +75 -13
@@ -0,0 +1,63 @@
1
+ sk:
2
+ activemodel:
3
+ models:
4
+ decidim/surveys/closed_survey_event: Prieskum ukončený
5
+ decidim/surveys/opened_survey_event: Prieskum začal
6
+ activerecord:
7
+ models:
8
+ decidim/surveys/survey:
9
+ one: Prieskum
10
+ few: Prieskumy
11
+ many: Prieskumy
12
+ other: Prieskumy
13
+ decidim/surveys/survey_answer:
14
+ one: Odpoveď
15
+ few: Odpovede
16
+ many: Odpovede
17
+ other: Odpovede
18
+ decidim:
19
+ components:
20
+ surveys:
21
+ actions:
22
+ answer: Odpovedať
23
+ name: Prieskum
24
+ settings:
25
+ global:
26
+ announcement: Oznámenie
27
+ step:
28
+ allow_answers: Povoliť odpovede
29
+ allow_unregistered: Povoliť neregistrovaným užívateľom odpovedať na prieskum
30
+ allow_unregistered_help: Ak aktívne, pre hlasovanie v prieskume nebude potrebná registrácia na platforme. To môže viesť ku nespoľahlivým výsledkom a vyššej zraniteľnosti voči automatizovaným útokom. Opatrne!
31
+ announcement: Oznámenie
32
+ events:
33
+ surveys:
34
+ survey_closed:
35
+ email_intro: Prieskum %{resource_title} v %{participatory_space_title} bol uzatvorený.
36
+ email_outro: Túto notifikáciu ste dostali, pretože sledujete %{participatory_space_title}. Notifikácie môžete zrušiť po kliknutí na predchádzajúci odkaz.
37
+ email_subject: Prieskum bol ukončený v %{participatory_space_title}
38
+ notification_title: Prieskum <a href="%{resource_path}">%{resource_title}</a> v <a href="%{participatory_space_url}">%{participatory_space_title}</a> bol ukončený.
39
+ survey_opened:
40
+ email_intro: 'Prieskum %{resource_title} v %{participatory_space_title} bol práve otvorený. Môžete sa na ňom podieľať na tejto stránke:'
41
+ email_outro: Túto notifikáciu ste dostali, pretože sledujete %{participatory_space_title}. Notifikácie môžete zrušiť po kliknutí na predchádzajúci odkaz.
42
+ email_subject: Nový prieskum v %{participatory_space_title}
43
+ notification_title: Prieskum <a href="%{resource_path}">%{resource_title}</a> v <a href="%{participatory_space_url}">%{participatory_space_title}</a> bol práve otvorený.
44
+ metrics:
45
+ survey_answers:
46
+ description: Počet prieskumov, na ktoré odpovedali účastníci
47
+ object: odpovede na prieskumy
48
+ title: Odpovede na prieskumy
49
+ surveys:
50
+ admin:
51
+ exports:
52
+ survey_user_answers: Odpovede účastníkov prieskumu
53
+ surveys:
54
+ update:
55
+ invalid: Vyskytol sa problém s ukladaním prieskumu.
56
+ success: Prieskum úspešne uložený.
57
+ last_activity:
58
+ new_survey_at_html: "<span>Nový prieskum na %{link}</span>"
59
+ surveys:
60
+ answer:
61
+ invalid: Vyskytol sa problém s odpovedaním na prieskum.
62
+ spam_detected: Vyskytol sa problém s odpovedaním na formulár. Možno ste boli príliš rýchli, skúste prosíme znovu.
63
+ success: Odpoveď úspešne zaznamenaná.
@@ -0,0 +1,63 @@
1
+ sk:
2
+ activemodel:
3
+ models:
4
+ decidim/surveys/closed_survey_event: Prieskum ukončený
5
+ decidim/surveys/opened_survey_event: Prieskum začal
6
+ activerecord:
7
+ models:
8
+ decidim/surveys/survey:
9
+ one: Prieskum
10
+ few: Prieskumy
11
+ many: Prieskumy
12
+ other: Prieskumy
13
+ decidim/surveys/survey_answer:
14
+ one: Odpoveď
15
+ few: Odpovede
16
+ many: Odpovede
17
+ other: Odpovede
18
+ decidim:
19
+ components:
20
+ surveys:
21
+ actions:
22
+ answer: Odpovedať
23
+ name: Prieskum
24
+ settings:
25
+ global:
26
+ announcement: Oznámenie
27
+ step:
28
+ allow_answers: Povoliť odpovede
29
+ allow_unregistered: Povoliť neregistrovaným užívateľom odpovedať na prieskum
30
+ allow_unregistered_help: Ak aktívne, pre hlasovanie v prieskume nebude potrebná registrácia na platforme. To môže viesť ku nespoľahlivým výsledkom a vyššej zraniteľnosti voči automatizovaným útokom. Opatrne!
31
+ announcement: Oznámenie
32
+ events:
33
+ surveys:
34
+ survey_closed:
35
+ email_intro: Prieskum %{resource_title} v %{participatory_space_title} bol uzatvorený.
36
+ email_outro: Túto notifikáciu ste dostali, pretože sledujete %{participatory_space_title}. Notifikácie môžete zrušiť po kliknutí na predchádzajúci odkaz.
37
+ email_subject: Prieskum bol ukončený v %{participatory_space_title}
38
+ notification_title: Prieskum <a href="%{resource_path}">%{resource_title}</a> v <a href="%{participatory_space_url}">%{participatory_space_title}</a> bol ukončený.
39
+ survey_opened:
40
+ email_intro: 'Prieskum %{resource_title} v %{participatory_space_title} bol práve otvorený. Môžete sa na ňom podieľať na tejto stránke:'
41
+ email_outro: Túto notifikáciu ste dostali, pretože sledujete %{participatory_space_title}. Notifikácie môžete zrušiť po kliknutí na predchádzajúci odkaz.
42
+ email_subject: Nový prieskum v %{participatory_space_title}
43
+ notification_title: Prieskum <a href="%{resource_path}">%{resource_title}</a> v <a href="%{participatory_space_url}">%{participatory_space_title}</a> bol práve otvorený.
44
+ metrics:
45
+ survey_answers:
46
+ description: Počet prieskumov, na ktoré odpovedali účastníci
47
+ object: odpovede na prieskumy
48
+ title: Odpovede na prieskumy
49
+ surveys:
50
+ admin:
51
+ exports:
52
+ survey_user_answers: Odpovede účastníkov prieskumu
53
+ surveys:
54
+ update:
55
+ invalid: Vyskytol sa problém s ukladaním prieskumu.
56
+ success: Prieskum úspešne uložený.
57
+ last_activity:
58
+ new_survey_at_html: "<span>Nový prieskum na %{link}</span>"
59
+ surveys:
60
+ answer:
61
+ invalid: Vyskytol sa problém s odpovedaním na prieskum.
62
+ spam_detected: Vyskytol sa problém s odpovedaním na formulár. Možno ste boli príliš rýchli, skúste prosíme znovu.
63
+ success: Odpoveď úspešne zaznamenaná.
@@ -0,0 +1,8 @@
1
+ sl:
2
+ activerecord:
3
+ models:
4
+ decidim/surveys/survey_answer:
5
+ one: Odgovor
6
+ two: Odgovora
7
+ few: Odgovorov
8
+ other: Odgovorov
@@ -0,0 +1 @@
1
+ so:
@@ -0,0 +1 @@
1
+ sr:
@@ -15,13 +15,16 @@ sv:
15
15
  components:
16
16
  surveys:
17
17
  actions:
18
- answer: Svara
18
+ answer: Svar
19
19
  name: Enkät
20
20
  settings:
21
21
  global:
22
22
  announcement: Meddelande
23
+ clean_after_publish: Ta bort svar vid publicering av enkäten
23
24
  step:
24
25
  allow_answers: Tillåt svar
26
+ allow_unregistered: Tillåt ej registrerade användare att besvara enkäten
27
+ allow_unregistered_help: Om valt krävs det ingen inloggning för att besvara enkäten. Detta kan leda till dåliga eller opålitliga data och det kommer att vara mer sårbart för automatiserade attacker. Använd med försiktighet!
25
28
  announcement: Meddelande
26
29
  events:
27
30
  surveys:
@@ -53,4 +56,5 @@ sv:
53
56
  surveys:
54
57
  answer:
55
58
  invalid: Det gick inte att besvara enkäten.
59
+ spam_detected: Det gick inte att svara på formuläret. Du hade kanske för bråttom, kan du försöka igen?
56
60
  success: Enkäten har besvarats.
@@ -0,0 +1 @@
1
+ ti:
@@ -0,0 +1 @@
1
+ vi:
@@ -0,0 +1 @@
1
+ vi:
@@ -0,0 +1,60 @@
1
+ zh-CN:
2
+ activemodel:
3
+ models:
4
+ decidim/surveys/closed_survey_event: 调查结束
5
+ decidim/surveys/opened_survey_event: 调查已开始
6
+ activerecord:
7
+ models:
8
+ decidim/surveys/survey:
9
+ other: 调查
10
+ decidim/surveys/survey_answer:
11
+ other: 答案
12
+ decidim:
13
+ components:
14
+ surveys:
15
+ actions:
16
+ answer: 答案
17
+ name: 调查
18
+ settings:
19
+ global:
20
+ announcement: 通 知
21
+ clean_after_publish: 在发布调查时删除答案
22
+ scope_id: 范围
23
+ scopes_enabled: 范围已启用
24
+ step:
25
+ allow_answers: 允许答案
26
+ allow_unregistered: 允许未注册用户回答调查
27
+ allow_unregistered_help: 如果激活,将不需要登录才能回答调查。 这可能导致数据不准确或不可靠,更容易受到自动攻击。请谨慎使用!
28
+ announcement: 通 知
29
+ events:
30
+ surveys:
31
+ survey_closed:
32
+ email_intro: '%{resource_title} 在 %{participatory_space_title} 中的调查已被关闭。'
33
+ email_outro: 您收到此通知是因为您正在关注 %{participatory_space_title}。您可以停止收到跟随上一个链接的通知。
34
+ email_subject: 调查已在 %{participatory_space_title} 完成
35
+ notification_title: 调查 <a href="%{resource_path}">%{resource_title}</a> 在 <a href="%{participatory_space_url}">%{participatory_space_title}</a> 已完成。
36
+ survey_opened:
37
+ email_intro: '调查 %{resource_title} %{participatory_space_title} 现已打开。您可以从这个页面参与:'
38
+ email_outro: 您收到此通知是因为您正在关注 %{participatory_space_title}。您可以停止收到跟随上一个链接的通知。
39
+ email_subject: '%{participatory_space_title} 的新调查'
40
+ notification_title: <a href="%{resource_path}">%{resource_title}</a> 在 <a href="%{participatory_space_url}">%{participatory_space_title}</a> 中的调查现已打开。
41
+ metrics:
42
+ survey_answers:
43
+ description: 参与者回答的调查次数
44
+ object: 调查答案
45
+ title: 对调查的答复
46
+ surveys:
47
+ admin:
48
+ exports:
49
+ survey_user_answers: 调查参与者答案
50
+ surveys:
51
+ update:
52
+ invalid: 保存调查时出现问题。
53
+ success: 调查保存成功。
54
+ last_activity:
55
+ new_survey_at_html: "<span>在 %{link}上的新调查</span>"
56
+ surveys:
57
+ answer:
58
+ invalid: 回答调查时出现问题。
59
+ spam_detected: 回答表单时出现问题。可能你太快了,你可以再试一次吗?
60
+ success: 调查回答成功。
@@ -0,0 +1 @@
1
+ zh-TW:
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Rails/Output
4
+ # rubocop:disable Style/GuardClause
5
+ class CheckLegacyTables < ActiveRecord::Migration[5.2]
6
+ class Answer < ApplicationRecord
7
+ self.table_name = :decidim_surveys_survey_answers
8
+ end
9
+
10
+ class AnswerChoice < ApplicationRecord
11
+ self.table_name = :decidim_surveys_survey_answer_choices
12
+ end
13
+
14
+ class AnswerOption < ApplicationRecord
15
+ self.table_name = :decidim_surveys_survey_answer_options
16
+ end
17
+
18
+ class Question < ApplicationRecord
19
+ self.table_name = :decidim_surveys_survey_questions
20
+ end
21
+
22
+ def up
23
+ if tables_exists.any?
24
+ if tables_exists.all?
25
+ migrate_legacy_data if Question.any?
26
+ else
27
+ puts "Some legacy surveys tables exist but not all. Have you migrated all the data?"
28
+ puts "Migrate or backup your data and then remove the following raise statement to continue with the migrations (that will remove surveys legacy tables)"
29
+ puts "For migrating your data you can do that with the command:"
30
+ puts "bundle exec rake decidim_surveys:migrate_data_to_decidim_forms"
31
+ raise "ERROR: there's the risk to loose legacy information from old surveys!"
32
+ end
33
+ end
34
+ end
35
+
36
+ def tables_exists
37
+ @tables_exists ||= [Answer, AnswerChoice, AnswerOption, Question].collect { |model| ActiveRecord::Base.connection.table_exists? model.table_name }
38
+ end
39
+
40
+ def migrate_legacy_data
41
+ puts "Migrating data from decidim_surveys tables to decidim_forms tables..."
42
+ ActiveRecord::Base.transaction do
43
+ Decidim::Surveys::Survey.find_each do |survey|
44
+ puts "Migrating survey #{survey.id}..."
45
+ if survey.questionnaire.present?
46
+ puts("already migrated at questionnaire #{survey.questionnaire.id}")
47
+ next
48
+ end
49
+
50
+ questionnaire = ::Decidim::Forms::Questionnaire.create!(
51
+ questionnaire_for: survey,
52
+ title: survey.title,
53
+ description: survey.description,
54
+ tos: survey.tos,
55
+ published_at: survey.published_at,
56
+ created_at: survey.created_at,
57
+ updated_at: survey.updated_at
58
+ )
59
+
60
+ Question.where(decidim_survey_id: survey.id).find_each do |survey_question|
61
+ puts "Migrating question #{survey_question.id}..."
62
+
63
+ question = ::Decidim::Forms::Question.create!(
64
+ questionnaire: questionnaire,
65
+ position: survey_question.position,
66
+ question_type: survey_question.question_type,
67
+ mandatory: survey_question.mandatory,
68
+ body: survey_question.body,
69
+ description: survey_question.description,
70
+ max_choices: survey_question.max_choices,
71
+ created_at: survey_question.created_at,
72
+ updated_at: survey_question.updated_at
73
+ )
74
+
75
+ # A hash with the old answer_option id as key, and the new form answer option as value
76
+ answer_option_mapping = {}
77
+
78
+ AnswerOption.where(decidim_survey_question_id: survey_question.id).find_each do |survey_answer_option|
79
+ answer_option_mapping[survey_answer_option.id] = ::Decidim::Forms::AnswerOption.create!(
80
+ question: question,
81
+ body: survey_answer_option.body,
82
+ free_text: survey_answer_option.free_text
83
+ )
84
+ end
85
+
86
+ Answer.where(decidim_survey_id: survey.id, decidim_survey_question_id: survey_question.id).find_each do |survey_answer|
87
+ answer = ::Decidim::Forms::Answer.new(
88
+ questionnaire: questionnaire,
89
+ question: question,
90
+ decidim_user_id: survey_answer.decidim_user_id,
91
+ body: survey_answer.body,
92
+ created_at: survey_answer.created_at,
93
+ updated_at: survey_answer.updated_at
94
+ )
95
+
96
+ AnswerChoice.where(decidim_survey_answer_id: survey_answer.id).find_each do |survey_answer_choice|
97
+ answer.choices.build(
98
+ answer_option: answer_option_mapping[survey_answer_choice.decidim_survey_answer_option_id],
99
+ body: survey_answer_choice.body,
100
+ custom_body: survey_answer_choice.custom_body,
101
+ position: survey_answer_choice.position
102
+ )
103
+ end
104
+
105
+ answer.save!
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ # rubocop:enable Style/GuardClause
114
+ # rubocop:enable Rails/Output
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveSurveyAnswerChoices < ActiveRecord::Migration[5.2]
4
+ def change
5
+ drop_table :decidim_surveys_survey_answer_choices, if_exists: true
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveSurveyAnswerOptions < ActiveRecord::Migration[5.2]
4
+ def change
5
+ drop_table :decidim_surveys_survey_answer_options, if_exists: true
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveSurveyAnswers < ActiveRecord::Migration[5.2]
4
+ def change
5
+ drop_table :decidim_surveys_survey_answers, if_exists: true
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveSurveyQuestions < ActiveRecord::Migration[5.2]
4
+ def change
5
+ drop_table :decidim_surveys_survey_questions, if_exists: true
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveSurveyColumns < ActiveRecord::Migration[5.2]
4
+ def change
5
+ remove_column :decidim_surveys_surveys, :title if ActiveRecord::Base.connection.column_exists?(:decidim_surveys_surveys, :title)
6
+ remove_column :decidim_surveys_surveys, :description if ActiveRecord::Base.connection.column_exists?(:decidim_surveys_surveys, :description)
7
+ remove_column :decidim_surveys_surveys, :tos if ActiveRecord::Base.connection.column_exists?(:decidim_surveys_surveys, :tos)
8
+ remove_column :decidim_surveys_surveys, :published_at if ActiveRecord::Base.connection.column_exists?(:decidim_surveys_surveys, :published_at)
9
+ end
10
+ end
@@ -10,10 +10,20 @@ module Decidim
10
10
  paths["lib/tasks"] = nil
11
11
 
12
12
  routes do
13
+ get "/answer/:session_token", to: "surveys#show", as: :show_survey
14
+ get "/answer/:session_token/export", to: "surveys#export_response", as: :export_response_survey
15
+ get "/answers", to: "surveys#index", as: :index_survey
16
+ get "/answer_options", to: "surveys#answer_options", as: :answer_options_survey
13
17
  put "/", to: "surveys#update", as: :survey
14
18
  root to: "surveys#edit"
15
19
  end
16
20
 
21
+ initializer "decidim.notifications.components" do
22
+ Decidim::EventsManager.subscribe(/^decidim\.events\.components/) do |event_name, data|
23
+ CleanSurveyAnswersJob.perform_later(event_name, data)
24
+ end
25
+ end
26
+
17
27
  def load_seed
18
28
  nil
19
29
  end
@@ -8,6 +8,10 @@ Decidim.register_component(:surveys) do |component|
8
8
  component.icon = "decidim/surveys/icon.svg"
9
9
  component.stylesheet = "decidim/surveys/surveys"
10
10
  component.permissions_class_name = "Decidim::Surveys::Permissions"
11
+ component.serializes_specific_data = true
12
+ component.specific_data_serializer_class_name = "Decidim::Surveys::DataSerializer"
13
+ component.specific_data_importer_class_name = "Decidim::Surveys::DataImporter"
14
+ component.query_type = "Decidim::Surveys::SurveysType"
11
15
 
12
16
  component.on(:copy) do |context|
13
17
  Decidim::Surveys::CreateSurvey.call(context[:new_component]) do
@@ -39,23 +43,27 @@ Decidim.register_component(:surveys) do |component|
39
43
  surveys.count
40
44
  end
41
45
 
42
- component.register_stat :answers_count, priority: Decidim::StatsRegistry::MEDIUM_PRIORITY do |components, start_at, end_at|
46
+ component.register_stat :answers_count, primary: true, priority: Decidim::StatsRegistry::MEDIUM_PRIORITY do |components, start_at, end_at|
43
47
  surveys = Decidim::Surveys::Survey.includes(:questionnaire).where(component: components)
44
48
  answers = Decidim::Forms::Answer.where(questionnaire: surveys.map(&:questionnaire))
45
49
  answers = answers.where("created_at >= ?", start_at) if start_at.present?
46
50
  answers = answers.where("created_at <= ?", end_at) if end_at.present?
47
- answers.group(:decidim_user_id).count.size
51
+ answers.group(:session_token).count.size
48
52
  end
49
53
 
50
54
  # These actions permissions can be configured in the admin panel
51
55
  component.actions = %w(answer)
52
56
 
53
57
  component.settings(:global) do |settings|
58
+ settings.attribute :scopes_enabled, type: :boolean, default: false
59
+ settings.attribute :scope_id, type: :scope
54
60
  settings.attribute :announcement, type: :text, translated: true, editor: true
61
+ settings.attribute :clean_after_publish, type: :boolean, default: true
55
62
  end
56
63
 
57
64
  component.settings(:step) do |settings|
58
65
  settings.attribute :allow_answers, type: :boolean, default: false
66
+ settings.attribute :allow_unregistered, type: :boolean, default: false
59
67
  settings.attribute :announcement, type: :text, translated: true, editor: true
60
68
  end
61
69
 
@@ -65,6 +73,8 @@ Decidim.register_component(:surveys) do |component|
65
73
  Decidim::Forms::QuestionnaireUserAnswers.for(survey.questionnaire)
66
74
  end
67
75
 
76
+ exports.formats %w(CSV JSON Excel FormPDF)
77
+
68
78
  exports.serializer Decidim::Forms::UserAnswersSerializer
69
79
  end
70
80
 
@@ -112,23 +122,45 @@ Decidim.register_component(:surveys) do |component|
112
122
  visibility: "all"
113
123
  )
114
124
 
115
- %w(short_answer long_answer).each do |text_question_type|
125
+ %w(short_answer long_answer).each_with_index do |text_question_type, index|
116
126
  Decidim::Forms::Question.create!(
117
127
  questionnaire: questionnaire,
118
128
  body: Decidim::Faker::Localized.paragraph,
119
- question_type: text_question_type
129
+ question_type: text_question_type,
130
+ position: index
131
+ )
132
+ end
133
+
134
+ %w(single_option multiple_option).each_with_index do |multiple_choice_question_type, index|
135
+ question = Decidim::Forms::Question.create!(
136
+ questionnaire: questionnaire,
137
+ body: Decidim::Faker::Localized.paragraph,
138
+ question_type: multiple_choice_question_type,
139
+ position: index + 2
140
+ )
141
+
142
+ 3.times do
143
+ question.answer_options.create!(body: Decidim::Faker::Localized.sentence)
144
+ end
145
+
146
+ question.display_conditions.create!(
147
+ condition_question: questionnaire.questions.find_by(position: question.position - 2),
148
+ question: question,
149
+ condition_type: :answered,
150
+ mandatory: true
120
151
  )
121
152
  end
122
153
 
123
- %w(single_option multiple_option).each do |multiple_choice_question_type|
154
+ %w(matrix_single matrix_multiple).each do |matrix_question_type|
124
155
  question = Decidim::Forms::Question.create!(
125
156
  questionnaire: questionnaire,
126
157
  body: Decidim::Faker::Localized.paragraph,
127
- question_type: multiple_choice_question_type
158
+ question_type: matrix_question_type
128
159
  )
129
160
 
130
161
  3.times do
131
162
  question.answer_options.create!(body: Decidim::Faker::Localized.sentence)
163
+ question.matrix_rows.create!(body: Decidim::Faker::Localized.sentence)
132
164
  end
133
165
  end
134
166
  end