From d1188d8184053ccfe849147a9de408f996c7d324 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 25 Apr 2017 10:55:16 -0500 Subject: [PATCH 1/3] /artists: add search params: has_tag, name/other_names/group_name/any_name/url_matches. --- app/models/artist.rb | 29 ++++++++++++++++++++++++++++- test/unit/artist_test.rb | 17 +++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/models/artist.rb b/app/models/artist.rb index a123a64b7..5d760f10b 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -430,6 +430,26 @@ class Artist < ActiveRecord::Base q = q.any_name_matches(params[:name]) end + if params[:name_matches].present? + q = q.name_matches(params[:name_matches]) + end + + if params[:other_names_match].present? + q = q.other_names_match(params[:other_names_match]) + end + + if params[:group_name_matches].present? + q = q.group_name_matches(params[:group_name_matches]) + end + + if params[:any_name_matches].present? + q = q.any_name_matches(params[:any_name_matches]) + end + + if params[:url_matches].present? + q = q.url_matches(params[:url_matches]) + end + params[:order] ||= params.delete(:sort) case params[:order] when "name" @@ -466,8 +486,15 @@ class Artist < ActiveRecord::Base q = q.where("creator_id = ?", params[:creator_id].to_i) end + # XXX deprecated, remove at some point. if params[:empty_only] == "true" - q = q.joins(:tag).where("tags.post_count = 0") + params[:has_tag] = "false" + end + + if params[:has_tag] == "true" + q = q.joins(:tag).where("tags.post_count > 0") + elsif params[:has_tag] == "false" + q = q.includes(:tag).where("tags.name IS NULL OR tags.post_count <= 0").references(:tags) end q diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 799735c02..c2342544f 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -291,6 +291,8 @@ class ArtistTest < ActiveSupport::TestCase should "search on its name should return results" do artist = FactoryGirl.create(:artist, :name => "artist") assert_not_nil(Artist.search(:name => "artist").first) + assert_not_nil(Artist.search(:name_matches => "artist").first) + assert_not_nil(Artist.search(:any_name_matches => "artist").first) end should "search on other names should return matches" do @@ -300,6 +302,9 @@ class ArtistTest < ActiveSupport::TestCase assert_not_nil(Artist.other_names_match("ccc_ddd").first) assert_not_nil(Artist.search(:name => "other:aaa").first) assert_not_nil(Artist.search(:name => "aaa").first) + + assert_not_nil(Artist.search(:other_names_match => "aaa").first) + assert_not_nil(Artist.search(:any_name_matches => "aaa").first) end should "search on group name and return matches" do @@ -308,6 +313,18 @@ class ArtistTest < ActiveSupport::TestCase cat_or_fish.reload assert_equal("yuu", cat_or_fish.member_names) assert_not_nil(Artist.search(:name => "group:cat_or_fish").first) + + assert_not_nil(Artist.search(:group_name_matches => "cat_or_fish").first) + assert_not_nil(Artist.search(:any_name_matches => "cat_or_fish").first) + end + + should "search on has_tag and return matches" do + post = FactoryGirl.create(:post, tag_string: "bkub") + bkub = FactoryGirl.create(:artist, name: "bkub") + none = FactoryGirl.create(:artist, name: "none") + + assert_equal(bkub.id, Artist.search(has_tag: "true").first.id) + assert_equal(none.id, Artist.search(has_tag: "false").first.id) end should "revert to prior versions" do From b61fdc2c6bce3caa544157ab36afed30236f9ee2 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 26 Apr 2017 13:12:20 -0500 Subject: [PATCH 2/3] /artists: convert search form to simple form. --- app/views/artists/_search.html.erb | 33 +++++------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/app/views/artists/_search.html.erb b/app/views/artists/_search.html.erb index 3c256ff8d..cf6a77ed3 100644 --- a/app/views/artists/_search.html.erb +++ b/app/views/artists/_search.html.erb @@ -1,28 +1,5 @@ - - - <%= form_tag(artists_path, :method => :get, :class => "simple_form") do %> - - - - - - - - - - - - <% end %> - - +<%= simple_form_for(:search, url: artists_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %> + <%= f.input :name, label: "Name", hint: "Use * for wildcard", input_html: { value: params[:search][:name] } %> + <%= f.input :order, collection: [["Recently created", "created_at"], ["Last updated", "updated_at"], ["Name", "name"], ["Post count", "post_count"]], selected: params[:search][:order] %> + <%= f.submit "Search" %> +<% end %> From ec895d6412510d5cbb4e07fce4b8e4934be63f05 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 26 Apr 2017 13:15:26 -0500 Subject: [PATCH 3/3] /artists: add URL/Creator/Active/Banned/Has Tag fields to search form. --- app/views/artists/_search.html.erb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/views/artists/_search.html.erb b/app/views/artists/_search.html.erb index cf6a77ed3..17eb78526 100644 --- a/app/views/artists/_search.html.erb +++ b/app/views/artists/_search.html.erb @@ -1,5 +1,10 @@ <%= simple_form_for(:search, url: artists_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %> <%= f.input :name, label: "Name", hint: "Use * for wildcard", input_html: { value: params[:search][:name] } %> + <%= f.input :url_matches, label: "URL", as: "string", input_html: { value: params[:search][:url_matches] } %> + <%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name] } %> + <%= f.input :is_active, label: "Active?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:is_active] %> + <%= f.input :is_banned, label: "Banned?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:is_banned] %> + <%= f.input :has_tag, label: "Has tag?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:has_tag] %> <%= f.input :order, collection: [["Recently created", "created_at"], ["Last updated", "updated_at"], ["Name", "name"], ["Post count", "post_count"]], selected: params[:search][:order] %> <%= f.submit "Search" %> <% end %>