mirror of
https://github.com/internetee/registry.git
synced 2025-08-13 04:59:42 +02:00
refactoring: deligious return domain wich related to registrar function in concern
This commit is contained in:
parent
fee6b897af
commit
13650ae37e
2 changed files with 25 additions and 20 deletions
|
@ -1,19 +1,21 @@
|
||||||
module Admin
|
module Admin
|
||||||
class DomainsController < BaseController
|
class DomainsController < BaseController
|
||||||
|
include AdminDomains
|
||||||
before_action :set_domain, only: %i[show edit update keep]
|
before_action :set_domain, only: %i[show edit update keep]
|
||||||
authorize_resource
|
authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
params[:q] ||= {}
|
params[:q] ||= {}
|
||||||
domains = if params[:statuses_contains]
|
if params[:statuses_contains]
|
||||||
Domain.includes(:registrar, :registrant).where(
|
domains = Domain.includes(:registrar, :registrant).where(
|
||||||
'domains.statuses @> ?::varchar[]', "{#{params[:statuses_contains].join(',')}}"
|
"domains.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
Domain.includes(:registrar, :registrant)
|
domains = Domain.includes(:registrar, :registrant)
|
||||||
end
|
end
|
||||||
|
|
||||||
domains = get_domains_which_related_to_registrars
|
domains = return_domains_which_related_to_registrars
|
||||||
|
|
||||||
|
|
||||||
normalize_search_parameters do
|
normalize_search_parameters do
|
||||||
@q = domains.search(params[:q])
|
@q = domains.search(params[:q])
|
||||||
|
@ -61,7 +63,7 @@ module Admin
|
||||||
redirect_to [:admin, @domain]
|
redirect_to [:admin, @domain]
|
||||||
else
|
else
|
||||||
build_associations
|
build_associations
|
||||||
flash.now[:alert] = I18n.t('failed_to_update_domain') + ' ' + @domain.errors.full_messages.join(', ')
|
flash.now[:alert] = I18n.t('failed_to_update_domain') + ' ' + @domain.errors.full_messages.join(", ")
|
||||||
render 'edit'
|
render 'edit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -107,7 +109,7 @@ module Admin
|
||||||
begin
|
begin
|
||||||
end_time = params[:q][:valid_to_lteq].try(:to_date)
|
end_time = params[:q][:valid_to_lteq].try(:to_date)
|
||||||
params[:q][:valid_to_lteq] = end_time.try(:end_of_day)
|
params[:q][:valid_to_lteq] = end_time.try(:end_of_day)
|
||||||
rescue StandardError
|
rescue
|
||||||
logger.warn('Invalid date')
|
logger.warn('Invalid date')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -115,15 +117,5 @@ module Admin
|
||||||
|
|
||||||
params[:q][:valid_to_lteq] = ca_cache
|
params[:q][:valid_to_lteq] = ca_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_domains_which_related_to_registrars
|
|
||||||
if params[:registrar_id_eq]
|
|
||||||
Domain.includes(:registrar, :registrant).where(
|
|
||||||
registrar: params[:registrar_id_eq]
|
|
||||||
)
|
|
||||||
else
|
|
||||||
Domain.includes(:registrar, :registrant)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
13
app/controllers/concerns/admin_domains.rb
Normal file
13
app/controllers/concerns/admin_domains.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
module AdminDomains
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
def return_domains_which_related_to_registrars
|
||||||
|
if params[:registrar_id_eq]
|
||||||
|
domains = Domain.includes(:registrar, :registrant).where(
|
||||||
|
registrar: params[:registrar_id_eq]
|
||||||
|
)
|
||||||
|
else
|
||||||
|
domains = Domain.includes(:registrar, :registrant)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue