@@ -15,7 +15,7 @@ header#top {
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
||||||
input {
|
input {
|
||||||
width: 8.5em;
|
width: 9.5em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,15 @@ class ArtistCommentariesController < ApplicationController
|
|||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
before_filter :member_only
|
before_filter :member_only
|
||||||
|
|
||||||
|
def index
|
||||||
|
@commentaries = ArtistCommentary.search(params[:search]).order("artist_commentaries.id desc").paginate(params[:page], :limit => params[:limit])
|
||||||
|
respond_with(@commentaries) do |format|
|
||||||
|
format.xml do
|
||||||
|
render :xml => @commentaries.to_xml(:root => "artist-commentaries")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_or_update
|
def create_or_update
|
||||||
@artist_commentary = ArtistCommentary.find_by_post_id(params[:artist_commentary][:post_id])
|
@artist_commentary = ArtistCommentary.find_by_post_id(params[:artist_commentary][:post_id])
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,46 @@ class ArtistCommentary < ActiveRecord::Base
|
|||||||
has_many :versions, :class_name => "ArtistCommentaryVersion", :dependent => :destroy, :foreign_key => :post_id, :primary_key => :post_id, :order => "artist_commentary_versions.id ASC"
|
has_many :versions, :class_name => "ArtistCommentaryVersion", :dependent => :destroy, :foreign_key => :post_id, :primary_key => :post_id, :order => "artist_commentary_versions.id ASC"
|
||||||
after_save :create_version
|
after_save :create_version
|
||||||
|
|
||||||
|
module SearchMethods
|
||||||
|
def text_matches(query)
|
||||||
|
escaped_query = query.to_escaped_for_sql_like
|
||||||
|
where("original_title ILIKE ? ESCAPE E'\\\\' OR original_description ILIKE ? ESCAPE E'\\\\' OR translated_title ILIKE ? ESCAPE E'\\\\' OR translated_description ILIKE ? ESCAPE E'\\\\'", escaped_query, escaped_query, escaped_query, escaped_query)
|
||||||
|
end
|
||||||
|
|
||||||
|
def post_tags_match(query)
|
||||||
|
joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', ?)", query.to_escaped_for_tsquery_split)
|
||||||
|
end
|
||||||
|
|
||||||
|
def search(params)
|
||||||
|
q = scoped
|
||||||
|
params = {} if params.blank?
|
||||||
|
|
||||||
|
if params[:text_matches].present?
|
||||||
|
q = q.text_matches(params[:text_matches])
|
||||||
|
end
|
||||||
|
|
||||||
|
if params[:original_present] == "yes"
|
||||||
|
q = q.where("(original_title is not null and original_title != '') or (original_description is not null and original_description != '')")
|
||||||
|
elsif params[:original_present] == "no"
|
||||||
|
q = q.where("(original_title is null or original_title = '') and (original_description is null or original_description = '')")
|
||||||
|
end
|
||||||
|
|
||||||
|
if params[:translated_present] == "yes"
|
||||||
|
q = q.where("(translated_title is not null and translated_title != '') or (translated_description is not null and translated_description != '')")
|
||||||
|
elsif params[:translated_present] == "no"
|
||||||
|
q = q.where("(translated_title is null or translated_title = '') and (translated_description is null or translated_description = '')")
|
||||||
|
end
|
||||||
|
|
||||||
|
if params[:post_tags_match].present?
|
||||||
|
q = q.post_tags_match(params[:post_tags_match])
|
||||||
|
end
|
||||||
|
|
||||||
|
q
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
extend SearchMethods
|
||||||
|
|
||||||
def original_present?
|
def original_present?
|
||||||
original_title.present? || original_description.present?
|
original_title.present? || original_description.present?
|
||||||
end
|
end
|
||||||
|
|||||||
3
app/views/artist_commentaries/_quick_search.html.erb
Normal file
3
app/views/artist_commentaries/_quick_search.html.erb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<%= form_tag(artist_commentaries_path, :method => :get) do %>
|
||||||
|
<%= text_field "search", "name", :id => "quick_search_name", :placeholder => "Search commentary" %>
|
||||||
|
<% end %>
|
||||||
9
app/views/artist_commentaries/_secondary_links.html.erb
Normal file
9
app/views/artist_commentaries/_secondary_links.html.erb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<% content_for(:secondary_links) do %>
|
||||||
|
<menu>
|
||||||
|
<li><%= render "artist_commentaries/quick_search" %></li>
|
||||||
|
<li><%= link_to "Search", search_artist_commentaries_path %></li>
|
||||||
|
<li><%= link_to "Listing", artist_commentaries_path %></li>
|
||||||
|
<li><%= link_to "Recent changes", artist_commentary_versions_path %></li>
|
||||||
|
<li><%= link_to "Translation requests", artist_commentaries_path(:search => {:post_tags_match => "commentary_request"}) %></li>
|
||||||
|
</menu>
|
||||||
|
<% end %>
|
||||||
38
app/views/artist_commentaries/index.html.erb
Normal file
38
app/views/artist_commentaries/index.html.erb
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<div id="c-artist-commentaries">
|
||||||
|
<div id="a-index">
|
||||||
|
<h1>Artist Commentary</h1>
|
||||||
|
|
||||||
|
<table width="100%" class="striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th width="1%">Post</th>
|
||||||
|
<th>Original</th>
|
||||||
|
<th>Translated</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @commentaries.each do |commentary| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= PostPresenter.preview(commentary.post) %></td>
|
||||||
|
<td>
|
||||||
|
<h3><%= h(commentary.original_title) %></h3>
|
||||||
|
<%= h(commentary.original_description) %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h3><%= h(commentary.translated_title) %></h3>
|
||||||
|
<%= h(commentary.translated_description) %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= numbered_paginator(@commentaries) %>
|
||||||
|
|
||||||
|
<%= render "secondary_links" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
Artist Commentary - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
27
app/views/artist_commentaries/search.html.erb
Normal file
27
app/views/artist_commentaries/search.html.erb
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<div id="c-artist-commentaries">
|
||||||
|
<div id="a-search">
|
||||||
|
<h1>Search Artist Commentary</h1>
|
||||||
|
<%= form_tag(artist_commentaries_path, :method => :get, :class => "simple_form") do %>
|
||||||
|
<%= search_field "text_matches", :label => "Text" %>
|
||||||
|
|
||||||
|
<div class="input">
|
||||||
|
<label for="search_original_present">Original present?</label>
|
||||||
|
<%= select "search", "original_present", ["yes", "no"], :include_blank => true %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input">
|
||||||
|
<label for="search_translated_present">Translation present?</label>
|
||||||
|
<%= select "search", "translated_present", ["yes", "no"], :include_blank => true %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= search_field "post_tags_match", :label => "Tags", :hint => "Meta-tags not supported" %>
|
||||||
|
<%= submit_tag "Search" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render "forum_topics/secondary_links" %>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
Search Artist Commentary - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
<%= numbered_paginator(@commentary_versions) %>
|
<%= numbered_paginator(@commentary_versions) %>
|
||||||
|
|
||||||
<%= render "posts/partials/common/secondary_links" %>
|
<%= render "artist_commentaries/secondary_links" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li><h1>Artist commentary</h1></li>
|
<li><h1>Artist commentary</h1></li>
|
||||||
<li><%= link_to("Help", wiki_pages_path(:title => "help:artist_commentary")) %></li>
|
<li><%= link_to("Help", wiki_pages_path(:title => "help:artist_commentary")) %></li>
|
||||||
|
<li><%= link_to("Listing", artist_commentaries_path) %></li>
|
||||||
<li><%= link_to("Changes", artist_commentary_versions_path) %></li>
|
<li><%= link_to("Changes", artist_commentary_versions_path) %></li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ Danbooru::Application.routes.draw do
|
|||||||
resources :artist_commentaries do
|
resources :artist_commentaries do
|
||||||
collection do
|
collection do
|
||||||
put :create_or_update
|
put :create_or_update
|
||||||
|
get :search
|
||||||
end
|
end
|
||||||
member do
|
member do
|
||||||
put :revert
|
put :revert
|
||||||
|
|||||||
Reference in New Issue
Block a user