mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 19:48:28 +02:00
Refactor and view improvement
This commit is contained in:
parent
1f2ba55acb
commit
03a66e2e68
5 changed files with 47 additions and 34 deletions
|
@ -2,27 +2,29 @@ class Registrar::NameserversController < RegistrarController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
nameservers = current_user.registrar.nameservers
|
if can_replace_hostnames?
|
||||||
|
res = Nameserver.replace_hostname_ends(
|
||||||
|
current_user.registrar.domains.includes(
|
||||||
|
:registrant, :nameservers, :admin_domain_contacts, :tech_domain_contacts, :domain_statuses,
|
||||||
|
:versions, :admin_contacts, :tech_contacts, :whois_record, :dnskeys
|
||||||
|
),
|
||||||
|
params[:q][:hostname_end],
|
||||||
|
params[:hostname_end_replacement]
|
||||||
|
)
|
||||||
|
|
||||||
|
if res
|
||||||
|
params[:q][:hostname_end] = params[:hostname_end_replacement]
|
||||||
|
params[:hostname_end_replacement] = nil
|
||||||
|
flash.now[:notice] = t('all_hostnames_replaced')
|
||||||
|
else
|
||||||
|
flash.now[:warning] = t('hostnames_partially_replaced')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
nameservers = current_user.registrar.nameservers.includes(:domain)
|
||||||
@q = nameservers.search(params[:q])
|
@q = nameservers.search(params[:q])
|
||||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||||
@nameservers = @q.result.page(params[:page])
|
@nameservers = @q.result.page(params[:page])
|
||||||
|
|
||||||
return unless can_replace_hostnames?
|
|
||||||
|
|
||||||
res = Nameserver.replace_hostname_ends(
|
|
||||||
current_user.registrar.domains.includes(
|
|
||||||
:registrant, :nameservers, :admin_domain_contacts, :tech_domain_contacts, :domain_statuses,
|
|
||||||
:versions, :admin_contacts, :tech_contacts, :whois_record, :dnskeys
|
|
||||||
),
|
|
||||||
params[:q][:hostname_end],
|
|
||||||
params[:hostname_end_replacement]
|
|
||||||
)
|
|
||||||
|
|
||||||
if res
|
|
||||||
flash.now[:notice] = t('all_hostnames_replaced')
|
|
||||||
else
|
|
||||||
flash.now[:warning] = t('hostnames_partially_replaced')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -45,14 +45,18 @@ class Nameserver < ActiveRecord::Base
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def replace_hostname_ends(domains, old_end, new_end)
|
def replace_hostname_ends(domains, old_end, new_end)
|
||||||
|
domains = domains.where('EXISTS(
|
||||||
|
select 1 from nameservers ns where ns.domain_id = domains.id AND ns.hostname LIKE ?
|
||||||
|
)', "%#{old_end}"
|
||||||
|
)
|
||||||
|
|
||||||
res = true
|
res = true
|
||||||
domains.each do |d|
|
domains.each do |d|
|
||||||
nameservers = d.nameservers.where('hostname LIKE ?', "%#{old_end}")
|
|
||||||
next unless nameservers
|
|
||||||
|
|
||||||
ns_attrs = { nameservers_attributes: [] }
|
ns_attrs = { nameservers_attributes: [] }
|
||||||
|
|
||||||
nameservers.each do |ns|
|
d.nameservers.each do |ns|
|
||||||
|
next unless ns.hostname.end_with?(old_end)
|
||||||
|
|
||||||
hn = ns.hostname.chomp(old_end)
|
hn = ns.hostname.chomp(old_end)
|
||||||
ns_attrs[:nameservers_attributes] << {
|
ns_attrs[:nameservers_attributes] << {
|
||||||
id: ns.id,
|
id: ns.id,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
- content_for :actions do
|
- content_for :actions do
|
||||||
= link_to(t(:new), new_registrar_domain_path, class: 'btn btn-primary')
|
= link_to(t(:new), new_registrar_domain_path, class: 'btn btn-default')
|
||||||
= link_to(t(:transfer), transfer_registrar_domains_path, class: 'btn btn-default')
|
= link_to(t(:transfer), transfer_registrar_domains_path, class: 'btn btn-default')
|
||||||
= link_to(t(:keyrelay), registrar_keyrelay_path, class: 'btn btn-default')
|
= link_to(t(:keyrelay), registrar_keyrelay_path, class: 'btn btn-default')
|
||||||
|
= link_to(t(:nameservers), registrar_nameservers_path, class: 'btn btn-default')
|
||||||
= render 'shared/title', name: t(:domains)
|
= render 'shared/title', name: t(:domains)
|
||||||
|
|
||||||
.row
|
.row
|
||||||
|
@ -12,7 +13,7 @@
|
||||||
= text_field_tag :domain_name, params[:domain_name], class: 'form-control', placeholder: t('domain_name'), autocomplete: 'off', autofocus: true
|
= 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
|
.col-md-1.text-right.text-center-xs
|
||||||
.form-group
|
.form-group
|
||||||
%button.btn.btn-primary
|
%button.btn.btn-default
|
||||||
|
|
||||||
%span.glyphicon.glyphicon-search
|
%span.glyphicon.glyphicon-search
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@
|
||||||
= Time.zone.parse(x['valid_to']).try(:to_date)
|
= Time.zone.parse(x['valid_to']).try(:to_date)
|
||||||
%td
|
%td
|
||||||
= link_to(t(:edit), edit_registrar_domains_path(domain_name: x['name']),
|
= link_to(t(:edit), edit_registrar_domains_path(domain_name: x['name']),
|
||||||
class: 'btn btn-primary btn-xs')
|
class: 'btn btn-default btn-xs')
|
||||||
= link_to(t(:renew), renew_registrar_domains_path(domain_name: x['name']),
|
= link_to(t(:renew), renew_registrar_domains_path(domain_name: x['name']),
|
||||||
class: 'btn btn-default btn-xs')
|
class: 'btn btn-default btn-xs')
|
||||||
= link_to(t(:delete), delete_registrar_domains_path(domain_name: x['name']),
|
= link_to(t(:delete), delete_registrar_domains_path(domain_name: x['name']),
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/ - content_for :actions do
|
- content_for :actions do
|
||||||
/ = link_to(t(:add_deposit), new_registrar_deposit_path, class: 'btn btn-primary')
|
= link_to(t(:back_to_domains), registrar_domains_path, class: 'btn btn-default')
|
||||||
/ = link_to(t(:account_activity), registrar_account_activities_path, class: 'btn btn-default')
|
|
||||||
= render 'shared/title', name: t(:nameservers)
|
= render 'shared/title', name: t(:nameservers)
|
||||||
|
|
||||||
.row
|
.row
|
||||||
|
@ -20,10 +19,13 @@
|
||||||
|
|
||||||
%span.glyphicon.glyphicon-search
|
%span.glyphicon.glyphicon-search
|
||||||
|
|
||||||
%button.btn.btn-default{name: 'replace'}
|
|
||||||
= t(:replace)
|
|
||||||
%button.btn.btn-default.js-reset-form
|
%button.btn.btn-default.js-reset-form
|
||||||
= t(:clear_fields)
|
= t(:clear_fields)
|
||||||
|
%button.btn.btn-primary{name: 'replace'}
|
||||||
|
= t(:replace)
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
|
%p.help-block= t('hostnames_will_be_replaced_only_if_domain_validates_with_the_new_nameserver')
|
||||||
%hr
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
|
@ -31,9 +33,10 @@
|
||||||
%table.table.table-hover.table-condensed
|
%table.table.table-hover.table-condensed
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
%th{class: 'col-xs-4'}= t(:hostname)
|
%th{class: 'col-xs-3'}= t(:hostname)
|
||||||
%th{class: 'col-xs-4'}= t(:ipv4)
|
%th{class: 'col-xs-3'}= t(:ipv4)
|
||||||
%th{class: 'col-xs-4'}= t(:ipv6)
|
%th{class: 'col-xs-3'}= t(:ipv6)
|
||||||
|
%th{class: 'col-xs-3'}= t(:domain)
|
||||||
%tbody
|
%tbody
|
||||||
- @nameservers.each do |x|
|
- @nameservers.each do |x|
|
||||||
%tr
|
%tr
|
||||||
|
@ -46,9 +49,10 @@
|
||||||
%td= x.hostname
|
%td= x.hostname
|
||||||
%td= x.ipv4
|
%td= x.ipv4
|
||||||
%td= x.ipv4
|
%td= x.ipv4
|
||||||
|
%td= link_to(x.domain, info_registrar_domains_url(domain_name: x.domain.name))
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
/ = paginate @nameservers
|
= paginate @nameservers
|
||||||
|
|
||||||
:coffee
|
:coffee
|
||||||
$(".js-reset-form").on "click", (e) ->
|
$(".js-reset-form").on "click", (e) ->
|
||||||
|
|
|
@ -753,3 +753,5 @@ en:
|
||||||
hostnames_replaced: 'Hostnames replaced'
|
hostnames_replaced: 'Hostnames replaced'
|
||||||
all_hostnames_replaced: 'All hostnames replaced'
|
all_hostnames_replaced: 'All hostnames replaced'
|
||||||
hostnames_partially_replaced: 'Hostnames partially replaced'
|
hostnames_partially_replaced: 'Hostnames partially replaced'
|
||||||
|
hostnames_will_be_replaced_only_if_domain_validates_with_the_new_nameserver: 'Hostnames will be replaced only if domain validates with the new nameserver'
|
||||||
|
back_to_domains: 'Back to domains'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue