diff --git a/app/controllers/admin/domain_versions_controller.rb b/app/controllers/admin/domain_versions_controller.rb index 17748b482..1a469ddeb 100644 --- a/app/controllers/admin/domain_versions_controller.rb +++ b/app/controllers/admin/domain_versions_controller.rb @@ -43,21 +43,19 @@ class Admin::DomainVersionsController < AdminController def show per_page = 7 - @version = DomainVersion.find(params[:id]) - @q = DomainVersion.where(item_id: @version.item_id).order(created_at: :desc).search + @version = DomainVersion.find(params[:id]) + @versions = DomainVersion.where(item_id: @version.item_id).order(created_at: :desc) - if (@q.result.count > per_page) && params[:page] == 'default' - page = 1 - @q.result.each_with_index do |v, i| - break if v.id == @version.id and page = (i / per_page) + 1 - end + # 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 - @versions = @q.result.page(page) - else - @versions = @q.result.page(params[:page]) end - @versions = @versions.per(per_page) + @versions = @versions.page(params[:page]).per(per_page) end def search diff --git a/app/views/admin/domain_versions/archive.haml b/app/views/admin/domain_versions/archive.haml index de81af1e4..31fb9bc9d 100644 --- a/app/views/admin/domain_versions/archive.haml +++ b/app/views/admin/domain_versions/archive.haml @@ -60,7 +60,7 @@ - version.object_changes.to_h.each{|k,v| domain[k]=v.last} %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 - if domain.registrant = domain.registrant diff --git a/app/views/admin/domain_versions/show.haml b/app/views/admin/domain_versions/show.haml index f169174f5..2a245ab1f 100644 --- a/app/views/admin/domain_versions/show.haml +++ b/app/views/admin/domain_versions/show.haml @@ -79,14 +79,14 @@ %div{:style => "margin: 20px 20px; clear:both;"} - if @version.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') - else %a.btn.btn-primary.disabled{:href => "#"} %span= t(:previous) - if @version.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') - else %a.btn.btn-default.disabled{:href => "#"} @@ -98,13 +98,13 @@ - @versions.each do |vs| - if vs.id == @version.id %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) = vs.event - else %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) = vs.event %span{:style => "padding-left:10px; position: absolute; bottom: 10px;"} - = paginate @versions + = paginate @versions, theme: :admin diff --git a/app/views/kaminari/admin/_first_page.html.haml b/app/views/kaminari/admin/_first_page.html.haml new file mode 100644 index 000000000..c5bbf13e1 --- /dev/null +++ b/app/views/kaminari/admin/_first_page.html.haml @@ -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 diff --git a/app/views/kaminari/admin/_gap.html.haml b/app/views/kaminari/admin/_gap.html.haml new file mode 100644 index 000000000..dd5789cc1 --- /dev/null +++ b/app/views/kaminari/admin/_gap.html.haml @@ -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 diff --git a/app/views/kaminari/admin/_last_page.html.haml b/app/views/kaminari/admin/_last_page.html.haml new file mode 100644 index 000000000..cdddb9e7c --- /dev/null +++ b/app/views/kaminari/admin/_last_page.html.haml @@ -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 diff --git a/app/views/kaminari/admin/_next_page.html.haml b/app/views/kaminari/admin/_next_page.html.haml new file mode 100644 index 000000000..2865dcd0c --- /dev/null +++ b/app/views/kaminari/admin/_next_page.html.haml @@ -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 diff --git a/app/views/kaminari/admin/_page.html.haml b/app/views/kaminari/admin/_page.html.haml new file mode 100644 index 000000000..d583c58f1 --- /dev/null +++ b/app/views/kaminari/admin/_page.html.haml @@ -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} diff --git a/app/views/kaminari/admin/_paginator.html.haml b/app/views/kaminari/admin/_paginator.html.haml new file mode 100644 index 000000000..4f33e2dee --- /dev/null +++ b/app/views/kaminari/admin/_paginator.html.haml @@ -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? diff --git a/app/views/kaminari/admin/_prev_page.html.haml b/app/views/kaminari/admin/_prev_page.html.haml new file mode 100644 index 000000000..3b565fa6f --- /dev/null +++ b/app/views/kaminari/admin/_prev_page.html.haml @@ -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