Add local_targets index to the administration
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
<%= header %>
|
||||||
|
|
||||||
|
<%= render SDGManagement::SubnavigationComponent.new(current: :local_targets) do %>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<th id="local-target-title" scope="col"><%= attribute_name(:title) %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<% local_targets.group_by(&:target).map do |target, local_targets| %>
|
||||||
|
<tr class="target-header">
|
||||||
|
<th id="<%= header_id(target) %>" colspan="2" scope="colgroup">
|
||||||
|
<%= target.code %> <%= target.title %>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% local_targets.each do |local_target| %>
|
||||||
|
<tr id="<%= dom_id(local_target) %>" class="local-target">
|
||||||
|
<th headers="<%= header_id(target) %>" id="<%= header_id(local_target) %>">
|
||||||
|
<%= local_target.code %>
|
||||||
|
</th>
|
||||||
|
<td headers="<%= header_id(target) %> <%= header_id(local_target) %> local-target-title">
|
||||||
|
<%= local_target.title %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% end %>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
class SDGManagement::LocalTargets::IndexComponent < ApplicationComponent
|
||||||
|
include SDGManagement::Header
|
||||||
|
|
||||||
|
attr_reader :local_targets
|
||||||
|
|
||||||
|
def initialize(local_targets)
|
||||||
|
@local_targets = local_targets
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def title
|
||||||
|
SDG::LocalTarget.model_name.human(count: 2).titleize
|
||||||
|
end
|
||||||
|
|
||||||
|
def attribute_name(attribute)
|
||||||
|
SDG::LocalTarget.human_attribute_name(attribute)
|
||||||
|
end
|
||||||
|
|
||||||
|
def header_id(object)
|
||||||
|
"#{dom_id(object)}_header"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -8,7 +8,7 @@ class SDGManagement::SubnavigationComponent < ApplicationComponent
|
|||||||
private
|
private
|
||||||
|
|
||||||
def sections
|
def sections
|
||||||
%i[goals targets]
|
%i[goals targets local_targets]
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_section(section)
|
def link_to_section(section)
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
class SDGManagement::LocalTargetsController < SDGManagement::BaseController
|
||||||
|
LocalTarget = ::SDG::LocalTarget
|
||||||
|
|
||||||
|
def index
|
||||||
|
@local_targets = LocalTarget.all.sort
|
||||||
|
end
|
||||||
|
end
|
||||||
1
app/views/sdg_management/local_targets/index.html.erb
Normal file
1
app/views/sdg_management/local_targets/index.html.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<%= render SDGManagement::LocalTargets::IndexComponent.new(@local_targets) %>
|
||||||
@@ -75,6 +75,9 @@ en:
|
|||||||
sdg/goal:
|
sdg/goal:
|
||||||
one: "goal"
|
one: "goal"
|
||||||
other: "goals"
|
other: "goals"
|
||||||
|
sdg/local_target:
|
||||||
|
one: "local target"
|
||||||
|
other: "local targets"
|
||||||
sdg/target:
|
sdg/target:
|
||||||
one: "target"
|
one: "target"
|
||||||
other: "targets"
|
other: "targets"
|
||||||
@@ -318,6 +321,10 @@ en:
|
|||||||
code: "Code"
|
code: "Code"
|
||||||
title: "Title"
|
title: "Title"
|
||||||
description: "Description"
|
description: "Description"
|
||||||
|
sdg/local_target:
|
||||||
|
title: "Title"
|
||||||
|
sdg/local_target/translation:
|
||||||
|
title: "Title"
|
||||||
sdg/target:
|
sdg/target:
|
||||||
code: "Code"
|
code: "Code"
|
||||||
title: "Title"
|
title: "Title"
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ es:
|
|||||||
sdg/goal:
|
sdg/goal:
|
||||||
one: "objetivo"
|
one: "objetivo"
|
||||||
other: "objetivos"
|
other: "objetivos"
|
||||||
|
sdg/local_target:
|
||||||
|
one: "meta localizada"
|
||||||
|
other: "metas localizadas"
|
||||||
sdg/target:
|
sdg/target:
|
||||||
one: "meta"
|
one: "meta"
|
||||||
other: "metas"
|
other: "metas"
|
||||||
@@ -315,6 +318,10 @@ es:
|
|||||||
code: "Código"
|
code: "Código"
|
||||||
title: "Título"
|
title: "Título"
|
||||||
description: "Descripción"
|
description: "Descripción"
|
||||||
|
sdg/local_target:
|
||||||
|
title: "Título"
|
||||||
|
sdg/local_target/translation:
|
||||||
|
title: "Título"
|
||||||
sdg/target:
|
sdg/target:
|
||||||
code: "Código"
|
code: "Código"
|
||||||
title: "Título"
|
title: "Título"
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ namespace :sdg_management do
|
|||||||
|
|
||||||
resources :goals, only: [:index]
|
resources :goals, only: [:index]
|
||||||
resources :targets, only: [:index]
|
resources :targets, only: [:index]
|
||||||
|
resources :local_targets, only: [:index]
|
||||||
end
|
end
|
||||||
|
|||||||
33
spec/system/sdg_management/local_targets_spec.rb
Normal file
33
spec/system/sdg_management/local_targets_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe "Local Targets", :js do
|
||||||
|
before do
|
||||||
|
login_as(create(:administrator).user)
|
||||||
|
Setting["feature.sdg"] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Index" do
|
||||||
|
scenario "Visit the index" do
|
||||||
|
create(:sdg_local_target, code: "1.1.1", title: "Affordable food")
|
||||||
|
|
||||||
|
visit sdg_management_goals_path
|
||||||
|
click_link "Local Targets"
|
||||||
|
|
||||||
|
expect(page).to have_title "SDG content - Local Targets"
|
||||||
|
within("table") { expect(page).to have_content "Affordable food for everyone" }
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Show local targets grouped by target" do
|
||||||
|
target_1 = SDG::Target["1.1"]
|
||||||
|
target_1_local_target = create(:sdg_local_target, code: "1.1.1", target: target_1)
|
||||||
|
target_2 = SDG::Target["2.1"]
|
||||||
|
target_2_local_target = create(:sdg_local_target, code: "2.1.1", target: target_2)
|
||||||
|
|
||||||
|
visit sdg_management_local_targets_path
|
||||||
|
|
||||||
|
expect(target_1.title).to appear_before(target_1_local_target.title)
|
||||||
|
expect(target_1_local_target.title).to appear_before(target_2.title)
|
||||||
|
expect(target_2.title).to appear_before(target_2_local_target.title)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user