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,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Solutions
|
5
|
+
module Admin
|
6
|
+
# A command that sets a solution as unpublished.
|
7
|
+
class UnpublishSolution < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# solution - A Solution that will be published
|
11
|
+
# current_user - the user performing the action
|
12
|
+
def initialize(solution, current_user)
|
13
|
+
super()
|
14
|
+
@solution = solution
|
15
|
+
@current_user = current_user
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if solution.nil? || !solution.published?
|
26
|
+
|
27
|
+
Decidim.traceability.perform_action!("unpublish", solution, current_user) do
|
28
|
+
solution.unpublish!
|
29
|
+
end
|
30
|
+
|
31
|
+
broadcast(:ok)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :solution, :current_user
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Solutions
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when a user updates a Solution.
|
7
|
+
class UpdateSolution < Decidim::Command
|
8
|
+
include Decidim::Challenges
|
9
|
+
include Decidim::CommandUtils
|
10
|
+
|
11
|
+
# Public: Initializes the command.
|
12
|
+
#
|
13
|
+
# form - A form object with the params.
|
14
|
+
# solution - the solution to update.
|
15
|
+
def initialize(form, solution)
|
16
|
+
super()
|
17
|
+
@form = form
|
18
|
+
@solution = solution
|
19
|
+
end
|
20
|
+
|
21
|
+
# Executes the command. Broadcasts these events:
|
22
|
+
#
|
23
|
+
# - :ok when everything is valid, together with the problem.
|
24
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
25
|
+
#
|
26
|
+
# Returns nothing.
|
27
|
+
def call
|
28
|
+
return broadcast(:invalid) if form.invalid?
|
29
|
+
|
30
|
+
transaction do
|
31
|
+
update_solution
|
32
|
+
end
|
33
|
+
|
34
|
+
broadcast(:ok, solution)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :form, :solution
|
40
|
+
|
41
|
+
def update_solution
|
42
|
+
Decidim.traceability.update!(
|
43
|
+
solution,
|
44
|
+
form.current_user,
|
45
|
+
attributes:
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def attributes
|
50
|
+
{
|
51
|
+
title: parsed_attribute(:title),
|
52
|
+
description: parsed_attribute(:description),
|
53
|
+
component: form.current_component,
|
54
|
+
decidim_problems_problem_id: form.decidim_problems_problem_id,
|
55
|
+
decidim_challenges_challenge_id: challenge_id,
|
56
|
+
tags: form.tags,
|
57
|
+
objectives: parsed_attribute(:objectives),
|
58
|
+
indicators: parsed_attribute(:indicators),
|
59
|
+
beneficiaries: parsed_attribute(:beneficiaries),
|
60
|
+
requirements: parsed_attribute(:requirements),
|
61
|
+
financing_type: parsed_attribute(:financing_type),
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Solutions
|
5
|
+
# A command with all the business logic when a user creates a new solution.
|
6
|
+
class CreateSolution < Decidim::Command
|
7
|
+
include ::Decidim::MultipleAttachmentsMethods
|
8
|
+
include Decidim::Challenges
|
9
|
+
include Decidim::CommandUtils
|
10
|
+
|
11
|
+
# Public: Initializes the command.
|
12
|
+
#
|
13
|
+
# form - A form object with the params.
|
14
|
+
def initialize(form)
|
15
|
+
super()
|
16
|
+
@form = form
|
17
|
+
end
|
18
|
+
|
19
|
+
# Executes the command. Broadcasts these events:
|
20
|
+
#
|
21
|
+
# - :ok when everything is valid, together with the solution.
|
22
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
23
|
+
#
|
24
|
+
# Returns nothing.
|
25
|
+
def call
|
26
|
+
return broadcast(:invalid) if form.invalid?
|
27
|
+
|
28
|
+
transaction do
|
29
|
+
create_solution!
|
30
|
+
|
31
|
+
if process_attachments?
|
32
|
+
build_attachments
|
33
|
+
create_attachments
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
broadcast(:ok, solution)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
attr_reader :form, :solution, :attachment
|
43
|
+
|
44
|
+
def create_solution!
|
45
|
+
params = {
|
46
|
+
title: parsed_attribute(:title),
|
47
|
+
description: parsed_attribute(:description),
|
48
|
+
component: form.current_component,
|
49
|
+
decidim_challenges_challenge_id: challenge_id,
|
50
|
+
project_status: parsed_attribute(:project_status),
|
51
|
+
project_url: parsed_attribute(:project_url),
|
52
|
+
coordinating_entity: parsed_attribute(:coordinating_entity),
|
53
|
+
author_id: form.author_id,
|
54
|
+
}
|
55
|
+
|
56
|
+
@solution = Decidim.traceability.create!(
|
57
|
+
Decidim::Solutions::Solution,
|
58
|
+
form.current_user,
|
59
|
+
params,
|
60
|
+
visibility: "all"
|
61
|
+
)
|
62
|
+
|
63
|
+
@attached_to = @solution
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Challenges
|
7
|
+
module Admin
|
8
|
+
module Filterable
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include Decidim::Admin::Filterable
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def base_query
|
17
|
+
collection
|
18
|
+
end
|
19
|
+
|
20
|
+
def extra_filters
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Challenges
|
7
|
+
# Common logic to sorting resources
|
8
|
+
module OrderableChallenges
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include Decidim::Orderable
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def available_orders
|
17
|
+
@available_orders ||= %w(random recent)
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_order
|
21
|
+
"random"
|
22
|
+
end
|
23
|
+
|
24
|
+
def reorder(challenges)
|
25
|
+
case order
|
26
|
+
when "recent"
|
27
|
+
challenges.order("created_at DESC")
|
28
|
+
when "random"
|
29
|
+
challenges.order_randomly(random_seed)
|
30
|
+
else
|
31
|
+
challenges
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Problems
|
7
|
+
module Admin
|
8
|
+
module Filterable
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include Decidim::Admin::Filterable
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def base_query
|
17
|
+
collection
|
18
|
+
end
|
19
|
+
|
20
|
+
def extra_filters
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Problems
|
7
|
+
# Common logic to sorting resources
|
8
|
+
module OrderableProblems
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include Decidim::Orderable
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def available_orders
|
17
|
+
@available_orders ||= %w(random recent)
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_order
|
21
|
+
"random"
|
22
|
+
end
|
23
|
+
|
24
|
+
def reorder(problems)
|
25
|
+
case order
|
26
|
+
when "recent"
|
27
|
+
problems.order("created_at DESC")
|
28
|
+
when "random"
|
29
|
+
problems.order_randomly(random_seed)
|
30
|
+
else
|
31
|
+
problems
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Solutions
|
7
|
+
module Admin
|
8
|
+
module Filterable
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include Decidim::Admin::Filterable
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def base_query
|
17
|
+
collection
|
18
|
+
end
|
19
|
+
|
20
|
+
def extra_filters
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Solutions
|
7
|
+
# Common logic to sorting resources
|
8
|
+
module OrderableSolutions
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include Decidim::Orderable
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def available_orders
|
17
|
+
@available_orders ||= %w(random recent)
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_order
|
21
|
+
"random"
|
22
|
+
end
|
23
|
+
|
24
|
+
def reorder(solutions)
|
25
|
+
case order
|
26
|
+
when "recent"
|
27
|
+
solutions.order("created_at DESC")
|
28
|
+
when "random"
|
29
|
+
solutions.order_randomly(random_seed)
|
30
|
+
else
|
31
|
+
solutions
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module WithDefaultFilters
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
private
|
11
|
+
|
12
|
+
def default_filter_scope_params
|
13
|
+
return "all" unless current_component.participatory_space.scopes.any?
|
14
|
+
|
15
|
+
if current_component.participatory_space.scope
|
16
|
+
["all", current_component.participatory_space.scope.id] + current_component.participatory_space.scope.children.map { |scope| scope.id.to_s }
|
17
|
+
else
|
18
|
+
%w(all global) + current_component.participatory_space.scopes.map { |scope| scope.id.to_s }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module WithSdgs
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
private
|
11
|
+
|
12
|
+
def has_sdgs?
|
13
|
+
sdgs_component = current_component.participatory_space.components.where(manifest_name: "sdgs").where.not(published_at: nil)
|
14
|
+
|
15
|
+
sdgs_component.present?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
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 Challenges
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing challenge publications.
|
7
|
+
#
|
8
|
+
class ChallengePublicationsController < Decidim::Challenges::Admin::ApplicationController
|
9
|
+
def create
|
10
|
+
enforce_permission_to(:publish, :challenge, challenge:)
|
11
|
+
|
12
|
+
Decidim::Challenges::Admin::PublishChallenge.call(challenge, current_user) do
|
13
|
+
on(:ok) do
|
14
|
+
flash[:notice] = I18n.t("challenge_publications.create.success", scope: "decidim.challenges.admin")
|
15
|
+
end
|
16
|
+
|
17
|
+
on(:invalid) do
|
18
|
+
flash.now[:alert] = I18n.t("challenge_publications.create.error", scope: "decidim.challenges.admin")
|
19
|
+
end
|
20
|
+
|
21
|
+
redirect_back(fallback_location: challenges_path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
enforce_permission_to(:publish, :challenge, challenge:)
|
27
|
+
|
28
|
+
Decidim::Challenges::Admin::UnpublishChallenge.call(challenge, current_user) do
|
29
|
+
on(:ok) do
|
30
|
+
flash[:notice] = I18n.t("challenge_publications.destroy.success", scope: "decidim.challenges.admin")
|
31
|
+
end
|
32
|
+
|
33
|
+
on(:invalid) do
|
34
|
+
flash.now[:alert] = I18n.t("challenge_publications.destroy.error", scope: "decidim.challenges.admin")
|
35
|
+
end
|
36
|
+
|
37
|
+
redirect_back(fallback_location: challenges_path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def collection
|
44
|
+
@collection ||= Challenge.where(component: current_component)
|
45
|
+
end
|
46
|
+
|
47
|
+
def challenge
|
48
|
+
@challenge ||= collection.find(params[:challenge_id])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing admin challenges.
|
7
|
+
#
|
8
|
+
class ChallengesController < Decidim::Challenges::Admin::ApplicationController
|
9
|
+
include Decidim::ApplicationHelper
|
10
|
+
|
11
|
+
helper Challenges::ApplicationHelper
|
12
|
+
helper Decidim::Sdgs::SdgsHelper
|
13
|
+
helper Decidim::PaginateHelper
|
14
|
+
|
15
|
+
helper_method :challenges, :challenge, :form_presenter
|
16
|
+
|
17
|
+
def index
|
18
|
+
enforce_permission_to :read, :challenges
|
19
|
+
@challenges = challenges
|
20
|
+
end
|
21
|
+
|
22
|
+
def new
|
23
|
+
enforce_permission_to :create, :challenge
|
24
|
+
@form = form(Decidim::Challenges::Admin::ChallengesForm).instance
|
25
|
+
end
|
26
|
+
|
27
|
+
def edit
|
28
|
+
enforce_permission_to(:edit, :challenge, challenge:)
|
29
|
+
@form = form(Decidim::Challenges::Admin::ChallengesForm).from_model(challenge)
|
30
|
+
end
|
31
|
+
|
32
|
+
def create
|
33
|
+
enforce_permission_to :create, :challenge
|
34
|
+
@form = form(Decidim::Challenges::Admin::ChallengesForm).from_params(params)
|
35
|
+
|
36
|
+
Decidim::Challenges::Admin::CreateChallenge.call(@form) do
|
37
|
+
on(:ok) do
|
38
|
+
flash[:notice] = I18n.t("challenges.create.success", scope: "decidim.challenges.admin")
|
39
|
+
# maybe used together?
|
40
|
+
# Rails.application.routes.mounted_helpers
|
41
|
+
# ResourceLocatorPresenter.new(resource).edit
|
42
|
+
redirect_to challenges_path(assembly_slug: -1, component_id: -1)
|
43
|
+
end
|
44
|
+
|
45
|
+
on(:invalid) do
|
46
|
+
flash.now[:alert] = I18n.t("challenges.create.error", scope: "decidim.challenges.admin")
|
47
|
+
render action: "new"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def update
|
53
|
+
enforce_permission_to(:edit, :challenge, challenge:)
|
54
|
+
@form = form(Decidim::Challenges::Admin::ChallengesForm).from_params(params)
|
55
|
+
|
56
|
+
Decidim::Challenges::Admin::UpdateChallenge.call(@form, challenge) do
|
57
|
+
on(:ok) do |_challenge|
|
58
|
+
flash[:notice] = t("challenges.update.success", scope: "decidim.challenges.admin")
|
59
|
+
redirect_to challenges_path(assembly_slug: -1, component_id: -1)
|
60
|
+
end
|
61
|
+
|
62
|
+
on(:invalid) do
|
63
|
+
flash.now[:alert] = t("challenges.update.error", scope: "decidim.challenges.admin")
|
64
|
+
render :edit
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def destroy
|
70
|
+
enforce_permission_to(:destroy, :challenge, challenge:)
|
71
|
+
|
72
|
+
Decidim::Challenges::Admin::DestroyChallenge.call(challenge, current_user) do
|
73
|
+
on(:ok) do
|
74
|
+
flash[:notice] = I18n.t("challenges.destroy.success", scope: "decidim.challenges.admin")
|
75
|
+
redirect_to challenges_path(assembly_slug: -1, component_id: -1)
|
76
|
+
end
|
77
|
+
|
78
|
+
on(:has_problems) do
|
79
|
+
redirect_to challenges_path, flash: { error: t("challenges.destroy.has_problems", scope: "decidim.challenges.admin") }
|
80
|
+
end
|
81
|
+
|
82
|
+
on(:invalid) do
|
83
|
+
redirect_to challenges_path, flash: { error: t("challenges.destroy.error", scope: "decidim.challenges.admin") }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def collection
|
91
|
+
@collection ||= Challenge.where(component: current_component)
|
92
|
+
end
|
93
|
+
|
94
|
+
def challenges
|
95
|
+
@challenges ||= collection.page(params[:page]).per(10)
|
96
|
+
end
|
97
|
+
|
98
|
+
def challenge
|
99
|
+
@challenge ||= collection.find(params[:id])
|
100
|
+
end
|
101
|
+
|
102
|
+
def form_presenter
|
103
|
+
@form_presenter ||= present(@form, presenter_class: Decidim::Challenges::ChallengePresenter)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
module Admin
|
6
|
+
# This controller allows an admin to manage the form to be filled when an user answer a survey
|
7
|
+
class SurveyFormController < Admin::ApplicationController
|
8
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaireAnswers
|
9
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaire
|
10
|
+
|
11
|
+
def questionnaire_for
|
12
|
+
challenge
|
13
|
+
end
|
14
|
+
|
15
|
+
def public_url
|
16
|
+
Decidim::EngineRouter.main_proxy(current_component).answer_challenge_survey_path(challenge)
|
17
|
+
end
|
18
|
+
|
19
|
+
def questionnaire_participants_url
|
20
|
+
index_answers_challenge_surveys_path(challenge_id: challenge.id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def answer_options_url(params)
|
24
|
+
answer_options_challenge_survey_path(**params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_url
|
28
|
+
challenge_surveys_form_path(challenge_id: challenge.id)
|
29
|
+
end
|
30
|
+
|
31
|
+
def after_update_url
|
32
|
+
edit_challenge_surveys_path(challenge_id: challenge.id)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def challenge
|
38
|
+
@challenge ||= Challenge.where(component: current_component).find(params[:challenge_id])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|