diff --git a/app/assets/stylesheets/common/page_header.css.scss b/app/assets/stylesheets/common/page_header.css.scss index 21d392b87..eb871e227 100644 --- a/app/assets/stylesheets/common/page_header.css.scss +++ b/app/assets/stylesheets/common/page_header.css.scss @@ -15,7 +15,7 @@ header#top { display: inline-block; input { - width: 8.5em; + width: 9.5em; } } diff --git a/app/controllers/artist_commentaries_controller.rb b/app/controllers/artist_commentaries_controller.rb index 579def6f1..6975e84af 100644 --- a/app/controllers/artist_commentaries_controller.rb +++ b/app/controllers/artist_commentaries_controller.rb @@ -2,6 +2,15 @@ class ArtistCommentariesController < ApplicationController respond_to :html, :xml, :json, :js 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 @artist_commentary = ArtistCommentary.find_by_post_id(params[:artist_commentary][:post_id]) diff --git a/app/models/artist_commentary.rb b/app/models/artist_commentary.rb index c3fc8649a..785ab503b 100644 --- a/app/models/artist_commentary.rb +++ b/app/models/artist_commentary.rb @@ -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" 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? original_title.present? || original_description.present? end diff --git a/app/views/artist_commentaries/_quick_search.html.erb b/app/views/artist_commentaries/_quick_search.html.erb new file mode 100644 index 000000000..f654021ae --- /dev/null +++ b/app/views/artist_commentaries/_quick_search.html.erb @@ -0,0 +1,3 @@ +<%= form_tag(artist_commentaries_path, :method => :get) do %> + <%= text_field "search", "name", :id => "quick_search_name", :placeholder => "Search commentary" %> +<% end %> diff --git a/app/views/artist_commentaries/_secondary_links.html.erb b/app/views/artist_commentaries/_secondary_links.html.erb new file mode 100644 index 000000000..514bd1895 --- /dev/null +++ b/app/views/artist_commentaries/_secondary_links.html.erb @@ -0,0 +1,9 @@ +<% content_for(:secondary_links) do %> +
+<% end %> diff --git a/app/views/artist_commentaries/index.html.erb b/app/views/artist_commentaries/index.html.erb new file mode 100644 index 000000000..222a0c535 --- /dev/null +++ b/app/views/artist_commentaries/index.html.erb @@ -0,0 +1,38 @@ +| Post | +Original | +Translated | +
|---|---|---|
| <%= PostPresenter.preview(commentary.post) %> | +
+ <%= h(commentary.original_title) %>+ <%= h(commentary.original_description) %> + |
+
+ <%= h(commentary.translated_title) %>+ <%= h(commentary.translated_description) %> + |
+