From 42627be1d38b1cdc777210a3e672b2b449e3b6e3 Mon Sep 17 00:00:00 2001 From: albert Date: Tue, 15 Mar 2011 19:19:49 -0400 Subject: [PATCH] moved out search pages --- app/controllers/artists_controller.rb | 7 ++- app/controllers/tags_controller.rb | 4 ++ app/models/artist.rb | 56 +------------------ app/views/artists/_search.html.erb | 6 -- app/views/artists/_secondary_links.html.erb | 1 + app/views/artists/index.html.erb | 10 ++-- app/views/artists/search.html.erb | 17 ++++++ app/views/comments/index_by_comment.html.erb | 4 +- .../comments/partials/index/_header.html.erb | 4 +- .../comments/partials/show/_comment.html.erb | 4 +- app/views/favorites/index.html.erb | 4 +- app/views/notes/index.html.erb | 6 ++ app/views/tags/_search.html.erb | 8 --- app/views/tags/_secondary_links.html.erb | 1 + app/views/tags/index.html.erb | 4 +- app/views/tags/search.html.erb | 10 ++++ config/routes.rb | 12 +++- public/stylesheets/compiled/default.css | 8 +-- public/stylesheets/src/default.scss | 4 +- 19 files changed, 77 insertions(+), 93 deletions(-) delete mode 100644 app/views/artists/_search.html.erb create mode 100644 app/views/artists/search.html.erb delete mode 100644 app/views/tags/_search.html.erb create mode 100644 app/views/tags/search.html.erb diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index f297491fd..5a465dbee 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -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]) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 7a64dd3a2..2a14c5079 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -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) diff --git a/app/models/artist.rb b/app/models/artist.rb index 83ec6553a..6560b1510 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -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 diff --git a/app/views/artists/_search.html.erb b/app/views/artists/_search.html.erb deleted file mode 100644 index 072712489..000000000 --- a/app/views/artists/_search.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -
- <%= form_tag(artists_path, :method => :get) do %> - <%= text_field_tag "name", params[:name], :size => 40 %> - <%= submit_tag "Search" %> - <% end %> -
diff --git a/app/views/artists/_secondary_links.html.erb b/app/views/artists/_secondary_links.html.erb index b32c31a7a..e705d20a8 100644 --- a/app/views/artists/_secondary_links.html.erb +++ b/app/views/artists/_secondary_links.html.erb @@ -1,6 +1,7 @@ <% content_for(:secondary_links) do %>
  • <%= link_to "Listing", artists_path %>
  • +
  • <%= link_to "Search", search_artists_path %>
  • <%= link_to "New", new_artist_path %>
  • <%= link_to "Recent changes", artist_versions_path %>
  • <% if @artist && !@artist.new_record? %> diff --git a/app/views/artists/index.html.erb b/app/views/artists/index.html.erb index 2d82f1d21..82464e52d 100644 --- a/app/views/artists/index.html.erb +++ b/app/views/artists/index.html.erb @@ -1,8 +1,6 @@ -
    -
    - <%= render "search" %> - - +
    +
    +
    @@ -20,7 +18,7 @@ <% end %> diff --git a/app/views/artists/search.html.erb b/app/views/artists/search.html.erb new file mode 100644 index 000000000..064f86af2 --- /dev/null +++ b/app/views/artists/search.html.erb @@ -0,0 +1,17 @@ +
    + +
    + +<%= render "secondary_links" %> \ No newline at end of file diff --git a/app/views/comments/index_by_comment.html.erb b/app/views/comments/index_by_comment.html.erb index 26deb2fa7..33b1ac9ae 100644 --- a/app/views/comments/index_by_comment.html.erb +++ b/app/views/comments/index_by_comment.html.erb @@ -1,5 +1,5 @@ -
    -
    +
    +
    <% @comments.each do |comment| %> <%= render :partial => "comments/partials/index/list", :locals => {:post => comment.post, :comments => [comment], :show_header => false} %> <% end %> diff --git a/app/views/comments/partials/index/_header.html.erb b/app/views/comments/partials/index/_header.html.erb index 5a21ccea4..9d79719ae 100644 --- a/app/views/comments/partials/index/_header.html.erb +++ b/app/views/comments/partials/index/_header.html.erb @@ -1,7 +1,7 @@
    - + Date <%= compact_time(post.created_at) %> @@ -14,7 +14,7 @@ Score - + <%= post.score %> <% 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) %>) diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 1dfc9f80c..b91bac47f 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -2,9 +2,7 @@

    <%= link_to comment.creator_name, user_path(comment.creator_id) %>

    - + <%= time_ago_in_words(comment.created_at) %> ago

    diff --git a/app/views/favorites/index.html.erb b/app/views/favorites/index.html.erb index c3e25b859..dee98b2bc 100644 --- a/app/views/favorites/index.html.erb +++ b/app/views/favorites/index.html.erb @@ -1,5 +1,5 @@ -
    -
    +
    +
    <%= 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 %>
    +
    diff --git a/app/views/tags/search.html.erb b/app/views/tags/search.html.erb new file mode 100644 index 000000000..768df8a70 --- /dev/null +++ b/app/views/tags/search.html.erb @@ -0,0 +1,10 @@ +
    + +
    diff --git a/config/routes.rb b/config/routes.rb index 71183e5c2..ff25e65df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/public/stylesheets/compiled/default.css b/public/stylesheets/compiled/default.css index db769864a..86e92e16d 100644 --- a/public/stylesheets/compiled/default.css +++ b/public/stylesheets/compiled/default.css @@ -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; } diff --git a/public/stylesheets/src/default.scss b/public/stylesheets/src/default.scss index 3ad0a7e0a..03fb7e580 100644 --- a/public/stylesheets/src/default.scss +++ b/public/stylesheets/src/default.scss @@ -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 {
    Count