diff --git a/app/models/artist_commentary.rb b/app/models/artist_commentary.rb
index 8c4cbfd33..783a5d757 100644
--- a/app/models/artist_commentary.rb
+++ b/app/models/artist_commentary.rb
@@ -56,10 +56,26 @@ class ArtistCommentary < ApplicationRecord
q = q.where("(translated_title = '') and (translated_description = '')")
end
- q = q.deleted if params[:is_deleted] == "yes"
- q = q.undeleted if params[:is_deleted] == "no"
+ if params[:is_deleted].to_s.truthy?
+ q = q.deleted
+ elsif params[:is_deleted].to_s.falsy?
+ q = q.undeleted
+ end
- q.apply_default_order(params)
+ case params[:order]
+ when "id_asc"
+ q = q.order(id: :asc)
+ when "post_id", "post_id_desc"
+ q = q.order(post_id: :desc)
+ when "post_id_asc"
+ q = q.order(post_id: :asc)
+ when "updated_at", "updated_at_desc"
+ q = q.order(updated_at: :desc, id: :desc)
+ when "updated_at_asc"
+ q = q.order(updated_at: :asc, id: :asc)
+ else
+ q = q.apply_default_order(params)
+ end
end
end
diff --git a/app/views/artist_commentaries/_secondary_links.html.erb b/app/views/artist_commentaries/_secondary_links.html.erb
index fe6c95385..d787883a6 100644
--- a/app/views/artist_commentaries/_secondary_links.html.erb
+++ b/app/views/artist_commentaries/_secondary_links.html.erb
@@ -1,6 +1,5 @@
<% content_for(:secondary_links) do %>
<%= quick_search_form_for(:text_matches, artist_commentaries_path, "commentaries") %>
- <%= subnav_link_to "Search", search_artist_commentaries_path %>
<%= subnav_link_to "Listing", artist_commentaries_path %>
<%= subnav_link_to "Recent changes", artist_commentary_versions_path %>
<%= subnav_link_to "Translation requests", artist_commentaries_path(:search => {:post_tags_match => "commentary_request"}) %>
diff --git a/app/views/artist_commentaries/index.html.erb b/app/views/artist_commentaries/index.html.erb
index 2d88e6688..faf3581cc 100644
--- a/app/views/artist_commentaries/index.html.erb
+++ b/app/views/artist_commentaries/index.html.erb
@@ -2,6 +2,16 @@
Artist Commentary
+ <%= search_form_for(artist_commentaries_path) do |f| %>
+ <%= f.input :text_matches, label: "Text", input_html: { value: params[:search][:text_matches] } %>
+ <%= f.input :post_tags_match, label: "Tags", input_html: { data: { autocomplete: "tag-query" }, value: params[:search][:post_tags_match] } %>
+ <%= f.input :original_present, label: "Original?", collection: ["Yes", "No"], include_blank: true, selected: params[:search][:original_present] %>
+ <%= f.input :translated_present, label: "Translated?", collection: ["Yes", "No"], include_blank: true, selected: params[:search][:translated_present] %>
+ <%= f.input :is_deleted, label: "Deleted?", collection: ["Yes", "No"], include_blank: true, selected: params[:search][:is_deleted] %>
+ <%= f.input :order, collection: [%w[Newest id], %w[Oldest id_asc], %w[Updated updated_at_desc], %w[Uploaded post_id_desc]], include_blank: true, selected: params[:search][:order] %>
+ <%= f.submit "Search" %>
+ <% end %>
+
<%= render "posts/partials/common/inline_blacklist" %>
<%= table_for @commentaries, width: "100%" do |t| %>
diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb
index d2c16e226..bb7df4078 100644
--- a/app/views/static/site_map.html.erb
+++ b/app/views/static/site_map.html.erb
@@ -108,7 +108,6 @@
Artist commentary
<%= link_to_wiki "Help", "help:artist_commentary" %>
<%= link_to("Listing", artist_commentaries_path) %>
- <%= link_to("Search", search_artist_commentaries_path) %>
<%= link_to("Changes", artist_commentary_versions_path) %>
diff --git a/config/routes.rb b/config/routes.rb
index 72a34327a..64315395c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -227,7 +227,6 @@ Rails.application.routes.draw do
resources :artist_commentaries, :only => [:index, :show] do
collection do
put :create_or_update
- get :search
end
member do
put :revert
diff --git a/test/functional/artist_commentaries_controller_test.rb b/test/functional/artist_commentaries_controller_test.rb
index 9698a00bd..2de603418 100644
--- a/test/functional/artist_commentaries_controller_test.rb
+++ b/test/functional/artist_commentaries_controller_test.rb
@@ -25,6 +25,7 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest
should respond_to_search(original_present: "true").with { [@other_commentary, @commentary] }
should respond_to_search(translated_present: "true").with { @commentary }
should respond_to_search(is_deleted: "yes").with { @deleted_commentary }
+ should respond_to_search(order: "id_asc").with { [@commentary, @other_commentary, @deleted_commentary] }
context "using includes" do
should respond_to_search(post_id: 999).with { @commentary }