add references to user statistics page about saved searches

This commit is contained in:
r888888888
2017-01-20 16:42:17 -08:00
parent 48e66cddbb
commit c7b5a4e229
4 changed files with 23 additions and 4 deletions

View File

@@ -8,7 +8,7 @@ class PopularSearchService
end
def each_search(limit = 100, &block)
fetch_data.scan(/(.+?) (\d+)\.0\n/).slice(0, limit).each(&block)
fetch_data.to_s.scan(/(.+?) (\d+)\.0\n/).slice(0, limit).each(&block)
end
def fetch_data

View File

@@ -132,6 +132,10 @@ class SavedSearch < ActiveRecord::Base
rename_listbooru(user_id, old_category, new_category)
end
def self.categories_for(user)
user.saved_searches.pluck("distinct category")
end
def normalize
self.category = SavedSearch.normalize_category(category) if category
self.tag_query = SavedSearch.normalize(tag_query)

View File

@@ -19,6 +19,8 @@ module PostSetPresenters
related_tags_for_single(post_set.unordered_tag_array.first)
elsif post_set.tag_string =~ /(?:^|\s)(?:#{Tag::SUBQUERY_METATAGS}):\S+/
calculate_related_tags_from_post_set
elsif post_set.tag_string =~ /search:/
saved_search_tags
elsif post_set.is_empty_tag?
popular_tags
else
@@ -52,6 +54,10 @@ module PostSetPresenters
RelatedTagCalculator.calculate_from_post_set_to_array(post_set).map(&:first)
end
def saved_search_tags
SavedSearch.categories_for(CurrentUser.user).map {|x| "search:#{x}"}
end
def tag_list_html(template, options = {})
tag_set_presenter.tag_list_html(template, options)
end

View File

@@ -111,9 +111,7 @@
<th>Appeals</th>
<td><%= presenter.appeal_count(self) %></td>
</tr>
<% end %>
<% if CurrentUser.user.id == user.id || CurrentUser.is_moderator? %>
<tr>
<th>Flags</th>
<td><%= presenter.flag_count(self) %></td>
@@ -145,7 +143,18 @@
</tr>
<% end %>
<% if CurrentUser.user.id == user.id %>
<% if CurrentUser.id == user.id %>
<% if CurrentUser.has_saved_searches? %>
<tr>
<th>Saved Searches</th>
<td>
<% SavedSearch.categories_for(CurrentUser.user).each do |category| %>
<p><%= link_to category, posts_path(tags: "search:#{category}") %></p>
<% end %>
</td>
</tr>
<% end %>
<tr>
<th>API Key</th>
<td>