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 @@ + diff --git a/config/routes.rb b/config/routes.rb index cdc42ff56..720c86c26 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -123,6 +123,7 @@ Rails.application.routes.draw do end end resource :dtext_preview, :only => [:create] + resources :dtext_links, only: [:index] resources :favorites, :only => [:index, :create, :destroy] resources :favorite_groups do member do