mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 19:48:28 +02:00
Add proper domains search to registrar #2122
This commit is contained in:
parent
c527a4e55a
commit
3a3a696035
8 changed files with 721 additions and 42 deletions
|
@ -2,21 +2,41 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
|
|||
before_action :init_domain, except: :new
|
||||
before_action :init_contacts_autocomplete_map, only: [:new, :edit, :create, :update]
|
||||
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
# rubocop: disable Metrics/AbcSize
|
||||
def index
|
||||
authorize! :view, Depp::Domain
|
||||
limit, offset = pagination_details
|
||||
|
||||
res = depp_current_user.repp_request('domains', { details: true, limit: limit, offset: offset })
|
||||
if res.code == '200'
|
||||
@response = res.parsed_body.with_indifferent_access
|
||||
@contacts = @response ? @response[:contacts] : []
|
||||
|
||||
@paginatable_array = Kaminari.paginate_array(
|
||||
[], total_count: @response[:total_number_of_records]
|
||||
).page(params[:page]).per(limit)
|
||||
params[:q] ||= {}
|
||||
if params[:statuses_contains]
|
||||
domains = current_user.registrar.domains.includes(:registrar, :registrant).where(
|
||||
"statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
||||
)
|
||||
else
|
||||
domains = current_user.registrar.domains.includes(:registrar, :registrant)
|
||||
end
|
||||
flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }]
|
||||
|
||||
normalize_search_parameters do
|
||||
@q = domains.search(params[:q])
|
||||
@domains = @q.result.page(params[:page])
|
||||
if @domains.count == 1 && params[:q][:name_matches].present?
|
||||
redirect_to info_registrar_domains_path(domain_name: @domains.first.name) 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
|
||||
|
||||
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
# rubocop: enable Metrics/AbcSize
|
||||
|
||||
def info
|
||||
authorize! :view, Depp::Domain
|
||||
|
@ -123,4 +143,18 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
|
|||
# @priv_contacts_autocomplete_map ||=
|
||||
# current_user.registrar.priv_contacts.pluck(:name, :code).map { |c| ["#{c.second} #{c.first}", c.second] }
|
||||
end
|
||||
|
||||
def normalize_search_parameters
|
||||
ca_cache = params[:q][:valid_to_lteq]
|
||||
begin
|
||||
end_time = params[:q][:valid_to_lteq].try(:to_date)
|
||||
params[:q][:valid_to_lteq] = end_time.try(:end_of_day)
|
||||
rescue
|
||||
logger.warn('Invalid date')
|
||||
end
|
||||
|
||||
yield
|
||||
|
||||
params[:q][:valid_to_lteq] = ca_cache
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,42 +7,89 @@
|
|||
= render 'shared/title', name: t(:domains)
|
||||
|
||||
.row
|
||||
.col-md-12{style: 'margin-bottom: -15px;'}
|
||||
= form_tag info_registrar_domains_path, class: 'form-horizontal', method: :get do
|
||||
.col-md-11
|
||||
.form-group
|
||||
= text_field_tag :domain_name, params[:domain_name], class: 'form-control', placeholder: t(:domain_name), autocomplete: 'off', autofocus: true
|
||||
.col-md-1.text-right.text-center-xs
|
||||
.form-group
|
||||
%button.btn.btn-default
|
||||
.col-md-12
|
||||
= search_form_for [:registrar, @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_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:registrant_ident)
|
||||
= f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:contact_ident)
|
||||
= f.search_field :contacts_ident_eq, class: 'form-control', placeholder: t(:contact_ident)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:nameserver_hostname)
|
||||
= f.search_field :nameservers_hostname_eq, class: 'form-control', placeholder: t(:nameserver_hostname)
|
||||
.row
|
||||
.col-md-6
|
||||
.form-group
|
||||
= label_tag t(:status)
|
||||
= select_tag :statuses_contains, options_for_select(DomainStatus::STATUSES, params[:statuses_contains]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' }
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:valid_to_from)
|
||||
= f.search_field :valid_to_gteq, value: params[:q][:valid_to_gteq], class: 'form-control datepicker', placeholder: t(:valid_to_from)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:valid_to_until)
|
||||
= f.search_field :valid_to_lteq, value: params[:q][:valid_to_lteq], class: 'form-control datepicker', placeholder: t(:valid_to_until)
|
||||
.row
|
||||
.col-md-6
|
||||
.col-md-3
|
||||
.form-group
|
||||
= label_tag t(:results_per_page)
|
||||
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
|
||||
.col-md-3{style: 'padding-top: 25px;'}
|
||||
%button.btn.btn-primary.search
|
||||
|
||||
%span.glyphicon.glyphicon-search
|
||||
|
||||
|
||||
%button.btn.btn-default.js-reset-form
|
||||
= t(:clear_fields)
|
||||
%hr
|
||||
|
||||
- if @response
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-3'}= t(:name)
|
||||
%th{class: 'col-xs-6'}= t(:valid)
|
||||
%th{class: 'col-xs-3'}= t(:actions)
|
||||
%tbody
|
||||
- @response['domains'].each do |x|
|
||||
.row
|
||||
.col-md-12
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%td= link_to(x['name'], info_registrar_domains_path(domain_name: x['name']))
|
||||
%td
|
||||
= Time.zone.parse(x['valid_from']).try(:to_date)
|
||||
\-
|
||||
= Time.zone.parse(x['valid_to']).try(:to_date)
|
||||
%td
|
||||
= link_to(t(:edit), edit_registrar_domains_path(domain_name: x['name']),
|
||||
class: 'btn btn-primary btn-xs')
|
||||
= link_to(t(:renew), renew_registrar_domains_path(domain_name: x['name']),
|
||||
class: 'btn btn-default btn-xs')
|
||||
= link_to(t(:delete), delete_registrar_domains_path(domain_name: x['name']),
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'name')
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'registrant_name', t(:registrant))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'valid_to', t(:valid_to))
|
||||
%th{class: 'col-xs-2'}= t('actions')
|
||||
%tbody
|
||||
- @domains.each do |x|
|
||||
%tr
|
||||
%td= link_to(x, info_registrar_domains_path(domain_name: x.name))
|
||||
%td
|
||||
- if x.registrant
|
||||
= link_to(x.registrant, registrar_contact_path(id: x.registrant.code))
|
||||
%td= l(x.valid_to, format: :date_long)
|
||||
%td
|
||||
= link_to(t(:edit), edit_registrar_domains_path(domain_name: x.name),
|
||||
class: 'btn btn-primary btn-xs')
|
||||
= link_to(t(:renew), renew_registrar_domains_path(domain_name: x.name),
|
||||
class: 'btn btn-default btn-xs')
|
||||
= link_to(t(:delete), delete_registrar_domains_path(domain_name: x.name),
|
||||
class: 'btn btn-default btn-xs')
|
||||
.row
|
||||
.col-md-6
|
||||
= paginate @domains
|
||||
.col-md-6.text-right
|
||||
.pagination
|
||||
= t(:result_count, count: @domains.total_count)
|
||||
|
||||
= paginate @paginatable_array
|
||||
:coffee
|
||||
$(".js-reset-form").on "click", (e) ->
|
||||
e.preventDefault();
|
||||
window.location = "#{registrar_domains_path}"
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
|||
(function(){$(document).on("page:change",function(){return $(".selectize").selectize({allowEmptyOption:!0}),$("form").each(function(){return $(this).validate()}),$(".js-contact-form").on("restoreDefault",function(t){var e;switch(e=$(t.target),e.find(".js-ident-tip").hide(),$(".js-ident-country-code option:selected").val()){case"EE":return $(".js-ident-type").find("option[value=birthday]").prop("disabled",!0);default:return $(".js-ident-type").find("option[value=birthday]").prop("disabled",!1)}}),$(".js-ident-country-code").change(function(){var t;return t=$(".js-contact-form"),t.trigger("restoreDefault")}),$(".js-ident-type").change(function(t){var e;switch(e=$(".js-contact-form"),e.trigger("restoreDefault"),t.target.value){case"birthday":return e.find(".js-ident-tip").show()}}),$(".js-contact-form").trigger("restoreDefault")})}).call(this);
|
|
@ -54,6 +54,47 @@ feature 'Domains', type: :feature do
|
|||
|
||||
page.should_not have_text(d1.name)
|
||||
page.should have_text(d2.name)
|
||||
|
||||
end
|
||||
|
||||
it 'should search domains' do
|
||||
# having shared state across tests is really annoying sometimes...
|
||||
click_link "#{@user} (#{@user.roles.first}) - #{@user.registrar}"
|
||||
|
||||
Fabricate(:domain, name: 'abcde.ee', registrar: @user.registrar)
|
||||
Fabricate(:domain, name: 'abcdee.ee', registrar: @user.registrar)
|
||||
Fabricate(:domain, name: 'defgh.pri.ee', registrar: @user.registrar)
|
||||
|
||||
visit '/registrar/domains'
|
||||
click_link 'Domains'
|
||||
|
||||
page.should have_content('abcde.ee')
|
||||
page.should have_content('abcdee.ee')
|
||||
page.should have_content('defgh.pri.ee')
|
||||
|
||||
fill_in 'q_name_matches', with: 'abcde.ee'
|
||||
find('.btn.btn-primary.search').click
|
||||
|
||||
current_path.should == "/registrar/domains/info"
|
||||
|
||||
visit '/registrar/domains'
|
||||
fill_in 'q_name_matches', with: '.ee'
|
||||
find('.btn.btn-primary.search').click
|
||||
|
||||
current_path.should == "/registrar/domains"
|
||||
page.should have_content('abcde.ee')
|
||||
page.should have_content('abcdee.ee')
|
||||
page.should have_content('defgh.pri.ee')
|
||||
|
||||
fill_in 'q_name_matches', with: 'abcd%.ee'
|
||||
find('.btn.btn-primary.search').click
|
||||
page.should have_content('abcde.ee')
|
||||
page.should have_content('abcdee.ee')
|
||||
page.should_not have_content('defgh.pri.ee')
|
||||
|
||||
fill_in 'q_name_matches', with: 'abcd_.ee'
|
||||
find('.btn.btn-primary.search').click
|
||||
current_path.should == "/registrar/domains/info"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue