From d26607183e0c76f49ff7f10ab687c62f4a388e2c Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 10 Feb 2021 18:43:14 +0100 Subject: [PATCH] Add sdg help page In this page we will render a list of clickable Goals icons that will show their targets and related local targets Co-authored-by: Senen --- app/assets/stylesheets/sdg/help.scss | 14 +++++++++ .../sdg/related_list_selector.scss | 7 ++++- .../sdg/goals/help_page_component.html.erb | 25 ++++++++++++++++ .../sdg/goals/help_page_component.rb | 17 +++++++++++ app/controllers/sdg/goals_controller.rb | 4 +++ app/models/abilities/everyone.rb | 2 +- app/views/sdg/goals/help.html.erb | 1 + config/locales/en/sdg.yml | 5 +++- config/locales/es/sdg.yml | 3 ++ config/routes/sdg.rb | 1 + .../sdg/goals/help_page_component_spec.rb | 28 +++++++++++++++++ spec/system/sdg/goals_spec.rb | 30 +++++++++++++++++++ 12 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 app/assets/stylesheets/sdg/help.scss create mode 100644 app/components/sdg/goals/help_page_component.html.erb create mode 100644 app/components/sdg/goals/help_page_component.rb create mode 100644 app/views/sdg/goals/help.html.erb create mode 100644 spec/components/sdg/goals/help_page_component_spec.rb diff --git a/app/assets/stylesheets/sdg/help.scss b/app/assets/stylesheets/sdg/help.scss new file mode 100644 index 000000000..0d9b94df1 --- /dev/null +++ b/app/assets/stylesheets/sdg/help.scss @@ -0,0 +1,14 @@ +.sdg-help-content { + @include grid-column-gutter; + + > .tabs { + @extend %sdg-goal-list-expanded; + + li { + + &:focus { + outline: $outline-focus; + } + } + } +} diff --git a/app/assets/stylesheets/sdg/related_list_selector.scss b/app/assets/stylesheets/sdg/related_list_selector.scss index ea3d00165..9f2b2a2a8 100644 --- a/app/assets/stylesheets/sdg/related_list_selector.scss +++ b/app/assets/stylesheets/sdg/related_list_selector.scss @@ -19,6 +19,10 @@ .goals { @extend %sdg-goal-list-expanded; + + label { + @include element-invisible; + } + legend { font-weight: normal; font-style: italic; @@ -37,9 +41,10 @@ } } - label { + .help-text { font-weight: normal; font-style: italic; + font-size: $base-font-size; } .input-section { diff --git a/app/components/sdg/goals/help_page_component.html.erb b/app/components/sdg/goals/help_page_component.html.erb new file mode 100644 index 000000000..d221f8d0f --- /dev/null +++ b/app/components/sdg/goals/help_page_component.html.erb @@ -0,0 +1,25 @@ +<% provide(:title) { t("sdg.goals.help.title") } %> + +
+

<%= t("sdg.goals.help.title") %>

+

<%= t("sdg.goals.help.description") %>

+
    + <% @goals.each do |goal| %> +
  • + <%= link_to "#goal_#{goal.code}_tab" do %> + <% render SDG::Goals::IconComponent.new(goal) %> + <% end %> +
  • + <% end %> +
+ +
+ <% @goals.each do |goal| %> +
+

<%= goal.code_and_title %>

+

<%= sanitize t("sdg.goals.goal_#{goal.code}.description") %>

+ <%= render SDG::Goals::TargetsComponent.new(goal) %> +
+ <% end %> +
+
diff --git a/app/components/sdg/goals/help_page_component.rb b/app/components/sdg/goals/help_page_component.rb new file mode 100644 index 000000000..470bdf5e6 --- /dev/null +++ b/app/components/sdg/goals/help_page_component.rb @@ -0,0 +1,17 @@ +class SDG::Goals::HelpPageComponent < ApplicationComponent + attr_reader :goals + + def initialize(goals) + @goals = goals + end + + def render? + feature?("sdg") + end + + private + + def is_active?(goal) + "is-active" if goal.code == 1 + end +end diff --git a/app/controllers/sdg/goals_controller.rb b/app/controllers/sdg/goals_controller.rb index 1c34983c8..8fcc94f3c 100644 --- a/app/controllers/sdg/goals_controller.rb +++ b/app/controllers/sdg/goals_controller.rb @@ -11,4 +11,8 @@ class SDG::GoalsController < ApplicationController def show end + + def help + @goals = @goals.order(:code) + end end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index b32e115e3..216b101f1 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -28,7 +28,7 @@ module Abilities can [:read, :map, :share], Legislation::Proposal can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation - can :read, ::SDG::Goal + can [:read, :help], ::SDG::Goal can :read, ::SDG::Phase end end diff --git a/app/views/sdg/goals/help.html.erb b/app/views/sdg/goals/help.html.erb new file mode 100644 index 000000000..28e2139fc --- /dev/null +++ b/app/views/sdg/goals/help.html.erb @@ -0,0 +1 @@ +<%= render SDG::Goals::HelpPageComponent.new(@goals) %> diff --git a/config/locales/en/sdg.yml b/config/locales/en/sdg.yml index 0eb3a869c..c3fbb20ac 100644 --- a/config/locales/en/sdg.yml +++ b/config/locales/en/sdg.yml @@ -24,7 +24,7 @@ en: goal_2: title: "Zero Hunger" title_in_two_lines: "Zero\nHunger" - description: "Zero Hunger" + description: "Zero Hunger." long_description: '

After decades of steady decline, the number of people who suffer from hunger – as measured by the prevalence of undernourishment – began to slowly increase again in 2015. Current estimates show that nearly 690 million people are hungry, or 8.9 percent of the world population – up by 10 million people in one year and by nearly 60 million in five years.

The world is not on track to achieve Zero Hunger by 2030. If recent trends continue, the number of people affected by hunger would surpass 840 million by 2030.

According to the World Food Programme, 135 million suffer from acute hunger largely due to man-made conflicts, climate change and economic downturns. The COVID-19 pandemic could now double that number, putting an additional 130 million people at risk of suffering acute hunger by the end of 2020.

With more than a quarter of a billion people potentially at the brink of starvation, swift action needs to be taken to provide food and humanitarian relief to the most at-risk regions.

At the same time, a profound change of the global food and agriculture system is needed if we are to nourish the more than 690 million people who are hungry today – and the additional 2 billion people the world will have by 2050. Increasing agricultural productivity and sustainable food production are crucial to help alleviate the perils of hunger.

' targets: target_2_1: @@ -441,6 +441,9 @@ en: title: "By 2020, enhance capacity-building support to developing countries, including for least developed countries and small island developing States, to increase significantly the availability of high-quality, timely and reliable data disaggregated by income, gender, age, race, ethnicity, migratory status, disability, geographic location and other characteristics relevant in national contexts." target_17_19: title: "By 2030, build on existing initiatives to develop measurements of progress on sustainable development that complement gross domestic product, and support statistical capacity-building in developing countries." + help: + title: "Sustainable Development Goals help" + description: "You can align your contributions to the community (debates, citizen proposals and investment projects) with the Sustaniable Development Goals 2030 Agenda, this will allow us to have an overview of our contribution to each of the Sustainable Development Goals. Below you can find out about all the goals, their targets and localized targets." show: read_more: "Read more about %{goal}" read_less: "Read less about %{goal}" diff --git a/config/locales/es/sdg.yml b/config/locales/es/sdg.yml index a3f4f9561..879a2484d 100644 --- a/config/locales/es/sdg.yml +++ b/config/locales/es/sdg.yml @@ -441,6 +441,9 @@ es: title: "De aquí a 2020, mejorar el apoyo a la creación de capacidad prestado a los países en desarrollo, incluidos los países menos adelantados y los pequeños Estados insulares en desarrollo, para aumentar significativamente la disponibilidad de datos oportunos, fiables y de gran calidad desglosados por ingresos, sexo, edad, raza, origen étnico, estatus migratorio, discapacidad, ubicación geográfica y otras características pertinentes en los contextos nacionales." target_17_19: title: "De aquí a 2030, aprovechar las iniciativas existentes para elaborar indicadores que permitan medir los progresos en materia de desarrollo sostenible y complementen el producto interno bruto, y apoyar la creación de capacidad estadística en los países en desarrollo." + help: + title: "Ayuda Objetivos de Desarrollo Sostenible" + description: "Puedes alinear tus aportaciones a la comunidad (debates, propuestas ciudadanas y proyectos de inversión) con los Objetivos de Desarrollo Sostenible de la Agenda 2030, esto nos permitirá tener una visión general de nuestra aportación en cada uno de los objetivos de desarrollo sostenible. A continuación puedes informarte de todos los objetivos, sus metas y las metas localizadas." show: read_more: "Leer más sobre %{goal}" read_less: "Leer menos sobre %{goal}" diff --git a/config/routes/sdg.rb b/config/routes/sdg.rb index 52525c685..758738f15 100644 --- a/config/routes/sdg.rb +++ b/config/routes/sdg.rb @@ -1,3 +1,4 @@ namespace :sdg do resources :goals, param: :code, only: [:index, :show] + get :help, controller: "goals" end diff --git a/spec/components/sdg/goals/help_page_component_spec.rb b/spec/components/sdg/goals/help_page_component_spec.rb new file mode 100644 index 000000000..6e02f58f0 --- /dev/null +++ b/spec/components/sdg/goals/help_page_component_spec.rb @@ -0,0 +1,28 @@ +require "rails_helper" + +describe SDG::Goals::HelpPageComponent, type: :component do + let(:goals) { SDG::Goal.all } + let(:component) { SDG::Goals::HelpPageComponent.new(goals) } + + before do + Setting["feature.sdg"] = true + end + + it "does not render when the feature is disabled" do + Setting["feature.sdg"] = false + + render_inline component + + expect(page).not_to have_css ".sdg-help-content" + end + + it "renders content when the feature is enabled" do + render_inline component + + expect(page).to have_css ".sdg-help-content" + expect(page).to have_content SDG::Goal[1].title + expect(page).to have_content SDG::Goal[1].description + expect(page).to have_css "#help_tabs" + expect(page).to have_css "#goal_1_tab" + end +end diff --git a/spec/system/sdg/goals_spec.rb b/spec/system/sdg/goals_spec.rb index b2e737172..e13e42bbf 100644 --- a/spec/system/sdg/goals_spec.rb +++ b/spec/system/sdg/goals_spec.rb @@ -140,4 +140,34 @@ describe "SDG Goals", :js do end end end + + describe "Help" do + scenario "shows all SDGs targets" do + create(:sdg_local_target, code: "15.1.1", title: "SDG local target sample text") + visit sdg_help_path + + expect(page).to have_content "You can align your contributions to the community" + expect(page).to have_css "h2", exact_text: "1. No Poverty" + expect(page).to have_content "End poverty in all its forms, everywhere." + expect(page).to have_content "1.1 By 2030, eradicate extreme poverty for all people everywhere" + + click_link "7. Affordable and Clean Energy" + + expect(page).not_to have_css "h2", exact_text: "1. No Poverty" + expect(page).to have_css "h2", exact_text: "7. Affordable and Clean Energy" + expect(page).to have_content "Ensure access to affordable, reliable, sustainable and modern energy." + expect(page).to have_content "7.1 By 2030, ensure universal access to affordable" + + click_link "15. Life on Land" + + expect(page).to have_css "h2", exact_text: "15. Life on Land" + expect(page).to have_content "Sustainably manage forests, combat desertification, halt and reverse" + expect(page).to have_content "15.1 By 2020, ensure the conservation, restoration and sustainable use" + + click_link "Local targets" + + expect(page).not_to have_content "15.1 By 2020, ensure the conservation, restoration and sustainable use" + expect(page).to have_content "SDG local target sample text" + end + end end