add saved search gallery link, can only view your own saved searches, normalize saved search categories

This commit is contained in:
r888888888
2015-11-24 16:26:04 -08:00
parent 90eb374d06
commit 89794a7ef2
7 changed files with 35 additions and 15 deletions

View File

@@ -103,16 +103,10 @@ class PostQueryBuilder
def add_saved_search_relation(saved_searches, relation)
saved_searches.each do |saved_search|
if saved_search =~ /^(.+?):(.+)$/
user_name = $1
name = $2
user = User.find_by_name(user_name)
return relation if user.nil?
post_ids = SavedSearch.post_ids(user.id, name)
if saved_search == "all"
post_ids = SavedSearch.post_ids(CurrentUser.id)
else
user = User.find_by_name(saved_search)
return relation if user.nil?
post_ids = SavedSearch.post_ids(user.id, nil)
post_ids = SavedSearch.post_ids(CurrentUser.id, saved_search)
end
post_ids = [0] if post_ids.empty?

View File

@@ -109,6 +109,7 @@ class SavedSearch < ActiveRecord::Base
end
def normalize
self.category = category.strip.gsub(/\s+/, "_").downcase if category
self.tag_query = SavedSearch.normalize(tag_query)
end

View File

@@ -460,10 +460,8 @@ class User < ActiveRecord::Base
def max_saved_searches
if is_platinum?
1_000
elsif is_gold?
200
else
100
250
end
end

View File

@@ -0,0 +1,6 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Gallery", posts_path(:tags => "search:all") %></li>
<li><%= link_to "Listing", saved_searches_path %></li>
</menu>
<% end %>

View File

@@ -12,7 +12,7 @@
</div>
</div>
<%= render "users/secondary_links" %>
<%= render "secondary_links" %>
<% content_for(:page_title) do %>
Edit Saved Search - <%= Danbooru.config.app_name %>

View File

@@ -3,7 +3,13 @@
<h1>Saved Searches</h1>
<% @categories.each do |category, saved_searches| %>
<h2><%= category.present? ? category : "Uncategorized" %></h2>
<h2>
<% if category.present? %>
<%= link_to category, posts_path(:tags => "search:#{category}") %>
<% else %>
Uncategorized
<% end %>
</h2>
<table class="striped" width="100%">
<thead>
<tr>
@@ -27,7 +33,7 @@
</div>
</div>
<%= render "users/secondary_links" %>
<%= render "secondary_links" %>
<% content_for(:page_title) do %>
Saved Searches - <%= Danbooru.config.app_name %>

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env ruby
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
CurrentUser.user = User.admins.first
CurrentUser.ip_addr = "127.0.0.1"
SavedSearch.where("category is not null and category <> ''").find_each do |ss|
print ss.category + " -> "
ss.normalize
puts ss.category
ss.save
end