Add targets index to the administration
Co-authored-by: Javi Martín <javim@elretirao.net>
This commit is contained in:
@@ -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 %>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@@ -2,6 +2,6 @@ class SDGManagement::MenuComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def sdg?
|
||||
controller_name == "goals"
|
||||
controller_name == "goals" || controller_name == "targets"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td></td>
|
||||
<th id="target-title" scope="col"><%= attribute_name(:title) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% targets.group_by(&:goal).map do |goal, targets| %>
|
||||
<tr class="goal-header">
|
||||
<th id="<%= header_id(goal) %>" colspan="2" scope="colgroup">
|
||||
<%= goal.code %>. <%= goal.title %>
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
<% targets.each do |target| %>
|
||||
<tr id="<%= dom_id(target) %>" class="target">
|
||||
<th headers="<%= header_id(goal) %>" id="<%= header_id(target) %>">
|
||||
<%= target.code %>
|
||||
</th>
|
||||
<td headers="<%= header_id(goal) %> <%= header_id(target) %> target-title">
|
||||
<%= target.title %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
23
app/components/sdg_management/targets/index_component.rb
Normal file
23
app/components/sdg_management/targets/index_component.rb
Normal file
@@ -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
|
||||
7
app/controllers/sdg_management/targets_controller.rb
Normal file
7
app/controllers/sdg_management/targets_controller.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class SDGManagement::TargetsController < SDGManagement::BaseController
|
||||
Target = ::SDG::Target
|
||||
|
||||
def index
|
||||
@targets = Target.all.sort
|
||||
end
|
||||
end
|
||||
1
app/views/sdg_management/targets/index.html.erb
Normal file
1
app/views/sdg_management/targets/index.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= render SDGManagement::Targets::IndexComponent.new(@targets) %>
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -2,4 +2,5 @@ namespace :sdg_management do
|
||||
root to: "goals#index"
|
||||
|
||||
resources :goals, only: [:index]
|
||||
resources :targets, only: [:index]
|
||||
end
|
||||
|
||||
35
spec/system/sdg_management/targets_spec.rb
Normal file
35
spec/system/sdg_management/targets_spec.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user