Add list of targets to SDG tag list

Co-authored-by: Senén Rodero Rodríguez <senenrodero@gmail.com>
This commit is contained in:
Javi Martín
2021-01-23 16:01:05 +01:00
parent 7b3fcf6cb5
commit 1fefc910d6
9 changed files with 146 additions and 0 deletions

View File

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

View File

@@ -0,0 +1 @@
<%= link_list(*links, class: "sdg-target-tag-list") %>

View 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