improved ui for saved searches #2523

This commit is contained in:
r888888888
2015-11-17 17:36:22 -08:00
parent ac617544b8
commit 156165a86f
5 changed files with 68 additions and 16 deletions

View File

@@ -524,23 +524,47 @@
}
Danbooru.Post.initialize_saved_searches = function() {
$("#saved_search_category").autocomplete({
minLength: 1,
source: function(req, resp) {
$.ajax({
url: "/saved_searches/categories.json",
method: "get",
success: function(data) {
resp($.map(data, function(saved_search) {
return {
label: saved_search.category,
value: saved_search.category
};
}));
}
})
}
});
$("#save-search-dialog").dialog({
width: 500,
modal: true,
autoOpen: false,
buttons: {
"Submit": function() {
$("#save-search-dialog form").submit();
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
$("#save-search").click(function() {
if (Danbooru.meta("disable-categorized-saved-searches") === "false") {
var input = window.prompt("Category for this saved search (optional):");
if (input !== null) {
$.post(
"/saved_searches.js",
{
"tags": $("#tags").attr("value"),
"category": input
}
);
}
$("#save-search-dialog").dialog("open");
} else {
$.post(
"/saved_searches.js",
{
"tags": $("#tags").attr("value")
"saved_search_tags": $("#tags").attr("value")
}
);
}

View File

@@ -3,7 +3,9 @@ class SavedSearchesController < ApplicationController
respond_to :html, :xml, :json, :js
def index
SavedSearch.delay(:queue => "default").refresh_listbooru(CurrentUser.id)
if Danbooru.config.listbooru_server
SavedSearch.delay(:queue => "default").refresh_listbooru(CurrentUser.id)
end
@saved_searches = saved_searches.order("tag_query")
@categories = @saved_searches.group_by{|saved_search| saved_search.category.to_s}
@@ -16,8 +18,18 @@ class SavedSearchesController < ApplicationController
end
end
def categories
@categories = saved_searches.select(:category).distinct
respond_with(@categories)
end
def create
@saved_search = saved_searches.create(:tag_query => params[:tags], :category => params[:category])
@saved_search = saved_searches.create(:tag_query => params[:saved_search_tags], :category => params[:saved_search_category])
if params[:saved_search_disable_categories]
CurrentUser.disable_categorized_saved_searches = true
CurrentUser.save
end
end
def destroy

View File

@@ -1,3 +1,17 @@
<% if CurrentUser.show_saved_searches? %>
<%= button_tag "Save search", :id => "save-search" %>
<% end %>
<div id="save-search-dialog" title="Save Search" style="display: none;">
<%= form_tag(saved_searches_path, :class => "simple_form", :remote => true) do %>
<%= hidden_field_tag "saved_search_tags", params[:tags] %>
<div class="input">
<label>
<%= text_field_tag "saved_search_category", "", :placeholder => "Category" %>
</label>
</div>
<p><label><%= check_box_tag "saved_search_disable_categories" %> Disable categorization</label></p>
<% end %>
</div>

View File

@@ -2,6 +2,4 @@
Danbooru.error("<%= j @saved_search.errors.full_messages.join(', ') %>");
<% else %>
Danbooru.notice("Search '<%= j @saved_search.tag_query %>' was saved");
$("#saved-searches-nav").html("<%= j render('saved_searches/interface', :saved_searches => CurrentUser.user.saved_searches) %>");
Danbooru.Post.initialize_saved_searches();
<% end %>

View File

@@ -222,7 +222,11 @@ Rails.application.routes.draw do
get "reports/user_promotions" => "reports#user_promotions"
get "reports/janitor_trials" => "reports#janitor_trials"
get "reports/contributors" => "reports#contributors"
resources :saved_searches, :only => [:index, :create, :destroy]
resources :saved_searches, :only => [:index, :create, :destroy] do
collection do
get :categories
end
end
resource :session do
collection do
get :sign_out