allow filtering by folder AND tag

This commit is contained in:
Andrew Brown 2021-06-29 16:23:57 -07:00
parent 3793e7f2e4
commit e37f1bf8a9
5 changed files with 14 additions and 16 deletions

View File

@ -48,8 +48,8 @@ class ContentController < ApplicationController
page_type: @content_type_class.name,
page_id: @content.pluck(:id)
).order(:tag)
if params.key?(:slug)
@filtered_page_tags = @page_tags.where(slug: params[:slug])
if params.key?(:tag)
@filtered_page_tags = @page_tags.where(slug: params[:tag])
@content.select! { |content| @filtered_page_tags.pluck(:page_id).include?(content.id) }
end

View File

@ -29,8 +29,8 @@ class DocumentsController < ApplicationController
page_id: @documents.pluck(:id)
).order(:tag)
if params.key?(:slug)
@filtered_page_tags = @page_tags.where(slug: params[:slug])
if params.key?(:tag)
@filtered_page_tags = @page_tags.where(slug: params[:tag])
@documents.select! { |document| @filtered_page_tags.pluck(:page_id).include?(document.id) }
end

View File

@ -35,13 +35,16 @@ class FoldersController < ApplicationController
page_id: @content.pluck(:id)
).order(:tag)
if params.key?(:slug)
@filtered_page_tags = @page_tags.where(slug: params[:slug])
@content.select! { |content| @filtered_page_tags.pluck(:page_id).include?(content.id) }
if params.key?(:tag)
@filtered_page_tags = @page_tags.where(slug: params[:tag])
@content = @content.to_a.select { |content| @filtered_page_tags.pluck(:page_id).include?(content.id) }
# TODO: the above could probably be replaced with something like the below, but not sure on nesting syntax
# @content = @content.where(page_tags: { slug: @filtered_page_tags.pluck(:slug) })
end
@page_tags = @page_tags.uniq(&:tag)
@suggested_page_tags = (@page_tags.pluck(:tag) + PageTagService.suggested_tags_for(@content.klass.name)).uniq
@suggested_page_tags = (@page_tags.pluck(:slug) + PageTagService.suggested_tags_for('Document')).uniq
end
private

View File

@ -18,8 +18,8 @@ class TimelinesController < ApplicationController
page_type: Timeline.name,
page_id: @timelines.pluck(:id)
).order(:tag)
if params.key?(:slug)
@filtered_page_tags = @page_tags.where(slug: params[:slug])
if params.key?(:tag)
@filtered_page_tags = @page_tags.where(slug: params[:tag])
@timelines = @timelines.select { |timeline| @filtered_page_tags.pluck(:page_id).include?(timeline.id) }
end

View File

@ -65,12 +65,7 @@
<% if @page_tags %>
<% @page_tags.each do |page_tag| %>
<li>
<%=
link_to send(
"page_tag_#{content_type.name.downcase.pluralize}_path",
slug: PageTagService.slug_for(page_tag.tag)
), class: "#{content_type.color}-text" do
%>
<%= link_to params.permit(:tag).merge({ tag: PageTagService.slug_for(page_tag.tag) }), class: "#{content_type.color}-text" do %>
<i class="material-icons">loyalty</i>
<small class="grey-text">tagged</small>
<%= page_tag.tag %>