-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4345 from consul/sdg_list_refactor
Refactor tags and SDG "tags" rendering
- Loading branch information
Showing
32 changed files
with
254 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -606,12 +606,6 @@ | |
img { | ||
max-width: 12rem; | ||
} | ||
|
||
.budget-investment-content { | ||
ul { | ||
margin-bottom: 0; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...s/stylesheets/sdg/goals/filter_links.scss → ...sets/stylesheets/sdg/goals/tag_cloud.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.sdg-goal-filter-links { | ||
.sdg-goal-tag-cloud { | ||
|
||
.sdg-goal-tag-list { | ||
@extend %sdg-goal-list; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,31 @@ | ||
module SDG::TagList | ||
extend ActiveSupport::Concern | ||
attr_reader :record_or_name, :limit | ||
delegate :link_list, to: :helpers | ||
attr_reader :record, :limit | ||
|
||
def initialize(record_or_name, limit: nil) | ||
@record_or_name = record_or_name | ||
def initialize(record, limit: nil) | ||
@record = record | ||
@limit = limit | ||
end | ||
|
||
def render? | ||
process.enabled? | ||
SDG::ProcessEnabled.new(record).enabled? | ||
end | ||
|
||
def see_more_link(collection) | ||
count = count_out_of_limit(collection) | ||
def tag_records | ||
tags = record.send(association_name) | ||
|
||
if count > 0 | ||
[ | ||
"#{count}+", | ||
polymorphic_path(record), | ||
class: "more-#{i18n_namespace}", title: t("sdg.#{i18n_namespace}.filter.more", count: count) | ||
] | ||
if tags.respond_to?(:limit) | ||
tags.order(:code).limit(limit) | ||
else | ||
tags.sort[0..(limit.to_i - 1)] | ||
end | ||
end | ||
|
||
def filter_text(goal_or_target) | ||
t("sdg.#{i18n_namespace}.filter.link", | ||
resources: model.model_name.human(count: :other), | ||
code: goal_or_target.code) | ||
def see_more_link | ||
render Shared::SeeMoreLinkComponent.new(record, association_name, limit: limit) | ||
end | ||
|
||
def index_by(advanced_search) | ||
polymorphic_path(model, advanced_search: advanced_search) | ||
end | ||
|
||
def count_out_of_limit(collection) | ||
return 0 unless limit | ||
|
||
collection.size - limit | ||
end | ||
|
||
def process | ||
@process ||= SDG::ProcessEnabled.new(record_or_name) | ||
end | ||
|
||
def model | ||
process.name.constantize | ||
def association_name | ||
raise NotImplementedError, "method must be implemented in the included class" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= link_list(*links, class: "sdg-#{parameter_name}-tag-list") %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
class SDG::FilterLinksComponent < ApplicationComponent | ||
attr_reader :records, :related_model, :see_more_link | ||
delegate :link_list, to: :helpers | ||
|
||
def initialize(records, related_model, see_more_link: nil) | ||
@records = records | ||
@related_model = related_model | ||
@see_more_link = see_more_link | ||
end | ||
|
||
def links | ||
[*sdg_links, see_more_link] | ||
end | ||
|
||
private | ||
|
||
def sdg_links | ||
records.map do |goal_or_target| | ||
[ | ||
render(SDG::TagComponent.new(goal_or_target)), | ||
index_by(parameter_name => goal_or_target.code), | ||
title: filter_text(goal_or_target), | ||
data: { code: goal_or_target.code } | ||
] | ||
end | ||
end | ||
|
||
def filter_text(goal_or_target) | ||
t("sdg.#{i18n_namespace}.filter.link", | ||
resources: related_model.model_name.human(count: :other), | ||
code: goal_or_target.code) | ||
end | ||
|
||
def index_by(advanced_search) | ||
polymorphic_path(related_model, advanced_search: advanced_search) | ||
end | ||
|
||
def i18n_namespace | ||
parameter_name.pluralize | ||
end | ||
|
||
def parameter_name | ||
if records.first.is_a?(SDG::Goal) | ||
"goal" | ||
else | ||
"target" | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="sdg-goal-tag-cloud"> | ||
<div class="sidebar-divider"></div> | ||
<h2 class="sidebar-title"><%= heading %></h2> | ||
<%= render SDG::FilterLinksComponent.new(goals, class_name.constantize) %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<%= link_list(*links, class: "sdg-goal-tag-list") %> | ||
<%= render SDG::FilterLinksComponent.new(tag_records, related_model, see_more_link: see_more_link) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= text -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class SDG::TagComponent < ApplicationComponent | ||
attr_reader :goal_or_target | ||
|
||
def initialize(goal_or_target) | ||
@goal_or_target = goal_or_target | ||
end | ||
|
||
def text | ||
if goal_or_target.is_a?(SDG::Goal) | ||
render SDG::Goals::IconComponent.new(goal_or_target) | ||
else | ||
"#{SDG::Target.model_name.human} #{goal_or_target.code}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<%= link_list(*links, class: "sdg-target-tag-list") %> | ||
<%= render SDG::FilterLinksComponent.new(tag_records, related_model, see_more_link: see_more_link) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% if count_out_of_limit > 0 %> | ||
<%= link_to text, url, class: html_class, title: title %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class Shared::SeeMoreLinkComponent < ApplicationComponent | ||
attr_reader :record, :association_name, :limit | ||
|
||
def initialize(record, association_name, limit: nil) | ||
@record = record | ||
@association_name = association_name | ||
@limit = limit | ||
end | ||
|
||
private | ||
|
||
def text | ||
"#{count_out_of_limit}+" | ||
end | ||
|
||
def url | ||
polymorphic_path(record) | ||
end | ||
|
||
def title | ||
t("#{i18n_namespace}.filter.more", count: count_out_of_limit) | ||
end | ||
|
||
def count_out_of_limit | ||
return 0 unless limit | ||
|
||
record.send(association_name).size - limit | ||
end | ||
|
||
def i18n_namespace | ||
association_name.to_s.tr("_", ".") | ||
end | ||
|
||
def html_class | ||
"more-#{i18n_namespace.split(".").last}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= link_list(*links, class: "tags", id: "tags_#{dom_id(taggable)}") %> |
Oops, something went wrong.