Refactor and view improvement

This commit is contained in:
Martin Lensment 2015-04-29 10:31:07 +03:00
parent 1f2ba55acb
commit 03a66e2e68
5 changed files with 47 additions and 34 deletions

View file

@ -2,27 +2,29 @@ class Registrar::NameserversController < RegistrarController
load_and_authorize_resource
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.sorts = 'id desc' if @q.sorts.empty?
@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
private

View file

@ -45,14 +45,18 @@ class Nameserver < ActiveRecord::Base
class << self
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
domains.each do |d|
nameservers = d.nameservers.where('hostname LIKE ?', "%#{old_end}")
next unless nameservers
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)
ns_attrs[:nameservers_attributes] << {
id: ns.id,

View file

@ -1,7 +1,8 @@
- 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(: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)
.row
@ -12,7 +13,7 @@
= 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-primary
%button.btn.btn-default
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
@ -37,7 +38,7 @@
= 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')
class: 'btn btn-default 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']),

View file

@ -1,6 +1,5 @@
/ - content_for :actions do
/ = link_to(t(:add_deposit), new_registrar_deposit_path, class: 'btn btn-primary')
/ = link_to(t(:account_activity), registrar_account_activities_path, class: 'btn btn-default')
- content_for :actions do
= link_to(t(:back_to_domains), registrar_domains_path, class: 'btn btn-default')
= render 'shared/title', name: t(:nameservers)
.row
@ -20,10 +19,13 @@
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
%button.btn.btn-default{name: 'replace'}
= t(:replace)
%button.btn.btn-default.js-reset-form
= 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
.row
.col-md-12
@ -31,9 +33,10 @@
%table.table.table-hover.table-condensed
%thead
%tr
%th{class: 'col-xs-4'}= t(:hostname)
%th{class: 'col-xs-4'}= t(:ipv4)
%th{class: 'col-xs-4'}= t(:ipv6)
%th{class: 'col-xs-3'}= t(:hostname)
%th{class: 'col-xs-3'}= t(:ipv4)
%th{class: 'col-xs-3'}= t(:ipv6)
%th{class: 'col-xs-3'}= t(:domain)
%tbody
- @nameservers.each do |x|
%tr
@ -46,9 +49,10 @@
%td= x.hostname
%td= x.ipv4
%td= x.ipv4
%td= link_to(x.domain, info_registrar_domains_url(domain_name: x.domain.name))
.row
.col-md-12
/ = paginate @nameservers
= paginate @nameservers
:coffee
$(".js-reset-form").on "click", (e) ->

View file

@ -753,3 +753,5 @@ en:
hostnames_replaced: 'Hostnames replaced'
all_hostnames_replaced: 'All hostnames 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'