This commit is contained in:
albert
2011-07-02 21:04:29 -04:00
parent e9bab19d51
commit bd3af50e10
16 changed files with 94 additions and 32 deletions

View File

@@ -194,7 +194,7 @@ menu {
li { li {
margin: 0; margin: 0;
padding: 0 1em 0 0; padding: 0 0.25em;
list-style-type: none; list-style-type: none;
display: inline; display: inline;
} }
@@ -262,6 +262,10 @@ table tfoot {
} }
table.striped { table.striped {
p {
margin: 0;
}
tbody { tbody {
tr:hover { tr:hover {
background-color: #FFE; background-color: #FFE;

View File

@@ -3,6 +3,10 @@ class NotesController < ApplicationController
before_filter :member_only, :except => [:index, :show] before_filter :member_only, :except => [:index, :show]
before_filter :pass_html_id, :only => [:create] before_filter :pass_html_id, :only => [:create]
def search
@search = Note.search(params[:search])
end
def index def index
if params[:group_by] == "post" if params[:group_by] == "post"
index_by_post index_by_post
@@ -52,7 +56,8 @@ private
end end
def index_by_post def index_by_post
@posts = Post.tag_match(params[:tags]).noted_before(params[:before_date] || Time.now).paginate(params[:page]) @post_set = PostSets::Note.new(params)
@posts = @post_set.posts
respond_with(@posts) do |format| respond_with(@posts) do |format|
format.html {render :action => "index_by_post"} format.html {render :action => "index_by_post"}
end end
@@ -65,5 +70,4 @@ private
format.html {render :action => "index_by_note"} format.html {render :action => "index_by_note"}
end end
end end
end end

View File

@@ -18,8 +18,8 @@ module PaginationHelper
params[:page] =~ /[ab]/ || records.current_page > Danbooru.config.max_numbered_pages params[:page] =~ /[ab]/ || records.current_page > Danbooru.config.max_numbered_pages
end end
def numbered_paginator(records, &block) def numbered_paginator(records, switch_to_sequential = true)
if use_sequential_paginator?(records) if use_sequential_paginator?(records) && switch_to_sequential
return sequential_paginator(records) return sequential_paginator(records)
end end
@@ -27,49 +27,49 @@ module PaginationHelper
window = 3 window = 3
if records.total_pages <= (window * 2) + 5 if records.total_pages <= (window * 2) + 5
1.upto(records.total_pages) do |page| 1.upto(records.total_pages) do |page|
html << numbered_paginator_item(page, records.current_page, &block) html << numbered_paginator_item(page, records.current_page)
end end
elsif records.current_page <= window + 2 elsif records.current_page <= window + 2
1.upto(records.current_page + window) do |page| 1.upto(records.current_page + window) do |page|
html << numbered_paginator_item(page, records.current_page, &block) html << numbered_paginator_item(page, records.current_page)
end end
html << numbered_paginator_item("...", records.current_page, &block) html << numbered_paginator_item("...", records.current_page)
html << numbered_paginator_final_item(records.total_pages, records.current_page, &block) html << numbered_paginator_final_item(records.total_pages, records.current_page)
elsif records.current_page >= records.total_pages - (window + 1) elsif records.current_page >= records.total_pages - (window + 1)
html << numbered_paginator_item(1, records.current_page, &block) html << numbered_paginator_item(1, records.current_page)
html << numbered_paginator_item("...", records.current_page, &block) html << numbered_paginator_item("...", records.current_page)
(records.current_page - window).upto(records.total_pages) do |page| (records.current_page - window).upto(records.total_pages) do |page|
html << numbered_paginator_item(page, records.current_page, &block) html << numbered_paginator_item(page, records.current_page)
end end
else else
html << numbered_paginator_item(1, records.current_page, &block) html << numbered_paginator_item(1, records.current_page)
html << numbered_paginator_item("...", records.current_page, &block) html << numbered_paginator_item("...", records.current_page)
(records.current_page - window).upto(records.current_page + window) do |page| (records.current_page - window).upto(records.current_page + window) do |page|
html << numbered_paginator_item(page, records.current_page, &block) html << numbered_paginator_item(page, records.current_page)
end end
html << numbered_paginator_item("...", records.current_page, &block) html << numbered_paginator_item("...", records.current_page)
html << numbered_paginator_final_item(records.total_pages, records.current_page, &block) html << numbered_paginator_final_item(records.total_pages, records.current_page)
end end
html << "</menu>" html << "</menu>"
html.html_safe html.html_safe
end end
def numbered_paginator_final_item(total_pages, current_page, &block) def numbered_paginator_final_item(total_pages, current_page)
if total_pages <= Danbooru.config.max_numbered_pages if total_pages <= Danbooru.config.max_numbered_pages
numbered_paginator_item(total_pages, current_page, &block) numbered_paginator_item(total_pages, current_page)
else else
"" ""
end end
end end
def numbered_paginator_item(page, current_page, &block) def numbered_paginator_item(page, current_page)
html = "<li>" html = "<li>"
if page == "..." if page == "..."
html << "..." html << "..."
elsif page == current_page elsif page == current_page
html << '<span>' + page.to_s + '</span>' html << '<span>' + page.to_s + '</span>'
else else
html << capture(page, &block) html << link_to(page, params.merge(:page => page))
end end
html << "</li>" html << "</li>"
html.html_safe html.html_safe

View File

@@ -0,0 +1,10 @@
module PostSets
class Note < Post
def initialize(params)
# don't call super because we don't want to repeat these queries
@tag_array = Tag.scan_query(params[:tags])
@page = params[:page]
@posts = ::Post.tag_match(tag_string).has_notes.paginate(page)
end
end
end

View File

@@ -14,7 +14,8 @@ class Note < ActiveRecord::Base
attr_accessible :x, :y, :width, :height, :body, :updater_id, :updater_ip_addr, :is_active, :post_id, :html_id attr_accessible :x, :y, :width, :height, :body, :updater_id, :updater_ip_addr, :is_active, :post_id, :html_id
scope :active, where("is_active = TRUE") scope :active, where("is_active = TRUE")
scope :body_matches, lambda {|query| where("text_index @@ plainto_tsquery(?)", query.scan(/\S+/).join(" & "))} scope :body_matches, lambda {|query| where("text_index @@ plainto_tsquery(?)", query.scan(/\S+/).join(" & "))}
search_methods :body_matches scope :post_tag_match, lambda {|query| joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', ?)", query)}
search_methods :body_matches, :post_tag_match
def presenter def presenter
@presenter ||= NotePresenter.new(self) @presenter ||= NotePresenter.new(self)

View File

@@ -35,7 +35,7 @@ class Post < ActiveRecord::Base
scope :deleted, where(["is_deleted = ?", true]) scope :deleted, where(["is_deleted = ?", true])
scope :visible, lambda {|user| Danbooru.config.can_user_see_post_conditions(user)} scope :visible, lambda {|user| Danbooru.config.can_user_see_post_conditions(user)}
scope :commented_before, lambda {|date| where("last_commented_at < ?", date).order("last_commented_at DESC")} scope :commented_before, lambda {|date| where("last_commented_at < ?", date).order("last_commented_at DESC")}
scope :noted_before, lambda {|date| where("last_noted_at < ?", date).order("last_noted_at DESC")} scope :has_notes, where("last_noted_at is not null")
scope :for_user, lambda {|user_id| where(["uploader_string = ?", "uploader:#{user_id}"])} scope :for_user, lambda {|user_id| where(["uploader_string = ?", "uploader:#{user_id}"])}
scope :available_for_moderation, lambda {where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])} scope :available_for_moderation, lambda {where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])} scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
@@ -861,6 +861,12 @@ class Post < ActiveRecord::Base
end end
end end
module NoteMethods
def last_noted_at_as_integer
last_noted_at.to_i
end
end
include FileMethods include FileMethods
include ImageMethods include ImageMethods
include ApprovalMethods include ApprovalMethods
@@ -876,6 +882,7 @@ class Post < ActiveRecord::Base
include ParentMethods include ParentMethods
include DeletionMethods include DeletionMethods
include VersionMethods include VersionMethods
include NoteMethods
def reload(options = nil) def reload(options = nil)
super super

View File

@@ -293,6 +293,7 @@ class Tag < ActiveRecord::Base
when "status" when "status"
q[:status] = $2 q[:status] = $2
end end
else else

View File

@@ -3,9 +3,9 @@
<h1>Search Comments</h1> <h1>Search Comments</h1>
<%= simple_form_for(@search) do |f| %> <%= simple_form_for(@search) do |f| %>
<%= hidden_field_tag "group_by", "comment" %> <%= hidden_field_tag "group_by", "comment" %>
<%= f.input :body_matches, :label => "Body" %> <%= f.input :body_matches, :label => "Body", :required => false %>
<%= f.input :creator_name_equals, :label => "User" %> <%= f.input :creator_name_equals, :label => "User", :required => false %>
<%= f.input :post_tag_match, :label => "Tags" %> <%= f.input :post_tag_match, :label => "Tags", :required => false %>
<%= f.button :submit, "Search" %> <%= f.button :submit, "Search" %>
<% end %> <% end %>

View File

@@ -32,7 +32,7 @@
<% end %> <% end %>
<%= nav_link_to("Posts", posts_path) %> <%= nav_link_to("Posts", posts_path) %>
<%= nav_link_to("Comments", comments_path(:group_by => "post")) %> <%= nav_link_to("Comments", comments_path(:group_by => "post")) %>
<%= nav_link_to("Notes", notes_path) %> <%= nav_link_to("Notes", notes_path(:group_by => "post")) %>
<%= nav_link_to("Artists", artists_path(:order => "date")) %> <%= nav_link_to("Artists", artists_path(:order => "date")) %>
<%= nav_link_to("Tags", tags_path(:order => "date")) %> <%= nav_link_to("Tags", tags_path(:order => "date")) %>
<% if CurrentUser.is_moderator? %> <% if CurrentUser.is_moderator? %>

View File

@@ -1,6 +1,6 @@
<div id="c-notes"> <div id="c-notes">
<div id="a-index"> <div id="a-index">
<table width="100%"> <table width="100%" class="striped">
<thead> <thead>
<tr> <tr>
<th>Post</th> <th>Post</th>
@@ -22,6 +22,10 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<div class="paginator">
<%= sequential_paginator(@notes) %>
</div>
</div> </div>
</div> </div>

View File

@@ -0,0 +1,11 @@
<div id="c-notes">
<div id="a-index">
<%= @post_set.presenter.post_previews_html(self) %>
<div class="paginator">
<%= numbered_paginator(@posts, false) %>
</div>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -0,0 +1,11 @@
<div id="c-notes">
<div id="a-search">
<%= simple_form_for @search do |f| %>
<%= f.input :body_matches, :label => "Body" %>
<%= f.input :post_tag_match, :label => "Tags" %>
<%= f.button :submit, "Search" %>
<% end %>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -5,7 +5,5 @@
<div class="clearfix"></div> <div class="clearfix"></div>
<div class="paginator"> <div class="paginator">
<%= numbered_paginator(post_set.posts) do |page| %> <%= numbered_paginator(post_set.posts) %>
<%= link_to(page, posts_path(:page => page, :tags => post_set.tag_string)) %>
<% end %>
</div> </div>

View File

@@ -50,6 +50,11 @@ module Danbooru
def paginate_numbered(page) def paginate_numbered(page)
page = [page.to_i, 1].max page = [page.to_i, 1].max
if page > Danbooru.config.max_numbered_pages
raise Error.new("You cannot go beyond page #{Danbooru.config.max_numbered_pages}. Please narrow your search terms.")
end
limit(records_per_page).offset((page - 1) * records_per_page).tap do |obj| limit(records_per_page).offset((page - 1) * records_per_page).tap do |obj|
obj.extend(NumberedCollectionExtension) obj.extend(NumberedCollectionExtension)
obj.total_pages = (obj.total_count.to_f / records_per_page).ceil obj.total_pages = (obj.total_count.to_f / records_per_page).ceil

View File

@@ -0,0 +1,6 @@
module Danbooru
module Paginator
class Error < Exception
end
end
end