diff --git a/.sass-cache/b118d4c1b1aae4efe3003ca592302b34dd7f51b1/default.scssc b/.sass-cache/b118d4c1b1aae4efe3003ca592302b34dd7f51b1/default.scssc index 5bb4eaff8..4ad796715 100644 Binary files a/.sass-cache/b118d4c1b1aae4efe3003ca592302b34dd7f51b1/default.scssc and b/.sass-cache/b118d4c1b1aae4efe3003ca592302b34dd7f51b1/default.scssc differ diff --git a/Gemfile.lock b/Gemfile.lock index e01b86639..0884d876f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,9 @@ GIT remote: http://github.com/mislav/will_paginate.git - revision: 3615938 + revision: b1a5bee branch: rails3 specs: - will_paginate (3.0.pre2) + will_paginate (3.0.pre3) GEM remote: http://gemcutter.org/ @@ -43,12 +43,12 @@ GEM daemons erubis (2.6.6) abstract (>= 1.0.0) - factory_girl (1.3.1) + factory_girl (1.3.2) faker (0.3.1) haml (3.0.21) i18n (0.4.1) imagesize (0.1.1) - mail (2.2.5) + mail (2.2.7) activesupport (>= 2.3.6) mime-types treetop (>= 1.4.5) @@ -59,9 +59,9 @@ GEM pg (0.9.0) polyglot (0.3.1) rack (1.2.1) - rack-mount (0.6.12) + rack-mount (0.6.13) rack (>= 1.0.0) - rack-test (0.5.4) + rack-test (0.5.6) rack (>= 1.0) rails (3.0.0) actionmailer (= 3.0.0) @@ -77,12 +77,12 @@ GEM rake (>= 0.8.4) thor (~> 0.14.0) rake (0.8.7) - shoulda (2.11.1) + shoulda (2.11.3) simple_form (1.2.2) super_exception_notifier (3.0.13) actionmailer rake - thor (0.14.0) + thor (0.14.3) treetop (1.4.8) polyglot (>= 0.3.1) tzinfo (0.3.23) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index a8c8fad85..246fcb8bc 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -2,7 +2,7 @@ class CommentsController < ApplicationController respond_to :html, :xml, :json def index - @posts = Post.paginate :order => "last_commented_at DESC", :per_page => 8 + @posts = Post.commented_before(params[:before_date] || Time.now).limit(8) end def update diff --git a/app/logical/related_tag_calculator.rb b/app/logical/related_tag_calculator.rb index ff680fe4e..44ccc59bd 100644 --- a/app/logical/related_tag_calculator.rb +++ b/app/logical/related_tag_calculator.rb @@ -1,23 +1,27 @@ class RelatedTagCalculator - def find_tags(tag, limit) + def self.find_tags(tag, limit) Post.find_by_tags(tag, :limit => limit, :select => "posts.tag_string", :order => "posts.md5").map(&:tag_string) end - def calculate_from_sample(name, limit, category_constraint = nil) + def self.calculate_from_sample_to_array(tags, category_constraint = nil) + convert_hash_to_array(calculate_from_sample(tags, Danbooru.config.post_sample_size, category_constraint)) + end + + def self.calculate_from_sample(tags, limit, category_constraint = nil) counts = Hash.new {|h, k| h[k] = 0} case category_constraint when Tag.categories.artist - limit *= 5 + limit *= 4 when Tag.categories.copyright - limit *= 4 + limit *= 3 when Tag.categories.character - limit *= 3 + limit *= 2 end - find_tags(name, limit).each do |tags| + find_tags(tags, limit).each do |tags| tag_array = Tag.scan_tags(tags) if category_constraint tag_array.each do |tag| @@ -36,11 +40,11 @@ class RelatedTagCalculator counts end - def convert_hash_to_array(hash) + def self.convert_hash_to_array(hash) hash.to_a.sort_by {|x| -x[1]}.slice(0, 25) end - def convert_hash_to_string(hash) + def self.convert_hash_to_string(hash) convert_hash_to_array(hash).flatten.join(" ") end end diff --git a/app/models/post.rb b/app/models/post.rb index efa4b28c0..13310e6f9 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -8,7 +8,7 @@ class Post < ActiveRecord::Base before_save :create_tags before_save :update_tag_post_counts before_save :set_tag_counts - before_validation_on_create :initialize_uploader + before_validation :initialize_uploader, :on => :create belongs_to :updater, :class_name => "User" belongs_to :approver, :class_name => "User" belongs_to :parent, :class_name => "Post" @@ -25,6 +25,7 @@ class Post < ActiveRecord::Base validate :validate_parent_does_not_have_a_parent attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at 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")} module FileMethods def delete_files diff --git a/app/models/tag.rb b/app/models/tag.rb index 632bc797b..2dbbde8c2 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -312,9 +312,8 @@ class Tag < ActiveRecord::Base module RelationMethods def update_related - calculator = RelatedTagCalculator.new - counts = calculator.calculate_from_sample(Danbooru.config.post_sample_size, name) - self.related_tags = calculator.convert_hash_to_string(counts) + counts = RelatedTagCalculator.calculate_from_sample(Danbooru.config.post_sample_size, name) + self.related_tags = RelatedTagCalculator.convert_hash_to_string(counts) end def update_related_if_outdated diff --git a/app/models/upload.rb b/app/models/upload.rb index 2567b5456..380d03ff8 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -7,8 +7,8 @@ class Upload < ActiveRecord::Base attr_accessor :file, :image_width, :image_height, :file_ext, :md5, :file_size belongs_to :uploader, :class_name => "User" belongs_to :post - before_validation_on_create :initialize_uploader - before_validation_on_create :initialize_status + before_validation :initialize_uploader, :on => :create + before_validation :initialize_status, :on => :create before_create :convert_cgi_file validate :uploader_is_not_limited diff --git a/app/presenters/paginator_presenter.rb b/app/presenters/paginator_presenter.rb deleted file mode 100644 index 48a747f61..000000000 --- a/app/presenters/paginator_presenter.rb +++ /dev/null @@ -1,2 +0,0 @@ -class PaginatorPresenter < Presenter -end diff --git a/app/presenters/paginators/base.rb b/app/presenters/paginators/base.rb new file mode 100644 index 000000000..832ce9cd5 --- /dev/null +++ b/app/presenters/paginators/base.rb @@ -0,0 +1,78 @@ +module Paginators + class Base < Presenter + def sequential_pagination_html(template) + html = "" + prev_url = template.request.env["HTTP_REFERER"] + next_url = sequential_link(template) + html << %{
  • « Previous
  • } + if post_set.posts.any? + html << %{
  • Next »
  • } + end + html << "
    " + html.html_safe + end + + def numbered_pagination_html(template) + html = "" + window = 3 + if total_pages <= (window * 2) + 5 + 1.upto(total_pages) do |page| + html << numbered_pagination_item(template, page, current_page) + end + elsif current_page <= window + 2 + 1.upto(current_page + window) do |page| + html << numbered_pagination_item(template, page, current_page) + end + html << numbered_pagination_item(template, "...", current_page) + html << numbered_pagination_item(template, total_pages, current_page) + + elsif current_page >= total_pages - (window + 1) + html << numbered_pagination_item(template, 1, current_page) + html << numbered_pagination_item(template, "...", current_page) + (current_page - window).upto(total_pages) do |page| + html << numbered_pagination_item(template, page, current_page) + end + else + html << numbered_pagination_item(template, 1, current_page) + html << numbered_pagination_item(template, "...", current_page) + (current_page - window).upto(current_page + window) do |page| + html << numbered_pagination_item(template, page, current_page) + end + html << numbered_pagination_item(template, "...", current_page) + html << numbered_pagination_item(template, total_pages, current_page) + end + html << "" + html.html_safe + end + + protected + def numbered_pagination_item(template, page, current_page) + html = "
  • " + if page == "..." + html << "..." + elsif page == current_page + html << page.to_s + else + html << link(template, page) + end + html << "
  • " + html.html_safe + end + + def total_pages + raise NotImplementedError + end + + def current_page + raise NotImplementedError + end + + def sequential_link(template) + raise NotImplementedError + end + + def paginated_link(template, page) + raise NotImplementedError + end + end +end diff --git a/app/presenters/paginators/post.rb b/app/presenters/paginators/post.rb new file mode 100644 index 000000000..fdc426bdf --- /dev/null +++ b/app/presenters/paginators/post.rb @@ -0,0 +1,26 @@ +module Paginators + class Post < 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 sequential_link(template) + template.posts_path(:tags => template.params[:tags], before_id => post_set.posts[-1].id, :page => nil) + end + + def paginated_link(template, page) + template.link_to(page, template.posts_path(:tags => template.params[:tags], :page => page)) + end + end +end diff --git a/app/presenters/post_set_presenter.rb b/app/presenters/post_set_presenter.rb index e15a12491..ec2aa1305 100644 --- a/app/presenters/post_set_presenter.rb +++ b/app/presenters/post_set_presenter.rb @@ -1,18 +1,19 @@ require 'pp' class PostSetPresenter < Presenter - attr_accessor :post_set + attr_accessor :post_set, :tag_set_presenter def initialize(post_set) @post_set = post_set + @tag_set_presenter = TagSetPresenter.new(RelatedTagCalculator.calculate_from_sample_to_array(@post_set.tags).map {|x| x[0]}) end def posts post_set.posts end - def tag_list_html - "" + def tag_list_html(template) + tag_set_presenter.tag_list_html(template) end def wiki_html(template) @@ -39,72 +40,12 @@ class PostSetPresenter < Presenter def pagination_html(template) if post_set.use_sequential_paginator? - sequential_pagination_html(template) + Paginators::Post.new(post_set).sequential_pagination_html(template) else - numbered_pagination_html(template) + Paginators::Post.new(post_set).numbered_pagination_html(template) end end - def sequential_pagination_html(template) - html = "" - prev_url = template.request.env["HTTP_REFERER"] - next_url = template.posts_path(:tags => template.params[:tags], before_id => post_set.posts[-1].id, :page => nil) - html << %{
  • « Previous
  • } - if post_set.posts.any? - html << %{
  • Next »
  • } - end - html << "
    " - html.html_safe - end - - def numbered_pagination_html(template) - total_pages = (post_set.count.to_f / post_set.limit.to_f).ceil - current_page = [1, post_set.page].max - html = "" - window = 3 - if total_pages <= (window * 2) + 5 - 1.upto(total_pages) do |page| - html << numbered_pagination_item(template, page, current_page) - end - elsif current_page <= window + 2 - 1.upto(current_page + window) do |page| - html << numbered_pagination_item(template, page, current_page) - end - html << numbered_pagination_item(template, "...", current_page) - html << numbered_pagination_item(template, total_pages, current_page) - - elsif current_page >= total_pages - (window + 1) - html << numbered_pagination_item(template, 1, current_page) - html << numbered_pagination_item(template, "...", current_page) - (current_page - window).upto(total_pages) do |page| - html << numbered_pagination_item(template, page, current_page) - end - else - html << numbered_pagination_item(template, 1, current_page) - html << numbered_pagination_item(template, "...", current_page) - (current_page - window).upto(current_page + window) do |page| - html << numbered_pagination_item(template, page, current_page) - end - html << numbered_pagination_item(template, "...", current_page) - html << numbered_pagination_item(template, total_pages, current_page) - end - html << "" - html.html_safe - end - - def numbered_pagination_item(template, page, current_page) - html = "
  • " - if page == "..." - html << "..." - elsif page == current_page - html << page.to_s - else - html << template.link_to(page, template.__send__(:posts_path, :tags => template.params[:tags], :page => page)) - end - html << "
  • " - html.html_safe - end - def post_previews_html html = "" diff --git a/app/presenters/tag_set_presenter.rb b/app/presenters/tag_set_presenter.rb index da6c7868f..227462075 100644 --- a/app/presenters/tag_set_presenter.rb +++ b/app/presenters/tag_set_presenter.rb @@ -31,12 +31,12 @@ private def build_list_item(tag, template, options) html = "" - html << %{
  • } + html << %{
  • } - if options[:show_extra_links] - html << %{? } + if CurrentUser.user.is_privileged? + html << %{? } html << %{+ } - html << %{- } + html << %{ } end humanized_tag = tag.tr("_", " ") diff --git a/app/views/comments/index.html.haml b/app/views/comments/index.html.haml new file mode 100644 index 000000000..390b6c3a8 --- /dev/null +++ b/app/views/comments/index.html.haml @@ -0,0 +1,2 @@ +- @posts.each do |post| + = @post.id \ No newline at end of file diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index f16b88905..d1ab79d21 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -13,6 +13,7 @@ <% end %> <%= auto_discovery_link_tag :atom, posts_path(:format => "atom", :tags => params[:tags]) %> <%= stylesheet_link_tag "compiled/default" %> + <%= stylesheet_link_tag "smoothness/jquery-ui-1.8.5.custom.css" %> <%= javascript_include_tag "compiled/default" %> <%= Danbooru.config.custom_html_header_content %> <%= yield :html_header %> @@ -47,7 +48,7 @@ <% end %> -
    +
    <%= yield :layout %>
    diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index f6d3c3100..7ea086e98 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,81 +1,90 @@ -<% if @post_set.suggestions.any? %> -
    - Maybe you meant: <%= @post_set.suggestions.map {|x| link_to(x, posts_path(:tags => x), :class => "tag-type-#{Tag.type_name(x)}" )}.to_sentence(:last_word_connector => ", or ", :two_words_connector => " or ") %> -
    -<% end %> +
    +
    + <% if @post_set.suggestions.any? %> +
    + Maybe you meant: <%= @post_set.suggestions.map {|x| link_to(x, posts_path(:tags => x), :class => "tag-type-#{Tag.type_name(x)}" )}.to_sentence(:last_word_connector => ", or ", :two_words_connector => " or ") %> +
    + <% end %> - + +
    +

    Posts

    + <%= @post_set.presenter.post_previews_html %> + +
    -
    -

    Tags

    - <%= @post_set.presenter.tag_list_html %> +
    + <%= @post_set.presenter.pagination_html(self) %> +
    -
    -

    Wiki

    - <%= @post_set.presenter.wiki_html(self) %> -
    + <% content_for(:page_title) do %> + / <%= @post_set.tags %> + <% end %> + + <%= render :partial => "posts/partials/common/secondary_links" %>
    - +
    -
    -

    Posts

    - <%= @post_set.presenter.post_previews_html %> -
    - -
    - <%= @post_set.presenter.pagination_html(self) %> -
    - -<% content_for(:page_title) do %> - / <%= @post_set.tags %> -<% end %> - -<%= render :partial => "posts/partials/common/secondary_links" %> diff --git a/app/views/posts/partials/show/_edit.html.erb b/app/views/posts/partials/show/_edit.html.erb index 9029b1082..0ac29e457 100644 --- a/app/views/posts/partials/show/_edit.html.erb +++ b/app/views/posts/partials/show/_edit.html.erb @@ -5,46 +5,54 @@
    <% end %> - <% form_for(post) do |f| %> + <% form_for(post, :html => {:class => "simple_form"}) do |f| %> <%= f.hidden_field :old_tags, :value => post.tag_string %> -

    +

    <% if post.is_rating_locked? %> This post is rating locked. <% else %> - <%= f.label :rating_explicit, "Explicit" %> - <%= f.radio_button :rating, :e %> - - <%= f.label :rating_questionable, "Questionable" %> - <%= f.radio_button :rating, :q %> + <%= f.label :blank, "Rating" %> + +
    + <%= f.radio_button :rating, :e %> + <%= f.label :rating_e, "Explicit" %> - <%= f.label :rating_safe, "Safe" %> - <%= f.radio_button :rating, :s %> + <%= f.radio_button :rating, :q %> + <%= f.label :rating_q, "Questionable" %> + + <%= f.radio_button :rating, :s %> + <%= f.label :rating_s, "Safe" %> +
    <% end %> -

    +
    <% if CurrentUser.user.is_privileged? %> -

    - <%= f.label :is_note_locked, "Lock notes" %> - <%= f.check_box :is_note_locked %> -

    - -

    - <%= f.label :is_rating_locked, "Lock rating" %> - <%= f.check_box :is_rating_locked %> -

    +
    + <%= f.label :blank, "Lock" %> + +
    + <%= f.check_box :is_note_locked %> + <%= f.label :is_note_locked, "Notes" %> + + <%= f.check_box :is_rating_locked %> + <%= f.label :is_rating_locked, "Rating" %> +
    +
    <% end %> -

    +

    <%= f.label :source %> <%= f.text_field :source %> -

    +
    -

    +

    <%= f.label :tag_string, "Tags" %> <%= f.text_area :tag_string , :size => "50x3" %> -

    +
    - <%= submit_tag "Submit" %> +
    + <%= submit_tag "Submit" %> +
    <% end %> \ No newline at end of file diff --git a/app/views/posts/partials/show/_information.html.erb b/app/views/posts/partials/show/_information.html.erb index d7e77ef31..d721c5d18 100644 --- a/app/views/posts/partials/show/_information.html.erb +++ b/app/views/posts/partials/show/_information.html.erb @@ -1,5 +1,4 @@