decidim-consultations 0.11.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +51 -0
- data/Rakefile +3 -0
- data/app/assets/config/decidim_consultations_manifest.js +5 -0
- data/app/assets/config/decidim_consultations_manifest.scss +3 -0
- data/app/assets/images/decidim/consultations/icon.svg +70 -0
- data/app/assets/images/decidim/consultations/icon2.svg +88 -0
- data/app/assets/javascripts/decidim/consultations/show_more.js.es6 +12 -0
- data/app/assets/javascripts/decidim/consultations/social_share.js +2 -0
- data/app/assets/javascripts/decidim/consultations/utils.js.es6 +19 -0
- data/app/assets/javascripts/decidim/consultations/vote_dialog.js +36 -0
- data/app/assets/stylesheets/decidim/consultations/_question.scss +46 -0
- data/app/assets/stylesheets/decidim/consultations/_stats.scss +22 -0
- data/app/assets/stylesheets/decidim/consultations/_video_wrapper.scss +14 -0
- data/app/assets/stylesheets/decidim/consultations/banners/_block-banner.scss +39 -0
- data/app/assets/stylesheets/decidim/consultations/consultations.scss +6 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-banner.scss +13 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-card.scss +17 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-header.scss +115 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-home-banner.scss +15 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-home-intro.scss +30 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-intro.scss +11 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-title.scss +26 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations_nav.scss +7 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/introductory_image.scss +3 -0
- data/app/assets/stylesheets/decidim/consultations/highlighted-content-banner.css.scss +42 -0
- data/app/assets/stylesheets/decidim/consultations/social_share.css.scss +18 -0
- data/app/commands/decidim/consultations/admin/create_consultation.rb +61 -0
- data/app/commands/decidim/consultations/admin/create_question.rb +68 -0
- data/app/commands/decidim/consultations/admin/create_response.rb +39 -0
- data/app/commands/decidim/consultations/admin/publish_consultation.rb +34 -0
- data/app/commands/decidim/consultations/admin/publish_consultation_results.rb +34 -0
- data/app/commands/decidim/consultations/admin/publish_question.rb +34 -0
- data/app/commands/decidim/consultations/admin/unpublish_consultation.rb +34 -0
- data/app/commands/decidim/consultations/admin/unpublish_consultation_results.rb +34 -0
- data/app/commands/decidim/consultations/admin/unpublish_question.rb +34 -0
- data/app/commands/decidim/consultations/admin/update_consultation.rb +64 -0
- data/app/commands/decidim/consultations/admin/update_question.rb +72 -0
- data/app/commands/decidim/consultations/admin/update_response.rb +46 -0
- data/app/commands/decidim/consultations/unvote_question.rb +37 -0
- data/app/commands/decidim/consultations/vote_question.rb +42 -0
- data/app/constraints/decidim/consultations/current_component.rb +28 -0
- data/app/constraints/decidim/consultations/current_question.rb +36 -0
- data/app/controllers/concerns/decidim/consultations/action_authorization.rb +38 -0
- data/app/controllers/concerns/decidim/consultations/admin/consultation_admin.rb +24 -0
- data/app/controllers/concerns/decidim/consultations/admin/question_admin.rb +28 -0
- data/app/controllers/concerns/decidim/consultations/needs_consultation.rb +54 -0
- data/app/controllers/concerns/decidim/consultations/needs_question.rb +79 -0
- data/app/controllers/concerns/decidim/consultations/orderable.rb +52 -0
- data/app/controllers/decidim/consultations/admin/application_controller.rb +14 -0
- data/app/controllers/decidim/consultations/admin/categories_controller.rb +13 -0
- data/app/controllers/decidim/consultations/admin/component_permissions_controller.rb +13 -0
- data/app/controllers/decidim/consultations/admin/components_controller.rb +13 -0
- data/app/controllers/decidim/consultations/admin/consultation_publications_controller.rb +44 -0
- data/app/controllers/decidim/consultations/admin/consultation_results_publications_controller.rb +44 -0
- data/app/controllers/decidim/consultations/admin/consultations_controller.rb +100 -0
- data/app/controllers/decidim/consultations/admin/question_attachments_controller.rb +25 -0
- data/app/controllers/decidim/consultations/admin/question_publications_controller.rb +44 -0
- data/app/controllers/decidim/consultations/admin/questions_controller.rb +88 -0
- data/app/controllers/decidim/consultations/admin/responses_controller.rb +85 -0
- data/app/controllers/decidim/consultations/consultation_widgets_controller.rb +25 -0
- data/app/controllers/decidim/consultations/consultations_controller.rb +75 -0
- data/app/controllers/decidim/consultations/question_votes_controller.rb +40 -0
- data/app/controllers/decidim/consultations/question_widgets_controller.rb +26 -0
- data/app/controllers/decidim/consultations/questions_controller.rb +23 -0
- data/app/forms/decidim/consultations/admin/consultation_form.rb +56 -0
- data/app/forms/decidim/consultations/admin/question_form.rb +74 -0
- data/app/forms/decidim/consultations/admin/response_form.rb +18 -0
- data/app/forms/decidim/consultations/vote_form.rb +28 -0
- data/app/helpers/decidim/consultations/admin/consultations_helper.rb +14 -0
- data/app/helpers/decidim/consultations/admin/questions_helper.rb +14 -0
- data/app/helpers/decidim/consultations/consultations_helper.rb +17 -0
- data/app/models/concerns/decidim/consultations/override_categorization.rb +21 -0
- data/app/models/concerns/decidim/consultations/publicable_results.rb +51 -0
- data/app/models/decidim/consultation.rb +79 -0
- data/app/models/decidim/consultations/abilities/admin/consultation_admin_ability.rb +34 -0
- data/app/models/decidim/consultations/abilities/admin/question_admin_ability.rb +30 -0
- data/app/models/decidim/consultations/abilities/admin/response_admin_ability.rb +26 -0
- data/app/models/decidim/consultations/abilities/current_user_ability.rb +45 -0
- data/app/models/decidim/consultations/abilities/everyone_ability.rb +23 -0
- data/app/models/decidim/consultations/application_record.rb +9 -0
- data/app/models/decidim/consultations/question.rb +127 -0
- data/app/models/decidim/consultations/response.rb +19 -0
- data/app/models/decidim/consultations/vote.rb +26 -0
- data/app/presenters/decidim/consultations/question_stats_presenter.rb +52 -0
- data/app/queries/decidim/consultations/admin/admin_users.rb +40 -0
- data/app/queries/decidim/consultations/organization_active_consultations.rb +20 -0
- data/app/queries/decidim/consultations/organization_consultations.rb +20 -0
- data/app/queries/decidim/consultations/organization_questions.rb +20 -0
- data/app/services/decidim/consultations/consultation_search.rb +51 -0
- data/app/views/decidim/consultations/_consultation.html.erb +32 -0
- data/app/views/decidim/consultations/admin/consultations/_form.html.erb +58 -0
- data/app/views/decidim/consultations/admin/consultations/edit.html.erb +42 -0
- data/app/views/decidim/consultations/admin/consultations/index.html.erb +74 -0
- data/app/views/decidim/consultations/admin/consultations/new.html.erb +11 -0
- data/app/views/decidim/consultations/admin/questions/_form.html.erb +84 -0
- data/app/views/decidim/consultations/admin/questions/edit.html.erb +32 -0
- data/app/views/decidim/consultations/admin/questions/index.html.erb +74 -0
- data/app/views/decidim/consultations/admin/questions/new.html.erb +13 -0
- data/app/views/decidim/consultations/admin/responses/_form.html.erb +11 -0
- data/app/views/decidim/consultations/admin/responses/edit.html.erb +18 -0
- data/app/views/decidim/consultations/admin/responses/index.html.erb +48 -0
- data/app/views/decidim/consultations/admin/responses/new.html.erb +13 -0
- data/app/views/decidim/consultations/consultation_widgets/show.html.erb +5 -0
- data/app/views/decidim/consultations/consultations/_consultation_card.html.erb +24 -0
- data/app/views/decidim/consultations/consultations/_consultation_details.html.erb +17 -0
- data/app/views/decidim/consultations/consultations/_consultations.html.erb +16 -0
- data/app/views/decidim/consultations/consultations/_count.html.erb +1 -0
- data/app/views/decidim/consultations/consultations/_filters.html.erb +25 -0
- data/app/views/decidim/consultations/consultations/_filters_small_view.html.erb +23 -0
- data/app/views/decidim/consultations/consultations/_highlighted_questions.html.erb +13 -0
- data/app/views/decidim/consultations/consultations/_question.html.erb +40 -0
- data/app/views/decidim/consultations/consultations/_regular_questions.html.erb +14 -0
- data/app/views/decidim/consultations/consultations/finished.html.erb +15 -0
- data/app/views/decidim/consultations/consultations/index.html.erb +27 -0
- data/app/views/decidim/consultations/consultations/index.js.erb +10 -0
- data/app/views/decidim/consultations/consultations/show.html.erb +11 -0
- data/app/views/decidim/consultations/question_votes/update_vote_button.js.erb +9 -0
- data/app/views/decidim/consultations/question_widgets/show.html.erb +2 -0
- data/app/views/decidim/consultations/questions/_results.html.erb +15 -0
- data/app/views/decidim/consultations/questions/_right_column.html.erb +20 -0
- data/app/views/decidim/consultations/questions/_statistics.html.erb +31 -0
- data/app/views/decidim/consultations/questions/_technical_data.html.erb +38 -0
- data/app/views/decidim/consultations/questions/_vote_button.html.erb +76 -0
- data/app/views/decidim/consultations/questions/_vote_modal.html.erb +27 -0
- data/app/views/decidim/consultations/questions/_vote_modal_confirm.html.erb +33 -0
- data/app/views/decidim/consultations/questions/show.html.erb +58 -0
- data/app/views/layouts/decidim/_consultation_header.html.erb +16 -0
- data/app/views/layouts/decidim/_consultation_voting_data.html.erb +10 -0
- data/app/views/layouts/decidim/_question_components.html.erb +38 -0
- data/app/views/layouts/decidim/_question_header.html.erb +46 -0
- data/app/views/layouts/decidim/admin/consultation.html.erb +28 -0
- data/app/views/layouts/decidim/admin/consultations.html.erb +16 -0
- data/app/views/layouts/decidim/admin/question.html.erb +72 -0
- data/app/views/layouts/decidim/consultation.html.erb +17 -0
- data/app/views/layouts/decidim/consultation_choose.html.erb +7 -0
- data/app/views/layouts/decidim/question.html.erb +19 -0
- data/config/locales/ca.yml +248 -0
- data/config/locales/en.yml +249 -0
- data/config/locales/es.yml +248 -0
- data/config/locales/eu.yml +248 -0
- data/config/locales/fi.yml +248 -0
- data/config/locales/fr.yml +248 -0
- data/config/locales/gl.yml +248 -0
- data/config/locales/it.yml +248 -0
- data/config/locales/nl.yml +248 -0
- data/config/locales/pl.yml +258 -0
- data/config/locales/pt-BR.yml +248 -0
- data/config/locales/pt.yml +248 -0
- data/config/locales/ru.yml +6 -0
- data/config/locales/sv.yml +248 -0
- data/config/locales/uk.yml +6 -0
- data/db/migrate/20180109092205_create_decidim_consultations.rb +37 -0
- data/db/migrate/20180112053247_create_decidim_consultations_questions.rb +35 -0
- data/db/migrate/20180115132000_add_end_voting_date_to_decidim_consultations.rb +18 -0
- data/db/migrate/20180115170933_add_slug_to_decidim_consultations_questions.rb +32 -0
- data/db/migrate/20180119084217_create_decidim_consultations_votes.rb +17 -0
- data/db/migrate/20180119084331_add_votes_count_to_decidim_consultations_question.rb +7 -0
- data/db/migrate/20180122113155_add_origin_scope_to_decidim_consultations_questions.rb +8 -0
- data/db/migrate/20180122113400_add_origin_title_to_decidim_consultations_questions.rb +8 -0
- data/db/migrate/20180122113447_add_origin_string_to_decidim_consultations_questions.rb +7 -0
- data/db/migrate/20180126142459_add_enable_highlighted_banner_to_decidim_consultations.rb +7 -0
- data/db/migrate/20180129063438_add_i_frame_url_to_decidim_consultations_questions.rb +8 -0
- data/db/migrate/20180129063700_create_decidim_consultations_responses.rb +14 -0
- data/db/migrate/20180129122226_rename_decidim_consultations_vote_to_decidim_consultations_endorsement.rb +7 -0
- data/db/migrate/20180129122504_rename_decidim_consultations_questions_votes_count_to_endorsements_count.rb +7 -0
- data/db/migrate/20180130060754_add_responses_count_to_decidim_consultations_questions.rb +22 -0
- data/db/migrate/20180130110449_rename_vote_related_attributes.rb +9 -0
- data/db/migrate/20180130142018_add_decidim_user_group_id_to_decidim_consultations_endorsements.rb +7 -0
- data/db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb +36 -0
- data/db/migrate/20180131083844_add_response_to_decidim_consultations_endorsements.rb +10 -0
- data/db/migrate/20180201135823_rename_endorsement_to_vote.rb +23 -0
- data/db/migrate/20180202050920_add_hero_image_to_decidim_consultations_question.rb +8 -0
- data/db/migrate/20180202085309_add_results_published_at_to_decidim_consultations.rb +7 -0
- data/db/migrate/20180202133655_add_votes_count_to_decidim_consultations_response.rb +7 -0
- data/db/migrate/20180212100503_remove_enable_highlighted_banner_flag.rb +7 -0
- data/db/migrate/20180219092120_add_order_to_decidim_consultations_questions.rb +7 -0
- data/db/migrate/20180320100658_add_introductory_image_to_decidim_consultations.rb +7 -0
- data/db/seeds/Exampledocument.pdf +0 -0
- data/db/seeds/city.jpeg +0 -0
- data/db/seeds/city2.jpeg +0 -0
- data/db/seeds/homepage_image.jpg +0 -0
- data/lib/decidim/consultations.rb +18 -0
- data/lib/decidim/consultations/admin.rb +10 -0
- data/lib/decidim/consultations/admin_engine.rb +72 -0
- data/lib/decidim/consultations/engine.rb +83 -0
- data/lib/decidim/consultations/participatory_space.rb +171 -0
- data/lib/decidim/consultations/test/factories.rb +104 -0
- data/lib/decidim/consultations/version.rb +9 -0
- metadata +288 -0
data/app/controllers/decidim/consultations/admin/consultation_results_publications_controller.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing consultation result publications.
|
7
|
+
class ConsultationResultsPublicationsController < Decidim::Admin::ApplicationController
|
8
|
+
include ConsultationAdmin
|
9
|
+
|
10
|
+
def create
|
11
|
+
authorize! :publish_results, current_consultation
|
12
|
+
|
13
|
+
PublishConsultationResults.call(current_consultation) do
|
14
|
+
on(:ok) do
|
15
|
+
flash[:notice] = I18n.t("consultation_results_publications.create.success", scope: "decidim.admin")
|
16
|
+
end
|
17
|
+
|
18
|
+
on(:invalid) do
|
19
|
+
flash[:alert] = I18n.t("consultation_results_publications.create.error", scope: "decidim.admin")
|
20
|
+
end
|
21
|
+
|
22
|
+
redirect_back(fallback_location: consultations_path)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy
|
27
|
+
authorize! :unpublish_Results, current_consultation
|
28
|
+
|
29
|
+
UnpublishConsultationResults.call(current_consultation) do
|
30
|
+
on(:ok) do
|
31
|
+
flash[:notice] = I18n.t("consultation_results_publications.destroy.success", scope: "decidim.admin")
|
32
|
+
end
|
33
|
+
|
34
|
+
on(:invalid) do
|
35
|
+
flash[:alert] = I18n.t("consultation_results_publications.destroy.error", scope: "decidim.admin")
|
36
|
+
end
|
37
|
+
|
38
|
+
redirect_back(fallback_location: consultations_path)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# Controller in charge of managing consultation related requests
|
7
|
+
class ConsultationsController < Decidim::Consultations::Admin::ApplicationController
|
8
|
+
helper_method :current_consultation, :current_participatory_space
|
9
|
+
|
10
|
+
# GET /admin/consultations
|
11
|
+
def index
|
12
|
+
authorize! :index, Decidim::Consultation
|
13
|
+
@consultations = collection
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /admin/consultations/new
|
17
|
+
def new
|
18
|
+
authorize! :new, Consultation
|
19
|
+
@form = consultation_form.instance
|
20
|
+
end
|
21
|
+
|
22
|
+
# POST /admin/consultations
|
23
|
+
def create
|
24
|
+
authorize! :create, Consultation
|
25
|
+
@form = consultation_form.from_params(params)
|
26
|
+
|
27
|
+
CreateConsultation.call(@form) do
|
28
|
+
on(:ok) do
|
29
|
+
flash[:notice] = I18n.t("consultations.create.success", scope: "decidim.admin")
|
30
|
+
redirect_to consultations_path
|
31
|
+
end
|
32
|
+
|
33
|
+
on(:invalid) do
|
34
|
+
flash.now[:alert] = I18n.t("consultations.create.error", scope: "decidim.admin")
|
35
|
+
render :new
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# GET /admin/consultations/:slug/edit
|
41
|
+
def edit
|
42
|
+
authorize! :edit, current_consultation
|
43
|
+
@form = consultation_form.from_model(current_consultation)
|
44
|
+
render layout: "decidim/admin/consultation"
|
45
|
+
end
|
46
|
+
|
47
|
+
# PUT /admin/initiatives/:id
|
48
|
+
def update
|
49
|
+
authorize! :update, current_consultation
|
50
|
+
|
51
|
+
@form = consultation_form
|
52
|
+
.from_params(params.except(:slug), consultation_id: current_consultation.id)
|
53
|
+
|
54
|
+
UpdateConsultation.call(current_consultation, @form) do
|
55
|
+
on(:ok) do |consultation|
|
56
|
+
flash[:notice] = I18n.t("consultations.update.success", scope: "decidim.admin")
|
57
|
+
redirect_to edit_consultation_path(consultation)
|
58
|
+
end
|
59
|
+
|
60
|
+
on(:invalid) do
|
61
|
+
flash.now[:alert] = I18n.t("consultations.update.error", scope: "decidim.admin")
|
62
|
+
render :edit, layout: "decidim/admin/consultation"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def destroy
|
68
|
+
authorize! :destroy, current_consultation
|
69
|
+
current_consultation.destroy!
|
70
|
+
|
71
|
+
flash[:notice] = I18n.t("consultations.destroy.success", scope: "decidim.admin")
|
72
|
+
|
73
|
+
redirect_to consultations_path
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def current_consultation
|
79
|
+
@current_consultation ||= collection.where(slug: params[:slug]).or(
|
80
|
+
collection.where(id: params[:slug])
|
81
|
+
).first
|
82
|
+
end
|
83
|
+
|
84
|
+
alias current_participatory_space current_consultation
|
85
|
+
|
86
|
+
def collection
|
87
|
+
@collection ||= OrganizationConsultations.new(current_user.organization).query
|
88
|
+
end
|
89
|
+
|
90
|
+
def ability_context
|
91
|
+
super.merge(current_consultation: current_consultation)
|
92
|
+
end
|
93
|
+
|
94
|
+
def consultation_form
|
95
|
+
form(ConsultationForm)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing all the attachments for a question
|
7
|
+
class QuestionAttachmentsController < Decidim::Admin::ApplicationController
|
8
|
+
include QuestionAdmin
|
9
|
+
include Decidim::Admin::Concerns::HasAttachments
|
10
|
+
|
11
|
+
def after_destroy_path
|
12
|
+
decidim_admin_consultations.question_attachments_path(current_question)
|
13
|
+
end
|
14
|
+
|
15
|
+
def attached_to
|
16
|
+
current_question
|
17
|
+
end
|
18
|
+
|
19
|
+
def authorization_object
|
20
|
+
collection.find_by(id: params[:id]) || Decidim::Attachment
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing question publications.
|
7
|
+
class QuestionPublicationsController < Decidim::Admin::ApplicationController
|
8
|
+
include QuestionAdmin
|
9
|
+
|
10
|
+
def create
|
11
|
+
authorize! :publish, current_question
|
12
|
+
|
13
|
+
PublishQuestion.call(current_question) do
|
14
|
+
on(:ok) do
|
15
|
+
flash[:notice] = I18n.t("question_publications.create.success", scope: "decidim.admin")
|
16
|
+
end
|
17
|
+
|
18
|
+
on(:invalid) do
|
19
|
+
flash[:alert] = I18n.t("question_publications.create.error", scope: "decidim.admin")
|
20
|
+
end
|
21
|
+
|
22
|
+
redirect_back(fallback_location: consultation_questions_path(current_consultation))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy
|
27
|
+
authorize! :publish, current_question
|
28
|
+
|
29
|
+
UnpublishConsultation.call(current_question) do
|
30
|
+
on(:ok) do
|
31
|
+
flash[:notice] = I18n.t("question_publications.destroy.success", scope: "decidim.admin")
|
32
|
+
end
|
33
|
+
|
34
|
+
on(:invalid) do
|
35
|
+
flash[:alert] = I18n.t("question_publications.destroy.error", scope: "decidim.admin")
|
36
|
+
end
|
37
|
+
|
38
|
+
redirect_back(fallback_location: consultation_questions_path(current_consultation))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
class QuestionsController < Decidim::Consultations::Admin::ApplicationController
|
7
|
+
include QuestionAdmin
|
8
|
+
|
9
|
+
def index
|
10
|
+
authorize! :index, Decidim::Consultations::Question
|
11
|
+
@questions = collection
|
12
|
+
render layout: "decidim/admin/consultation"
|
13
|
+
end
|
14
|
+
|
15
|
+
def new
|
16
|
+
authorize! :new, Decidim::Consultations::Question
|
17
|
+
@form = question_form.instance
|
18
|
+
render layout: "decidim/admin/consultation"
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
authorize! :create, Decidim::Consultations::Question
|
23
|
+
@form = question_form.from_params(params, current_consultation: current_consultation)
|
24
|
+
|
25
|
+
CreateQuestion.call(@form) do
|
26
|
+
on(:ok) do
|
27
|
+
flash[:notice] = I18n.t("questions.create.success", scope: "decidim.admin")
|
28
|
+
redirect_to consultation_questions_path
|
29
|
+
end
|
30
|
+
|
31
|
+
on(:invalid) do
|
32
|
+
flash.now[:alert] = I18n.t("questions.create.error", scope: "decidim.admin")
|
33
|
+
render :new, layout: "decidim/admin/consultation"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def edit
|
39
|
+
authorize! :edit, current_question
|
40
|
+
@form = question_form.from_model(current_question, current_consultation: current_consultation)
|
41
|
+
render layout: "decidim/admin/question"
|
42
|
+
end
|
43
|
+
|
44
|
+
def update
|
45
|
+
authorize! :update, current_question
|
46
|
+
|
47
|
+
@form = question_form
|
48
|
+
.from_params(params, question_id: current_question.id, current_consultation: current_consultation)
|
49
|
+
|
50
|
+
UpdateQuestion.call(current_question, @form) do
|
51
|
+
on(:ok) do |question|
|
52
|
+
flash[:notice] = I18n.t("questions.update.success", scope: "decidim.admin")
|
53
|
+
redirect_to edit_question_path(question)
|
54
|
+
end
|
55
|
+
|
56
|
+
on(:invalid) do
|
57
|
+
flash.now[:alert] = I18n.t("questions.update.error", scope: "decidim.admin")
|
58
|
+
render :edit, layout: "decidim/admin/question"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def destroy
|
64
|
+
authorize! :destroy, current_question
|
65
|
+
current_question.destroy!
|
66
|
+
|
67
|
+
flash[:notice] = I18n.t("questions.destroy.success", scope: "decidim.admin")
|
68
|
+
|
69
|
+
redirect_to consultation_questions_path(current_consultation)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def collection
|
75
|
+
@collection ||= current_consultation&.questions
|
76
|
+
end
|
77
|
+
|
78
|
+
def ability_context
|
79
|
+
super.merge(current_consultation: current_consultation)
|
80
|
+
end
|
81
|
+
|
82
|
+
def question_form
|
83
|
+
form(QuestionForm)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# Controller that manages responses for a question
|
7
|
+
class ResponsesController < Decidim::Admin::ApplicationController
|
8
|
+
include QuestionAdmin
|
9
|
+
|
10
|
+
helper_method :current_response
|
11
|
+
|
12
|
+
def index
|
13
|
+
authorize! :index, Decidim::Consultations::Response
|
14
|
+
end
|
15
|
+
|
16
|
+
def new
|
17
|
+
authorize! :create, Decidim::Consultations::Response
|
18
|
+
@form = response_form.instance
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
authorize! :create, Decidim::Consultations::Response
|
23
|
+
@form = response_form.from_params(params, current_question: current_question)
|
24
|
+
|
25
|
+
CreateResponse.call(@form) do
|
26
|
+
on(:ok) do
|
27
|
+
flash[:notice] = I18n.t("responses.create.success", scope: "decidim.admin")
|
28
|
+
redirect_to responses_path(current_question)
|
29
|
+
end
|
30
|
+
|
31
|
+
on(:invalid) do
|
32
|
+
flash.now[:alert] = I18n.t("responses.create.error", scope: "decidim.admin")
|
33
|
+
render :new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def edit
|
39
|
+
authorize! :update, current_response
|
40
|
+
@form = response_form.from_model(current_response, current_question: current_question)
|
41
|
+
end
|
42
|
+
|
43
|
+
def update
|
44
|
+
authorize! :update, current_response
|
45
|
+
|
46
|
+
@form = response_form.from_params(params, current_question: current_question)
|
47
|
+
UpdateResponse.call(current_response, @form) do
|
48
|
+
on(:ok) do
|
49
|
+
flash[:notice] = I18n.t("responses.update.success", scope: "decidim.admin")
|
50
|
+
redirect_to responses_path(current_question)
|
51
|
+
end
|
52
|
+
|
53
|
+
on(:invalid) do
|
54
|
+
flash.now[:alert] = I18n.t("responses.update.error", scope: "decidim.admin")
|
55
|
+
render :edit
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def destroy
|
61
|
+
authorize! :destroy, current_response
|
62
|
+
|
63
|
+
current_response.destroy
|
64
|
+
if current_response.valid?
|
65
|
+
flash[:notice] = I18n.t("responses.destroy.success", scope: "decidim.admin")
|
66
|
+
redirect_to responses_path(current_question)
|
67
|
+
else
|
68
|
+
flash.now[:alert] = I18n.t("responses.destroy.error", scope: "decidim.admin")
|
69
|
+
render :edit
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def current_response
|
76
|
+
@current_response ||= Response.find_by(id: params[:id])
|
77
|
+
end
|
78
|
+
|
79
|
+
def response_form
|
80
|
+
form(ResponseForm)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
class ConsultationWidgetsController < Decidim::WidgetsController
|
6
|
+
helper Decidim::SanitizeHelper
|
7
|
+
|
8
|
+
layout false
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def model
|
13
|
+
@model ||= Consultation.find_by(slug: params[:consultation_slug])
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_participatory_space
|
17
|
+
model
|
18
|
+
end
|
19
|
+
|
20
|
+
def iframe_url
|
21
|
+
@iframe_url ||= consultation_consultation_widget_url(model)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
# A controller that holds the logic to show consultations in a
|
6
|
+
# public layout.
|
7
|
+
class ConsultationsController < Decidim::ApplicationController
|
8
|
+
layout "layouts/decidim/consultation", only: :show
|
9
|
+
|
10
|
+
include NeedsConsultation
|
11
|
+
include FilterResource
|
12
|
+
include Paginable
|
13
|
+
include Orderable
|
14
|
+
|
15
|
+
helper_method :collection, :consultations, :finished_consultations, :active_consultations, :filter
|
16
|
+
|
17
|
+
helper Decidim::FiltersHelper
|
18
|
+
helper Decidim::OrdersHelper
|
19
|
+
helper Decidim::SanitizeHelper
|
20
|
+
helper Decidim::PaginateHelper
|
21
|
+
helper Decidim::IconHelper
|
22
|
+
helper Decidim::WidgetUrlsHelper
|
23
|
+
|
24
|
+
def index
|
25
|
+
authorize! :read, Consultation
|
26
|
+
redirect_to consultation_path(active_consultations.first) if active_consultations.count == 1
|
27
|
+
end
|
28
|
+
|
29
|
+
def show
|
30
|
+
authorize! :read, current_consultation
|
31
|
+
end
|
32
|
+
|
33
|
+
def finished
|
34
|
+
authorize! :read, Consultation
|
35
|
+
render layout: "layouts/decidim/consultation_choose"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def finished_consultations
|
41
|
+
@finished_consultations ||= OrganizationConsultations.for(current_organization).finished.published
|
42
|
+
end
|
43
|
+
|
44
|
+
def active_consultations
|
45
|
+
@active_consultations ||= OrganizationConsultations.for(current_organization).active.published
|
46
|
+
end
|
47
|
+
|
48
|
+
def consultations
|
49
|
+
@consultations = search.results
|
50
|
+
@consultations = reorder(@consultations)
|
51
|
+
@consultations = paginate(@consultations)
|
52
|
+
end
|
53
|
+
|
54
|
+
alias collection consultations
|
55
|
+
|
56
|
+
def search_klass
|
57
|
+
ConsultationSearch
|
58
|
+
end
|
59
|
+
|
60
|
+
def default_filter_params
|
61
|
+
{
|
62
|
+
search_text: "",
|
63
|
+
state: "all"
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def context_params
|
68
|
+
{
|
69
|
+
organization: current_organization,
|
70
|
+
current_user: current_user
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|