From 085995126c04ebde4615c63a0424120256ee399e Mon Sep 17 00:00:00 2001 From: albert Date: Sun, 3 Jul 2011 19:12:31 -0400 Subject: [PATCH] changes --- app/controllers/artist_versions_controller.rb | 2 +- app/helpers/pagination_helper.rb | 2 + app/logical/post_sets/pool.rb | 17 +++- app/presenters/post_presenter.rb | 2 +- app/views/artist_versions/index.html.erb | 66 +++++++------- app/views/artists/index.html.erb | 28 +++--- app/views/pools/index.html.erb | 2 +- app/views/pools/show.html.erb | 4 +- app/views/tag_aliases/index.html.erb | 12 ++- app/views/tag_implications/index.html.erb | 12 ++- app/views/tags/index.html.erb | 4 +- config/danbooru_default_config.rb | 2 +- config/danbooru_local_config.rb | 2 +- db/seeds.rb | 91 +++++++++++++++++-- .../paginator/active_record_extension.rb | 2 +- lib/danbooru/paginator/error.rb | 6 -- 16 files changed, 176 insertions(+), 78 deletions(-) delete mode 100644 lib/danbooru/paginator/error.rb diff --git a/app/controllers/artist_versions_controller.rb b/app/controllers/artist_versions_controller.rb index 410609057..5639a5320 100644 --- a/app/controllers/artist_versions_controller.rb +++ b/app/controllers/artist_versions_controller.rb @@ -3,7 +3,7 @@ class ArtistVersionsController < ApplicationController def index @search = ArtistVersion.search(params[:search]) - @artist_versions = @search.paginate :page => params[:page] + @artist_versions = @search.paginate(params[:page]) respond_with(@artist_versions) end end diff --git a/app/helpers/pagination_helper.rb b/app/helpers/pagination_helper.rb index 0e9202ab9..7646b702f 100644 --- a/app/helpers/pagination_helper.rb +++ b/app/helpers/pagination_helper.rb @@ -63,6 +63,8 @@ module PaginationHelper end def numbered_paginator_item(page, current_page) + return "" if page.to_i > Danbooru.config.max_numbered_pages + html = "
  • " if page == "..." html << "..." diff --git a/app/logical/post_sets/pool.rb b/app/logical/post_sets/pool.rb index a091b99d7..754818ed3 100644 --- a/app/logical/post_sets/pool.rb +++ b/app/logical/post_sets/pool.rb @@ -1,11 +1,18 @@ module PostSets class Pool < Base + module ActiveRecordExtension + attr_accessor :total_pages, :current_page + end + attr_reader :pool, :page, :posts - def initailize(pool, page) + def initialize(pool, page) @pool = pool @page = page @posts = pool.posts(:offset => offset, :limit => limit) + @posts.extend(ActiveRecordExtension) + @posts.total_pages = total_pages + @posts.current_page = current_page end def offset @@ -27,5 +34,13 @@ module PostSets def presenter @presenter ||= PostSetPresenters::Pool.new(self) end + + def total_pages + (pool.post_count.to_f / limit).ceil + end + + def current_page + (offset.to_f / pool.post_count).floor + end end end diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 04395c5ce..97d93284c 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -23,7 +23,7 @@ class PostPresenter < Presenter def image_html(template) return template.content_tag("p", "This image was deleted.") if @post.is_deleted? && !CurrentUser.user.is_janitor? - return template.content_tag("p", "You need a privileged account to see this image.") if !Danbooru.config.can_see_post?(@post, CurrentUser.user) + return template.content_tag("p", "You need a privileged account to see this image.") if !Danbooru.config.can_user_see_post?(CurrentUser.user, @post) if @post.is_flash? template.render(:partial => "posts/partials/show/flash", :locals => {:post => @post}) diff --git a/app/views/artist_versions/index.html.erb b/app/views/artist_versions/index.html.erb index d69e4edd7..bfbd733e7 100644 --- a/app/views/artist_versions/index.html.erb +++ b/app/views/artist_versions/index.html.erb @@ -1,36 +1,40 @@ -

    Artist History

    +
    +
    +

    Artist History

    -
    - - - - - - - - - - - - - - <% @artist_versions.each do |artist_version| %> - - - - - - - - - - <% end %> - -
    NameOther NamesGroupUpdatedUpdated byActiveURLs
    <%= link_to h(artist_version.name), artist_versions_path(:artist_id => artist_version.artist_id) %><%= h artist_version.other_names %><%= h artist_version.group_name %><%= time_ago_in_words artist_version.created_at %> ago<%= link_to artist_version.updater_name, user_path(artist_version.updater_id) %><%= artist_version.is_active? %><%= artist_version.url_string %>
    -
    +
    + + + + + + + + + + + + + + <% @artist_versions.each do |artist_version| %> + + + + + + + + + + <% end %> + +
    NameOther NamesGroupUpdatedUpdated byActiveURLs
    <%= link_to h(artist_version.name), artist_versions_path(:artist_id => artist_version.artist_id) %><%= h artist_version.other_names %><%= h artist_version.group_name %><%= time_ago_in_words artist_version.created_at %> ago<%= link_to artist_version.updater_name, user_path(artist_version.updater_id) %><%= artist_version.is_active? %><%= artist_version.url_string %>
    +
    -
    - <%= sequential_paginator(@artist_versions) %> +
    + <%= sequential_paginator(@artist_versions) %> +
    +
    <%= render "artists/secondary_links" %> diff --git a/app/views/artists/index.html.erb b/app/views/artists/index.html.erb index 56863b6d7..04db54711 100644 --- a/app/views/artists/index.html.erb +++ b/app/views/artists/index.html.erb @@ -3,33 +3,39 @@ - - + + + <% @artists.each do |artist| %> <%= content_tag(:tr, :id => "artist-#{artist.id}") do %> - + + <% end %> <% end %>
    NamePrimary NameSecondary NamesStatus
    - <%= link_to "P", posts_path(:tags => artist.name), :title => "Find posts for artist" %> - <%= link_to "E", edit_artist_path(artist), :title => "Edit artist" %> - <%= link_to "D", artist_path(artist, :method => :delete, :confirm => "Do you really want to delete this artist?") %> - <%= link_to h(artist.name), artist_path(artist) %> <% if !artist.group_name.blank? %> (group:<%= link_to(artist.group_name, artist_path(artist)) %>) <% end %> <%= artist.other_names %> + <% if artist.is_active? %> + Active + <% else %> + Deleted + <% end %> + + <% if artist.is_banned? %> + Banned + <% end %> +
    -
    - <%= numbered_paginator(@artists) do |page| %> - <%= link_to(page, artists_path(:page => page, :search => params[:search])) %> - <% end %> +
    + <%= numbered_paginator(@artists) %>
    <%= render "secondary_links" %> diff --git a/app/views/pools/index.html.erb b/app/views/pools/index.html.erb index 279f61acf..f1dac6cd9 100644 --- a/app/views/pools/index.html.erb +++ b/app/views/pools/index.html.erb @@ -25,7 +25,7 @@ -
    +
    <%= sequential_paginator(@pools) %>
    diff --git a/app/views/pools/show.html.erb b/app/views/pools/show.html.erb index b4ab4be75..b1ede6d9e 100644 --- a/app/views/pools/show.html.erb +++ b/app/views/pools/show.html.erb @@ -12,9 +12,7 @@
    - <%= numbered_paginator(@post_set) do |page| %> - <%= link_to(page, pool_path(@pool, :page => page)) %> - <% end %> + <%= numbered_paginator(@post_set) %>
    diff --git a/app/views/tag_aliases/index.html.erb b/app/views/tag_aliases/index.html.erb index b7c554541..27d955a65 100644 --- a/app/views/tag_aliases/index.html.erb +++ b/app/views/tag_aliases/index.html.erb @@ -22,7 +22,11 @@ <%= link_to tag_alias.antecedent_name, posts_path(:tags => tag_alias.antecedent_name) %> (<%= tag_alias.antecedent_tag.post_count rescue 0 %>) <%= link_to tag_alias.consequent_name, posts_path(:tags => tag_alias.consequent_name) %> (<%= tag_alias.consequent_tag.post_count rescue 0 %>) - <%= link_to tag_alias.forum_topic_id, forum_topic_path(tag_alias.forum_topic_id) %> + + <% if tag_alias.forum_topic_id %> + <%= link_to tag_alias.forum_topic_id, forum_topic_path(tag_alias.forum_topic_id) %> + <% end %> + <% if CurrentUser.is_admin? %> <%= link_to "Delete", tag_alias_path(tag_alias), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this alias?" %> @@ -35,10 +39,8 @@
    -
    - <%= numbered_paginator(@tag_aliases) do |page| %> - <%= link_to(page, tag_aliases_path(:page => page)) %> - <% end %> +
    + <%= numbered_paginator(@tag_aliases) %>
    <%= render "secondary_links" %> diff --git a/app/views/tag_implications/index.html.erb b/app/views/tag_implications/index.html.erb index 466ef2f89..92aaefbb4 100644 --- a/app/views/tag_implications/index.html.erb +++ b/app/views/tag_implications/index.html.erb @@ -22,7 +22,11 @@ <%= link_to tag_implication.antecedent_name, posts_path(:tags => tag_implication.antecedent_name) %> (<%= tag_implication.antecedent_tag.post_count rescue 0 %>) <%= link_to tag_implication.consequent_name, posts_path(:tags => tag_implication.consequent_name) %> (<%= tag_implication.consequent_tag.post_count rescue 0 %>) - <%= link_to tag_implication.forum_topic_id, forum_topic_path(tag_implication.forum_topic_id) %> + + <% if tag_implication.forum_topic_id %> + <%= link_to tag_implication.forum_topic_id, forum_topic_path(tag_implication.forum_topic_id) %> + <% end %> + <% if CurrentUser.is_admin? %> <%= link_to "Delete", tag_implication_path(tag_implication), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this implication?" %> @@ -35,10 +39,8 @@
    -
    - <%= numbered_paginator(@tag_implications) do |page| %> - <%= link_to(page, tag_impliactions_path(:page => page)) %> - <% end %> +
    + <%= numbered_paginator(@tag_implications) %>
    <%= render "secondary_links" %> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index 314faf9f0..aacb7aefa 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -19,9 +19,7 @@
    - <%= numbered_paginator(@tags) do |page| %> - <%= link_to(page, tags_path(:page => page)) %> - <% end %> + <%= numbered_paginator(@tags) %>
    <%= render "secondary_links" %> diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 858e89679..dac00824a 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -109,7 +109,7 @@ module Danbooru # After this many pages, the paginator will switch to sequential mode. def max_numbered_pages - 2 + 10 end # Max number of tag subscriptions per user diff --git a/config/danbooru_local_config.rb b/config/danbooru_local_config.rb index e380ab2f2..283e02225 100644 --- a/config/danbooru_local_config.rb +++ b/config/danbooru_local_config.rb @@ -6,7 +6,7 @@ module Danbooru end def posts_per_page - 1 + 3 end def is_user_restricted?(user) diff --git a/db/seeds.rb b/db/seeds.rb index 664d8c74c..132843e4a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,84 @@ -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). -# -# Examples: -# -# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) -# Mayor.create(:name => 'Daley', :city => cities.first) +if User.count == 0 + puts "Creating users" + user = User.create( + :name => "albert", + :password => "password1", + :password_confirmation => "password1" + ) +else + puts "Skipping users" + user = User.first +end + +CurrentUser.user = user +CurrentUser.ip_addr = "127.0.0.1" + +if Upload.count == 0 + puts "Creating uploads" + 1.upto(100) do |i| + url = "http://dummyimage.com/#{i * 10}x400/000/fff" + tags = (i * i * i).to_s.scan(/./).uniq.join(" ") + + Upload.create(:source => url, :content_type => "image/gif", :rating => "q", :tag_string => tags) + end +else + puts "Skipping uploads" +end + +if Post.count == 0 + puts "Creating posts" + Upload.all.each do |upload| + upload.process! + end +else + puts "Skipping posts" +end + +if Comment.count == 0 + puts "Creating comments" + Post.all.each do |post| + Comment.create(:post_id => post.id, :body => rand(1_000_000).to_s) + end +else + puts "Skipping comments" +end + +if Note.count == 0 + puts "Creating notes" + Post.all.each do |post| + 3.times do + Note.create(:post_id => post.id, :x => 0, :y => 0, :width => 100, :height => 100, :body => rand(1_000_000).to_s) + end + end +else + puts "Skipping notes" +end + +if Artist.count == 0 + puts "Creating artists" + 0.upto(100) do |i| + Artist.create(:name => i.to_s) + end +else + puts "Skipping artists" +end + +if TagAlias.count == 0 + puts "Creating tag aliases" + + 11.upto(99) do |i| + TagAlias.create(:antecedent_name => i.to_s, :consequent_name => (i * 100).to_s) + end +else + puts "Skipping tag aliases" +end + +if TagImplication.count == 0 + puts "Creating tag implictions" + + 10_000.upto(10_100) do |i| + TagImplication.create(:antecedent_name => i.to_s, :consequent_name => (i * 100).to_s) + end +else + puts "Skipping tag implications" +end \ No newline at end of file diff --git a/lib/danbooru/paginator/active_record_extension.rb b/lib/danbooru/paginator/active_record_extension.rb index 1abaf8937..37f9ab6ab 100644 --- a/lib/danbooru/paginator/active_record_extension.rb +++ b/lib/danbooru/paginator/active_record_extension.rb @@ -52,7 +52,7 @@ module Danbooru 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.") + raise "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| diff --git a/lib/danbooru/paginator/error.rb b/lib/danbooru/paginator/error.rb deleted file mode 100644 index 4acfa49fc..000000000 --- a/lib/danbooru/paginator/error.rb +++ /dev/null @@ -1,6 +0,0 @@ -module Danbooru - module Paginator - class Error < Exception - end - end -end