decidim-surveys 0.15.2 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -9
  3. data/app/assets/stylesheets/decidim/surveys/surveys.scss +2 -2
  4. data/app/commands/decidim/surveys/create_survey.rb +1 -1
  5. data/app/controllers/decidim/surveys/admin/surveys_controller.rb +6 -37
  6. data/app/controllers/decidim/surveys/surveys_controller.rb +8 -22
  7. data/app/jobs/decidim/surveys/settings_change_job.rb +6 -3
  8. data/app/models/decidim/surveys/survey.rb +2 -12
  9. data/app/permissions/decidim/surveys/admin/permissions.rb +1 -1
  10. data/app/permissions/decidim/surveys/permissions.rb +1 -1
  11. data/app/queries/decidim/surveys/metrics/answers_metric_manage.rb +70 -0
  12. data/app/queries/decidim/surveys/metrics/survey_participants_metric_measure.rb +30 -0
  13. data/config/locales/ca.yml +5 -66
  14. data/config/locales/de.yml +5 -66
  15. data/config/locales/en.yml +5 -66
  16. data/config/locales/es-PY.yml +5 -66
  17. data/config/locales/es.yml +5 -66
  18. data/config/locales/eu.yml +5 -66
  19. data/config/locales/fi-pl.yml +5 -66
  20. data/config/locales/fi.yml +5 -66
  21. data/config/locales/fr.yml +5 -66
  22. data/config/locales/gl.yml +5 -66
  23. data/config/locales/hu.yml +5 -66
  24. data/config/locales/id-ID.yml +0 -70
  25. data/config/locales/it.yml +5 -66
  26. data/config/locales/nl.yml +5 -66
  27. data/config/locales/pl.yml +5 -66
  28. data/config/locales/pt-BR.yml +5 -66
  29. data/config/locales/pt.yml +5 -66
  30. data/config/locales/ru.yml +0 -66
  31. data/config/locales/sv.yml +5 -66
  32. data/config/locales/tr-TR.yml +0 -70
  33. data/config/locales/uk.yml +0 -66
  34. data/lib/decidim/surveys.rb +0 -2
  35. data/lib/decidim/surveys/admin_engine.rb +1 -5
  36. data/lib/decidim/surveys/component.rb +18 -15
  37. data/lib/decidim/surveys/engine.rb +17 -4
  38. data/lib/decidim/surveys/test/factories.rb +2 -42
  39. data/lib/decidim/surveys/version.rb +1 -1
  40. data/lib/tasks/decidim_surveys_tasks.rake +92 -0
  41. metadata +28 -42
  42. data/app/assets/config/admin/decidim_surveys_manifest.js +0 -1
  43. data/app/assets/config/decidim_surveys_manifest.js +0 -1
  44. data/app/assets/images/decidim/surveys/icon.svg +0 -19
  45. data/app/assets/javascripts/decidim/surveys/admin/auto_buttons_by_min_items.component.js.es6 +0 -25
  46. data/app/assets/javascripts/decidim/surveys/admin/auto_select_options_by_total_items.component.js.es6 +0 -23
  47. data/app/assets/javascripts/decidim/surveys/admin/surveys.js.es6 +0 -188
  48. data/app/assets/javascripts/decidim/surveys/autosortable_checkboxes.component.js.es6 +0 -65
  49. data/app/assets/javascripts/decidim/surveys/option_attached_inputs.component.js.es6 +0 -32
  50. data/app/assets/javascripts/decidim/surveys/surveys.js.es6 +0 -20
  51. data/app/commands/decidim/surveys/admin/update_survey.rb +0 -86
  52. data/app/commands/decidim/surveys/answer_survey.rb +0 -54
  53. data/app/forms/decidim/surveys/admin/survey_answer_option_form.rb +0 -23
  54. data/app/forms/decidim/surveys/admin/survey_form.rb +0 -27
  55. data/app/forms/decidim/surveys/admin/survey_question_form.rb +0 -35
  56. data/app/forms/decidim/surveys/survey_answer_choice_form.rb +0 -15
  57. data/app/forms/decidim/surveys/survey_answer_form.rb +0 -69
  58. data/app/forms/decidim/surveys/survey_form.rb +0 -22
  59. data/app/helpers/decidim/surveys/admin/application_helper.rb +0 -19
  60. data/app/models/decidim/surveys/survey_answer.rb +0 -45
  61. data/app/models/decidim/surveys/survey_answer_choice.rb +0 -15
  62. data/app/models/decidim/surveys/survey_answer_option.rb +0 -11
  63. data/app/models/decidim/surveys/survey_question.rb +0 -36
  64. data/app/queries/decidim/surveys/survey_user_answers.rb +0 -28
  65. data/app/views/decidim/surveys/admin/surveys/_answer_option.html.erb +0 -44
  66. data/app/views/decidim/surveys/admin/surveys/_form.html.erb +0 -51
  67. data/app/views/decidim/surveys/admin/surveys/_question.html.erb +0 -115
  68. data/app/views/decidim/surveys/admin/surveys/edit.html.erb +0 -7
  69. data/app/views/decidim/surveys/surveys/_answer.html.erb +0 -94
  70. data/app/views/decidim/surveys/surveys/show.html.erb +0 -84
  71. data/lib/decidim/surveys/data_portability_survey_user_answers_serializer.rb +0 -37
  72. data/lib/decidim/surveys/survey_user_answers_serializer.rb +0 -29
@@ -1,51 +0,0 @@
1
- <div class="card">
2
- <div class="card-divider">
3
- <h2 class="card-title">
4
- <%= title %>
5
- <div class="button--title">
6
- <%= export_dropdown if allowed_to? :export_answers, :survey %>
7
- </div>
8
- </h2>
9
- </div>
10
- <div class="card-section">
11
- <div class="row column">
12
- <%= form.translated :text_field, :title, autofocus: true %>
13
- </div>
14
- <div class="row column">
15
- <%= form.translated :editor, :description, toolbar: :full, lines: 30, label: t("models.components.description", scope: "decidim.surveys.admin") %>
16
- </div>
17
- <div class="row column">
18
- <%= form.translated :editor, :tos, toolbar: :full, lines: 10, label: t("models.components.tos", scope: "decidim.surveys.admin") %>
19
- </div>
20
- </div>
21
- </div>
22
-
23
- <div class="survey-questions">
24
- <% if survey.questions_editable? %>
25
- <template>
26
- <%= fields_for "survey[questions][#{blank_question.to_param}]", blank_question do |question_form| %>
27
- <%= render "question", form: question_form, id: tabs_id_for_question(blank_question), editable: survey.questions_editable? %>
28
- <% end %>
29
- </template>
30
- <% else %>
31
- <div class="callout warning">
32
- <%= t(".already_answered_warning") %>
33
- </div>
34
- <% end %>
35
-
36
- <div class="survey-questions-list">
37
- <% @form.questions.each do |question| %>
38
- <%= fields_for "survey[questions][]", question do |question_form| %>
39
- <%= render "question", form: question_form, id: tabs_id_for_question(question), editable: survey.questions_editable? %>
40
- <% end %>
41
- <% end %>
42
- </div>
43
-
44
- <% if survey.questions_editable? %>
45
- <button class="button add-question"><%= t(".add_question") %></button>
46
- <% end %>
47
- </div>
48
-
49
- <% if survey.questions_editable? %>
50
- <%= javascript_include_tag "decidim/surveys/admin/surveys" %>
51
- <% end %>
@@ -1,115 +0,0 @@
1
- <% question = form.object %>
2
-
3
- <div class="card survey-question" id="<%= id %>-field">
4
- <div class="card-divider question-divider">
5
- <h2 class="card-title">
6
- <span>
7
- <% if editable %>
8
- <%== "#{icon("move")} #{t(".question")}" %>
9
- <% else %>
10
- <%= t(".question") %>
11
- <% end %>
12
- </span>
13
-
14
- <% if editable %>
15
- <button class="button small alert hollow move-up-question button--title">
16
- <%== "#{icon("arrow-top")} #{t(".up")}" %>
17
- </button>
18
-
19
- <button class="button small alert hollow move-down-question button--title">
20
- <%== "#{icon("arrow-bottom")} #{t(".down")}" %>
21
- </button>
22
-
23
- <button class="button small alert hollow remove-question button--title">
24
- <%= t(".remove") %>
25
- </button>
26
- <% end %>
27
- </h2>
28
- </div>
29
-
30
- <div class="card-section">
31
- <div class="row column">
32
- <%=
33
- form.translated(
34
- :text_field,
35
- :body,
36
- tabs_id: id,
37
- label: t(".statement"),
38
- disabled: !editable
39
- )
40
- %>
41
- </div>
42
-
43
- <div class="row column">
44
- <%=
45
- form.translated(
46
- :editor,
47
- :description,
48
- toolbar: :full,
49
- tabs_id: id,
50
- label: t(".description"),
51
- disabled: !editable
52
- )
53
- %>
54
- </div>
55
-
56
- <div class="row column">
57
- <%=
58
- form.check_box(
59
- :mandatory,
60
- disabled: !editable,
61
- label: t("activemodel.attributes.survey_question.mandatory")
62
- )
63
- %>
64
- </div>
65
-
66
- <div class="row column">
67
- <%=
68
- form.select(
69
- :question_type,
70
- options_from_collection_for_select(question_types, :first, :last, question.question_type),
71
- {},
72
- disabled: !editable
73
- )
74
- %>
75
- </div>
76
-
77
- <% if question.persisted? %>
78
- <%= form.hidden_field :id, disabled: !editable %>
79
- <% end %>
80
-
81
- <%= form.hidden_field :position, value: question.position || 0, disabled: !editable %>
82
- <%= form.hidden_field :deleted, disabled: !editable %>
83
-
84
- <div class="survey-question-answer-options">
85
- <template>
86
- <%= fields_for "survey[questions][#{question.to_param}][answer_options][]", blank_answer_option do |answer_option_form| %>
87
- <%= render "answer_option", form: answer_option_form, question: question, editable: editable %>
88
- <% end %>
89
- </template>
90
-
91
- <div class="survey-question-answer-options-list">
92
- <% question.answer_options.each do |answer_option| %>
93
- <%= fields_for "survey[questions][#{question.to_param}][answer_options][]", answer_option do |answer_option_form| %>
94
- <%= render "answer_option", form: answer_option_form, question: question, editable: editable %>
95
- <% end %>
96
- <% end %>
97
- </div>
98
-
99
- <% if editable %>
100
- <button class="button add-answer-option"><%= t(".add_answer_option") %></button>
101
- <% end %>
102
- </div>
103
-
104
- <div class="row column survey-question-max-choices">
105
- <%=
106
- form.select(
107
- :max_choices,
108
- (2..question.number_of_options),
109
- { prompt: t(".any") },
110
- disabled: !editable
111
- )
112
- %>
113
- </div>
114
- </div>
115
- </div>
@@ -1,7 +0,0 @@
1
- <%= decidim_form_for(@form, url: survey_path, method: :post, html: { class: "form edit_survey" }) do |form| %>
2
- <%= render partial: "form", object: form, locals: { title: t(".title") } %>
3
-
4
- <div class="button--double form-general-submit">
5
- <%= form.submit t(".save"), class: "button" %>
6
- </div>
7
- <% end %>
@@ -1,94 +0,0 @@
1
- <% field_id = "survey_answers_#{answer_idx}" %>
2
- <%= label_tag field_id, answer.label(answer_idx), class: "survey-question" %>
3
-
4
- <% if translated_attribute(answer.question.description).present? %>
5
- <div class="help-text">
6
- <%= decidim_sanitize translated_attribute(answer.question.description) %>
7
- </div>
8
- <% end %>
9
-
10
- <% case answer.question.question_type %>
11
- <% when "short_answer" %>
12
- <%= answer_form.text_field :body, label: false, id: field_id, disabled: disabled %>
13
- <% when "long_answer" %>
14
- <%= answer_form.text_area :body, label: false, id: field_id, rows: 10, disabled: disabled %>
15
- <% when "single_option" %>
16
- <div class="radio-button-collection">
17
- <% choice = answer.choices.first %>
18
-
19
- <% answer.question.answer_options.each_with_index do |answer_option, idx| %>
20
- <% choice_id = "#{field_id}_choices_#{idx}" %>
21
-
22
- <%= label_tag "#{choice_id}_body" do %>
23
- <%= radio_button_tag "survey[survey_answers][#{answer_idx}][choices][][body]",
24
- translated_attribute(answer_option.body),
25
- choice.try(:body),
26
- id: "#{choice_id}_body", disabled: disabled %>
27
-
28
- <%= translated_attribute(answer_option.body) %>
29
-
30
- <% if answer_option.free_text %>
31
- <%= text_field_tag "survey[survey_answers][#{answer_idx}][choices][][custom_body]",
32
- choice.try(:custom_body),
33
- id: "#{choice_id}_custom_body",
34
- disabled: true %>
35
- <% end %>
36
-
37
- <%= hidden_field_tag "survey[survey_answers][#{answer_idx}][choices][][answer_option_id]",
38
- answer_option.id,
39
- id: "#{choice_id}_answer_option",
40
- disabled: true %>
41
- <% end %>
42
- <% end %>
43
- </div>
44
- <% when "multiple_option" %>
45
- <div class="check-box-collection">
46
- <% answer.question.answer_options.each_with_index do |answer_option, idx| %>
47
- <% choice = answer.selected_choices.find { |choice| choice.answer_option_id == answer_option.id } %>
48
-
49
- <%= label_tag do %>
50
- <%= check_box_tag "survey[survey_answers][#{answer_idx}][choices][#{idx}][body]",
51
- translated_attribute(answer_option.body),
52
- choice.present?, disabled: disabled %>
53
-
54
- <%= translated_attribute(answer_option.body) %>
55
-
56
- <% if answer_option.free_text %>
57
- <%= text_field_tag "survey[survey_answers][#{answer_idx}][choices][#{idx}][custom_body]",
58
- choice.try(:custom_body),
59
- disabled: true %>
60
- <% end %>
61
-
62
- <%= hidden_field_tag "survey[survey_answers][#{answer_idx}][choices][#{idx}][answer_option_id]", answer_option.id %>
63
- <% end %>
64
- <% end %>
65
- </div>
66
- <% when "sorting" %>
67
- <div class="sortable-check-box-collection">
68
- <% answer.question.answer_options.each_with_index do |answer_option, idx| %>
69
- <% choice = answer.selected_choices.find { |choice| choice.answer_option_id == answer_option.id } %>
70
-
71
- <%= label_tag do %>
72
- <%= check_box_tag "survey[survey_answers][#{answer_idx}][choices][#{idx}][body]",
73
- translated_attribute(answer_option.body),
74
- choice.present?, disabled: disabled %>
75
-
76
- <span class="position"><%= choice.try(:position) %></span>
77
-
78
- <%= translated_attribute(answer_option.body) %>
79
-
80
- <%= hidden_field_tag "survey[survey_answers][#{answer_idx}][choices][#{idx}][position]",
81
- choice.try(:position),
82
- disabled: true %>
83
-
84
- <%= hidden_field_tag "survey[survey_answers][#{answer_idx}][choices][#{idx}][answer_option_id]", answer_option.id %>
85
- <% end %>
86
- <% end %>
87
- </div>
88
- <% end %>
89
-
90
- <%= answer_form.hidden_field :question_id %>
91
-
92
- <% answer.errors.full_messages.each do |msg| %>
93
- <small class="form-error is-visible"><%= msg %></small>
94
- <% end %>
@@ -1,84 +0,0 @@
1
- <% add_decidim_meta_tags({
2
- title: translated_attribute(survey.title),
3
- description: translated_attribute(survey.description),
4
- }) %>
5
-
6
- <%= render partial: "decidim/shared/component_announcement" %>
7
-
8
- <div class="row columns">
9
- <h2 class="section-heading"><%= translated_attribute survey.title %></h2>
10
- <div class="row">
11
- <div class="columns large-6 medium-centered lead">
12
- <%= decidim_sanitize translated_attribute survey.description %>
13
- </div>
14
- </div>
15
- </div>
16
-
17
- <div class="row">
18
- <div class="columns large-6 medium-centered">
19
- <div class="card">
20
- <div class="card__content">
21
- <% if current_settings.allow_answers? %>
22
- <% if current_user %>
23
- <% if survey.answered_by?(current_user) %>
24
- <div class="section">
25
- <div class="callout success">
26
- <h5><%= t(".survey_answered.title") %></h5>
27
- <p><%= t(".survey_answered.body") %></p>
28
- </div>
29
- </div>
30
- <% else %>
31
- <div class="answer-survey">
32
- <% unless current_participatory_space.can_participate?(current_user) %>
33
- <div class="section">
34
- <div class="callout alert">
35
- <h5><%= t(".survey_for_private_users.title") %></h5>
36
- <p><%= t(".survey_for_private_users.body") %></p>
37
- </div>
38
- </div>
39
- <% end %>
40
-
41
- <%= decidim_form_for(@form, url: answer_survey_path(survey), method: :post, html: { class: "form answer-survey" }) do |form| %>
42
- <% @form.survey_answers.each_with_index do |answer, answer_idx| %>
43
- <div class="row column">
44
- <%= fields_for "survey[survey_answers][#{answer_idx}]", answer do |answer_form| %>
45
- <%= render "answer", answer_form: answer_form, answer: answer, answer_idx: answer_idx, disabled: !current_participatory_space.can_participate?(current_user) %>
46
- <% end %>
47
- </div>
48
- <% end %>
49
-
50
- <div class="row column tos-agreement">
51
- <%= form.check_box :tos_agreement, label: t(".tos_agreement"), id: "survey_tos_agreement", disabled: !current_participatory_space.can_participate?(current_user) %>
52
- <div class="help-text">
53
- <%= decidim_sanitize translated_attribute survey.tos %>
54
- </div>
55
- </div>
56
-
57
- <div class="button--double form-general-submit">
58
- <%= form.submit t(".submit"), class: "button", disabled: !current_participatory_space.can_participate?(current_user), data: { confirm: t(".are_you_sure"), disable: true } %>
59
- </div>
60
- <% end %>
61
- </div>
62
- <% end %>
63
- <% else %>
64
- <div class="answer-survey">
65
- <h5 class="section-heading"><%= t(".answer_survey.title") %></h5>
66
- <p>
67
- <%= t(".answer_survey.anonymous_user_message", sign_in_link: decidim.new_user_session_path, sign_up_link: decidim.new_user_registration_path).html_safe %>
68
- </p>
69
- </div>
70
- <% end %>
71
- <% else %>
72
- <div class="section">
73
- <div class="callout warning">
74
- <h5><%= t(".survey_closed.title") %></h5>
75
- <p><%= t(".survey_closed.body") %></p>
76
- </div>
77
- </div>
78
- <% end %>
79
- </div>
80
- </div>
81
- </div>
82
- </div>
83
-
84
- <%= javascript_include_tag "decidim/surveys/surveys" %>
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Surveys
5
- class DataPortabilitySurveyUserAnswersSerializer < Decidim::Exporters::Serializer
6
- include Decidim::TranslationsHelper
7
- # Serializes a Survey User Answer for data portability
8
- def serialize
9
- {
10
- id: resource.id,
11
- user: {
12
- name: resource.user.name,
13
- email: resource.user.email
14
- },
15
- survey: {
16
- id: resource.question.survey.id,
17
- title: translated_attribute(resource.question.survey.title),
18
- description: translated_attribute(resource.question.survey.description),
19
- tos: translated_attribute(resource.question.survey.tos)
20
- },
21
- question: {
22
- id: resource.question.id,
23
- body: translated_attribute(resource.question.body),
24
- description: translated_attribute(resource.question.description)
25
- },
26
- answer: normalize_body(resource)
27
- }
28
- end
29
-
30
- private
31
-
32
- def normalize_body(resource)
33
- resource.body || resource.choices.pluck(:body)
34
- end
35
- end
36
- end
37
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Surveys
5
- # This class serializes the answers given by a User for survey so can be
6
- # exported to CSV, JSON or other formats.
7
- class SurveyUserAnswersSerializer < Decidim::Exporters::Serializer
8
- include Decidim::TranslationsHelper
9
-
10
- # Public: Initializes the serializer with a collection of SurveyAnswers.
11
- def initialize(survey_answers)
12
- @survey_answers = survey_answers
13
- end
14
-
15
- # Public: Exports a hash with the serialized data for the user answers.
16
- def serialize
17
- @survey_answers.each_with_index.inject({}) do |serialized, (answer, idx)|
18
- serialized.update("#{idx + 1}. #{translated_attribute(answer.question.body)}" => normalize_body(answer))
19
- end
20
- end
21
-
22
- private
23
-
24
- def normalize_body(answer)
25
- answer.body || answer.choices.pluck(:body)
26
- end
27
- end
28
- end
29
- end