diff --git a/app/controllers/dtext_links_controller.rb b/app/controllers/dtext_links_controller.rb new file mode 100644 index 000000000..79a50a0d7 --- /dev/null +++ b/app/controllers/dtext_links_controller.rb @@ -0,0 +1,8 @@ +class DtextLinksController < ApplicationController + respond_to :html, :xml, :json + + def index + @dtext_links = DtextLink.includes(:model).paginated_search(params) + respond_with(@dtext_links) + end +end diff --git a/app/models/dtext_link.rb b/app/models/dtext_link.rb index 4cd2f5bc6..caa77689a 100644 --- a/app/models/dtext_link.rb +++ b/app/models/dtext_link.rb @@ -19,6 +19,18 @@ class DtextLink < ApplicationRecord links end + def self.model_matches(params) + return all if params.blank? + where(model_id: WikiPage.search(params).reorder(nil)) + end + + def self.search(params) + q = super + q = q.search_attributes(params, :model_type, :model_id, :link_type, :link_target) + q = q.model_matches(params[:model]) + q.apply_default_order(params) + end + def normalize_link_target if wiki_link? self.link_target = WikiPage.normalize_title(link_target) diff --git a/app/views/dtext_links/index.html.erb b/app/views/dtext_links/index.html.erb new file mode 100644 index 000000000..5fc1b8b43 --- /dev/null +++ b/app/views/dtext_links/index.html.erb @@ -0,0 +1,44 @@ +
| Wiki | +Link | +Type | +
|---|---|---|
| + <%= link_to(dtext_link.model.title, dtext_link.model) %> + <%= link_to("»", dtext_links_path(search: { model: { title: dtext_link.model.title }})) %> + | ++ <% if dtext_link.external_link? %> + <%= external_link_to(dtext_link.link_target) %> + <% elsif dtext_link.wiki_link? %> + <%= link_to(dtext_link.link_target, show_or_new_wiki_pages_path(title: dtext_link.link_target), class: "tag-type-#{Tag.category_for(dtext_link.link_target)}") %> + <% end %> + + <%= link_to("»", dtext_links_path(search: { link_target: dtext_link.link_target })) %> + | +<%= dtext_link.link_type.delete_suffix("_link").capitalize %> | +