Add local_targets index to the administration

This commit is contained in:
Senén Rodero Rodríguez
2020-11-23 17:29:40 +01:00
parent 2ad66409e2
commit 88bcf527d8
9 changed files with 113 additions and 1 deletions

View File

@@ -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 %>

View File

@@ -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

View File

@@ -8,7 +8,7 @@ class SDGManagement::SubnavigationComponent < ApplicationComponent
private
def sections
%i[goals targets]
%i[goals targets local_targets]
end
def link_to_section(section)

View File

@@ -0,0 +1,7 @@
class SDGManagement::LocalTargetsController < SDGManagement::BaseController
LocalTarget = ::SDG::LocalTarget
def index
@local_targets = LocalTarget.all.sort
end
end

View File

@@ -0,0 +1 @@
<%= render SDGManagement::LocalTargets::IndexComponent.new(@local_targets) %>

View File

@@ -75,6 +75,9 @@ en:
sdg/goal:
one: "goal"
other: "goals"
sdg/local_target:
one: "local target"
other: "local targets"
sdg/target:
one: "target"
other: "targets"
@@ -318,6 +321,10 @@ en:
code: "Code"
title: "Title"
description: "Description"
sdg/local_target:
title: "Title"
sdg/local_target/translation:
title: "Title"
sdg/target:
code: "Code"
title: "Title"

View File

@@ -75,6 +75,9 @@ es:
sdg/goal:
one: "objetivo"
other: "objetivos"
sdg/local_target:
one: "meta localizada"
other: "metas localizadas"
sdg/target:
one: "meta"
other: "metas"
@@ -315,6 +318,10 @@ es:
code: "Código"
title: "Título"
description: "Descripción"
sdg/local_target:
title: "Título"
sdg/local_target/translation:
title: "Título"
sdg/target:
code: "Código"
title: "Título"

View File

@@ -3,4 +3,5 @@ namespace :sdg_management do
resources :goals, only: [:index]
resources :targets, only: [:index]
resources :local_targets, only: [:index]
end

View 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