decidim-surveys 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.
- checksums.yaml +4 -4
- data/app/cells/decidim/surveys/survey_card_metadata_cell.rb +43 -0
- data/app/cells/decidim/surveys/survey_cell.rb +26 -0
- data/app/cells/decidim/surveys/survey_l_cell.rb +34 -0
- data/app/cells/decidim/surveys/survey_s_cell.rb +21 -0
- data/app/commands/decidim/surveys/admin/create_survey.rb +21 -0
- data/app/commands/decidim/surveys/admin/publish_survey.rb +58 -0
- data/app/commands/decidim/surveys/admin/unpublish_survey.rb +44 -0
- data/app/commands/decidim/surveys/admin/update_survey.rb +62 -0
- data/app/commands/decidim/surveys/publish_answers.rb +55 -0
- data/app/commands/decidim/surveys/unpublish_answers.rb +55 -0
- data/app/controllers/concerns/decidim/surveys/admin/filterable.rb +23 -0
- data/app/controllers/decidim/surveys/admin/answers_controller.rb +73 -0
- data/app/controllers/decidim/surveys/admin/publish_answers_controller.rb +66 -0
- data/app/controllers/decidim/surveys/admin/surveys_controller.rb +99 -11
- data/app/controllers/decidim/surveys/surveys_controller.rb +50 -5
- data/app/forms/decidim/surveys/admin/survey_form.rb +18 -0
- data/app/helpers/decidim/surveys/application_helper.rb +34 -0
- data/app/helpers/decidim/surveys/publish_answers_helper.rb +104 -0
- data/app/helpers/decidim/surveys/survey_helper.rb +4 -0
- data/app/models/decidim/surveys/survey.rb +67 -12
- data/app/permissions/decidim/surveys/admin/permissions.rb +10 -1
- data/app/permissions/decidim/surveys/permissions.rb +0 -2
- data/app/presenters/decidim/surveys/admin_log/survey_presenter.rb +34 -0
- data/app/queries/decidim/surveys/metrics/answers_metric_manage.rb +3 -3
- data/app/queries/decidim/surveys/metrics/survey_participants_metric_measure.rb +2 -2
- data/app/views/decidim/surveys/admin/answers/index.html.erb +49 -0
- data/app/views/decidim/surveys/admin/answers/show.html.erb +43 -0
- data/app/views/decidim/surveys/admin/publish_answers/_toggle_button.html.erb +22 -0
- data/app/views/decidim/surveys/admin/publish_answers/index.html.erb +44 -0
- data/app/views/decidim/surveys/admin/surveys/_form.html.erb +28 -0
- data/app/views/decidim/surveys/admin/surveys/edit.html.erb +4 -21
- data/app/views/decidim/surveys/admin/surveys/edit_questions.html.erb +47 -0
- data/app/views/decidim/surveys/admin/surveys/index.html.erb +51 -0
- data/app/views/decidim/surveys/surveys/_published_questions_answers.html.erb +13 -0
- data/app/views/decidim/surveys/surveys/_surveys.html.erb +13 -0
- data/app/views/decidim/surveys/surveys/index.html.erb +27 -0
- data/app/views/decidim/surveys/surveys/index.js.erb +4 -0
- data/app/views/decidim/surveys/surveys/not_allowed.html.erb +22 -0
- data/config/locales/ar.yml +4 -3
- data/config/locales/bg.yml +0 -14
- data/config/locales/ca.yml +83 -14
- data/config/locales/cs.yml +87 -14
- data/config/locales/de.yml +83 -14
- data/config/locales/el.yml +0 -11
- data/config/locales/en.yml +83 -14
- data/config/locales/es-MX.yml +83 -14
- data/config/locales/es-PY.yml +83 -14
- data/config/locales/es.yml +83 -14
- data/config/locales/eu.yml +83 -14
- data/config/locales/fi-plain.yml +83 -14
- data/config/locales/fi.yml +83 -14
- data/config/locales/fr-CA.yml +74 -14
- data/config/locales/fr.yml +74 -14
- data/config/locales/ga-IE.yml +0 -4
- data/config/locales/gl.yml +0 -10
- data/config/locales/hu.yml +0 -3
- data/config/locales/id-ID.yml +0 -2
- data/config/locales/is-IS.yml +0 -2
- data/config/locales/it.yml +3 -10
- data/config/locales/ja.yml +80 -13
- data/config/locales/lb.yml +0 -10
- data/config/locales/lt.yml +0 -11
- data/config/locales/lv.yml +0 -3
- data/config/locales/nl.yml +0 -10
- data/config/locales/no.yml +0 -10
- data/config/locales/pl.yml +0 -14
- data/config/locales/pt-BR.yml +0 -14
- data/config/locales/pt.yml +0 -10
- data/config/locales/ro-RO.yml +0 -11
- data/config/locales/ru.yml +0 -2
- data/config/locales/sk.yml +0 -3
- data/config/locales/sv.yml +0 -14
- data/config/locales/tr-TR.yml +0 -10
- data/config/locales/uk.yml +0 -2
- data/config/locales/zh-CN.yml +0 -6
- data/config/locales/zh-TW.yml +0 -11
- data/db/migrate/20240828103030_add_deleted_at_to_decidim_surveys_surveys.rb +8 -0
- data/db/migrate/20240925124312_add_settings_to_decidim_surveys_surveys.rb +42 -0
- data/db/migrate/20250115193836_add_allow_survey_editing.rb +7 -0
- data/decidim-surveys.gemspec +1 -1
- data/lib/decidim/api/survey_type.rb +2 -2
- data/lib/decidim/api/surveys_type.rb +4 -5
- data/lib/decidim/surveys/admin_engine.rb +15 -5
- data/lib/decidim/surveys/component.rb +7 -24
- data/lib/decidim/surveys/engine.rb +2 -2
- data/lib/decidim/surveys/seeds.rb +115 -10
- data/lib/decidim/surveys/test/factories.rb +24 -0
- data/lib/decidim/surveys/version.rb +1 -1
- metadata +48 -18
- data/app/commands/decidim/surveys/create_survey.rb +0 -19
- data/app/views/decidim/surveys/admin/component/_actions.html.erb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8455d8ce7923d4bb4fdc113acbeb4218202f7c81300a3572a1e9fa4740215c4e
|
4
|
+
data.tar.gz: 8377bee6e90f393f2e2ea6c726e399ddc75bc58cfc1cabb1751f02cbe8f895ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ada20e415fc6d3d75bc45ba256b423d4316c9b1f1d8d76fa50fd4c88a13c487b0fd1eb281ebcd2cae8f2557bed7342e4534ff40381a08208ba68bc8e339909e1
|
7
|
+
data.tar.gz: 4a5bd5b90568d885e6015e82f417a02defe3355874f020997d978cbebc7b6744536a55860595354b3b59163a17be453b152b69c6922a2404404f2c2a6086e162
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
# This cell renders metadata for an instance of a Survey
|
6
|
+
class SurveyCardMetadataCell < Decidim::CardMetadataCell
|
7
|
+
include Decidim::LayoutHelper
|
8
|
+
include ActionView::Helpers::DateHelper
|
9
|
+
|
10
|
+
alias survey model
|
11
|
+
|
12
|
+
def initialize(*)
|
13
|
+
super
|
14
|
+
|
15
|
+
@items.prepend(*survey_items)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def survey_items
|
21
|
+
[duration, questions_count_item]
|
22
|
+
end
|
23
|
+
|
24
|
+
def duration
|
25
|
+
text = survey.open? ? t("open", scope: "decidim.surveys.surveys.show") : t("closed", scope: "decidim.surveys.surveys.show")
|
26
|
+
|
27
|
+
{
|
28
|
+
text:,
|
29
|
+
icon: "time-line"
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def questions_count_item
|
34
|
+
text = "#{survey.questionnaire.questions.size} #{t("questions", scope: "decidim.surveys.surveys.show")}"
|
35
|
+
|
36
|
+
{
|
37
|
+
text:,
|
38
|
+
icon: "survey-line"
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
# This cell renders the proposal card for an instance of a Survey
|
6
|
+
# the default size is the Medium Card (:m)
|
7
|
+
class SurveyCell < Decidim::ViewModel
|
8
|
+
include Cell::ViewModel::Partial
|
9
|
+
|
10
|
+
def show
|
11
|
+
cell card_size, model, options
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def card_size
|
17
|
+
case @options[:size]
|
18
|
+
when :s
|
19
|
+
"decidim/surveys/survey_s"
|
20
|
+
else
|
21
|
+
"decidim/surveys/survey_l"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cell/partial"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Surveys
|
7
|
+
# This cell renders the List (:l) survey card
|
8
|
+
# for a given instance of a Survey
|
9
|
+
class SurveyLCell < Decidim::CardLCell
|
10
|
+
include Decidim::SanitizeHelper
|
11
|
+
|
12
|
+
def has_description?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def title
|
17
|
+
decidim_sanitize_translated(model.title)
|
18
|
+
end
|
19
|
+
|
20
|
+
def description
|
21
|
+
attribute = model.try(:short_description) || model.try(:body) || model.description
|
22
|
+
text = translated_attribute(attribute)
|
23
|
+
|
24
|
+
decidim_sanitize(html_truncate(text, length: 240), strip_tags: true)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def metadata_cell
|
30
|
+
"decidim/surveys/survey_card_metadata"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cell/partial"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Surveys
|
7
|
+
# This cell renders the Search (:s) survey card
|
8
|
+
# for a given instance of a Survey
|
9
|
+
class SurveySCell < Decidim::CardSCell
|
10
|
+
private
|
11
|
+
|
12
|
+
def title
|
13
|
+
present(model).title(html_escape: true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def metadata_cell
|
17
|
+
"decidim/surveys/survey_card_metadata"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
module Admin
|
6
|
+
# Command that gets called whenever a component's survey has to be created. It
|
7
|
+
# usually happens as a callback when the component itself is created.
|
8
|
+
class CreateSurvey < Decidim::Command
|
9
|
+
def initialize(component)
|
10
|
+
@component = component
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
@survey = Survey.new(component: @component, questionnaire: Decidim::Forms::Questionnaire.new)
|
15
|
+
|
16
|
+
@survey.save ? broadcast(:ok, @survey) : broadcast(:invalid)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic that publishes an
|
7
|
+
# existing survey.
|
8
|
+
class PublishSurvey < Decidim::Command
|
9
|
+
# Public: Initializes the command.
|
10
|
+
#
|
11
|
+
# survey - Decidim::Surveys::Survey
|
12
|
+
# current_user - the user performing the action
|
13
|
+
def initialize(survey, current_user)
|
14
|
+
@survey = survey
|
15
|
+
@current_user = current_user
|
16
|
+
@questionnaire = survey.questionnaire
|
17
|
+
end
|
18
|
+
|
19
|
+
# Executes the command. Broadcasts these events:
|
20
|
+
#
|
21
|
+
# - :ok when everything is valid.
|
22
|
+
# - :invalid if the form was not valid and we could not proceed.
|
23
|
+
#
|
24
|
+
# Returns nothing.
|
25
|
+
def call
|
26
|
+
return broadcast(:invalid) if survey.published?
|
27
|
+
|
28
|
+
transaction do
|
29
|
+
publish_survey
|
30
|
+
delete_answers if @survey.clean_after_publish?
|
31
|
+
end
|
32
|
+
|
33
|
+
broadcast(:ok, survey)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :survey, :current_user
|
39
|
+
|
40
|
+
def publish_survey
|
41
|
+
@survey = Decidim.traceability.perform_action!(
|
42
|
+
:publish,
|
43
|
+
survey,
|
44
|
+
current_user,
|
45
|
+
visibility: "all"
|
46
|
+
) do
|
47
|
+
survey.publish!
|
48
|
+
survey
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_answers
|
53
|
+
@questionnaire.answers.destroy_all
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic that unpublishes an
|
7
|
+
# existing survey.
|
8
|
+
class UnpublishSurvey < Decidim::Command
|
9
|
+
# Public: Initializes the command.
|
10
|
+
#
|
11
|
+
# survey - Decidim::Surveys::Survey
|
12
|
+
# current_user - the user performing the action
|
13
|
+
def initialize(survey, current_user)
|
14
|
+
@survey = survey
|
15
|
+
@current_user = current_user
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the form was not valid and we could not proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) unless survey.published?
|
26
|
+
|
27
|
+
@survey = Decidim.traceability.perform_action!(
|
28
|
+
:unpublish,
|
29
|
+
survey,
|
30
|
+
current_user
|
31
|
+
) do
|
32
|
+
survey.unpublish!
|
33
|
+
survey
|
34
|
+
end
|
35
|
+
broadcast(:ok, survey)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_reader :survey, :current_user
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
module Admin
|
6
|
+
# This command is executed when the user changes a Survey Questionnaire from the admin
|
7
|
+
# panel.
|
8
|
+
class UpdateSurvey < Decidim::Forms::Admin::UpdateQuestionnaire
|
9
|
+
# Initializes a UpdateSurvey Command.
|
10
|
+
#
|
11
|
+
# form - The form from which to get the data.
|
12
|
+
# survey questionnaire - The current instance of the questionnaire to be updated.
|
13
|
+
def initialize(form, survey, user)
|
14
|
+
@form = form
|
15
|
+
@survey = survey
|
16
|
+
@questionnaire = survey.questionnaire
|
17
|
+
@user = user
|
18
|
+
end
|
19
|
+
|
20
|
+
# Updates the survey questionnaire if valid.
|
21
|
+
#
|
22
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
23
|
+
def call
|
24
|
+
return broadcast(:invalid) if @form.invalid?
|
25
|
+
|
26
|
+
Decidim.traceability.perform_action!("update", @survey, @user) do
|
27
|
+
transaction do
|
28
|
+
update_survey_attributes
|
29
|
+
update_questionnaire_attributes
|
30
|
+
end
|
31
|
+
rescue ActiveRecord::RecordInvalid
|
32
|
+
broadcast(:invalid)
|
33
|
+
end
|
34
|
+
|
35
|
+
broadcast(:ok)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def update_survey_attributes
|
41
|
+
@survey.update!(
|
42
|
+
allow_answers: @form.allow_answers,
|
43
|
+
allow_editing_answers: @form.allow_editing_answers,
|
44
|
+
allow_unregistered: @form.allow_unregistered,
|
45
|
+
starts_at: @form.starts_at,
|
46
|
+
ends_at: @form.ends_at,
|
47
|
+
clean_after_publish: @form.clean_after_publish,
|
48
|
+
announcement: @form.announcement
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def update_questionnaire_attributes
|
53
|
+
@questionnaire.update!(
|
54
|
+
title: @form.title,
|
55
|
+
description: @form.description,
|
56
|
+
tos: @form.tos
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
# This command is executed when the admin publishes the Answers from the admin
|
6
|
+
# panel.
|
7
|
+
class PublishAnswers < Decidim::Command
|
8
|
+
include Decidim::TranslatableAttributes
|
9
|
+
|
10
|
+
# Initializes a PublishAnswers Command.
|
11
|
+
#
|
12
|
+
def initialize(question_id, current_user)
|
13
|
+
@question_id = question_id
|
14
|
+
@current_user = current_user
|
15
|
+
end
|
16
|
+
|
17
|
+
# Publishes the questions' answers
|
18
|
+
#
|
19
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
20
|
+
def call
|
21
|
+
transaction do
|
22
|
+
publish_survey_answer
|
23
|
+
create_action_log
|
24
|
+
end
|
25
|
+
|
26
|
+
broadcast(:ok)
|
27
|
+
rescue StandardError
|
28
|
+
broadcast(:invalid)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :question_id, :current_user
|
34
|
+
|
35
|
+
def publish_survey_answer
|
36
|
+
question.update(survey_answers_published_at: Time.current)
|
37
|
+
end
|
38
|
+
|
39
|
+
def question
|
40
|
+
Decidim::Forms::Question.find(question_id)
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_action_log
|
44
|
+
Decidim::ActionLogger.log(
|
45
|
+
"publish_answers",
|
46
|
+
current_user,
|
47
|
+
question,
|
48
|
+
nil,
|
49
|
+
resource: { title: translated_attribute(question.body) },
|
50
|
+
participatory_space: { title: question.questionnaire.questionnaire_for.title }
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
# This command is executed when the admin unpublishes the Answers from the admin
|
6
|
+
# panel.
|
7
|
+
class UnpublishAnswers < Decidim::Command
|
8
|
+
include Decidim::TranslatableAttributes
|
9
|
+
|
10
|
+
# Initializes a UnpublishAnswers Command.
|
11
|
+
#
|
12
|
+
def initialize(question_id, current_user)
|
13
|
+
@question_id = question_id
|
14
|
+
@current_user = current_user
|
15
|
+
end
|
16
|
+
|
17
|
+
# Unpublishes the questions' answers
|
18
|
+
#
|
19
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
20
|
+
def call
|
21
|
+
transaction do
|
22
|
+
unpublish_survey_answer
|
23
|
+
create_action_log
|
24
|
+
end
|
25
|
+
|
26
|
+
broadcast(:ok)
|
27
|
+
rescue StandardError
|
28
|
+
broadcast(:invalid)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :question_id, :current_user
|
34
|
+
|
35
|
+
def unpublish_survey_answer
|
36
|
+
question.update(survey_answers_published_at: nil)
|
37
|
+
end
|
38
|
+
|
39
|
+
def question
|
40
|
+
Decidim::Forms::Question.find(question_id)
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_action_log
|
44
|
+
Decidim::ActionLogger.log(
|
45
|
+
"unpublish_answers",
|
46
|
+
current_user,
|
47
|
+
question,
|
48
|
+
nil,
|
49
|
+
resource: { title: translated_attribute(question.body) },
|
50
|
+
participatory_space: { title: question.questionnaire.questionnaire_for.title }
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Surveys
|
7
|
+
module Admin
|
8
|
+
module Filterable
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include Decidim::Admin::Filterable
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def base_query
|
17
|
+
collection
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
module Admin
|
6
|
+
# This controller allows the user to update a Page.
|
7
|
+
class AnswersController < Admin::ApplicationController
|
8
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaireAnswers
|
9
|
+
|
10
|
+
def index
|
11
|
+
enforce_permission_to :index, :questionnaire_answers
|
12
|
+
|
13
|
+
@query = paginate(collection)
|
14
|
+
@participants = participants(@query)
|
15
|
+
@total = participants_query.count_participants
|
16
|
+
|
17
|
+
render template: "decidim/surveys/admin/answers/index"
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
enforce_permission_to :show, :questionnaire_answers
|
22
|
+
|
23
|
+
@participant = participant(participants_query.participant(params[:id]))
|
24
|
+
|
25
|
+
render template: "decidim/surveys/admin/answers/show"
|
26
|
+
end
|
27
|
+
|
28
|
+
def questionnaire_for
|
29
|
+
@questionnaire_for ||= Decidim::Surveys::Survey.where(component: current_component).find_by(id: params[:survey_id])
|
30
|
+
end
|
31
|
+
|
32
|
+
def questionnaire_export_response_url(id)
|
33
|
+
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).export_response_survey_answer_path(questionnaire_for, id:)
|
34
|
+
end
|
35
|
+
|
36
|
+
def questionnaire_url
|
37
|
+
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).edit_questions_survey_path(questionnaire_for)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Specify where to redirect after exporting a user response
|
41
|
+
def questionnaire_participant_answers_url(id)
|
42
|
+
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).survey_answer_path(questionnaire_for, id:)
|
43
|
+
end
|
44
|
+
|
45
|
+
def questionnaire_participants_url
|
46
|
+
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).survey_answers_path(questionnaire_for)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def questionnaire
|
52
|
+
@questionnaire ||= Decidim::Forms::Questionnaire.find_by(questionnaire_for:)
|
53
|
+
end
|
54
|
+
|
55
|
+
def participants_query
|
56
|
+
Decidim::Forms::QuestionnaireParticipants.new(questionnaire)
|
57
|
+
end
|
58
|
+
|
59
|
+
def collection
|
60
|
+
@collection ||= participants_query.participants
|
61
|
+
end
|
62
|
+
|
63
|
+
def participant(answer)
|
64
|
+
Decidim::Forms::Admin::QuestionnaireParticipantPresenter.new(participant: answer)
|
65
|
+
end
|
66
|
+
|
67
|
+
def participants(query)
|
68
|
+
query.map { |answer| participant(answer) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
module Admin
|
6
|
+
# This controller allows the user to see which questions' answers can be published, and publish or unpublish them
|
7
|
+
class PublishAnswersController < Admin::ApplicationController
|
8
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaireAnswersUrlHelper
|
9
|
+
|
10
|
+
helper PublishAnswersHelper
|
11
|
+
|
12
|
+
def index
|
13
|
+
enforce_permission_to(:index, :questionnaire_publish_answers, survey:)
|
14
|
+
|
15
|
+
@survey ||= survey
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
enforce_permission_to(:update, :questionnaire_publish_answers, survey:)
|
20
|
+
|
21
|
+
Decidim::Surveys::PublishAnswers.call(params[:id], current_user) do
|
22
|
+
on(:ok) do
|
23
|
+
render json: {}
|
24
|
+
end
|
25
|
+
|
26
|
+
on(:invalid) do
|
27
|
+
render json: {}, status: :unprocessable_entity
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def destroy
|
33
|
+
enforce_permission_to(:destroy, :questionnaire_publish_answers, survey:)
|
34
|
+
|
35
|
+
Decidim::Surveys::UnpublishAnswers.call(params[:id], current_user) do
|
36
|
+
on(:ok) do
|
37
|
+
render json: {}
|
38
|
+
end
|
39
|
+
|
40
|
+
on(:invalid) do
|
41
|
+
render json: {}, status: :unprocessable_entity
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def questionnaire
|
47
|
+
@questionnaire ||= Decidim::Forms::Questionnaire.find_by(questionnaire_for:)
|
48
|
+
end
|
49
|
+
|
50
|
+
def questionnaire_for
|
51
|
+
survey
|
52
|
+
end
|
53
|
+
|
54
|
+
def questionnaire_url
|
55
|
+
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).edit_questions_survey_path(questionnaire_for)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def survey
|
61
|
+
@survey ||= Survey.where(component: current_component).find(params[:survey_id])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|