Split goal tag list component
This way we'll be able to add targets as well. Besides, having two classes in the CSS selector will allows to overwrite styles such as `.debate-show ul li`. On the other hand, we need to add a stylesheet for the filters as well.
This commit is contained in:
6
app/assets/stylesheets/sdg/goals/filter_links.scss
Normal file
6
app/assets/stylesheets/sdg/goals/filter_links.scss
Normal file
@@ -0,0 +1,6 @@
|
||||
.sdg-goal-filter-links {
|
||||
|
||||
.sdg-goal-tag-list {
|
||||
@extend %sdg-goal-list;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
.sdg-goal-tag-list {
|
||||
@extend %sdg-goal-list;
|
||||
|
||||
.more-goals {
|
||||
@extend %tag;
|
||||
}
|
||||
}
|
||||
10
app/assets/stylesheets/sdg/tag_list.scss
Normal file
10
app/assets/stylesheets/sdg/tag_list.scss
Normal file
@@ -0,0 +1,10 @@
|
||||
.sdg-tag-list {
|
||||
|
||||
.sdg-goal-tag-list {
|
||||
@extend %sdg-goal-list;
|
||||
|
||||
.more-goals {
|
||||
@extend %tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
app/components/concerns/sdg/tag_list.rb
Normal file
50
app/components/concerns/sdg/tag_list.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
module SDG::TagList
|
||||
extend ActiveSupport::Concern
|
||||
attr_reader :record_or_name, :limit
|
||||
delegate :link_list, to: :helpers
|
||||
|
||||
def initialize(record_or_name, limit: nil)
|
||||
@record_or_name = record_or_name
|
||||
@limit = limit
|
||||
end
|
||||
|
||||
def render?
|
||||
process.enabled?
|
||||
end
|
||||
|
||||
def see_more_link(collection)
|
||||
count = count_out_of_limit(collection)
|
||||
|
||||
if count > 0
|
||||
[
|
||||
"#{count}+",
|
||||
polymorphic_path(record),
|
||||
class: "more-#{i18n_namespace}", title: t("sdg.#{i18n_namespace}.filter.more", count: count)
|
||||
]
|
||||
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)
|
||||
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
|
||||
end
|
||||
end
|
||||
@@ -1,24 +1,18 @@
|
||||
class SDG::Goals::TagListComponent < ApplicationComponent
|
||||
attr_reader :record_or_name, :limit
|
||||
delegate :link_list, to: :helpers
|
||||
|
||||
def initialize(record_or_name, limit: nil)
|
||||
@record_or_name = record_or_name
|
||||
@limit = limit
|
||||
end
|
||||
|
||||
def render?
|
||||
process.enabled?
|
||||
end
|
||||
include SDG::TagList
|
||||
|
||||
private
|
||||
|
||||
def record
|
||||
record_or_name if record_or_name.respond_to?(:sdg_goals)
|
||||
end
|
||||
|
||||
def links
|
||||
[*goal_links, see_more_link]
|
||||
[*goal_links, see_more_link(goals)]
|
||||
end
|
||||
|
||||
def goal_links
|
||||
goals.limit(limit).map do |goal|
|
||||
goals.order(:code).limit(limit).map do |goal|
|
||||
[
|
||||
render(SDG::Goals::IconComponent.new(goal)),
|
||||
index_by_goal(goal),
|
||||
@@ -28,42 +22,14 @@ class SDG::Goals::TagListComponent < ApplicationComponent
|
||||
end
|
||||
|
||||
def goals
|
||||
if record_or_name.respond_to?(:sdg_goals)
|
||||
record_or_name.sdg_goals.order(:code)
|
||||
else
|
||||
SDG::Goal.order(:code)
|
||||
end
|
||||
end
|
||||
|
||||
def see_more_link
|
||||
return unless limit && count_out_of_limit > 0
|
||||
|
||||
[
|
||||
"#{count_out_of_limit}+",
|
||||
polymorphic_path(record_or_name),
|
||||
class: "more-goals", title: t("sdg.goals.filter.more", count: count_out_of_limit)
|
||||
]
|
||||
record&.sdg_goals || SDG::Goal.all
|
||||
end
|
||||
|
||||
def index_by_goal(goal)
|
||||
polymorphic_path(model, advanced_search: { goal: goal.code })
|
||||
index_by(goal: goal.code)
|
||||
end
|
||||
|
||||
def filter_text(goal)
|
||||
t("sdg.goals.filter.link",
|
||||
resources: model.model_name.human(count: :other),
|
||||
code: goal.code)
|
||||
end
|
||||
|
||||
def count_out_of_limit
|
||||
goals.size - limit
|
||||
end
|
||||
|
||||
def model
|
||||
process.name.constantize
|
||||
end
|
||||
|
||||
def process
|
||||
@process ||= SDG::ProcessEnabled.new(record_or_name)
|
||||
def i18n_namespace
|
||||
"goals"
|
||||
end
|
||||
end
|
||||
|
||||
3
app/components/sdg/tag_list_component.html.erb
Normal file
3
app/components/sdg/tag_list_component.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<div class="sdg-tag-list">
|
||||
<%= render SDG::Goals::TagListComponent.new(record, limit: limit) %>
|
||||
</div>
|
||||
8
app/components/sdg/tag_list_component.rb
Normal file
8
app/components/sdg/tag_list_component.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class SDG::TagListComponent < ApplicationComponent
|
||||
attr_reader :record, :limit
|
||||
|
||||
def initialize(record, limit: nil)
|
||||
@record = record
|
||||
@limit = limit
|
||||
end
|
||||
end
|
||||
@@ -17,4 +17,4 @@
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<%= render SDG::Goals::TagListComponent.new(taggable, limit: limit) %>
|
||||
<%= render SDG::TagListComponent.new(taggable, limit: limit) %>
|
||||
|
||||
Reference in New Issue
Block a user