pool views

This commit is contained in:
albert
2011-02-25 17:41:00 -05:00
parent f48000a8b5
commit 6d0157265c
39 changed files with 1213 additions and 674 deletions

View File

@@ -1,5 +1,5 @@
class PoolsController < ApplicationController
respond_to :html, :xml, :json
respond_to :html, :xml, :json, :js
before_filter :member_only, :except => [:index, :show]
before_filter :moderator_only, :only => [:destroy]
@@ -20,6 +20,7 @@ class PoolsController < ApplicationController
def show
@pool = Pool.find(params[:id])
@post_set = PostSets::Pool.new(@pool, :page => params[:page])
respond_with(@pool)
end

View File

@@ -1,2 +1,6 @@
module PoolsHelper
def recent_pool_list
pool_ids = session[:recent_pool_ids].to_s.split(/,/)
pool_ids.map {|x| content_tag("option", x, :value => x)}.join("\n").html_safe
end
end

View File

@@ -3,7 +3,7 @@ module PostSets
attr_accessor :page, :before_id, :count, :posts
def initialize(options = {})
@page = options[:page].to_i
@page = options[:page] ? options[:page].to_i : 1
@before_id = options[:before_id]
load_posts
end
@@ -33,7 +33,15 @@ module PostSets
end
def presenter
@presnter ||= PostSetPresenter.new(self)
@presenter ||= PostSetPresenter.new(self)
end
def offset
((page < 1) ? 0 : (page - 1)) * count
end
def limit
Danbooru.config.posts_per_page
end
end
end

View File

@@ -14,9 +14,5 @@ module PostSets
def load_posts
@posts = user.favorite_posts(:before_id => before_id)
end
def limit
Danbooru.config.posts_per_page
end
end
end

View File

@@ -0,0 +1,33 @@
module PostSets
class Pool < Base
attr_reader :pool
def initialize(pool, options = {})
@pool = pool
@count = pool.post_id_array.size
super(options)
end
def tags
"pool:#{pool.name}"
end
def load_posts
@posts = pool.posts(:limit => limit, :offset => offset)
end
def sorted_posts
sort_posts(@posts)
end
private
def sort_posts(posts)
posts_by_id = posts.inject({}) do |hash, post|
hash[post.id] = post
hash
end
@pool.post_id_array.map {|x| posts_by_id[x]}
end
end
end

View File

@@ -30,10 +30,6 @@ module PostSets
x
end
def limit
Danbooru.config.posts_per_page
end
def is_single_tag?
tag_array.size == 1
end

View File

@@ -7,10 +7,14 @@ class Pool < ActiveRecord::Base
before_validation :normalize_name
before_validation :initialize_creator, :on => :create
after_save :create_version
attr_accessible :name, :description, :post_ids, :is_active
attr_accessible :name, :description, :post_ids, :is_active, :post_id_array
def self.name_to_id(name)
select_value_sql("SELECT id FROM pools WHERE name = ?", name.downcase)
if name =~ /^\d+$/
name.to_i
else
select_value_sql("SELECT id FROM pools WHERE name = ?", name.downcase)
end
end
def self.create_anonymous(creator, creator_ip_addr)
@@ -61,6 +65,11 @@ class Pool < ActiveRecord::Base
@post_id_array ||= post_ids.scan(/\d+/).map(&:to_i)
end
def post_id_array=(array)
self.post_ids = array.join(" ")
clear_post_id_array
end
def clear_post_id_array
@post_id_array = nil
end

View File

@@ -76,11 +76,19 @@ class Post < ActiveRecord::Base
end
def medium_file_url
"/data/medium/#{file_path_prefix}#{md5}.jpg"
if has_medium?
"/data/medium/#{file_path_prefix}#{md5}.jpg"
else
file_url
end
end
def large_file_url
"/data/large/#{file_path_prefix}#{md5}.jpg"
if has_large?
"/data/large/#{file_path_prefix}#{md5}.jpg"
else
medium_file_url
end
end
def preview_file_url

View File

@@ -0,0 +1,22 @@
module Paginators
class Pool < Base
attr_accessor :post_set
def initialize(post_set)
@post_set = post_set
end
protected
def total_pages
(post_set.count.to_f / post_set.limit.to_f).ceil
end
def current_page
[1, post_set.page].max
end
def paginated_link(template, page)
template.link_to(page, template.pool_path(post_set.pool, :page => page))
end
end
end

View File

@@ -35,8 +35,10 @@
</section>
<% content_for(:page_title) do %>
/ fav:<%= CurrentUser.name %>
/fav:<%= CurrentUser.name %>
<% end %>
<%= render :partial => "posts/partials/common/secondary_links" %>
</div>
</div>

View File

@@ -0,0 +1,6 @@
<%= simple_form_for(@pool) do |f| %>
<h2>Edit Pool: <%= @pool.name %></h2>
<p>If you know the precise ordering of posts that you want, you can just enter them here instead of sorting each post manually. Enter a list of post ids separated by spaces.</p>
<%= f.input :post_ids, :label => "Posts" %>
<%= f.button :submit %>
<% end %>

View File

@@ -0,0 +1,6 @@
<%= simple_form_for(pool) do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.input :is_active %>
<%= f.button :submit %>
<% end %>

View File

@@ -0,0 +1,7 @@
<div>
<%= simple_form_for @search, :method => :get do |f| %>
<%= f.input :name_contains, :label => "Name", :required => false %>
<%= f.input :description_contains, :label => "Description", :required => false %>
<%= f.button :submit, "Search" %>
<% end %>
</div>

View File

@@ -0,0 +1,13 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Listing", pools_path %></li>
<li><%= link_to "New", new_pool_path %></li>
<% if @pool %>
<li>|</li>
<li><%= link_to "Show", pool_path(@pool) %></li>
<li><%= link_to "Search", posts_path(:tags => "pool:#{@pool.id}") %></li>
<li><%= link_to "Simple Edit", edit_pool_path(@pool) %></li>
<li><%= link_to "Advanced Edit", edit_pool_path(@pool, :advanced => true) %></li>
<% end %>
</menu>
<% end %>

View File

@@ -0,0 +1,17 @@
<h2>Edit Pool: <%= @pool.name %></h2>
<p>Drag and drop the list below to determine ordering.</p>
<ul id="sortable">
<% posts.each do |post| %>
<li class="ui-state-default" id="pool[post_id_array]_<%= post.id %>">
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
<span class="delete">Delete</span>
</li>
<% end %>
</ul>
<%= simple_form_for(@pool, :format => :js, :html => {:id => "ordering-form"}) do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= submit_tag "Save" %>
<% end %>

View File

@@ -0,0 +1,11 @@
<div class="pools">
<div class="edit">
<% if params[:advanced] %>
<%= render "advanced_edit" %>
<% else %>
<%= render :partial => "simple_edit", :locals => {:posts => @pool.posts} %>
<% end %>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -0,0 +1,36 @@
<div id="pools">
<div id="index">
<%= render "search" %>
<table class="highlightable" width="100%">
<thead>
<tr>
<th width="5%"></th>
<th width="70%">Name</th>
<th width="25%">Creator</th>
</tr>
</thead>
<tbody>
<% @pools.each do |pool| %>
<%= content_tag(:tr, :id => "pool-#{pool.id}") do %>
<td>
</td>
<td>
<%= link_to h(pool.name), pool_path(pool) %>
</td>
<td>
<%= link_to h(pool.creator.name), user_path(pool.creator) %>
</td>
<% end %>
<% end %>
</tbody>
</table>
<div id="paginator">
<%= will_paginate(@pools) %>
</div>
<%= render "secondary_links" %>
</div>
</div>

View File

@@ -0,0 +1,2 @@
<h1>New Pool</h1>
<%= render :partial => "form", :locals => {:pool => @pool} %>

View File

@@ -0,0 +1,21 @@
<div class="pools">
<div class="show">
<aside id="sidebar">
<h2>Pool: <%= @pool.name %></h2>
<p><%= format_text(@pool.description) %></p>
</aside>
<section id="content">
<%= @post_set.presenter.post_previews_html %>
<div class="clearfix"></div>
<div class="paginator">
<%= @post_set.presenter.pagination_html(self) %>
</div>
</section>
</div>
</div>
<%= render "secondary_links" %>

View File

@@ -0,0 +1 @@
window.location.href = "/pools/<%= @pool.id %>";

View File

@@ -0,0 +1,4 @@
<%= form_for(post_pools_path(@post)) do %>
<p>Select a pool:</p>
<%= recent_pool_list %>
<% end %>

View File

@@ -3,7 +3,7 @@
<li><%= link_to "Listing", posts_path %></li>
<li><%= link_to "Upload", new_upload_path %></li>
<li>Popular</li>
<li>Favorites</li>
<li><%= link_to "Favorites", favorites_path %></li>
<li>Subscriptions</li>
<li><%= link_to "Changes", post_versions_path %></li>
<li>Approvals</li>

View File

@@ -4,6 +4,9 @@
<% if post.approver %>
<li>Approver: <%= link_to(post.approver.name, user_path(post.approver_id)) %></li>
<% end %>
<% if post.unapproval %>
<li>Unapproved: <%= post.unapproval.reason %> (by <%= post.unapproval.unapprover.name %>)</li>
<% end %>
<li>
Size: <%= number_to_human_size(post.file_size) %>
<% if post.is_image? %>

View File

@@ -12,5 +12,5 @@
<li><%= link_to "Undelete", "#", :id => "undelete" %> <%= wait_image("undelete-wait") %></li>
<li><%= link_to "Delete", "#", :id => "delete" %> <%= wait_image("delete-wait") %></li>
<% end %>
<li><%= link_to "Pool", "#" %></li>
<li><%= link_to "Pool", "#", :id => "pool" %></li>
</ul>

View File

@@ -56,6 +56,10 @@
<div id="unapprove-dialog" title="Unapprove Post">
<%= render :template => "unapprovals/new" %>
</div>
<div id="add-to-pool-dialog" title="Add to Pool">
<%= render :template => "pools_posts/new" %>
</div>
</div>
<% content_for(:page_title) do %>

View File

@@ -17,7 +17,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? %>
<%= link_to "Force update", upload_path(@upload), :remote => true, :method => :put %>.
<%= link_to "Force update", upload_path(@upload, :format => "js"), :remote => true, :method => :put %>.
<% end %>
</p>

View File

@@ -1 +1 @@
location.reload()
location.reload();