add saved search category change ui
This commit is contained in:
14
app/controllers/saved_search_category_changes_controller.rb
Normal file
14
app/controllers/saved_search_category_changes_controller.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class SavedSearchCategoryChangesController < ApplicationController
|
||||
before_filter :member_only
|
||||
respond_to :html
|
||||
|
||||
def new
|
||||
@category = params[:old]
|
||||
end
|
||||
|
||||
def create
|
||||
SavedSearch.rename(CurrentUser.user.id, params[:old], params[:new])
|
||||
flash[:notice] = "Saved searches will be renamed"
|
||||
redirect_to saved_searches_path
|
||||
end
|
||||
end
|
||||
@@ -30,6 +30,15 @@ class SavedSearch < ActiveRecord::Base
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def rename_listbooru(user_id, old_category, new_category)
|
||||
return false unless Danbooru.config.listbooru_enabled?
|
||||
|
||||
sqs = SqsService.new(Danbooru.config.aws_sqs_queue_url)
|
||||
sqs.send_message("rename\n#{user_id}\n#{old_category}\n#{new_category}\n")
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def update_listbooru_on_create
|
||||
@@ -71,13 +80,25 @@ class SavedSearch < ActiveRecord::Base
|
||||
before_validation :normalize
|
||||
|
||||
def self.tagged(tags)
|
||||
where(:tag_query => SavedSearch.normalize(tags)).first
|
||||
where(:tag_query => normalize(tags)).first
|
||||
end
|
||||
|
||||
def self.normalize(tag_query)
|
||||
Tag.scan_query(tag_query).join(" ")
|
||||
end
|
||||
|
||||
def self.normalize_category(category)
|
||||
category.to_s.strip.gsub(/\s+/, "_").downcase
|
||||
end
|
||||
|
||||
def self.rename(user_id, old_category, new_category)
|
||||
user = User.find(user_id)
|
||||
old_category = normalize_category(old_category)
|
||||
new_category = normalize_category(new_category)
|
||||
user.saved_searches.where(category: old_category).update_all(category: new_category)
|
||||
rename_listbooru(user_id, old_category, new_category)
|
||||
end
|
||||
|
||||
def self.post_ids(user_id, name = nil)
|
||||
return [] unless Danbooru.config.listbooru_enabled?
|
||||
|
||||
@@ -110,7 +131,7 @@ class SavedSearch < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def normalize
|
||||
self.category = category.strip.gsub(/\s+/, "_").downcase if category
|
||||
self.category = SavedSearch.normalize_category(category) if category
|
||||
self.tag_query = SavedSearch.normalize(tag_query)
|
||||
end
|
||||
|
||||
|
||||
25
app/views/saved_search_category_changes/new.html.erb
Normal file
25
app/views/saved_search_category_changes/new.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<div id="c-saved-searches">
|
||||
<div id="a-edit">
|
||||
<h1>Change Category</h1>
|
||||
|
||||
<%= form_tag(saved_search_category_change_path, :class => "simple_form") do %>
|
||||
<div class="input">
|
||||
<label for="old">Old Category</label>
|
||||
<%= text_field_tag "old", params[:old] %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<label for="new">New Category</label>
|
||||
<%= text_field_tag "new" %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "saved_searches/secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Edit Category - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
@@ -6,6 +6,7 @@
|
||||
<h2>
|
||||
<% if category.present? %>
|
||||
<%= 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") %>
|
||||
<% end %>
|
||||
@@ -13,8 +14,8 @@
|
||||
<table class="striped" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="90%">Tags</th>
|
||||
<th width="10%"></th>
|
||||
<th width="80%">Tags</th>
|
||||
<th width="20%"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
|
||||
@@ -236,6 +236,7 @@ Rails.application.routes.draw do
|
||||
get :categories
|
||||
end
|
||||
end
|
||||
resource :saved_search_category_change, :only => [:new, :create]
|
||||
resource :session do
|
||||
collection do
|
||||
get :sign_out
|
||||
|
||||
Reference in New Issue
Block a user