moved out search pages
This commit is contained in:
@@ -13,10 +13,15 @@ class ArtistsController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@artists = Artist.build_relation(params).paginate(:per_page => 25, :page => params[:page])
|
||||
@search = Artist.search(params[:search])
|
||||
@artists = @search.paginate(:page => params[:page])
|
||||
respond_with(@artists)
|
||||
end
|
||||
|
||||
def search
|
||||
@search = Artist.search(params[:search])
|
||||
end
|
||||
|
||||
def show
|
||||
@artist = Artist.find(params[:id])
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ class TagsController < ApplicationController
|
||||
respond_with(@tags)
|
||||
end
|
||||
|
||||
def search
|
||||
@search = Tag.search(params[:search])
|
||||
end
|
||||
|
||||
def show
|
||||
@tag = Tag.find(params[:id])
|
||||
respond_with(@tag)
|
||||
|
||||
@@ -12,6 +12,9 @@ class Artist < ActiveRecord::Base
|
||||
has_one :tag_alias, :foreign_key => "antecedent_name", :primary_key => "name"
|
||||
accepts_nested_attributes_for :wiki_page
|
||||
attr_accessible :name, :url_string, :other_names, :group_name, :wiki_page_attributes, :notes
|
||||
scope :url_match, lambda {|string| where(["id in (?)", Artist.find_all_by_url(string).map(&:id)])}
|
||||
scope :other_names_match, lambda {|string| where(["other_names_index @@ to_tsquery('danbooru', ?)", Artist.normalize_name(string)])}
|
||||
search_method :url_match, :other_names_match
|
||||
|
||||
module UrlMethods
|
||||
module ClassMethods
|
||||
@@ -78,58 +81,6 @@ class Artist < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
def find_by_name_or_id(params)
|
||||
if params[:name]
|
||||
find_by_name(params[:name])
|
||||
else
|
||||
find(params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
def find_by_any_name(name)
|
||||
build_relation(:name => name).first
|
||||
end
|
||||
|
||||
def build_relation(params)
|
||||
relation = Artist.where("is_active = TRUE")
|
||||
|
||||
case params[:name]
|
||||
when /^http/
|
||||
relation = relation.where("id IN (?)", find_all_by_url(params[:name]).map(&:id))
|
||||
|
||||
when /name:(.+)/
|
||||
escaped_name = Artist.normalize_name($1).to_escaped_for_sql_like
|
||||
relation = relation.where(["name LIKE ? ESCAPE E'\\\\'", escaped_name])
|
||||
|
||||
when /other:(.+)/
|
||||
escaped_name = Artist.normalize_name($1)
|
||||
relation = relation.where(["other_names_index @@ to_tsquery('danbooru', ?)", escaped_name])
|
||||
|
||||
when /group:(.+)/
|
||||
escaped_name = Artist.normalize_name($1).to_escaped_for_sql_like
|
||||
relation = relation.where(["group_name LIKE ? ESCAPE E'\\\\'", escaped_name])
|
||||
|
||||
when /./
|
||||
normalized_name = Artist.normalize_name($1)
|
||||
escaped_name = normalized_name.to_escaped_for_sql_like
|
||||
relation = relation.where(["name LIKE ? ESCAPE E'\\\\' OR other_names_index @@ to_tsquery('danbooru', ?) OR group_name LIKE ? ESCAPE E'\\\\'", escaped_name, normalized_name, escaped_name])
|
||||
end
|
||||
|
||||
if params[:id]
|
||||
relation = relation.where(["id = ?", params[:id]])
|
||||
end
|
||||
|
||||
if params[:order] == "date"
|
||||
relation = relation.order("updated_at DESC")
|
||||
else
|
||||
relation = relation.order("name")
|
||||
end
|
||||
|
||||
relation
|
||||
end
|
||||
end
|
||||
|
||||
module VersionMethods
|
||||
def create_version
|
||||
ArtistVersion.create(
|
||||
@@ -209,7 +160,6 @@ class Artist < ActiveRecord::Base
|
||||
include UrlMethods
|
||||
include NameMethods
|
||||
include GroupMethods
|
||||
extend SearchMethods
|
||||
include VersionMethods
|
||||
extend FactoryMethods
|
||||
include NoteMethods
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<div id="search-form" style="margin-bottom: 1em;">
|
||||
<%= form_tag(artists_path, :method => :get) do %>
|
||||
<%= text_field_tag "name", params[:name], :size => 40 %>
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,6 +1,7 @@
|
||||
<% content_for(:secondary_links) do %>
|
||||
<menu>
|
||||
<li><%= link_to "Listing", artists_path %></li>
|
||||
<li><%= link_to "Search", search_artists_path %></li>
|
||||
<li><%= link_to "New", new_artist_path %></li>
|
||||
<li><%= link_to "Recent changes", artist_versions_path %></li>
|
||||
<% if @artist && !@artist.new_record? %>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
<div id="artists">
|
||||
<div id="index">
|
||||
<%= render "search" %>
|
||||
|
||||
<table class="highlightable" width="100%">
|
||||
<div id="c-artists">
|
||||
<div id="a-index">
|
||||
<table class="striped" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%"></th>
|
||||
@@ -20,7 +18,7 @@
|
||||
<td>
|
||||
<%= link_to h(artist.name), artist_path(artist) %>
|
||||
<% if !artist.group_name.blank? %>
|
||||
[<%= link_to(artist.group_name, artist_path(artist)) %>]
|
||||
(group:<%= link_to(artist.group_name, artist_path(artist)) %>)
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
|
||||
17
app/views/artists/search.html.erb
Normal file
17
app/views/artists/search.html.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
<div id="c-artists">
|
||||
<div id="a-search">
|
||||
<h1>Search Artists</h1>
|
||||
|
||||
<div id="search-form" style="margin-bottom: 1em;">
|
||||
<%= simple_form_for(@search) do |f| %>
|
||||
<%= f.input :name_contains, :label => "Name" %>
|
||||
<%= f.input :other_names_match, :label => "Other Names" %>
|
||||
<%= f.input :group_name_contains, :label => "Group Name" %>
|
||||
<%= f.input :url_match, :label => "URL" %>
|
||||
<%= f.button :submit, "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="comments">
|
||||
<div class="index">
|
||||
<div id="c-comments">
|
||||
<div id="a-index">
|
||||
<% @comments.each do |comment| %>
|
||||
<%= render :partial => "comments/partials/index/list", :locals => {:post => comment.post, :comments => [comment], :show_header => false} %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="header">
|
||||
<div class="row">
|
||||
<span class="info">
|
||||
<time>Date</time>
|
||||
<strong>Date</strong>
|
||||
<%= compact_time(post.created_at) %>
|
||||
</span>
|
||||
<span class="info">
|
||||
@@ -14,7 +14,7 @@
|
||||
</span>
|
||||
<span class="info">
|
||||
<strong>Score</strong>
|
||||
<span id="score-for-post-<%= post.id %>"%>
|
||||
<span id="score-for-post-<%= post.id %>">
|
||||
<span><%= post.score %></span>
|
||||
<% if CurrentUser.user.is_privileged? %>
|
||||
(vote <%= link_to("up", post_votes_path(:score => "up", :post_id => post.id), :remote => true, :method => :post) %>/<%= link_to("down", post_votes_path(:score => "down", :post_id => post.id), :remote => true, :method => :post) %>)
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
<div class="author">
|
||||
<h1><%= link_to comment.creator_name, user_path(comment.creator_id) %></h1>
|
||||
<p>
|
||||
<time datetime="<%= comment.created_at %>">
|
||||
<%= time_ago_in_words(comment.created_at) %> ago
|
||||
</time>
|
||||
<%= time_ago_in_words(comment.created_at) %> ago
|
||||
</p>
|
||||
</div>
|
||||
<div class="content">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="favorites">
|
||||
<div class="index">
|
||||
<div id="c-favorites">
|
||||
<div id="a-index">
|
||||
<aside id="sidebar">
|
||||
<section id="search-box">
|
||||
<h1>Search Favorites</h1>
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
<div id="c-notes">
|
||||
<div id="a-index">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="note-list">
|
||||
<%= render :partial => "post/posts", :locals => {:posts => @posts} %>
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<div>
|
||||
<%= simple_form_for(@search) do |f| %>
|
||||
<%= f.input :name_matches, :required => false, :label => "Name" %>
|
||||
<%= f.input :category_equals, :required => false, :label => "Category" %>
|
||||
<%= f.input :meta_sort, :collection => [["Name", "name.asc"], ["Count", "post_count.desc"], ["Date", "created_at.desc"]], :label => "Sort", :required => false %>
|
||||
<%= f.button :submit, "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,6 +1,7 @@
|
||||
<% content_for(:secondary_links) do %>
|
||||
<menu>
|
||||
<li><%= link_to "Listing", tags_path %></li>
|
||||
<li><%= link_to "Search", search_tags_path %></li>
|
||||
<li><%= link_to "Aliases", tag_aliases_path %></li>
|
||||
<li><%= link_to "Implications", tag_implications_path %></li>
|
||||
<li><%= link_to "Help", wiki_pages_path(:search => {:title_equals => "help:tags"}) %></li>
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
<%= render "search" %>
|
||||
|
||||
<table width="100%" class="highlightable">
|
||||
<table width="100%" class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Count</th>
|
||||
|
||||
10
app/views/tags/search.html.erb
Normal file
10
app/views/tags/search.html.erb
Normal file
@@ -0,0 +1,10 @@
|
||||
<div id="c-tags">
|
||||
<div id="a-search">
|
||||
<%= simple_form_for(@search) do |f| %>
|
||||
<%= f.input :name_matches, :required => false, :label => "Name" %>
|
||||
<%= f.input :category_equals, :required => false, :label => "Category" %>
|
||||
<%= f.input :meta_sort, :collection => [["Name", "name.asc"], ["Count", "post_count.desc"], ["Date", "created_at.desc"]], :label => "Sort", :required => false %>
|
||||
<%= f.button :submit, "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -10,11 +10,17 @@ Danbooru::Application.routes.draw do
|
||||
member do
|
||||
put :revert
|
||||
end
|
||||
collection do
|
||||
get :search
|
||||
end
|
||||
end
|
||||
resources :artist_versions, :only => [:index]
|
||||
resources :bans
|
||||
resources :comments do
|
||||
resources :votes, :controller => "comment_votes", :only => [:create, :destroy]
|
||||
collection do
|
||||
get :search
|
||||
end
|
||||
end
|
||||
resources :dmails
|
||||
resources :favorites
|
||||
@@ -53,7 +59,11 @@ Danbooru::Application.routes.draw do
|
||||
|
||||
resources :post_versions, :only => [:index]
|
||||
resource :session
|
||||
resources :tags
|
||||
resources :tags do
|
||||
collection do
|
||||
get :search
|
||||
end
|
||||
end
|
||||
resources :tag_aliases do
|
||||
member do
|
||||
delete :cache
|
||||
|
||||
@@ -407,15 +407,15 @@ div#sessions div#new h2 {
|
||||
margin-bottom: 5px; }
|
||||
|
||||
/*** Artists ***/
|
||||
div#artists span.new-artist {
|
||||
div#c-artists span.new-artist {
|
||||
font-weight: bold;
|
||||
color: #A00; }
|
||||
div#artists div#show {
|
||||
div#c-artists div#a-show {
|
||||
max-width: 60em; }
|
||||
div#artists div#show h1 {
|
||||
div#c-artists div#a-show h1 {
|
||||
font-size: 1.5em;
|
||||
margin-bottom: 5px; }
|
||||
div#artists div#show p.legend {
|
||||
div#c-artists div#a-show p.legend {
|
||||
margin-bottom: 2em;
|
||||
font-size: 0.8em;
|
||||
font-style: italic; }
|
||||
|
||||
@@ -680,13 +680,13 @@ div#sessions {
|
||||
|
||||
|
||||
/*** Artists ***/
|
||||
div#artists {
|
||||
div#c-artists {
|
||||
span.new-artist {
|
||||
font-weight: bold;
|
||||
color: #A00;
|
||||
}
|
||||
|
||||
div#show {
|
||||
div#a-show {
|
||||
max-width: 60em;
|
||||
|
||||
h1 {
|
||||
|
||||
Reference in New Issue
Block a user