Merge branch 'master' of github.com:r888888888/danbooru
This commit is contained in:
@@ -523,16 +523,12 @@
|
|||||||
|
|
||||||
Danbooru.Post.initialize_saved_searches = function() {
|
Danbooru.Post.initialize_saved_searches = function() {
|
||||||
$("#save-search").click(function() {
|
$("#save-search").click(function() {
|
||||||
var input = window.prompt("Category for this saved search (optional):");
|
$.post(
|
||||||
if (input !== null) {
|
"/saved_searches.js",
|
||||||
$.post(
|
{
|
||||||
"/saved_searches.js",
|
"tags": $("#tags").attr("value")
|
||||||
{
|
}
|
||||||
"tags": $("#tags").attr("value"),
|
);
|
||||||
"category": input
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
class SavedSearchesController < ApplicationController
|
class SavedSearchesController < ApplicationController
|
||||||
|
before_filter :member_only
|
||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
SavedSearch.delay(:queue => "default").refresh_listbooru(CurrentUser.id)
|
||||||
|
|
||||||
@saved_searches = saved_searches.order("tag_query")
|
@saved_searches = saved_searches.order("tag_query")
|
||||||
@categories = @saved_searches.group_by{|saved_search| saved_search.category.to_s}
|
@categories = @saved_searches.group_by{|saved_search| saved_search.category.to_s}
|
||||||
@categories = @categories.sort_by{|category, saved_searches| category.to_s}
|
@categories = @categories.sort_by{|category, saved_searches| category.to_s}
|
||||||
@@ -22,17 +25,6 @@ class SavedSearchesController < ApplicationController
|
|||||||
@saved_search.destroy
|
@saved_search.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
|
||||||
@saved_search = saved_searches.find(params[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
@saved_search = saved_searches.find(params[:id])
|
|
||||||
@saved_search.update_attributes(params[:saved_search])
|
|
||||||
flash[:notice] = "Saved search updated"
|
|
||||||
respond_with(@saved_search, :location => saved_searches_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def saved_searches
|
def saved_searches
|
||||||
|
|||||||
@@ -1,11 +1,51 @@
|
|||||||
class SavedSearch < ActiveRecord::Base
|
class SavedSearch < ActiveRecord::Base
|
||||||
|
module ListbooruMethods
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
module ClassMethods
|
||||||
|
def refresh_listbooru(user_id)
|
||||||
|
return unless Danbooru.config.listbooru_auth_key
|
||||||
|
uri = URI.parse("#{Danbooru.config.listbooru_server}/users/#{user_id}")
|
||||||
|
Net::HTTP.get_response(uri)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_listbooru_on_create(user_id, query)
|
||||||
|
return unless Danbooru.config.listbooru_auth_key
|
||||||
|
uri = URI.parse("#{Danbooru.config.listbooru_server}/searches")
|
||||||
|
Net::HTTP.post_form(uri, {"user_id" => user_id, "query" => query, "key" => Danbooru.config.listbooru_auth_key})
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_listbooru_on_destroy(user_id, query)
|
||||||
|
return unless Danbooru.config.listbooru_auth_key
|
||||||
|
uri = URI.parse("#{Danbooru.config.listbooru_server}/searches")
|
||||||
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
||||||
|
req = Net::HTTP::Delete.new("/searches")
|
||||||
|
req.set_form_data("user_id" => user_id, "query" => query, "key" => Danbooru.config.listbooru_auth_key)
|
||||||
|
http.request(req)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_listbooru_on_create
|
||||||
|
return unless Danbooru.config.listbooru_auth_key
|
||||||
|
SavedSearch.delay(:queue => "default").update_listbooru_on_create(user_id, tag_query)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_listbooru_on_destroy
|
||||||
|
return unless Danbooru.config.listbooru_auth_key
|
||||||
|
SavedSearch.delay(:queue => "default").update_listbooru_on_destroy(user_id, tag_query)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
include ListbooruMethods
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
validates :tag_query, :presence => true
|
validates :tag_query, :presence => true
|
||||||
validate :validate_count
|
validate :validate_count
|
||||||
attr_accessible :tag_query, :category
|
attr_accessible :tag_query, :category
|
||||||
before_create :update_user_on_create
|
before_create :update_user_on_create
|
||||||
after_destroy :update_user_on_destroy
|
after_destroy :update_user_on_destroy
|
||||||
before_create :update_listbooru_on_create
|
after_create :update_listbooru_on_create
|
||||||
after_destroy :update_listbooru_on_destroy
|
after_destroy :update_listbooru_on_destroy
|
||||||
validates_uniqueness_of :tag_query, :scope => :user_id
|
validates_uniqueness_of :tag_query, :scope => :user_id
|
||||||
before_validation :normalize
|
before_validation :normalize
|
||||||
@@ -40,18 +80,4 @@ class SavedSearch < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_listbooru_on_create
|
|
||||||
return unless Danbooru.config.listbooru_auth_key
|
|
||||||
Net::HTTP.post_form(Danbooru.config.listbooru_server, {"user_id" => user_id, "query" => tag_query, "key" => Danbooru.config.listbooru_auth_key, "name" => "saved"})
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_listbooru_on_destroy
|
|
||||||
return unless Danbooru.config.listbooru_auth_key
|
|
||||||
uri = URI.parse(Danbooru.config.listbooru_server)
|
|
||||||
Net::HTTP.start(uri.host, uri.port) do |http|
|
|
||||||
req = Net::HTTP::Delete.new("/searches")
|
|
||||||
req.set_form_data("user_id" => user_id, "query" => tag_query, "key" => Danbooru.config.listbooru_auth_key, "name" => "saved")
|
|
||||||
http.request(req)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ class TagSubscription < ActiveRecord::Base
|
|||||||
before_validation :initialize_post_ids, :on => :create
|
before_validation :initialize_post_ids, :on => :create
|
||||||
before_save :normalize_name
|
before_save :normalize_name
|
||||||
before_save :limit_tag_count
|
before_save :limit_tag_count
|
||||||
before_create :update_listbooru_on_create
|
|
||||||
before_update :update_listbooru_on_update
|
|
||||||
after_destroy :update_listbooru_on_destroy
|
|
||||||
attr_accessible :name, :tag_query, :post_ids, :is_public, :is_visible_on_profile
|
attr_accessible :name, :tag_query, :post_ids, :is_public, :is_visible_on_profile
|
||||||
validates_presence_of :name, :tag_query, :creator_id
|
validates_presence_of :name, :tag_query, :creator_id
|
||||||
validate :validate_number_of_queries
|
validate :validate_number_of_queries
|
||||||
@@ -78,26 +75,6 @@ class TagSubscription < ActiveRecord::Base
|
|||||||
post_ids.split(/,/)
|
post_ids.split(/,/)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_listbooru_on_create
|
|
||||||
return unless Danbooru.config.listbooru_auth_key
|
|
||||||
Net::HTTP.post_form(Danbooru.config.listbooru_server, {"user_id" => user_id, "query" => tag_query, "name" => "sub:#{id}", "key" => Danbooru.config.listbooru_auth_key})
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_listbooru_on_update
|
|
||||||
update_listbooru_on_destroy
|
|
||||||
update_listbooru_on_create
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_listbooru_on_destroy
|
|
||||||
return unless Danbooru.config.listbooru_auth_key
|
|
||||||
uri = URI.parse(Danbooru.config.listbooru_server)
|
|
||||||
Net::HTTP.start(uri.host, uri.port) do |http|
|
|
||||||
req = Net::HTTP::Delete.new("/searches")
|
|
||||||
req.set_form_data("user_id" => user_id, "query" => tag_query, "key" => Danbooru.config.listbooru_auth_key, "name" => "sub:#{id}")
|
|
||||||
http.request(req)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def visible_to(user)
|
def visible_to(user)
|
||||||
where("(is_public = TRUE OR creator_id = ? OR ?)", user.id, user.is_moderator?)
|
where("(is_public = TRUE OR creator_id = ? OR ?)", user.id, user.is_moderator?)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title><%= yield :page_title %></title>
|
<title><%= yield :page_title %></title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||||
<link rel="top" title="<%= Danbooru.config.app_name %>" href="/">
|
<link rel="top" title="<%= Danbooru.config.app_name %>" href="/">
|
||||||
<%= csrf_meta_tag %>
|
<%= csrf_meta_tag %>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html xmlns:fb="http://ogp.me/ns/fb#">
|
<html xmlns:fb="http://ogp.me/ns/fb#">
|
||||||
<head>
|
<head>
|
||||||
<title><%= yield :page_title %></title>
|
<title><%= yield :page_title %></title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||||
<link rel="top" title="<%= Danbooru.config.app_name %>" href="/">
|
<link rel="top" title="<%= Danbooru.config.app_name %>" href="/">
|
||||||
<%= csrf_meta_tag %>
|
<%= csrf_meta_tag %>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title><%= yield :page_title %></title>
|
<title><%= yield :page_title %></title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||||
<%= csrf_meta_tag %>
|
<%= csrf_meta_tag %>
|
||||||
<%= stylesheet_link_tag "mobile", :media => "screen" %>
|
<%= stylesheet_link_tag "mobile", :media => "screen" %>
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
<tr id="saved-search-<%= saved_search.id %>">
|
<tr id="saved-search-<%= saved_search.id %>">
|
||||||
<td><%= link_to saved_search.tag_query, posts_path(:tags => saved_search.tag_query) %></td>
|
<td><%= link_to saved_search.tag_query, posts_path(:tags => saved_search.tag_query) %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to "edit", edit_saved_search_path(saved_search) %> |
|
|
||||||
<%= link_to "delete", saved_search_path(saved_search), :method => :delete, :remote => true %>
|
<%= link_to "delete", saved_search_path(saved_search), :method => :delete, :remote => true %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ Rails.application.routes.draw do
|
|||||||
get "reports/user_promotions" => "reports#user_promotions"
|
get "reports/user_promotions" => "reports#user_promotions"
|
||||||
get "reports/janitor_trials" => "reports#janitor_trials"
|
get "reports/janitor_trials" => "reports#janitor_trials"
|
||||||
get "reports/contributors" => "reports#contributors"
|
get "reports/contributors" => "reports#contributors"
|
||||||
resources :saved_searches
|
resources :saved_searches, :only => [:index, :create, :destroy]
|
||||||
resource :session do
|
resource :session do
|
||||||
collection do
|
collection do
|
||||||
get :sign_out
|
get :sign_out
|
||||||
|
|||||||
Reference in New Issue
Block a user