added pagination for frontend .. directly embeded in kernel and backend n frontend

This commit is contained in:
Harry Bomrah 2014-06-04 20:36:12 +08:00
parent 6ec300813d
commit 7f8b471180
8 changed files with 52 additions and 21 deletions

View File

@ -51,6 +51,7 @@ class PagesController < ApplicationController
params[:slug] = nil
params[:uid] = nil
params[:target_action] = params[:method] || "index"
OrbitHelper.set_page_number params[:page_no].to_i || 1
end
page = Page.find_by_param(params[:page_id])
if !page.nil?
@ -213,8 +214,10 @@ class PagesController < ApplicationController
html_string = html_string + p
end
pp = doc.css("*[#{key}]")
pp = pp[0]
pp.inner_html = html_string
if !pp.blank?
pp = pp[0]
pp.inner_html = html_string
end
end
if original_view != "home"

View File

@ -164,7 +164,6 @@ module ApplicationHelper
file.close
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
data = controller.send("#{params[:target_action]}")
keys = data.keys
wrap_elements = doc.css("*[data-list][data-level='0']")
htmls = parsing_repeats_again(wrap_elements,data,1)
html = doc.to_s
@ -172,13 +171,38 @@ module ApplicationHelper
html = html.gsub(h,htmls[1][i])
end
if keys[1]
(data[keys[1]].kind_of?(Array) ? data[keys[0]] : data[keys[1]]).each do |key,value|
if data["extras"]
data["extras"].each do |key,value|
value = value.nil? ? "" : value
html = html.gsub("{{#{key}}}",value.to_s)
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
else
html = html.gsub("{{pagination_goes_here}}","");
end
html.html_safe
elsif params[:target_action] == "show"
file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb"))

View File

@ -15,6 +15,14 @@ module OrbitHelper
@data_count
end
def self.set_page_number(page)
@page_number = page
end
def self.page_number
@page_number || 1
end
def self.page_categories
@categories
end

View File

@ -6,15 +6,17 @@
<body>
<%= render_orbit_bar %>
<%= render_header %>
<section class="layout-slide" data-pp="1"></section>
<section class="layout-slide" data-pp="4"></section>
<div class="layout-content">
<div class="layout-content-inner container">
<div class="row">
<section class="layout-content-box col-sm-8" data-pp="2">
<main id="main-content" data-content="true">
<%= yield %>
</main>
<section class="layout-content-box col-sm-8">
<div data-pp="1"></div>
<main id="main-content" data-content="true">
<%= yield %>
</main>
<div data-pp="2"></div>
</section>
<aside class="layout-content-box col-sm-4" data-pp="3"></aside>
</div>

View File

@ -1,3 +1,3 @@
<ul class="pagination">
<li><a href="{{page_link}}">{{amount}}</a></li>
<ul class="pagination" data-pagination="true">
<li class="{{pagination_active}}"><a href="{{pagination_link}}">{{page_number}}</a></li>
</ul>

View File

@ -20,10 +20,4 @@
</div>
</div>
</div>
<ul class="pagination">
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
</ul>
{{pagination_goes_here}}

View File

@ -13,13 +13,13 @@ module OrbitCategory
if OrbitHelper.page_data_count == 0
self.all
else
self.all.limit(OrbitHelper.page_data_count)
self.all.page(OrbitHelper.page_number).per(OrbitHelper.page_data_count)
end
else
if OrbitHelper.page_data_count == 0
self.where(:category_id.in => categories) rescue []
else
self.where(:category_id.in => categories).limit(OrbitHelper.page_data_count) rescue []
self.where(:category_id.in => categories).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
end
end
else