decidim-challenges 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +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
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Decidim::Challenges
|
2
|
+
|
3
|
+
Articulates the collective action of diverse actors in order to address common and shared challenges and the problems that derive from them across the territory..
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Challenges will be available as a Component for a Participatory
|
8
|
+
Space.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem "decidim-challenges"
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
bundle install
|
22
|
+
bundle exec rails decidim_challenges:install:migrations
|
23
|
+
bundle exec rails db:migrate
|
24
|
+
```
|
25
|
+
|
26
|
+
### Run tests
|
27
|
+
|
28
|
+
Create a dummy app in your application (if not present):
|
29
|
+
|
30
|
+
```bash
|
31
|
+
bin/rails decidim:generate_external_test_app
|
32
|
+
cd spec/decidim_dummy_app/
|
33
|
+
bundle exec rails decidim_challenges:install:migrations
|
34
|
+
RAILS_ENV=test bundle exec rails db:migrate
|
35
|
+
```
|
36
|
+
|
37
|
+
And run tests:
|
38
|
+
|
39
|
+
```bash
|
40
|
+
bundle exec rspec spec
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
See [Decidim](https://github.com/decidim/decidim).
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
This engine is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/dev/common_rake"
|
4
|
+
|
5
|
+
desc "Generates a dummy app for testing"
|
6
|
+
task test_app: "decidim:generate_external_test_app"
|
7
|
+
|
8
|
+
desc "Generates a development app."
|
9
|
+
task development_app: "decidim:generate_external_development_app"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
class ChallengeCell < Decidim::ViewModel
|
6
|
+
include ChallengeCellsHelper
|
7
|
+
include Decidim::SanitizeHelper
|
8
|
+
include Cell::ViewModel::Partial
|
9
|
+
|
10
|
+
def show
|
11
|
+
cell card_size, model, options
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def card_size
|
17
|
+
"decidim/challenges/challenge_g"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<%= append_stylesheet_pack_tag "decidim_challenges" %>
|
2
|
+
|
3
|
+
<%= link_to resource_path, class: "card__list", id: resource_id do %>
|
4
|
+
<div class="card__list-image">
|
5
|
+
<% if has_image? %>
|
6
|
+
<%= image_tag resource_image_url, class: "w-full h-full object-cover" %>
|
7
|
+
<% else %>
|
8
|
+
<div class="w-full h-full relative">
|
9
|
+
<div class="w-full h-full bg-primary opacity-10 absolute top-0 left-0 z-10">
|
10
|
+
</div>
|
11
|
+
<%= external_icon "media/images/placeholder-card-l.svg", class: "card__placeholder-l" %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="card__list-content">
|
17
|
+
<%= content_tag title_tag, class: "h4 card__list-title" do %>
|
18
|
+
<%= translated_attribute(title) %>
|
19
|
+
<% end %>
|
20
|
+
<div class="card__list-text">
|
21
|
+
<%= description %>
|
22
|
+
<% if has_sdgs? %>
|
23
|
+
<div class="card__sdg">
|
24
|
+
<div class="card_text--sdg--image">
|
25
|
+
<div class="ods challenges">
|
26
|
+
<% if resource_sdg_index %>
|
27
|
+
<%= image_pack_tag "media/images/ods-#{resource_sdg_index}.svg", alt: "Logo SDG #{resource_sdg_index}", class: "challenge--view" %>
|
28
|
+
<% end %>
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
<div class="card_text--sdg--text">
|
32
|
+
<% if resource_sdg %>
|
33
|
+
<strong><%= t_sdg(resource_sdg) %></strong>
|
34
|
+
<% end %>
|
35
|
+
</div>
|
36
|
+
</div>
|
37
|
+
<% end %>
|
38
|
+
</div>
|
39
|
+
<div class="card__list-metadata">
|
40
|
+
<div>
|
41
|
+
<span class="label challenge-status <%= resource_state %>">
|
42
|
+
<%= t(resource_state, scope: 'decidim.challenges.states') %>
|
43
|
+
</span>
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
<% end %>
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
# This cell renders the Grid (:g) Challenge card
|
6
|
+
# for an given instance of a Challenge
|
7
|
+
class ChallengeGCell < Decidim::CardGCell
|
8
|
+
include ActiveSupport::NumberHelper
|
9
|
+
include Decidim::Challenges::ChallengesHelper
|
10
|
+
include Decidim::Sdgs::SdgsHelper
|
11
|
+
include ChallengeCellsHelper
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def resource_icon
|
16
|
+
icon "challenges", class: "icon--big"
|
17
|
+
end
|
18
|
+
|
19
|
+
def resource_image_url
|
20
|
+
model.attached_uploader(:card_image).url
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_image?
|
24
|
+
@has_image ||= model.component.settings.allow_card_image && model.card_image.attached?
|
25
|
+
end
|
26
|
+
|
27
|
+
def resource_image_path
|
28
|
+
@resource_image_path ||= has_image? ? model.attached_uploader(:card_image).path : nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def description
|
32
|
+
text = translated_attribute(model.global_description)
|
33
|
+
decidim_sanitize(html_truncate(text, length: 100))
|
34
|
+
end
|
35
|
+
|
36
|
+
def challenge_path
|
37
|
+
resource_locator(model).path
|
38
|
+
end
|
39
|
+
|
40
|
+
def show
|
41
|
+
render
|
42
|
+
end
|
43
|
+
|
44
|
+
def resource_path
|
45
|
+
resource_locator(model).path
|
46
|
+
end
|
47
|
+
|
48
|
+
def resource_title
|
49
|
+
translated_attribute model.title
|
50
|
+
end
|
51
|
+
|
52
|
+
def resource_sdg
|
53
|
+
model.sdg_code
|
54
|
+
end
|
55
|
+
|
56
|
+
def resource_sdg_index
|
57
|
+
model.sdg_code ? (1 + Decidim::Sdgs::Sdg.index_from_code(model.sdg_code.to_sym)).to_s.rjust(2, "0") : nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def resource_state
|
61
|
+
model.state
|
62
|
+
end
|
63
|
+
|
64
|
+
def current_organization
|
65
|
+
current_organization
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
# This cell renders the problem card for an instance of a problem
|
6
|
+
# the default size is the Medium Card (:m)
|
7
|
+
class ProblemCell < Decidim::ViewModel
|
8
|
+
include ProblemCellsHelper
|
9
|
+
include Decidim::SanitizeHelper
|
10
|
+
include Cell::ViewModel::Partial
|
11
|
+
|
12
|
+
def show
|
13
|
+
cell card_size, model, options
|
14
|
+
end
|
15
|
+
|
16
|
+
def card_size
|
17
|
+
"decidim/problems/problem_g"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<%= append_stylesheet_pack_tag "decidim_challenges" %>
|
2
|
+
|
3
|
+
<%= link_to resource_path, class: "card__list", id: resource_id do %>
|
4
|
+
<div class="card__list-content">
|
5
|
+
<%= content_tag title_tag, class: "h4 card__list-title" do %>
|
6
|
+
<%= title %>
|
7
|
+
<% end %>
|
8
|
+
<div class="card__list-text">
|
9
|
+
<p><%= description %></p>
|
10
|
+
<% if has_sdgs? %>
|
11
|
+
<div class="card__sdg">
|
12
|
+
<div class="card_text--sdg--image">
|
13
|
+
<div class="ods challenges">
|
14
|
+
<% if resource_sdg_index %>
|
15
|
+
<%= image_pack_tag "media/images/ods-#{resource_sdg_index}.svg", alt: "Logo SDG #{resource_sdg_index}", class: "challenge--view" %>
|
16
|
+
<% end %>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
<div class="card_text--sdg--text">
|
20
|
+
<% if resource_sdg %>
|
21
|
+
<strong><%= t_sdg(resource_sdg) %></strong>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
26
|
+
</div>
|
27
|
+
<div class="card__list-metadata">
|
28
|
+
<div>
|
29
|
+
<span class="label problem-status <%= resource_state %>">
|
30
|
+
<%= t(resource_state, scope: 'decidim.challenges.states') %>
|
31
|
+
</span>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
<% end %>
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
# This cell renders the Grid (:g) Problem card
|
6
|
+
# for an given instance of a Problem
|
7
|
+
class ProblemGCell < Decidim::CardGCell
|
8
|
+
include ActiveSupport::NumberHelper
|
9
|
+
include Decidim::Problems::ProblemsHelper
|
10
|
+
include Decidim::Sdgs::SdgsHelper
|
11
|
+
include ProblemCellsHelper
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def resource_icon
|
16
|
+
icon "problems", class: "icon--big"
|
17
|
+
end
|
18
|
+
|
19
|
+
def show
|
20
|
+
render
|
21
|
+
end
|
22
|
+
|
23
|
+
def problem_path
|
24
|
+
resource_locator(model).path
|
25
|
+
end
|
26
|
+
|
27
|
+
def challenge_path
|
28
|
+
resource_locator(model.challenge).path
|
29
|
+
end
|
30
|
+
|
31
|
+
def resource_title
|
32
|
+
translated_attribute model.title
|
33
|
+
end
|
34
|
+
|
35
|
+
def resource_description
|
36
|
+
text = translated_attribute(model.description)
|
37
|
+
decidim_sanitize(html_truncate(text, length: 100))
|
38
|
+
end
|
39
|
+
|
40
|
+
def resource_state
|
41
|
+
model.state
|
42
|
+
end
|
43
|
+
|
44
|
+
def problem
|
45
|
+
model
|
46
|
+
end
|
47
|
+
|
48
|
+
def resource_challenge_title
|
49
|
+
translated_attribute model.challenge.title
|
50
|
+
end
|
51
|
+
|
52
|
+
def resource_sdg
|
53
|
+
model.challenge.sdg_code
|
54
|
+
end
|
55
|
+
|
56
|
+
def resource_sdg_index
|
57
|
+
model.challenge.sdg_code ? (1 + Decidim::Sdgs::Sdg.index_from_code(model.challenge.sdg_code.to_sym)).to_s.rjust(2, "0") : nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Solutions
|
5
|
+
class SolutionCell < Decidim::ViewModel
|
6
|
+
include SolutionCellsHelper
|
7
|
+
include Decidim::SanitizeHelper
|
8
|
+
include Cell::ViewModel::Partial
|
9
|
+
|
10
|
+
def show
|
11
|
+
cell card_size, model, options
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def card_size
|
17
|
+
"decidim/solutions/solution_g"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<%= append_stylesheet_pack_tag "decidim_challenges" %>
|
2
|
+
|
3
|
+
<%= link_to resource_path, class: "card__list", id: resource_id do %>
|
4
|
+
<div class="card__list-content">
|
5
|
+
<%= content_tag resource_title, class: "h4 card__list-title" do %>
|
6
|
+
<%= title %>
|
7
|
+
<% end %>
|
8
|
+
<div class="card__list-text">
|
9
|
+
<%= description %>
|
10
|
+
<% if resource_sdg %>
|
11
|
+
<div class="card__sdg">
|
12
|
+
<div class="card_text--sdg--image">
|
13
|
+
<div class="ods challenges">
|
14
|
+
<% if resource_sdg_index %>
|
15
|
+
<%= image_pack_tag "media/images/ods-#{resource_sdg_index}.svg", alt: "Logo SDG #{resource_sdg_index}", class: "challenge--view" %>
|
16
|
+
<% end %>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
<div class="card_text--sdg--text">
|
20
|
+
<% if resource_sdg %>
|
21
|
+
<strong><%= t_sdg(resource_sdg) %></strong>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
26
|
+
</div>
|
27
|
+
<div class="card__list-metadata">
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
<% end %>
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Solutions
|
5
|
+
# This cell renders the Grid (:g) Solution card
|
6
|
+
# for an given instance of a Solution
|
7
|
+
class SolutionGCell < Decidim::CardGCell
|
8
|
+
include ActiveSupport::NumberHelper
|
9
|
+
include Decidim::Sdgs::SdgsHelper
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def resource_problem_title
|
14
|
+
translated_attribute model.problem.title
|
15
|
+
end
|
16
|
+
|
17
|
+
def resource_challenge_title
|
18
|
+
if model.problem.present?
|
19
|
+
translated_attribute model.problem.challenge.title
|
20
|
+
else
|
21
|
+
translated_attribute model.challenge.title
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def resource_icon
|
26
|
+
icon "solutions", class: "icon--big"
|
27
|
+
end
|
28
|
+
|
29
|
+
def description
|
30
|
+
text = translated_attribute(model.description)
|
31
|
+
decidim_sanitize(html_truncate(text, length: 100))
|
32
|
+
end
|
33
|
+
|
34
|
+
def solution_path
|
35
|
+
resource_locator(model).path
|
36
|
+
end
|
37
|
+
|
38
|
+
def show
|
39
|
+
render
|
40
|
+
end
|
41
|
+
|
42
|
+
def resource_path
|
43
|
+
resource_locator(model).path
|
44
|
+
end
|
45
|
+
|
46
|
+
def resource_title
|
47
|
+
translated_attribute model.title
|
48
|
+
end
|
49
|
+
|
50
|
+
def resource_id
|
51
|
+
model.id
|
52
|
+
end
|
53
|
+
|
54
|
+
def problem_path
|
55
|
+
resource_locator(model.problem).path if model.problem.present?
|
56
|
+
end
|
57
|
+
|
58
|
+
def challenge_path
|
59
|
+
if model.problem.present?
|
60
|
+
resource_locator(model.problem.challenge).path
|
61
|
+
else
|
62
|
+
resource_locator(model.challenge).path
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def resource_sdg
|
67
|
+
if model.problem.present?
|
68
|
+
model.problem.challenge.sdg_code
|
69
|
+
else
|
70
|
+
model.challenge.sdg_code
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def resource_sdg_index
|
75
|
+
challenge = model.problem ? model.problem.challenge : model.challenge
|
76
|
+
challenge.sdg_code ? (1 + Decidim::Sdgs::Sdg.index_from_code(challenge.sdg_code.to_sym)).to_s.rjust(2, "0") : nil
|
77
|
+
end
|
78
|
+
|
79
|
+
def current_organization
|
80
|
+
current_organization
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when a user creates a new challenge.
|
7
|
+
class CreateChallenge < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# form - A form object with the params.
|
11
|
+
def initialize(form)
|
12
|
+
super()
|
13
|
+
@form = form
|
14
|
+
end
|
15
|
+
|
16
|
+
# Executes the command. Broadcasts these events:
|
17
|
+
#
|
18
|
+
# - :ok when everything is valid, together with the proposal.
|
19
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
def call
|
23
|
+
return broadcast(:invalid) if form.invalid?
|
24
|
+
|
25
|
+
transaction do
|
26
|
+
create_challenge!
|
27
|
+
end
|
28
|
+
|
29
|
+
broadcast(:ok, challenge)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :form, :challenge
|
35
|
+
|
36
|
+
def create_challenge!
|
37
|
+
parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
|
38
|
+
parsed_local_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.local_description, current_organization: form.current_organization).rewrite
|
39
|
+
parsed_global_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.global_description, current_organization: form.current_organization).rewrite
|
40
|
+
params = {
|
41
|
+
title: parsed_title,
|
42
|
+
local_description: parsed_local_description,
|
43
|
+
global_description: parsed_global_description,
|
44
|
+
component: form.current_component,
|
45
|
+
tags: form.tags,
|
46
|
+
sdg_code: form.sdg_code,
|
47
|
+
scope: form.scope,
|
48
|
+
state: form.state,
|
49
|
+
start_date: form.start_date,
|
50
|
+
end_date: form.end_date,
|
51
|
+
coordinating_entities: form.coordinating_entities,
|
52
|
+
collaborating_entities: form.collaborating_entities,
|
53
|
+
questionnaire: Decidim::Forms::Questionnaire.new,
|
54
|
+
card_image: form.card_image,
|
55
|
+
}
|
56
|
+
|
57
|
+
@challenge = Decidim.traceability.create!(
|
58
|
+
Decidim::Challenges::Challenge,
|
59
|
+
form.current_user,
|
60
|
+
params,
|
61
|
+
visibility: "all"
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
module Admin
|
6
|
+
# This command deals with destroying a Challenge from the admin panel.
|
7
|
+
class DestroyChallenge < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# page - The Challenge to be destroyed.
|
11
|
+
def initialize(challenge, current_user)
|
12
|
+
super()
|
13
|
+
@challenge = challenge
|
14
|
+
@current_user = current_user
|
15
|
+
end
|
16
|
+
|
17
|
+
# Public: Executes the command.
|
18
|
+
#
|
19
|
+
# Broadcasts :ok if it got destroyed
|
20
|
+
# Broadcasts :has_problems if not destroyed 'cause dependent
|
21
|
+
# Broadcasts :invalid if it not destroyed
|
22
|
+
def call
|
23
|
+
destroy_challenge
|
24
|
+
broadcast(:ok)
|
25
|
+
rescue ActiveRecord::DeleteRestrictionError
|
26
|
+
broadcast(:has_problems)
|
27
|
+
rescue ActiveRecord::RecordNotDestroyed
|
28
|
+
broadcast(:invalid)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :challenge, :current_user
|
34
|
+
|
35
|
+
def destroy_challenge
|
36
|
+
transaction do
|
37
|
+
Decidim.traceability.perform_action!(
|
38
|
+
"delete",
|
39
|
+
challenge,
|
40
|
+
current_user
|
41
|
+
) do
|
42
|
+
challenge.destroy!
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
module Admin
|
6
|
+
# This command is executed when the user exports the registrations of
|
7
|
+
# a Meeting from the admin panel.
|
8
|
+
class ExportChallengeSurveys < Decidim::Command
|
9
|
+
# challenge - The current instance of the page to be closed.
|
10
|
+
# format - a string representing the export format
|
11
|
+
# current_user - the user performing the action
|
12
|
+
def initialize(challenge, format, current_user)
|
13
|
+
super()
|
14
|
+
@challenge = challenge
|
15
|
+
@format = format
|
16
|
+
@current_user = current_user
|
17
|
+
end
|
18
|
+
|
19
|
+
# Exports the challenge registrations.
|
20
|
+
#
|
21
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
22
|
+
def call
|
23
|
+
broadcast(:ok, export_data)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :current_user, :challenge, :format
|
29
|
+
|
30
|
+
def export_data
|
31
|
+
Decidim.traceability.perform_action!(
|
32
|
+
:export_surveys,
|
33
|
+
challenge,
|
34
|
+
current_user
|
35
|
+
) do
|
36
|
+
Decidim::Exporters
|
37
|
+
.find_exporter(format)
|
38
|
+
.new(challenge.surveys, Decidim::Challenges::SurveySerializer)
|
39
|
+
.export
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
module Admin
|
6
|
+
# A command that sets a challenge as published.
|
7
|
+
class PublishChallenge < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# challenge - A Challenge that will be published
|
11
|
+
# current_user - the user performing the action
|
12
|
+
def initialize(challenge, current_user)
|
13
|
+
super()
|
14
|
+
@challenge = challenge
|
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 challenge.nil? || challenge.published?
|
26
|
+
|
27
|
+
Decidim.traceability.perform_action!("publish", challenge, current_user, visibility: "all") do
|
28
|
+
challenge.publish!
|
29
|
+
end
|
30
|
+
|
31
|
+
broadcast(:ok)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :challenge, :current_user
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|