mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 02:09:39 +02:00
108869472-pagination_modification
This commit is contained in:
parent
09f28e0470
commit
97c4bf0097
10 changed files with 93 additions and 17 deletions
|
@ -43,21 +43,19 @@ class Admin::DomainVersionsController < AdminController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
per_page = 7
|
per_page = 7
|
||||||
@version = DomainVersion.find(params[:id])
|
@version = DomainVersion.find(params[:id])
|
||||||
@q = DomainVersion.where(item_id: @version.item_id).order(created_at: :desc).search
|
@versions = DomainVersion.where(item_id: @version.item_id).order(created_at: :desc)
|
||||||
|
|
||||||
if (@q.result.count > per_page) && params[:page] == 'default'
|
# what we do is calc amount of results until needed version
|
||||||
page = 1
|
# then we cacl which page it is
|
||||||
@q.result.each_with_index do |v, i|
|
if params[:page].blank?
|
||||||
break if v.id == @version.id and page = (i / per_page) + 1
|
counter = @versions.where("created_at > ?", @version.created_at).count
|
||||||
end
|
page = counter / per_page
|
||||||
|
page += 1 if (counter % per_page) != 0
|
||||||
params[:page] = page
|
params[:page] = page
|
||||||
@versions = @q.result.page(page)
|
|
||||||
else
|
|
||||||
@versions = @q.result.page(params[:page])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@versions = @versions.per(per_page)
|
@versions = @versions.page(params[:page]).per(per_page)
|
||||||
end
|
end
|
||||||
|
|
||||||
def search
|
def search
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
- version.object_changes.to_h.each{|k,v| domain[k]=v.last}
|
- version.object_changes.to_h.each{|k,v| domain[k]=v.last}
|
||||||
|
|
||||||
%tr
|
%tr
|
||||||
%td= link_to(domain.name, admin_domain_version_path(version.id, :page => 'default'))
|
%td= link_to(domain.name, admin_domain_version_path(version.id))
|
||||||
%td
|
%td
|
||||||
- if domain.registrant
|
- if domain.registrant
|
||||||
= domain.registrant
|
= domain.registrant
|
||||||
|
|
|
@ -79,14 +79,14 @@
|
||||||
%div{:style => "margin: 20px 20px; clear:both;"}
|
%div{:style => "margin: 20px 20px; clear:both;"}
|
||||||
- if @version.previous
|
- if @version.previous
|
||||||
= link_to(t(:previous),
|
= link_to(t(:previous),
|
||||||
admin_domain_version_path(@version.previous.id, :page => 'default'),
|
admin_domain_version_path(@version.previous.id),
|
||||||
class: 'btn btn-primary')
|
class: 'btn btn-primary')
|
||||||
- else
|
- else
|
||||||
%a.btn.btn-primary.disabled{:href => "#"}
|
%a.btn.btn-primary.disabled{:href => "#"}
|
||||||
%span= t(:previous)
|
%span= t(:previous)
|
||||||
- if @version.next
|
- if @version.next
|
||||||
= link_to(t(:next),
|
= link_to(t(:next),
|
||||||
admin_domain_version_path(@version.next.id, :page => 'default'),
|
admin_domain_version_path(@version.next.id),
|
||||||
class: 'btn btn-default')
|
class: 'btn btn-default')
|
||||||
- else
|
- else
|
||||||
%a.btn.btn-default.disabled{:href => "#"}
|
%a.btn.btn-default.disabled{:href => "#"}
|
||||||
|
@ -98,13 +98,13 @@
|
||||||
- @versions.each do |vs|
|
- @versions.each do |vs|
|
||||||
- if vs.id == @version.id
|
- if vs.id == @version.id
|
||||||
%li.active
|
%li.active
|
||||||
= link_to admin_domain_version_path(vs.id, :page => 'default') do
|
= link_to admin_domain_version_path(vs) do
|
||||||
= l(vs.created_at, format: :short)
|
= l(vs.created_at, format: :short)
|
||||||
= vs.event
|
= vs.event
|
||||||
- else
|
- else
|
||||||
%li
|
%li
|
||||||
= link_to admin_domain_version_path(vs.id, :page => 'default') do
|
= link_to admin_domain_version_path(vs) do
|
||||||
= l(vs.created_at, format: :short)
|
= l(vs.created_at, format: :short)
|
||||||
= vs.event
|
= vs.event
|
||||||
%span{:style => "padding-left:10px; position: absolute; bottom: 10px;"}
|
%span{:style => "padding-left:10px; position: absolute; bottom: 10px;"}
|
||||||
= paginate @versions
|
= paginate @versions, theme: :admin
|
||||||
|
|
11
app/views/kaminari/admin/_first_page.html.haml
Normal file
11
app/views/kaminari/admin/_first_page.html.haml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
-# Link to the "First" page
|
||||||
|
-# available local variables
|
||||||
|
-# url: url to the first page
|
||||||
|
-# current_page: a page object for the currently displayed page
|
||||||
|
-# total_pages: total number of pages
|
||||||
|
-# per_page: number of items to fetch per page
|
||||||
|
-# remote: data-remote
|
||||||
|
%span.first
|
||||||
|
- param_name = current_page.instance_variable_get("@options")[:param_name] || Kaminari.config.param_name
|
||||||
|
- urlik = url_for( params.merge(param_name => 1, :only_path => true))
|
||||||
|
= link_to_unless current_page.first?, t('views.pagination.first').html_safe, urlik, :remote => remote
|
8
app/views/kaminari/admin/_gap.html.haml
Normal file
8
app/views/kaminari/admin/_gap.html.haml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
-# Non-link tag that stands for skipped pages...
|
||||||
|
-# available local variables
|
||||||
|
-# current_page: a page object for the currently displayed page
|
||||||
|
-# total_pages: total number of pages
|
||||||
|
-# per_page: number of items to fetch per page
|
||||||
|
-# remote: data-remote
|
||||||
|
%span.page.gap
|
||||||
|
= t('views.pagination.truncate').html_safe
|
9
app/views/kaminari/admin/_last_page.html.haml
Normal file
9
app/views/kaminari/admin/_last_page.html.haml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
-# Link to the "Last" page
|
||||||
|
-# available local variables
|
||||||
|
-# url: url to the last page
|
||||||
|
-# current_page: a page object for the currently displayed page
|
||||||
|
-# total_pages: total number of pages
|
||||||
|
-# per_page: number of items to fetch per page
|
||||||
|
-# remote: data-remote
|
||||||
|
%span.last
|
||||||
|
= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, :remote => remote
|
9
app/views/kaminari/admin/_next_page.html.haml
Normal file
9
app/views/kaminari/admin/_next_page.html.haml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
-# Link to the "Next" page
|
||||||
|
-# available local variables
|
||||||
|
-# url: url to the next page
|
||||||
|
-# current_page: a page object for the currently displayed page
|
||||||
|
-# total_pages: total number of pages
|
||||||
|
-# per_page: number of items to fetch per page
|
||||||
|
-# remote: data-remote
|
||||||
|
%span.next
|
||||||
|
= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, :rel => 'next', :remote => remote
|
12
app/views/kaminari/admin/_page.html.haml
Normal file
12
app/views/kaminari/admin/_page.html.haml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
-# Link showing page number
|
||||||
|
-# available local variables
|
||||||
|
-# page: a page object for "this" page
|
||||||
|
-# url: url to this page
|
||||||
|
-# current_page: a page object for the currently displayed page
|
||||||
|
-# total_pages: total number of pages
|
||||||
|
-# per_page: number of items to fetch per page
|
||||||
|
-# remote: data-remote
|
||||||
|
%span{:class => "page#{' current' if page.current?}"}
|
||||||
|
- param_name = current_page.instance_variable_get("@options")[:param_name] || Kaminari.config.param_name
|
||||||
|
- urlik = url_for( params.merge(param_name => page.to_i, :only_path => true))
|
||||||
|
= link_to_unless page.current?, page, urlik, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}
|
18
app/views/kaminari/admin/_paginator.html.haml
Normal file
18
app/views/kaminari/admin/_paginator.html.haml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
-# The container tag
|
||||||
|
-# available local variables
|
||||||
|
-# current_page: a page object for the currently displayed page
|
||||||
|
-# total_pages: total number of pages
|
||||||
|
-# per_page: number of items to fetch per page
|
||||||
|
-# remote: data-remote
|
||||||
|
-# paginator: the paginator that renders the pagination tags inside
|
||||||
|
= paginator.render do
|
||||||
|
%nav.pagination
|
||||||
|
= first_page_tag unless current_page.first?
|
||||||
|
= prev_page_tag unless current_page.first?
|
||||||
|
- each_page do |page|
|
||||||
|
- if page.left_outer? || page.right_outer? || page.inside_window?
|
||||||
|
= page_tag page
|
||||||
|
- elsif !page.was_truncated?
|
||||||
|
= gap_tag
|
||||||
|
= next_page_tag unless current_page.last?
|
||||||
|
= last_page_tag unless current_page.last?
|
11
app/views/kaminari/admin/_prev_page.html.haml
Normal file
11
app/views/kaminari/admin/_prev_page.html.haml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
-# Link to the "Previous" page
|
||||||
|
-# available local variables
|
||||||
|
-# url: url to the previous page
|
||||||
|
-# current_page: a page object for the currently displayed page
|
||||||
|
-# total_pages: total number of pages
|
||||||
|
-# per_page: number of items to fetch per page
|
||||||
|
-# remote: data-remote
|
||||||
|
%span.prev
|
||||||
|
- param_name = current_page.instance_variable_get("@options")[:param_name] || Kaminari.config.param_name
|
||||||
|
- urlik = url_for( params.merge(param_name => current_page.to_i - 1, :only_path => true))
|
||||||
|
= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, urlik, :rel => 'prev', :remote => remote
|
Loading…
Add table
Add a link
Reference in a new issue