decidim-challenges 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE-AGPLv3.txt +661 -0
- data/README.md +49 -0
- data/Rakefile +9 -0
- data/app/cells/decidim/challenges/challenge_cell.rb +21 -0
- data/app/cells/decidim/challenges/challenge_g/show.erb +47 -0
- data/app/cells/decidim/challenges/challenge_g_cell.rb +69 -0
- data/app/cells/decidim/problems/problem_cell.rb +21 -0
- data/app/cells/decidim/problems/problem_g/show.erb +35 -0
- data/app/cells/decidim/problems/problem_g_cell.rb +61 -0
- data/app/cells/decidim/solutions/solution_cell.rb +21 -0
- data/app/cells/decidim/solutions/solution_g/show.erb +30 -0
- data/app/cells/decidim/solutions/solution_g_cell.rb +84 -0
- data/app/commands/decidim/challenges/admin/create_challenge.rb +67 -0
- data/app/commands/decidim/challenges/admin/destroy_challenge.rb +49 -0
- data/app/commands/decidim/challenges/admin/export_challenge_surveys.rb +45 -0
- data/app/commands/decidim/challenges/admin/publish_challenge.rb +40 -0
- data/app/commands/decidim/challenges/admin/unpublish_challenge.rb +40 -0
- data/app/commands/decidim/challenges/admin/update_challenge.rb +72 -0
- data/app/commands/decidim/challenges/admin/update_surveys.rb +43 -0
- data/app/commands/decidim/challenges/survey_challenge.rb +67 -0
- data/app/commands/decidim/command_utils.rb +20 -0
- data/app/commands/decidim/problems/admin/create_problem.rb +66 -0
- data/app/commands/decidim/problems/admin/destroy_problem.rb +49 -0
- data/app/commands/decidim/problems/admin/publish_problem.rb +40 -0
- data/app/commands/decidim/problems/admin/unpublish_problem.rb +40 -0
- data/app/commands/decidim/problems/admin/update_problem.rb +69 -0
- data/app/commands/decidim/solutions/admin/create_solution.rb +65 -0
- data/app/commands/decidim/solutions/admin/destroy_solution.rb +43 -0
- data/app/commands/decidim/solutions/admin/publish_solution.rb +40 -0
- data/app/commands/decidim/solutions/admin/unpublish_solution.rb +40 -0
- data/app/commands/decidim/solutions/admin/update_solution.rb +67 -0
- data/app/commands/decidim/solutions/create_solution.rb +67 -0
- data/app/controllers/concerns/decidim/challenges/admin/filterable.rb +27 -0
- data/app/controllers/concerns/decidim/challenges/orderable_challenges.rb +37 -0
- data/app/controllers/concerns/decidim/problems/admin/filterable.rb +27 -0
- data/app/controllers/concerns/decidim/problems/orderable_problems.rb +37 -0
- data/app/controllers/concerns/decidim/solutions/admin/filterable.rb +27 -0
- data/app/controllers/concerns/decidim/solutions/orderable_solutions.rb +37 -0
- data/app/controllers/concerns/decidim/with_default_filters.rb +23 -0
- data/app/controllers/concerns/decidim/with_sdgs.rb +19 -0
- data/app/controllers/decidim/challenges/admin/application_controller.rb +15 -0
- data/app/controllers/decidim/challenges/admin/challenge_publications_controller.rb +53 -0
- data/app/controllers/decidim/challenges/admin/challenges_controller.rb +108 -0
- data/app/controllers/decidim/challenges/admin/survey_form_controller.rb +43 -0
- data/app/controllers/decidim/challenges/admin/surveys_controller.rb +104 -0
- data/app/controllers/decidim/challenges/application_controller.rb +13 -0
- data/app/controllers/decidim/challenges/challenges_controller.rb +70 -0
- data/app/controllers/decidim/challenges/surveys_controller.rb +61 -0
- data/app/controllers/decidim/problems/admin/application_controller.rb +15 -0
- data/app/controllers/decidim/problems/admin/problem_publications_controller.rb +53 -0
- data/app/controllers/decidim/problems/admin/problems_controller.rb +102 -0
- data/app/controllers/decidim/problems/application_controller.rb +13 -0
- data/app/controllers/decidim/problems/problems_controller.rb +62 -0
- data/app/controllers/decidim/sdgs/admin/application_controller.rb +15 -0
- data/app/controllers/decidim/sdgs/admin/sdgs_controller.rb +18 -0
- data/app/controllers/decidim/sdgs/application_controller.rb +13 -0
- data/app/controllers/decidim/sdgs/sdgs_controller.rb +24 -0
- data/app/controllers/decidim/solutions/admin/application_controller.rb +15 -0
- data/app/controllers/decidim/solutions/admin/solution_publications_controller.rb +53 -0
- data/app/controllers/decidim/solutions/admin/solutions_controller.rb +106 -0
- data/app/controllers/decidim/solutions/application_controller.rb +13 -0
- data/app/controllers/decidim/solutions/solutions_controller.rb +115 -0
- data/app/forms/decidim/challenges/admin/challenge_surveys_form.rb +35 -0
- data/app/forms/decidim/challenges/admin/challenges_form.rb +78 -0
- data/app/forms/decidim/problems/admin/problems_form.rb +90 -0
- data/app/forms/decidim/solutions/admin/solutions_form.rb +71 -0
- data/app/forms/decidim/solutions/solutions_form.rb +50 -0
- data/app/helpers/decidim/challenges/application_helper.rb +25 -0
- data/app/helpers/decidim/challenges/challenge_cells_helper.rb +57 -0
- data/app/helpers/decidim/challenges/challenges_helper.rb +39 -0
- data/app/helpers/decidim/problems/application_helper.rb +10 -0
- data/app/helpers/decidim/problems/problem_cells_helper.rb +23 -0
- data/app/helpers/decidim/problems/problems_helper.rb +24 -0
- data/app/helpers/decidim/sdgs/sdgs_helper.rb +28 -0
- data/app/helpers/decidim/show_filters_helper.rb +13 -0
- data/app/helpers/decidim/solutions/application_helper.rb +27 -0
- data/app/helpers/decidim/solutions/solution_cells_helper.rb +56 -0
- data/app/helpers/decidim/solutions/solutions_helper.rb +21 -0
- data/app/models/decidim/application_record.rb +8 -0
- data/app/models/decidim/challenges/challenge.rb +82 -0
- data/app/models/decidim/challenges/survey.rb +19 -0
- data/app/models/decidim/problems/problem.rb +118 -0
- data/app/models/decidim/sdgs/sdg.rb +47 -0
- data/app/models/decidim/solutions/application_record.rb +10 -0
- data/app/models/decidim/solutions/solution.rb +69 -0
- data/app/packs/entrypoints/decidim_challenges.js +4 -0
- data/app/packs/entrypoints/decidim_challenges.scss +1 -0
- data/app/packs/entrypoints/decidim_problems.js +1 -0
- data/app/packs/entrypoints/decidim_problems.scss +1 -0
- data/app/packs/entrypoints/decidim_sdgs.js +6 -0
- data/app/packs/entrypoints/decidim_sdgs.scss +3 -0
- data/app/packs/entrypoints/decidim_shared.js +1 -0
- data/app/packs/entrypoints/decidim_shared.scss +1 -0
- data/app/packs/entrypoints/decidim_solutions.js +4 -0
- data/app/packs/entrypoints/decidim_solutions.scss +1 -0
- data/app/packs/fonts/Oswald-Medium.ttf +0 -0
- data/app/packs/images/decidim/challenges/decidim_challenges_icon.svg +1 -0
- data/app/packs/images/decidim/sdgs/ods-01.svg +11 -0
- data/app/packs/images/decidim/sdgs/ods-02.svg +11 -0
- data/app/packs/images/decidim/sdgs/ods-03.svg +11 -0
- data/app/packs/images/decidim/sdgs/ods-04.svg +12 -0
- data/app/packs/images/decidim/sdgs/ods-05.svg +12 -0
- data/app/packs/images/decidim/sdgs/ods-06.svg +20 -0
- data/app/packs/images/decidim/sdgs/ods-07.svg +18 -0
- data/app/packs/images/decidim/sdgs/ods-08.svg +13 -0
- data/app/packs/images/decidim/sdgs/ods-09.svg +25 -0
- data/app/packs/images/decidim/sdgs/ods-10.svg +13 -0
- data/app/packs/images/decidim/sdgs/ods-11.svg +41 -0
- data/app/packs/images/decidim/sdgs/ods-12.svg +11 -0
- data/app/packs/images/decidim/sdgs/ods-13.svg +57 -0
- data/app/packs/images/decidim/sdgs/ods-14.svg +14 -0
- data/app/packs/images/decidim/sdgs/ods-15.svg +11 -0
- data/app/packs/images/decidim/sdgs/ods-16.svg +14 -0
- data/app/packs/images/decidim/sdgs/ods-17.svg +39 -0
- data/app/packs/images/decidim/sdgs/sdg-wheel.png +0 -0
- data/app/packs/images/decidim/sdgs/un_emblem_square.png +0 -0
- data/app/packs/src/decidim/challenges/add_challenge.js +3 -0
- data/app/packs/src/decidim/challenges/admin/challenges_form.js +3 -0
- data/app/packs/src/decidim/sdgs/filter.js +75 -0
- data/app/packs/stylesheets/decidim/challenges/challenges.scss +3 -0
- data/app/packs/stylesheets/decidim/problems/problems.scss +3 -0
- data/app/packs/stylesheets/decidim/sdgs/ods.scss +185 -0
- data/app/packs/stylesheets/decidim/sdgs/sdgs_filter/button.scss +27 -0
- data/app/packs/stylesheets/decidim/sdgs/sdgs_filter/modal.scss +60 -0
- data/app/packs/stylesheets/decidim/shared/_cards.scss +52 -0
- data/app/packs/stylesheets/decidim/shared/base.scss +9 -0
- data/app/packs/stylesheets/decidim/solutions/solutions.scss +3 -0
- data/app/permissions/decidim/challenges/admin/permissions.rb +88 -0
- data/app/permissions/decidim/challenges/permissions.rb +27 -0
- data/app/permissions/decidim/problems/admin/permissions.rb +52 -0
- data/app/permissions/decidim/problems/permissions.rb +16 -0
- data/app/permissions/decidim/solutions/admin/permissions.rb +58 -0
- data/app/permissions/decidim/solutions/permissions.rb +17 -0
- data/app/presenters/decidim/challenges/challenge_presenter.rb +134 -0
- data/app/presenters/decidim/problems/problem_presenter.rb +108 -0
- data/app/presenters/decidim/solutions/solution_presenter.rb +198 -0
- data/app/serializers/decidim/challenges/data_serializer.rb +46 -0
- data/app/serializers/decidim/challenges/survey_serializer.rb +37 -0
- data/app/types/decidim/challenges/challenge_type.rb +28 -0
- data/app/types/decidim/challenges/challenges_type.rb +32 -0
- data/app/types/decidim/problems/problem_type.rb +29 -0
- data/app/types/decidim/problems/problems_type.rb +32 -0
- data/app/types/decidim/solutions/solution_type.rb +25 -0
- data/app/types/decidim/solutions/solutions_type.rb +32 -0
- data/app/views/decidim/challenges/admin/challenges/_form.html.erb +78 -0
- data/app/views/decidim/challenges/admin/challenges/edit.html.erb +24 -0
- data/app/views/decidim/challenges/admin/challenges/index.html.erb +88 -0
- data/app/views/decidim/challenges/admin/challenges/new.html.erb +18 -0
- data/app/views/decidim/challenges/admin/surveys/_form.html.erb +9 -0
- data/app/views/decidim/challenges/admin/surveys/edit.html.erb +39 -0
- data/app/views/decidim/challenges/admin/surveys/index.html.erb +49 -0
- data/app/views/decidim/challenges/admin/surveys/show.html.erb +43 -0
- data/app/views/decidim/challenges/challenges/_challenge.html.erb +1 -0
- data/app/views/decidim/challenges/challenges/_challenges.html.erb +11 -0
- data/app/views/decidim/challenges/challenges/_related_problems.html.erb +14 -0
- data/app/views/decidim/challenges/challenges/_sidebar_data.html.erb +60 -0
- data/app/views/decidim/challenges/challenges/index.html.erb +29 -0
- data/app/views/decidim/challenges/challenges/index.js.erb +5 -0
- data/app/views/decidim/challenges/challenges/show.html.erb +41 -0
- data/app/views/decidim/problems/admin/problems/_form.html.erb +79 -0
- data/app/views/decidim/problems/admin/problems/edit.html.erb +24 -0
- data/app/views/decidim/problems/admin/problems/index.html.erb +93 -0
- data/app/views/decidim/problems/admin/problems/new.html.erb +18 -0
- data/app/views/decidim/problems/problems/_problem.html.erb +1 -0
- data/app/views/decidim/problems/problems/_problems.html.erb +11 -0
- data/app/views/decidim/problems/problems/_sidebar_data.html.erb +70 -0
- data/app/views/decidim/problems/problems/index.html.erb +28 -0
- data/app/views/decidim/problems/problems/index.js.erb +5 -0
- data/app/views/decidim/problems/problems/show.html.erb +38 -0
- data/app/views/decidim/sdgs/sdgs/_objectives.html.erb +320 -0
- data/app/views/decidim/sdgs/sdgs/_ods.html.erb +132 -0
- data/app/views/decidim/sdgs/sdgs/index.html.erb +64 -0
- data/app/views/decidim/sdgs/sdgs_filter/_filter_selector.html.erb +7 -0
- data/app/views/decidim/sdgs/sdgs_filter/_modal.html.erb +35 -0
- data/app/views/decidim/shared/_related_solutions.html.erb +14 -0
- data/app/views/decidim/solutions/admin/solutions/_documents.html.erb +13 -0
- data/app/views/decidim/solutions/admin/solutions/_form.html.erb +70 -0
- data/app/views/decidim/solutions/admin/solutions/_photos.html.erb +13 -0
- data/app/views/decidim/solutions/admin/solutions/edit.html.erb +24 -0
- data/app/views/decidim/solutions/admin/solutions/index.html.erb +97 -0
- data/app/views/decidim/solutions/admin/solutions/new.html.erb +18 -0
- data/app/views/decidim/solutions/admin/solutions/show.html.erb +114 -0
- data/app/views/decidim/solutions/solutions/_form.html.erb +22 -0
- data/app/views/decidim/solutions/solutions/_sidebar_data.html.erb +114 -0
- data/app/views/decidim/solutions/solutions/_solution.html.erb +1 -0
- data/app/views/decidim/solutions/solutions/_solutions.html.erb +13 -0
- data/app/views/decidim/solutions/solutions/index.html.erb +37 -0
- data/app/views/decidim/solutions/solutions/index.js.erb +5 -0
- data/app/views/decidim/solutions/solutions/new.html.erb +20 -0
- data/app/views/decidim/solutions/solutions/show.html.erb +72 -0
- data/config/assets.rb +27 -0
- data/config/i18n-tasks.yml +10 -0
- data/config/locales/ca.yml +1244 -0
- data/config/locales/cs.yml +668 -0
- data/config/locales/en.yml +1245 -0
- data/config/locales/es.yml +1250 -0
- data/config/locales/oc.yml +1229 -0
- data/db/migrate/20201014125000_create_decidim_challenges_challenges.rb +23 -0
- data/db/migrate/20201103155100_create_decidim_problems_problems.rb +25 -0
- data/db/migrate/20201116111200_create_decidim_solutions_solutions.rb +21 -0
- data/db/migrate/20210413083244_create_decidim_challenges_surveys.rb +14 -0
- data/db/migrate/20210413083507_add_survey_attributes_to_challenges.rb +7 -0
- data/db/migrate/20210413083604_add_questionnaire_to_existing_challenges.rb +15 -0
- data/db/migrate/20210413112229_add_challenge_reference_to_solutions.rb +7 -0
- data/db/migrate/20210427091033_remove_require_null_in_problems_for_solutions.rb +7 -0
- data/db/migrate/20220407110503_add_card_image_to_challenges.rb +7 -0
- data/db/migrate/20240919094714_add_public_fields_to_solutions.rb +10 -0
- data/lib/decidim/challenges/admin.rb +10 -0
- data/lib/decidim/challenges/admin_engine.rb +37 -0
- data/lib/decidim/challenges/component.rb +65 -0
- data/lib/decidim/challenges/engine.rb +39 -0
- data/lib/decidim/challenges/test/factories.rb +59 -0
- data/lib/decidim/challenges/version.rb +14 -0
- data/lib/decidim/challenges.rb +13 -0
- data/lib/decidim/problems/admin.rb +10 -0
- data/lib/decidim/problems/admin_engine.rb +25 -0
- data/lib/decidim/problems/component.rb +51 -0
- data/lib/decidim/problems/engine.rb +31 -0
- data/lib/decidim/problems/test/factories.rb +39 -0
- data/lib/decidim/sdgs/admin.rb +10 -0
- data/lib/decidim/sdgs/admin_engine.rb +28 -0
- data/lib/decidim/sdgs/component.rb +44 -0
- data/lib/decidim/sdgs/engine.rb +23 -0
- data/lib/decidim/sdgs/test/factories.rb +13 -0
- data/lib/decidim/solutions/admin.rb +10 -0
- data/lib/decidim/solutions/admin_engine.rb +25 -0
- data/lib/decidim/solutions/component.rb +52 -0
- data/lib/decidim/solutions/engine.rb +31 -0
- data/lib/decidim/solutions/test/factories.rb +28 -0
- metadata +316 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
module Admin
|
6
|
+
# This controller allows an admin to manage surveys from a challenge
|
7
|
+
class SurveysController < Admin::ApplicationController
|
8
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaireAnswers
|
9
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaire
|
10
|
+
|
11
|
+
def index
|
12
|
+
enforce_permission_to :index, :questionnaire_answers
|
13
|
+
|
14
|
+
@query = paginate(collection)
|
15
|
+
@participants = participants(@query)
|
16
|
+
@total = participants_query.count_participants
|
17
|
+
end
|
18
|
+
|
19
|
+
def show
|
20
|
+
enforce_permission_to :show, :questionnaire_answers
|
21
|
+
|
22
|
+
@participant = participant(participants_query.participant(params[:session_token]))
|
23
|
+
end
|
24
|
+
|
25
|
+
def edit
|
26
|
+
enforce_permission_to(:edit, :challenge, challenge:)
|
27
|
+
|
28
|
+
@form = ChallengeSurveysForm.from_model(challenge)
|
29
|
+
end
|
30
|
+
|
31
|
+
def update
|
32
|
+
enforce_permission_to(:edit, :challenge, challenge:)
|
33
|
+
|
34
|
+
@form = ChallengeSurveysForm.from_params(params).with_context(current_organization: challenge.organization, challenge:)
|
35
|
+
|
36
|
+
UpdateSurveys.call(@form, challenge) do
|
37
|
+
on(:ok) do
|
38
|
+
flash[:notice] = I18n.t("surveys.update.success", scope: "decidim.challenges.admin")
|
39
|
+
redirect_to challenges_path
|
40
|
+
end
|
41
|
+
|
42
|
+
on(:invalid) do
|
43
|
+
flash.now[:alert] = I18n.t("surveys.update.invalid", scope: "decidim.challenges.admin")
|
44
|
+
render action: "edit"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def export
|
50
|
+
enforce_permission_to(:export_surveys, :challenge, challenge:)
|
51
|
+
|
52
|
+
ExportChallengeSurveys.call(challenge, params[:format], current_user) do
|
53
|
+
on(:ok) do |export_data|
|
54
|
+
send_data export_data.read, type: "text/#{export_data.extension}", filename: export_data.filename("registrations")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def export_response
|
60
|
+
enforce_permission_to :export_answers, :questionnaire
|
61
|
+
|
62
|
+
session_token = params[:session_token]
|
63
|
+
answers = Decidim::Forms::QuestionnaireUserAnswers.for(questionnaire)
|
64
|
+
title = t("export_response.title", scope: i18n_scope, token: session_token)
|
65
|
+
Decidim::Forms::ExportQuestionnaireAnswersJob.perform_later(current_user, title, answers.select { |a| a.first.session_token == session_token })
|
66
|
+
|
67
|
+
flash[:notice] = t("decidim.admin.exports.notice")
|
68
|
+
|
69
|
+
redirect_back(fallback_location: questionnaire_participant_answers_url(session_token))
|
70
|
+
end
|
71
|
+
|
72
|
+
def questionnaire_participants_url
|
73
|
+
index_answers_challenge_surveys_path
|
74
|
+
end
|
75
|
+
|
76
|
+
def questionnaire_participant_answers_url(session_token)
|
77
|
+
show_answers_challenge_surveys_url(session_token:)
|
78
|
+
end
|
79
|
+
|
80
|
+
def questionnaire_export_response_url(session_token)
|
81
|
+
export_response_challenge_surveys_url(session_token:, format: "pdf")
|
82
|
+
end
|
83
|
+
|
84
|
+
def questionnaire_for
|
85
|
+
challenge
|
86
|
+
end
|
87
|
+
|
88
|
+
def public_url
|
89
|
+
Decidim::EngineRouter.main_proxy(current_component).answer_challenge_survey_path(challenge.id)
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def challenge
|
95
|
+
@challenge ||= Challenge.where(component: current_component).find(params[:challenge_id])
|
96
|
+
end
|
97
|
+
|
98
|
+
def participants_query
|
99
|
+
Decidim::Forms::QuestionnaireParticipants.new(questionnaire)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
# This controller is the abstract class from which all other controllers of
|
6
|
+
# this engine inherit.
|
7
|
+
#
|
8
|
+
# Note that it inherits from `Decidim::Components::BaseController`, which
|
9
|
+
# override its layout and provide all kinds of useful methods.
|
10
|
+
class ApplicationController < Decidim::Components::BaseController
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
# Controller that allows browsing challenges.
|
6
|
+
#
|
7
|
+
class ChallengesController < Decidim::Challenges::ApplicationController
|
8
|
+
include Decidim::ApplicationHelper
|
9
|
+
include FilterResource
|
10
|
+
include Paginable
|
11
|
+
include OrderableChallenges
|
12
|
+
include WithSdgs
|
13
|
+
include WithDefaultFilters
|
14
|
+
|
15
|
+
helper Decidim::CheckBoxesTreeHelper
|
16
|
+
helper Decidim::Sdgs::SdgsHelper
|
17
|
+
helper Decidim::ShowFiltersHelper
|
18
|
+
helper Decidim::Challenges::ChallengesHelper
|
19
|
+
helper Decidim::PaginateHelper
|
20
|
+
|
21
|
+
helper_method :challenges, :has_sdgs?, :new_solution_path, :solutions_component, :default_filter_scope_params
|
22
|
+
|
23
|
+
def index
|
24
|
+
@challenges = search.result
|
25
|
+
@challenges = reorder(@challenges)
|
26
|
+
@challenges = paginate(@challenges)
|
27
|
+
end
|
28
|
+
|
29
|
+
def show
|
30
|
+
@challenge = Challenge.find(params[:id])
|
31
|
+
@challenge_scope = challenge_scope
|
32
|
+
@sdg = @challenge.sdg_code if @challenge.sdg_code.present?
|
33
|
+
@sdg_index = (1 + Decidim::Sdgs::Sdg.index_from_code(@challenge.sdg_code.to_sym)).to_s.rjust(2, "0") if @sdg
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def challenge_scope
|
39
|
+
@challenge_scope ||= current_organization.scopes.find_by(id: @challenge.decidim_scope_id)
|
40
|
+
end
|
41
|
+
|
42
|
+
def challenges
|
43
|
+
@challenges ||= reorder(paginate(search.result))
|
44
|
+
end
|
45
|
+
|
46
|
+
def search_collection
|
47
|
+
::Decidim::Challenges::Challenge.where(component: current_component).published
|
48
|
+
end
|
49
|
+
|
50
|
+
def default_filter_params
|
51
|
+
{
|
52
|
+
search_text_cont: "",
|
53
|
+
with_any_state: %w(proposal execution finished),
|
54
|
+
with_any_scope: default_filter_scope_params,
|
55
|
+
with_any_sdgs_codes: [],
|
56
|
+
related_to: "",
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def new_solution_path
|
61
|
+
component = solutions_component
|
62
|
+
Decidim::EngineRouter.main_proxy(component).new_solution_path
|
63
|
+
end
|
64
|
+
|
65
|
+
def solutions_component
|
66
|
+
current_participatory_space.components.find_by(manifest_name: "solutions")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
# Exposes the registration resource so users can answers surveys.
|
6
|
+
class SurveysController < Decidim::Challenges::ApplicationController
|
7
|
+
include Decidim::Forms::Concerns::HasQuestionnaire
|
8
|
+
|
9
|
+
def answer
|
10
|
+
enforce_permission_to(:answer, :challenge, challenge:)
|
11
|
+
|
12
|
+
@form = form(Decidim::Forms::QuestionnaireForm).from_params(params, session_token:)
|
13
|
+
|
14
|
+
SurveyChallenge.call(challenge, current_user, @form) do
|
15
|
+
on(:ok) do
|
16
|
+
flash[:notice] = I18n.t("surveys.create.success", scope: "decidim.challenges")
|
17
|
+
redirect_to after_answer_path
|
18
|
+
end
|
19
|
+
|
20
|
+
on(:invalid) do
|
21
|
+
flash.now[:alert] = I18n.t("surveys.create.invalid", scope: "decidim.challenges")
|
22
|
+
render template: "decidim/forms/questionnaires/show"
|
23
|
+
end
|
24
|
+
|
25
|
+
on(:invalid_form) do
|
26
|
+
flash.now[:alert] = I18n.t("answer.invalid", scope: i18n_flashes_scope)
|
27
|
+
render template: "decidim/forms/questionnaires/show"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def allow_answers?
|
33
|
+
challenge.survey_enabled?
|
34
|
+
end
|
35
|
+
|
36
|
+
def after_answer_path
|
37
|
+
challenge_path(challenge)
|
38
|
+
end
|
39
|
+
|
40
|
+
# You can implement this method in your controller to change the URL
|
41
|
+
# where the questionnaire will be submitted.
|
42
|
+
def update_url
|
43
|
+
answer_challenge_survey_path(challenge_id: challenge.id)
|
44
|
+
end
|
45
|
+
|
46
|
+
def questionnaire_for
|
47
|
+
challenge
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def challenge
|
53
|
+
@challenge ||= Challenge.where(component: current_component).find(params[:challenge_id])
|
54
|
+
end
|
55
|
+
|
56
|
+
def redirect_after_path
|
57
|
+
redirect_to challenge_path(challenge)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
module Admin
|
6
|
+
# This controller is the abstract class from which all other controllers of
|
7
|
+
# this engine inherit.
|
8
|
+
#
|
9
|
+
# Note that it inherits from `Decidim::Admin::Components::BaseController`, which
|
10
|
+
# override its layout and provide all kinds of useful methods.
|
11
|
+
class ApplicationController < Decidim::Admin::Components::BaseController
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing problems publications.
|
7
|
+
#
|
8
|
+
class ProblemPublicationsController < Decidim::Problems::Admin::ApplicationController
|
9
|
+
def create
|
10
|
+
enforce_permission_to(:publish, :problem, problem:)
|
11
|
+
|
12
|
+
Decidim::Problems::Admin::PublishProblem.call(problem, current_user) do
|
13
|
+
on(:ok) do
|
14
|
+
flash[:notice] = I18n.t("problem_publications.create.success", scope: "decidim.problems.admin")
|
15
|
+
end
|
16
|
+
|
17
|
+
on(:invalid) do
|
18
|
+
flash.now[:alert] = I18n.t("problem_publications.create.error", scope: "decidim.problems.admin")
|
19
|
+
end
|
20
|
+
|
21
|
+
redirect_back(fallback_location: problems_path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
enforce_permission_to(:publish, :problem, problem:)
|
27
|
+
|
28
|
+
Decidim::Problems::Admin::UnpublishProblem.call(problem, current_user) do
|
29
|
+
on(:ok) do
|
30
|
+
flash[:notice] = I18n.t("problem_publications.destroy.success", scope: "decidim.problems.admin")
|
31
|
+
end
|
32
|
+
|
33
|
+
on(:invalid) do
|
34
|
+
flash.now[:alert] = I18n.t("problem_publications.destroy.error", scope: "decidim.problems.admin")
|
35
|
+
end
|
36
|
+
|
37
|
+
redirect_back(fallback_location: problems_path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def collection
|
44
|
+
@collection ||= Problem.where(component: current_component)
|
45
|
+
end
|
46
|
+
|
47
|
+
def problem
|
48
|
+
@problem ||= collection.find(params[:problem_id])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing admin problems.
|
7
|
+
#
|
8
|
+
class ProblemsController < Decidim::Problems::Admin::ApplicationController
|
9
|
+
helper Challenges::ApplicationHelper
|
10
|
+
helper Decidim::PaginateHelper
|
11
|
+
|
12
|
+
helper_method :problems, :problem, :form_presenter
|
13
|
+
|
14
|
+
def index
|
15
|
+
enforce_permission_to :read, :problems
|
16
|
+
@problems = problems
|
17
|
+
end
|
18
|
+
|
19
|
+
def new
|
20
|
+
enforce_permission_to :create, :problem
|
21
|
+
@form = form(Decidim::Problems::Admin::ProblemsForm).instance
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit
|
25
|
+
enforce_permission_to(:edit, :problem, problem:)
|
26
|
+
@form = form(Decidim::Problems::Admin::ProblemsForm).from_model(problem)
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
enforce_permission_to :create, :problem
|
31
|
+
@form = form(Decidim::Problems::Admin::ProblemsForm).from_params(params)
|
32
|
+
|
33
|
+
Decidim::Problems::Admin::CreateProblem.call(@form) do
|
34
|
+
on(:ok) do
|
35
|
+
flash[:notice] = I18n.t("problems.create.success", scope: "decidim.problems.admin")
|
36
|
+
redirect_to problems_path(assembly_slug: -1, component_id: -1)
|
37
|
+
end
|
38
|
+
|
39
|
+
on(:invalid) do
|
40
|
+
flash.now[:alert] = I18n.t("problems.create.error", scope: "decidim.problems.admin")
|
41
|
+
render action: "new"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def update
|
47
|
+
enforce_permission_to(:edit, :problem, problem:)
|
48
|
+
@form = form(Decidim::Problems::Admin::ProblemsForm).from_params(params)
|
49
|
+
|
50
|
+
Decidim::Problems::Admin::UpdateProblem.call(@form, problem) do
|
51
|
+
on(:ok) do |_problem|
|
52
|
+
flash[:notice] = t("problems.update.success", scope: "decidim.problems.admin")
|
53
|
+
redirect_to problems_path(assembly_slug: -1, component_id: -1)
|
54
|
+
end
|
55
|
+
|
56
|
+
on(:invalid) do
|
57
|
+
flash.now[:alert] = t("problems.update.error", scope: "decidim.problems.admin")
|
58
|
+
render :edit
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def destroy
|
64
|
+
enforce_permission_to(:destroy, :problem, problem:)
|
65
|
+
|
66
|
+
Decidim::Problems::Admin::DestroyProblem.call(problem, current_user) do
|
67
|
+
on(:ok) do
|
68
|
+
flash[:notice] = I18n.t("problems.destroy.success", scope: "decidim.problems.admin")
|
69
|
+
redirect_to problems_path(assembly_slug: -1, component_id: -1)
|
70
|
+
end
|
71
|
+
|
72
|
+
on(:has_solutions) do
|
73
|
+
redirect_to problems_path, flash: { error: t("problems.destroy.has_solutions", scope: "decidim.problems.admin") }
|
74
|
+
end
|
75
|
+
|
76
|
+
on(:invalid) do
|
77
|
+
redirect_to problems_path, flash: { error: t("problems.destroy.error", scope: "decidim.problems.admin") }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def collection
|
85
|
+
@collection ||= Problem.where(component: current_component)
|
86
|
+
end
|
87
|
+
|
88
|
+
def problems
|
89
|
+
@problems ||= collection.page(params[:page]).per(10)
|
90
|
+
end
|
91
|
+
|
92
|
+
def problem
|
93
|
+
@problem ||= collection.find(params[:id])
|
94
|
+
end
|
95
|
+
|
96
|
+
def form_presenter
|
97
|
+
@form_presenter ||= present(@form, presenter_class: Decidim::Problems::ProblemPresenter)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
# This controller is the abstract class from which all other controllers of
|
6
|
+
# this engine inherit.
|
7
|
+
#
|
8
|
+
# Note that it inherits from `Decidim::Components::BaseController`, which
|
9
|
+
# override its layout and provide all kinds of useful methods.
|
10
|
+
class ApplicationController < Decidim::Components::BaseController
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
# Controller that allows browsing problems.
|
6
|
+
#
|
7
|
+
class ProblemsController < Decidim::Problems::ApplicationController
|
8
|
+
include Decidim::ApplicationHelper
|
9
|
+
include FilterResource
|
10
|
+
include Paginable
|
11
|
+
include OrderableProblems
|
12
|
+
include WithSdgs
|
13
|
+
include WithDefaultFilters
|
14
|
+
|
15
|
+
helper Decidim::CheckBoxesTreeHelper
|
16
|
+
helper Decidim::Sdgs::SdgsHelper
|
17
|
+
helper Decidim::ShowFiltersHelper
|
18
|
+
helper ProblemsHelper
|
19
|
+
helper Decidim::Challenges::ApplicationHelper
|
20
|
+
helper Decidim::PaginateHelper
|
21
|
+
|
22
|
+
helper_method :problems, :has_sdgs?, :default_filter_scope_params
|
23
|
+
|
24
|
+
def index
|
25
|
+
@problems = search.result
|
26
|
+
@problems = reorder(@problems)
|
27
|
+
@problems = paginate(@problems)
|
28
|
+
end
|
29
|
+
|
30
|
+
def show
|
31
|
+
@problem = Decidim::Problems::Problem.find(params[:id])
|
32
|
+
@challenge_scope = challenge_scope
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def challenge_scope
|
38
|
+
@challenge_scope ||= current_organization.scopes.find_by(id: @problem.challenge.decidim_scope_id)
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_filter_params
|
42
|
+
{
|
43
|
+
search_text_cont: "",
|
44
|
+
with_any_state: %w(proposal execution finished),
|
45
|
+
with_any_sectorial_scope: default_filter_scope_params,
|
46
|
+
with_any_technological_scope: default_filter_scope_params,
|
47
|
+
with_any_territorial_scope: default_filter_scope_params,
|
48
|
+
with_any_sdgs_codes: [],
|
49
|
+
related_to: "",
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def problems
|
54
|
+
@problems ||= order(paginate(search.result))
|
55
|
+
end
|
56
|
+
|
57
|
+
def search_collection
|
58
|
+
::Decidim::Problems::Problem.where(component: current_component).published
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Sdgs
|
5
|
+
module Admin
|
6
|
+
# This controller is the abstract class from which all other controllers of
|
7
|
+
# this engine inherit.
|
8
|
+
#
|
9
|
+
# Note that it inherits from `Decidim::Admin::Components::BaseController`, which
|
10
|
+
# override its layout and provide all kinds of useful methods.
|
11
|
+
class ApplicationController < Decidim::Admin::Components::BaseController
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Sdgs
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing admin Sdgs.
|
7
|
+
#
|
8
|
+
class SdgsController < Decidim::Sdgs::Admin::ApplicationController
|
9
|
+
include Decidim::ApplicationHelper
|
10
|
+
|
11
|
+
def index
|
12
|
+
flash[:alert] = t(".cant_manage")
|
13
|
+
redirect_to decidim_admin_participatory_processes.components_path(current_participatory_space)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Sdgs
|
5
|
+
# This controller is the abstract class from which all other controllers of
|
6
|
+
# this engine inherit.
|
7
|
+
#
|
8
|
+
# Note that it inherits from `Decidim::Components::BaseController`, which
|
9
|
+
# override its layout and provide all kinds of useful methods.
|
10
|
+
class ApplicationController < Decidim::Components::BaseController
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Sdgs
|
5
|
+
# Exposes the SustainableDevelopmentGoal resource so users can view and create them.
|
6
|
+
class SdgsController < Decidim::Sdgs::ApplicationController
|
7
|
+
helper_method :sdgs, :sdg
|
8
|
+
|
9
|
+
def index; end
|
10
|
+
|
11
|
+
def show; end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def sdg
|
16
|
+
@sdg ||= sdgs.find(params[:id])
|
17
|
+
end
|
18
|
+
|
19
|
+
def sdgs
|
20
|
+
@sdgs ||= Sdg.where(component: current_component)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Solutions
|
5
|
+
module Admin
|
6
|
+
# This controller is the abstract class from which all other controllers of
|
7
|
+
# this engine inherit.
|
8
|
+
#
|
9
|
+
# Note that it inherits from `Decidim::Admin::Components::BaseController`, which
|
10
|
+
# override its layout and provide all kinds of useful methods.
|
11
|
+
class ApplicationController < Decidim::Admin::Components::BaseController
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Solutions
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing solutions publications.
|
7
|
+
#
|
8
|
+
class SolutionPublicationsController < Decidim::Solutions::Admin::ApplicationController
|
9
|
+
def create
|
10
|
+
enforce_permission_to(:publish, :solution, solution:)
|
11
|
+
|
12
|
+
Decidim::Solutions::Admin::PublishSolution.call(solution, current_user) do
|
13
|
+
on(:ok) do
|
14
|
+
flash[:notice] = I18n.t("solution_publications.create.success", scope: "decidim.solutions.admin")
|
15
|
+
end
|
16
|
+
|
17
|
+
on(:invalid) do
|
18
|
+
flash.now[:alert] = I18n.t("solution_publications.create.error", scope: "decidim.solutions.admin")
|
19
|
+
end
|
20
|
+
|
21
|
+
redirect_back(fallback_location: solutions_path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
enforce_permission_to(:publish, :solution, solution:)
|
27
|
+
|
28
|
+
Decidim::Solutions::Admin::UnpublishSolution.call(solution, current_user) do
|
29
|
+
on(:ok) do
|
30
|
+
flash[:notice] = I18n.t("solution_publications.destroy.success", scope: "decidim.solutions.admin")
|
31
|
+
end
|
32
|
+
|
33
|
+
on(:invalid) do
|
34
|
+
flash.now[:alert] = I18n.t("solution_publications.destroy.error", scope: "decidim.solutions.admin")
|
35
|
+
end
|
36
|
+
|
37
|
+
redirect_back(fallback_location: solutions_path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def collection
|
44
|
+
@collection ||= Solution.where(component: current_component)
|
45
|
+
end
|
46
|
+
|
47
|
+
def solution
|
48
|
+
@solution ||= collection.find(params[:solution_id])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|