From 4b9ba0fe13d5afdfe19e4ae77a1c66d02add0ea7 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Wed, 25 May 2016 11:09:06 +0300 Subject: [PATCH 1/3] Story#108869472 - contact history uses same pagination what domain history does --- .../admin/contact_versions_controller.rb | 17 +++++++++++++---- app/views/admin/contact_versions/show.haml | 16 +++++----------- app/views/admin/domain_versions/show.haml | 14 ++++---------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/app/controllers/admin/contact_versions_controller.rb b/app/controllers/admin/contact_versions_controller.rb index 9c8d05e61..cf7648720 100644 --- a/app/controllers/admin/contact_versions_controller.rb +++ b/app/controllers/admin/contact_versions_controller.rb @@ -29,10 +29,19 @@ class Admin::ContactVersionsController < AdminController def show per_page = 7 - @version = ContactVersion.find(params[:id]) - @q = ContactVersion.where(item_id: @version.item_id).order(created_at: :desc).search - @versions = @q.result.page(params[:page]) - @versions = @versions.per(per_page) + @version = ContactVersion.find(params[:id]) + @versions = ContactVersion.where(item_id: @version.item_id).order(created_at: :desc) + + # what we do is calc amount of results until needed version + # then we cacl which page it is + if params[:page].blank? + counter = @versions.where("created_at > ?", @version.created_at).count + page = counter / per_page + page += 1 if (counter % per_page) != 0 + params[:page] = page + end + + @versions = @versions.page(params[:page]).per(per_page) end def search diff --git a/app/views/admin/contact_versions/show.haml b/app/views/admin/contact_versions/show.haml index d48f22be6..6bfe88ecc 100644 --- a/app/views/admin/contact_versions/show.haml +++ b/app/views/admin/contact_versions/show.haml @@ -92,15 +92,9 @@ .panel.panel-default{:style => "min-height:420px;"} %ul.nav.nav-pills.nav-stacked - @versions.each do |vs| - - if vs.id == @version.id - %li.active - = link_to admin_contact_version_path(vs.id) do - = l(vs.created_at, format: :short) - = vs.event - - else - %li - = link_to admin_contact_version_path(vs.id) do - = l(vs.created_at, format: :short) - = vs.event + %li{class: (vs.id == @version.id) && :active} + = link_to admin_contact_version_path(vs.id, page: params[:page]) do + = l(vs.created_at, format: :short) + = vs.event %span{:style => "padding-left:10px; position: absolute; bottom: 10px;"} - = paginate @versions \ No newline at end of file + = paginate @versions, theme: :admin \ No newline at end of file diff --git a/app/views/admin/domain_versions/show.haml b/app/views/admin/domain_versions/show.haml index 2a245ab1f..999714ad3 100644 --- a/app/views/admin/domain_versions/show.haml +++ b/app/views/admin/domain_versions/show.haml @@ -96,15 +96,9 @@ .panel.panel-default{:style => "min-height:450px;"} %ul.nav.nav-pills.nav-stacked - @versions.each do |vs| - - if vs.id == @version.id - %li.active - = link_to admin_domain_version_path(vs) do - = l(vs.created_at, format: :short) - = vs.event - - else - %li - = link_to admin_domain_version_path(vs) do - = l(vs.created_at, format: :short) - = vs.event + %li{class: (vs.id == @version.id) && :active} + = link_to admin_domain_version_path(vs) do + = l(vs.created_at, format: :short) + = vs.event %span{:style => "padding-left:10px; position: absolute; bottom: 10px;"} = paginate @versions, theme: :admin From a1dc8043ec16f26a4af2c16400ce501f0811eeb5 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Wed, 25 May 2016 11:20:45 +0300 Subject: [PATCH 2/3] Story#120259603 - sort versions by id as otherwise postgresql becomes crazy on offset --- app/controllers/admin/contact_versions_controller.rb | 4 ++-- app/controllers/admin/domain_versions_controller.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/contact_versions_controller.rb b/app/controllers/admin/contact_versions_controller.rb index cf7648720..e318c0e9c 100644 --- a/app/controllers/admin/contact_versions_controller.rb +++ b/app/controllers/admin/contact_versions_controller.rb @@ -30,12 +30,12 @@ class Admin::ContactVersionsController < AdminController def show per_page = 7 @version = ContactVersion.find(params[:id]) - @versions = ContactVersion.where(item_id: @version.item_id).order(created_at: :desc) + @versions = ContactVersion.where(item_id: @version.item_id).order(id: :desc) # what we do is calc amount of results until needed version # then we cacl which page it is if params[:page].blank? - counter = @versions.where("created_at > ?", @version.created_at).count + counter = @versions.where("id > ?", @version.id).count page = counter / per_page page += 1 if (counter % per_page) != 0 params[:page] = page diff --git a/app/controllers/admin/domain_versions_controller.rb b/app/controllers/admin/domain_versions_controller.rb index 1a469ddeb..debf628cf 100644 --- a/app/controllers/admin/domain_versions_controller.rb +++ b/app/controllers/admin/domain_versions_controller.rb @@ -44,12 +44,12 @@ class Admin::DomainVersionsController < AdminController def show per_page = 7 @version = DomainVersion.find(params[:id]) - @versions = DomainVersion.where(item_id: @version.item_id).order(created_at: :desc) + @versions = DomainVersion.where(item_id: @version.item_id).order(id: :desc) # what we do is calc amount of results until needed version # then we cacl which page it is if params[:page].blank? - counter = @versions.where("created_at > ?", @version.created_at).count + counter = @versions.where("id > ?", @version.id).count page = counter / per_page page += 1 if (counter % per_page) != 0 params[:page] = page From c0a6737f1f417413efc129e531c9ca115f6447d8 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Wed, 25 May 2016 12:07:02 +0300 Subject: [PATCH 3/3] Story#120259603 - remove phone number and rename column name in contact history --- app/views/admin/contact_versions/index.haml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/views/admin/contact_versions/index.haml b/app/views/admin/contact_versions/index.haml index 0e513f37b..93699d4e3 100644 --- a/app/views/admin/contact_versions/index.haml +++ b/app/views/admin/contact_versions/index.haml @@ -16,16 +16,13 @@ .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 .form-group = label_tag :action = select_tag '[q][event]', options_for_select([['Update', 'update'], ['Destroy', 'destroy'], ['Create', 'create']], params[:q][:event]), { include_blank:true, multiple: false, placeholder: t(:choose), class: 'form-control js-combobox' } + .row + .col-md-3 + .col-md-3 .col-md-3 .form-group = label_tag t(:results_per_page) @@ -52,14 +49,12 @@ = t(:id) %th{class: 'col-xs-2'} = t(:ident) - %th{class: 'col-xs-2'} - = t(:phone) %th{class: 'col-xs-2'} = t(:registrar) - %th{class: 'col-xs-2'} - = t(:action_date) %th{class: 'col-xs-2'} = t(:action) + %th{class: 'col-xs-2'} + = t(:created_at) %tbody - @versions.each do |version| - if version @@ -70,12 +65,11 @@ %td= link_to(contact.name, admin_contact_version_path(version.id)) %td= contact.code %td= ident_for(contact) - %td= contact.phone %td - if contact.registrar = link_to(contact.registrar, admin_registrar_path(contact.registrar)) - %td= l(version.created_at, format: :short) %td= version.event + %td= l(version.created_at, format: :short) .row