post index noe works

This commit is contained in:
albert
2011-06-24 18:22:54 -04:00
parent 9ac7f85f0b
commit 1ad075c05a
17 changed files with 91 additions and 136 deletions

View File

@@ -30,24 +30,6 @@ class PostsController < ApplicationController
end
private
def extend_post_set(post_set)
@post_set.extend(PostSets::Post)
if use_sequential_paginator?
@post_set.extend(PostSets::Sequential)
else
@post_set.extend(PostSets::Numbered)
end
end
def use_sequential_paginator?
if params[:page].to_i > 1000
true
else
false
end
end
def save_recent_tags
if params[:tags] || (params[:post] && params[:post][:tags])
tags = Tag.scan_tags(params[:tags] || params[:post][:tags])

View File

@@ -12,7 +12,7 @@ class UploadsController < ApplicationController
def index
@search = Upload.search(params[:search])
@uploads = @search.paginate(:page => params[:page])
@uploads = @search.order("id desc").paginate(params[:page])
respond_with(@uploads)
end

View File

@@ -1,28 +1,28 @@
module PaginationHelper
def smart_paginator(records, &block)
if records.is_sequential_paginator? || params[:page].to_i > 200
sequential_paginator(records)
else
numbered_paginator(records, &block)
end
end
def sequential_paginator(records)
html = "<menu>"
unless records.is_first_page?
html << '<li>' + link_to("&laquo; Previous", params.merge(:page => "b#{records.before_id}")) + '</li>'
end
if records.any?
if params[:page] =~ /[ab]/
html << '<li>' + link_to("< Previous", params.merge(:page => "a#{records[0].id}")) + '</li>'
end
unless records.is_last_page?
html << '<li>' + link_to("Next &raquo;", params.merge(:page => "a#{records.after_id}")) + '</li>'
html << '<li>' + link_to("Next >", params.merge(:page => "b#{records[-1].id}")) + '</li>'
end
html << "</menu>"
html.html_safe
end
def use_sequential_paginator?(records)
params[:page] =~ /[ab]/ || records.current_page > Danbooru.config.max_numbered_pages
end
def numbered_paginator(records, &block)
if use_sequential_paginator?(records)
return sequential_paginator(records)
end
html = "<menu>"
window = 3
if records.total_pages <= (window * 2) + 5
@@ -55,7 +55,7 @@ module PaginationHelper
end
def numbered_paginator_final_item(total_pages, current_page, &block)
if total_pages <= 200
if total_pages <= Danbooru.config.max_numbered_pages
numbered_paginator_item(total_pages, current_page, &block)
else
""
@@ -67,7 +67,7 @@ module PaginationHelper
if page == "..."
html << "..."
elsif page == current_page
html << page.to_s
html << '<span>' + page.to_s + '</span>'
else
html << capture(page, &block)
end

View File

@@ -4,7 +4,7 @@ module PostSets
def initialize(params)
@tag_array = Tag.scan_query(params[:tags])
@page = [params[:page].to_i, 1].max
@page = params[:page]
@posts = ::Post.tag_match(tag_string).paginate(page)
end
@@ -13,7 +13,7 @@ module PostSets
end
def has_wiki?
if tags.any?
if tag_array.any?
::WikiPage.titled(tag_string).exists?
else
false
@@ -21,7 +21,7 @@ module PostSets
end
def wiki_page
if tags.any?
if tag_array.any?
::WikiPage.titled(tag_string).first
else
nil

View File

@@ -14,9 +14,13 @@ class PostSetPresenter < Presenter
tag_set_presenter.tag_list_html(template)
end
def post_previews_html
def post_previews_html(template)
html = ""
if posts.empty?
return template.render(:partial => "post_sets/blank")
end
posts.each do |post|
html << PostPresenter.preview(post)
end

View File

@@ -48,13 +48,13 @@
</nav>
</header>
<%- if flash[:notice] -%>
<div class="ui-corner-all ui-state-highlight" id="notice"><span class="ui-icon ui-icon-info"></span> <%= flash[:notice] %></div>
<%- else -%>
<div class="ui-corner-all ui-state-highlight" id="notice" style="display: none;"><span class="ui-icon ui-icon-info"></span></div>
<%- end -%>
<div id="page">
<%- if flash[:notice] -%>
<div class="ui-corner-all ui-state-highlight" id="notice"><span class="ui-icon ui-icon-info"></span> <%= flash[:notice] %></div>
<%- else -%>
<div class="ui-corner-all ui-state-highlight" id="notice" style="display: none;"><span class="ui-icon ui-icon-info"></span></div>
<%- end -%>
<%= yield :layout %>
</div>

View File

@@ -0,0 +1,3 @@
<p>Nobody here but us chickens!</p>
<p><%= link_to "Go back", :back %>.</p>

View File

@@ -34,7 +34,7 @@
</section>
<% content_for(:page_title) do %>
/<%= @post_set.tags.join(" ") %>
/<%= @post_set.tag_string %>
<% end %>
<%= render :partial => "posts/partials/common/secondary_links" %>

View File

@@ -1,11 +1,11 @@
<h1>Posts</h1>
<%= post_set.presenter.post_previews_html %>
<%= post_set.presenter.post_previews_html(self) %>
<div class="clearfix"></div>
<div class="paginator">
<%= smart_paginator(post_set.posts) do |page| %>
<%= link_to(page, posts_path(:page => page, :tags => post_set.tags)) %>
<%= numbered_paginator(post_set.posts) do |page| %>
<%= link_to(page, posts_path(:page => page, :tags => post_set.tag_string)) %>
<% end %>
</div>

View File

@@ -1,24 +1,32 @@
<table width="100%">
<thead>
<tr>
<th></th>
<th>Uploader</th>
<th>Status</th>
<th>Date</th>
<th>Tags</th>
</tr>
</thead>
<tbody>
<% @uploads.each do |upload| %>
<tr>
<td><%= link_to upload.id, upload_path(upload) %></td>
<td><%= link_to upload.uploader.name, user_path(upload.uploader) %></td>
<td><%= upload.presenter.status(self) %></td>
<td><%= upload.created_at %></td>
<td><%= upload.tag_string %></td>
</tr>
<% end %>
</tbody>
</table>
<div id="c-uploads">
<div id="a-index">
<table width="100%">
<thead>
<tr>
<th></th>
<th>Uploader</th>
<th>Status</th>
<th>Date</th>
<th>Tags</th>
</tr>
</thead>
<tbody>
<% @uploads.each do |upload| %>
<tr>
<td><%= link_to upload.id, upload_path(upload) %></td>
<td><%= link_to upload.uploader.name, user_path(upload.uploader) %></td>
<td><%= upload.presenter.status(self) %></td>
<td><%= upload.created_at %></td>
<td><%= upload.tag_string %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="paginator">
<%= sequential_paginator(@uploads) %>
</div>
</div>
</div>
<%= render :partial => "posts/partials/common/secondary_links" %>

View File

@@ -16,7 +16,7 @@
<p>
You can <%= link_to "upload another file", new_upload_path %> or <%= link_to "view your current uploads", uploads_path %>.
<% if CurrentUser.user.is_moderator? %>
<% if CurrentUser.user.is_moderator? && @upload.is_pending? %>
<%= link_to "Force update", upload_path(@upload, :format => "js"), :remote => true, :method => :put %>.
<% end %>
</p>