diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index efef59f3a..73f7f8ced 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -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 diff --git a/app/views/wiki_pages/search.html.erb b/app/views/wiki_pages/search.html.erb index 4fb24c4fb..3297d9695 100644 --- a/app/views/wiki_pages/search.html.erb +++ b/app/views/wiki_pages/search.html.erb @@ -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 %>