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
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
# This class infers the current component on an consultation context
|
6
|
+
# request parameters and injects it into the environment.
|
7
|
+
class CurrentComponent
|
8
|
+
# Public: Initializes the class.
|
9
|
+
#
|
10
|
+
# manifest - The manifest of the component to check against.
|
11
|
+
def initialize(manifest)
|
12
|
+
@manifest = manifest
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: Matches the request against a component and injects it into the
|
16
|
+
# environment.
|
17
|
+
#
|
18
|
+
# request - The request that holds the current component relevant information.
|
19
|
+
#
|
20
|
+
# Returns a true if the request matches a consultation and a
|
21
|
+
# component belonging to that consultation, false otherwise
|
22
|
+
def matches?(request)
|
23
|
+
CurrentQuestion.new.matches?(request) &&
|
24
|
+
Decidim::CurrentComponent.new(@manifest).matches?(request)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
# This class infers the current consultation we're scoped to by
|
6
|
+
# looking at the request parameters and the organization in the request
|
7
|
+
# environment, and injects it into the environment.
|
8
|
+
class CurrentQuestion
|
9
|
+
# Public: Matches the request against a question and injects it
|
10
|
+
# into the environment.
|
11
|
+
#
|
12
|
+
# request - The request that holds the question relevant
|
13
|
+
# information.
|
14
|
+
#
|
15
|
+
# Returns a true if the request matched, false otherwise
|
16
|
+
def matches?(request)
|
17
|
+
env = request.env
|
18
|
+
|
19
|
+
@organization = env["decidim.current_organization"]
|
20
|
+
return false unless @organization
|
21
|
+
|
22
|
+
current_question(env, request.params) ? true : false
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def current_question(env, params)
|
28
|
+
env["decidim.current_participatory_space"] ||= detect_current_question(params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def detect_current_question(params)
|
32
|
+
Decidim::Consultations::Question.find_by(slug: params[:question_slug], organization: @organization)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Consultations
|
7
|
+
module ActionAuthorization
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
helper_method :action_authorization
|
12
|
+
end
|
13
|
+
|
14
|
+
# Public: Returns the authorization object for an authorization.
|
15
|
+
#
|
16
|
+
# action_name - The action to authorize against.
|
17
|
+
#
|
18
|
+
# Returns an AuthorizationStatus
|
19
|
+
def action_authorization(action_name)
|
20
|
+
return AuthorizationStatus.new(:ok) if can?(action_name.to_sym, Question)
|
21
|
+
|
22
|
+
AuthorizationStatus.new(:denied)
|
23
|
+
end
|
24
|
+
|
25
|
+
class AuthorizationStatus
|
26
|
+
attr_reader :code
|
27
|
+
|
28
|
+
def initialize(code)
|
29
|
+
@code = code.to_sym
|
30
|
+
end
|
31
|
+
|
32
|
+
def ok?
|
33
|
+
@code == :ok
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Consultations
|
7
|
+
module Admin
|
8
|
+
# This concern is meant to be included in all controllers that are scoped
|
9
|
+
# into an consultation's admin panel. It will override the layout so it shows
|
10
|
+
# the sidebar, preload the consultation, etc.
|
11
|
+
module ConsultationAdmin
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
include NeedsConsultation
|
16
|
+
|
17
|
+
layout "decidim/admin/consultation"
|
18
|
+
|
19
|
+
alias_method :current_participatory_space, :current_consultation
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Consultations
|
7
|
+
module Admin
|
8
|
+
# This concern is meant to be included in all controllers that are scoped
|
9
|
+
# into an question's admin panel. It will override the layout so it shows
|
10
|
+
# the sidebar, preload the consultation, etc.
|
11
|
+
module QuestionAdmin
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
include NeedsQuestion
|
16
|
+
|
17
|
+
include Decidim::Admin::ParticipatorySpaceAdminContext
|
18
|
+
participatory_space_admin_layout
|
19
|
+
|
20
|
+
def current_participatory_space
|
21
|
+
return current_consultation if params.has_key? :consultation_slug
|
22
|
+
current_question
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
# This module, when injected into a controller, ensures there's a
|
6
|
+
# consultation available and deducts it from the context.
|
7
|
+
module NeedsConsultation
|
8
|
+
def self.enhance_controller(instance_or_module)
|
9
|
+
instance_or_module.class_eval do
|
10
|
+
helper_method :current_consultation
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.extended(base)
|
15
|
+
base.extend Decidim::NeedsOrganization, InstanceMethods
|
16
|
+
|
17
|
+
enhance_controller(base)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.included(base)
|
21
|
+
base.include Decidim::NeedsOrganization, InstanceMethods
|
22
|
+
|
23
|
+
enhance_controller(base)
|
24
|
+
end
|
25
|
+
|
26
|
+
module InstanceMethods
|
27
|
+
# Public: Finds the current Consultation given this controller's
|
28
|
+
# context.
|
29
|
+
#
|
30
|
+
# Returns the current Consultation.
|
31
|
+
def current_consultation
|
32
|
+
@current_consultation ||= detect_consultation
|
33
|
+
end
|
34
|
+
|
35
|
+
alias current_participatory_space current_consultation
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def ability_context
|
40
|
+
super.merge(current_consultation: current_consultation)
|
41
|
+
end
|
42
|
+
|
43
|
+
def detect_consultation
|
44
|
+
request.env["current_consultation"] ||
|
45
|
+
organization_consultations.find_by(slug: params[:consultation_slug] || params[:slug])
|
46
|
+
end
|
47
|
+
|
48
|
+
def organization_consultations
|
49
|
+
@organization_consultations ||= OrganizationConsultations.new(current_organization).query
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
# This module, when injected into a controller, ensures there's a
|
6
|
+
# question available and deducts it from the context.
|
7
|
+
module NeedsQuestion
|
8
|
+
def self.enhance_controller(instance_or_module)
|
9
|
+
instance_or_module.class_eval do
|
10
|
+
helper_method :current_question, :current_consultation, :current_participatory_space, :stats,
|
11
|
+
:sorted_results
|
12
|
+
|
13
|
+
helper Decidim::WidgetUrlsHelper
|
14
|
+
helper Decidim::ActionAuthorizationHelper
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.extended(base)
|
19
|
+
base.extend Decidim::NeedsOrganization, InstanceMethods
|
20
|
+
base.include Decidim::Consultations::ActionAuthorization
|
21
|
+
|
22
|
+
enhance_controller(base)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(base)
|
26
|
+
base.include Decidim::NeedsOrganization, InstanceMethods, Decidim::Consultations::ActionAuthorization
|
27
|
+
|
28
|
+
enhance_controller(base)
|
29
|
+
end
|
30
|
+
|
31
|
+
module InstanceMethods
|
32
|
+
# Public: Finds the current Question given this controller's
|
33
|
+
# context.
|
34
|
+
#
|
35
|
+
# Returns the current Question.
|
36
|
+
def current_question
|
37
|
+
@current_question ||= detect_question
|
38
|
+
end
|
39
|
+
|
40
|
+
# Public: Finds the current Consultation given this controller's
|
41
|
+
# context.
|
42
|
+
#
|
43
|
+
# Returns the current Consultation.
|
44
|
+
def current_consultation
|
45
|
+
@current_consultation ||= current_question&.consultation || detect_consultation
|
46
|
+
end
|
47
|
+
|
48
|
+
alias current_participatory_space current_question
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def ability_context
|
53
|
+
super.merge(
|
54
|
+
current_question: current_question,
|
55
|
+
current_consultation: current_consultation
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def detect_question
|
60
|
+
request.env["current_question"] ||
|
61
|
+
OrganizationQuestions.for(current_organization).find_by(slug: params[:question_slug] || params[:slug])
|
62
|
+
end
|
63
|
+
|
64
|
+
def detect_consultation
|
65
|
+
request.env["current_consultation"] ||
|
66
|
+
organization_consultations.find_by(slug: params[:consultation_slug])
|
67
|
+
end
|
68
|
+
|
69
|
+
def organization_consultations
|
70
|
+
@organization_consultations ||= OrganizationConsultations.new(current_organization).query
|
71
|
+
end
|
72
|
+
|
73
|
+
def stats
|
74
|
+
@stats ||= QuestionStatsPresenter.new(question: current_question)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Consultations
|
7
|
+
# Common logic to ordering resources
|
8
|
+
module Orderable
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
helper_method :order, :available_orders, :random_seed
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# Gets how the proposals should be ordered based on the choice
|
17
|
+
# made by the user.
|
18
|
+
def order
|
19
|
+
@order ||= detect_order(params[:order]) || default_order
|
20
|
+
end
|
21
|
+
|
22
|
+
def detect_order(candidate)
|
23
|
+
available_orders.detect { |order| order == candidate }
|
24
|
+
end
|
25
|
+
|
26
|
+
# Available orders based on enabled settings
|
27
|
+
def available_orders
|
28
|
+
%w(random recent)
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_order
|
32
|
+
"random"
|
33
|
+
end
|
34
|
+
|
35
|
+
def reorder(consultations)
|
36
|
+
case order
|
37
|
+
when "recent"
|
38
|
+
consultations.order_by_most_recent
|
39
|
+
else
|
40
|
+
consultations.order_randomly(random_seed)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns: A random float number between -1 and 1 to be used as a
|
45
|
+
# random seed at the database.
|
46
|
+
def random_seed
|
47
|
+
@random_seed ||= (params[:random_seed] ? params[:random_seed].to_f : (rand * 2 - 1))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# The main admin application controller for consultations
|
7
|
+
class ApplicationController < Decidim::Admin::ApplicationController
|
8
|
+
layout "decidim/admin/consultations"
|
9
|
+
|
10
|
+
helper Decidim::SanitizeHelper
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing categories for questions.
|
7
|
+
#
|
8
|
+
class CategoriesController < Decidim::Admin::CategoriesController
|
9
|
+
include QuestionAdmin
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing the Consultation Component
|
7
|
+
# permissions in the admin panel.
|
8
|
+
class ComponentPermissionsController < Decidim::Admin::ComponentPermissionsController
|
9
|
+
include QuestionAdmin
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing the Question's Components in the
|
7
|
+
# admin panel.
|
8
|
+
class ComponentsController < Decidim::Admin::ComponentsController
|
9
|
+
include QuestionAdmin
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
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 consultation publications.
|
7
|
+
class ConsultationPublicationsController < Decidim::Admin::ApplicationController
|
8
|
+
include ConsultationAdmin
|
9
|
+
|
10
|
+
def create
|
11
|
+
authorize! :publish, current_consultation
|
12
|
+
|
13
|
+
PublishConsultation.call(current_consultation) do
|
14
|
+
on(:ok) do
|
15
|
+
flash[:notice] = I18n.t("consultation_publications.create.success", scope: "decidim.admin")
|
16
|
+
end
|
17
|
+
|
18
|
+
on(:invalid) do
|
19
|
+
flash[:alert] = I18n.t("consultation_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! :publish, current_consultation
|
28
|
+
|
29
|
+
UnpublishConsultation.call(current_consultation) do
|
30
|
+
on(:ok) do
|
31
|
+
flash[:notice] = I18n.t("consultation_publications.destroy.success", scope: "decidim.admin")
|
32
|
+
end
|
33
|
+
|
34
|
+
on(:invalid) do
|
35
|
+
flash[:alert] = I18n.t("consultation_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
|