diff --git a/app/components/sdg_management/goals/index_component.html.erb b/app/components/sdg_management/goals/index_component.html.erb index 03d21e27d..d08dd0ca9 100644 --- a/app/components/sdg_management/goals/index_component.html.erb +++ b/app/components/sdg_management/goals/index_component.html.erb @@ -1,5 +1,9 @@ <%= header %> +<%# TODO: replace links with tabs %> +<%= link_to SDG::Goal.model_name.human(count: 2).titleize, sdg_management_goals_path %> +<%= link_to SDG::Target.model_name.human(count: 2).titleize, sdg_management_targets_path %> + diff --git a/app/components/sdg_management/menu_component.rb b/app/components/sdg_management/menu_component.rb index a4dfcb7a4..7c22e27c2 100644 --- a/app/components/sdg_management/menu_component.rb +++ b/app/components/sdg_management/menu_component.rb @@ -2,6 +2,6 @@ class SDGManagement::MenuComponent < ApplicationComponent private def sdg? - controller_name == "goals" + controller_name == "goals" || controller_name == "targets" end end diff --git a/app/components/sdg_management/targets/index_component.html.erb b/app/components/sdg_management/targets/index_component.html.erb new file mode 100644 index 000000000..6608dfb64 --- /dev/null +++ b/app/components/sdg_management/targets/index_component.html.erb @@ -0,0 +1,35 @@ +<%= header %> + +<%# TODO: replace links with tabs %> +<%= link_to SDG::Goal.model_name.human(count: 2).titleize, sdg_management_goals_path %> +<%= link_to SDG::Target.model_name.human(count: 2).titleize, sdg_management_targets_path %> + +
+ + + + + + + + + <% targets.group_by(&:goal).map do |goal, targets| %> + + + + + <% targets.each do |target| %> + + + + + <% end %> + <% end %> + +
<%= attribute_name(:title) %>
+ <%= goal.code %>. <%= goal.title %> +
+ <%= target.code %> + + <%= target.title %> +
diff --git a/app/components/sdg_management/targets/index_component.rb b/app/components/sdg_management/targets/index_component.rb new file mode 100644 index 000000000..35bd5815d --- /dev/null +++ b/app/components/sdg_management/targets/index_component.rb @@ -0,0 +1,23 @@ +class SDGManagement::Targets::IndexComponent < ApplicationComponent + include SDGManagement::Header + + attr_reader :targets + + def initialize(targets) + @targets = targets + end + + private + + def title + SDG::Target.model_name.human(count: 2).titleize + end + + def attribute_name(attribute) + SDG::Target.human_attribute_name(attribute) + end + + def header_id(object) + "#{dom_id(object)}_header" + end +end diff --git a/app/controllers/sdg_management/targets_controller.rb b/app/controllers/sdg_management/targets_controller.rb new file mode 100644 index 000000000..eda7391c8 --- /dev/null +++ b/app/controllers/sdg_management/targets_controller.rb @@ -0,0 +1,7 @@ +class SDGManagement::TargetsController < SDGManagement::BaseController + Target = ::SDG::Target + + def index + @targets = Target.all.sort + end +end diff --git a/app/views/sdg_management/targets/index.html.erb b/app/views/sdg_management/targets/index.html.erb new file mode 100644 index 000000000..a11c1c689 --- /dev/null +++ b/app/views/sdg_management/targets/index.html.erb @@ -0,0 +1 @@ +<%= render SDGManagement::Targets::IndexComponent.new(@targets) %> diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 8d07b0aae..5721fc5e5 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -75,6 +75,9 @@ en: sdg/goal: one: "goal" other: "goals" + sdg/target: + one: "target" + other: "targets" site_customization/page: one: Custom page other: Custom pages @@ -315,6 +318,9 @@ en: code: "Code" title: "Title" description: "Description" + sdg/target: + code: "Code" + title: "Title" site_customization/page: content: Content created_at: Created at diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index b3ab98a8e..4abe798c7 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -75,6 +75,9 @@ es: sdg/goal: one: "objetivo" other: "objetivos" + sdg/target: + one: "meta" + other: "metas" site_customization/page: one: Página other: Páginas @@ -312,6 +315,9 @@ es: code: "Código" title: "Título" description: "Descripción" + sdg/target: + code: "Código" + title: "Título" signature_sheet: title: "Título" signable_type: "Tipo de hoja de firmas" diff --git a/config/routes/sdg_management.rb b/config/routes/sdg_management.rb index d1da24999..50b0f45d5 100644 --- a/config/routes/sdg_management.rb +++ b/config/routes/sdg_management.rb @@ -2,4 +2,5 @@ namespace :sdg_management do root to: "goals#index" resources :goals, only: [:index] + resources :targets, only: [:index] end diff --git a/spec/system/sdg_management/targets_spec.rb b/spec/system/sdg_management/targets_spec.rb new file mode 100644 index 000000000..49fedc87f --- /dev/null +++ b/spec/system/sdg_management/targets_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +describe "Targets", :js do + before do + login_as(create(:administrator).user) + Setting["feature.sdg"] = true + end + + describe "Index" do + scenario "Visit the index" do + visit sdg_management_goals_path + click_link "Targets" + + expect(page).to have_title "SDG content - Targets" + within("table") { expect(page).to have_content "By 2030, eradicate extreme poverty" } + end + + scenario "Show targets grouped by goal and sorted asc by code" do + goal_8 = SDG::Goal[8] + goal_8_target_2 = SDG::Target["8.2"] + goal_8_target_10 = SDG::Target["8.10"] + goal_16 = SDG::Goal[16] + goal_16_target_10 = SDG::Target["16.10"] + goal_16_target_A = SDG::Target["16.A"] + + visit sdg_management_targets_path + + expect(goal_8.title).to appear_before(goal_8_target_2.title) + expect(goal_8_target_2.title).to appear_before(goal_8_target_10.title) + expect(goal_8_target_10.title).to appear_before(goal_16.title) + expect(goal_16.title).to appear_before(goal_16_target_10.title) + expect(goal_16_target_10.title).to appear_before(goal_16_target_A.title) + end + end +end