Merge pull request #4531 from BrokenEagle/wiki-linked-to

Add option to search for wikis that don't link to a specific wiki
This commit is contained in:
evazion
2020-06-23 23:21:16 -05:00
committed by GitHub
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

View File

@@ -4,6 +4,8 @@
<%= f.input :title_normalize, label: "Title", hint: "Use * for wildcard searches", input_html: { "data-autocomplete": "wiki-page" } %>
<%= f.input :other_names_match, label: "Other names", hint: "Use * for wildcard searches" %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :linked_to, hint: "Which wikis link to the specified wiki.", input_html: { "data-autocomplete": "wiki-page" } %>
<%= f.input :not_linked_to, hint: "Which wikis do not link to the specified wiki.", input_html: { "data-autocomplete": "wiki-page" } %>
<%= f.input :other_names_present, as: :select %>
<%= f.input :hide_deleted, as: :select, include_blank: false %>
<%= f.input :order, collection: [%w[Name title], %w[Date time], %w[Posts post_count]], include_blank: false %>