diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2e2e5c8..dce6a94 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -191,28 +191,9 @@ module ApplicationHelper html = html.gsub("%7B%7B#{key}%7D%7D",value.to_s) end end - file = File.join(Rails.root, 'app', 'templates', "#{@key}", 'home', "pagination.html.erb") total_pages = data['total_pages'].to_i rescue 1 if total_pages > 1 - if File.exists?file - file = File.open(file) - doc = Nokogiri::HTML(file, nil, "UTF-8") - file.close - paginationobj = doc.css("*[data-pagination='true']").first - in_html = paginationobj.inner_html - f_html = "" - (1..total_pages).each do |i| - h = in_html - h = h.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{i.to_s}") - h = h.gsub("{{page_number}}",i.to_s) - h = h.gsub("{{pagination_active}}",(i == OrbitHelper.page_number ? "active" : "")) - f_html = f_html + h - end - paginationobj.inner_html = f_html - html = html.gsub("{{pagination_goes_here}}",paginationobj.to_s) - else - html = html.gsub("{{pagination_goes_here}}",""); - end + html = html.gsub("{{pagination_goes_here}}",create_pagination(total_pages)) else html = html.gsub("{{pagination_goes_here}}",""); end @@ -357,4 +338,62 @@ module ApplicationHelper html.html_safe end + def create_pagination(total_pages) + file = File.join(Rails.root, 'app', 'templates', "#{@key}", 'home', "pagination.html.erb") + html = "" + if File.exists?file + file = File.open(file) + doc = Nokogiri::HTML(file, nil, "UTF-8") + file.close + paginationobj = doc.css("*[data-pagination='true']").first + in_html = first = last = nextpage = prevpage = paginationobj.inner_html + f_html = "" + current_page_number = OrbitHelper.page_number + if current_page_number > 1 + first = first.gsub("%7B%7Bpagination_link%7D%7D","?page_no=1") + first = first.gsub("{{page_number}}","First") + first = first.gsub("{{pagination_active}}","") + f_html = f_html + first + end + start_number = current_page_number - 2 + end_number = current_page_number + 2 + if end_number > total_pages + end_number = total_pages + start_number = total_pages - 4 + end + if start_number < 1 + start_number = 1 + end_number = 5 + end + (start_number..end_number).each do |i| + h = in_html + h = h.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{i.to_s}") + h = h.gsub("{{page_number}}",i.to_s) + h = h.gsub("{{pagination_active}}",(i == current_page_number ? "active" : "")) + f_html = f_html + h + end + if current_page_number > 1 + prevpage = prevpage.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{current_page_number - 1}") + prevpage = prevpage.gsub("{{page_number}}","«") + prevpage = prevpage.gsub("{{pagination_active}}","") + f_html = f_html + prevpage + end + + if current_page_number < total_pages + nextpage = nextpage.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{current_page_number + 1}") + nextpage = nextpage.gsub("{{page_number}}","»") + nextpage = nextpage.gsub("{{pagination_active}}","") + f_html = f_html + nextpage + + last = last.gsub("%7B%7Bpagination_link%7D%7D","?page_no=#{total_pages}") + last = last.gsub("{{page_number}}","Last") + last = last.gsub("{{pagination_active}}","") + f_html = f_html + last + end + paginationobj.inner_html = f_html + html = paginationobj.to_s + end + html + end + end diff --git a/app/helpers/orbit_helper.rb b/app/helpers/orbit_helper.rb index 70d0441..e91a6c4 100644 --- a/app/helpers/orbit_helper.rb +++ b/app/helpers/orbit_helper.rb @@ -17,6 +17,9 @@ module OrbitHelper def self.set_page_number(page) @page_number = page + if @page_number == 0 + @page_number = 1 + end end def self.page_number diff --git a/app/templates/orbit_bootstrap/home/pagination.html.erb b/app/templates/orbit_bootstrap/home/pagination.html.erb index 96c2b2f..7a5e994 100644 --- a/app/templates/orbit_bootstrap/home/pagination.html.erb +++ b/app/templates/orbit_bootstrap/home/pagination.html.erb @@ -1,3 +1,7 @@ \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/admin/import/index.html.erb b/app/views/admin/import/index.html.erb index 16209c6..e91cfc3 100644 --- a/app/views/admin/import/index.html.erb +++ b/app/views/admin/import/index.html.erb @@ -127,7 +127,7 @@ -
+

<%= t("page_content.page") %>