Add list of targets to SDG tag list
Co-authored-by: Senén Rodero Rodríguez <senenrodero@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
<div class="sdg-tag-list">
|
||||
<%= render SDG::Goals::TagListComponent.new(record, limit: limit) %>
|
||||
<%= render SDG::Targets::TagListComponent.new(record, limit: limit) %>
|
||||
</div>
|
||||
|
||||
1
app/components/sdg/targets/tag_list_component.html.erb
Normal file
1
app/components/sdg/targets/tag_list_component.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= link_list(*links, class: "sdg-target-tag-list") %>
|
||||
36
app/components/sdg/targets/tag_list_component.rb
Normal file
36
app/components/sdg/targets/tag_list_component.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
class SDG::Targets::TagListComponent < ApplicationComponent
|
||||
include SDG::TagList
|
||||
|
||||
private
|
||||
|
||||
def record
|
||||
record_or_name
|
||||
end
|
||||
|
||||
def links
|
||||
[*target_links, see_more_link(targets)]
|
||||
end
|
||||
|
||||
def target_links
|
||||
targets.sort[0..(limit.to_i - 1)].map do |target|
|
||||
[
|
||||
"#{SDG::Target.model_name.human} #{target.code}",
|
||||
index_by_target(target),
|
||||
title: filter_text(target),
|
||||
data: { code: target.code }
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
def targets
|
||||
record.sdg_targets
|
||||
end
|
||||
|
||||
def index_by_target(target)
|
||||
index_by(target: target.code)
|
||||
end
|
||||
|
||||
def i18n_namespace
|
||||
"targets"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user