additional saved search fixes

This commit is contained in:
r888888888 2017-01-25 12:44:10 -08:00
parent 1207faa600
commit 8a93fdf18f
6 changed files with 32 additions and 7 deletions

View File

@ -1,2 +1,2 @@
unicorn: bundle exec unicorn -c config/unicorn/unicorn.rb
unicorn: bundle exec rails server
jobs: bundle exec script/delayed_job run

View File

@ -548,7 +548,7 @@
method: "get",
success: function(data) {
resp($.map(data, function(saved_search) {
var category = saved_search.category === null ? "Uncategorized" : saved_search.category;
var category = saved_search.category === null ? "uncategorized" : saved_search.category;
return {
label: category,
value: category

View File

@ -0,0 +1,7 @@
#c-saved-searches {
#a-index {
table {
margin-bottom: 2em;
}
}
}

View File

@ -1,5 +1,5 @@
class SavedSearch < ActiveRecord::Base
UNCATEGORIZED_NAME = "Uncategorized"
UNCATEGORIZED_NAME = "uncategorized"
module ListbooruMethods
extend ActiveSupport::Concern
@ -57,9 +57,15 @@ class SavedSearch < ActiveRecord::Base
body = Cache.get("ss-pids-#{user_id}-#{hash_name}", 60) do
params = {
"key" => Danbooru.config.listbooru_auth_key,
"user_id" => user_id,
"name" => name
"user_id" => user_id
}
if name == UNCATEGORIZED_NAME
params["name"] = nil
elsif name.present?
params["name"] = name
end
uri = URI.parse("#{Danbooru.config.listbooru_server}/users")
uri.query = URI.encode_www_form(params)
@ -133,7 +139,13 @@ class SavedSearch < ActiveRecord::Base
end
def self.categories_for(user)
user.saved_searches.pluck("distinct category")
user.saved_searches.pluck("distinct category").map do |x|
if x.blank?
SavedSearch::UNCATEGORIZED_NAME
else
x
end
end
end
def normalize

View File

@ -11,6 +11,8 @@ module PostSetPresenters
def related_tags
if post_set.is_pattern_search?
pattern_tags
elsif post_set.is_saved_search?
SavedSearch.categories_for(CurrentUser.user).map {|x| "search:#{x}"}
elsif post_set.is_tag_subscription?
post_set.tag_subscription_tags
elsif post_set.is_single_tag?
@ -59,6 +61,10 @@ module PostSetPresenters
end
def tag_list_html(template, options = {})
if post_set.is_saved_search?
options[:name_only] = true
end
tag_set_presenter.tag_list_html(template, options)
end
end

View File

@ -8,7 +8,7 @@
<%= link_to_if SavedSearch.posts_search_available?, category.tr("_", " "), posts_path(:tags => "search:#{category}") %>
(<%= link_to "rename", new_saved_search_category_change_path(:old => category) %>)
<% else %>
<%= link_to_if SavedSearch.posts_search_available?, SavedSearch::UNCATEGORIZED_NAME, posts_path(:tags => "search:all") %>
<%= link_to_if SavedSearch.posts_search_available?, SavedSearch::UNCATEGORIZED_NAME, posts_path(:tags => "search:#{SavedSearch::UNCATEGORIZED_NAME}") %>
<% end %>
</h2>
<table class="striped" width="100%">