Add SDG page to create local targets
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
<%= back_link_to sdg_management_local_targets_path %>
|
||||||
|
|
||||||
|
<%= header %>
|
||||||
|
|
||||||
|
<%= render "shared/globalize_locales", resource: local_target %>
|
||||||
|
|
||||||
|
<%= translatable_form_for [:sdg_managment, local_target], url: form_url do |f| %>
|
||||||
|
<%= render "shared/errors", resource: local_target %>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= f.select :target_id, target_options %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= f.text_field :code, hint: t("sdg_management.local_targets.form.code") %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<%= f.translatable_fields do |translations_form| %>
|
||||||
|
<div class="small-12 column end">
|
||||||
|
<%= translations_form.text_field :title %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="small-12 column end">
|
||||||
|
<%= translations_form.text_area :description,
|
||||||
|
rows: 4,
|
||||||
|
hint: t("sdg_management.local_targets.form.description") %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= f.submit class: "button" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
class SDGManagement::LocalTargets::FormComponent < ApplicationComponent
|
||||||
|
delegate :back_link_to, to: :helpers
|
||||||
|
include SDGManagement::Header
|
||||||
|
include TranslatableFormHelper
|
||||||
|
include GlobalizeHelper
|
||||||
|
|
||||||
|
attr_reader :local_target
|
||||||
|
|
||||||
|
def initialize(local_target)
|
||||||
|
@local_target = local_target
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def title
|
||||||
|
t("sdg_management.local_targets.new.title")
|
||||||
|
end
|
||||||
|
|
||||||
|
def form_url
|
||||||
|
if local_target.persisted?
|
||||||
|
sdg_management_local_target_path(local_target)
|
||||||
|
else
|
||||||
|
sdg_management_local_targets_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def target_options
|
||||||
|
grouped_targets = SDG::Goal.order(:code).map do |goal|
|
||||||
|
[
|
||||||
|
code_and_title(goal),
|
||||||
|
goal.targets.sort.map { |target| [code_and_title(target), target.id] }
|
||||||
|
]
|
||||||
|
end
|
||||||
|
grouped_options_for_select(grouped_targets, local_target.target_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def code_and_title(resource)
|
||||||
|
"#{resource.code} #{resource.title}"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
<%= header %>
|
<%= header do %>
|
||||||
|
<%= link_to t("sdg_management.local_targets.index.new"),
|
||||||
|
new_sdg_management_local_target_path,
|
||||||
|
class: "new-link" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= render SDGManagement::SubnavigationComponent.new(current: :local_targets) do %>
|
<%= render SDGManagement::SubnavigationComponent.new(current: :local_targets) do %>
|
||||||
<table>
|
<table>
|
||||||
|
|||||||
@@ -1,7 +1,30 @@
|
|||||||
class SDGManagement::LocalTargetsController < SDGManagement::BaseController
|
class SDGManagement::LocalTargetsController < SDGManagement::BaseController
|
||||||
|
include Translatable
|
||||||
|
|
||||||
LocalTarget = ::SDG::LocalTarget
|
LocalTarget = ::SDG::LocalTarget
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@local_targets = LocalTarget.all.sort
|
@local_targets = LocalTarget.all.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@local_target = LocalTarget.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@local_target = LocalTarget.new(local_target_params)
|
||||||
|
|
||||||
|
if @local_target.save
|
||||||
|
redirect_to sdg_management_local_targets_path, notice: t("sdg_management.local_targets.create.notice")
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def local_target_params
|
||||||
|
translations_attributes = translation_params(LocalTarget)
|
||||||
|
params.require(:sdg_local_target).permit(:code, :target_id, translations_attributes)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
1
app/views/sdg_management/local_targets/new.html.erb
Normal file
1
app/views/sdg_management/local_targets/new.html.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<%= render SDGManagement::LocalTargets::FormComponent.new(@local_target) %>
|
||||||
@@ -322,9 +322,12 @@ en:
|
|||||||
title: "Title"
|
title: "Title"
|
||||||
description: "Description"
|
description: "Description"
|
||||||
sdg/local_target:
|
sdg/local_target:
|
||||||
|
code: "Code"
|
||||||
|
target_id: "Target"
|
||||||
title: "Title"
|
title: "Title"
|
||||||
sdg/local_target/translation:
|
sdg/local_target/translation:
|
||||||
title: "Title"
|
title: "Title"
|
||||||
|
description: "Description"
|
||||||
sdg/target:
|
sdg/target:
|
||||||
code: "Code"
|
code: "Code"
|
||||||
title: "Title"
|
title: "Title"
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ en:
|
|||||||
local_census_records/import: Local Census Records Import
|
local_census_records/import: Local Census Records Import
|
||||||
site_customization/content_block: content block
|
site_customization/content_block: content block
|
||||||
site_customization/page: page
|
site_customization/page: page
|
||||||
|
sdg/local_target: local target
|
||||||
geozones:
|
geozones:
|
||||||
none: All city
|
none: All city
|
||||||
layouts:
|
layouts:
|
||||||
|
|||||||
@@ -4,3 +4,13 @@ en:
|
|||||||
title: "SDG content"
|
title: "SDG content"
|
||||||
menu:
|
menu:
|
||||||
sdg_content: "Goals and Targets"
|
sdg_content: "Goals and Targets"
|
||||||
|
local_targets:
|
||||||
|
create:
|
||||||
|
notice: "Local target created successfully"
|
||||||
|
form:
|
||||||
|
code: "Code must start with the selected target code followed by a dot"
|
||||||
|
description: "This description will be shown as help to users."
|
||||||
|
index:
|
||||||
|
new: "Create local target"
|
||||||
|
new:
|
||||||
|
title: "New local target"
|
||||||
|
|||||||
@@ -319,9 +319,12 @@ es:
|
|||||||
title: "Título"
|
title: "Título"
|
||||||
description: "Descripción"
|
description: "Descripción"
|
||||||
sdg/local_target:
|
sdg/local_target:
|
||||||
|
code: "Código"
|
||||||
|
target_id: "Meta"
|
||||||
title: "Título"
|
title: "Título"
|
||||||
sdg/local_target/translation:
|
sdg/local_target/translation:
|
||||||
title: "Título"
|
title: "Título"
|
||||||
|
description: "Descripción"
|
||||||
sdg/target:
|
sdg/target:
|
||||||
code: "Código"
|
code: "Código"
|
||||||
title: "Título"
|
title: "Título"
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ es:
|
|||||||
local_census_records/import: la importación de registros del censo local
|
local_census_records/import: la importación de registros del censo local
|
||||||
site_customization/content_block: el bloque
|
site_customization/content_block: el bloque
|
||||||
site_customization/page: la página
|
site_customization/page: la página
|
||||||
|
sdg/local_target: la meta localizada
|
||||||
geozones:
|
geozones:
|
||||||
none: Toda la ciudad
|
none: Toda la ciudad
|
||||||
layouts:
|
layouts:
|
||||||
|
|||||||
@@ -4,3 +4,13 @@ es:
|
|||||||
title: "Contenido ODS"
|
title: "Contenido ODS"
|
||||||
menu:
|
menu:
|
||||||
sdg_content: "Objetivos y Metas"
|
sdg_content: "Objetivos y Metas"
|
||||||
|
local_targets:
|
||||||
|
create:
|
||||||
|
notice: "Meta localizada creada correctamente"
|
||||||
|
form:
|
||||||
|
code: "El código debe comenzar por el código de la meta seleccionada seguida de un '.'"
|
||||||
|
description: "Este texto ser mostrará como ayuda para los usuarios."
|
||||||
|
index:
|
||||||
|
new: "Crear meta localizada"
|
||||||
|
new:
|
||||||
|
title: "Nueva meta localizada"
|
||||||
|
|||||||
@@ -3,5 +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]
|
resources :local_targets, only: [:index, :new, :create]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ describe "Local Targets", :js do
|
|||||||
|
|
||||||
expect(page).to have_title "SDG content - Local Targets"
|
expect(page).to have_title "SDG content - Local Targets"
|
||||||
within("table") { expect(page).to have_content "Affordable food for everyone" }
|
within("table") { expect(page).to have_content "Affordable food for everyone" }
|
||||||
|
expect(page).to have_link "Create local target", href: new_sdg_management_local_target_path
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Show local targets grouped by target" do
|
scenario "Show local targets grouped by target" do
|
||||||
@@ -30,4 +31,32 @@ describe "Local Targets", :js do
|
|||||||
expect(target_2.title).to appear_before(target_2_local_target.title)
|
expect(target_2.title).to appear_before(target_2_local_target.title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Create" do
|
||||||
|
scenario "Shows succesful notice when form is fullfilled correctly" do
|
||||||
|
visit new_sdg_management_local_target_path
|
||||||
|
|
||||||
|
target = SDG::Target["1.1"]
|
||||||
|
select "#{target.code} #{target.title}", from: "Target"
|
||||||
|
fill_in "Code", with: "1.1.1"
|
||||||
|
fill_in "Title", with: "Local target title"
|
||||||
|
fill_in "Description", with: "Local target description"
|
||||||
|
click_button "Create local target"
|
||||||
|
|
||||||
|
expect(page).to have_content("Local target created successfully")
|
||||||
|
expect(page).to have_content("1.1.1")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Shows form errors when not valid" do
|
||||||
|
visit new_sdg_management_local_target_path
|
||||||
|
|
||||||
|
target = SDG::Target["2.3"]
|
||||||
|
code_and_title = "#{target.code} #{target.title}"
|
||||||
|
select code_and_title, from: "Target"
|
||||||
|
click_button "Create local target"
|
||||||
|
|
||||||
|
expect(page).to have_content("errors prevented this local target from being saved.")
|
||||||
|
expect(page).to have_select("Target", selected: code_and_title)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user