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 %>
|
<%= 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>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ class SDGManagement::MenuComponent < ApplicationComponent
|
|||||||
private
|
private
|
||||||
|
|
||||||
def sdg?
|
def sdg?
|
||||||
controller_name == "goals"
|
controller_name == "goals" || controller_name == "targets"
|
||||||
end
|
end
|
||||||
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:
|
sdg/goal:
|
||||||
one: "goal"
|
one: "goal"
|
||||||
other: "goals"
|
other: "goals"
|
||||||
|
sdg/target:
|
||||||
|
one: "target"
|
||||||
|
other: "targets"
|
||||||
site_customization/page:
|
site_customization/page:
|
||||||
one: Custom page
|
one: Custom page
|
||||||
other: Custom pages
|
other: Custom pages
|
||||||
@@ -315,6 +318,9 @@ en:
|
|||||||
code: "Code"
|
code: "Code"
|
||||||
title: "Title"
|
title: "Title"
|
||||||
description: "Description"
|
description: "Description"
|
||||||
|
sdg/target:
|
||||||
|
code: "Code"
|
||||||
|
title: "Title"
|
||||||
site_customization/page:
|
site_customization/page:
|
||||||
content: Content
|
content: Content
|
||||||
created_at: Created at
|
created_at: Created at
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ es:
|
|||||||
sdg/goal:
|
sdg/goal:
|
||||||
one: "objetivo"
|
one: "objetivo"
|
||||||
other: "objetivos"
|
other: "objetivos"
|
||||||
|
sdg/target:
|
||||||
|
one: "meta"
|
||||||
|
other: "metas"
|
||||||
site_customization/page:
|
site_customization/page:
|
||||||
one: Página
|
one: Página
|
||||||
other: Páginas
|
other: Páginas
|
||||||
@@ -312,6 +315,9 @@ es:
|
|||||||
code: "Código"
|
code: "Código"
|
||||||
title: "Título"
|
title: "Título"
|
||||||
description: "Descripción"
|
description: "Descripción"
|
||||||
|
sdg/target:
|
||||||
|
code: "Código"
|
||||||
|
title: "Título"
|
||||||
signature_sheet:
|
signature_sheet:
|
||||||
title: "Título"
|
title: "Título"
|
||||||
signable_type: "Tipo de hoja de firmas"
|
signable_type: "Tipo de hoja de firmas"
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ namespace :sdg_management do
|
|||||||
root to: "goals#index"
|
root to: "goals#index"
|
||||||
|
|
||||||
resources :goals, only: [:index]
|
resources :goals, only: [:index]
|
||||||
|
resources :targets, only: [:index]
|
||||||
end
|
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