forked from saurabh/orbit4-5
added pagination for frontend .. directly embeded in kernel and backend n frontend
This commit is contained in:
parent
6ec300813d
commit
7f8b471180
|
@ -51,6 +51,7 @@ class PagesController < ApplicationController
|
||||||
params[:slug] = nil
|
params[:slug] = nil
|
||||||
params[:uid] = nil
|
params[:uid] = nil
|
||||||
params[:target_action] = params[:method] || "index"
|
params[:target_action] = params[:method] || "index"
|
||||||
|
OrbitHelper.set_page_number params[:page_no].to_i || 1
|
||||||
end
|
end
|
||||||
page = Page.find_by_param(params[:page_id])
|
page = Page.find_by_param(params[:page_id])
|
||||||
if !page.nil?
|
if !page.nil?
|
||||||
|
@ -213,8 +214,10 @@ class PagesController < ApplicationController
|
||||||
html_string = html_string + p
|
html_string = html_string + p
|
||||||
end
|
end
|
||||||
pp = doc.css("*[#{key}]")
|
pp = doc.css("*[#{key}]")
|
||||||
pp = pp[0]
|
if !pp.blank?
|
||||||
pp.inner_html = html_string
|
pp = pp[0]
|
||||||
|
pp.inner_html = html_string
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if original_view != "home"
|
if original_view != "home"
|
||||||
|
|
|
@ -164,7 +164,6 @@ module ApplicationHelper
|
||||||
file.close
|
file.close
|
||||||
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
|
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
|
||||||
data = controller.send("#{params[:target_action]}")
|
data = controller.send("#{params[:target_action]}")
|
||||||
keys = data.keys
|
|
||||||
wrap_elements = doc.css("*[data-list][data-level='0']")
|
wrap_elements = doc.css("*[data-list][data-level='0']")
|
||||||
htmls = parsing_repeats_again(wrap_elements,data,1)
|
htmls = parsing_repeats_again(wrap_elements,data,1)
|
||||||
html = doc.to_s
|
html = doc.to_s
|
||||||
|
@ -172,13 +171,38 @@ module ApplicationHelper
|
||||||
html = html.gsub(h,htmls[1][i])
|
html = html.gsub(h,htmls[1][i])
|
||||||
end
|
end
|
||||||
|
|
||||||
if keys[1]
|
if data["extras"]
|
||||||
(data[keys[1]].kind_of?(Array) ? data[keys[0]] : data[keys[1]]).each do |key,value|
|
data["extras"].each do |key,value|
|
||||||
value = value.nil? ? "" : value
|
value = value.nil? ? "" : value
|
||||||
html = html.gsub("{{#{key}}}",value.to_s)
|
html = html.gsub("{{#{key}}}",value.to_s)
|
||||||
html = html.gsub("%7B%7B#{key}%7D%7D",value.to_s)
|
html = html.gsub("%7B%7B#{key}%7D%7D",value.to_s)
|
||||||
end
|
end
|
||||||
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
|
html.html_safe
|
||||||
elsif params[:target_action] == "show"
|
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"))
|
file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb"))
|
||||||
|
|
|
@ -15,6 +15,14 @@ module OrbitHelper
|
||||||
@data_count
|
@data_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.set_page_number(page)
|
||||||
|
@page_number = page
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.page_number
|
||||||
|
@page_number || 1
|
||||||
|
end
|
||||||
|
|
||||||
def self.page_categories
|
def self.page_categories
|
||||||
@categories
|
@categories
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,15 +6,17 @@
|
||||||
<body>
|
<body>
|
||||||
<%= render_orbit_bar %>
|
<%= render_orbit_bar %>
|
||||||
<%= render_header %>
|
<%= 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">
|
||||||
<div class="layout-content-inner container">
|
<div class="layout-content-inner container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<section class="layout-content-box col-sm-8" data-pp="2">
|
<section class="layout-content-box col-sm-8">
|
||||||
<main id="main-content" data-content="true">
|
<div data-pp="1"></div>
|
||||||
<%= yield %>
|
<main id="main-content" data-content="true">
|
||||||
</main>
|
<%= yield %>
|
||||||
|
</main>
|
||||||
|
<div data-pp="2"></div>
|
||||||
</section>
|
</section>
|
||||||
<aside class="layout-content-box col-sm-4" data-pp="3"></aside>
|
<aside class="layout-content-box col-sm-4" data-pp="3"></aside>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<ul class="pagination">
|
<ul class="pagination" data-pagination="true">
|
||||||
<li><a href="{{page_link}}">{{amount}}</a></li>
|
<li class="{{pagination_active}}"><a href="{{pagination_link}}">{{page_number}}</a></li>
|
||||||
</ul>
|
</ul>
|
|
@ -20,10 +20,4 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul class="pagination">
|
{{pagination_goes_here}}
|
||||||
<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>
|
|
|
@ -13,13 +13,13 @@ module OrbitCategory
|
||||||
if OrbitHelper.page_data_count == 0
|
if OrbitHelper.page_data_count == 0
|
||||||
self.all
|
self.all
|
||||||
else
|
else
|
||||||
self.all.limit(OrbitHelper.page_data_count)
|
self.all.page(OrbitHelper.page_number).per(OrbitHelper.page_data_count)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if OrbitHelper.page_data_count == 0
|
if OrbitHelper.page_data_count == 0
|
||||||
self.where(:category_id.in => categories) rescue []
|
self.where(:category_id.in => categories) rescue []
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue