dtext links: add basic index page.

This commit is contained in:
evazion
2019-10-23 20:22:11 -05:00
parent 9f0ecf7247
commit 812cabfc07
4 changed files with 65 additions and 0 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -0,0 +1,44 @@
<div id="c-dtext-links">
<div id="a-index">
<%= search_form_for(dtext_links_path) do |f| %>
<%= f.simple_fields_for :model do |fa| %>
<%= fa.input :title, label: "Wiki", hint: "Use * for wildcard", input_html: { value: params.dig(:search, :model, :title), "data-autocomplete": "wiki-page" } %>
<% end %>
<%= f.input :link_target_ilike, label: "Link", hint: "Use * for wildcard", input_html: { value: params[:search][:link_target_ilike], data: { autocomplete: "wiki-page" } } %>
<%= f.input :link_type, label: "Type", collection: [["Wiki", "0"], ["External", "1"]], include_blank: true, selected: params[:search][:link_type] %>
<%= f.submit "Search" %>
<% end %>
<table class="striped autofit">
<thead>
<tr>
<th>Wiki</th>
<th>Link</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<% @dtext_links.each do |dtext_link| %>
<tr>
<td class="category-<%= Tag.category_for(dtext_link.model.title) %>">
<%= link_to(dtext_link.model.title, dtext_link.model) %>
<%= link_to("»", dtext_links_path(search: { model: { title: dtext_link.model.title }})) %>
</td>
<td class="col-expand">
<% 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 })) %>
</td>
<td><%= dtext_link.link_type.delete_suffix("_link").capitalize %></td>
</tr>
<% end %>
</tbody>
</table>
<%= numbered_paginator(@dtext_links) %>
</div>
</div>

View File

@@ -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