Skip to content

Commit

Permalink
Use tags on macro cluster to display tags and search for them
Browse files Browse the repository at this point in the history
  • Loading branch information
ujh committed Feb 29, 2024
1 parent f9d1ebb commit c4a67e6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
13 changes: 3 additions & 10 deletions app/controllers/inks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ def index
end

def show
@ink =
MacroCluster
.where(id: params[:id])
.includes(public_collected_inks: { taggings: :tag })
.first
@ink = MacroCluster.find(params[:id])
@description = build_description
add_breadcrumb "Inks", "/brands"
add_breadcrumb "#{@ink.brand_cluster.name}", brand_path(@ink.brand_cluster)
Expand Down Expand Up @@ -47,12 +43,9 @@ def find_clusters
if params[:q].present?
MacroCluster.full_text_search(params[:q])
else
collected_inks =
CollectedInk.where(private: false).tagged_with(names: [params[:tag]])
MacroCluster
.distinct
.joins(micro_clusters: :collected_inks)
.where(collected_inks: { id: collected_inks.pluck(:id) })
.where("? = ANY(tags)", params[:tag])
.includes(:brand_cluster)
.order(:brand_name, :line_name, :ink_name)
end
end
Expand Down
4 changes: 0 additions & 4 deletions app/models/macro_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,4 @@ def to_param
def name
[brand_name, line_name, ink_name].reject(&:blank?).join(" ")
end

def tags
public_collected_inks.flat_map(&:taggings).map(&:tag).map(&:name).uniq.sort
end
end
6 changes: 6 additions & 0 deletions app/views/brands/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ div class="fpc-table fpc-table--full-width fpc-inks-table fpc-scroll-shadow"
th Brand
th Line
th colspan="2" Ink
th Tags
th
- if user_signed_in?
th
Expand All @@ -48,6 +49,11 @@ div class="fpc-table fpc-table--full-width fpc-inks-table fpc-scroll-shadow"
td
div style="background-color:#{ink.color};width:45px;height:45px;"
td= ink.ink_name
td
ul class="tags"
- ink.tags.each do |tag|
li class="tag badge text-bg-secondary"
a href="#{inks_path(tag: tag)}"= tag
td= link_to "Details", brand_ink_url(@brand, ink)
- if user_signed_in?
td
Expand Down
12 changes: 6 additions & 6 deletions app/views/inks/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ div class="fpc-table fpc-table--full-width fpc-inks-table fpc-scroll-shadow"
th Brand
th Line
th colspan="2" Ink
/ th Tags
th Tags
th
- if user_signed_in?
th
Expand All @@ -24,11 +24,11 @@ div class="fpc-table fpc-table--full-width fpc-inks-table fpc-scroll-shadow"
td
div style="background-color:#{ink.color};width:45px;height:45px;"
td= ink.ink_name
/ td
/ ul class="tags"
/ - ink.tags.each do |tag|
/ li class="tag badge text-bg-secondary"
/ a href="#{inks_path(tag: tag)}"= tag
td
ul class="tags"
- ink.tags.each do |tag|
li class="tag badge text-bg-secondary"
a href="#{inks_path(tag: tag)}"= tag
td
- if ink.brand_cluster.present?
= link_to "Details", brand_ink_path(ink.brand_cluster, ink)
Expand Down
3 changes: 2 additions & 1 deletion app/workers/update_macro_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def perform(id)
attr_accessor :cluster

def update_tags
cluster.tags = Gutentag::Tag.names_for_scope(cluster.public_collected_inks)
cluster.tags =
Gutentag::Tag.names_for_scope(cluster.public_collected_inks).to_a
end

def update_names
Expand Down

0 comments on commit c4a67e6

Please sign in to comment.