Add option to search for wikis that don't link to a specific wiki

Also add inputs on the search page for both the linked_to and the
not_linked_to search parameters. Additionally, normalize the title
first since autocomplete adds trailing spaces. The search query was
also simplified a bit by taking advantage of Rails associations.
This commit is contained in:
BrokenEagle
2020-06-22 16:07:11 +00:00
parent fd6ba473a5
commit 50740e302f
2 changed files with 12 additions and 1 deletions

View File

@@ -53,7 +53,11 @@ class WikiPage < ApplicationRecord
end
def linked_to(title)
where(id: DtextLink.wiki_page.wiki_link.where(link_target: title).select(:model_id))
where(dtext_links: DtextLink.wiki_page.wiki_link.where(link_target: normalize_title(title)))
end
def not_linked_to(title)
where.not(dtext_links: DtextLink.wiki_page.wiki_link.where(link_target: normalize_title(title)))
end
def default_order
@@ -82,6 +86,10 @@ class WikiPage < ApplicationRecord
q = q.linked_to(params[:linked_to])
end
if params[:not_linked_to].present?
q = q.not_linked_to(params[:not_linked_to])
end
if params[:hide_deleted].to_s.truthy?
q = q.where("is_deleted = false")
end
@@ -146,6 +154,7 @@ class WikiPage < ApplicationRecord
end
def self.normalize_title(title)
return if title.blank?
title.downcase.delete_prefix("~").gsub(/[[:space:]]+/, "_").gsub(/__/, "_").gsub(/\A_|_\z/, "")
end