This commit is contained in:
albert 2013-03-22 10:38:37 -07:00
parent 40ee7e72b8
commit 3e4d149d28
8 changed files with 34 additions and 5 deletions

View File

@ -173,6 +173,10 @@ class AnonymousUser
3_000
end
def per_page
Danbooru.config.posts_per_page
end
%w(member banned privileged builder platinum contributor janitor moderator admin).each do |name|
define_method("is_#{name}?") do
false

View File

@ -5,7 +5,7 @@ module PostSets
def initialize(tags, page = 1, per_page = nil)
@tag_array = Tag.scan_query(tags)
@page = page
@per_page = (per_page || Danbooru.config.posts_per_page).to_i
@per_page = (per_page || CurrentUser.per_page).to_i
@per_page = 200 if @per_page > 200
end

View File

@ -17,7 +17,7 @@ class User < ActiveRecord::Base
end
attr_accessor :password, :old_password
attr_accessible :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :as => [:moderator, :janitor, :contributor, :privileged, :member, :anonymous, :default, :builder, :admin]
attr_accessible :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :as => [:moderator, :janitor, :contributor, :privileged, :member, :anonymous, :default, :builder, :admin]
attr_accessible :level, :as => :admin
validates_length_of :name, :within => 2..100, :on => :create
validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons"
@ -25,11 +25,13 @@ class User < ActiveRecord::Base
validates_uniqueness_of :email, :case_sensitive => false, :if => lambda {|rec| rec.email.present?}
validates_length_of :password, :minimum => 5, :if => lambda {|rec| rec.new_record? || rec.password.present?}
validates_inclusion_of :default_image_size, :in => %w(large original)
validates_inclusion_of :per_page, :in => [20, 50, 100]
validates_confirmation_of :password
validates_presence_of :email, :if => lambda {|rec| rec.new_record? && Danbooru.config.enable_email_verification?}
validates_presence_of :comment_threshold
validate :validate_ip_addr_is_not_banned, :on => :create
before_validation :normalize_blacklisted_tags
before_validation :set_per_page
before_create :encrypt_password_on_create
before_update :encrypt_password_on_update
after_save :update_cache
@ -345,6 +347,10 @@ class User < ActiveRecord::Base
ModAction.create(:description => "#{name} level changed #{level_string(level_was)} -> #{level_string} by #{CurrentUser.name}")
end
end
def set_per_page
self.per_page = Danbooru.config.posts_per_page unless is_privileged?
end
end
module EmailMethods

View File

@ -18,6 +18,10 @@
<%= f.input :new_post_navigation_layout, :as => :select, :label => "Pool links", :include_blank => false, :collection => [["Bottom", "true"], ["Top", "false"]], :hint => "When browsing pools, where do you want the navigation links to be placed?" %>
<%= f.input :enable_sequential_post_navigation, :as => :select, :label => "Enable slideshow mode", :hint => "Show prev/next links when viewing a post", :include_blank => false %>
<% if CurrentUser.is_privileged? %>
<%= f.input :per_page, :as => :select, :label => "Posts per page", :collection => [20, 50, 100], :include_blank => false %>
<% end %>
<div class="input text optional field_with_hint">
<label class="text optional" for="user_favorite_tags">Favorite tags</label>
<textarea id="user_favorite_tags" class="text optional" rows="5" name="user[favorite_tags]" cols="40"><%= raw @user.favorite_tags %></textarea>

View File

@ -79,6 +79,12 @@
<td>6 sec</td>
<td>9 sec</td>
</tr>
<tr>
<td>50 or 100 Posts Per Page</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</tbody>
</table>
</div>

View File

@ -0,0 +1,6 @@
class AddPerPageToUsers < ActiveRecord::Migration
def change
execute("set statement_timeout = 0")
add_column :users, :per_page, :integer, :null => false, :default => 20
end
end

View File

@ -2602,7 +2602,8 @@ CREATE TABLE users (
enable_post_navigation boolean DEFAULT true NOT NULL,
new_post_navigation_layout boolean DEFAULT true NOT NULL,
enable_privacy_mode boolean DEFAULT false NOT NULL,
enable_sequential_post_navigation boolean DEFAULT true NOT NULL
enable_sequential_post_navigation boolean DEFAULT true NOT NULL,
per_page integer DEFAULT 20 NOT NULL
);
@ -6267,3 +6268,5 @@ INSERT INTO schema_migrations (version) VALUES ('20130320070700');
INSERT INTO schema_migrations (version) VALUES ('20130321144736');
INSERT INTO schema_migrations (version) VALUES ('20130322162059');
INSERT INTO schema_migrations (version) VALUES ('20130322173202');

View File

@ -81,7 +81,7 @@ module Danbooru
def option_for(key)
case key
when :limit
limit = @paginator_options.try(:[], :limit) || Danbooru.config.posts_per_page
limit = @paginator_options.try(:[], :limit) || CurrentUser.user.per_page
if limit.to_i > 1_000
limit = 1_000
end