mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
allow filtering by folder AND tag
This commit is contained in:
parent
3793e7f2e4
commit
e37f1bf8a9
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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 %>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user