108869472-archive

This commit is contained in:
Stas 2016-01-12 18:37:05 +02:00
parent a8ff887717
commit 9278e6703f
5 changed files with 171 additions and 39 deletions

View file

@ -3,37 +3,30 @@ class Admin::ContactVersionsController < AdminController
def index
params[:q] ||= {}
@q = ContactVersion.search(params[:q])
@versions = @q.result.page(params[:page])
versions = ContactVersion.all
whereS = "1=1"
normalize_search_parameters do
@q = versions.search(params[:q])
@versions = @q.result.page(params[:page])
params[:q].each do |key, value|
next if value.empty?
whereS += create_where_string(key, value)
end
versions = ContactVersion.includes(:item).where(whereS)
@q = versions.search(params[:q])
@versions = @q.result.page(params[:page])
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
end
def search
render json: ContactVersion.search_by_query(params[:q])
end
def normalize_search_parameters
ca_cache = params[:q][:created_at_lteq]
begin
end_time = params[:q][:created_at_lteq].try(:to_date)
params[:q][:created_at_lteq] = end_time.try(:end_of_day)
end_time = params[:q][:updated_at_gteq].try(:to_date)
params[:q][:updated_at_lteq] = end_time.try(:end_of_day)
rescue
logger.warn('Invalid date')
end
yield
params[:q][:created_at_lteq] = ca_cache
def create_where_string(key, value)
" AND object->>'#{key}' ~ '#{value}'"
end
end

View file

@ -1,18 +1,48 @@
class Admin::DomainVersionsController < AdminController
load_and_authorize_resource
# rubocop:disable Style/GuardClause
def index
# @domain = Domain.where(id: params[:domain_id]).includes({versions: :item}).first
# @versions = @domain.versions
params[:q] ||= {}
@q = DomainVersion.includes(:item).search(params[:q])
@versions = @q.result.page(params[:page])
search_params = params[:q].deep_dup
if search_params[:registrant]
registrant = Contact.find_by_name(search_params[:registrant])
search_params.delete(:registrant)
end
if search_params[:registrar]
registrar = Registrar.find_by_name(search_params[:registrar])
search_params.delete(:registrar)
end
whereS = "1=1"
search_params.each do |key, value|
next if value.empty?
whereS += create_where_string(key, value)
end
whereS += " AND object->>'registrant_id' ~ '#{registrant.id}'" if registrant
whereS += " AND object->>'registrar_id' ~ '#{registrar.id}'" if registrar
versions = DomainVersion.includes(:item).where(whereS)
@q = versions.search(params[:q])
@versions = @q.result.page(params[:page])
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
render "admin/domain_versions/archive"
# Depricated it had to load legal document. We may do it by parsing and adding link.
# if @domain.pending_json.present?
# frame = Nokogiri::XML(@domain.pending_json['frame'])
# @pending_user = User.find(@domain.pending_json['current_user_id'])
# @pending_domain = Epp::Domain.find(@domain.id)
# @pending_domain.update(frame, @pending_user, false)
# end
end
# rubocop:enable Style/GuardClause
def search
render json: DomainVersion.search_by_query(params[:q])
end
def create_where_string(key, value)
" AND object->>'#{key}' ~ '#{value}'"
end
end

View file

@ -38,7 +38,7 @@ class DomainNameValidator < ActiveModel::EachValidator
def validate_blocked(value)
return true unless value
return false if BlockedDomain.where("names @> ?::varchar[]", "{#{value}}").count > 0
return false if BlockedDomain.where(name: value).count > 0
ZonefileSetting.where(origin: value).count == 0
end
end

View file

@ -1,4 +1,40 @@
= render 'shared/title', name: t(:contact_versions)
= render 'shared/title', name: t(:contacts)
.row
.col-md-12
= 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, value: params[:q][:name], class: 'form-control', placeholder: t(:name)
.col-md-3
.form-group
= f.label :id
= f.search_field :id, value: params[:q][:id], class: 'form-control', placeholder: t(:id)
.col-md-3
.form-group
= f.label :ident
= f.search_field :ident, value: params[:q][:ident], class: 'form-control', placeholder: t(:ident)
.col-md-3
.form-group
= f.label :phone
= f.search_field :phone, value: params[:q][:phone], class: 'form-control', placeholder: t(:phone)
.row
.col-md-3
.col-md-3
.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
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
%button.btn.btn-default.js-reset-form
= t(:clear_fields)
%hr
.row
@ -8,30 +44,30 @@
%thead
%tr
%th{class: 'col-xs-2'}
= sort_link(@q, 'name', t(:name))
= t(:name)
%th{class: 'col-xs-2'}
= sort_link(@q, 'code', t(:id))
= t(:id)
%th{class: 'col-xs-2'}
= sort_link(@q, 'ident', t(:ident))
= t(:ident)
%th{class: 'col-xs-2'}
= sort_link(@q, 'registrar_name', t(:registrar))
= t(:phone)
%th{class: 'col-xs-2'}
= sort_link(@q, 'email', t(:created_at))
= t(:registrar)
%th{class: 'col-xs-2'}
= sort_link(@q, 'action', t(:action))
= t(:action)
%tbody
- @versions.each do |version|
%tr
%td= version.reify.name
%td= version.reify.code
%td= ident_for(version.reify)
%td= l(version.created_at, format: :short)
%td= version.reify.phone
%td
- if version.reify.registrar
= link_to(version.reify.registrar, admin_registrar_path(version.reify.registrar))
%td= version.event
.row
.col-md-6
= paginate @versions

View file

@ -0,0 +1,73 @@
= render 'shared/title', name: t(:domains)
.row
.col-md-12
= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f|
.row
.col-md-3
.form-group
= label_tag :name
= f.search_field :name, value: params[:q][:name], class: 'form-control', placeholder: t(:name)
.col-md-3
.form-group
= label_tag :registrant
= f.search_field :registrant, value: params[:q][:registrant], class: 'form-control', placeholder: t(:registrant)
.col-md-3
.form-group
= label_tag t(:registrar)
= f.search_field :registrar, value: params[:q][:registrar], class: 'form-control', placeholder: t(:registrant)
.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)
.row
.col-md-3
.col-md-3
.col-md-3
.col-md-3{style: 'padding-top: 25px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
%button.btn.btn-default.js-reset-form
= t(:clear_fields)
%hr
.row
.col-md-12
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-2'}
= t(:name)
%th{class: 'col-xs-2'}
= t(:registrant)
%th{class: 'col-xs-2'}
= t(:registrar)
%th{class: 'col-xs-2'}
= t(:action)
%tbody
- @versions.each do |version|
%tr
%td= version.reify.name
%td
- if version.reify.registrant.ident
= link_to(version.reify.registrant, admin_registrant_path(version.reify.registrant))
%td
- if version.reify.registrar
= link_to(version.reify.registrar, admin_registrar_path(version.reify.registrar))
%td= version.event
.row
.col-md-6
= paginate @versions
.col-md-6.text-right
:coffee
$(".js-reset-form").on "click", (e) ->
e.preventDefault();
window.location = "#{admin_domain_versions_path}"