mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 18:59:38 +02:00
Add pattern matching for domain name field in search #2122
This commit is contained in:
parent
31d19ff64e
commit
4b9e082712
3 changed files with 12 additions and 3 deletions
|
@ -15,6 +15,16 @@ class Admin::DomainsController < AdminController
|
|||
normalize_search_parameters do
|
||||
@q = domains.search(params[:q])
|
||||
@domains = @q.result.page(params[:page])
|
||||
if @domains.count == 1
|
||||
redirect_to [:admin, @domains.first] and return
|
||||
elsif @domains.count == 0 && params[:q][:name_matches] !~ /^%.+%$/
|
||||
# if we do not get any results, add wildcards to the name field and search again
|
||||
n_cache = params[:q][:name_matches]
|
||||
params[:q][:name_matches] = "%#{params[:q][:name_matches]}%"
|
||||
@q = domains.search(params[:q])
|
||||
@domains = @q.result.page(params[:page])
|
||||
params[:q][:name_matches] = n_cache # we don't want to show wildcards in search form
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
# TODO: whois requests ip whitelist for full info for own domains and partial info for other domains
|
||||
# TODO: most inputs should be trimmed before validatation, probably some global logic?
|
||||
paginates_per 10 # just for showoff
|
||||
|
||||
belongs_to :registrar
|
||||
belongs_to :registrant
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
.row
|
||||
.col-md-12
|
||||
= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form' } do |f|
|
||||
= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f|
|
||||
.row
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label :name
|
||||
= f.search_field :name_cont, class: 'form-control', placeholder: t(:name)
|
||||
= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:registrant_ident)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue