diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 2834ad61e..922b42745 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -360,7 +360,11 @@ Danbooru.Note = { var $note_box = Danbooru.Note.Box.find(id); var text = $textarea.val(); $note_body.data("original-body", text); - Danbooru.Note.Body.set_text($note_body, text); + Danbooru.Note.Body.set_text($note_body, "Loading..."); + $.get("/note_previews.json", {body: text}).success(function(data) { + Danbooru.Note.Body.set_text($note_body, data.body); + $note_body.show(); + }); $this.dialog("close"); if (id.match(/\d/)) { @@ -386,8 +390,11 @@ Danbooru.Note = { var id = $this.data("id"); var $note_body = Danbooru.Note.Body.find(id); var text = $textarea.val(); - Danbooru.Note.Body.set_text($note_body, text); - $note_body.show(); + Danbooru.Note.Body.set_text($note_body, "Loading..."); + $.get("/note_previews.json", {body: text}).success(function(data) { + Danbooru.Note.Body.set_text($note_body, data.body); + $note_body.show(); + }); }, cancel: function() { diff --git a/app/controllers/dmails_controller.rb b/app/controllers/dmails_controller.rb index 9b9e5cfc3..30759c3c5 100644 --- a/app/controllers/dmails_controller.rb +++ b/app/controllers/dmails_controller.rb @@ -14,6 +14,7 @@ class DmailsController < ApplicationController end def index + cookies[:dmail_folder] = params[:folder] @search = Dmail.visible.search(params[:search]) @dmails = @search.order("dmails.created_at desc").paginate(params[:page]) respond_with(@dmails) do |format| diff --git a/app/controllers/note_previews_controller.rb b/app/controllers/note_previews_controller.rb new file mode 100644 index 000000000..81c464689 --- /dev/null +++ b/app/controllers/note_previews_controller.rb @@ -0,0 +1,12 @@ +class NotePreviewsController < ApplicationController + respond_to :json + + def show + @body = DText.sanitize(params[:body].to_s) + respond_with(@body) do |format| + format.json do + render :json => {:body => @body}.to_json + end + end + end +end diff --git a/app/helpers/dmails_helper.rb b/app/helpers/dmails_helper.rb index 3583e9cf4..869a21820 100644 --- a/app/helpers/dmails_helper.rb +++ b/app/helpers/dmails_helper.rb @@ -1,2 +1,12 @@ module DmailsHelper + def dmails_current_folder_path + case cookies[:dmail_folder] + when "sent" + dmails_path(:search => {:owner_id => CurrentUser.id, :from_id => CurrentUser.id}, :folder => "sent") + when "all" + dmails_path(:search => {:owner_id => CurrentUser.id}, :folder => "all") + else + dmails_path(:search => {:owner_id => CurrentUser.id, :to_id => CurrentUser.id}, :folder => "received") + end + end end diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index 216194cc2..21db554ca 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -69,6 +69,10 @@ module PostSets tag_string =~ /\*/ end + def is_empty_search? + posts.count == 0 + end + def current_page [page.to_i, 1].max end diff --git a/app/presenters/post_set_presenters/post.rb b/app/presenters/post_set_presenters/post.rb index c24c9c7dc..6ebe62790 100644 --- a/app/presenters/post_set_presenters/post.rb +++ b/app/presenters/post_set_presenters/post.rb @@ -9,7 +9,9 @@ module PostSetPresenters end def related_tags - if post_set.is_pattern_search? + if post_set.is_empty_search? + suggested_tags + elsif post_set.is_pattern_search? pattern_tags elsif post_set.is_tag_subscription? post_set.tag_subscription_tags @@ -39,6 +41,12 @@ module PostSetPresenters Tag.name_matches(post_set.tag_string).all(:select => "name", :limit => Danbooru.config.tag_query_limit, :order => "post_count DESC").map(&:name) end + def suggested_tags + if post_set.tag_string.length >= 3 + Tag.name_matches("*#{post_set.tag_string}*").where("post_count > 0").all(:select => "name", :limit => Danbooru.config.tag_query_limit, :order => "post_count DESC").map(&:name) + end + end + def related_tags_for_group RelatedTagCalculator.calculate_from_sample_to_array(post_set.tag_string).map(&:first) end diff --git a/app/views/artists/_secondary_links.html.erb b/app/views/artists/_secondary_links.html.erb index fe6245524..0afb0fb1a 100644 --- a/app/views/artists/_secondary_links.html.erb +++ b/app/views/artists/_secondary_links.html.erb @@ -7,7 +7,7 @@
  • <%= link_to "Recent changes", artist_versions_path %>
  • <% if @artist && !@artist.new_record? %>
  • |
  • -
  • <%= link_to "Posts", posts_path(:tags => @artist.name) %>
  • +
  • <%= link_to "Posts (#{Post.fast_count(@artist.name)})", posts_path(:tags => @artist.name) %>
  • <%= link_to "Show", artist_path(@artist) %>
  • <% if CurrentUser.is_member? %>
  • <%= link_to "Edit", edit_artist_path(@artist) %>
  • diff --git a/app/views/dmails/_secondary_links.html.erb b/app/views/dmails/_secondary_links.html.erb index 4eac22d6b..2a46bc711 100644 --- a/app/views/dmails/_secondary_links.html.erb +++ b/app/views/dmails/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= link_to "All", dmails_path %>
  • +
  • <%= link_to "All", dmails_path(:search => {:owner_id => CurrentUser.id}, :folder => "all") %>
  • <%= link_to "Received", dmails_path(:search => {:owner_id => CurrentUser.id, :to_id => CurrentUser.id}, :folder => "received") %>
  • <%= link_to "Sent", dmails_path(:search => {:owner_id => CurrentUser.id, :from_id => CurrentUser.id}, :folder => "sent") %>
  • <%= link_to "New", new_dmail_path %>
  • diff --git a/app/views/users/_secondary_links.html.erb b/app/views/users/_secondary_links.html.erb index 18bd6b648..3cd6bdb62 100644 --- a/app/views/users/_secondary_links.html.erb +++ b/app/views/users/_secondary_links.html.erb @@ -16,7 +16,7 @@
  • <%= link_to "Edit subscriptions", tag_subscriptions_path %>
  • <% end %>
  • <%= link_to "Profile", user_path(CurrentUser.user) %>
  • -
  • <%= link_to "Messages #{CurrentUser.dmail_count}", dmails_path(:search => {:owner_id => CurrentUser.id, :to_id => CurrentUser.id}, :folder => "received") %>
  • +
  • <%= link_to "Messages #{CurrentUser.dmail_count}", dmails_current_folder_path %>
  • <% else %>
  • <%= link_to "Send message", new_dmail_path(:dmail => {:to_id => @user.id}) %>
  • <% end %> diff --git a/config/routes.rb b/config/routes.rb index 58543ec82..4f53f744d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -120,6 +120,7 @@ Danbooru::Application.routes.draw do end end resources :note_versions, :only => [:index] + resource :note_previews, :only => [:show] resources :pools do member do put :revert