diff --git a/app/models/post_version.rb b/app/models/post_version.rb index 13fae86bf..701742d67 100644 --- a/app/models/post_version.rb +++ b/app/models/post_version.rb @@ -32,6 +32,13 @@ class PostVersion < ApplicationRecord end end + def tag_matches(string) + tag = string.split(/\S+/)[0] + return all if tag.nil? + tag = "*#{tag}*" unless tag =~ /\*/ + where_ilike(:tags, tag) + end + def search(params) q = super q = q.search_attributes(params, :updater_id, :post_id, :tags, :added_tags, :removed_tags, :rating, :rating_changed, :parent_id, :parent_changed, :source, :source_changed, :version) @@ -40,10 +47,20 @@ class PostVersion < ApplicationRecord q = q.changed_tags_include_all(params[:changed_tags].scan(/[^[:space:]]+/)) end + if params[:tag_matches] + q = q.tag_matches(params[:tag_matches]) + end + if params[:updater_name].present? q = q.where(updater_id: User.name_to_id(params[:updater_name])) end + if params[:is_new].to_s.truthy? + q = q.where(version: 1) + elsif params[:is_new].to_s.falsy? + q = q.where("version != 1") + end + q.apply_default_order(params) end end diff --git a/app/views/post_versions/search.html.erb b/app/views/post_versions/search.html.erb index 0413edc9b..926ed4ca9 100644 --- a/app/views/post_versions/search.html.erb +++ b/app/views/post_versions/search.html.erb @@ -12,7 +12,9 @@ <%= f.input :parent_id %> <%= f.input :rating %> <%= f.input :source_ilike, label: "Source", hint: "Use * for wildcard" %> + <%= f.input :tag_matches, hint: "Use * for wildcard" %> <%= f.input :version %> + <%= f.input :is_new, label: "Include uploads?", collection: [["Yes", nil], ["No", false], ["Only", true]], include_blank: false, hint: "I.e. the 1st versions of posts" %> <%= f.input :rating_changed, as: :select %> <%= f.input :parent_changed, as: :select %> <%= f.input :source_changed, as: :select %>